Skip to content

Commit

Permalink
Read Loss of Signal and CDR Loss of Lock Alarms (#93)
Browse files Browse the repository at this point in the history
* read serial num

* pushed all my work for reading alarms

* fix error

* allow reading alarm info

* fixed some errors with integers

* why does it crash mcu?

* debugging stuff

* can read out alarms

* rmv some comments

* .

* fix comment

* Update FireFlyTask.c

fix formatting (remove tabs, update brace positions) to follow clang-format rules

* Update FireFlyTask.c

fix bug I introduced

* address review

* quick change

* reduce for loop

Co-authored-by: Fatima Yousef <[email protected]>
Co-authored-by: Peter Wittich <[email protected]>
  • Loading branch information
3 people authored Apr 26, 2021
1 parent 88a9a94 commit d97fd98
Show file tree
Hide file tree
Showing 5 changed files with 280 additions and 4 deletions.
12 changes: 12 additions & 0 deletions projects/cm_mcu/CommandLineTask.c
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,18 @@ static struct command_t commands[] = {
"ff_status\r\n Displays a table showing the status of the fireflies.\r\n",
0,
},
{
"ff_los",
ff_los_alarm,
"ff_los_alarm\r\n Displays a table showing the loss of signal alarms of the fireflies.\r\n",
0,
},
{
"ff_cdr_lol",
ff_cdr_lol_alarm,
"ff_cd_lol_alarm\r\n Displays a table showing the CDR loss of lock alarms of the fireflies.\r\n",
0,
},
{
"zmon",
zmon_ctl,
Expand Down
173 changes: 172 additions & 1 deletion projects/cm_mcu/FireFlyTask.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,23 @@ void get_smbus_vars(int ff, tSMBus **smbus, tSMBusStatus **status)
// is a bit weird -- 0-3 on byte 4a, 4-11 on byte 4b
#define ECU0_25G_TXRX_CDR_REG 0x4A

#define ECU0_25G_XCVR_LOS_ALARM_REG 0x3
#define ECU0_25G_XCVR_CDR_LOL_ALARM_REG 0x5

#define ECU0_25G_TX_LOS_ALARM_REG_1 0x7
#define ECU0_25G_TX_LOS_ALARM_REG_2 0x8
#define ECU0_25G_CDR_LOL_ALARM_REG_1 0x14
#define ECU0_25G_CDR_LOL_ALARM_REG_2 0x15

static TickType_t ff_updateTick;

struct firefly_status {
int8_t status;
int8_t temp;
uint8_t los_alarm[2];
uint8_t cdr_lol_alarm[2];
#ifdef DEBUG_FIF
int8_t serial_num[16];
int8_t test[20]; // Used for reading "Samtec Inc. " for testing purposes
#endif
};
Expand Down Expand Up @@ -198,6 +208,53 @@ int8_t getFFtemp(const uint8_t i)
return ff_status[i].temp;
}

#ifdef DEBUG
int8_t* getFFserialnum(const uint8_t i){
configASSERT(i < NFIREFLIES);
return ff_status[i].serial_num;
}
#endif

bool getFFlos(int i, int channel)
{
configASSERT(i < NFIREFLIES);
configASSERT(channel < 12);
uint8_t *los_alarms = ff_status[i].los_alarm;

if (channel >= 8) {
if (!((1 << (channel - 8)) & los_alarms[1])) {
return false;
}
return true;
}
else {
if (!((1 << channel) & los_alarms[0])) {
return false;
}
return true;
}
}

bool getFFlol(int i, int channel)
{
configASSERT(i < NFIREFLIES);
configASSERT(channel < 12);
uint8_t *cdr_lol_alarms = ff_status[i].cdr_lol_alarm;

if (strstr(ff_i2c_addrs[i].name, "XCVR") == NULL && channel >= 8) {
if (!((1 << (channel - 8)) & cdr_lol_alarms[1])) {
return false;
}
return true;
}
else {
if (!((1 << channel) & cdr_lol_alarms[0])) {
return false;
}
return true;
}
}

#ifdef DEBUG_FIF
int8_t* test_read(const uint8_t i) {
configASSERT(i < NFIREFLIES);
Expand All @@ -210,7 +267,7 @@ TickType_t getFFupdateTick()
return ff_updateTick;
}

static bool isEnabledFF(int ff)
bool isEnabledFF(int ff)
{
// firefly config stored in on-board EEPROM
static bool configured = false;
Expand Down Expand Up @@ -469,6 +526,15 @@ void FireFlyTask(void *parameters)
#endif // DEBUG_FIF
ff_status[i].temp = -55;
ff_status[i].status = 1;
#ifdef DEBUG
for (int j = 0; j<16; j++){
ff_status[i].serial_num[j] = 0;
}
#endif
for (int channel=0; channel<2; channel++) {
ff_status[i].los_alarm[channel] = 255;
ff_status[i].cdr_lol_alarm[channel] = 255;
}
}
vTaskDelayUntil(&ff_updateTick, pdMS_TO_TICKS(2500));

Expand Down Expand Up @@ -702,6 +768,111 @@ void FireFlyTask(void *parameters)
tmp2.us = data[0]; // change from uint_8 to int8_t, preserving bit pattern
ff_status[ff].status = tmp2.s;

// Read the serial number
#ifdef DEBUG
data[0] = 0x0U;
data[1] = 0x0U;
for (uint8_t i = 189; i < 205; i++) {// change from 171-185 to 189-198 or 189-204 or 196-211
r = SMBusMasterI2CWriteRead(smbus, ff_i2c_addrs[ff].dev_addr, &i, 1, data, 1);

if (r != SMBUS_OK) {
snprintf(tmp, 64, "FIF: %s: SMBUS failed (master/bus busy, ps=%d,c=%d)\r\n", __func__, ff,
2);
DPRINT(tmp);
continue; // abort reading this register
}
while (SMBusStatusGet(smbus) == SMBUS_TRANSFER_IN_PROGRESS) {
vTaskDelayUntil(&ff_updateTick, pdMS_TO_TICKS(10)); // wait
}
if (*p_status != SMBUS_OK) {
snprintf(tmp, 64, "FIF: %s: Error %d, break loop (ps=%d,c=%d) ...\r\n", __func__,
*p_status, ff, 2);
DPRINT(tmp);
ff_status[ff].serial_num[i - 196] = 3;
break;
}
convert_8_t tmp5;
tmp5.us = data[0]; // change from uint_8 to int8_t, preserving bit pattern
ff_status[ff].serial_num[i - 196] = tmp5.s;
}
#endif

// Check the loss of signal alarm
int los_regs[2];
if (strstr(ff_i2c_addrs[ff].name, "XCVR") == NULL) {
los_regs[0] = ECU0_25G_TX_LOS_ALARM_REG_2;
los_regs[1] = ECU0_25G_TX_LOS_ALARM_REG_1;
}
else{
los_regs[0] = ECU0_25G_XCVR_LOS_ALARM_REG;
los_regs[1] = 0;
}

int reg_i=0;
while(reg_i<2 && los_regs[reg_i] != 0){
data[0] = 0x0U;
data[1] = 0x0U;
reg_addr = los_regs[reg_i];

r = SMBusMasterI2CWriteRead(smbus, ff_i2c_addrs[ff].dev_addr, &reg_addr, 1, data, 1);
if (r != SMBUS_OK) {
snprintf(tmp, 64, "FIF: %s: SMBUS failed (master/bus busy, ps=%d,c=%d)\r\n", __func__, ff,
2);
DPRINT(tmp);
continue; // abort reading this register
}
while (SMBusStatusGet(smbus) == SMBUS_TRANSFER_IN_PROGRESS) {
vTaskDelayUntil(&ff_updateTick, pdMS_TO_TICKS(10)); // wait
}
if (*p_status != SMBUS_OK) {
snprintf(tmp, 64, "FIF: %s: Error %d, break loop (ps=%d,c=%d) ...\r\n", __func__,
*p_status, ff, 2);
DPRINT(tmp);
ff_status[ff].los_alarm[reg_i] = 255;
break;
}
ff_status[ff].los_alarm[reg_i] = data[0];
reg_i+=1;
}

// Check the CDR loss of lock alarm
int cdr_lol_regs[2];
if (strstr(ff_i2c_addrs[ff].name, "XCVR") == NULL) {
cdr_lol_regs[0] = ECU0_25G_CDR_LOL_ALARM_REG_2;
cdr_lol_regs[1] = ECU0_25G_CDR_LOL_ALARM_REG_1;
}
else{
cdr_lol_regs[0] = ECU0_25G_XCVR_CDR_LOL_ALARM_REG;
cdr_lol_regs[1] = 0;
}

reg_i=0;
while(reg_i<2 && cdr_lol_regs[reg_i] != 0){
data[0] = 0x0U;
data[1] = 0x0U;
reg_addr = cdr_lol_regs[reg_i];

r = SMBusMasterI2CWriteRead(smbus, ff_i2c_addrs[ff].dev_addr, &reg_addr, 1, data, 1);
if (r != SMBUS_OK) {
snprintf(tmp, 64, "FIF: %s: SMBUS failed (master/bus busy, ps=%d,c=%d)\r\n", __func__, ff,
2);
DPRINT(tmp);
continue; // abort reading this register
}
while (SMBusStatusGet(smbus) == SMBUS_TRANSFER_IN_PROGRESS) {
vTaskDelayUntil(&ff_updateTick, pdMS_TO_TICKS(10)); // wait
}
if (*p_status != SMBUS_OK) {
snprintf(tmp, 64, "FIF: %s: Error %d, break loop (ps=%d,c=%d) ...\r\n", __func__,
*p_status, ff, 2);
DPRINT(tmp);
ff_status[ff].cdr_lol_alarm[reg_i] = 255;
break;
}
ff_status[ff].cdr_lol_alarm[reg_i] = data[0];
reg_i+=1;
}

#ifdef DEBUG_FIF
// Read the Samtec line - testing only
data[0] = 0x0U;
Expand Down
3 changes: 3 additions & 0 deletions projects/cm_mcu/Tasks.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,11 @@ extern QueueHandle_t xFFlyQueueOut;

const char *getFFname(const uint8_t i);
int8_t *test_read(const uint8_t i);
bool isEnabledFF(int ff);
int8_t getFFtemp(const uint8_t i);
int8_t getFFstatus(const uint8_t i);
bool getFFlos(int i, int channel);
bool getFFlol(int i, int channel);
TickType_t getFFupdateTick();

int disable_xcvr_cdr(const char *name);
Expand Down
94 changes: 91 additions & 3 deletions projects/cm_mcu/commands/SensorControl.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,14 +332,13 @@ BaseType_t ff_ctl(int argc, char **argv, char* m)
}
// parse command based on how many arguments it has
if (argc == 1) { // default command: temps
uint32_t ff_config = read_eeprom_single(EEPROM_ID_FF_ADDR);
if (whichff == 0) {
copied += snprintf(m + copied, SCRATCH_SIZE - copied, "FF temperatures\r\n");
}
for (; whichff < NFIREFLIES; ++whichff) {
int8_t val = getFFtemp(whichff);
const char *name = getFFname(whichff);
if ((1 << whichff) & ff_config) // val > 0 )
if (isEnabledFF(whichff)) // val > 0 )
copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%17s: %2d", name, val);
else // dummy value
copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%17s: %2s", name, "--");
Expand Down Expand Up @@ -508,7 +507,96 @@ BaseType_t ff_status(int argc, char **argv, char* m)
for (; whichff < 25; ++whichff) {
int8_t status = getFFstatus(whichff);
const char *name = getFFname(whichff);
copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%s %02d", name, status);
copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%s %02d ", name, status);

bool isTx = (strstr(name, "Tx") != NULL);
if (isTx)
copied += snprintf(m + copied, SCRATCH_SIZE - copied, "\t");
else
copied += snprintf(m + copied, SCRATCH_SIZE - copied, "\r\n");

if ((SCRATCH_SIZE - copied) < 20 && (whichff < 25)) {
++whichff;
return pdTRUE;
}
}
whichff = 0;
return pdFALSE;
}

BaseType_t ff_los_alarm(int argc, char **argv, char* m) {
int copied = 0;

static int whichff = 0;
if (whichff == 0) {
copied += snprintf(m + copied, SCRATCH_SIZE - copied, "FIREFLY LOS ALARM:\r\n");
}
for (; whichff < 25; ++whichff) {
const char *name = getFFname(whichff);
copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%s ", name);
if (!isEnabledFF(whichff)){
copied+=snprintf(m + copied, SCRATCH_SIZE - copied, "------------");
}
else{
for (size_t i = 0; i<8; i++) {
int alarm = getFFlos(whichff, i)? 1:0;
copied+=snprintf(m + copied, SCRATCH_SIZE - copied, "%d", alarm);
}
if (strstr(name, "XCVR") == NULL) {
for (size_t i = 8; i<12; i++) {
int alarm = getFFlos(whichff, i)? 1:0;
copied+=snprintf(m + copied, SCRATCH_SIZE - copied, "%d", alarm);
}
}
else{
copied+=snprintf(m + copied, SCRATCH_SIZE - copied, " ");
}

}

bool isTx = (strstr(name, "Tx") != NULL);
if (isTx)
copied += snprintf(m + copied, SCRATCH_SIZE - copied, "\t");
else
copied += snprintf(m + copied, SCRATCH_SIZE - copied, "\r\n");

if ((SCRATCH_SIZE - copied) < 20 && (whichff < 25)) {
++whichff;
return pdTRUE;
}
}
whichff = 0;
return pdFALSE;
}

BaseType_t ff_cdr_lol_alarm(int argc, char **argv, char* m) {
int copied = 0;

static int whichff = 0;
if (whichff == 0) {
copied += snprintf(m + copied, SCRATCH_SIZE - copied, "FIREFLY CDR LOL ALARM:\r\n");
}
for (; whichff < 25; ++whichff) {
const char *name = getFFname(whichff);
copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%s ", name);
if (!isEnabledFF(whichff)){
copied+=snprintf(m + copied, SCRATCH_SIZE - copied, "------------");
}
else{
for (size_t i = 0; i<8; i++) {
int alarm = getFFlol(whichff, i)? 1:0;
copied+=snprintf(m + copied, SCRATCH_SIZE - copied, "%d", alarm);
}
if (strstr(name, "XCVR") == NULL) {
for (size_t i = 8; i<12; i++) {
int alarm = getFFlol(whichff, i)? 1:0;
copied+=snprintf(m + copied, SCRATCH_SIZE - copied, "%d", alarm);
}
}
else{
copied+=snprintf(m + copied, SCRATCH_SIZE - copied, " ");
}
}

bool isTx = (strstr(name, "Tx") != NULL);
if (isTx)
Expand Down
2 changes: 2 additions & 0 deletions projects/cm_mcu/commands/SensorControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ BaseType_t adc_ctl(int argc, char **argv, char* m);
// Fireflies
BaseType_t ff_ctl(int argc, char **argv, char* m);
BaseType_t ff_status(int argc, char **argv, char* m);
BaseType_t ff_los_alarm(int argc, char **argv, char* m);
BaseType_t ff_cdr_lol_alarm(int argc, char **argv, char* m);

// FPGA
BaseType_t fpga_ctl(int argc, char **argv, char* m);
Expand Down

0 comments on commit d97fd98

Please sign in to comment.