Skip to content

Commit

Permalink
add optpow CLI + clean-up structs
Browse files Browse the repository at this point in the history
  • Loading branch information
pkotamnives committed Oct 13, 2023
1 parent 28532ef commit 56b3340
Show file tree
Hide file tree
Showing 5 changed files with 174 additions and 132 deletions.
2 changes: 1 addition & 1 deletion projects/cm_mcu/CommandLineTask.c
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ static struct command_t commands[] = {
{
"ff_optpow",
ff_optpow,
"Displays a table showing the avg. optical power of the I2C fireflies.\r\n",
"Displays a table showing the per-ch optical power of the I2C fireflies.\r\n",
0,
},
{
Expand Down
119 changes: 91 additions & 28 deletions projects/cm_mcu/LocalTasks.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,13 @@ struct sm_command_t sm_command_ffldaq_f1[] = {
{1, 0x00, 0x16, 2, "FF_TEMPERATURE", 0xff, "C", PM_STATUS},
{1, 0x00, 0x03, 1, "FF_LOS_ALARM", 0xff, "", PM_STATUS},
{1, 0x00, 0x05, 1, "FF_CDR_LOL_ALARM", 0xff, "", PM_STATUS},
{2, 0x00, 0x22, 1, "FF_OPT_POW", 0xff, "mw", PM_STATUS}, // read 4 Rx-ch registers with increasing addresses
{2, 0x00, 0x22, 1, "FF_CH01_OPT_POW", 0xff, "mw", PM_STATUS}, // read 4 Rx-ch registers with increasing addresses
{2, 0x00, 0x24, 1, "FF_CH02_OPT_POW", 0xff, "mw", PM_STATUS},
{2, 0x00, 0x26, 1, "FF_CH03_OPT_POW", 0xff, "mw", PM_STATUS},
{2, 0x00, 0x28, 1, "FF_CH04_OPT_POW", 0xff, "mw", PM_STATUS},
};

uint16_t ffldaq_f1_values[NSUPPLIES_FFLDAQ_F1 * NCOMMANDS_FFLDAQ_F1];
uint16_t ffldaq_f1_optpow_values[NSUPPLIES_FFLDAQ_F1];

struct MonitorI2CTaskArgs_t ffldaq_f1_args = {
.name = "FFDAQ",
Expand All @@ -186,8 +188,6 @@ struct MonitorI2CTaskArgs_t ffldaq_f1_args = {
.smbus_status = &eStatus4,
.xSem = NULL,
.ffpart_bit_mask = 0U,
.n_rxchs = FF_DAQ_NRXCH,
.opt_pow_values = ffldaq_f1_optpow_values,
.present_bit_mask = 0U,
.stack_size = 4096U,
};
Expand All @@ -200,6 +200,21 @@ struct sm_command_t sm_command_fflit_f1[] = {
{1, 0x00, 0x16, 2, "FF_TEMPERATURE", 0xff, "C", PM_STATUS},
{2, 0x00, 0x07, 1, "FF_LOS_ALARM", 0xffff, "", PM_STATUS},
{2, 0x00, 0x14, 1, "FF_CDR_LOL_ALARM", 0xffff, "", PM_STATUS},
// there are no registers to read optical power for 14Gbps ECUO.
// registers below are a placeholder with a reading equal to zero
// the reason we need them because n_commands is fixed
{1, 0x00, 0x00, 1, "FF_CH01_OPT_POW", 0xff, "mw", PM_STATUS},
{1, 0x00, 0x00, 1, "FF_CH02_OPT_POW", 0xff, "mw", PM_STATUS},
{1, 0x00, 0x00, 1, "FF_CH03_OPT_POW", 0xff, "mw", PM_STATUS},
{1, 0x00, 0x00, 1, "FF_CH04_OPT_POW", 0xff, "mw", PM_STATUS},
{1, 0x00, 0x00, 1, "FF_CH05_OPT_POW", 0xff, "mw", PM_STATUS},
{1, 0x00, 0x00, 1, "FF_CH06_OPT_POW", 0xff, "mw", PM_STATUS},
{1, 0x00, 0x00, 1, "FF_CH07_OPT_POW", 0xff, "mw", PM_STATUS},
{1, 0x00, 0x00, 1, "FF_CH08_OPT_POW", 0xff, "mw", PM_STATUS},
{1, 0x00, 0x00, 1, "FF_CH09_OPT_POW", 0xff, "mw", PM_STATUS},
{1, 0x00, 0x00, 1, "FF_CH10_OPT_POW", 0xff, "mw", PM_STATUS},
{1, 0x00, 0x00, 1, "FF_CH11_OPT_POW", 0xff, "mw", PM_STATUS},
{1, 0x00, 0x00, 1, "FF_CH12_OPT_POW", 0xff, "mw", PM_STATUS},

};
// register maps for OT-DTC Fireflies 12-ch part -- 25Gbps ECUO (no connected devices to test as of 08.04.22)
Expand All @@ -209,7 +224,19 @@ struct sm_command_t sm_command_fflot_f1[] = {
{1, 0x00, 0x16, 2, "FF_TEMPERATURE", 0xff, "C", PM_STATUS},
{2, 0x00, 0x07, 1, "FF_LOS_ALARM", 0xffff, "", PM_STATUS},
{2, 0x00, 0x14, 1, "FF_CDR_LOL_ALARM", 0xffff, "", PM_STATUS},
{2, 0x01, 0xe4, 1, "FF_OPT_POW", 0xff, "mw", PM_STATUS}, // read 12 Rx-ch registers with decreasing addresses
{2, 0x01, 0xe4, 1, "FF_CH01_OPT_POW", 0xff, "mw", PM_STATUS}, // read 12 Rx-ch registers with decreasing addresses
{2, 0x01, 0xe2, 1, "FF_CH02_OPT_POW", 0xff, "mw", PM_STATUS},
{2, 0x01, 0xe0, 1, "FF_CH03_OPT_POW", 0xff, "mw", PM_STATUS},
{2, 0x01, 0xde, 1, "FF_CH04_OPT_POW", 0xff, "mw", PM_STATUS},
{2, 0x01, 0xdc, 1, "FF_CH05_OPT_POW", 0xff, "mw", PM_STATUS},
{2, 0x01, 0xda, 1, "FF_CH06_OPT_POW", 0xff, "mw", PM_STATUS},
{2, 0x01, 0xd8, 1, "FF_CH07_OPT_POW", 0xff, "mw", PM_STATUS},
{2, 0x01, 0xd6, 1, "FF_CH08_OPT_POW", 0xff, "mw", PM_STATUS},
{2, 0x01, 0xd4, 1, "FF_CH09_OPT_POW", 0xff, "mw", PM_STATUS},
{2, 0x01, 0xd2, 1, "FF_CH10_OPT_POW", 0xff, "mw", PM_STATUS},
{2, 0x01, 0xd0, 1, "FF_CH11_OPT_POW", 0xff, "mw", PM_STATUS},
{2, 0x01, 0xce, 1, "FF_CH12_OPT_POW", 0xff, "mw", PM_STATUS},

};

#ifdef REV1
Expand Down Expand Up @@ -238,7 +265,6 @@ struct dev_moni2c_addr_t ffl12_f1_moni2c_addrs[NFIREFLIES_IT_F1] = {
#endif

uint16_t ffl12_f1_values[NSUPPLIES_FFL12_F1 * NCOMMANDS_FFL12_F1];
uint16_t ffl12_f1_optpow_values[NSUPPLIES_FFL12_F1];

struct MonitorI2CTaskArgs_t ffl12_f1_args = {
.name = "FF12",
Expand All @@ -255,8 +281,6 @@ struct MonitorI2CTaskArgs_t ffl12_f1_args = {
.smbus_status = &eStatus4,
.xSem = NULL,
.ffpart_bit_mask = 0U,
.n_rxchs = FF_12_NRXCH,
.opt_pow_values = ffl12_f1_optpow_values,
.present_bit_mask = 0U,
.stack_size = 4096U,
};
Expand Down Expand Up @@ -291,10 +315,12 @@ struct sm_command_t sm_command_ffldaq_f2[] = {
{1, 0x00, 0x16, 2, "FF_TEMPERATURE", 0xff, "C", PM_STATUS},
{1, 0x00, 0x03, 1, "FF_LOS_ALARM", 0xff, "", PM_STATUS},
{1, 0x00, 0x05, 1, "FF_CDR_LOL_ALARM", 0xff, "", PM_STATUS},
{2, 0x00, 0x22, 1, "FF_OPT_POW", 0xff, "mw", PM_STATUS}, // read 4 Rx-ch registers with increasing addresses
{2, 0x00, 0x22, 1, "FF_CH01_OPT_POW", 0xff, "mw", PM_STATUS}, // read 4 Rx-ch registers with increasing addresses
{2, 0x00, 0x24, 1, "FF_CH02_OPT_POW", 0xff, "mw", PM_STATUS},
{2, 0x00, 0x26, 1, "FF_CH03_OPT_POW", 0xff, "mw", PM_STATUS},
{2, 0x00, 0x28, 1, "FF_CH04_OPT_POW", 0xff, "mw", PM_STATUS},
};
uint16_t ffldaq_f2_values[NSUPPLIES_FFLDAQ_F2 * NCOMMANDS_FFLDAQ_F2];
uint16_t ffldaq_f2_optpow_values[NSUPPLIES_FFLDAQ_F2];

struct MonitorI2CTaskArgs_t ffldaq_f2_args = {
.name = "FFDAV",
Expand All @@ -311,8 +337,6 @@ struct MonitorI2CTaskArgs_t ffldaq_f2_args = {
.smbus_status = &eStatus3,
.xSem = NULL,
.ffpart_bit_mask = 0U,
.n_rxchs = FF_DAQ_NRXCH,
.opt_pow_values = ffldaq_f2_optpow_values,
.present_bit_mask = 0U,
.stack_size = 4096U,
};
Expand All @@ -325,7 +349,21 @@ struct sm_command_t sm_command_fflit_f2[] = {
{1, 0x00, 0x16, 2, "FF_TEMPERATURE", 0xff, "C", PM_STATUS},
{2, 0x00, 0x07, 1, "FF_LOS_ALARM", 0xffff, "", PM_STATUS},
{2, 0x00, 0x14, 1, "FF_CDR_LOL_ALARM", 0xffff, "", PM_STATUS},

// there are no registers to read optical power for 14Gbps ECUO.
// registers below are a placeholder with a reading equal to zero
// the reason we need them because n_commands is fixed
{1, 0x00, 0x00, 1, "FF_CH01_OPT_POW", 0xff, "mw", PM_STATUS},
{1, 0x00, 0x00, 1, "FF_CH02_OPT_POW", 0xff, "mw", PM_STATUS},
{1, 0x00, 0x00, 1, "FF_CH03_OPT_POW", 0xff, "mw", PM_STATUS},
{1, 0x00, 0x00, 1, "FF_CH04_OPT_POW", 0xff, "mw", PM_STATUS},
{1, 0x00, 0x00, 1, "FF_CH05_OPT_POW", 0xff, "mw", PM_STATUS},
{1, 0x00, 0x00, 1, "FF_CH06_OPT_POW", 0xff, "mw", PM_STATUS},
{1, 0x00, 0x00, 1, "FF_CH07_OPT_POW", 0xff, "mw", PM_STATUS},
{1, 0x00, 0x00, 1, "FF_CH08_OPT_POW", 0xff, "mw", PM_STATUS},
{1, 0x00, 0x00, 1, "FF_CH09_OPT_POW", 0xff, "mw", PM_STATUS},
{1, 0x00, 0x00, 1, "FF_CH10_OPT_POW", 0xff, "mw", PM_STATUS},
{1, 0x00, 0x00, 1, "FF_CH11_OPT_POW", 0xff, "mw", PM_STATUS},
{1, 0x00, 0x00, 1, "FF_CH12_OPT_POW", 0xff, "mw", PM_STATUS},
};
// register maps for OT-DTC Fireflies 12-ch part -- 25Gbps ECUO (no connected devices to test as of 08.04.22)
// **commands below have not been tested yet**
Expand All @@ -334,7 +372,18 @@ struct sm_command_t sm_command_fflot_f2[] = {
{1, 0x00, 0x16, 2, "FF_TEMPERATURE", 0xff, "C", PM_STATUS},
{2, 0x00, 0x07, 1, "FF_LOS_ALARM", 0xffff, "", PM_STATUS},
{2, 0x00, 0x14, 1, "FF_CDR_LOL_ALARM", 0xffff, "", PM_STATUS},
{2, 0x01, 0xe4, 1, "FF_OPT_POW", 0xff, "mw", PM_STATUS}, // read 12 Rx-ch registers with decreasing addresses
{2, 0x01, 0xe4, 1, "FF_CH01_OPT_POW", 0xff, "mw", PM_STATUS}, // read 12 Rx-ch registers with decreasing addresses
{2, 0x01, 0xe2, 1, "FF_CH02_OPT_POW", 0xff, "mw", PM_STATUS},
{2, 0x01, 0xe0, 1, "FF_CH03_OPT_POW", 0xff, "mw", PM_STATUS},
{2, 0x01, 0xde, 1, "FF_CH04_OPT_POW", 0xff, "mw", PM_STATUS},
{2, 0x01, 0xdc, 1, "FF_CH05_OPT_POW", 0xff, "mw", PM_STATUS},
{2, 0x01, 0xda, 1, "FF_CH06_OPT_POW", 0xff, "mw", PM_STATUS},
{2, 0x01, 0xd8, 1, "FF_CH07_OPT_POW", 0xff, "mw", PM_STATUS},
{2, 0x01, 0xd6, 1, "FF_CH08_OPT_POW", 0xff, "mw", PM_STATUS},
{2, 0x01, 0xd4, 1, "FF_CH09_OPT_POW", 0xff, "mw", PM_STATUS},
{2, 0x01, 0xd2, 1, "FF_CH10_OPT_POW", 0xff, "mw", PM_STATUS},
{2, 0x01, 0xd0, 1, "FF_CH11_OPT_POW", 0xff, "mw", PM_STATUS},
{2, 0x01, 0xce, 1, "FF_CH12_OPT_POW", 0xff, "mw", PM_STATUS},
};

#ifdef REV1
Expand All @@ -358,7 +407,6 @@ struct dev_moni2c_addr_t ffl12_f2_moni2c_addrs[NFIREFLIES_IT_F2] = {
#endif

uint16_t ffl12_f2_values[NSUPPLIES_FFL12_F2 * NCOMMANDS_FFL12_F2];
uint16_t ffl12_f2_optpow_values[NSUPPLIES_FFL12_F2];

struct MonitorI2CTaskArgs_t ffl12_f2_args = {
.name = "FF12V",
Expand All @@ -375,8 +423,6 @@ struct MonitorI2CTaskArgs_t ffl12_f2_args = {
.smbus_status = &eStatus3,
.xSem = NULL,
.ffpart_bit_mask = 0U,
.n_rxchs = FF_12_NRXCH,
.opt_pow_values = ffl12_f2_optpow_values,
.present_bit_mask = 0U,
.stack_size = 4096U,
};
Expand Down Expand Up @@ -670,28 +716,45 @@ uint16_t getFFtemp(const uint8_t i)

uint16_t getFFoptpow(const uint8_t i)
{
uint16_t val;

uint16_t avg_val;
uint16_t sum_val;
configASSERT(i < NFIREFLIES);
if (i < NFIREFLIES_IT_F1) {
int index = i;
val = ffl12_f1_args.opt_pow_values[index];
for (int i1 = 4; i1 < ffl12_f1_args.n_commands; ++i1) {
int dev = i - ff_moni2c_arg[0].int_idx + ff_moni2c_arg[0].dev_int_idx;
int index = dev * (ffl12_f1_args.n_commands * ffl12_f1_args.n_pages) + i1;
sum_val += ffl12_f1_args.sm_values[index];
}
avg_val = sum_val/(ffl12_f1_args.n_commands-4);
}

else if (NFIREFLIES_IT_F1 <= i && i < NFIREFLIES_IT_F1 + NFIREFLIES_DAQ_F1) {
int index = i - NFIREFLIES_IT_F1;
val = ffldaq_f1_args.opt_pow_values[index];
for (int i1 = 4; i1 < ffldaq_f1_args.n_commands; ++i1) {
int dev = i - ff_moni2c_arg[1].int_idx + ff_moni2c_arg[1].dev_int_idx;
int index = (dev) * (ffldaq_f1_args.n_commands * ffldaq_f1_args.n_pages) + i1;
sum_val += ffldaq_f1_args.sm_values[index];
}
avg_val = sum_val/(ffldaq_f1_args.n_commands-4);
}

else if (NFIREFLIES_F1 <= i && i < NFIREFLIES_F1 + NFIREFLIES_IT_F2) {
int index = i - NFIREFLIES_F1;
val = ffl12_f2_args.opt_pow_values[index];
for (int i1 = 4; i1 < ffl12_f2_args.n_commands; ++i1) {
int dev = i - ff_moni2c_arg[2].int_idx + ff_moni2c_arg[2].dev_int_idx;
int index = (dev) * (ffl12_f2_args.n_commands * ffl12_f2_args.n_pages) + i1;
sum_val += ffl12_f2_args.sm_values[index];
}
avg_val = sum_val/(ffl12_f2_args.n_commands-4);
}
else {
int index = i - NFIREFLIES_F1 - NFIREFLIES_IT_F2;
val = ffldaq_f2_args.opt_pow_values[index];
for (int i1 = 4; i1 < ffldaq_f2_args.n_commands; ++i1) {
int dev = i - ff_moni2c_arg[3].int_idx + ff_moni2c_arg[3].dev_int_idx;
int index = (dev) * (ffldaq_f2_args.n_commands * ffldaq_f2_args.n_pages) + i1;
sum_val += ffldaq_f2_args.sm_values[index];
}
avg_val = sum_val/(ffldaq_f2_args.n_commands-4);
}

return val;
return avg_val;
}

uint16_t getFFpresentbit(const uint8_t i)
Expand Down
44 changes: 1 addition & 43 deletions projects/cm_mcu/MonitorI2CTask.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ void MonitorI2CTask(void *parameters)

// Read I2C registers/commands
for (int c = 0; c < args->n_commands; ++c) {

int index = ps * (args->n_commands * args->n_pages) + c;

log_debug(LOG_MONI2C, "%s: command %s.\r\n", args->name, args->commands[c].name);
Expand Down Expand Up @@ -205,49 +206,6 @@ void MonitorI2CTask(void *parameters)

} // loop over commands

#ifdef REV2
// get optical power information from 25Gbs FFs
bool has_opt_pow = false;
if (IsFFDAQ)
has_opt_pow = true;
if (IsFF12 && (ps % 2 == 1))
has_opt_pow = 0x1U & (args->ffpart_bit_mask >> (int)ps / 2);

if (has_opt_pow) {
uint16_t opt_pow_values = 0x0U;
uint8_t page_reg_value = args->commands[FF_OPT_POW_C].page;
int r = apollo_i2c_ctl_reg_w(args->i2c_dev, args->devices[ps].dev_addr, 1, args->selpage_reg, 1, page_reg_value);
if (r != 0) {
log_error(LOG_MONI2C, "%s : page fail %s\r\n", args->devices[ps].name, SMBUS_get_error(r));
break;
}

for (int ch = 0; ch < args->n_rxchs; ++ch) {
uint32_t output_raw;
uint16_t opt_pw_command;
if (IsFFDAQ) {
opt_pw_command = args->commands[FF_OPT_POW_C].command + 2 * ch;
}
else {
opt_pw_command = args->commands[FF_OPT_POW_C].command - 2 * ch;
}
int res = apollo_i2c_ctl_reg_r(args->i2c_dev, args->devices[ps].dev_addr, args->commands[FF_OPT_POW_C].reg_size,
opt_pw_command, args->commands[FF_OPT_POW_C].size, &output_raw);

if (res != 0) {
log_error(LOG_MONI2C, "%s: %s read Error %s, break (ps=%d)\r\n", args->name, args->commands[FF_OPT_POW_C].name, SMBUS_get_error(res), ps);
opt_pow_values = 0xff;
break;
}
else {
opt_pow_values += output_raw;
}
}
opt_pow_values = opt_pow_values / args->n_rxchs;
args->opt_pow_values[ps] = opt_pow_values;
}

#endif // REV2
log_debug(LOG_MONI2C, "%s: end loop commands\r\n", args->name);
args->updateTick = xTaskGetTickCount(); // current time in ticks

Expand Down
14 changes: 4 additions & 10 deletions projects/cm_mcu/MonitorI2CTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,48 +43,42 @@ struct MonitorI2CTaskArgs_t {
SemaphoreHandle_t xSem; // semaphore for controlling access to device
uint8_t ffpart_bit_mask; // this mask is only used for detecting 12-ch 25Gbps on the REV2 board
uint32_t present_bit_mask; // this mask is used for all ffs to detect if it is mounted or not
const uint8_t n_rxchs; // the number of optical receiver channels
uint16_t *opt_pow_values; // optical power measurements from 4/12ch FFs with 25Gbs
UBaseType_t stack_size; // stack size of task
};

#define FF_SELPAGE_REG 0x7f
#define CLK_SELPAGE_REG 0x1

#define FF_OPT_POW_C 4 // the order of optical power command in sm_command array
#define FF_DAQ_NRXCH 4
#define FF_12_NRXCH 12

#ifndef REV2
#define NSUPPLIES_FFLDAQ_F1 (3)
#else // REV2
#define NSUPPLIES_FFLDAQ_F1 (4)
#endif // REV 2
#define NCOMMANDS_FFLDAQ_F1 4 // number of commands
#define NCOMMANDS_FFLDAQ_F1 8 // number of commands
#define NPAGES_FFLDAQ_F1 1 // number of pages on the 4-channel firefly ports

#ifndef REV2
#define NSUPPLIES_FFL12_F1 (8)
#else // REV1
#define NSUPPLIES_FFL12_F1 (6)
#endif // REV 2
#define NCOMMANDS_FFL12_F1 4 // number of commands
#define NCOMMANDS_FFL12_F1 16 // number of commands
#define NPAGES_FFL12_F1 1 // number of pages on the 12-channel firefly ports

#ifndef REV2
#define NSUPPLIES_FFLDAQ_F2 (10)
#else // REV1
#define NSUPPLIES_FFLDAQ_F2 (4)
#endif // REV 2
#define NCOMMANDS_FFLDAQ_F2 4 // number of commands
#define NCOMMANDS_FFLDAQ_F2 8 // number of commands
#define NPAGES_FFLDAQ_F2 1 // number of pages on the 4-channel firefly ports

#ifndef REV2
#define NSUPPLIES_FFL12_F2 (4)
#else // REV1
#define NSUPPLIES_FFL12_F2 (6)
#endif // REV 2
#define NCOMMANDS_FFL12_F2 4 // number of commands
#define NCOMMANDS_FFL12_F2 16 // number of commands
#define NPAGES_FFL12_F2 1 // number of pages on the 12-channel firefly ports

extern struct dev_moni2c_addr_t ffl12_f1_moni2c_addrs[NFIREFLIES_IT_F1];
Expand Down
Loading

0 comments on commit 56b3340

Please sign in to comment.