From 1777a3466463fd0d3d92390afb9443d6f4c259d2 Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Tue, 9 Apr 2024 10:37:08 -0400 Subject: [PATCH 01/71] Update ZynqMonTask.c minor text updates --- projects/cm_mcu/ZynqMonTask.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/projects/cm_mcu/ZynqMonTask.c b/projects/cm_mcu/ZynqMonTask.c index 361021eb..2e92553e 100644 --- a/projects/cm_mcu/ZynqMonTask.c +++ b/projects/cm_mcu/ZynqMonTask.c @@ -14,18 +14,11 @@ #include // to be moved -#include "driverlib/sysctl.h" -#include "driverlib/timer.h" -#include "driverlib/gpio.h" #include "inc/hw_memmap.h" -#include "inc/hw_ints.h" #include "driverlib/rom.h" -#include "driverlib/rom_map.h" #ifdef REV1 #include "common/softuart.h" -#elif defined(REV2) -#include "driverlib/uart.h" #endif #include "Tasks.h" @@ -38,7 +31,7 @@ #include "ZynqMon_addresses.h" // Rev 2 -// this needs to be split into a SoftUART version (Rev1) and a hard UART version (Rev2) +// this was split into a SoftUART version (Rev1) and a hard UART version (Rev2) #define SZ 20 @@ -292,7 +285,7 @@ void zm_set_firefly_temps(struct zynqmon_data_t data[], int start) for (uint8_t i = 0; i < NFIREFLIES; i++) { data[i].sensor = i + start; // sensor id if (!isFFStale()) { - data[i].data.i = getFFtemp(i); // sensor value and type + data[i].data.us = getFFtemp(i); // sensor value and type } else { data[i].data.i = -56; // special stale value @@ -302,7 +295,7 @@ void zm_set_firefly_temps(struct zynqmon_data_t data[], int start) } #ifdef REV2 -uint16_t getFFtXdisenablebit(const uint8_t i) +uint16_t getFFtXdisablebit(const uint8_t i) { return 56; // FIXME #ifdef NOTDEF @@ -442,8 +435,8 @@ void zm_set_firefly_info(struct zynqmon_data_t data[], int start) data[ll].data.us = 0xff; // special stale value } else { - data[ll].data.us = getFFtXdisenablebit(j); // sensor value and type - log_debug(LOG_SERVICE, "TX-disenabled? for ff argv %d: 0x%02x\r\n", j, getFFtXdisenablebit(j)); + data[ll].data.us = getFFtXdisablebit(j); // sensor value and type + log_debug(LOG_SERVICE, "TX-disabled? for ff argv %d: 0x%02x\r\n", j, data[ll].data.us); } data[ll].sensor = ll + start; ++ll; From ac64b8d44d8c531bc0057065f701d35dbfaa0063 Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Thu, 11 Apr 2024 15:49:51 -0400 Subject: [PATCH 02/71] start breaking up LocalTasks.c --- projects/cm_mcu/AlarmUtilities.c | 1 + projects/cm_mcu/FireflyUtils.c | 393 +++++++++++++++++++++++++++++++ projects/cm_mcu/FireflyUtils.h | 90 +++++++ projects/cm_mcu/I2CSlaveTask.c | 1 + projects/cm_mcu/LocalTasks.c | 85 ++----- projects/cm_mcu/Makefile | 1 + projects/cm_mcu/MonitorI2CTask.c | 32 +-- projects/cm_mcu/MonitorI2CTask.h | 4 + projects/cm_mcu/Tasks.h | 90 +------ 9 files changed, 541 insertions(+), 156 deletions(-) create mode 100644 projects/cm_mcu/FireflyUtils.c create mode 100644 projects/cm_mcu/FireflyUtils.h diff --git a/projects/cm_mcu/AlarmUtilities.c b/projects/cm_mcu/AlarmUtilities.c index 56eebf29..7cd4786d 100644 --- a/projects/cm_mcu/AlarmUtilities.c +++ b/projects/cm_mcu/AlarmUtilities.c @@ -1,6 +1,7 @@ #include "AlarmUtilities.h" #include "Tasks.h" #include "MonitorTask.h" +#include "FireflyUtils.h" #include "common/log.h" #include "common/pinsel.h" diff --git a/projects/cm_mcu/FireflyUtils.c b/projects/cm_mcu/FireflyUtils.c new file mode 100644 index 00000000..93669e8b --- /dev/null +++ b/projects/cm_mcu/FireflyUtils.c @@ -0,0 +1,393 @@ +/** + * @file FileflyUtils.c + * @brief Utilities to access and control SamTec Firefly devices. + * + * This file contains utility functions and definitions for interacting with + * SamTec Firefly devices. + + * @author Peter Wittich + * @date September 20, 2022 + */ +#include +#include +#include // memset + +#include "common/log.h" + +#include "Semaphore.h" +#include "I2CCommunication.h" +#include "MonitorI2CTask.h" +#include "common/smbus_helper.h" +#include "FireflyUtils.h" + +uint32_t ff_PRESENT_mask = 0; // global variable from getting combined ff signals +uint32_t ff_USER_mask = 0; // global variable of ff signals from user input +#ifdef REV2 +uint32_t f1_ff12xmit_4v0_sel = 0; // global variable for FPGA1 12-ch xmit ff's power-supply physical selection +uint32_t f2_ff12xmit_4v0_sel = 0; // global variable for FPGA2 12-ch xmit ff's power-supply physical selection + +struct ff_bit_mask_t ff_bitmask_args[] = { + {0U, 0U}, // {3, 6} bits correspond to ffl12_f1 devices + {0U, 0U}, // {0, 4} and bits correspond to ffldaq_f1 devices + {0U, 0U}, // {3, 6} bits correspond to ffl12_f2 devices + {0U, 0U}, // {0, 4} bits correspond to ffldaq_f2 devices +}; + +#endif +// outputs from *_PRESENT pins for constructing ff_PRESENT_mask +#ifdef REV1 +// 4.05 I2C KU15P OPTICS +uint32_t present_FFLDAQ_F1, present_FFL12_F1, + // 4.06 I2C VU7P OPTICS (the I/O expanders at 0x20 and 0x21 have mixed 4-ch (FFLDAQ) and 12-ch (FFL12) pins) + present_0X20_F2, present_0X21_F2, present_FFLDAQ_0X20_F2, present_FFL12_0X20_F2, + present_FFLDAQ_0X21_F2, present_FFL12_0X21_F2 = 0; +#elif defined(REV2) +// 4.05 I2C FPGA31 OPTICS +uint32_t present_FFLDAQ_F1, present_FFL12_F1, + // 4.06 I2C FPGA2 OPTICS + present_FFLDAQ_F2, present_FFL12_F2 = 0; +#endif // REV2 + +void setFFmask(uint32_t ff_combined_present) +{ + + log_info(LOG_SERVICE, "Setting a bit mask of enabled Fireflys to 1 \r\n"); + + // int32_t data = (~ff_combined_present) & 0xFFFFFU; // the bit value for an FF mask is an inverted bit value of the PRESENT signals +#ifdef REV1 + uint32_t data = (~ff_combined_present) & 0x1FFFFFFU; +#elif defined(REV2) + uint32_t data = (~ff_combined_present) & 0xFFFFFU; +#endif // REV1 + ff_USER_mask = read_eeprom_single(EEPROM_ID_FF_ADDR); + ff_PRESENT_mask = data; + uint64_t block = EEPROMBlockFromAddr(ADDR_FF); + + uint64_t unlock = EPRMMessage((uint64_t)EPRM_UNLOCK_BLOCK, block, PASS); + xQueueSendToBack(xEPRMQueue_in, &unlock, portMAX_DELAY); + + uint64_t message = EPRMMessage((uint64_t)EPRM_WRITE_SINGLE, ADDR_FF, data); + xQueueSendToBack(xEPRMQueue_in, &message, portMAX_DELAY); + + uint64_t lock = EPRMMessage((uint64_t)EPRM_LOCK_BLOCK, block << 32, 0); + xQueueSendToBack(xEPRMQueue_in, &lock, portMAX_DELAY); + + return; +} + +void readFFpresent(void) +{ + // grab the semaphore to ensure unique access to I2C controller + // otherwise, block its operations indefinitely until it's available + acquireI2CSemaphoreBlock(i2c4_sem); + +#ifdef REV1 + // to port 7 + apollo_i2c_ctl_w(4, 0x70, 1, 0x80); + apollo_i2c_ctl_reg_r(4, 0x20, 1, 0x01, 1, &present_FFL12_F1); + // to port 6 + apollo_i2c_ctl_w(4, 0x71, 1, 0x40); + apollo_i2c_ctl_reg_r(4, 0x21, 1, 0x00, 1, &present_FFLDAQ_F1); +#elif defined(REV2) + // to port 7 + apollo_i2c_ctl_w(4, 0x70, 1, 0x80); + apollo_i2c_ctl_reg_r(4, 0x20, 1, 0x01, 1, &present_FFL12_F1); + // to port 6 + apollo_i2c_ctl_w(4, 0x71, 1, 0x40); + apollo_i2c_ctl_reg_r(4, 0x21, 1, 0x00, 1, &present_FFLDAQ_F1); + apollo_i2c_ctl_reg_r(4, 0x21, 1, 0x01, 1, &f1_ff12xmit_4v0_sel); // reading FPGA1 12-ch xmit FF's power-supply physical selection (i.e either 3.3v or 4.0v) +#endif + + // if we have a semaphore, give it + if (xSemaphoreGetMutexHolder(i2c4_sem) == xTaskGetCurrentTaskHandle()) { + xSemaphoreGive(i2c4_sem); + } + + // grab the semaphore to ensure unique access to I2C controller + // otherwise, block its operations indefinitely until it's available + acquireI2CSemaphoreBlock(i2c3_sem); + +#ifdef REV1 + // to port 0 + apollo_i2c_ctl_w(3, 0x72, 1, 0x01); + apollo_i2c_ctl_reg_r(3, 0x20, 1, 0x01, 1, &present_0X20_F2); + // to port 1 + apollo_i2c_ctl_w(3, 0x72, 1, 0x02); + apollo_i2c_ctl_reg_r(3, 0x21, 1, 0x01, 1, &present_0X21_F2); +#elif defined(REV2) + // to port 7 + apollo_i2c_ctl_w(3, 0x70, 1, 0x80); + apollo_i2c_ctl_reg_r(3, 0x20, 1, 0x01, 1, &present_FFL12_F2); + // to port 6 + apollo_i2c_ctl_w(3, 0x71, 1, 0x40); + apollo_i2c_ctl_reg_r(3, 0x21, 1, 0x00, 1, &present_FFLDAQ_F2); + apollo_i2c_ctl_reg_r(3, 0x21, 1, 0x01, 1, &f2_ff12xmit_4v0_sel); // reading FPGA2 12-ch xmit FF's power-supply physical selection (i.e either 3.3v or 4.0v) + +#endif + // if we have a semaphore, give it + if (xSemaphoreGetMutexHolder(i2c3_sem) == xTaskGetCurrentTaskHandle()) { + xSemaphoreGive(i2c3_sem); + } + +#ifdef REV1 + uint32_t present_FFL12_BOTTOM_F1 = present_FFL12_F1 & 0x3FU; // bottom 6 bits + uint32_t present_FFL12_TOP_F1 = (present_FFL12_F1 >> 6) & 0x3U; // top 2 bits + present_FFLDAQ_F1 = (present_FFLDAQ_F1 >> 5) & 0x7U; // bits 5-7 + present_FFL12_0X20_F2 = (present_0X20_F2 >> 6) & 0x3U; // bit 6-7 + present_FFLDAQ_0X20_F2 = present_0X20_F2 & 0x3FU; // bottom 6 bits + present_FFL12_0X21_F2 = (present_0X21_F2 >> 4) & 0x3U; // bit 4-5 + present_FFLDAQ_0X21_F2 = (present_0X21_F2 >> 2) & 0xFU; // bit 4 bits + + uint32_t ff_combined_present = ((present_FFL12_0X21_F2) << 23) | // 2 bits + ((present_FFL12_0X20_F2) << 21) | // 2 bits + ((present_FFLDAQ_0X21_F2) << 17) | // 4 bits + ((present_FFLDAQ_0X20_F2) << 11) | // 6 bits + ((present_FFL12_TOP_F1) << 9) | // 2 bits + (present_FFLDAQ_F1) << 6 | // 3 bits + ((present_FFL12_BOTTOM_F1)); // 6 bits + +#elif defined(REV2) + present_FFL12_F1 = present_FFL12_F1 & 0x3FU; // bottom 6 bits + present_FFL12_F2 = present_FFL12_F2 & 0x3FU; // bottom 6 bits + present_FFLDAQ_F1 = (present_FFLDAQ_F1 >> 4) & 0xFU; // bits 4-7 + present_FFLDAQ_F2 = (present_FFLDAQ_F2 >> 4) & 0xFU; // bits 4-7 + + uint32_t ff_combined_present = ((present_FFLDAQ_F2) << 16) | // 4 bits + ((present_FFL12_F2) << 10) | // 6 bits + (present_FFLDAQ_F1) << 6 | // 4 bits + ((present_FFL12_F1)); // 6 bits + + ff_bitmask_args[1].present_bit_mask = (~present_FFLDAQ_F1) & 0xFU; // 4 bits + ff_bitmask_args[0].present_bit_mask = (~present_FFL12_F1) & 0x3FU; // 6 bits + ff_bitmask_args[3].present_bit_mask = (~present_FFLDAQ_F2) & 0xFU; // 4 bits + ff_bitmask_args[2].present_bit_mask = (~present_FFL12_F2) & 0x3FU; // 6 bits + + f1_ff12xmit_4v0_sel = (f1_ff12xmit_4v0_sel >> 4) & 0x7; // bits 4-6 + f2_ff12xmit_4v0_sel = (f2_ff12xmit_4v0_sel >> 4) & 0x7; // bits 4-6 +#endif + + setFFmask(ff_combined_present); +} + +bool isEnabledFF(int ff) +{ + // firefly config stored in on-board EEPROM via user input + // and firefly config via PRESENT signals at the first boot + // must be true for a firefly to be enabled. + if (!((1 << ff) & ff_PRESENT_mask) || !((1 << ff) & ff_USER_mask)) { + return false; + } + else { + return true; + } +} + +unsigned isFFStale(void) +{ + TickType_t now = pdTICKS_TO_S(xTaskGetTickCount()); + TickType_t last[4]; + last[0] = pdTICKS_TO_S(ffl12_f1_args.updateTick); + last[1] = pdTICKS_TO_S(ffldaq_f1_args.updateTick); + last[2] = pdTICKS_TO_S(ffl12_f2_args.updateTick); + last[3] = pdTICKS_TO_S(ffldaq_f2_args.updateTick); + + unsigned mask = 0U; + for (int ff_t = 0; ff_t < 4; ++ff_t) { + if (checkStale(last[ff_t], now)) { + mask |= (1U << ff_t); + } + } + + return mask; // bits set for stale tasks. no bits set == not stale. +} + +// this will return the tick of the _lowest_ set bit. +TickType_t getFFupdateTick(int mask) +{ + log_debug(LOG_SERVICE, "mask = %x\r\n", mask); + if (__builtin_popcount(mask) == 0) { + log_warn(LOG_SERVICE, "empty mask\r\n"); + } + if (mask & 0x1U) { + return ffl12_f1_args.updateTick; + } + else if (mask & 0x02U) { + return ffldaq_f1_args.updateTick; + } + else if (mask & 0x04U) { + return ffl12_f2_args.updateTick; + } + else { + return ffldaq_f2_args.updateTick; + } +} + +uint16_t getFFtemp(const uint8_t i) +{ + int i1 = 1; + int8_t val; + configASSERT(i < NFIREFLIES); + if (i < NFIREFLIES_IT_F1) { + int index = i * (ffl12_f1_args.n_commands * ffl12_f1_args.n_pages) + i1; + val = ffl12_f1_args.sm_values[index]; + } + + else if (NFIREFLIES_IT_F1 <= i && i < NFIREFLIES_IT_F1 + NFIREFLIES_DAQ_F1) { + int index = (i - NFIREFLIES_IT_F1) * (ffldaq_f1_args.n_commands * ffldaq_f1_args.n_pages) + i1; + val = ffldaq_f1_args.sm_values[index]; + } + + else if (NFIREFLIES_F1 <= i && i < NFIREFLIES_F1 + NFIREFLIES_IT_F2) { + int index = (i - NFIREFLIES_F1) * (ffl12_f2_args.n_commands * ffl12_f2_args.n_pages) + i1; + val = ffl12_f2_args.sm_values[index]; + } + else { + int index = (i - NFIREFLIES_F1 - NFIREFLIES_IT_F2) * (ffldaq_f2_args.n_commands * ffldaq_f2_args.n_pages) + i1; + val = ffldaq_f2_args.sm_values[index]; + } + + return val; +} + +#ifdef REV2 +uint16_t getFFavgoptpow(const uint8_t i) +{ + + uint16_t avg_val = 0; + uint16_t sum_val = 0; + configASSERT(i < NFIREFLIES); + + for (int n = 0; n < 4; ++n) { + if (ff_moni2c_arg[n].int_idx <= i && i < ff_moni2c_arg[n].int_idx + ff_moni2c_arg[n].num_dev) { + for (int i1 = 4; i1 < ff_moni2c_arg[n].arg->n_commands; ++i1) { + int dev = i - ff_moni2c_arg[n].int_idx + ff_moni2c_arg[n].dev_int_idx; + int index = dev * (ff_moni2c_arg[n].arg->n_commands * ff_moni2c_arg[n].arg->n_pages) + i1; + sum_val += ff_moni2c_arg[n].arg->sm_values[index]; + } + avg_val = sum_val / (ff_moni2c_arg[n].arg->n_commands - 4); + } + } + + return avg_val; +} + +uint16_t getFFpresentbit(const uint8_t i) +{ + if (i > 3) { + log_warn(LOG_SERVICE, "caught %d > total fireflies %d\r\n", i, NFIREFLIES); + return 56; + } + uint16_t val = ff_bitmask_args[i].present_bit_mask; + + return val; +} + +void getFFpart(void) +{ + // Write device vendor part for identifying FF device + uint8_t nstring = VENDOR_STOP_BIT_FF12 - VENDOR_START_BIT_FF12 + 1; + char vendor_string[nstring]; + uint8_t data; + + SemaphoreHandle_t semaphores[2] = {i2c4_sem, i2c3_sem}; + const int ff_ndev_offset[2] = {0, NFIREFLIES_IT_F1 + NFIREFLIES_DAQ_F1}; + const uint32_t ndevices[2] = {NSUPPLIES_FFL12_F1 / 2, NSUPPLIES_FFL12_F2 / 2}; + const uint32_t dev_present_mask[2] = {present_FFL12_F1, present_FFL12_F2}; + const uint32_t dev_xmit_4v0_sel[2] = {f1_ff12xmit_4v0_sel, f2_ff12xmit_4v0_sel}; + + struct MonitorI2CTaskArgs_t args_st[2] = {ffl12_f1_args, ffl12_f2_args}; + + for (int f = 0; f < 2; ++f) { + + // grab the semaphore to ensure unique access to I2C controller + // otherwise, block its operations indefinitely until it's available + acquireI2CSemaphoreBlock(semaphores[f]); + uint32_t tmp_ffpart_bit_mask = 0U; + bool detect_ff = false; + for (uint8_t n = 0; n < ndevices[f]; n++) { + uint8_t vendor_data_rxch[4]; + int8_t vendor_part_rxch[17]; + + data = 0x1U << args_st[f].devices[(2 * n) + 1].mux_bit; + log_debug(LOG_SERVICE, "Mux set to 0x%02x\r\n", data); + int rmux = apollo_i2c_ctl_w(args_st[f].i2c_dev, args_st[f].devices[(2 * n) + 1].mux_addr, 1, data); + if (rmux != 0) { + log_warn(LOG_SERVICE, "Mux write error %s\r\n", SMBUS_get_error(rmux)); + } + for (uint8_t i = VENDOR_START_BIT_FF12; i < VENDOR_STOP_BIT_FF12; i++) { + uint32_t vendor_char_rxch; + int res = apollo_i2c_ctl_reg_r(args_st[f].i2c_dev, args_st[f].devices[(2 * n) + 1].dev_addr, 1, (uint16_t)i, 1, &vendor_char_rxch); + if (res != 0) { + log_warn(LOG_SERVICE, "GetFFpart read Error %s, break\r\n", SMBUS_get_error(res)); + vendor_part_rxch[i - VENDOR_START_BIT_FF12] = 0; + break; + } + for (int j = 0; j < 4; ++j) { + vendor_data_rxch[j] = (vendor_char_rxch >> (3 - j) * 8) & 0xFF; + } + convert_8_t tmp1; + tmp1.us = vendor_data_rxch[3]; // change from uint_8 to int8_t, preserving bit pattern + vendor_part_rxch[i - VENDOR_START_BIT_FF12] = tmp1.s; + vendor_part_rxch[i - VENDOR_START_BIT_FF12 + 1] = '\0'; // null-terminated + } + + char *vendor_string_rxch = (char *)vendor_part_rxch; + + if ((dev_present_mask[f] & (1 << (2 * n))) == 0) { // check that there is a FF installed in this ch + if (!detect_ff) { + detect_ff = true; + if (strstr(vendor_string_rxch, "14") == NULL && strstr(vendor_string_rxch, "CRRNB") == NULL) { // the first 25Gbs 12-ch detected on FPGA1(2) + tmp_ffpart_bit_mask = tmp_ffpart_bit_mask | (0x1U << n); // bit 1 for a 25Gbs ch and assign to a Bit-mask of Firefly 12-ch part + } + else { + if (f == 0) + ffl12_f1_args.commands = sm_command_fflit_f1; // if the 14Gbsp 12-ch part is found, change the set of commands to sm_command_fflit_f1 + else + ffl12_f2_args.commands = sm_command_fflit_f2; // if the 14Gbsp 12-ch part is found, change the set of commands to sm_command_fflit_f2 + } + log_info(LOG_SERVICE, "Getting Firefly 12-ch part (FPGA%d): %s \r\n:", f + 1, vendor_string_rxch); + strncpy(vendor_string, vendor_string_rxch, nstring); + } + else { + if (strstr(vendor_string_rxch, "14") == NULL && strstr(vendor_string_rxch, "CRRNB") == NULL) { + tmp_ffpart_bit_mask = tmp_ffpart_bit_mask | (0x1U << n); // bit 1 for a 25Gbs ch and assign to a Bit-mask of Firefly 12-ch part + } + else { + if (strncmp(vendor_string_rxch, vendor_string, nstring) != 0) { + log_info(LOG_SERVICE, "Different Firefly 12-ch part(FPGA%d) on %s \r\n:", f + 1, ff_moni2c_addrs[(2 * n) + 1 + ff_ndev_offset[f]].name); + log_info(LOG_SERVICE, "with %s \r\n:", vendor_string_rxch); + } + } + } + } + else { + log_info(LOG_SERVICE, "No Firefly 12-ch part(FPGA%d) on %s \r\n:", f + 1, ff_moni2c_addrs[(2 * n) + 1 + ff_ndev_offset[f]].name); + } + memset(vendor_data_rxch, 0, sizeof(vendor_data_rxch)); + memset(vendor_part_rxch, 0, sizeof(vendor_part_rxch)); + rmux = apollo_i2c_ctl_w(args_st[f].i2c_dev, args_st[f].devices[(2 * n) + 1].mux_addr, 1, 0); + if (rmux != 0) { + log_warn(LOG_SERVICE, "Mux write error %s\r\n", SMBUS_get_error(rmux)); + } + log_debug(LOG_SERVICE, "%s: reset mux\r\n", args_st[f].devices[(2 * n) + 1].name); + } + + log_debug(LOG_SERVICE, "Bit-mask of Firefly 12-ch part (FPGA%d): 0x%02x \r\n:", f + 1, tmp_ffpart_bit_mask); + log_debug(LOG_SERVICE, "Bit-mask of xmit_3v8_sel(FPGA%d): 0x%02x \r\n:", f + 1, dev_xmit_4v0_sel[f]); + // Warning if 25Gbs found but is connected to 3.3V or Non-25Gbs found but is connected to 3.8V + if ((dev_xmit_4v0_sel[f] ^ tmp_ffpart_bit_mask) != 0U) { + log_warn(LOG_SERVICE, "FPGA%d 12-ch FFs have unmatched xmit_3v8_sel(0x%02x) and 12-ch ff-mask(0x%02x) \r\n", f + 1, dev_xmit_4v0_sel[f], tmp_ffpart_bit_mask); + } + + if (f == 0) + ff_bitmask_args[0].ffpart_bit_mask = tmp_ffpart_bit_mask; + else + ff_bitmask_args[2].ffpart_bit_mask = tmp_ffpart_bit_mask; + + // if we have a semaphore, give it + if (xSemaphoreGetMutexHolder(semaphores[f]) == xTaskGetCurrentTaskHandle()) { + xSemaphoreGive(semaphores[f]); + } + } +} +#endif diff --git a/projects/cm_mcu/FireflyUtils.h b/projects/cm_mcu/FireflyUtils.h new file mode 100644 index 00000000..e87d6ae2 --- /dev/null +++ b/projects/cm_mcu/FireflyUtils.h @@ -0,0 +1,90 @@ +#ifndef FIREFLYUTILS_H +#define FIREFLYUTILS_H +#include +#include +#include "FreeRTOS.h" +#include "FreeRTOSConfig.h" +#include "Tasks.h" + +// Function declarations +// the following are true for both Rev1 and Rev2 +#define FF_I2CMUX_1_ADDR 0x70 +#define FF_I2CMUX_2_ADDR 0x71 +#define I2C_DEVICE_CLK 2 + +// REV1 +#ifndef REV2 +#define NFIREFLY_ARG 5 +#define NFIREFLIES_F1 11 +#define NFIREFLIES_F2 14 +#define NFIREFLIES_IT_F1 8 +#define NFIREFLIES_DAQ_F1 3 +#define NFIREFLIES_IT_F2 4 +#define NFIREFLIES_DAQ_F2 10 +#else // REV2 +// REV 2 +#define NFIREFLY_ARG 4 +#define NFIREFLIES_F1 10 +#define NFIREFLIES_F2 10 +#define NFIREFLIES_IT_F1 6 +#define NFIREFLIES_DAQ_F1 4 +#define NFIREFLIES_IT_F2 6 +#define NFIREFLIES_DAQ_F2 4 +#endif // REV 2 +#define CLK_PAGE_COMMAND 1 +#define NFIREFLIES (NFIREFLIES_F1 + NFIREFLIES_F2) + +#define VENDOR_START_BIT_FFDAQ 168 +#define VENDOR_STOP_BIT_FFDAQ 184 +#define VENDOR_START_BIT_FF12 171 +#define VENDOR_STOP_BIT_FF12 187 + + +struct arg_moni2c_ff_t { + char *ff_part; // ff part + struct MonitorI2CTaskArgs_t *arg; // ff arg + uint8_t int_idx; // start idx of this arg in ff_moni2c_addrs + uint8_t dev_int_idx; // start idx of the device in its arg + uint8_t num_dev; // number of devices in this ff arg. +}; + +extern struct dev_moni2c_addr_t ff_moni2c_addrs[NFIREFLIES]; +extern struct arg_moni2c_ff_t ff_moni2c_arg[NFIREFLY_ARG]; + +// Samtec firefly specific commands +bool getFFch_low(uint8_t val, int channel); +bool getFFch_high(uint8_t val, int channel); +bool isEnabledFF(int ff); +void setFFmask(uint32_t ff_combined_mask); +void readFFpresent(void); +uint16_t getFFtemp(const uint8_t i); +uint16_t getFFavgoptpow(const uint8_t i); +uint16_t getFFpresentbit(const uint8_t i); +#ifdef REV2 +void getFFpart(void); +#endif + +uint8_t getFFstatus(const uint8_t i); +unsigned isFFStale(void); +TickType_t getFFupdateTick(int ff_t); +void init_registers_ff(void); + +extern uint32_t ff_PRESENT_mask; +extern uint32_t ff_USER_mask; +#ifdef REV2 +extern uint32_t f1_ff12xmit_4v0_sel; +extern uint32_t f2_ff12xmit_4v0_sel; +struct ff_bit_mask_t { + 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 +}; +extern struct ff_bit_mask_t ff_bitmask_args[NFIREFLY_ARG]; +#endif + +#ifdef REV1 +extern uint32_t present_0X20_F2, present_0X21_F2, present_FFLDAQ_F1, present_FFL12_F1, present_FFLDAQ_0X20_F2, present_FFL12_0X20_F2, present_FFLDAQ_0X21_F2, present_FFL12_0X21_F2; +#elif defined(REV2) +extern uint32_t present_FFLDAQ_F1, present_FFL12_F1, present_FFLDAQ_F2, present_FFL12_F2; +#endif // REV2 + +#endif // FIREFLYUTILS_H diff --git a/projects/cm_mcu/I2CSlaveTask.c b/projects/cm_mcu/I2CSlaveTask.c index a5abfa6c..bca70fa8 100644 --- a/projects/cm_mcu/I2CSlaveTask.c +++ b/projects/cm_mcu/I2CSlaveTask.c @@ -19,6 +19,7 @@ #include "MonitorTask.h" #include "common/LocalUart.h" #include "common/log.h" +#include "FireflyUtils.h" #include "I2CSlaveTask.h" // Rev 2: diff --git a/projects/cm_mcu/LocalTasks.c b/projects/cm_mcu/LocalTasks.c index dc0874e5..3336cbca 100644 --- a/projects/cm_mcu/LocalTasks.c +++ b/projects/cm_mcu/LocalTasks.c @@ -30,34 +30,11 @@ #include "I2CCommunication.h" #include "common/log.h" -convert_8_t tmp1; +//convert_8_t tmp1; // local prototype void Print(const char *str); -uint32_t ff_PRESENT_mask = 0; // global variable from getting combined ff signals -uint32_t ff_USER_mask = 0; // global variable of ff signals from user input -#ifdef REV2 -uint32_t f1_ff12xmit_4v0_sel = 0; // global variable for FPGA1 12-ch xmit ff's power-supply physical selection -uint32_t f2_ff12xmit_4v0_sel = 0; // global variable for FPGA2 12-ch xmit ff's power-supply physical selection - -struct ff_bit_mask_t ff_bitmask_args[4] = { - {0U, 0U}, // {3, 6} bits correspond to ffl12_f1 devices - {0U, 0U}, // {0, 4} and bits correspond to ffldaq_f1 devices - {0U, 0U}, // {3, 6} bits correspond to ffl12_f2 devices - {0U, 0U}, // {0, 4} bits correspond to ffldaq_f2 devices -}; - -#endif -// outputs from *_PRESENT pins for constructing ff_PRESENT_mask -#ifdef REV1 -// 4.05 I2C KU15P OPTICS -uint32_t present_FFLDAQ_F1, present_FFL12_F1, - // 4.06 I2C VU7P OPTICS (the I/O expanders at 0x20 and 0x21 have mixed 4-ch (FFLDAQ) and 12-ch (FFL12) pins) - present_0X20_F2, present_0X21_F2, present_FFLDAQ_0X20_F2, present_FFL12_0X20_F2, - present_FFLDAQ_0X21_F2, present_FFL12_0X21_F2 = 0; -#endif // REV2 - #ifdef REV1 // ------------------------------------------------- // @@ -508,7 +485,7 @@ struct MonitorI2CTaskArgs_t clockr0a_args = { void setFFmask(uint32_t ff_combined_present) { - log_info(LOG_SERVICE, "Setting bit mask of enabled Fireflys\r\n"); + log_info(LOG_SERVICE, "Setting a bit mask of enabled Fireflys to 1 \r\n"); // int32_t data = (~ff_combined_present) & 0xFFFFFU; // the bit value for an FF mask is an inverted bit value of the PRESENT signals #ifdef REV1 @@ -532,9 +509,6 @@ void setFFmask(uint32_t ff_combined_present) return; } -// this function reads out the I/O expanders to determine which Fireflys are present -// and if they require 3.8V or not. -// the code sets ff_bitmask_args[] and f[12]_ff12xmit_4v0_sel void readFFpresent(void) { // grab the semaphore to ensure unique access to I2C controller @@ -549,13 +523,12 @@ void readFFpresent(void) apollo_i2c_ctl_w(4, 0x71, 1, 0x40); apollo_i2c_ctl_reg_r(4, 0x21, 1, 0x00, 1, &present_FFLDAQ_F1); #elif defined(REV2) - uint32_t present_FFL12_F1_bar, present_FFLDAQ_F1_bar; // active low signals // to port 7 apollo_i2c_ctl_w(4, 0x70, 1, 0x80); - apollo_i2c_ctl_reg_r(4, 0x20, 1, 0x01, 1, &present_FFL12_F1_bar); // active low!! + apollo_i2c_ctl_reg_r(4, 0x20, 1, 0x01, 1, &present_FFL12_F1); // to port 6 apollo_i2c_ctl_w(4, 0x71, 1, 0x40); - apollo_i2c_ctl_reg_r(4, 0x21, 1, 0x00, 1, &present_FFLDAQ_F1_bar); + apollo_i2c_ctl_reg_r(4, 0x21, 1, 0x00, 1, &present_FFLDAQ_F1); apollo_i2c_ctl_reg_r(4, 0x21, 1, 0x01, 1, &f1_ff12xmit_4v0_sel); // reading FPGA1 12-ch xmit FF's power-supply physical selection (i.e either 3.3v or 4.0v) #endif @@ -576,13 +549,12 @@ void readFFpresent(void) apollo_i2c_ctl_w(3, 0x72, 1, 0x02); apollo_i2c_ctl_reg_r(3, 0x21, 1, 0x01, 1, &present_0X21_F2); #elif defined(REV2) - uint32_t present_FFL12_F2_bar, present_FFLDAQ_F2_bar; // active low signals // to port 7 apollo_i2c_ctl_w(3, 0x70, 1, 0x80); - apollo_i2c_ctl_reg_r(3, 0x20, 1, 0x01, 1, &present_FFL12_F2_bar); // active low!! + apollo_i2c_ctl_reg_r(3, 0x20, 1, 0x01, 1, &present_FFL12_F2); // to port 6 apollo_i2c_ctl_w(3, 0x71, 1, 0x40); - apollo_i2c_ctl_reg_r(3, 0x21, 1, 0x00, 1, &present_FFLDAQ_F2_bar); + apollo_i2c_ctl_reg_r(3, 0x21, 1, 0x00, 1, &present_FFLDAQ_F2); apollo_i2c_ctl_reg_r(3, 0x21, 1, 0x01, 1, &f2_ff12xmit_4v0_sel); // reading FPGA2 12-ch xmit FF's power-supply physical selection (i.e either 3.3v or 4.0v) #endif @@ -609,20 +581,20 @@ void readFFpresent(void) ((present_FFL12_BOTTOM_F1)); // 6 bits #elif defined(REV2) - present_FFL12_F1_bar = present_FFL12_F1_bar & 0x3FU; // bottom 6 bits - present_FFL12_F2_bar = present_FFL12_F2_bar & 0x3FU; // bottom 6 bits - present_FFLDAQ_F1_bar = (present_FFLDAQ_F1_bar >> 4) & 0xFU; // bits 4-7 - present_FFLDAQ_F2_bar = (present_FFLDAQ_F2_bar >> 4) & 0xFU; // bits 4-7 + present_FFL12_F1 = present_FFL12_F1 & 0x3FU; // bottom 6 bits + present_FFL12_F2 = present_FFL12_F2 & 0x3FU; // bottom 6 bits + present_FFLDAQ_F1 = (present_FFLDAQ_F1 >> 4) & 0xFU; // bits 4-7 + present_FFLDAQ_F2 = (present_FFLDAQ_F2 >> 4) & 0xFU; // bits 4-7 - uint32_t ff_combined_present = ((present_FFLDAQ_F2_bar) << 16) | // 4 bits - ((present_FFL12_F2_bar) << 10) | // 6 bits - (present_FFLDAQ_F1_bar) << 6 | // 4 bits - ((present_FFL12_F1_bar)); // 6 bits + uint32_t ff_combined_present = ((present_FFLDAQ_F2) << 16) | // 4 bits + ((present_FFL12_F2) << 10) | // 6 bits + (present_FFLDAQ_F1) << 6 | // 4 bits + ((present_FFL12_F1)); // 6 bits - ff_bitmask_args[0].present_bit_mask = (~present_FFL12_F1_bar) & 0x3FU; // 6 bits - ff_bitmask_args[1].present_bit_mask = (~present_FFLDAQ_F1_bar) & 0xFU; // 4 bits - ff_bitmask_args[2].present_bit_mask = (~present_FFL12_F2_bar) & 0x3FU; // 6 bits - ff_bitmask_args[3].present_bit_mask = (~present_FFLDAQ_F2_bar) & 0xFU; // 4 bits + ff_bitmask_args[1].present_bit_mask = (~present_FFLDAQ_F1) & 0xFU; // 4 bits + ff_bitmask_args[0].present_bit_mask = (~present_FFL12_F1) & 0x3FU; // 6 bits + ff_bitmask_args[3].present_bit_mask = (~present_FFLDAQ_F2) & 0xFU; // 4 bits + ff_bitmask_args[2].present_bit_mask = (~present_FFL12_F2) & 0x3FU; // 6 bits f1_ff12xmit_4v0_sel = (f1_ff12xmit_4v0_sel >> 4) & 0x7; // bits 4-6 f2_ff12xmit_4v0_sel = (f2_ff12xmit_4v0_sel >> 4) & 0x7; // bits 4-6 @@ -744,22 +716,17 @@ uint16_t getFFpresentbit(const uint8_t i) return val; } -// there is a lot of indirection here -// this function modifies ffl12_f[12]_args to point to the appropriate command set -// it also modifies ff_bitmask_args[] -// -#define NSTRING (VENDOR_STOP_BIT_FF12 - VENDOR_START_BIT_FF12 + 1) void getFFpart(void) { // Write device vendor part for identifying FF device - char vendor_string[NSTRING]; + uint8_t nstring = VENDOR_STOP_BIT_FF12 - VENDOR_START_BIT_FF12 + 1; + char vendor_string[nstring]; + uint8_t data; SemaphoreHandle_t semaphores[2] = {i2c4_sem, i2c3_sem}; const int ff_ndev_offset[2] = {0, NFIREFLIES_IT_F1 + NFIREFLIES_DAQ_F1}; const uint32_t ndevices[2] = {NSUPPLIES_FFL12_F1 / 2, NSUPPLIES_FFL12_F2 / 2}; - // why are these masks inverted? I am inverting them to preserve past behavior - const uint32_t dev_present_mask[2] = {~ff_bitmask_args[0].present_bit_mask, - ~ff_bitmask_args[2].present_bit_mask}; + const uint32_t dev_present_mask[2] = {present_FFL12_F1, present_FFL12_F2}; const uint32_t dev_xmit_4v0_sel[2] = {f1_ff12xmit_4v0_sel, f2_ff12xmit_4v0_sel}; struct MonitorI2CTaskArgs_t args_st[2] = {ffl12_f1_args, ffl12_f2_args}; @@ -771,11 +738,11 @@ void getFFpart(void) acquireI2CSemaphoreBlock(semaphores[f]); uint32_t tmp_ffpart_bit_mask = 0U; bool detect_ff = false; - for (uint32_t n = 0; n < ndevices[f]; n++) { + for (uint8_t n = 0; n < ndevices[f]; n++) { uint8_t vendor_data_rxch[4]; int8_t vendor_part_rxch[17]; - uint8_t data = 0x1U << args_st[f].devices[(2 * n) + 1].mux_bit; + data = 0x1U << args_st[f].devices[(2 * n) + 1].mux_bit; log_debug(LOG_SERVICE, "Mux set to 0x%02x\r\n", data); int rmux = apollo_i2c_ctl_w(args_st[f].i2c_dev, args_st[f].devices[(2 * n) + 1].mux_addr, 1, data); if (rmux != 0) { @@ -813,14 +780,14 @@ void getFFpart(void) ffl12_f2_args.commands = sm_command_fflit_f2; // if the 14Gbsp 12-ch part is found, change the set of commands to sm_command_fflit_f2 } log_info(LOG_SERVICE, "Getting Firefly 12-ch part (FPGA%d): %s \r\n:", f + 1, vendor_string_rxch); - strncpy(vendor_string, vendor_string_rxch, NSTRING); + strncpy(vendor_string, vendor_string_rxch, nstring); } else { if (strstr(vendor_string_rxch, "14") == NULL && strstr(vendor_string_rxch, "CRRNB") == NULL) { tmp_ffpart_bit_mask = tmp_ffpart_bit_mask | (0x1U << n); // bit 1 for a 25Gbs ch and assign to a Bit-mask of Firefly 12-ch part } else { - if (strncmp(vendor_string_rxch, vendor_string, NSTRING) != 0) { + if (strncmp(vendor_string_rxch, vendor_string, nstring) != 0) { log_info(LOG_SERVICE, "Different Firefly 12-ch part(FPGA%d) on %s \r\n:", f + 1, ff_moni2c_addrs[(2 * n) + 1 + ff_ndev_offset[f]].name); log_info(LOG_SERVICE, "with %s \r\n:", vendor_string_rxch); } diff --git a/projects/cm_mcu/Makefile b/projects/cm_mcu/Makefile index 660d5f3b..9571ee42 100644 --- a/projects/cm_mcu/Makefile +++ b/projects/cm_mcu/Makefile @@ -163,6 +163,7 @@ ${COMPILER}/cm_mcu.axf: ${COMPILER}/WatchdogTask.o ${COMPILER}/cm_mcu.axf: ${COMPILER}/LocalTasks.o ${COMPILER}/cm_mcu.axf: ${COMPILER}/BoardCommands.o ${COMPILER}/cm_mcu.axf: ${COMPILER}/SoftwareCommands.o +${COMPILER}/cm_mcu.axf: ${COMPILER}/FireflyUtils.o ${COMPILER}/cm_mcu.axf: ${COMPILER}/BufferCommands.o ${COMPILER}/cm_mcu.axf: ${COMPILER}/EEPROMCommands.o ${COMPILER}/cm_mcu.axf: ${COMPILER}/I2CCommands.o diff --git a/projects/cm_mcu/MonitorI2CTask.c b/projects/cm_mcu/MonitorI2CTask.c index 5dd6fc9f..4f5fb5c3 100644 --- a/projects/cm_mcu/MonitorI2CTask.c +++ b/projects/cm_mcu/MonitorI2CTask.c @@ -86,8 +86,8 @@ void MonitorI2CTask(void *parameters) // ------------------------------- // loop over devices in the device-type instance // ------------------------------- - for (int thisdev = 0; thisdev < args->n_devices; ++thisdev) { - log_debug(LOG_MONI2C, "%s: dev %d pwrchk\r\n", args->name, thisdev); + for (int device = 0; device < args->n_devices; ++device) { + log_debug(LOG_MONI2C, "%s: device %d powercheck\r\n", args->name, device); if (getPowerControlState() != POWER_ON) { if (good) { @@ -108,6 +108,7 @@ void MonitorI2CTask(void *parameters) } } + // for firefly devices, skip if FF is not enabled if (!IsCLK) { // Fireflies need to be checked if the links are connected or not if (args->i2c_dev == I2C_DEVICE_F1) { // FPGA #1 #ifdef REV1 @@ -115,7 +116,7 @@ void MonitorI2CTask(void *parameters) if (!isEnabledFF((IsFFDAQ * (thisdev + NFIREFLIES_IT_F1_P1)) + (IsFF12 * (thisdev < NFIREFLIES_IT_F1 - 3) * (thisdev)) + (IsFF12 * (thisdev > NFIREFLIES_IT_F1 - 3) * (thisdev + NFIREFLIES_DAQ_F1)))) // skip the FF if it's not enabled via the FF config continue; #elif defined(REV2) - if (!isEnabledFF((IsFFDAQ * (thisdev + NFIREFLIES_IT_F1)) + (IsFF12 * (thisdev)))) // skip the FF if it's not enabled via the FF config + if (!isEnabledFF((IsFFDAQ * (device + NFIREFLIES_IT_F1)) + (IsFF12 * (device)))) // skip the FF if it's not enabled via the FF config continue; #else #error "Define either Rev1 or Rev2" @@ -126,7 +127,7 @@ void MonitorI2CTask(void *parameters) if (!isEnabledFF(NFIREFLIES_F1 + (IsFFDAQ * (thisdev)) + (IsFF12 * (thisdev + NFIREFLIES_DAQ_F2)))) // skip the FF if it's not enabled via the FF config continue; #elif defined(REV2) - if (!isEnabledFF(NFIREFLIES_F1 + (IsFFDAQ * (thisdev + NFIREFLIES_IT_F2)) + (IsFF12 * (thisdev)))) // skip the FF if it's not enabled via the FF config + if (!isEnabledFF(NFIREFLIES_F1 + (IsFFDAQ * (device + NFIREFLIES_IT_F2)) + (IsFF12 * (device)))) // skip the FF if it's not enabled via the FF config continue; #else #error "Define either Rev1 or Rev2" @@ -134,6 +135,7 @@ void MonitorI2CTask(void *parameters) } } + // for firefly devices, check the reset pin if (!IsCLK) { // mux setting int result = apollo_i2c_ctl_w(args->i2c_dev, 0x71, 1, 0x40); @@ -156,34 +158,34 @@ void MonitorI2CTask(void *parameters) // select the appropriate output for the mux uint8_t data; - data = 0x1U << args->devices[thisdev].mux_bit; + data = 0x1U << args->devices[device].mux_bit; log_debug(LOG_MONI2C, "Mux set to 0x%02x\r\n", data); - int res = apollo_i2c_ctl_w(args->i2c_dev, args->devices[thisdev].mux_addr, 1, data); + int res = apollo_i2c_ctl_w(args->i2c_dev, args->devices[device].mux_addr, 1, data); if (res != 0) { - log_warn(LOG_MONI2C, "Mux write error %s, break (instance=%s,dev=%d)\r\n", SMBUS_get_error(res), args->name, thisdev); + log_warn(LOG_MONI2C, "Mux write error %s, break (instance=%s,ps=%d)\r\n", SMBUS_get_error(res), args->name, device); break; } // Read I2C registers/commands for (int c = 0; c < args->n_commands; ++c) { - int index = thisdev * (args->n_commands * args->n_pages) + c; + int index = device * (args->n_commands * args->n_pages) + c; log_debug(LOG_MONI2C, "%s: reg %s\r\n", args->name, args->commands[c].name); uint8_t page_reg_value = args->commands[c].page; - int r = apollo_i2c_ctl_reg_w(args->i2c_dev, args->devices[thisdev].dev_addr, 1, args->selpage_reg, 1, page_reg_value); + int r = apollo_i2c_ctl_reg_w(args->i2c_dev, args->devices[device].dev_addr, 1, args->selpage_reg, 1, page_reg_value); if (r != 0) { - log_error(LOG_MONI2C, "%s: %s : page fail %s\r\n", args->name, args->devices[thisdev].name, SMBUS_get_error(r)); + log_error(LOG_MONI2C, "%s : page fail %s\r\n", args->devices[device].name, SMBUS_get_error(r)); break; } uint32_t output_raw; - int res = apollo_i2c_ctl_reg_r(args->i2c_dev, args->devices[thisdev].dev_addr, args->commands[c].reg_size, + int res = apollo_i2c_ctl_reg_r(args->i2c_dev, args->devices[device].dev_addr, args->commands[c].reg_size, args->commands[c].command, args->commands[c].size, &output_raw); if (res != 0) { - log_error(LOG_MONI2C, "%s: %s read Error %s, break (dev=%d)\r\n", - args->name, args->commands[c].name, SMBUS_get_error(res), thisdev); + log_error(LOG_MONI2C, "%s: %s read Error %s, break (ps=%d)\r\n", + args->name, args->commands[c].name, SMBUS_get_error(res), device); args->sm_values[index] = 0xffff; break; } @@ -197,9 +199,9 @@ void MonitorI2CTask(void *parameters) log_debug(LOG_MONI2C, "%s: end loop commands\r\n", args->name); args->updateTick = xTaskGetTickCount(); // current time in ticks - res = apollo_i2c_ctl_w(args->i2c_dev, args->devices[thisdev].mux_addr, 1, 0U); // reset mux + res = apollo_i2c_ctl_w(args->i2c_dev, args->devices[device].mux_addr, 1, 0); if (res != 0) { - log_warn(LOG_MONI2C, "Mux write error %s, break (instance=%s,dev=%d)\r\n", SMBUS_get_error(res), args->name, thisdev); + log_warn(LOG_MONI2C, "Mux write error %s, break (instance=%s,ps=%d)\r\n", SMBUS_get_error(res), args->name, device); break; } log_debug(LOG_MONI2C, "%s: reset mux\r\n", args->name); diff --git a/projects/cm_mcu/MonitorI2CTask.h b/projects/cm_mcu/MonitorI2CTask.h index 5dd5e065..27005963 100644 --- a/projects/cm_mcu/MonitorI2CTask.h +++ b/projects/cm_mcu/MonitorI2CTask.h @@ -12,6 +12,7 @@ #include "FreeRTOS.h" #include "semphr.h" #include "Tasks.h" +#include "FireflyUtils.h" struct sm_command_t { int reg_size; // number of bytes of register/command @@ -26,6 +27,8 @@ struct sm_command_t { // how to find an I2C device, with a mux infront of it. +typedef bool (*MonTaskFcnPointer)(struct MonitorI2CTaskArgs_t *); + struct MonitorI2CTaskArgs_t { const char *name; // name to be assigned to the task struct dev_moni2c_addr_t *devices; // list of devices to query @@ -42,6 +45,7 @@ struct MonitorI2CTaskArgs_t { TickType_t updateTick; // last update time, in ticks SemaphoreHandle_t xSem; // semaphore for controlling access to device UBaseType_t stack_size; // stack size of task + MonTaskFcnPointer presentCallback; // callback for present check }; #define FF_SELPAGE_REG 0x7f diff --git a/projects/cm_mcu/Tasks.h b/projects/cm_mcu/Tasks.h index fdbd3c56..cae39d12 100644 --- a/projects/cm_mcu/Tasks.h +++ b/projects/cm_mcu/Tasks.h @@ -27,6 +27,14 @@ #define __fp16 float #endif // __INTELLISENSE +struct dev_moni2c_addr_t { + char *name; + uint8_t mux_addr; // I2C address of the Mux + uint8_t mux_bit; // port of the mux; write value 0x1U< Date: Sun, 14 Apr 2024 22:27:13 -0400 Subject: [PATCH 03/71] naming cleanups --- projects/cm_mcu/FireflyUtils.c | 7 ++++-- projects/cm_mcu/I2CCommunication.h | 4 --- projects/cm_mcu/LocalTasks.c | 39 +++++++++++++++--------------- projects/cm_mcu/MonitorI2CTask.h | 20 +++++++-------- projects/cm_mcu/clocksynth.c | 2 +- 5 files changed, 35 insertions(+), 37 deletions(-) diff --git a/projects/cm_mcu/FireflyUtils.c b/projects/cm_mcu/FireflyUtils.c index 93669e8b..641c7e2a 100644 --- a/projects/cm_mcu/FireflyUtils.c +++ b/projects/cm_mcu/FireflyUtils.c @@ -225,7 +225,7 @@ TickType_t getFFupdateTick(int mask) uint16_t getFFtemp(const uint8_t i) { int i1 = 1; - int8_t val; + uint16_t val; configASSERT(i < NFIREFLIES); if (i < NFIREFLIES_IT_F1) { int index = i * (ffl12_f1_args.n_commands * ffl12_f1_args.n_pages) + i1; @@ -282,6 +282,9 @@ uint16_t getFFpresentbit(const uint8_t i) return val; } +extern struct sm_command_t sm_command_fflit_f1[]; +extern struct sm_command_t sm_command_fflit_f2[]; + void getFFpart(void) { // Write device vendor part for identifying FF device @@ -291,7 +294,7 @@ void getFFpart(void) SemaphoreHandle_t semaphores[2] = {i2c4_sem, i2c3_sem}; const int ff_ndev_offset[2] = {0, NFIREFLIES_IT_F1 + NFIREFLIES_DAQ_F1}; - const uint32_t ndevices[2] = {NSUPPLIES_FFL12_F1 / 2, NSUPPLIES_FFL12_F2 / 2}; + const uint32_t ndevices[2] = {NDEVICES_FFL12_F1 / 2, NDEVICES_FFL12_F2 / 2}; const uint32_t dev_present_mask[2] = {present_FFL12_F1, present_FFL12_F2}; const uint32_t dev_xmit_4v0_sel[2] = {f1_ff12xmit_4v0_sel, f2_ff12xmit_4v0_sel}; diff --git a/projects/cm_mcu/I2CCommunication.h b/projects/cm_mcu/I2CCommunication.h index d6d0a1e2..2536d1dd 100644 --- a/projects/cm_mcu/I2CCommunication.h +++ b/projects/cm_mcu/I2CCommunication.h @@ -10,11 +10,7 @@ // includes for types #include #include -#include -#include "FreeRTOS.h" -#include "FreeRTOSConfig.h" -#include "stream_buffer.h" #include "common/smbus.h" #include "MonitorTask.h" diff --git a/projects/cm_mcu/LocalTasks.c b/projects/cm_mcu/LocalTasks.c index 3336cbca..72f102c9 100644 --- a/projects/cm_mcu/LocalTasks.c +++ b/projects/cm_mcu/LocalTasks.c @@ -14,8 +14,6 @@ #include // memset #include // struct tm -// ROM header must come before MAP header -#include "driverlib/rom.h" #include "driverlib/hibernate.h" #include "Tasks.h" @@ -147,16 +145,16 @@ struct sm_command_t sm_command_ffldaq_f1[] = { {2, 0x00, 0x28, 2, "FF_CH04_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, }; -uint16_t ffldaq_f1_values[NSUPPLIES_FFLDAQ_F1 * NCOMMANDS_FFLDAQ_F1]; +uint16_t ffldaq_f1_values[NDEVICES_FFLDAQ_F1 * NCOMMANDS_FFLDAQ_F1]; struct MonitorI2CTaskArgs_t ffldaq_f1_args = { .name = "F1_4", .devices = ffldaq_f1_moni2c_addrs, .i2c_dev = I2C_DEVICE_F1, - .n_devices = NSUPPLIES_FFLDAQ_F1, + .n_devices = NDEVICES_FFLDAQ_F1, .commands = sm_command_ffldaq_f1, .n_commands = NCOMMANDS_FFLDAQ_F1, - .n_values = NSUPPLIES_FFLDAQ_F1 * NPAGES_FFLDAQ_F1 * NCOMMANDS_FFLDAQ_F1, + .n_values = NDEVICES_FFLDAQ_F1 * NPAGES_FFLDAQ_F1 * NCOMMANDS_FFLDAQ_F1, .n_pages = NPAGES_FFLDAQ_F1, .selpage_reg = FF_SELPAGE_REG, .sm_values = ffldaq_f1_values, @@ -238,16 +236,16 @@ struct dev_moni2c_addr_t ffl12_f1_moni2c_addrs[NFIREFLIES_IT_F1] = { #error "Define either Rev1 or Rev2" #endif -uint16_t ffl12_f1_values[NSUPPLIES_FFL12_F1 * NCOMMANDS_FFL12_F1]; +uint16_t ffl12_f1_values[NDEVICES_FFL12_F1 * NCOMMANDS_FFL12_F1]; struct MonitorI2CTaskArgs_t ffl12_f1_args = { .name = "F1_12", .devices = ffl12_f1_moni2c_addrs, .i2c_dev = I2C_DEVICE_F1, - .n_devices = NSUPPLIES_FFL12_F1, + .n_devices = NDEVICES_FFL12_F1, .commands = sm_command_fflot_f1, // 25Gbps by default but if the 14Gbsp 12-ch part is found, the set of commands is changed in INIT task .n_commands = NCOMMANDS_FFL12_F1, - .n_values = NSUPPLIES_FFL12_F1 * NPAGES_FFL12_F1 * NCOMMANDS_FFL12_F1, + .n_values = NDEVICES_FFL12_F1 * NPAGES_FFL12_F1 * NCOMMANDS_FFL12_F1, .n_pages = NPAGES_FFL12_F1, .selpage_reg = FF_SELPAGE_REG, .sm_values = ffl12_f1_values, @@ -292,16 +290,16 @@ struct sm_command_t sm_command_ffldaq_f2[] = { {2, 0x00, 0x26, 2, "FF_CH03_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, {2, 0x00, 0x28, 2, "FF_CH04_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, }; -uint16_t ffldaq_f2_values[NSUPPLIES_FFLDAQ_F2 * NCOMMANDS_FFLDAQ_F2]; +uint16_t ffldaq_f2_values[NDEVICES_FFLDAQ_F2 * NCOMMANDS_FFLDAQ_F2]; struct MonitorI2CTaskArgs_t ffldaq_f2_args = { .name = "F2_4", .devices = ffldaq_f2_moni2c_addrs, .i2c_dev = I2C_DEVICE_F2, - .n_devices = NSUPPLIES_FFLDAQ_F2, + .n_devices = NDEVICES_FFLDAQ_F2, .commands = sm_command_ffldaq_f2, .n_commands = NCOMMANDS_FFLDAQ_F2, - .n_values = NSUPPLIES_FFLDAQ_F2 * NPAGES_FFLDAQ_F2 * NCOMMANDS_FFLDAQ_F2, + .n_values = NDEVICES_FFLDAQ_F2 * NPAGES_FFLDAQ_F2 * NCOMMANDS_FFLDAQ_F2, .n_pages = NPAGES_FFLDAQ_F2, .selpage_reg = FF_SELPAGE_REG, .sm_values = ffldaq_f2_values, @@ -375,16 +373,17 @@ struct dev_moni2c_addr_t ffl12_f2_moni2c_addrs[NFIREFLIES_IT_F2] = { #else #error "Define either Rev1 or Rev2" #endif -uint16_t ffl12_f2_values[NSUPPLIES_FFL12_F2 * NCOMMANDS_FFL12_F2]; + +uint16_t ffl12_f2_values[NDEVICES_FFL12_F2 * NCOMMANDS_FFL12_F2]; struct MonitorI2CTaskArgs_t ffl12_f2_args = { .name = "F2_12", .devices = ffl12_f2_moni2c_addrs, .i2c_dev = I2C_DEVICE_F2, - .n_devices = NSUPPLIES_FFL12_F2, + .n_devices = NDEVICES_FFL12_F2, .commands = sm_command_fflot_f2, // 25Gbps by default but if the 14Gbsp 12-ch part is found, the set of commands is changed in INIT task .n_commands = NCOMMANDS_FFL12_F2, - .n_values = NSUPPLIES_FFL12_F2 * NPAGES_FFL12_F2 * NCOMMANDS_FFL12_F2, + .n_values = NDEVICES_FFL12_F2 * NPAGES_FFL12_F2 * NCOMMANDS_FFL12_F2, .n_pages = NPAGES_FFL12_F2, .selpage_reg = FF_SELPAGE_REG, .sm_values = ffl12_f2_values, @@ -425,16 +424,16 @@ struct sm_command_t sm_command_clk[] = { {1, 0x00, 0x11, 1, "STICKY_FLG", 0x27, "", PM_STATUS}, // page 0x00 }; -uint16_t clk_values[NSUPPLIES_CLK * NPAGES_CLK * NCOMMANDS_CLK]; +uint16_t clk_values[NDEVICES_CLK * NPAGES_CLK * NCOMMANDS_CLK]; struct MonitorI2CTaskArgs_t clock_args = { .name = "CLKSI", .devices = clk_moni2c_addrs, .i2c_dev = I2C_DEVICE_CLK, - .n_devices = NSUPPLIES_CLK, + .n_devices = NDEVICES_CLK, .commands = sm_command_clk, .n_commands = NCOMMANDS_CLK, - .n_values = NSUPPLIES_CLK * NPAGES_CLK * NCOMMANDS_CLK, + .n_values = NDEVICES_CLK * NPAGES_CLK * NCOMMANDS_CLK, .n_pages = NPAGES_CLK, .selpage_reg = CLK_SELPAGE_REG, .sm_values = clk_values, @@ -462,16 +461,16 @@ struct sm_command_t sm_command_clkr0a[] = { {1, 0x00, 0x11, 1, "STICKY_FLG", 0x2f, "", PM_STATUS}, // page 0x00 }; -uint16_t clkr0a_values[NSUPPLIES_CLKR0A * NPAGES_CLKR0A * NCOMMANDS_CLKR0A]; +uint16_t clkr0a_values[NDEVICES_CLKR0A * NPAGES_CLKR0A * NCOMMANDS_CLKR0A]; struct MonitorI2CTaskArgs_t clockr0a_args = { .name = "CLKR0A", .devices = clkr0a_moni2c_addrs, .i2c_dev = I2C_DEVICE_CLK, - .n_devices = NSUPPLIES_CLKR0A, + .n_devices = NDEVICES_CLKR0A, .commands = sm_command_clkr0a, .n_commands = NCOMMANDS_CLKR0A, - .n_values = NSUPPLIES_CLKR0A * NPAGES_CLKR0A * NCOMMANDS_CLKR0A, + .n_values = NDEVICES_CLKR0A * NPAGES_CLKR0A * NCOMMANDS_CLKR0A, .n_pages = NPAGES_CLKR0A, .selpage_reg = CLK_SELPAGE_REG, .sm_values = clkr0a_values, diff --git a/projects/cm_mcu/MonitorI2CTask.h b/projects/cm_mcu/MonitorI2CTask.h index 27005963..7b60bc98 100644 --- a/projects/cm_mcu/MonitorI2CTask.h +++ b/projects/cm_mcu/MonitorI2CTask.h @@ -52,33 +52,33 @@ struct MonitorI2CTaskArgs_t { #define CLK_SELPAGE_REG 0x1 #ifndef REV2 -#define NSUPPLIES_FFLDAQ_F1 (3) +#define NDEVICES_FFLDAQ_F1 (3) #else // REV2 -#define NSUPPLIES_FFLDAQ_F1 (4) +#define NDEVICES_FFLDAQ_F1 (4) #endif // REV 2 #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) +#define NDEVICES_FFL12_F1 (8) #else // REV1 -#define NSUPPLIES_FFL12_F1 (6) +#define NDEVICES_FFL12_F1 (6) #endif // REV 2 #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) +#define NDEVICES_FFLDAQ_F2 (10) #else // REV1 -#define NSUPPLIES_FFLDAQ_F2 (4) +#define NDEVICES_FFLDAQ_F2 (4) #endif // REV 2 #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) +#define NDEVICES_FFL12_F2 (4) #else // REV1 -#define NSUPPLIES_FFL12_F2 (6) +#define NDEVICES_FFL12_F2 (6) #endif // REV 2 #define NCOMMANDS_FFL12_F2 16 // number of commands #define NPAGES_FFL12_F2 1 // number of pages on the 12-channel firefly ports @@ -92,11 +92,11 @@ extern struct MonitorI2CTaskArgs_t ffldaq_f1_args; extern struct MonitorI2CTaskArgs_t ffl12_f2_args; extern struct MonitorI2CTaskArgs_t ffldaq_f2_args; -#define NSUPPLIES_CLK (4) +#define NDEVICES_CLK (4) #define NCOMMANDS_CLK 7 // number of commands #define NCOMMANDS_FLG_CLK 1 // number of sticky commands #define NPAGES_CLK 1 // -#define NSUPPLIES_CLKR0A (1) +#define NDEVICES_CLKR0A (1) #define NCOMMANDS_CLKR0A 7 // number of commands #define NCOMMANDS_FLG_CLKR0A 2 // number of sticky commands #define NPAGES_CLKR0A 1 // diff --git a/projects/cm_mcu/clocksynth.c b/projects/cm_mcu/clocksynth.c index 3f5eaffd..ef8f6735 100644 --- a/projects/cm_mcu/clocksynth.c +++ b/projects/cm_mcu/clocksynth.c @@ -30,7 +30,7 @@ int clear_clk_stickybits(void) int status = -99; - const uint8_t nsupplies[2] = {NSUPPLIES_CLKR0A, NSUPPLIES_CLK}; + const uint8_t nsupplies[2] = {NDEVICES_CLKR0A, NDEVICES_CLK}; const uint8_t ncommands[2] = {NCOMMANDS_FLG_CLKR0A, NCOMMANDS_FLG_CLK}; const uint8_t dev_addr[2] = {CLOCK_SYNTH5341_I2C_ADDRESS, CLOCK_SYNTH5395_I2C_ADDRESS}; From ca1068c3bced31a58522074853d16876ab2a497b Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Thu, 18 Apr 2024 09:41:20 -0400 Subject: [PATCH 04/71] Cleanup --- projects/cm_mcu/FireflyUtils.h | 2 -- projects/cm_mcu/LocalTasks.c | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/projects/cm_mcu/FireflyUtils.h b/projects/cm_mcu/FireflyUtils.h index e87d6ae2..d899fd4d 100644 --- a/projects/cm_mcu/FireflyUtils.h +++ b/projects/cm_mcu/FireflyUtils.h @@ -2,8 +2,6 @@ #define FIREFLYUTILS_H #include #include -#include "FreeRTOS.h" -#include "FreeRTOSConfig.h" #include "Tasks.h" // Function declarations diff --git a/projects/cm_mcu/LocalTasks.c b/projects/cm_mcu/LocalTasks.c index 72f102c9..b984546a 100644 --- a/projects/cm_mcu/LocalTasks.c +++ b/projects/cm_mcu/LocalTasks.c @@ -1524,7 +1524,7 @@ void init_registers_ff(void) #define EEPROM_MAX_PER_PAGE 126 // You must claim the semaphore at a higher level than this -static int load_clk_registers(int reg_count, uint16_t reg_page, uint16_t i2c_addrs) +static int load_clk_registers(uint32_t reg_count, uint16_t reg_page, uint16_t i2c_addrs) { int8_t HighByte = -1; // keep track when reg0 is changed int status_w = -1; From a4b5882c63368ae20a28de265d44a23cd3ad34eb Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Mon, 6 May 2024 12:51:10 -0400 Subject: [PATCH 05/71] FFLDAQ->FFL4 --- projects/cm_mcu/FireflyUtils.c | 64 +++++++++--------- projects/cm_mcu/LocalTasks.c | 108 ++++++++++++++++--------------- projects/cm_mcu/MonitorI2CTask.c | 4 +- projects/cm_mcu/MonitorI2CTask.h | 24 +++---- projects/cm_mcu/cm_mcu.c | 8 +-- 5 files changed, 105 insertions(+), 103 deletions(-) diff --git a/projects/cm_mcu/FireflyUtils.c b/projects/cm_mcu/FireflyUtils.c index 641c7e2a..4de2283b 100644 --- a/projects/cm_mcu/FireflyUtils.c +++ b/projects/cm_mcu/FireflyUtils.c @@ -26,26 +26,26 @@ uint32_t ff_USER_mask = 0; // global variable of ff signals from user input uint32_t f1_ff12xmit_4v0_sel = 0; // global variable for FPGA1 12-ch xmit ff's power-supply physical selection uint32_t f2_ff12xmit_4v0_sel = 0; // global variable for FPGA2 12-ch xmit ff's power-supply physical selection -struct ff_bit_mask_t ff_bitmask_args[] = { +struct ff_bit_mask_t ff_bitmask_args[4] = { {0U, 0U}, // {3, 6} bits correspond to ffl12_f1 devices - {0U, 0U}, // {0, 4} and bits correspond to ffldaq_f1 devices + {0U, 0U}, // {0, 4} and bits correspond to ffl4_f1 devices {0U, 0U}, // {3, 6} bits correspond to ffl12_f2 devices - {0U, 0U}, // {0, 4} bits correspond to ffldaq_f2 devices + {0U, 0U}, // {0, 4} bits correspond to ffl4_f2 devices }; #endif // outputs from *_PRESENT pins for constructing ff_PRESENT_mask #ifdef REV1 // 4.05 I2C KU15P OPTICS -uint32_t present_FFLDAQ_F1, present_FFL12_F1, - // 4.06 I2C VU7P OPTICS (the I/O expanders at 0x20 and 0x21 have mixed 4-ch (FFLDAQ) and 12-ch (FFL12) pins) - present_0X20_F2, present_0X21_F2, present_FFLDAQ_0X20_F2, present_FFL12_0X20_F2, - present_FFLDAQ_0X21_F2, present_FFL12_0X21_F2 = 0; +uint32_t present_FFL4_F1, present_FFL12_F1, + // 4.06 I2C VU7P OPTICS (the I/O expanders at 0x20 and 0x21 have mixed 4-ch (ffl4) and 12-ch (FFL12) pins) + present_0X20_F2, present_0X21_F2, present_FFL4_0X20_F2, present_FFL12_0X20_F2, + present_FFL4_0X21_F2, present_FFL12_0X21_F2 = 0; #elif defined(REV2) // 4.05 I2C FPGA31 OPTICS -uint32_t present_FFLDAQ_F1, present_FFL12_F1, +uint32_t present_FFL4_F1, present_FFL12_F1, // 4.06 I2C FPGA2 OPTICS - present_FFLDAQ_F2, present_FFL12_F2 = 0; + present_FFL4_F2, present_FFL12_F2 = 0; #endif // REV2 void setFFmask(uint32_t ff_combined_present) @@ -87,14 +87,14 @@ void readFFpresent(void) apollo_i2c_ctl_reg_r(4, 0x20, 1, 0x01, 1, &present_FFL12_F1); // to port 6 apollo_i2c_ctl_w(4, 0x71, 1, 0x40); - apollo_i2c_ctl_reg_r(4, 0x21, 1, 0x00, 1, &present_FFLDAQ_F1); + apollo_i2c_ctl_reg_r(4, 0x21, 1, 0x00, 1, &present_FFL4_F1); #elif defined(REV2) // to port 7 apollo_i2c_ctl_w(4, 0x70, 1, 0x80); apollo_i2c_ctl_reg_r(4, 0x20, 1, 0x01, 1, &present_FFL12_F1); // to port 6 apollo_i2c_ctl_w(4, 0x71, 1, 0x40); - apollo_i2c_ctl_reg_r(4, 0x21, 1, 0x00, 1, &present_FFLDAQ_F1); + apollo_i2c_ctl_reg_r(4, 0x21, 1, 0x00, 1, &present_FFL4_F1); apollo_i2c_ctl_reg_r(4, 0x21, 1, 0x01, 1, &f1_ff12xmit_4v0_sel); // reading FPGA1 12-ch xmit FF's power-supply physical selection (i.e either 3.3v or 4.0v) #endif @@ -120,7 +120,7 @@ void readFFpresent(void) apollo_i2c_ctl_reg_r(3, 0x20, 1, 0x01, 1, &present_FFL12_F2); // to port 6 apollo_i2c_ctl_w(3, 0x71, 1, 0x40); - apollo_i2c_ctl_reg_r(3, 0x21, 1, 0x00, 1, &present_FFLDAQ_F2); + apollo_i2c_ctl_reg_r(3, 0x21, 1, 0x00, 1, &present_FFL4_F2); apollo_i2c_ctl_reg_r(3, 0x21, 1, 0x01, 1, &f2_ff12xmit_4v0_sel); // reading FPGA2 12-ch xmit FF's power-supply physical selection (i.e either 3.3v or 4.0v) #endif @@ -132,34 +132,34 @@ void readFFpresent(void) #ifdef REV1 uint32_t present_FFL12_BOTTOM_F1 = present_FFL12_F1 & 0x3FU; // bottom 6 bits uint32_t present_FFL12_TOP_F1 = (present_FFL12_F1 >> 6) & 0x3U; // top 2 bits - present_FFLDAQ_F1 = (present_FFLDAQ_F1 >> 5) & 0x7U; // bits 5-7 + present_FFL4_F1 = (present_FFL4_F1 >> 5) & 0x7U; // bits 5-7 present_FFL12_0X20_F2 = (present_0X20_F2 >> 6) & 0x3U; // bit 6-7 - present_FFLDAQ_0X20_F2 = present_0X20_F2 & 0x3FU; // bottom 6 bits + present_FFL4_0X20_F2 = present_0X20_F2 & 0x3FU; // bottom 6 bits present_FFL12_0X21_F2 = (present_0X21_F2 >> 4) & 0x3U; // bit 4-5 - present_FFLDAQ_0X21_F2 = (present_0X21_F2 >> 2) & 0xFU; // bit 4 bits + present_FFL4_0X21_F2 = (present_0X21_F2 >> 2) & 0xFU; // bit 4 bits uint32_t ff_combined_present = ((present_FFL12_0X21_F2) << 23) | // 2 bits ((present_FFL12_0X20_F2) << 21) | // 2 bits - ((present_FFLDAQ_0X21_F2) << 17) | // 4 bits - ((present_FFLDAQ_0X20_F2) << 11) | // 6 bits + ((present_FFL4_0X21_F2) << 17) | // 4 bits + ((present_FFL4_0X20_F2) << 11) | // 6 bits ((present_FFL12_TOP_F1) << 9) | // 2 bits - (present_FFLDAQ_F1) << 6 | // 3 bits + (present_FFL4_F1) << 6 | // 3 bits ((present_FFL12_BOTTOM_F1)); // 6 bits #elif defined(REV2) present_FFL12_F1 = present_FFL12_F1 & 0x3FU; // bottom 6 bits present_FFL12_F2 = present_FFL12_F2 & 0x3FU; // bottom 6 bits - present_FFLDAQ_F1 = (present_FFLDAQ_F1 >> 4) & 0xFU; // bits 4-7 - present_FFLDAQ_F2 = (present_FFLDAQ_F2 >> 4) & 0xFU; // bits 4-7 + present_FFL4_F1 = (present_FFL4_F1 >> 4) & 0xFU; // bits 4-7 + present_FFL4_F2 = (present_FFL4_F2 >> 4) & 0xFU; // bits 4-7 - uint32_t ff_combined_present = ((present_FFLDAQ_F2) << 16) | // 4 bits + uint32_t ff_combined_present = ((present_FFL4_F2) << 16) | // 4 bits ((present_FFL12_F2) << 10) | // 6 bits - (present_FFLDAQ_F1) << 6 | // 4 bits + (present_FFL4_F1) << 6 | // 4 bits ((present_FFL12_F1)); // 6 bits - ff_bitmask_args[1].present_bit_mask = (~present_FFLDAQ_F1) & 0xFU; // 4 bits + ff_bitmask_args[1].present_bit_mask = (~present_FFL4_F1) & 0xFU; // 4 bits ff_bitmask_args[0].present_bit_mask = (~present_FFL12_F1) & 0x3FU; // 6 bits - ff_bitmask_args[3].present_bit_mask = (~present_FFLDAQ_F2) & 0xFU; // 4 bits + ff_bitmask_args[3].present_bit_mask = (~present_FFL4_F2) & 0xFU; // 4 bits ff_bitmask_args[2].present_bit_mask = (~present_FFL12_F2) & 0x3FU; // 6 bits f1_ff12xmit_4v0_sel = (f1_ff12xmit_4v0_sel >> 4) & 0x7; // bits 4-6 @@ -187,9 +187,9 @@ unsigned isFFStale(void) TickType_t now = pdTICKS_TO_S(xTaskGetTickCount()); TickType_t last[4]; last[0] = pdTICKS_TO_S(ffl12_f1_args.updateTick); - last[1] = pdTICKS_TO_S(ffldaq_f1_args.updateTick); + last[1] = pdTICKS_TO_S(ffl4_f1_args.updateTick); last[2] = pdTICKS_TO_S(ffl12_f2_args.updateTick); - last[3] = pdTICKS_TO_S(ffldaq_f2_args.updateTick); + last[3] = pdTICKS_TO_S(ffl4_f2_args.updateTick); unsigned mask = 0U; for (int ff_t = 0; ff_t < 4; ++ff_t) { @@ -212,13 +212,13 @@ TickType_t getFFupdateTick(int mask) return ffl12_f1_args.updateTick; } else if (mask & 0x02U) { - return ffldaq_f1_args.updateTick; + return ffl4_f1_args.updateTick; } else if (mask & 0x04U) { return ffl12_f2_args.updateTick; } else { - return ffldaq_f2_args.updateTick; + return ffl4_f2_args.updateTick; } } @@ -233,8 +233,8 @@ uint16_t getFFtemp(const uint8_t i) } else if (NFIREFLIES_IT_F1 <= i && i < NFIREFLIES_IT_F1 + NFIREFLIES_DAQ_F1) { - int index = (i - NFIREFLIES_IT_F1) * (ffldaq_f1_args.n_commands * ffldaq_f1_args.n_pages) + i1; - val = ffldaq_f1_args.sm_values[index]; + int index = (i - NFIREFLIES_IT_F1) * (ffl4_f1_args.n_commands * ffl4_f1_args.n_pages) + i1; + val = ffl4_f1_args.sm_values[index]; } else if (NFIREFLIES_F1 <= i && i < NFIREFLIES_F1 + NFIREFLIES_IT_F2) { @@ -242,8 +242,8 @@ uint16_t getFFtemp(const uint8_t i) val = ffl12_f2_args.sm_values[index]; } else { - int index = (i - NFIREFLIES_F1 - NFIREFLIES_IT_F2) * (ffldaq_f2_args.n_commands * ffldaq_f2_args.n_pages) + i1; - val = ffldaq_f2_args.sm_values[index]; + int index = (i - NFIREFLIES_F1 - NFIREFLIES_IT_F2) * (ffl4_f2_args.n_commands * ffl4_f2_args.n_pages) + i1; + val = ffl4_f2_args.sm_values[index]; } return val; diff --git a/projects/cm_mcu/LocalTasks.c b/projects/cm_mcu/LocalTasks.c index b984546a..27c3eb98 100644 --- a/projects/cm_mcu/LocalTasks.c +++ b/projects/cm_mcu/LocalTasks.c @@ -28,7 +28,6 @@ #include "I2CCommunication.h" #include "common/log.h" -//convert_8_t tmp1; // local prototype void Print(const char *str); @@ -70,9 +69,9 @@ struct dev_moni2c_addr_t ff_moni2c_addrs[NFIREFLIES] = { struct arg_moni2c_ff_t ff_moni2c_arg[NFIREFLY_ARG] = { {"FFL12", &ffl12_f1_args, 0, 0, 6}, // - {"FFLDAQ", &ffldaq_f1_args, 6, 0, 3}, // + {"FFL4", &ffl4_f1_args, 6, 0, 3}, // {"FFL12", &ffl12_f1_args, 9, 6, 2}, // - {"FFLDAQ", &ffldaq_f2_args, 11, 0, 10}, // + {"FFL4", &ffl4_f2_args, 11, 0, 10}, // {"FFL12", &ffl12_f2_args, 21, 0, 4}, // }; @@ -108,9 +107,9 @@ struct dev_moni2c_addr_t ff_moni2c_addrs[NFIREFLIES] = { struct arg_moni2c_ff_t ff_moni2c_arg[NFIREFLY_ARG] = { {"FFL12", &ffl12_f1_args, 0, 0, 6}, // - {"FFLDAQ", &ffldaq_f1_args, 6, 0, 4}, // + {"FFL4", &ffl4_f1_args, 6, 0, 4}, // {"FFL12", &ffl12_f2_args, 10, 0, 6}, // - {"FFLDAQ", &ffldaq_f2_args, 16, 0, 4}, // + {"FFL4", &ffl4_f2_args, 16, 0, 4}, // }; #else #error "Define either Rev1 or Rev2" @@ -118,13 +117,13 @@ struct arg_moni2c_ff_t ff_moni2c_arg[NFIREFLY_ARG] = { // FFDAQ arguments for monitoring i2c task of 4-channel firefly ports connected to FPGA1 #ifdef REV1 -struct dev_moni2c_addr_t ffldaq_f1_moni2c_addrs[NFIREFLIES_DAQ_F1] = { +struct dev_moni2c_addr_t ffl4_f1_moni2c_addrs[NFIREFLIES_DAQ_F1] = { {"K04 4 XCVR GTY", FF_I2CMUX_2_ADDR, 0, 0x50}, // {"K05 4 XCVR GTY", FF_I2CMUX_2_ADDR, 1, 0x50}, // {"K06 4 XCVR GTY", FF_I2CMUX_2_ADDR, 2, 0x50}, // }; #elif defined(REV2) -struct dev_moni2c_addr_t ffldaq_f1_moni2c_addrs[NFIREFLIES_DAQ_F1] = { +struct dev_moni2c_addr_t ffl4_f1_moni2c_addrs[NFIREFLIES_DAQ_F1] = { {"F1_4 4 XCVR", FF_I2CMUX_1_ADDR, 2, 0x50}, // {"F1_5 4 XCVR", FF_I2CMUX_2_ADDR, 0, 0x50}, // {"F1_6 4 XCVR", FF_I2CMUX_2_ADDR, 1, 0x50}, // @@ -134,7 +133,7 @@ struct dev_moni2c_addr_t ffldaq_f1_moni2c_addrs[NFIREFLIES_DAQ_F1] = { #error "Define either Rev1 or Rev2" #endif -struct sm_command_t sm_command_ffldaq_f1[] = { +struct sm_command_t sm_command_ffl4_f1[] = { {1, 0x00, 0x02, 2, "FF_STATUS_REG", 0xff, "", PM_STATUS}, {1, 0x00, 0x16, 2, "FF_TEMPERATURE", 0xff, "C", PM_STATUS}, {1, 0x00, 0x03, 1, "FF_LOS_ALARM", 0xff, "", PM_STATUS}, @@ -145,19 +144,19 @@ struct sm_command_t sm_command_ffldaq_f1[] = { {2, 0x00, 0x28, 2, "FF_CH04_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, }; -uint16_t ffldaq_f1_values[NDEVICES_FFLDAQ_F1 * NCOMMANDS_FFLDAQ_F1]; +uint16_t ffl4_f1_values[NDEVICES_FFL4_F1 * NCOMMANDS_FFL4_F1]; -struct MonitorI2CTaskArgs_t ffldaq_f1_args = { +struct MonitorI2CTaskArgs_t ffl4_f1_args = { .name = "F1_4", - .devices = ffldaq_f1_moni2c_addrs, + .devices = ffl4_f1_moni2c_addrs, .i2c_dev = I2C_DEVICE_F1, - .n_devices = NDEVICES_FFLDAQ_F1, - .commands = sm_command_ffldaq_f1, - .n_commands = NCOMMANDS_FFLDAQ_F1, - .n_values = NDEVICES_FFLDAQ_F1 * NPAGES_FFLDAQ_F1 * NCOMMANDS_FFLDAQ_F1, - .n_pages = NPAGES_FFLDAQ_F1, + .n_devices = NDEVICES_FFL4_F1, + .commands = sm_command_ffl4_f1, + .n_commands = NCOMMANDS_FFL4_F1, + .n_values = NDEVICES_FFL4_F1 * NPAGES_FFL4_F1 * NCOMMANDS_FFL4_F1, + .n_pages = NPAGES_FFL4_F1, .selpage_reg = FF_SELPAGE_REG, - .sm_values = ffldaq_f1_values, + .sm_values = ffl4_f1_values, .smbus = &g_sMaster4, .smbus_status = &eStatus4, .xSem = NULL, @@ -257,7 +256,7 @@ struct MonitorI2CTaskArgs_t ffl12_f1_args = { // FFDAQV arguments for monitoring i2c task of 4-channel firefly ports connected to FPGA2 #ifdef REV1 -struct dev_moni2c_addr_t ffldaq_f2_moni2c_addrs[NFIREFLIES_DAQ_F2] = { +struct dev_moni2c_addr_t ffl4_f2_moni2c_addrs[NFIREFLIES_DAQ_F2] = { {"V01 4 XCVR GTY", FF_I2CMUX_1_ADDR, 0, 0x50}, // {"V02 4 XCVR GTY", FF_I2CMUX_1_ADDR, 1, 0x50}, // {"V03 4 XCVR GTY", FF_I2CMUX_1_ADDR, 2, 0x50}, // @@ -270,7 +269,7 @@ struct dev_moni2c_addr_t ffldaq_f2_moni2c_addrs[NFIREFLIES_DAQ_F2] = { {"V10 4 XCVR GTY", FF_I2CMUX_2_ADDR, 3, 0x50}, // }; #elif defined(REV2) -struct dev_moni2c_addr_t ffldaq_f2_moni2c_addrs[NFIREFLIES_DAQ_F2] = { +struct dev_moni2c_addr_t ffl4_f2_moni2c_addrs[NFIREFLIES_DAQ_F2] = { {"F2_4 4 XCVR", FF_I2CMUX_1_ADDR, 2, 0x50}, // {"F2_5 4 XCVR", FF_I2CMUX_2_ADDR, 0, 0x50}, // {"F2_6 4 XCVR", FF_I2CMUX_2_ADDR, 1, 0x50}, // @@ -280,7 +279,7 @@ struct dev_moni2c_addr_t ffldaq_f2_moni2c_addrs[NFIREFLIES_DAQ_F2] = { #error "Define either Rev1 or Rev2" #endif -struct sm_command_t sm_command_ffldaq_f2[] = { +struct sm_command_t sm_command_ffl4_f2[] = { {1, 0x00, 0x02, 2, "FF_STATUS_REG", 0xff, "", PM_STATUS}, {1, 0x00, 0x16, 2, "FF_TEMPERATURE", 0xff, "C", PM_STATUS}, {1, 0x00, 0x03, 1, "FF_LOS_ALARM", 0xff, "", PM_STATUS}, @@ -290,19 +289,19 @@ struct sm_command_t sm_command_ffldaq_f2[] = { {2, 0x00, 0x26, 2, "FF_CH03_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, {2, 0x00, 0x28, 2, "FF_CH04_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, }; -uint16_t ffldaq_f2_values[NDEVICES_FFLDAQ_F2 * NCOMMANDS_FFLDAQ_F2]; +uint16_t ffl4_f2_values[NDEVICES_FFL4_F2 * NCOMMANDS_FFL4_F2]; -struct MonitorI2CTaskArgs_t ffldaq_f2_args = { +struct MonitorI2CTaskArgs_t ffl4_f2_args = { .name = "F2_4", - .devices = ffldaq_f2_moni2c_addrs, + .devices = ffl4_f2_moni2c_addrs, .i2c_dev = I2C_DEVICE_F2, - .n_devices = NDEVICES_FFLDAQ_F2, - .commands = sm_command_ffldaq_f2, - .n_commands = NCOMMANDS_FFLDAQ_F2, - .n_values = NDEVICES_FFLDAQ_F2 * NPAGES_FFLDAQ_F2 * NCOMMANDS_FFLDAQ_F2, - .n_pages = NPAGES_FFLDAQ_F2, + .n_devices = NDEVICES_FFL4_F2, + .commands = sm_command_ffl4_f2, + .n_commands = NCOMMANDS_FFL4_F2, + .n_values = NDEVICES_FFL4_F2 * NPAGES_FFL4_F2 * NCOMMANDS_FFL4_F2, + .n_pages = NPAGES_FFL4_F2, .selpage_reg = FF_SELPAGE_REG, - .sm_values = ffldaq_f2_values, + .sm_values = ffl4_f2_values, .smbus = &g_sMaster3, .smbus_status = &eStatus3, .xSem = NULL, @@ -481,6 +480,7 @@ struct MonitorI2CTaskArgs_t clockr0a_args = { }; #endif // REV2 +#if 0 void setFFmask(uint32_t ff_combined_present) { @@ -520,14 +520,14 @@ void readFFpresent(void) apollo_i2c_ctl_reg_r(4, 0x20, 1, 0x01, 1, &present_FFL12_F1); // to port 6 apollo_i2c_ctl_w(4, 0x71, 1, 0x40); - apollo_i2c_ctl_reg_r(4, 0x21, 1, 0x00, 1, &present_FFLDAQ_F1); + apollo_i2c_ctl_reg_r(4, 0x21, 1, 0x00, 1, &present_FFL4_F1); #elif defined(REV2) // to port 7 apollo_i2c_ctl_w(4, 0x70, 1, 0x80); apollo_i2c_ctl_reg_r(4, 0x20, 1, 0x01, 1, &present_FFL12_F1); // to port 6 apollo_i2c_ctl_w(4, 0x71, 1, 0x40); - apollo_i2c_ctl_reg_r(4, 0x21, 1, 0x00, 1, &present_FFLDAQ_F1); + apollo_i2c_ctl_reg_r(4, 0x21, 1, 0x00, 1, &present_FFL4_F1); apollo_i2c_ctl_reg_r(4, 0x21, 1, 0x01, 1, &f1_ff12xmit_4v0_sel); // reading FPGA1 12-ch xmit FF's power-supply physical selection (i.e either 3.3v or 4.0v) #endif @@ -553,7 +553,7 @@ void readFFpresent(void) apollo_i2c_ctl_reg_r(3, 0x20, 1, 0x01, 1, &present_FFL12_F2); // to port 6 apollo_i2c_ctl_w(3, 0x71, 1, 0x40); - apollo_i2c_ctl_reg_r(3, 0x21, 1, 0x00, 1, &present_FFLDAQ_F2); + apollo_i2c_ctl_reg_r(3, 0x21, 1, 0x00, 1, &present_FFL4_F2); apollo_i2c_ctl_reg_r(3, 0x21, 1, 0x01, 1, &f2_ff12xmit_4v0_sel); // reading FPGA2 12-ch xmit FF's power-supply physical selection (i.e either 3.3v or 4.0v) #endif @@ -565,34 +565,34 @@ void readFFpresent(void) #ifdef REV1 uint32_t present_FFL12_BOTTOM_F1 = present_FFL12_F1 & 0x3FU; // bottom 6 bits uint32_t present_FFL12_TOP_F1 = (present_FFL12_F1 >> 6) & 0x3U; // top 2 bits - present_FFLDAQ_F1 = (present_FFLDAQ_F1 >> 5) & 0x7U; // bits 5-7 + present_FFL4_F1 = (present_FFL4_F1 >> 5) & 0x7U; // bits 5-7 present_FFL12_0X20_F2 = (present_0X20_F2 >> 6) & 0x3U; // bit 6-7 - present_FFLDAQ_0X20_F2 = present_0X20_F2 & 0x3FU; // bottom 6 bits + present_FFL4_0X20_F2 = present_0X20_F2 & 0x3FU; // bottom 6 bits present_FFL12_0X21_F2 = (present_0X21_F2 >> 4) & 0x3U; // bit 4-5 - present_FFLDAQ_0X21_F2 = (present_0X21_F2 >> 2) & 0xFU; // bit 4 bits + present_FFL4_0X21_F2 = (present_0X21_F2 >> 2) & 0xFU; // bit 4 bits uint32_t ff_combined_present = ((present_FFL12_0X21_F2) << 23) | // 2 bits ((present_FFL12_0X20_F2) << 21) | // 2 bits - ((present_FFLDAQ_0X21_F2) << 17) | // 4 bits - ((present_FFLDAQ_0X20_F2) << 11) | // 6 bits + ((present_FFL4_0X21_F2) << 17) | // 4 bits + ((present_FFL4_0X20_F2) << 11) | // 6 bits ((present_FFL12_TOP_F1) << 9) | // 2 bits - (present_FFLDAQ_F1) << 6 | // 3 bits + (present_FFL4_F1) << 6 | // 3 bits ((present_FFL12_BOTTOM_F1)); // 6 bits #elif defined(REV2) present_FFL12_F1 = present_FFL12_F1 & 0x3FU; // bottom 6 bits present_FFL12_F2 = present_FFL12_F2 & 0x3FU; // bottom 6 bits - present_FFLDAQ_F1 = (present_FFLDAQ_F1 >> 4) & 0xFU; // bits 4-7 - present_FFLDAQ_F2 = (present_FFLDAQ_F2 >> 4) & 0xFU; // bits 4-7 + present_FFL4_F1 = (present_FFL4_F1 >> 4) & 0xFU; // bits 4-7 + present_FFL4_F2 = (present_FFL4_F2 >> 4) & 0xFU; // bits 4-7 - uint32_t ff_combined_present = ((present_FFLDAQ_F2) << 16) | // 4 bits + uint32_t ff_combined_present = ((present_FFL4_F2) << 16) | // 4 bits ((present_FFL12_F2) << 10) | // 6 bits - (present_FFLDAQ_F1) << 6 | // 4 bits + (present_FFL4_F1) << 6 | // 4 bits ((present_FFL12_F1)); // 6 bits - ff_bitmask_args[1].present_bit_mask = (~present_FFLDAQ_F1) & 0xFU; // 4 bits + ff_bitmask_args[1].present_bit_mask = (~present_FFL4_F1) & 0xFU; // 4 bits ff_bitmask_args[0].present_bit_mask = (~present_FFL12_F1) & 0x3FU; // 6 bits - ff_bitmask_args[3].present_bit_mask = (~present_FFLDAQ_F2) & 0xFU; // 4 bits + ff_bitmask_args[3].present_bit_mask = (~present_FFL4_F2) & 0xFU; // 4 bits ff_bitmask_args[2].present_bit_mask = (~present_FFL12_F2) & 0x3FU; // 6 bits f1_ff12xmit_4v0_sel = (f1_ff12xmit_4v0_sel >> 4) & 0x7; // bits 4-6 @@ -620,9 +620,9 @@ unsigned isFFStale(void) TickType_t now = pdTICKS_TO_S(xTaskGetTickCount()); TickType_t last[4]; last[0] = pdTICKS_TO_S(ffl12_f1_args.updateTick); - last[1] = pdTICKS_TO_S(ffldaq_f1_args.updateTick); + last[1] = pdTICKS_TO_S(ffl4_f1_args.updateTick); last[2] = pdTICKS_TO_S(ffl12_f2_args.updateTick); - last[3] = pdTICKS_TO_S(ffldaq_f2_args.updateTick); + last[3] = pdTICKS_TO_S(ffl4_f2_args.updateTick); unsigned mask = 0U; for (int ff_t = 0; ff_t < 4; ++ff_t) { @@ -645,13 +645,13 @@ TickType_t getFFupdateTick(int mask) return ffl12_f1_args.updateTick; } else if (mask & 0x02U) { - return ffldaq_f1_args.updateTick; + return ffl4_f1_args.updateTick; } else if (mask & 0x04U) { return ffl12_f2_args.updateTick; } else { - return ffldaq_f2_args.updateTick; + return ffl4_f2_args.updateTick; } } @@ -666,8 +666,8 @@ uint16_t getFFtemp(const uint8_t i) } else if (NFIREFLIES_IT_F1 <= i && i < NFIREFLIES_IT_F1 + NFIREFLIES_DAQ_F1) { - int index = (i - NFIREFLIES_IT_F1) * (ffldaq_f1_args.n_commands * ffldaq_f1_args.n_pages) + i1; - val = ffldaq_f1_args.sm_values[index]; + int index = (i - NFIREFLIES_IT_F1) * (ffl4_f1_args.n_commands * ffl4_f1_args.n_pages) + i1; + val = ffl4_f1_args.sm_values[index]; } else if (NFIREFLIES_F1 <= i && i < NFIREFLIES_F1 + NFIREFLIES_IT_F2) { @@ -675,8 +675,8 @@ uint16_t getFFtemp(const uint8_t i) val = ffl12_f2_args.sm_values[index]; } else { - int index = (i - NFIREFLIES_F1 - NFIREFLIES_IT_F2) * (ffldaq_f2_args.n_commands * ffldaq_f2_args.n_pages) + i1; - val = ffldaq_f2_args.sm_values[index]; + int index = (i - NFIREFLIES_F1 - NFIREFLIES_IT_F2) * (ffl4_f2_args.n_commands * ffl4_f2_args.n_pages) + i1; + val = ffl4_f2_args.sm_values[index]; } return val; @@ -724,7 +724,7 @@ void getFFpart(void) SemaphoreHandle_t semaphores[2] = {i2c4_sem, i2c3_sem}; const int ff_ndev_offset[2] = {0, NFIREFLIES_IT_F1 + NFIREFLIES_DAQ_F1}; - const uint32_t ndevices[2] = {NSUPPLIES_FFL12_F1 / 2, NSUPPLIES_FFL12_F2 / 2}; + const uint32_t ndevices[2] = {NDEVICES_FFL12_F1 / 2, NDEVICES_FFL12_F2 / 2}; const uint32_t dev_present_mask[2] = {present_FFL12_F1, present_FFL12_F2}; const uint32_t dev_xmit_4v0_sel[2] = {f1_ff12xmit_4v0_sel, f2_ff12xmit_4v0_sel}; @@ -759,6 +759,7 @@ void getFFpart(void) vendor_data_rxch[j] = (vendor_char_rxch >> (3 - j) * 8) & 0xFF; } + convert_8_t tmp1; tmp1.us = vendor_data_rxch[3]; // change from uint_8 to int8_t, preserving bit pattern vendor_part_rxch[i - VENDOR_START_BIT_FF12] = tmp1.s; vendor_part_rxch[i - VENDOR_START_BIT_FF12 + 1] = '\0'; // null-terminated @@ -824,6 +825,7 @@ void getFFpart(void) } } #endif +#endif #define FPGA_MON_NDEVICES_PER_FPGA 2 #define FPGA_MON_NFPGA 2 diff --git a/projects/cm_mcu/MonitorI2CTask.c b/projects/cm_mcu/MonitorI2CTask.c index 4f5fb5c3..ed82bd7d 100644 --- a/projects/cm_mcu/MonitorI2CTask.c +++ b/projects/cm_mcu/MonitorI2CTask.c @@ -113,7 +113,7 @@ void MonitorI2CTask(void *parameters) if (args->i2c_dev == I2C_DEVICE_F1) { // FPGA #1 #ifdef REV1 int NFIREFLIES_IT_F1_P1 = NFIREFLIES_IT_F1 - 2; - if (!isEnabledFF((IsFFDAQ * (thisdev + NFIREFLIES_IT_F1_P1)) + (IsFF12 * (thisdev < NFIREFLIES_IT_F1 - 3) * (thisdev)) + (IsFF12 * (thisdev > NFIREFLIES_IT_F1 - 3) * (thisdev + NFIREFLIES_DAQ_F1)))) // skip the FF if it's not enabled via the FF config + if (!isEnabledFF((IsFFDAQ * (device + NFIREFLIES_IT_F1_P1)) + (IsFF12 * (device < NFIREFLIES_IT_F1 - 3) * (device)) + (IsFF12 * (device > NFIREFLIES_IT_F1 - 3) * (device + NFIREFLIES_DAQ_F1)))) // skip the FF if it's not enabled via the FF config continue; #elif defined(REV2) if (!isEnabledFF((IsFFDAQ * (device + NFIREFLIES_IT_F1)) + (IsFF12 * (device)))) // skip the FF if it's not enabled via the FF config @@ -124,7 +124,7 @@ void MonitorI2CTask(void *parameters) } if (args->i2c_dev == I2C_DEVICE_F2) { // FPGA #2 #ifdef REV1 - if (!isEnabledFF(NFIREFLIES_F1 + (IsFFDAQ * (thisdev)) + (IsFF12 * (thisdev + NFIREFLIES_DAQ_F2)))) // skip the FF if it's not enabled via the FF config + if (!isEnabledFF(NFIREFLIES_F1 + (IsFFDAQ * (device)) + (IsFF12 * (device + NFIREFLIES_DAQ_F2)))) // skip the FF if it's not enabled via the FF config continue; #elif defined(REV2) if (!isEnabledFF(NFIREFLIES_F1 + (IsFFDAQ * (device + NFIREFLIES_IT_F2)) + (IsFF12 * (device)))) // skip the FF if it's not enabled via the FF config diff --git a/projects/cm_mcu/MonitorI2CTask.h b/projects/cm_mcu/MonitorI2CTask.h index 7b60bc98..2b4c5f6b 100644 --- a/projects/cm_mcu/MonitorI2CTask.h +++ b/projects/cm_mcu/MonitorI2CTask.h @@ -52,12 +52,12 @@ struct MonitorI2CTaskArgs_t { #define CLK_SELPAGE_REG 0x1 #ifndef REV2 -#define NDEVICES_FFLDAQ_F1 (3) +#define NDEVICES_FFL4_F1 (3) #else // REV2 -#define NDEVICES_FFLDAQ_F1 (4) +#define NDEVICES_FFL4_F1 (4) #endif // REV 2 -#define NCOMMANDS_FFLDAQ_F1 8 // number of commands -#define NPAGES_FFLDAQ_F1 1 // number of pages on the 4-channel firefly ports +#define NCOMMANDS_FFL4_F1 8 // number of commands +#define NPAGES_FFL4_F1 1 // number of pages on the 4-channel firefly ports #ifndef REV2 #define NDEVICES_FFL12_F1 (8) @@ -68,12 +68,12 @@ struct MonitorI2CTaskArgs_t { #define NPAGES_FFL12_F1 1 // number of pages on the 12-channel firefly ports #ifndef REV2 -#define NDEVICES_FFLDAQ_F2 (10) +#define NDEVICES_FFL4_F2 (10) #else // REV1 -#define NDEVICES_FFLDAQ_F2 (4) +#define NDEVICES_FFL4_F2 (4) #endif // REV 2 -#define NCOMMANDS_FFLDAQ_F2 8 // number of commands -#define NPAGES_FFLDAQ_F2 1 // number of pages on the 4-channel firefly ports +#define NCOMMANDS_FFL4_F2 8 // number of commands +#define NPAGES_FFL4_F2 1 // number of pages on the 4-channel firefly ports #ifndef REV2 #define NDEVICES_FFL12_F2 (4) @@ -84,13 +84,13 @@ struct MonitorI2CTaskArgs_t { #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]; -extern struct dev_moni2c_addr_t ffldaq_f1_moni2c_addrs[NFIREFLIES_DAQ_F1]; +extern struct dev_moni2c_addr_t ffl4_f1_moni2c_addrs[NFIREFLIES_DAQ_F1]; extern struct dev_moni2c_addr_t ffl12_f2_moni2c_addrs[NFIREFLIES_IT_F2]; -extern struct dev_moni2c_addr_t ffldaq_f2_moni2c_addrs[NFIREFLIES_DAQ_F2]; +extern struct dev_moni2c_addr_t ffl4_f2_moni2c_addrs[NFIREFLIES_DAQ_F2]; extern struct MonitorI2CTaskArgs_t ffl12_f1_args; -extern struct MonitorI2CTaskArgs_t ffldaq_f1_args; +extern struct MonitorI2CTaskArgs_t ffl4_f1_args; extern struct MonitorI2CTaskArgs_t ffl12_f2_args; -extern struct MonitorI2CTaskArgs_t ffldaq_f2_args; +extern struct MonitorI2CTaskArgs_t ffl4_f2_args; #define NDEVICES_CLK (4) #define NCOMMANDS_CLK 7 // number of commands diff --git a/projects/cm_mcu/cm_mcu.c b/projects/cm_mcu/cm_mcu.c index a5218da8..2819075a 100644 --- a/projects/cm_mcu/cm_mcu.c +++ b/projects/cm_mcu/cm_mcu.c @@ -254,9 +254,9 @@ __attribute__((noreturn)) int main(void) dcdc_args.xSem = i2c1_sem; fpga_args.xSem = i2c5_sem; ffl12_f1_args.xSem = i2c4_sem; - ffldaq_f1_args.xSem = i2c4_sem; + ffl4_f1_args.xSem = i2c4_sem; ffl12_f2_args.xSem = i2c3_sem; - ffldaq_f2_args.xSem = i2c3_sem; + ffl4_f2_args.xSem = i2c3_sem; #ifdef REV2 clock_args.xSem = i2c2_sem; clockr0a_args.xSem = i2c2_sem; @@ -301,11 +301,11 @@ __attribute__((noreturn)) int main(void) xTaskCreate(MonitorI2CTask, ffl12_f1_args.name, 2 * configMINIMAL_STACK_SIZE, &ffl12_f1_args, tskIDLE_PRIORITY + 4, NULL); - xTaskCreate(MonitorI2CTask, ffldaq_f1_args.name, 2 * configMINIMAL_STACK_SIZE, &ffldaq_f1_args, tskIDLE_PRIORITY + 4, + xTaskCreate(MonitorI2CTask, ffl4_f1_args.name, 2 * configMINIMAL_STACK_SIZE, &ffl4_f1_args, tskIDLE_PRIORITY + 4, NULL); xTaskCreate(MonitorI2CTask, ffl12_f2_args.name, 2 * configMINIMAL_STACK_SIZE, &ffl12_f2_args, tskIDLE_PRIORITY + 4, NULL); - xTaskCreate(MonitorI2CTask, ffldaq_f2_args.name, 2 * configMINIMAL_STACK_SIZE, &ffldaq_f2_args, tskIDLE_PRIORITY + 4, + xTaskCreate(MonitorI2CTask, ffl4_f2_args.name, 2 * configMINIMAL_STACK_SIZE, &ffl4_f2_args, tskIDLE_PRIORITY + 4, NULL); #ifdef REV2 From a66a61cfe4bcceccb13b6d27c9e96e62f379b80e Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Mon, 6 May 2024 12:51:36 -0400 Subject: [PATCH 06/71] header file cleanup and snprintf --- projects/cm_mcu/ZynqMonTask.c | 34 +++++++++++++----------- projects/cm_mcu/commands/SensorControl.c | 6 ++--- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/projects/cm_mcu/ZynqMonTask.c b/projects/cm_mcu/ZynqMonTask.c index 2e92553e..76a261e3 100644 --- a/projects/cm_mcu/ZynqMonTask.c +++ b/projects/cm_mcu/ZynqMonTask.c @@ -19,12 +19,14 @@ #ifdef REV1 #include "common/softuart.h" +#include "driverlib/timer.h" +#include "driverlib/gpio.h" +#include "inc/hw_ints.h" #endif #include "Tasks.h" #include "MonitorTask.h" #include "MonitorI2CTask.h" -#include "commands/SensorControl.h" #include "clocksynth.h" #include "common/log.h" @@ -152,8 +154,8 @@ void InitSUART(void) // Enable the GPIO modules that contains the GPIO pins to be used by // the software UART. // - // MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); - // MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); + // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); + // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); // // Configure the software UART module: 8 data bits, no parity, and one // stop bit. @@ -170,33 +172,33 @@ void InitSUART(void) // UART. The interface in this example is run at 38,400 baud, // requiring a timer tick at 38,400 Hz. // - MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); - MAP_TimerConfigure(TIMER0_BASE, + ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); + ROM_TimerConfigure(TIMER0_BASE, (TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PERIODIC | TIMER_CFG_B_PERIODIC)); - MAP_TimerLoadSet(TIMER0_BASE, TIMER_A, g_ulBitTime); - MAP_TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT | TIMER_TIMB_TIMEOUT); - MAP_TimerEnable(TIMER0_BASE, TIMER_A); + ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, g_ulBitTime); + ROM_TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT | TIMER_TIMB_TIMEOUT); + ROM_TimerEnable(TIMER0_BASE, TIMER_A); // // Set the priorities of the interrupts associated with the software // UART. The receiver is higher priority than the transmitter, and the // receiver edge interrupt is higher priority than the receiver timer // interrupt. // - // MAP_IntPrioritySet(INT_GPIOE, 0x00); - // MAP_IntPrioritySet(INT_TIMER0B, 0x40); + // ROM_IntPrioritySet(INT_GPIOE, 0x00); + // ROM_IntPrioritySet(INT_TIMER0B, 0x40); // 0x80 corresponds to 4 << (8-5) // Remember that on the TM4C only 3 highest bits // are used for setting interrupt priority, and numerically lower // values are logically higher. // this is lower that configMAX_SYSCALL_INTERRUPT_PRIORITY but the ISR // does not call any FreeRTOS functions so this will work. - MAP_IntPrioritySet(INT_TIMER0A, 0x80); // THIS NEEDS TO BE at a HIGH PRIORITY!!!! DONOT CHANGE + ROM_IntPrioritySet(INT_TIMER0A, 0x80); // THIS NEEDS TO BE at a HIGH PRIORITY!!!! DONOT CHANGE // // Enable the interrupts associated with the software UART. // - // MAP_IntEnable(INT_GPIOE); - // MAP_IntEnable(INT_TIMER0A); - // MAP_IntEnable(INT_TIMER0B); + // ROM_IntEnable(INT_GPIOE); + // ROM_IntEnable(INT_TIMER0A); + // ROM_IntEnable(INT_TIMER0B); // // Enable the transmit FIFO half full interrupt in the software UART. @@ -655,7 +657,7 @@ void ZynqMonTask(void *parameters) if (enable) { #ifdef REV1 // Enable the interrupts during transmission - MAP_IntEnable(INT_TIMER0A); + ROM_IntEnable(INT_TIMER0A); #endif // REV1 if (inTestMode) { @@ -701,7 +703,7 @@ void ZynqMonTask(void *parameters) while (g_sUART.ui16TxBufferRead != g_sUART.ui16TxBufferWrite) vTaskDelay(pdMS_TO_TICKS(10)); - MAP_IntDisable(INT_TIMER0A); + ROM_IntDisable(INT_TIMER0A); #endif // REV1 } // if ( enabled) diff --git a/projects/cm_mcu/commands/SensorControl.c b/projects/cm_mcu/commands/SensorControl.c index 000f6b71..ee6f8f43 100644 --- a/projects/cm_mcu/commands/SensorControl.c +++ b/projects/cm_mcu/commands/SensorControl.c @@ -591,7 +591,7 @@ BaseType_t ff_reset(int argc, char **argv, char *m) copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%s: error %d\r\n", argv[0], ret); } else { - copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%s: reset complete F%d\r\n", argv[0], which_fpga); + copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%s: reset complete F%ld\r\n", argv[0], which_fpga); } return pdFALSE; } @@ -626,7 +626,7 @@ BaseType_t ff_mux_reset(int argc, char **argv, char *m) if (xSemaphoreGetMutexHolder(s) == xTaskGetCurrentTaskHandle()) xSemaphoreGive(s); - copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%s: mux reset complete F%d\r\n", argv[0], which_fpga); + copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%s: mux reset complete F%ld\r\n", argv[0], which_fpga); return pdFALSE; } #endif // REV2 @@ -661,7 +661,7 @@ BaseType_t ff_status(int argc, char **argv, char *m) extern struct ff_bit_mask_t ff_bitmask_args[4]; char *ff_bitmask_names[4] = {"1_12", "1_4 ", "2_12", "2_4 "}; for (int i = 0; i < 4; ++i) { - copied += snprintf(m + copied, SCRATCH_SIZE - copied, "F%s: 0x%02x\r\n", ff_bitmask_names[i], + copied += snprintf(m + copied, SCRATCH_SIZE - copied, "F%s: 0x%02lx\r\n", ff_bitmask_names[i], ff_bitmask_args[i].present_bit_mask); } } From bb96d61e4694ad36a659410dcfa7dcad00e54476 Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Mon, 6 May 2024 15:46:33 -0400 Subject: [PATCH 07/71] code cleanup, intermediate --- .gitignore | 1 + Makefile | 11 +++ projects/cm_mcu/FireflyUtils.c | 2 +- projects/cm_mcu/Makefile | 28 ++++++-- projects/cm_mcu/MonitorI2CTask.c | 2 +- projects/cm_mcu/MonitorI2CTask.h | 9 +++ projects/cm_mcu/commands/BoardCommands.c | 2 +- sm_cm_config/data/MON_I2C_rev2.yml | 43 +++++++++++ sm_cm_config/src/mon_generate.py | 92 ++++++++++++++++++++++++ 9 files changed, 181 insertions(+), 9 deletions(-) create mode 100644 sm_cm_config/data/MON_I2C_rev2.yml create mode 100755 sm_cm_config/src/mon_generate.py diff --git a/.gitignore b/.gitignore index 20c60e81..84713da5 100644 --- a/.gitignore +++ b/.gitignore @@ -65,3 +65,4 @@ projects/cm_mcu/ZynqMon_addresses.c projects/cm_mcu/ZynqMon_addresses.h PL_MEM_CM_rev1.xml PL_MEM_CM_rev2.xml +projects/cm_mcu/MonI2C_addresses.c diff --git a/Makefile b/Makefile index 9d534072..78a175ca 100644 --- a/Makefile +++ b/Makefile @@ -38,4 +38,15 @@ check-and-reinit-submodules: release: @$(MAKE) -C projects/cm_mcu release +check-for-pr: format + @./buildall.sh + + +# 2nd dollar sign in grep is to pass along a single dollar sign to make +format: + run-clang-format.py $(shell git diff --name-only master | egrep '.[ch]$$') + +format-apply: + run-clang-format.py -i $(shell git diff --name-only master | egrep '.[ch]$$') + .PHONY: all clean $(DIRS) $(DIRSCLEAN) check-and-reinit-submodules diff --git a/projects/cm_mcu/FireflyUtils.c b/projects/cm_mcu/FireflyUtils.c index 4de2283b..dcef8ab7 100644 --- a/projects/cm_mcu/FireflyUtils.c +++ b/projects/cm_mcu/FireflyUtils.c @@ -307,7 +307,7 @@ void getFFpart(void) acquireI2CSemaphoreBlock(semaphores[f]); uint32_t tmp_ffpart_bit_mask = 0U; bool detect_ff = false; - for (uint8_t n = 0; n < ndevices[f]; n++) { + for (uint32_t n = 0; n < ndevices[f]; n++) { uint8_t vendor_data_rxch[4]; int8_t vendor_part_rxch[17]; diff --git a/projects/cm_mcu/Makefile b/projects/cm_mcu/Makefile index 9571ee42..e168f5c6 100644 --- a/projects/cm_mcu/Makefile +++ b/projects/cm_mcu/Makefile @@ -91,12 +91,12 @@ ${COMPILER}: @mkdir -p ${COMPILER} ## Zynq address table -- MCU code -YAML_FILES=$(wildcard ${ROOT}/sm_cm_config/data/*.yml) +ZYNQMON_YAML_FILES=$(wildcard ${ROOT}/sm_cm_config/data/PL_MEM*.yml) # # for building tar files in a release # -release: ${YAML_FILES} - @for f in ${YAML_FILES}; do \ +release: ${ZYNQMON_YAML_FILES} + @for f in ${ZYNQMON_YAML_FILES}; do \ if [ 'x${VERBOSE}' = x ]; then \ echo " PY $(notdir $$f)"; \ else \ @@ -108,14 +108,29 @@ release: ${YAML_FILES} # # Zynq address table -- MCU code # -ZynqMon_addresses.c ZynqMon_addresses.h &: ${YAML_FILES} +ZynqMon_addresses.c ZynqMon_addresses.h &: ${ZYNQMON_YAML_FILES} @if [ 'x${VERBOSE}' = x ]; \ then \ echo " PY $(notdir $?)"; \ else \ - echo ${ROOT}/sm_cm_config/src/mcu_generate.py -o $@ ${YAML_FILES}; \ + echo ${ROOT}/sm_cm_config/src/mcu_generate.py -o $@ ${ZYNQMON_YAML_FILES}; \ fi - @python ${ROOT}/sm_cm_config/src/mcu_generate.py -o $@ ${YAML_FILES} + @python ${ROOT}/sm_cm_config/src/mcu_generate.py -o $@ ${ZYNQMON_YAML_FILES} + +# +# Rules for building the MonI2C_address.c file +# +MONI2C_YAML_FILES=$(wildcard ${ROOT}/sm_cm_config/data/MON_I2C*.yml) + +MonI2C_addresses.c: ${MONI2C_YAML_FILES} + @if [ 'x${VERBOSE}' = x ]; \ + then \ + echo " PY $(notdir $?)"; \ + else \ + echo ${ROOT}/sm_cm_config/src/mon_generate.py -o $@ ${MONI2C_YAML_FILES}; \ + fi + @python ${ROOT}/sm_cm_config/src/mon_generate.py -o $@ ${MONI2C_YAML_FILES} + # these rules are required to force the generation of the ZynqMon_addresses.c # and .h file. The second one depends on the .h file only, but putting that @@ -156,6 +171,7 @@ ${COMPILER}/cm_mcu.axf: ${COMPILER}/AlarmUtilities.o ${COMPILER}/cm_mcu.axf: ${COMPILER}/LedTask.o ${COMPILER}/cm_mcu.axf: ${COMPILER}/microrl.o ${COMPILER}/cm_mcu.axf: ${COMPILER}/ZynqMon_addresses.o +${COMPILER}/cm_mcu.axf: ${COMPILER}/MonI2C_addresses.o ${COMPILER}/cm_mcu.axf: ${COMPILER}/ZynqMonTask.o ${COMPILER}/cm_mcu.axf: ${COMPILER}/InterruptHandlers.o ${COMPILER}/cm_mcu.axf: ${COMPILER}/InitTask.o diff --git a/projects/cm_mcu/MonitorI2CTask.c b/projects/cm_mcu/MonitorI2CTask.c index ed82bd7d..0e14425a 100644 --- a/projects/cm_mcu/MonitorI2CTask.c +++ b/projects/cm_mcu/MonitorI2CTask.c @@ -14,7 +14,7 @@ #include // FreeRTOS -#include "FreeRTOS.h" +#include "FreeRTOS.h" // IWYU pragma: keep #include "FreeRTOSConfig.h" #include "task.h" diff --git a/projects/cm_mcu/MonitorI2CTask.h b/projects/cm_mcu/MonitorI2CTask.h index 2b4c5f6b..1eec6275 100644 --- a/projects/cm_mcu/MonitorI2CTask.h +++ b/projects/cm_mcu/MonitorI2CTask.h @@ -23,6 +23,8 @@ struct sm_command_t { uint16_t bit_mask; // begin bit mask char *units; // units for pretty printing enum pm_type type; // how to decode command (L11 or bitfield or ...) + bool (*devicelist)(void); + void (*storeData)(uint16_t data, int which); }; // how to find an I2C device, with a mux infront of it. @@ -104,4 +106,11 @@ extern struct MonitorI2CTaskArgs_t ffl4_f2_args; extern struct MonitorI2CTaskArgs_t clock_args; extern struct MonitorI2CTaskArgs_t clockr0a_args; + +// for autogenerated code +#define DEVICE_14G 0x1 +#define DEVICE_25G12 0x2 +#define DEVICE_25G4 0x4 +#define DEVICE_CERNB 0x8 + #endif /* PROJECTS_CM_MCU_MONITORI2CTASK_H_ */ diff --git a/projects/cm_mcu/commands/BoardCommands.c b/projects/cm_mcu/commands/BoardCommands.c index 478494f9..ab4e7a36 100644 --- a/projects/cm_mcu/commands/BoardCommands.c +++ b/projects/cm_mcu/commands/BoardCommands.c @@ -11,7 +11,7 @@ #include #include "commands/parameters.h" #include "common/utils.h" -#include "driverlib/gpio.h" +#include "driverlib/gpio.h" // IWYU pragma: keep #include "BoardCommands.h" #include "common/pinsel.h" #include "inc/hw_hibernate.h" diff --git a/sm_cm_config/data/MON_I2C_rev2.yml b/sm_cm_config/data/MON_I2C_rev2.yml new file mode 100644 index 00000000..42d5ea2b --- /dev/null +++ b/sm_cm_config/data/MON_I2C_rev2.yml @@ -0,0 +1,43 @@ +# Configuration generation for how to access various data +# read out via the I2C-based monitoring tasks. +metadata: + - cm_hw_rev: 2A + - revision: 1 + +config: +# - name: "bob" # register name +# reg_size: 1 # size of register address +# page: 0 +# reg_address: 0x1 # actual register address +# size: 0 # how many bytes to read +# bit_mask: 0xFFFF # ?? +# units: A +# type: Linear11 # bitfield, linear11 +# devices: # list of devices that have this register. 14G, 25G-12, 25G-4, CERN-B. + - name: FF_STATUS_REG + reg_size: 1 + page: 0 + reg_address: 0x2 + size: 2 + mask: 0xFF + units: "" + type: PM_STATUS + devices: [14G, 25G12, 25G4, CERNB] + - name: FF_TEMPERATURE + reg_size: 1 + page: 0 + reg_address: 0x16 + size: 2 + mask: 0xFF + units: C + type: PM_NONVOLTAGE + devices: [14G, 25G12, 25G4, CERNB] + - name: FF_LOS_ALARM + reg_size: 1 + page: 0 + reg_address: 0x07 + size: 2 + mask: 0xFFFF + units: "" + type: PM_STATUS + devices: [25G12, 25G4] diff --git a/sm_cm_config/src/mon_generate.py b/sm_cm_config/src/mon_generate.py new file mode 100755 index 00000000..00f0bfb9 --- /dev/null +++ b/sm_cm_config/src/mon_generate.py @@ -0,0 +1,92 @@ +#! /usr/bin/env python +# -*- coding: utf-8 -*- +"""generate the C source file for the MCU Mon I2C addresses and initialization calls""" + +import os +import sys +import argparse +import datetime +import subprocess +from string import Template + +import yaml + +parser = argparse.ArgumentParser(description='Process YAML for MCU Mon.') +parser.add_argument('-v', '--verbose', action='store_true', + help='increase output verbosity') +parser.add_argument('-o', '--output', type=str, help='output file name', + default="MonI2C_addresses.c") +#this argument is required +parser.add_argument('input_files', metavar='file', type=str, + nargs='+', help='input yaml file names') + +args = parser.parse_args() + +if args.output and args.verbose: + print('Output file name:', args.output) + +addr_template = Template("{$reg_size, $page, $reg_address, $size, \"$name\"," + " $mask, \"$units\", $type, }, ") + +# open output c source file for writing +with open(args.output, 'w', encoding="ascii") as fout: + print(f"// This file is generated by {os.path.basename(sys.argv[0])}", file=fout) + print(r"// Do not edit this file directly", file=fout) + print(r"// Edit the yaml files in the data directory and run the script again", file=fout) + print(r"// to re-generate this file", file=fout) + print(r"//", file=fout) + print(r"// This file contains the arrays of the i2c monitoring data", file=fout) + print(r"// and the C calls to set and retrieve it", file=fout) + # Print timestamp to output file + timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") + print(f"// Generated: {timestamp}", file=fout) + print(r"//", file=fout) + print("#include \"stdint.h\"", file=fout) + print("#include \"MonitorI2CTask.h\"", file=fout) + + with open(args.input_files[0], encoding="ascii") as f: + + # generate the list of registers to access + print(r"struct sm_command_t sm_command_test[] = {", file=fout) + data = yaml.load(f, Loader=yaml.FullLoader) + config = data['config'] + for c in config: + s = addr_template.substitute(c) + print(s, file=fout) + # print(f"{{{c['reg_size']},\"{c['name']}\"}},", file=fout) + print(r"};", file=fout) + + # generate the arrays to store the data + print(r"// Arrays to store the data", file=fout) + for c in config: + print(f"static uint16_t {c['name']}_data[NUM_ENTRIES] = {{0}};", file=fout) + # generate access functions + print(r"// Access functions", file=fout) + for c in config: + print(f"uint16_t get_{c['name']}_data(int which) {{", file=fout) + print(f" return {c['name']}_data[which];", file=fout) + print(r"}", file=fout) + print(f"void set_{c['name']}_data(uint16_t data, int which) {{", file=fout) + print(f" {c['name']}_data[which] = data;", file=fout) + print(r"}", file=fout) + # using the devices field, generate a function that returns a mask of the devices + print(r"// Function to return a mask of the devices for each command", file=fout) + for c in config: + print(f"uint16_t get_{c['name']}_mask(void) {{", file=fout) + print(r" return ", end="", file=fout) + for d in c['devices']: + print(f"DEVICE_{d} | ", end="", file=fout) + print(r"0;", file=fout) + print(r"}", file=fout) +# reformat the c file using clang-format +# -style=file:$HOME/src/apollo_cm_mcu/.clang-format +# if the clang-format fails, we just ignore it +try: + r = subprocess.run(["clang-format", "-i", args.output], check=False) + if r.returncode != 0 and args.verbose: + print('clang-format failed') + if args.verbose: + print('clang-format complete') +except FileNotFoundError as e: + if args.verbose: + print(f"clang-format not found: {e}") From f49c1873bc56eda54892b8409f8494bd320e3e59 Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Mon, 6 May 2024 15:46:47 -0400 Subject: [PATCH 08/71] clang-format --- projects/cm_mcu/FireflyUtils.c | 38 ++++++++++++++++---------------- projects/cm_mcu/FireflyUtils.h | 1 - projects/cm_mcu/LocalTasks.c | 19 ++++++++-------- projects/cm_mcu/MonitorI2CTask.c | 2 +- projects/cm_mcu/MonitorI2CTask.h | 9 ++++---- projects/cm_mcu/Tasks.h | 2 -- projects/cm_mcu/ZynqMonTask.c | 2 +- projects/cm_mcu/clocksynth.c | 6 ++--- 8 files changed, 37 insertions(+), 42 deletions(-) diff --git a/projects/cm_mcu/FireflyUtils.c b/projects/cm_mcu/FireflyUtils.c index dcef8ab7..72942490 100644 --- a/projects/cm_mcu/FireflyUtils.c +++ b/projects/cm_mcu/FireflyUtils.c @@ -3,7 +3,7 @@ * @brief Utilities to access and control SamTec Firefly devices. * * This file contains utility functions and definitions for interacting with - * SamTec Firefly devices. + * SamTec Firefly devices. * @author Peter Wittich * @date September 20, 2022 @@ -132,34 +132,34 @@ void readFFpresent(void) #ifdef REV1 uint32_t present_FFL12_BOTTOM_F1 = present_FFL12_F1 & 0x3FU; // bottom 6 bits uint32_t present_FFL12_TOP_F1 = (present_FFL12_F1 >> 6) & 0x3U; // top 2 bits - present_FFL4_F1 = (present_FFL4_F1 >> 5) & 0x7U; // bits 5-7 + present_FFL4_F1 = (present_FFL4_F1 >> 5) & 0x7U; // bits 5-7 present_FFL12_0X20_F2 = (present_0X20_F2 >> 6) & 0x3U; // bit 6-7 - present_FFL4_0X20_F2 = present_0X20_F2 & 0x3FU; // bottom 6 bits + present_FFL4_0X20_F2 = present_0X20_F2 & 0x3FU; // bottom 6 bits present_FFL12_0X21_F2 = (present_0X21_F2 >> 4) & 0x3U; // bit 4-5 - present_FFL4_0X21_F2 = (present_0X21_F2 >> 2) & 0xFU; // bit 4 bits + present_FFL4_0X21_F2 = (present_0X21_F2 >> 2) & 0xFU; // bit 4 bits - uint32_t ff_combined_present = ((present_FFL12_0X21_F2) << 23) | // 2 bits - ((present_FFL12_0X20_F2) << 21) | // 2 bits - ((present_FFL4_0X21_F2) << 17) | // 4 bits - ((present_FFL4_0X20_F2) << 11) | // 6 bits - ((present_FFL12_TOP_F1) << 9) | // 2 bits - (present_FFL4_F1) << 6 | // 3 bits - ((present_FFL12_BOTTOM_F1)); // 6 bits + uint32_t ff_combined_present = ((present_FFL12_0X21_F2) << 23) | // 2 bits + ((present_FFL12_0X20_F2) << 21) | // 2 bits + ((present_FFL4_0X21_F2) << 17) | // 4 bits + ((present_FFL4_0X20_F2) << 11) | // 6 bits + ((present_FFL12_TOP_F1) << 9) | // 2 bits + (present_FFL4_F1) << 6 | // 3 bits + ((present_FFL12_BOTTOM_F1)); // 6 bits #elif defined(REV2) - present_FFL12_F1 = present_FFL12_F1 & 0x3FU; // bottom 6 bits - present_FFL12_F2 = present_FFL12_F2 & 0x3FU; // bottom 6 bits + present_FFL12_F1 = present_FFL12_F1 & 0x3FU; // bottom 6 bits + present_FFL12_F2 = present_FFL12_F2 & 0x3FU; // bottom 6 bits present_FFL4_F1 = (present_FFL4_F1 >> 4) & 0xFU; // bits 4-7 present_FFL4_F2 = (present_FFL4_F2 >> 4) & 0xFU; // bits 4-7 - uint32_t ff_combined_present = ((present_FFL4_F2) << 16) | // 4 bits - ((present_FFL12_F2) << 10) | // 6 bits - (present_FFL4_F1) << 6 | // 4 bits - ((present_FFL12_F1)); // 6 bits + uint32_t ff_combined_present = ((present_FFL4_F2) << 16) | // 4 bits + ((present_FFL12_F2) << 10) | // 6 bits + (present_FFL4_F1) << 6 | // 4 bits + ((present_FFL12_F1)); // 6 bits - ff_bitmask_args[1].present_bit_mask = (~present_FFL4_F1) & 0xFU; // 4 bits + ff_bitmask_args[1].present_bit_mask = (~present_FFL4_F1) & 0xFU; // 4 bits ff_bitmask_args[0].present_bit_mask = (~present_FFL12_F1) & 0x3FU; // 6 bits - ff_bitmask_args[3].present_bit_mask = (~present_FFL4_F2) & 0xFU; // 4 bits + ff_bitmask_args[3].present_bit_mask = (~present_FFL4_F2) & 0xFU; // 4 bits ff_bitmask_args[2].present_bit_mask = (~present_FFL12_F2) & 0x3FU; // 6 bits f1_ff12xmit_4v0_sel = (f1_ff12xmit_4v0_sel >> 4) & 0x7; // bits 4-6 diff --git a/projects/cm_mcu/FireflyUtils.h b/projects/cm_mcu/FireflyUtils.h index d899fd4d..c92a44b3 100644 --- a/projects/cm_mcu/FireflyUtils.h +++ b/projects/cm_mcu/FireflyUtils.h @@ -37,7 +37,6 @@ #define VENDOR_START_BIT_FF12 171 #define VENDOR_STOP_BIT_FF12 187 - struct arg_moni2c_ff_t { char *ff_part; // ff part struct MonitorI2CTaskArgs_t *arg; // ff arg diff --git a/projects/cm_mcu/LocalTasks.c b/projects/cm_mcu/LocalTasks.c index 27c3eb98..c368db78 100644 --- a/projects/cm_mcu/LocalTasks.c +++ b/projects/cm_mcu/LocalTasks.c @@ -28,7 +28,6 @@ #include "I2CCommunication.h" #include "common/log.h" - // local prototype void Print(const char *str); @@ -68,11 +67,11 @@ struct dev_moni2c_addr_t ff_moni2c_addrs[NFIREFLIES] = { }; struct arg_moni2c_ff_t ff_moni2c_arg[NFIREFLY_ARG] = { - {"FFL12", &ffl12_f1_args, 0, 0, 6}, // - {"FFL4", &ffl4_f1_args, 6, 0, 3}, // - {"FFL12", &ffl12_f1_args, 9, 6, 2}, // - {"FFL4", &ffl4_f2_args, 11, 0, 10}, // - {"FFL12", &ffl12_f2_args, 21, 0, 4}, // + {"FFL12", &ffl12_f1_args, 0, 0, 6}, // + {"FFL4", &ffl4_f1_args, 6, 0, 3}, // + {"FFL12", &ffl12_f1_args, 9, 6, 2}, // + {"FFL4", &ffl4_f2_args, 11, 0, 10}, // + {"FFL12", &ffl12_f2_args, 21, 0, 4}, // }; #elif defined(REV2) @@ -106,10 +105,10 @@ struct dev_moni2c_addr_t ff_moni2c_addrs[NFIREFLIES] = { }; struct arg_moni2c_ff_t ff_moni2c_arg[NFIREFLY_ARG] = { - {"FFL12", &ffl12_f1_args, 0, 0, 6}, // - {"FFL4", &ffl4_f1_args, 6, 0, 4}, // - {"FFL12", &ffl12_f2_args, 10, 0, 6}, // - {"FFL4", &ffl4_f2_args, 16, 0, 4}, // + {"FFL12", &ffl12_f1_args, 0, 0, 6}, // + {"FFL4", &ffl4_f1_args, 6, 0, 4}, // + {"FFL12", &ffl12_f2_args, 10, 0, 6}, // + {"FFL4", &ffl4_f2_args, 16, 0, 4}, // }; #else #error "Define either Rev1 or Rev2" diff --git a/projects/cm_mcu/MonitorI2CTask.c b/projects/cm_mcu/MonitorI2CTask.c index 0e14425a..82e0c5e8 100644 --- a/projects/cm_mcu/MonitorI2CTask.c +++ b/projects/cm_mcu/MonitorI2CTask.c @@ -108,7 +108,7 @@ void MonitorI2CTask(void *parameters) } } - // for firefly devices, skip if FF is not enabled + // for firefly devices, skip if FF is not enabled if (!IsCLK) { // Fireflies need to be checked if the links are connected or not if (args->i2c_dev == I2C_DEVICE_F1) { // FPGA #1 #ifdef REV1 diff --git a/projects/cm_mcu/MonitorI2CTask.h b/projects/cm_mcu/MonitorI2CTask.h index 1eec6275..4ec47f87 100644 --- a/projects/cm_mcu/MonitorI2CTask.h +++ b/projects/cm_mcu/MonitorI2CTask.h @@ -57,7 +57,7 @@ struct MonitorI2CTaskArgs_t { #define NDEVICES_FFL4_F1 (3) #else // REV2 #define NDEVICES_FFL4_F1 (4) -#endif // REV 2 +#endif // REV 2 #define NCOMMANDS_FFL4_F1 8 // number of commands #define NPAGES_FFL4_F1 1 // number of pages on the 4-channel firefly ports @@ -73,7 +73,7 @@ struct MonitorI2CTaskArgs_t { #define NDEVICES_FFL4_F2 (10) #else // REV1 #define NDEVICES_FFL4_F2 (4) -#endif // REV 2 +#endif // REV 2 #define NCOMMANDS_FFL4_F2 8 // number of commands #define NPAGES_FFL4_F2 1 // number of pages on the 4-channel firefly ports @@ -94,11 +94,11 @@ extern struct MonitorI2CTaskArgs_t ffl4_f1_args; extern struct MonitorI2CTaskArgs_t ffl12_f2_args; extern struct MonitorI2CTaskArgs_t ffl4_f2_args; -#define NDEVICES_CLK (4) +#define NDEVICES_CLK (4) #define NCOMMANDS_CLK 7 // number of commands #define NCOMMANDS_FLG_CLK 1 // number of sticky commands #define NPAGES_CLK 1 // -#define NDEVICES_CLKR0A (1) +#define NDEVICES_CLKR0A (1) #define NCOMMANDS_CLKR0A 7 // number of commands #define NCOMMANDS_FLG_CLKR0A 2 // number of sticky commands #define NPAGES_CLKR0A 1 // @@ -106,7 +106,6 @@ extern struct MonitorI2CTaskArgs_t ffl4_f2_args; extern struct MonitorI2CTaskArgs_t clock_args; extern struct MonitorI2CTaskArgs_t clockr0a_args; - // for autogenerated code #define DEVICE_14G 0x1 #define DEVICE_25G12 0x2 diff --git a/projects/cm_mcu/Tasks.h b/projects/cm_mcu/Tasks.h index cae39d12..ede6ca87 100644 --- a/projects/cm_mcu/Tasks.h +++ b/projects/cm_mcu/Tasks.h @@ -134,7 +134,6 @@ void MonitorI2CTask(void *parameters); #define I2C_DEVICE_F2 3 #endif - // pilfered and adapted from http://billauer.co.il/blog/2018/01/c-pmbus-xilinx-fpga-kc705/ enum pm_type { PM_VOLTAGE, PM_NONVOLTAGE, @@ -143,7 +142,6 @@ enum pm_type { PM_VOLTAGE, PM_LINEAR16U, PM_LINEAR16S }; - struct clk_program_t { char progname_clkdesgid[CLOCK_PROGNAME_REG_NAME]; // program name from DESIGN_ID register of clock chip char progname_eeprom[CLOCK_EEPROM_PROGNAME_REG_NAME]; // program name from eeprom diff --git a/projects/cm_mcu/ZynqMonTask.c b/projects/cm_mcu/ZynqMonTask.c index 76a261e3..9a9db462 100644 --- a/projects/cm_mcu/ZynqMonTask.c +++ b/projects/cm_mcu/ZynqMonTask.c @@ -19,7 +19,7 @@ #ifdef REV1 #include "common/softuart.h" -#include "driverlib/timer.h" +#include "driverlib/timer.h" #include "driverlib/gpio.h" #include "inc/hw_ints.h" #endif diff --git a/projects/cm_mcu/clocksynth.c b/projects/cm_mcu/clocksynth.c index ef8f6735..86631bd7 100644 --- a/projects/cm_mcu/clocksynth.c +++ b/projects/cm_mcu/clocksynth.c @@ -104,7 +104,7 @@ void getClockProgram(int device, char progname_clkdesgid[CLOCK_PROGNAME_REG_NAME CLOCK_CHANGEPAGE_REG_ADDR, 1, page); // now read out the six bytes of data in two reads - const uint8_t reg = (CLOCK_PROGNAME_REG_ADDR_START)&0xFF; + const uint8_t reg = (CLOCK_PROGNAME_REG_ADDR_START) & 0xFF; uint16_t init_postamble_page = 32 * (device + 1) - 1; // read the addresses in EEPROM that store the number of registers in Preamble-register, Register, and Postamble-register list per a clock config file @@ -131,10 +131,10 @@ void getClockProgram(int device, char progname_clkdesgid[CLOCK_PROGNAME_REG_NAME // as eepromdata[0] and eepromdat[1],respectively // third byte from three addresses in EEPROM is a value byte - apollo_i2c_ctl_reg_r(CLOCK_I2C_DEV, CLOCK_I2C_EEPROM_ADDR, 2, eeprom_progname_reg + ((i)*3), 3, tempdata); + apollo_i2c_ctl_reg_r(CLOCK_I2C_DEV, CLOCK_I2C_EEPROM_ADDR, 2, eeprom_progname_reg + ((i) * 3), 3, tempdata); eepromdata[0] |= ((tempdata[0] >> (16)) & 0xFF) << (i * 8); // third byte from three addresses in EEPROM is a value byte - apollo_i2c_ctl_reg_r(CLOCK_I2C_DEV, CLOCK_I2C_EEPROM_ADDR, 2, eeprom_progname_reg + 12 + ((i)*3), 3, tempdata); + apollo_i2c_ctl_reg_r(CLOCK_I2C_DEV, CLOCK_I2C_EEPROM_ADDR, 2, eeprom_progname_reg + 12 + ((i) * 3), 3, tempdata); eepromdata[1] |= ((tempdata[0] >> (16)) & 0xFF) << (i * 8); } } From 46ac14f765d58390aad634d90d06f176036c8f9e Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Tue, 7 May 2024 12:15:47 -0400 Subject: [PATCH 09/71] code that sort of works --- .gitignore | 1 + projects/cm_mcu/MonitorI2CTask.c | 3 ++ projects/cm_mcu/MonitorI2CTask.h | 2 +- sm_cm_config/src/mon_generate.py | 71 ++++++++++++++++++++++---------- 4 files changed, 54 insertions(+), 23 deletions(-) diff --git a/.gitignore b/.gitignore index 84713da5..7f52a2a7 100644 --- a/.gitignore +++ b/.gitignore @@ -66,3 +66,4 @@ projects/cm_mcu/ZynqMon_addresses.h PL_MEM_CM_rev1.xml PL_MEM_CM_rev2.xml projects/cm_mcu/MonI2C_addresses.c +projects/cm_mcu/MonI2C_addresses.h diff --git a/projects/cm_mcu/MonitorI2CTask.c b/projects/cm_mcu/MonitorI2CTask.c index 82e0c5e8..32627843 100644 --- a/projects/cm_mcu/MonitorI2CTask.c +++ b/projects/cm_mcu/MonitorI2CTask.c @@ -192,6 +192,9 @@ void MonitorI2CTask(void *parameters) else { uint16_t masked_output = output_raw & args->commands[c].bit_mask; args->sm_values[index] = masked_output; + if ( args->commands[c].devicelist() ) { + args->commands[c].storeData(masked_output, device); + } } } // loop over commands diff --git a/projects/cm_mcu/MonitorI2CTask.h b/projects/cm_mcu/MonitorI2CTask.h index 4ec47f87..7f6f2f41 100644 --- a/projects/cm_mcu/MonitorI2CTask.h +++ b/projects/cm_mcu/MonitorI2CTask.h @@ -23,7 +23,7 @@ struct sm_command_t { uint16_t bit_mask; // begin bit mask char *units; // units for pretty printing enum pm_type type; // how to decode command (L11 or bitfield or ...) - bool (*devicelist)(void); + uint16_t (*devicelist)(void); void (*storeData)(uint16_t data, int which); }; diff --git a/sm_cm_config/src/mon_generate.py b/sm_cm_config/src/mon_generate.py index 00f0bfb9..d01f04ad 100755 --- a/sm_cm_config/src/mon_generate.py +++ b/sm_cm_config/src/mon_generate.py @@ -26,10 +26,18 @@ print('Output file name:', args.output) addr_template = Template("{$reg_size, $page, $reg_address, $size, \"$name\"," - " $mask, \"$units\", $type, }, ") + " $mask, \"$units\", $type, get_${name}_mask, set_${name}_data}, ") +# output file names: header file and c source file +# make sure that the output file ends with .c. Print error message and exit if it doesn't +if not args.output.endswith(".c"): + print(f"Output file name {args.output} does not end with .c") + sys.exit(1) +source_fname = args.output +header_fname = args.output[:-2] + '.h' # open output c source file for writing -with open(args.output, 'w', encoding="ascii") as fout: +def write_boilderplate(fout): + """Write the boilerplate to the output file""" print(f"// This file is generated by {os.path.basename(sys.argv[0])}", file=fout) print(r"// Do not edit this file directly", file=fout) print(r"// Edit the yaml files in the data directory and run the script again", file=fout) @@ -41,43 +49,62 @@ timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") print(f"// Generated: {timestamp}", file=fout) print(r"//", file=fout) - print("#include \"stdint.h\"", file=fout) - print("#include \"MonitorI2CTask.h\"", file=fout) + +with open(source_fname, 'w', encoding="ascii") as fout_source, \ + open(header_fname, 'w', encoding="ascii") as fout_header: + write_boilderplate(fout_source) + write_boilderplate(fout_header) + print("#include \"stdint.h\"", file=fout_source) + print("#include \"MonitorI2CTask.h\"", file=fout_source) + print(f"#include \"{header_fname}\"", file=fout_source) + + # header file + print(r"#ifndef MON_I2C_ADDRESSES_H", file=fout_header) + print(r"#define MON_I2C_ADDRESSES_H", file=fout_header) + print("#include \"stdint.h\"", file=fout_header) + with open(args.input_files[0], encoding="ascii") as f: # generate the list of registers to access - print(r"struct sm_command_t sm_command_test[] = {", file=fout) + print(r"struct sm_command_t sm_command_test[] = {", file=fout_source) data = yaml.load(f, Loader=yaml.FullLoader) config = data['config'] for c in config: s = addr_template.substitute(c) - print(s, file=fout) + print(s, file=fout_source) # print(f"{{{c['reg_size']},\"{c['name']}\"}},", file=fout) - print(r"};", file=fout) + print(r"};", file=fout_source) # generate the arrays to store the data - print(r"// Arrays to store the data", file=fout) + print(r"// Arrays to store the data", file=fout_source) for c in config: - print(f"static uint16_t {c['name']}_data[NUM_ENTRIES] = {{0}};", file=fout) + print(f"static uint16_t {c['name']}_data[NFIREFLIES] = {{0}};", file=fout_source) # generate access functions - print(r"// Access functions", file=fout) + print(r"// Access functions", file=fout_source) for c in config: - print(f"uint16_t get_{c['name']}_data(int which) {{", file=fout) - print(f" return {c['name']}_data[which];", file=fout) - print(r"}", file=fout) - print(f"void set_{c['name']}_data(uint16_t data, int which) {{", file=fout) - print(f" {c['name']}_data[which] = data;", file=fout) - print(r"}", file=fout) + set_fcn_name = f"set_{c['name']}_data" + # getter + print(f"uint16_t get_{c['name']}_data(int which);", file=fout_header) + print(f"uint16_t get_{c['name']}_data(int which) {{", file=fout_source) + print(f" return {c['name']}_data[which];", file=fout_source) + print(r"}", file=fout_source) + # setter + print(f"void {set_fcn_name}(uint16_t data, int which);", file=fout_header) + print(f"void {set_fcn_name}(uint16_t data, int which) {{", file=fout_source) + print(f" {c['name']}_data[which] = data;", file=fout_source) + print(r"}", file=fout_source) # using the devices field, generate a function that returns a mask of the devices - print(r"// Function to return a mask of the devices for each command", file=fout) + print(r"// Function to return a mask of the devices for each command", file=fout_source) for c in config: - print(f"uint16_t get_{c['name']}_mask(void) {{", file=fout) - print(r" return ", end="", file=fout) + print(f"uint16_t get_{c['name']}_mask(void);", file=fout_header) + print(f"uint16_t get_{c['name']}_mask(void) {{", file=fout_source) + print(r" return ", end="", file=fout_source) for d in c['devices']: - print(f"DEVICE_{d} | ", end="", file=fout) - print(r"0;", file=fout) - print(r"}", file=fout) + print(f"DEVICE_{d} | ", end="", file=fout_source) + print(r"0;", file=fout_source) + print(r"}", file=fout_source) + print(r"#endif", file=fout_header) # reformat the c file using clang-format # -style=file:$HOME/src/apollo_cm_mcu/.clang-format # if the clang-format fails, we just ignore it From 673b0169acf359a337fb3707f89534c5c1c79f55 Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Wed, 8 May 2024 21:56:43 -0400 Subject: [PATCH 10/71] Update Makefile clean target --- projects/cm_mcu/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/cm_mcu/Makefile b/projects/cm_mcu/Makefile index e168f5c6..ecfc0b3f 100644 --- a/projects/cm_mcu/Makefile +++ b/projects/cm_mcu/Makefile @@ -82,7 +82,7 @@ all: ${COMPILER}/cm_mcu.axf # The rule to clean out all the build products. # clean: - @rm -rf ${COMPILER} ${wildcard *~} ZynqMon_addresses.c ZynqMon_addresses.h ${ROOT}/PL_MEM*.xml + @rm -rf ${COMPILER} ${wildcard *~} ZynqMon_addresses.c ZynqMon_addresses.h ${ROOT}/PL_MEM*.xml MonI2C_addresses.* # # The rule to create the target directory. From a22f917fb49fd99f0fc47e14d197af07eb69e05b Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Thu, 9 May 2024 11:32:08 -0400 Subject: [PATCH 11/71] minor tweaks --- projects/cm_mcu/MonitorI2CTask.c | 2 +- sm_cm_config/src/mon_generate.py | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/projects/cm_mcu/MonitorI2CTask.c b/projects/cm_mcu/MonitorI2CTask.c index 32627843..ac167184 100644 --- a/projects/cm_mcu/MonitorI2CTask.c +++ b/projects/cm_mcu/MonitorI2CTask.c @@ -192,7 +192,7 @@ void MonitorI2CTask(void *parameters) else { uint16_t masked_output = output_raw & args->commands[c].bit_mask; args->sm_values[index] = masked_output; - if ( args->commands[c].devicelist() ) { + if (args->commands[c].devicelist()) { args->commands[c].storeData(masked_output, device); } } diff --git a/sm_cm_config/src/mon_generate.py b/sm_cm_config/src/mon_generate.py index d01f04ad..5a3f21c8 100755 --- a/sm_cm_config/src/mon_generate.py +++ b/sm_cm_config/src/mon_generate.py @@ -73,7 +73,6 @@ def write_boilderplate(fout): for c in config: s = addr_template.substitute(c) print(s, file=fout_source) - # print(f"{{{c['reg_size']},\"{c['name']}\"}},", file=fout) print(r"};", file=fout_source) # generate the arrays to store the data @@ -104,12 +103,14 @@ def write_boilderplate(fout): print(f"DEVICE_{d} | ", end="", file=fout_source) print(r"0;", file=fout_source) print(r"}", file=fout_source) - print(r"#endif", file=fout_header) + # closing header guard + print(r"#endif// MON_I2C_ADDRESSES_H", file=fout_header) + # reformat the c file using clang-format # -style=file:$HOME/src/apollo_cm_mcu/.clang-format # if the clang-format fails, we just ignore it try: - r = subprocess.run(["clang-format", "-i", args.output], check=False) + r = subprocess.run(["clang-format", "-i", source_fname, header_fname], check=False) if r.returncode != 0 and args.verbose: print('clang-format failed') if args.verbose: From 6dabeabd9589b123b29eb42a04add3fe89219753 Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Sat, 18 May 2024 20:28:36 -0400 Subject: [PATCH 12/71] in progress --- projects/cm_mcu/Makefile | 1 + projects/cm_mcu/MonUtils.c | 40 ++++++ projects/cm_mcu/MonitorI2CTask.c | 3 - projects/cm_mcu/MonitorI2CTask.h | 8 -- projects/cm_mcu/MonitorTaskI2C_new.c | 177 +++++++++++++++++++++++++++ projects/cm_mcu/MonitorTaskI2C_new.h | 125 +++++++++++++++++++ sm_cm_config/data/MON_I2C_rev2.yml | 136 ++++++++++++++------ sm_cm_config/src/mon_generate.py | 151 ++++++++++++++--------- 8 files changed, 536 insertions(+), 105 deletions(-) create mode 100644 projects/cm_mcu/MonUtils.c create mode 100644 projects/cm_mcu/MonitorTaskI2C_new.c create mode 100644 projects/cm_mcu/MonitorTaskI2C_new.h diff --git a/projects/cm_mcu/Makefile b/projects/cm_mcu/Makefile index ecfc0b3f..57c2962b 100644 --- a/projects/cm_mcu/Makefile +++ b/projects/cm_mcu/Makefile @@ -164,6 +164,7 @@ ${COMPILER}/cm_mcu.axf: ${COMPILER}/EEPROMTask.o ${COMPILER}/cm_mcu.axf: ${COMPILER}/PowerSupplyTask.o ${COMPILER}/cm_mcu.axf: ${COMPILER}/ADCMonitorTask.o ${COMPILER}/cm_mcu.axf: ${COMPILER}/MonitorTask.o +${COMPILER}/cm_mcu.axf: ${COMPILER}/MonitorTaskI2C_new.o ${COMPILER}/cm_mcu.axf: ${COMPILER}/MonitorI2CTask.o ${COMPILER}/cm_mcu.axf: ${COMPILER}/I2CSlaveTask.o ${COMPILER}/cm_mcu.axf: ${COMPILER}/GenericAlarmTask.o diff --git a/projects/cm_mcu/MonUtils.c b/projects/cm_mcu/MonUtils.c new file mode 100644 index 00000000..9f459b5d --- /dev/null +++ b/projects/cm_mcu/MonUtils.c @@ -0,0 +1,40 @@ +#include "MonitorTaskI2C_new.h" + +int FirefflyType(int device) +{ + switch (device) { + case 0: + case 1: + case 2: + case 3: { + // fixme: this should be a check on CERN-B or ECUO-[RT]12-25 + // with a function call + return DEVICE_25G12; + } + case 4: + case 5: + case 6: + case 7: + return DEVICE_25G4; + default: + return DEVICE_NONE; + } +} + +#ifdef REV2 +// For rev2 clocks there is one 5341 and 4 5395s +int ClockType(int device) +{ + switch (device) { + case 0: + return DEVICE_SI5341; + case 1: + case 2: + case 3: + case 4: + return DEVICE_SI5395; + default: + return DEVICE_NONE; + } +} +#endif // REV2 diff --git a/projects/cm_mcu/MonitorI2CTask.c b/projects/cm_mcu/MonitorI2CTask.c index ac167184..82e0c5e8 100644 --- a/projects/cm_mcu/MonitorI2CTask.c +++ b/projects/cm_mcu/MonitorI2CTask.c @@ -192,9 +192,6 @@ void MonitorI2CTask(void *parameters) else { uint16_t masked_output = output_raw & args->commands[c].bit_mask; args->sm_values[index] = masked_output; - if (args->commands[c].devicelist()) { - args->commands[c].storeData(masked_output, device); - } } } // loop over commands diff --git a/projects/cm_mcu/MonitorI2CTask.h b/projects/cm_mcu/MonitorI2CTask.h index 7f6f2f41..466ee41c 100644 --- a/projects/cm_mcu/MonitorI2CTask.h +++ b/projects/cm_mcu/MonitorI2CTask.h @@ -23,8 +23,6 @@ struct sm_command_t { uint16_t bit_mask; // begin bit mask char *units; // units for pretty printing enum pm_type type; // how to decode command (L11 or bitfield or ...) - uint16_t (*devicelist)(void); - void (*storeData)(uint16_t data, int which); }; // how to find an I2C device, with a mux infront of it. @@ -106,10 +104,4 @@ extern struct MonitorI2CTaskArgs_t ffl4_f2_args; extern struct MonitorI2CTaskArgs_t clock_args; extern struct MonitorI2CTaskArgs_t clockr0a_args; -// for autogenerated code -#define DEVICE_14G 0x1 -#define DEVICE_25G12 0x2 -#define DEVICE_25G4 0x4 -#define DEVICE_CERNB 0x8 - #endif /* PROJECTS_CM_MCU_MONITORI2CTASK_H_ */ diff --git a/projects/cm_mcu/MonitorTaskI2C_new.c b/projects/cm_mcu/MonitorTaskI2C_new.c new file mode 100644 index 00000000..24d93f64 --- /dev/null +++ b/projects/cm_mcu/MonitorTaskI2C_new.c @@ -0,0 +1,177 @@ +/* + * MonitorI2CTask_new.c + * + * Created on: June 30, 2022 + * Author: pkotamnives + * Monitor temperatures, and statuses of firefly ports via I2C BUS + * pass in addresses via parameter to the task. + */ + +// includes for types +#include +#include +#include +#include + +// FreeRTOS +#include "FreeRTOS.h" // IWYU pragma: keep +#include "FreeRTOSConfig.h" +#include "task.h" + +// local includes +#include "common/smbus_helper.h" +#include "MonitorTaskI2C_new.h" +#include "common/log.h" +#include "Tasks.h" +#include "I2CCommunication.h" +#include "Semaphore.h" + +// local prototype + +// read-only accessor functions for Firefly names and values. +#if 0 +bool getFFch_low(uint8_t val, int channel) +{ + configASSERT(channel < 8); + if (!((1 << channel) & val)) { + return false; + } + return true; +} + +bool getFFch_high(uint8_t val, int channel) +{ + configASSERT(channel >= 8); + if (!((1 << (channel - 8)) & val)) { + return false; + } + return true; +} +#endif + +// Monitor registers of FF temperatures, voltages, currents, and ClK statuses via I2C +void MonitorI2CTask_new(void *parameters) +{ + + struct MonitorI2CTaskArgs_new_t *args = parameters; + + configASSERT(args->name != 0); + + // watchdog info + task_watchdog_register_task(kWatchdogTaskID_MonitorI2CTask); + + // wait for the power to come up + vTaskDelayUntil(&(args->updateTick), pdMS_TO_TICKS(5000)); + + // initialize to the current tick time + args->updateTick = xTaskGetTickCount(); + + bool good = false; + for (;;) { + + log_debug(LOG_MONI2C, "%s: grab sem\r\n", args->name); + + // grab the semaphore to ensure unique access to I2C controller + if (args->xSem != NULL) { + if (acquireI2CSemaphore(args->xSem) == pdFAIL) { + log_debug(LOG_SERVICE, "%s could'nt get sem; delay & continue\r\n", args->name); + vTaskDelayUntil(&(args->updateTick), pdMS_TO_TICKS(10)); // wait + continue; + } + } + + // ------------------------------- + // loop over devices in the device-type instance + // ------------------------------- + for (int device = 0; device < args->n_devices; ++device) { + log_debug(LOG_MONI2C, "%s: device %d powercheck\r\n", args->name, device); + + if (getPowerControlState() != POWER_ON) { + if (good) { + log_info(LOG_MONI2C, "%s: PWR off. Disable I2Cmon.\r\n", args->name); + good = false; + task_watchdog_unregister_task(kWatchdogTaskID_MonitorI2CTask); + } + if (xSemaphoreGetMutexHolder(args->xSem) == xTaskGetCurrentTaskHandle()) { + xSemaphoreGive(args->xSem); + } + break; + } + else if (getPowerControlState() == POWER_ON) { // power is on, and ... + if (!good) { // ... was not good, but is now good + task_watchdog_register_task(kWatchdogTaskID_MonitorI2CTask); + log_info(LOG_MONI2C, "%s: PWR on. (Re)start I2Cmon.\r\n", args->name); + good = true; + } + } + // what kind of device do we have (e.g., 4 ch FF, 12 ch 25 G FF, 12 ch CERN-B FF, etc.) + int devtype = args->typeCallback(device); + int dev_mask = 0x1U << device; + + // select the appropriate output for the mux + uint8_t data; + data = 0x1U << args->devices[device].mux_bit; + log_debug(LOG_MONI2C, "Mux set to 0x%02x\r\n", data); + int res = apollo_i2c_ctl_w(args->i2c_dev, args->devices[device].mux_addr, 1, data); + if (res != 0) { + log_warn(LOG_MONI2C, "Mux write error %s, break (instance=%s,ps=%d)\r\n", SMBUS_get_error(res), args->name, device); + break; + } + + // Read I2C registers/commands + for (int c = 0; c < args->n_commands; ++c) { + // check if the command is for this device + if ((args->commands[c].devicelist() & dev_mask) == 0 ) { + continue; // not for me! + } + + + log_debug(LOG_MONI2C, "%s: reg %s\r\n", args->name, args->commands[c].name); + uint8_t page_reg_value = args->commands[c].page; + int r = apollo_i2c_ctl_reg_w(args->i2c_dev, args->devices[device].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[device].name, SMBUS_get_error(r)); + break; + } + + uint32_t output_raw; + int res = apollo_i2c_ctl_reg_r(args->i2c_dev, args->devices[device].dev_addr, args->commands[c].reg_size, + args->commands[c].command[devtype], args->commands[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[c].name, SMBUS_get_error(res), device); + args->commands[c].storeData(0xffff, device); + break; + } + else { + uint16_t masked_output = output_raw & args->commands[c].bit_mask; + args->commands[c].storeData(masked_output, device); + } + + } // loop over commands + + log_debug(LOG_MONI2C, "%s: end loop commands\r\n", args->name); + args->updateTick = xTaskGetTickCount(); // current time in ticks + + res = apollo_i2c_ctl_w(args->i2c_dev, args->devices[device].mux_addr, 1, 0); + if (res != 0) { + log_warn(LOG_MONI2C, "Mux write error %s, break (instance=%s,ps=%d)\r\n", SMBUS_get_error(res), args->name, device); + break; + } + log_debug(LOG_MONI2C, "%s: reset mux\r\n", args->name); + + } // loop over devices + + // if we have a semaphore, give it + if (xSemaphoreGetMutexHolder(args->xSem) == xTaskGetCurrentTaskHandle()) { + xSemaphoreGive(args->xSem); + } + + // monitor stack usage for this task + CHECK_TASK_STACK_USAGE(args->stack_size); + + // task_watchdog_feed_task(kWatchdogTaskID_MonitorI2CTask); + vTaskDelayUntil(&(args->updateTick), pdMS_TO_TICKS(250)); + } // infinite loop for task +} diff --git a/projects/cm_mcu/MonitorTaskI2C_new.h b/projects/cm_mcu/MonitorTaskI2C_new.h new file mode 100644 index 00000000..65660253 --- /dev/null +++ b/projects/cm_mcu/MonitorTaskI2C_new.h @@ -0,0 +1,125 @@ +/* + * MonitorI2CTask_new.h + * + * Created on: June 30, 2022 + * Author: pkotamnives + */ + +#ifndef PROJECTS_CM_MCU_MONITORI2CTASK_H_ +#define PROJECTS_CM_MCU_MONITORI2CTASK_H_ + +#include "common/smbus.h" +#include "FreeRTOS.h" +#include "semphr.h" +#include "Tasks.h" +#include "FireflyUtils.h" + +struct sm_command_t { + int reg_size; // number of bytes of register/command + unsigned char page; // I2C page address + unsigned char command; // I2c register address + int size; // number of bytes to read + char *name; // text describing command + uint16_t bit_mask; // begin bit mask + char *units; // units for pretty printing + enum pm_type type; // how to decode command (L11 or bitfield or ...) +}; + +struct i2c_reg_command_t { + int reg_size; // number of bytes of register/command + unsigned char page; // I2C page address + unsigned char command[4]; // I2c register address + int size; // number of bytes to read + char *name; // text describing command + uint16_t bit_mask; // begin bit mask + char *units; // units for pretty printing + enum pm_type type; // how to decode command (L11 or bitfield or ...) + uint16_t (*devicelist)(void); + void (*storeData)(uint16_t data, int which); // store data in location which +}; + +// how to find an I2C device, with a mux infront of it. + +typedef bool (*MonTaskFcnPointer)(struct MonitorI2CTaskArgs_t *); +typedef int (*MonTaskI2CTypeFcnPointer)(int); // what kind of device we have (i.e., for FF, CERN-B, B04, Y12-14, Y12-25, etc.) + +struct MonitorI2CTaskArgs_new_t { + const char *name; // name to be assigned to the task + struct dev_moni2c_addr_t *devices; // list of devices to query + int i2c_dev; // i2c controller # + int n_devices; // number of devices + struct i2c_reg_command_t *commands; // list of commands + const uint8_t n_commands; // number of commands + const int n_values; // number of results + const uint8_t n_pages; // number of pages to loop over + const uint16_t selpage_reg; // register for selecting page + tSMBus *smbus; // pointer to I2C controller + volatile tSMBusStatus *smbus_status; // pointer to I2C status + TickType_t updateTick; // last update time, in ticks + SemaphoreHandle_t xSem; // semaphore for controlling access to device + UBaseType_t stack_size; // stack size of task + MonTaskFcnPointer presentCallback; // callback for present check + MonTaskI2CTypeFcnPointer typeCallback; // callback for type check +}; + +#define FF_SELPAGE_REG 0x7f +#define CLK_SELPAGE_REG 0x1 + +#ifndef REV2 +#define NDEVICES_FFL4_F1 (3) +#else // REV2 +#define NDEVICES_FFL4_F1 (4) +#endif // REV 2 +#define NCOMMANDS_FFL4_F1 8 // number of commands +#define NPAGES_FFL4_F1 1 // number of pages on the 4-channel firefly ports + +#ifndef REV2 +#define NDEVICES_FFL12_F1 (8) +#else // REV1 +#define NDEVICES_FFL12_F1 (6) +#endif // REV 2 +#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 NDEVICES_FFL4_F2 (10) +#else // REV1 +#define NDEVICES_FFL4_F2 (4) +#endif // REV 2 +#define NCOMMANDS_FFL4_F2 8 // number of commands +#define NPAGES_FFL4_F2 1 // number of pages on the 4-channel firefly ports + +#ifndef REV2 +#define NDEVICES_FFL12_F2 (4) +#else // REV1 +#define NDEVICES_FFL12_F2 (6) +#endif // REV 2 +#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]; +extern struct dev_moni2c_addr_t ffl4_f1_moni2c_addrs[NFIREFLIES_DAQ_F1]; +extern struct dev_moni2c_addr_t ffl12_f2_moni2c_addrs[NFIREFLIES_IT_F2]; +extern struct dev_moni2c_addr_t ffl4_f2_moni2c_addrs[NFIREFLIES_DAQ_F2]; + +#define NDEVICES_CLK (4) +#define NCOMMANDS_CLK 7 // number of commands +#define NCOMMANDS_FLG_CLK 1 // number of sticky commands +#define NPAGES_CLK 1 // +#define NDEVICES_CLKR0A (1) +#define NCOMMANDS_CLKR0A 7 // number of commands +#define NCOMMANDS_FLG_CLKR0A 2 // number of sticky commands +#define NPAGES_CLKR0A 1 // + + +// for autogenerated code +#define DEVICE_CERNB 0x01 +#define DEVICE_14G 0x02 +#define DEVICE_25G4 0x04 +#define DEVICE_25G12 0x08 +#define DEVICE_SI5395 0x10 +#define DEVICE_SI5341 0x20 + +#define DEVICE_NONE 0x80 + +#endif /* PROJECTS_CM_MCU_MONITORI2CTASK_H_ */ diff --git a/sm_cm_config/data/MON_I2C_rev2.yml b/sm_cm_config/data/MON_I2C_rev2.yml index 42d5ea2b..a95e77da 100644 --- a/sm_cm_config/data/MON_I2C_rev2.yml +++ b/sm_cm_config/data/MON_I2C_rev2.yml @@ -4,40 +4,102 @@ metadata: - cm_hw_rev: 2A - revision: 1 -config: -# - name: "bob" # register name -# reg_size: 1 # size of register address -# page: 0 -# reg_address: 0x1 # actual register address -# size: 0 # how many bytes to read -# bit_mask: 0xFFFF # ?? -# units: A -# type: Linear11 # bitfield, linear11 -# devices: # list of devices that have this register. 14G, 25G-12, 25G-4, CERN-B. - - name: FF_STATUS_REG - reg_size: 1 - page: 0 - reg_address: 0x2 - size: 2 - mask: 0xFF - units: "" - type: PM_STATUS - devices: [14G, 25G12, 25G4, CERNB] - - name: FF_TEMPERATURE - reg_size: 1 - page: 0 - reg_address: 0x16 - size: 2 - mask: 0xFF - units: C - type: PM_NONVOLTAGE - devices: [14G, 25G12, 25G4, CERNB] - - name: FF_LOS_ALARM - reg_size: 1 - page: 0 - reg_address: 0x07 - size: 2 - mask: 0xFFFF - units: "" - type: PM_STATUS - devices: [25G12, 25G4] +devices: + - name: Fireflies + ndevices: NFIREFLIES + prefix: FF + config: + # - name: "bob" # register name + # reg_size: 1 # size of register address + # page: 0 + # reg_address: 0x1 # actual register address by device type + # size: 0 # how many bytes to read + # bit_mask: 0xFFFF # ?? + # units: A + # type: Linear11 # bitfield, linear11, linear16 + # devices: # list of devices that have this register. 14G, 25G-12, 25G-4, CERN-B. + - name: FF_STATUS_REG + reg_size: 1 + page: 0 + reg_address: 0x2 + size: 2 + mask: 0xFF + units: "" + type: PM_STATUS + devices: [CERNB, 14G, 25G4, 25G12] + - name: FF_TEMPERATURE + reg_size: 1 + page: 0 + reg_address: 0x16 + size: 2 + mask: 0xFF + units: C + type: PM_NONVOLTAGE + devices: [14G, 25G12, 25G4, CERNB] + - name: FF_LOS_ALARM + reg_size: 1 + page: 0 + reg_address: 0x07 + size: 2 + mask: 0xFFFF + units: "" + type: PM_STATUS + devices: [25G12, 25G4] + - name: FF_OPT_POWER_CH1 + reg_size: 1 + page: 0 + reg_address: [-1, -1, 0x22, 0xe4] + size: 2 + mask: 0xFFFF + units: uW + type: PM_VOLTAGE + devices: [25G4, 25G12] + - name: Clocks + ndevices: NDEVICES_CLK + prefix: CLK + config: + - name: CLK_PN_BASE + reg_size: 1 + page: 0 + reg_address: 0x2 + size: 2 + mask: 0xFFFF + units: "" + type: PM_STATUS + devices: [SI5395, SI5341] + - name: CLK_DEVICE_REV + reg_size: 1 + page: 0 + reg_address: 0x5 + size: 1 + mask: 0xFF + units: "" + type: PM_STATUS + devices: [SI5395, SI5341] + - name: CLK_I2C_ADDR + reg_size: 1 + page: 0 + reg_address: 0xB + size: 1 + mask: 0xFF + units: "" + type: PM_STATUS + devices: [SI5395, SI5341] + - name: CLK_STATUS + reg_size: 1 + page: 0 + reg_address: 0x35 + size: 1 + mask: 0xFF + units: "" + type: PM_STATUS + devices: [SI5341] + - name: CLK_LOL + reg_size: 1 + page: 0 + reg_address: 0xE + size: 1 + mask: 0x02 + units: "" + type: PM_STATUS + devices: [SI5395] diff --git a/sm_cm_config/src/mon_generate.py b/sm_cm_config/src/mon_generate.py index 5a3f21c8..3d944fdf 100755 --- a/sm_cm_config/src/mon_generate.py +++ b/sm_cm_config/src/mon_generate.py @@ -7,36 +7,25 @@ import argparse import datetime import subprocess +import io from string import Template import yaml -parser = argparse.ArgumentParser(description='Process YAML for MCU Mon.') -parser.add_argument('-v', '--verbose', action='store_true', +def parse_args() -> argparse.Namespace: + """Parse the command line arguments""" + parser = argparse.ArgumentParser(description='Process YAML for MCU Mon.') + parser.add_argument('-v', '--verbose', action='store_true', help='increase output verbosity') -parser.add_argument('-o', '--output', type=str, help='output file name', + parser.add_argument('-o', '--output', type=str, help='output file name', default="MonI2C_addresses.c") #this argument is required -parser.add_argument('input_files', metavar='file', type=str, + parser.add_argument('input_files', metavar='file', type=str, nargs='+', help='input yaml file names') -args = parser.parse_args() + return parser.parse_args() -if args.output and args.verbose: - print('Output file name:', args.output) - -addr_template = Template("{$reg_size, $page, $reg_address, $size, \"$name\"," - " $mask, \"$units\", $type, get_${name}_mask, set_${name}_data}, ") -# output file names: header file and c source file -# make sure that the output file ends with .c. Print error message and exit if it doesn't -if not args.output.endswith(".c"): - print(f"Output file name {args.output} does not end with .c") - sys.exit(1) -source_fname = args.output -header_fname = args.output[:-2] + '.h' - -# open output c source file for writing -def write_boilderplate(fout): +def write_boilderplate(fout: io.TextIOWrapper): """Write the boilerplate to the output file""" print(f"// This file is generated by {os.path.basename(sys.argv[0])}", file=fout) print(r"// Do not edit this file directly", file=fout) @@ -50,12 +39,41 @@ def write_boilderplate(fout): print(f"// Generated: {timestamp}", file=fout) print(r"//", file=fout) +####################################### +# +# parse the command line arguments +# +####################################### +args = parse_args() + +if args.output and args.verbose: + print('Output file name:', args.output) + +# addr_template = Template("{$reg_size, $page, $reg_address, $size, \"$name\"," +# " $mask, \"$units\", $type, get_${name}_mask, set_${name}_data}, ") +addr_template = Template("{$reg_size, $page, $reg_list, $size, \"$name\"," + " $mask, \"$units\", $type, get_${name}_mask, set_${name}_data}, ") +# output file names: header file and c source file +# make sure that the output file ends with .c. Print error message and exit if it doesn't +if not args.output.endswith(".c"): + print(f"Output file name {args.output} does not end with .c") + sys.exit(1) +source_fname = args.output +header_fname = args.output[:-2] + '.h' + +####################################### +# +# end of processing command line arguments +# +####################################### + +# open output c source file for writing with open(source_fname, 'w', encoding="ascii") as fout_source, \ open(header_fname, 'w', encoding="ascii") as fout_header: write_boilderplate(fout_source) write_boilderplate(fout_header) print("#include \"stdint.h\"", file=fout_source) - print("#include \"MonitorI2CTask.h\"", file=fout_source) + print("#include \"MonitorTaskI2C_new.h\"", file=fout_source) print(f"#include \"{header_fname}\"", file=fout_source) # header file @@ -67,43 +85,62 @@ def write_boilderplate(fout): with open(args.input_files[0], encoding="ascii") as f: # generate the list of registers to access - print(r"struct sm_command_t sm_command_test[] = {", file=fout_source) + # loop over devices first data = yaml.load(f, Loader=yaml.FullLoader) - config = data['config'] - for c in config: - s = addr_template.substitute(c) - print(s, file=fout_source) - print(r"};", file=fout_source) - - # generate the arrays to store the data - print(r"// Arrays to store the data", file=fout_source) - for c in config: - print(f"static uint16_t {c['name']}_data[NFIREFLIES] = {{0}};", file=fout_source) - # generate access functions - print(r"// Access functions", file=fout_source) - for c in config: - set_fcn_name = f"set_{c['name']}_data" - # getter - print(f"uint16_t get_{c['name']}_data(int which);", file=fout_header) - print(f"uint16_t get_{c['name']}_data(int which) {{", file=fout_source) - print(f" return {c['name']}_data[which];", file=fout_source) - print(r"}", file=fout_source) - # setter - print(f"void {set_fcn_name}(uint16_t data, int which);", file=fout_header) - print(f"void {set_fcn_name}(uint16_t data, int which) {{", file=fout_source) - print(f" {c['name']}_data[which] = data;", file=fout_source) - print(r"}", file=fout_source) - # using the devices field, generate a function that returns a mask of the devices - print(r"// Function to return a mask of the devices for each command", file=fout_source) - for c in config: - print(f"uint16_t get_{c['name']}_mask(void);", file=fout_header) - print(f"uint16_t get_{c['name']}_mask(void) {{", file=fout_source) - print(r" return ", end="", file=fout_source) - for d in c['devices']: - print(f"DEVICE_{d} | ", end="", file=fout_source) - print(r"0;", file=fout_source) - print(r"}", file=fout_source) - # closing header guard + for d in data['devices']: + + ndev = d['ndevices'] + prefix = d['prefix'] + config = d['config'] + print(f"#define {prefix}_NOT_COVERED (-1)", file=fout_source) + print(f"struct i2c_reg_command_t sm_command_test_{prefix}[] = {{", file=fout_source) + for c in config: + reg_list = c['reg_address'] + print(f"reg list is >{reg_list}<") + # if reg_list is an integer, convert it to a list of 4 integers + # this handles the case where all 4 types share the same address + if isinstance(reg_list, int): + reg_list = [reg_list, reg_list, reg_list, reg_list] + reg_list_str = '{' + for r in reg_list: + if r > 0: + reg_list_str += f"{r}, " + else: + reg_list_str += f"{prefix}_NOT_COVERED, " + reg_list_str += "}" + s = addr_template.substitute(c, reg_list=reg_list_str) + print(s, file=fout_source) + print(r"};", file=fout_source) + + # generate the arrays to store the data + print(r"// Arrays to store the data", file=fout_source) + for c in config: + print(f"static uint16_t {c['name']}_data[{ndev}] = {{0}};", file=fout_source) + # generate access functions + print(r"// Access functions", file=fout_source) + for c in config: + set_fcn_name = f"set_{c['name']}_data" + # getter + print(f"uint16_t get_{c['name']}_data(int which);", file=fout_header) + print(f"uint16_t get_{c['name']}_data(int which) {{", file=fout_source) + print(f" return {c['name']}_data[which];", file=fout_source) + print(r"}", file=fout_source) + # setter + print(f"void {set_fcn_name}(uint16_t data, int which);", file=fout_header) + print(f"void {set_fcn_name}(uint16_t data, int which) {{", file=fout_source) + print(f" {c['name']}_data[which] = data;", file=fout_source) + print(r"}", file=fout_source) + # using the devices field, generate a function that returns a mask of the devices + print(r"// Function to return a mask of the devices for each command", file=fout_source) + for c in config: + print(f"uint16_t get_{c['name']}_mask(void);", file=fout_header) + print(f"uint16_t get_{c['name']}_mask(void) {{", file=fout_source) + print(r" return ", end="", file=fout_source) + for d in c['devices']: + print(f"DEVICE_{d} | ", end="", file=fout_source) + print(r"0;", file=fout_source) + print(r"}", file=fout_source) + # closing header guard print(r"#endif// MON_I2C_ADDRESSES_H", file=fout_header) # reformat the c file using clang-format From 490b44982284af8c48595eb753ad13e849c83651 Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Sun, 19 May 2024 16:20:24 -0400 Subject: [PATCH 13/71] WIP --- .clang-tidy | 7 ++--- .clangd | 5 ++++ projects/cm_mcu/FireflyUtils.c | 9 ++++--- projects/cm_mcu/I2CSlaveTask.c | 5 ---- projects/cm_mcu/LocalTasks.c | 24 ++++++++--------- projects/cm_mcu/Makefile | 1 + projects/cm_mcu/MonUtils.c | 39 +++++++++++++++++++++++++--- projects/cm_mcu/MonitorI2CTask.h | 13 ++++------ projects/cm_mcu/MonitorTaskI2C_new.c | 28 +++++++++++++------- projects/cm_mcu/MonitorTaskI2C_new.h | 37 +++++++++++--------------- projects/cm_mcu/Tasks.h | 14 +++++----- projects/cm_mcu/clocksynth.c | 6 ++--- projects/cm_mcu/cm_mcu.c | 20 +++++++------- sm_cm_config/src/mon_generate.py | 17 +++++++----- 14 files changed, 131 insertions(+), 94 deletions(-) create mode 100644 .clangd diff --git a/.clang-tidy b/.clang-tidy index 8e0c8eda..7eb07ecc 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -21,12 +21,14 @@ Checks: -*, ,readability-uniqueptr-delete-release, ,security* ,-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling + ,readability-braces-around-statements + ,readability-* WarningsAsErrors: '' AnalyzeTemporaryDtors: false HeaderFilterRegex: .*FreeRTOS.*/.* CheckOptions: - - key: google-readability-braces-around-statements.ShortStatementLines - value: '1' + - key: readability-braces-around-statements.ShortStatementLines + value: '5' - key: google-readability-function-size.StatementThreshold value: '800' - key: google-readability-namespace-comments.ShortNamespaceLines @@ -46,4 +48,3 @@ CheckOptions: - key: modernize-use-nullptr.NullMacros value: 'NULL' ... - diff --git a/.clangd b/.clangd new file mode 100644 index 00000000..8cd23b26 --- /dev/null +++ b/.clangd @@ -0,0 +1,5 @@ +Diagnostics: + ClangTidy: + Add: modernize* + Remove: readability-braces-around-statements + diff --git a/projects/cm_mcu/FireflyUtils.c b/projects/cm_mcu/FireflyUtils.c index 72942490..3322b7aa 100644 --- a/projects/cm_mcu/FireflyUtils.c +++ b/projects/cm_mcu/FireflyUtils.c @@ -18,6 +18,7 @@ #include "I2CCommunication.h" #include "MonitorI2CTask.h" #include "common/smbus_helper.h" +#include "driverlib/eeprom.h" #include "FireflyUtils.h" uint32_t ff_PRESENT_mask = 0; // global variable from getting combined ff signals @@ -147,10 +148,10 @@ void readFFpresent(void) ((present_FFL12_BOTTOM_F1)); // 6 bits #elif defined(REV2) - present_FFL12_F1 = present_FFL12_F1 & 0x3FU; // bottom 6 bits - present_FFL12_F2 = present_FFL12_F2 & 0x3FU; // bottom 6 bits - present_FFL4_F1 = (present_FFL4_F1 >> 4) & 0xFU; // bits 4-7 - present_FFL4_F2 = (present_FFL4_F2 >> 4) & 0xFU; // bits 4-7 + present_FFL12_F1 = present_FFL12_F1 & 0x3FU; // bottom 6 bits + present_FFL12_F2 = present_FFL12_F2 & 0x3FU; // bottom 6 bits + present_FFL4_F1 = (present_FFL4_F1 >> 4) & 0xFU; // bits 4-7 + present_FFL4_F2 = (present_FFL4_F2 >> 4) & 0xFU; // bits 4-7 uint32_t ff_combined_present = ((present_FFL4_F2) << 16) | // 4 bits ((present_FFL12_F2) << 10) | // 6 bits diff --git a/projects/cm_mcu/I2CSlaveTask.c b/projects/cm_mcu/I2CSlaveTask.c index bca70fa8..96e25138 100644 --- a/projects/cm_mcu/I2CSlaveTask.c +++ b/projects/cm_mcu/I2CSlaveTask.c @@ -9,18 +9,13 @@ #include #include "inc/hw_memmap.h" -#include "inc/hw_ints.h" // to be removed -#include "inc/hw_i2c.h" -#include "inc/hw_types.h" #include "driverlib/rom.h" // to be removed #include "driverlib/i2c.h" // to be removed #include "InterruptHandlers.h" #include "Tasks.h" #include "MonitorTask.h" -#include "common/LocalUart.h" #include "common/log.h" #include "FireflyUtils.h" -#include "I2CSlaveTask.h" // Rev 2: // All that needs to be done is rename local_fpga_{v,k}u to diff --git a/projects/cm_mcu/LocalTasks.c b/projects/cm_mcu/LocalTasks.c index c368db78..c8130001 100644 --- a/projects/cm_mcu/LocalTasks.c +++ b/projects/cm_mcu/LocalTasks.c @@ -156,8 +156,8 @@ struct MonitorI2CTaskArgs_t ffl4_f1_args = { .n_pages = NPAGES_FFL4_F1, .selpage_reg = FF_SELPAGE_REG, .sm_values = ffl4_f1_values, - .smbus = &g_sMaster4, - .smbus_status = &eStatus4, + // .smbus = &g_sMaster4, + // .smbus_status = &eStatus4, .xSem = NULL, .stack_size = 4096U, }; @@ -247,8 +247,8 @@ struct MonitorI2CTaskArgs_t ffl12_f1_args = { .n_pages = NPAGES_FFL12_F1, .selpage_reg = FF_SELPAGE_REG, .sm_values = ffl12_f1_values, - .smbus = &g_sMaster4, - .smbus_status = &eStatus4, + // .smbus = &g_sMaster4, + // .smbus_status = &eStatus4, .xSem = NULL, .stack_size = 4096U, }; @@ -301,8 +301,8 @@ struct MonitorI2CTaskArgs_t ffl4_f2_args = { .n_pages = NPAGES_FFL4_F2, .selpage_reg = FF_SELPAGE_REG, .sm_values = ffl4_f2_values, - .smbus = &g_sMaster3, - .smbus_status = &eStatus3, + // .smbus = &g_sMaster3, + // .smbus_status = &eStatus3, .xSem = NULL, .stack_size = 4096U, }; @@ -385,8 +385,8 @@ struct MonitorI2CTaskArgs_t ffl12_f2_args = { .n_pages = NPAGES_FFL12_F2, .selpage_reg = FF_SELPAGE_REG, .sm_values = ffl12_f2_values, - .smbus = &g_sMaster3, - .smbus_status = &eStatus3, + // .smbus = &g_sMaster3, + // .smbus_status = &eStatus3, .xSem = NULL, .stack_size = 4096U, }; @@ -435,8 +435,8 @@ struct MonitorI2CTaskArgs_t clock_args = { .n_pages = NPAGES_CLK, .selpage_reg = CLK_SELPAGE_REG, .sm_values = clk_values, - .smbus = &g_sMaster2, - .smbus_status = &eStatus2, + // .smbus = &g_sMaster2, + // .smbus_status = &eStatus2, .xSem = NULL, .stack_size = 4096U, }; @@ -472,8 +472,8 @@ struct MonitorI2CTaskArgs_t clockr0a_args = { .n_pages = NPAGES_CLKR0A, .selpage_reg = CLK_SELPAGE_REG, .sm_values = clkr0a_values, - .smbus = &g_sMaster2, - .smbus_status = &eStatus2, + // .smbus = &g_sMaster2, + // .smbus_status = &eStatus2, .xSem = NULL, .stack_size = 4096U, }; diff --git a/projects/cm_mcu/Makefile b/projects/cm_mcu/Makefile index 57c2962b..73161f8b 100644 --- a/projects/cm_mcu/Makefile +++ b/projects/cm_mcu/Makefile @@ -176,6 +176,7 @@ ${COMPILER}/cm_mcu.axf: ${COMPILER}/MonI2C_addresses.o ${COMPILER}/cm_mcu.axf: ${COMPILER}/ZynqMonTask.o ${COMPILER}/cm_mcu.axf: ${COMPILER}/InterruptHandlers.o ${COMPILER}/cm_mcu.axf: ${COMPILER}/InitTask.o +${COMPILER}/cm_mcu.axf: ${COMPILER}/MonUtils.o ${COMPILER}/cm_mcu.axf: ${COMPILER}/WatchdogTask.o ${COMPILER}/cm_mcu.axf: ${COMPILER}/LocalTasks.o ${COMPILER}/cm_mcu.axf: ${COMPILER}/BoardCommands.o diff --git a/projects/cm_mcu/MonUtils.c b/projects/cm_mcu/MonUtils.c index 9f459b5d..cdaebe4a 100644 --- a/projects/cm_mcu/MonUtils.c +++ b/projects/cm_mcu/MonUtils.c @@ -1,15 +1,17 @@ #include "MonitorTaskI2C_new.h" +#include "MonI2C_addresses.h" +#include "FireflyUtils.h" -int FirefflyType(int device) +int FireflyType(int device) { switch (device) { case 0: case 1: case 2: case 3: { - // fixme: this should be a check on CERN-B or ECUO-[RT]12-25 - // with a function call - return DEVICE_25G12; + // fixme: this should be a check on CERN-B or ECUO-[RT]12-25 + // with a function call + return DEVICE_25G12; } case 4: case 5: @@ -37,4 +39,33 @@ int ClockType(int device) return DEVICE_NONE; } } + +struct MonitorI2CTaskArgs_new_t ff_f1_args = { + .name = "FF_F1", + .devices = ffl12_f2_moni2c_addrs, + .i2c_dev = I2C_DEVICE_F1, + .n_devices = NDEVICES_FFL4_F1, // FIXME: NDEVICES_FF_F1 + .commands = sm_command_test_FF, + .n_commands = NCOMMANDS_FF, + .selpage_reg = FF_SELPAGE_REG, + .xSem = NULL, + .stack_size = 4096U, + .typeCallback = FireflyType, + .presentCallback = isEnabledFF, +}; + +struct MonitorI2CTaskArgs_new_t ff_f2_args = { + .name = "FF_F2", + .devices = ffl12_f2_moni2c_addrs, + .i2c_dev = I2C_DEVICE_F2, + .n_devices = NDEVICES_FFL12_F2, // FIXME: NDEVICES_FF_F2 + .commands = sm_command_test_FF, + .n_commands = NCOMMANDS_FF, + .selpage_reg = FF_SELPAGE_REG, + .xSem = NULL, + .stack_size = 4096U, + .typeCallback = FireflyType, + .presentCallback = isEnabledFF, +}; + #endif // REV2 diff --git a/projects/cm_mcu/MonitorI2CTask.h b/projects/cm_mcu/MonitorI2CTask.h index 466ee41c..a1ce7fd6 100644 --- a/projects/cm_mcu/MonitorI2CTask.h +++ b/projects/cm_mcu/MonitorI2CTask.h @@ -8,8 +8,7 @@ #ifndef PROJECTS_CM_MCU_MONITORI2CTASK_H_ #define PROJECTS_CM_MCU_MONITORI2CTASK_H_ -#include "common/smbus.h" -#include "FreeRTOS.h" +#include "FreeRTOS.h" // IWYU pragma: keep #include "semphr.h" #include "Tasks.h" #include "FireflyUtils.h" @@ -40,12 +39,10 @@ struct MonitorI2CTaskArgs_t { const uint8_t n_pages; // number of pages to loop over const uint16_t selpage_reg; // register for selecting page uint16_t *sm_values; - tSMBus *smbus; // pointer to I2C controller - volatile tSMBusStatus *smbus_status; // pointer to I2C status - TickType_t updateTick; // last update time, in ticks - SemaphoreHandle_t xSem; // semaphore for controlling access to device - UBaseType_t stack_size; // stack size of task - MonTaskFcnPointer presentCallback; // callback for present check + TickType_t updateTick; // last update time, in ticks + SemaphoreHandle_t xSem; // semaphore for controlling access to device + UBaseType_t stack_size; // stack size of task + MonTaskFcnPointer presentCallback; // callback for present check }; #define FF_SELPAGE_REG 0x7f diff --git a/projects/cm_mcu/MonitorTaskI2C_new.c b/projects/cm_mcu/MonitorTaskI2C_new.c index 24d93f64..69c11c7b 100644 --- a/projects/cm_mcu/MonitorTaskI2C_new.c +++ b/projects/cm_mcu/MonitorTaskI2C_new.c @@ -84,8 +84,11 @@ void MonitorI2CTask_new(void *parameters) // loop over devices in the device-type instance // ------------------------------- for (int device = 0; device < args->n_devices; ++device) { + if (args->presentCallback && !args->presentCallback(device)) { + log_debug(LOG_MONI2C, "%s: device %d not present\r\n", args->name, device); + continue; + } log_debug(LOG_MONI2C, "%s: device %d powercheck\r\n", args->name, device); - if (getPowerControlState() != POWER_ON) { if (good) { log_info(LOG_MONI2C, "%s: PWR off. Disable I2Cmon.\r\n", args->name); @@ -106,7 +109,7 @@ void MonitorI2CTask_new(void *parameters) } // what kind of device do we have (e.g., 4 ch FF, 12 ch 25 G FF, 12 ch CERN-B FF, etc.) int devtype = args->typeCallback(device); - int dev_mask = 0x1U << device; + uint32_t dev_mask = 0x1U << device; // select the appropriate output for the mux uint8_t data; @@ -117,23 +120,27 @@ void MonitorI2CTask_new(void *parameters) log_warn(LOG_MONI2C, "Mux write error %s, break (instance=%s,ps=%d)\r\n", SMBUS_get_error(res), args->name, device); break; } - + uint8_t last_page_reg_value = 0xff; // Read I2C registers/commands for (int c = 0; c < args->n_commands; ++c) { // check if the command is for this device - if ((args->commands[c].devicelist() & dev_mask) == 0 ) { + if ((args->commands[c].devicelist() & dev_mask) == 0) { continue; // not for me! } - + // set page register if it's different than the last time log_debug(LOG_MONI2C, "%s: reg %s\r\n", args->name, args->commands[c].name); uint8_t page_reg_value = args->commands[c].page; - int r = apollo_i2c_ctl_reg_w(args->i2c_dev, args->devices[device].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[device].name, SMBUS_get_error(r)); - break; + if (page_reg_value != last_page_reg_value) { + int r = apollo_i2c_ctl_reg_w(args->i2c_dev, args->devices[device].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[device].name, SMBUS_get_error(r)); + break; + } + last_page_reg_value = page_reg_value; } + // get the data from the I2C register uint32_t output_raw; int res = apollo_i2c_ctl_reg_r(args->i2c_dev, args->devices[device].dev_addr, args->commands[c].reg_size, args->commands[c].command[devtype], args->commands[c].size, &output_raw); @@ -141,7 +148,7 @@ void MonitorI2CTask_new(void *parameters) if (res != 0) { log_error(LOG_MONI2C, "%s: %s read Error %s, break (ps=%d)\r\n", args->name, args->commands[c].name, SMBUS_get_error(res), device); - args->commands[c].storeData(0xffff, device); + args->commands[c].storeData(0xffff, device); // store error value break; } else { @@ -154,6 +161,7 @@ void MonitorI2CTask_new(void *parameters) log_debug(LOG_MONI2C, "%s: end loop commands\r\n", args->name); args->updateTick = xTaskGetTickCount(); // current time in ticks + // clear out the I2C mux res = apollo_i2c_ctl_w(args->i2c_dev, args->devices[device].mux_addr, 1, 0); if (res != 0) { log_warn(LOG_MONI2C, "Mux write error %s, break (instance=%s,ps=%d)\r\n", SMBUS_get_error(res), args->name, device); diff --git a/projects/cm_mcu/MonitorTaskI2C_new.h b/projects/cm_mcu/MonitorTaskI2C_new.h index 65660253..f9f0f469 100644 --- a/projects/cm_mcu/MonitorTaskI2C_new.h +++ b/projects/cm_mcu/MonitorTaskI2C_new.h @@ -8,8 +8,7 @@ #ifndef PROJECTS_CM_MCU_MONITORI2CTASK_H_ #define PROJECTS_CM_MCU_MONITORI2CTASK_H_ -#include "common/smbus.h" -#include "FreeRTOS.h" +#include "FreeRTOS.h" // IWYU pragma: keep #include "semphr.h" #include "Tasks.h" #include "FireflyUtils.h" @@ -35,30 +34,26 @@ struct i2c_reg_command_t { char *units; // units for pretty printing enum pm_type type; // how to decode command (L11 or bitfield or ...) uint16_t (*devicelist)(void); - void (*storeData)(uint16_t data, int which); // store data in location which + void (*storeData)(uint16_t data, int which); // store data in location which }; // how to find an I2C device, with a mux infront of it. -typedef bool (*MonTaskFcnPointer)(struct MonitorI2CTaskArgs_t *); +typedef bool (*MonTaskFcnPointer)(int device); typedef int (*MonTaskI2CTypeFcnPointer)(int); // what kind of device we have (i.e., for FF, CERN-B, B04, Y12-14, Y12-25, etc.) struct MonitorI2CTaskArgs_new_t { - const char *name; // name to be assigned to the task - struct dev_moni2c_addr_t *devices; // list of devices to query - int i2c_dev; // i2c controller # - int n_devices; // number of devices - struct i2c_reg_command_t *commands; // list of commands - const uint8_t n_commands; // number of commands - const int n_values; // number of results - const uint8_t n_pages; // number of pages to loop over - const uint16_t selpage_reg; // register for selecting page - tSMBus *smbus; // pointer to I2C controller - volatile tSMBusStatus *smbus_status; // pointer to I2C status - TickType_t updateTick; // last update time, in ticks - SemaphoreHandle_t xSem; // semaphore for controlling access to device - UBaseType_t stack_size; // stack size of task - MonTaskFcnPointer presentCallback; // callback for present check + const char *name; // name to be assigned to the task + struct dev_moni2c_addr_t *devices; // list of devices to query + int i2c_dev; // i2c controller # + int n_devices; // number of devices + struct i2c_reg_command_t *commands; // list of commands + const uint8_t n_commands; // number of commands + const uint16_t selpage_reg; // register for selecting page + TickType_t updateTick; // last update time, in ticks + SemaphoreHandle_t xSem; // semaphore for controlling access to device + UBaseType_t stack_size; // stack size of task + MonTaskFcnPointer presentCallback; // callback for present check MonTaskI2CTypeFcnPointer typeCallback; // callback for type check }; @@ -103,7 +98,6 @@ extern struct dev_moni2c_addr_t ffl12_f2_moni2c_addrs[NFIREFLIES_IT_F2]; extern struct dev_moni2c_addr_t ffl4_f2_moni2c_addrs[NFIREFLIES_DAQ_F2]; #define NDEVICES_CLK (4) -#define NCOMMANDS_CLK 7 // number of commands #define NCOMMANDS_FLG_CLK 1 // number of sticky commands #define NPAGES_CLK 1 // #define NDEVICES_CLKR0A (1) @@ -111,7 +105,6 @@ extern struct dev_moni2c_addr_t ffl4_f2_moni2c_addrs[NFIREFLIES_DAQ_F2]; #define NCOMMANDS_FLG_CLKR0A 2 // number of sticky commands #define NPAGES_CLKR0A 1 // - // for autogenerated code #define DEVICE_CERNB 0x01 #define DEVICE_14G 0x02 @@ -120,6 +113,6 @@ extern struct dev_moni2c_addr_t ffl4_f2_moni2c_addrs[NFIREFLIES_DAQ_F2]; #define DEVICE_SI5395 0x10 #define DEVICE_SI5341 0x20 -#define DEVICE_NONE 0x80 +#define DEVICE_NONE 0x80 #endif /* PROJECTS_CM_MCU_MONITORI2CTASK_H_ */ diff --git a/projects/cm_mcu/Tasks.h b/projects/cm_mcu/Tasks.h index ede6ca87..e5b71e48 100644 --- a/projects/cm_mcu/Tasks.h +++ b/projects/cm_mcu/Tasks.h @@ -11,14 +11,14 @@ #ifndef PROJECTS_CM_MCU_TASKS_H_ #define PROJECTS_CM_MCU_TASKS_H_ -#include "FreeRTOS.h" -#include "FreeRTOSConfig.h" +#include "FreeRTOS.h" // IWYU pragma: keep +// #include "FreeRTOSConfig.h" #include "queue.h" #include "semphr.h" #include "common/log.h" -#include "driverlib/eeprom.h" +// #include "driverlib/eeprom.h" -#include "common/printf.h" +// #include "common/printf.h" #include #include "clocksynth.h" @@ -341,11 +341,11 @@ uint16_t task_watchdog_get_status(void); #define CHECK_TASK_STACK_USAGE(vv) \ { \ UBaseType_t val = uxTaskGetStackHighWaterMark(NULL); \ - if (val < vv) { \ + if (val < (vv)) { \ log_debug(LOG_SERVICE, "stack (%s) = %d(was %d)\r\n", pcTaskGetName(NULL), val, \ - vv); \ + (vv)); \ } \ - vv = val; \ + (vv) = val; \ } #endif /* PROJECTS_CM_MCU_TASKS_H_ */ diff --git a/projects/cm_mcu/clocksynth.c b/projects/cm_mcu/clocksynth.c index 86631bd7..ef8f6735 100644 --- a/projects/cm_mcu/clocksynth.c +++ b/projects/cm_mcu/clocksynth.c @@ -104,7 +104,7 @@ void getClockProgram(int device, char progname_clkdesgid[CLOCK_PROGNAME_REG_NAME CLOCK_CHANGEPAGE_REG_ADDR, 1, page); // now read out the six bytes of data in two reads - const uint8_t reg = (CLOCK_PROGNAME_REG_ADDR_START) & 0xFF; + const uint8_t reg = (CLOCK_PROGNAME_REG_ADDR_START)&0xFF; uint16_t init_postamble_page = 32 * (device + 1) - 1; // read the addresses in EEPROM that store the number of registers in Preamble-register, Register, and Postamble-register list per a clock config file @@ -131,10 +131,10 @@ void getClockProgram(int device, char progname_clkdesgid[CLOCK_PROGNAME_REG_NAME // as eepromdata[0] and eepromdat[1],respectively // third byte from three addresses in EEPROM is a value byte - apollo_i2c_ctl_reg_r(CLOCK_I2C_DEV, CLOCK_I2C_EEPROM_ADDR, 2, eeprom_progname_reg + ((i) * 3), 3, tempdata); + apollo_i2c_ctl_reg_r(CLOCK_I2C_DEV, CLOCK_I2C_EEPROM_ADDR, 2, eeprom_progname_reg + ((i)*3), 3, tempdata); eepromdata[0] |= ((tempdata[0] >> (16)) & 0xFF) << (i * 8); // third byte from three addresses in EEPROM is a value byte - apollo_i2c_ctl_reg_r(CLOCK_I2C_DEV, CLOCK_I2C_EEPROM_ADDR, 2, eeprom_progname_reg + 12 + ((i) * 3), 3, tempdata); + apollo_i2c_ctl_reg_r(CLOCK_I2C_DEV, CLOCK_I2C_EEPROM_ADDR, 2, eeprom_progname_reg + 12 + ((i)*3), 3, tempdata); eepromdata[1] |= ((tempdata[0] >> (16)) & 0xFF) << (i * 8); } } diff --git a/projects/cm_mcu/cm_mcu.c b/projects/cm_mcu/cm_mcu.c index 2819075a..5a11b90f 100644 --- a/projects/cm_mcu/cm_mcu.c +++ b/projects/cm_mcu/cm_mcu.c @@ -20,10 +20,10 @@ #include "FreeRTOSConfig.h" #include "common/LocalUart.h" #include "common/utils.h" -#include "common/power_ctl.h" +// #include "common/power_ctl.h" #include "common/i2c_reg.h" #include "common/pinout.h" -#include "common/pinsel.h" +// #include "common/pinsel.h" #include "common/smbus.h" #include "common/log.h" #include "CommandLineTask.h" @@ -31,25 +31,25 @@ #include "MonitorI2CTask.h" #include "MonitorTask.h" #include "Tasks.h" -#include "I2CSlaveTask.h" +// #include "I2CSlaveTask.h" #include "AlarmUtilities.h" // TI Includes #include "driverlib/rom.h" #include "driverlib/rom_map.h" -#include "inc/hw_types.h" +// #include "inc/hw_types.h" #include "inc/hw_memmap.h" #include "inc/hw_ints.h" -#include "driverlib/pin_map.h" +// #include "driverlib/pin_map.h" #include "driverlib/sysctl.h" -#include "driverlib/gpio.h" +// #include "driverlib/gpio.h" #include "driverlib/i2c.h" #include "driverlib/adc.h" -#include "driverlib/uart.h" -#include "driverlib/interrupt.h" +// #include "driverlib/uart.h" +// #include "driverlib/interrupt.h" // FreeRTOS includes -#include "FreeRTOS.h" +#include "FreeRTOS.h" // IWYU pragma: keep #include "task.h" #include "queue.h" #include "stream_buffer.h" @@ -144,7 +144,7 @@ void SystemInitInterrupts(void) #if defined(REV1) initI2C6(g_ui32SysClock); // controller for FPGAs #elif defined(REV2) - initI2C5(g_ui32SysClock); // controller for FPGAs + initI2C5(g_ui32SysClock); // controller for FPGAs #endif // smbus diff --git a/sm_cm_config/src/mon_generate.py b/sm_cm_config/src/mon_generate.py index 3d944fdf..0f66bf62 100755 --- a/sm_cm_config/src/mon_generate.py +++ b/sm_cm_config/src/mon_generate.py @@ -72,14 +72,15 @@ def write_boilderplate(fout: io.TextIOWrapper): open(header_fname, 'w', encoding="ascii") as fout_header: write_boilderplate(fout_source) write_boilderplate(fout_header) - print("#include \"stdint.h\"", file=fout_source) - print("#include \"MonitorTaskI2C_new.h\"", file=fout_source) print(f"#include \"{header_fname}\"", file=fout_source) + #print("#include \"MonitorTaskI2C_new.h\"", file=fout_source) - # header file + # header file print(r"#ifndef MON_I2C_ADDRESSES_H", file=fout_header) print(r"#define MON_I2C_ADDRESSES_H", file=fout_header) - print("#include \"stdint.h\"", file=fout_header) + print("#include ", file=fout_header) + print("#include \"MonitorTaskI2C_new.h\"", file=fout_header) + #print("#include \"MonI2C_addresses.h\"", file=fout_header) with open(args.input_files[0], encoding="ascii") as f: @@ -88,12 +89,16 @@ def write_boilderplate(fout: io.TextIOWrapper): # loop over devices first data = yaml.load(f, Loader=yaml.FullLoader) for d in data['devices']: - ndev = d['ndevices'] prefix = d['prefix'] config = d['config'] + ncommands = len(config) + print(f"#define NCOMMANDS_{prefix} {ncommands}", file=fout_header) + print(f"// {prefix} has {ndev} devices and {ncommands} commands", file=fout_source) print(f"#define {prefix}_NOT_COVERED (-1)", file=fout_source) - print(f"struct i2c_reg_command_t sm_command_test_{prefix}[] = {{", file=fout_source) + print(f"struct i2c_reg_command_t sm_command_test_{prefix}[NCOMMANDS_{prefix}] = {{", + file=fout_source) + print(f"extern struct i2c_reg_command_t sm_command_test_{prefix}[];", file=fout_header) for c in config: reg_list = c['reg_address'] print(f"reg list is >{reg_list}<") From 63d601a77cf257d0f76ed891cebcb200aa42e7ba Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Sun, 19 May 2024 22:12:49 -0400 Subject: [PATCH 14/71] WIP --- projects/cm_mcu/FireflyUtils.h | 2 ++ projects/cm_mcu/LocalTasks.c | 29 +++++++++++++++++++++++++++-- projects/cm_mcu/MonUtils.c | 10 +++++----- projects/cm_mcu/Tasks.h | 1 + projects/cm_mcu/cm_mcu.c | 10 ++-------- sm_cm_config/src/mon_generate.py | 2 +- 6 files changed, 38 insertions(+), 16 deletions(-) diff --git a/projects/cm_mcu/FireflyUtils.h b/projects/cm_mcu/FireflyUtils.h index c92a44b3..182d4014 100644 --- a/projects/cm_mcu/FireflyUtils.h +++ b/projects/cm_mcu/FireflyUtils.h @@ -46,6 +46,8 @@ struct arg_moni2c_ff_t { }; extern struct dev_moni2c_addr_t ff_moni2c_addrs[NFIREFLIES]; +extern struct dev_moni2c_addr_t ff_moni2c_addrs_f1[NFIREFLIES_F1]; +extern struct dev_moni2c_addr_t ff_moni2c_addrs_f2[NFIREFLIES_F2]; extern struct arg_moni2c_ff_t ff_moni2c_arg[NFIREFLY_ARG]; // Samtec firefly specific commands diff --git a/projects/cm_mcu/LocalTasks.c b/projects/cm_mcu/LocalTasks.c index c8130001..507c3c07 100644 --- a/projects/cm_mcu/LocalTasks.c +++ b/projects/cm_mcu/LocalTasks.c @@ -14,6 +14,7 @@ #include // memset #include // struct tm +#include "FireflyUtils.h" #include "driverlib/hibernate.h" #include "Tasks.h" @@ -102,6 +103,31 @@ struct dev_moni2c_addr_t ff_moni2c_addrs[NFIREFLIES] = { {"F2_6 4 XCVR", FF_I2CMUX_2_ADDR, 1, 0x50}, // {"F2_7 4 XCVR", FF_I2CMUX_2_ADDR, 2, 0x50}, // +}; +struct dev_moni2c_addr_t ff_moni2c_addrs_f1[NFIREFLIES_F1] = { + {"F1_1 12 Tx", FF_I2CMUX_1_ADDR, 0, 0x50}, // + {"F1_1 12 Rx", FF_I2CMUX_1_ADDR, 1, 0x54}, // + {"F1_2 12 Tx", FF_I2CMUX_1_ADDR, 3, 0x50}, // + {"F1_2 12 Rx", FF_I2CMUX_1_ADDR, 4, 0x54}, // + {"F1_3 12 Tx", FF_I2CMUX_2_ADDR, 3, 0x50}, // + {"F1_3 12 Rx", FF_I2CMUX_2_ADDR, 4, 0x54}, // + {"F1_4 4 XCVR", FF_I2CMUX_1_ADDR, 2, 0x50}, // + {"F1_5 4 XCVR", FF_I2CMUX_2_ADDR, 0, 0x50}, // + {"F1_6 4 XCVR", FF_I2CMUX_2_ADDR, 1, 0x50}, // + {"F1_7 4 XCVR", FF_I2CMUX_2_ADDR, 2, 0x50}, // +}; +struct dev_moni2c_addr_t ff_moni2c_addrs_f2[NFIREFLIES_F2] = { + {"F2_1 12 Tx", FF_I2CMUX_1_ADDR, 0, 0x50}, // + {"F2_1 12 Rx", FF_I2CMUX_1_ADDR, 1, 0x54}, // + {"F2_2 12 Tx", FF_I2CMUX_1_ADDR, 3, 0x50}, // + {"F2_2 12 Rx", FF_I2CMUX_1_ADDR, 4, 0x54}, // + {"F2_3 12 Tx", FF_I2CMUX_2_ADDR, 3, 0x50}, // + {"F2_3 12 Rx", FF_I2CMUX_2_ADDR, 4, 0x54}, // + {"F2_4 4 XCVR", FF_I2CMUX_1_ADDR, 2, 0x50}, // + {"F2_5 4 XCVR", FF_I2CMUX_2_ADDR, 0, 0x50}, // + {"F2_6 4 XCVR", FF_I2CMUX_2_ADDR, 1, 0x50}, // + {"F2_7 4 XCVR", FF_I2CMUX_2_ADDR, 2, 0x50}, // + }; struct arg_moni2c_ff_t ff_moni2c_arg[NFIREFLY_ARG] = { @@ -222,8 +248,7 @@ struct dev_moni2c_addr_t ffl12_f1_moni2c_addrs[NFIREFLIES_IT_F1] = { }; #elif defined(REV2) struct dev_moni2c_addr_t ffl12_f1_moni2c_addrs[NFIREFLIES_IT_F1] = { - {"F1_1 12 Tx", - FF_I2CMUX_1_ADDR, 0, 0x50}, // + {"F1_1 12 Tx", FF_I2CMUX_1_ADDR, 0, 0x50}, // {"F1_1 12 Rx", FF_I2CMUX_1_ADDR, 1, 0x54}, // {"F1_2 12 Tx", FF_I2CMUX_1_ADDR, 3, 0x50}, // {"F1_2 12 Rx", FF_I2CMUX_1_ADDR, 4, 0x54}, // diff --git a/projects/cm_mcu/MonUtils.c b/projects/cm_mcu/MonUtils.c index cdaebe4a..263dbba7 100644 --- a/projects/cm_mcu/MonUtils.c +++ b/projects/cm_mcu/MonUtils.c @@ -9,7 +9,7 @@ int FireflyType(int device) case 1: case 2: case 3: { - // fixme: this should be a check on CERN-B or ECUO-[RT]12-25 + // FIXME: this should be a check on CERN-B or ECUO-[RT]12-25 // with a function call return DEVICE_25G12; } @@ -42,9 +42,9 @@ int ClockType(int device) struct MonitorI2CTaskArgs_new_t ff_f1_args = { .name = "FF_F1", - .devices = ffl12_f2_moni2c_addrs, + .devices = ff_moni2c_addrs_f1, .i2c_dev = I2C_DEVICE_F1, - .n_devices = NDEVICES_FFL4_F1, // FIXME: NDEVICES_FF_F1 + .n_devices = NFIREFLIES_F1, .commands = sm_command_test_FF, .n_commands = NCOMMANDS_FF, .selpage_reg = FF_SELPAGE_REG, @@ -56,9 +56,9 @@ struct MonitorI2CTaskArgs_new_t ff_f1_args = { struct MonitorI2CTaskArgs_new_t ff_f2_args = { .name = "FF_F2", - .devices = ffl12_f2_moni2c_addrs, + .devices = ff_moni2c_addrs_f2, .i2c_dev = I2C_DEVICE_F2, - .n_devices = NDEVICES_FFL12_F2, // FIXME: NDEVICES_FF_F2 + .n_devices = NFIREFLIES_F2, .commands = sm_command_test_FF, .n_commands = NCOMMANDS_FF, .selpage_reg = FF_SELPAGE_REG, diff --git a/projects/cm_mcu/Tasks.h b/projects/cm_mcu/Tasks.h index e5b71e48..a929a873 100644 --- a/projects/cm_mcu/Tasks.h +++ b/projects/cm_mcu/Tasks.h @@ -115,6 +115,7 @@ void LGA80D_init(void); // --- Semi-generic PMBUS based I2C task void MonitorTask(void *parameters); void MonitorI2CTask(void *parameters); +void MonitorI2CTask_new(void *parameters); #ifdef REV1 #define N_PM_ADDRS_DCDC 5 #elif defined(REV2) // REV2 diff --git a/projects/cm_mcu/cm_mcu.c b/projects/cm_mcu/cm_mcu.c index 5a11b90f..5ca971e9 100644 --- a/projects/cm_mcu/cm_mcu.c +++ b/projects/cm_mcu/cm_mcu.c @@ -20,10 +20,8 @@ #include "FreeRTOSConfig.h" #include "common/LocalUart.h" #include "common/utils.h" -// #include "common/power_ctl.h" #include "common/i2c_reg.h" #include "common/pinout.h" -// #include "common/pinsel.h" #include "common/smbus.h" #include "common/log.h" #include "CommandLineTask.h" @@ -31,22 +29,16 @@ #include "MonitorI2CTask.h" #include "MonitorTask.h" #include "Tasks.h" -// #include "I2CSlaveTask.h" #include "AlarmUtilities.h" // TI Includes #include "driverlib/rom.h" #include "driverlib/rom_map.h" -// #include "inc/hw_types.h" #include "inc/hw_memmap.h" #include "inc/hw_ints.h" -// #include "driverlib/pin_map.h" #include "driverlib/sysctl.h" -// #include "driverlib/gpio.h" #include "driverlib/i2c.h" #include "driverlib/adc.h" -// #include "driverlib/uart.h" -// #include "driverlib/interrupt.h" // FreeRTOS includes #include "FreeRTOS.h" // IWYU pragma: keep @@ -307,6 +299,8 @@ __attribute__((noreturn)) int main(void) NULL); xTaskCreate(MonitorI2CTask, ffl4_f2_args.name, 2 * configMINIMAL_STACK_SIZE, &ffl4_f2_args, tskIDLE_PRIORITY + 4, NULL); + xTaskCreate(MonitorI2CTask_new, ffl4_f2_args.name, 2 * configMINIMAL_STACK_SIZE, &ffl4_f2_args, tskIDLE_PRIORITY + 4, + NULL); #ifdef REV2 xTaskCreate(MonitorI2CTask, clock_args.name, 2 * configMINIMAL_STACK_SIZE, &clock_args, tskIDLE_PRIORITY + 4, diff --git a/sm_cm_config/src/mon_generate.py b/sm_cm_config/src/mon_generate.py index 0f66bf62..8dc028e8 100755 --- a/sm_cm_config/src/mon_generate.py +++ b/sm_cm_config/src/mon_generate.py @@ -101,7 +101,7 @@ def write_boilderplate(fout: io.TextIOWrapper): print(f"extern struct i2c_reg_command_t sm_command_test_{prefix}[];", file=fout_header) for c in config: reg_list = c['reg_address'] - print(f"reg list is >{reg_list}<") + #print(f"reg list is >{reg_list}<") # if reg_list is an integer, convert it to a list of 4 integers # this handles the case where all 4 types share the same address if isinstance(reg_list, int): From 8cd98a0f8c93d2794acf445c433f5a9abce116ff Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Mon, 20 May 2024 16:59:22 -0400 Subject: [PATCH 15/71] bug fixes --- projects/cm_mcu/MonUtils.c | 13 +++++++++---- projects/cm_mcu/MonitorI2CTask.h | 4 ---- projects/cm_mcu/MonitorTaskI2C_new.c | 12 +++++++----- projects/cm_mcu/MonitorTaskI2C_new.h | 10 ++++------ projects/cm_mcu/cm_mcu.c | 5 ++++- 5 files changed, 24 insertions(+), 20 deletions(-) diff --git a/projects/cm_mcu/MonUtils.c b/projects/cm_mcu/MonUtils.c index 263dbba7..c497d6da 100644 --- a/projects/cm_mcu/MonUtils.c +++ b/projects/cm_mcu/MonUtils.c @@ -1,22 +1,27 @@ #include "MonitorTaskI2C_new.h" #include "MonI2C_addresses.h" #include "FireflyUtils.h" +#include "MonUtils.h" +// for 12 channel parts, there is one Tx and Rx device. +// for 4 channel parts, there is one XCVR part int FireflyType(int device) { switch (device) { case 0: case 1: case 2: - case 3: { + case 3: + case 4: + case 5: { // FIXME: this should be a check on CERN-B or ECUO-[RT]12-25 // with a function call - return DEVICE_25G12; + return DEVICE_CERNB; } - case 4: - case 5: case 6: case 7: + case 8: + case 9: return DEVICE_25G4; default: return DEVICE_NONE; diff --git a/projects/cm_mcu/MonitorI2CTask.h b/projects/cm_mcu/MonitorI2CTask.h index a1ce7fd6..6645e1dd 100644 --- a/projects/cm_mcu/MonitorI2CTask.h +++ b/projects/cm_mcu/MonitorI2CTask.h @@ -24,9 +24,6 @@ struct sm_command_t { enum pm_type type; // how to decode command (L11 or bitfield or ...) }; -// how to find an I2C device, with a mux infront of it. - -typedef bool (*MonTaskFcnPointer)(struct MonitorI2CTaskArgs_t *); struct MonitorI2CTaskArgs_t { const char *name; // name to be assigned to the task @@ -42,7 +39,6 @@ struct MonitorI2CTaskArgs_t { TickType_t updateTick; // last update time, in ticks SemaphoreHandle_t xSem; // semaphore for controlling access to device UBaseType_t stack_size; // stack size of task - MonTaskFcnPointer presentCallback; // callback for present check }; #define FF_SELPAGE_REG 0x7f diff --git a/projects/cm_mcu/MonitorTaskI2C_new.c b/projects/cm_mcu/MonitorTaskI2C_new.c index 69c11c7b..861b7f8e 100644 --- a/projects/cm_mcu/MonitorTaskI2C_new.c +++ b/projects/cm_mcu/MonitorTaskI2C_new.c @@ -107,9 +107,6 @@ void MonitorI2CTask_new(void *parameters) good = true; } } - // what kind of device do we have (e.g., 4 ch FF, 12 ch 25 G FF, 12 ch CERN-B FF, etc.) - int devtype = args->typeCallback(device); - uint32_t dev_mask = 0x1U << device; // select the appropriate output for the mux uint8_t data; @@ -121,10 +118,15 @@ void MonitorI2CTask_new(void *parameters) break; } uint8_t last_page_reg_value = 0xff; - // Read I2C registers/commands + + // what kind of device is this + int devtype = args->typeCallback(device); + uint32_t devtype_mask = 0x1U << devtype; + // Loop to read I2C registers/commands for (int c = 0; c < args->n_commands; ++c) { // check if the command is for this device - if ((args->commands[c].devicelist() & dev_mask) == 0) { + // what kind of device do we have (e.g., 4 ch FF, 12 ch 25 G FF, 12 ch CERN-B FF, etc.) + if ((args->commands[c].devicelist() & devtype_mask) == 0) { continue; // not for me! } diff --git a/projects/cm_mcu/MonitorTaskI2C_new.h b/projects/cm_mcu/MonitorTaskI2C_new.h index f9f0f469..5c5461c7 100644 --- a/projects/cm_mcu/MonitorTaskI2C_new.h +++ b/projects/cm_mcu/MonitorTaskI2C_new.h @@ -1,19 +1,17 @@ /* * MonitorI2CTask_new.h * - * Created on: June 30, 2022 - * Author: pkotamnives */ -#ifndef PROJECTS_CM_MCU_MONITORI2CTASK_H_ -#define PROJECTS_CM_MCU_MONITORI2CTASK_H_ +#ifndef PROJECTS_CM_MCU_MONITORI2CTASKNEW_H_ +#define PROJECTS_CM_MCU_MONITORI2CTASKNEW_H_ #include "FreeRTOS.h" // IWYU pragma: keep #include "semphr.h" #include "Tasks.h" #include "FireflyUtils.h" -struct sm_command_t { +struct sm_command_new_t { int reg_size; // number of bytes of register/command unsigned char page; // I2C page address unsigned char command; // I2c register address @@ -115,4 +113,4 @@ extern struct dev_moni2c_addr_t ffl4_f2_moni2c_addrs[NFIREFLIES_DAQ_F2]; #define DEVICE_NONE 0x80 -#endif /* PROJECTS_CM_MCU_MONITORI2CTASK_H_ */ +#endif /* PROJECTS_CM_MCU_MONITORI2CTASKNEW_H_ */ diff --git a/projects/cm_mcu/cm_mcu.c b/projects/cm_mcu/cm_mcu.c index 5ca971e9..2e3a3849 100644 --- a/projects/cm_mcu/cm_mcu.c +++ b/projects/cm_mcu/cm_mcu.c @@ -28,6 +28,7 @@ #include "InterruptHandlers.h" #include "MonitorI2CTask.h" #include "MonitorTask.h" +#include "MonUtils.h" #include "Tasks.h" #include "AlarmUtilities.h" @@ -249,6 +250,8 @@ __attribute__((noreturn)) int main(void) ffl4_f1_args.xSem = i2c4_sem; ffl12_f2_args.xSem = i2c3_sem; ffl4_f2_args.xSem = i2c3_sem; + ff_f1_args.xSem = i2c4_sem; + ff_f2_args.xSem = i2c3_sem; #ifdef REV2 clock_args.xSem = i2c2_sem; clockr0a_args.xSem = i2c2_sem; @@ -299,7 +302,7 @@ __attribute__((noreturn)) int main(void) NULL); xTaskCreate(MonitorI2CTask, ffl4_f2_args.name, 2 * configMINIMAL_STACK_SIZE, &ffl4_f2_args, tskIDLE_PRIORITY + 4, NULL); - xTaskCreate(MonitorI2CTask_new, ffl4_f2_args.name, 2 * configMINIMAL_STACK_SIZE, &ffl4_f2_args, tskIDLE_PRIORITY + 4, + xTaskCreate(MonitorI2CTask_new, ff_f1_args.name, 2 * configMINIMAL_STACK_SIZE, &ff_f1_args, tskIDLE_PRIORITY + 4, NULL); #ifdef REV2 From 59cf55250cfceb65d0ca1429c33db4fdedf0e70d Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Mon, 20 May 2024 17:04:12 -0400 Subject: [PATCH 16/71] missing header --- projects/cm_mcu/MonUtils.h | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 projects/cm_mcu/MonUtils.h diff --git a/projects/cm_mcu/MonUtils.h b/projects/cm_mcu/MonUtils.h new file mode 100644 index 00000000..e768815d --- /dev/null +++ b/projects/cm_mcu/MonUtils.h @@ -0,0 +1,10 @@ +#ifndef MONUTILS_H +#define MONUTILS_H + +#include "MonitorTaskI2C_new.h" + +extern struct MonitorI2CTaskArgs_new_t ff_f1_args; +extern struct MonitorI2CTaskArgs_new_t ff_f2_args; + +#endif // MONUTILS_H + From 2ee56c83431cddfee56917f21e64eb1d0691ac6f Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Mon, 20 May 2024 17:14:54 -0400 Subject: [PATCH 17/71] fix rev1 build --- projects/cm_mcu/cm_mcu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/cm_mcu/cm_mcu.c b/projects/cm_mcu/cm_mcu.c index 2e3a3849..708dc8b2 100644 --- a/projects/cm_mcu/cm_mcu.c +++ b/projects/cm_mcu/cm_mcu.c @@ -250,9 +250,9 @@ __attribute__((noreturn)) int main(void) ffl4_f1_args.xSem = i2c4_sem; ffl12_f2_args.xSem = i2c3_sem; ffl4_f2_args.xSem = i2c3_sem; +#ifdef REV2 ff_f1_args.xSem = i2c4_sem; ff_f2_args.xSem = i2c3_sem; -#ifdef REV2 clock_args.xSem = i2c2_sem; clockr0a_args.xSem = i2c2_sem; #endif // REV2 @@ -302,10 +302,10 @@ __attribute__((noreturn)) int main(void) NULL); xTaskCreate(MonitorI2CTask, ffl4_f2_args.name, 2 * configMINIMAL_STACK_SIZE, &ffl4_f2_args, tskIDLE_PRIORITY + 4, NULL); +#ifdef REV2 xTaskCreate(MonitorI2CTask_new, ff_f1_args.name, 2 * configMINIMAL_STACK_SIZE, &ff_f1_args, tskIDLE_PRIORITY + 4, NULL); -#ifdef REV2 xTaskCreate(MonitorI2CTask, clock_args.name, 2 * configMINIMAL_STACK_SIZE, &clock_args, tskIDLE_PRIORITY + 4, NULL); xTaskCreate(MonitorI2CTask, clockr0a_args.name, 2 * configMINIMAL_STACK_SIZE, &clockr0a_args, tskIDLE_PRIORITY + 4, From 4c28a2731ae0e191c398cc363e6dcb9ea77f6330 Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Mon, 20 May 2024 17:15:12 -0400 Subject: [PATCH 18/71] formatting --- projects/cm_mcu/FireflyUtils.c | 8 ++++---- projects/cm_mcu/MonUtils.h | 1 - projects/cm_mcu/MonitorI2CTask.h | 7 +++---- projects/cm_mcu/clocksynth.c | 6 +++--- projects/cm_mcu/cm_mcu.c | 2 +- 5 files changed, 11 insertions(+), 13 deletions(-) diff --git a/projects/cm_mcu/FireflyUtils.c b/projects/cm_mcu/FireflyUtils.c index 3322b7aa..009c60b5 100644 --- a/projects/cm_mcu/FireflyUtils.c +++ b/projects/cm_mcu/FireflyUtils.c @@ -148,10 +148,10 @@ void readFFpresent(void) ((present_FFL12_BOTTOM_F1)); // 6 bits #elif defined(REV2) - present_FFL12_F1 = present_FFL12_F1 & 0x3FU; // bottom 6 bits - present_FFL12_F2 = present_FFL12_F2 & 0x3FU; // bottom 6 bits - present_FFL4_F1 = (present_FFL4_F1 >> 4) & 0xFU; // bits 4-7 - present_FFL4_F2 = (present_FFL4_F2 >> 4) & 0xFU; // bits 4-7 + present_FFL12_F1 = present_FFL12_F1 & 0x3FU; // bottom 6 bits + present_FFL12_F2 = present_FFL12_F2 & 0x3FU; // bottom 6 bits + present_FFL4_F1 = (present_FFL4_F1 >> 4) & 0xFU; // bits 4-7 + present_FFL4_F2 = (present_FFL4_F2 >> 4) & 0xFU; // bits 4-7 uint32_t ff_combined_present = ((present_FFL4_F2) << 16) | // 4 bits ((present_FFL12_F2) << 10) | // 6 bits diff --git a/projects/cm_mcu/MonUtils.h b/projects/cm_mcu/MonUtils.h index e768815d..587ee6d9 100644 --- a/projects/cm_mcu/MonUtils.h +++ b/projects/cm_mcu/MonUtils.h @@ -7,4 +7,3 @@ extern struct MonitorI2CTaskArgs_new_t ff_f1_args; extern struct MonitorI2CTaskArgs_new_t ff_f2_args; #endif // MONUTILS_H - diff --git a/projects/cm_mcu/MonitorI2CTask.h b/projects/cm_mcu/MonitorI2CTask.h index 6645e1dd..2b13e6a8 100644 --- a/projects/cm_mcu/MonitorI2CTask.h +++ b/projects/cm_mcu/MonitorI2CTask.h @@ -24,7 +24,6 @@ struct sm_command_t { enum pm_type type; // how to decode command (L11 or bitfield or ...) }; - struct MonitorI2CTaskArgs_t { const char *name; // name to be assigned to the task struct dev_moni2c_addr_t *devices; // list of devices to query @@ -36,9 +35,9 @@ struct MonitorI2CTaskArgs_t { const uint8_t n_pages; // number of pages to loop over const uint16_t selpage_reg; // register for selecting page uint16_t *sm_values; - TickType_t updateTick; // last update time, in ticks - SemaphoreHandle_t xSem; // semaphore for controlling access to device - UBaseType_t stack_size; // stack size of task + TickType_t updateTick; // last update time, in ticks + SemaphoreHandle_t xSem; // semaphore for controlling access to device + UBaseType_t stack_size; // stack size of task }; #define FF_SELPAGE_REG 0x7f diff --git a/projects/cm_mcu/clocksynth.c b/projects/cm_mcu/clocksynth.c index ef8f6735..86631bd7 100644 --- a/projects/cm_mcu/clocksynth.c +++ b/projects/cm_mcu/clocksynth.c @@ -104,7 +104,7 @@ void getClockProgram(int device, char progname_clkdesgid[CLOCK_PROGNAME_REG_NAME CLOCK_CHANGEPAGE_REG_ADDR, 1, page); // now read out the six bytes of data in two reads - const uint8_t reg = (CLOCK_PROGNAME_REG_ADDR_START)&0xFF; + const uint8_t reg = (CLOCK_PROGNAME_REG_ADDR_START) & 0xFF; uint16_t init_postamble_page = 32 * (device + 1) - 1; // read the addresses in EEPROM that store the number of registers in Preamble-register, Register, and Postamble-register list per a clock config file @@ -131,10 +131,10 @@ void getClockProgram(int device, char progname_clkdesgid[CLOCK_PROGNAME_REG_NAME // as eepromdata[0] and eepromdat[1],respectively // third byte from three addresses in EEPROM is a value byte - apollo_i2c_ctl_reg_r(CLOCK_I2C_DEV, CLOCK_I2C_EEPROM_ADDR, 2, eeprom_progname_reg + ((i)*3), 3, tempdata); + apollo_i2c_ctl_reg_r(CLOCK_I2C_DEV, CLOCK_I2C_EEPROM_ADDR, 2, eeprom_progname_reg + ((i) * 3), 3, tempdata); eepromdata[0] |= ((tempdata[0] >> (16)) & 0xFF) << (i * 8); // third byte from three addresses in EEPROM is a value byte - apollo_i2c_ctl_reg_r(CLOCK_I2C_DEV, CLOCK_I2C_EEPROM_ADDR, 2, eeprom_progname_reg + 12 + ((i)*3), 3, tempdata); + apollo_i2c_ctl_reg_r(CLOCK_I2C_DEV, CLOCK_I2C_EEPROM_ADDR, 2, eeprom_progname_reg + 12 + ((i) * 3), 3, tempdata); eepromdata[1] |= ((tempdata[0] >> (16)) & 0xFF) << (i * 8); } } diff --git a/projects/cm_mcu/cm_mcu.c b/projects/cm_mcu/cm_mcu.c index 708dc8b2..3974f997 100644 --- a/projects/cm_mcu/cm_mcu.c +++ b/projects/cm_mcu/cm_mcu.c @@ -137,7 +137,7 @@ void SystemInitInterrupts(void) #if defined(REV1) initI2C6(g_ui32SysClock); // controller for FPGAs #elif defined(REV2) - initI2C5(g_ui32SysClock); // controller for FPGAs + initI2C5(g_ui32SysClock); // controller for FPGAs #endif // smbus From c4e760e5876aa6b7ad7ff58d8be2f27d80b12b82 Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Mon, 20 May 2024 22:27:46 -0400 Subject: [PATCH 19/71] add F2 task --- projects/cm_mcu/cm_mcu.c | 2 ++ projects/cm_mcu/commands/SensorControl.c | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/projects/cm_mcu/cm_mcu.c b/projects/cm_mcu/cm_mcu.c index 3974f997..b7d371d0 100644 --- a/projects/cm_mcu/cm_mcu.c +++ b/projects/cm_mcu/cm_mcu.c @@ -305,6 +305,8 @@ __attribute__((noreturn)) int main(void) #ifdef REV2 xTaskCreate(MonitorI2CTask_new, ff_f1_args.name, 2 * configMINIMAL_STACK_SIZE, &ff_f1_args, tskIDLE_PRIORITY + 4, NULL); + xTaskCreate(MonitorI2CTask_new, ff_f2_args.name, 2 * configMINIMAL_STACK_SIZE, &ff_f1_args, tskIDLE_PRIORITY + 4, + NULL); xTaskCreate(MonitorI2CTask, clock_args.name, 2 * configMINIMAL_STACK_SIZE, &clock_args, tskIDLE_PRIORITY + 4, NULL); diff --git a/projects/cm_mcu/commands/SensorControl.c b/projects/cm_mcu/commands/SensorControl.c index ee6f8f43..d587780e 100644 --- a/projects/cm_mcu/commands/SensorControl.c +++ b/projects/cm_mcu/commands/SensorControl.c @@ -7,7 +7,9 @@ #include #include +#include "FireflyUtils.h" #include "I2CCommunication.h" +#include "MonI2C_addresses.h" #include "common/utils.h" #include "parameters.h" #include "SensorControl.h" @@ -891,6 +893,20 @@ BaseType_t ff_temp(int argc, char **argv, char *m) copied += snprintf(m + copied, SCRATCH_SIZE - copied, "\t"); else copied += snprintf(m + copied, SCRATCH_SIZE - copied, "\r\n"); + if ((SCRATCH_SIZE - copied) < 20) { + ++whichff; + copied = 0; + return pdTRUE; + } + } + n = 0; + for ( ; n < NFIREFLIES; ++n ) { + if (isEnabledFF(n)) { + uint8_t val = get_FF_TEMPERATURE_data(n); + copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%17s: %2d", ff_moni2c_addrs[whichff].name, val); + } + else // dummy value + copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%17s: %2s", ff_moni2c_addrs[whichff].name, "--"); if ((SCRATCH_SIZE - copied) < 20) { ++whichff; return pdTRUE; From e7cf33c65ff50e6551be830985a2afd56db38216 Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Wed, 22 May 2024 12:47:35 -0400 Subject: [PATCH 20/71] WIP --- projects/cm_mcu/LocalTasks.c | 22 +++----- projects/cm_mcu/MonUtils.c | 1 + projects/cm_mcu/MonitorI2CTask.h | 4 +- projects/cm_mcu/MonitorTaskI2C_new.h | 58 ------------------- sm_cm_config/data/MON_I2C_rev2.yml | 83 +++++++++++++++++++++++++--- sm_cm_config/src/mon_generate.py | 16 ++++-- 6 files changed, 96 insertions(+), 88 deletions(-) diff --git a/projects/cm_mcu/LocalTasks.c b/projects/cm_mcu/LocalTasks.c index 507c3c07..289b8edc 100644 --- a/projects/cm_mcu/LocalTasks.c +++ b/projects/cm_mcu/LocalTasks.c @@ -29,8 +29,8 @@ #include "I2CCommunication.h" #include "common/log.h" -// local prototype -void Print(const char *str); +#define NCOMMANDS_CLK_TMP 7 +#define NCOMMANDS_CLK_TMPR0A 7 #ifdef REV1 // ------------------------------------------------- @@ -434,7 +434,7 @@ struct dev_moni2c_addr_t clk_moni2c_addrs[CLOCK_NUM_SI5395] = { {"r1c", 0x70, 4, 0x6b, 0x864E}, // CLK R1C : Si5395-REVA #regs = 587 (read at 0x9F7D in EEPROM) if change, addr 0x864E will have to change }; -struct sm_command_t sm_command_clk[] = { +struct sm_command_t sm_command_clk[NCOMMANDS_CLK_TMP] = { // device information on page 0 : table 16.2 and 16.4 {1, 0x00, 0x02, 2, "PN_BASE", 0xffff, "", PM_STATUS}, // page 0x00 {1, 0x00, 0x05, 1, "DEVICE_REV", 0xff, "", PM_STATUS}, // page 0x00 @@ -447,7 +447,7 @@ struct sm_command_t sm_command_clk[] = { {1, 0x00, 0x11, 1, "STICKY_FLG", 0x27, "", PM_STATUS}, // page 0x00 }; -uint16_t clk_values[NDEVICES_CLK * NPAGES_CLK * NCOMMANDS_CLK]; +uint16_t clk_values[NDEVICES_CLK * NPAGES_CLK * NCOMMANDS_CLK_TMP]; struct MonitorI2CTaskArgs_t clock_args = { .name = "CLKSI", @@ -455,13 +455,11 @@ struct MonitorI2CTaskArgs_t clock_args = { .i2c_dev = I2C_DEVICE_CLK, .n_devices = NDEVICES_CLK, .commands = sm_command_clk, - .n_commands = NCOMMANDS_CLK, - .n_values = NDEVICES_CLK * NPAGES_CLK * NCOMMANDS_CLK, + .n_commands = NCOMMANDS_CLK_TMP, + .n_values = NDEVICES_CLK * NPAGES_CLK * NCOMMANDS_CLK_TMP, .n_pages = NPAGES_CLK, .selpage_reg = CLK_SELPAGE_REG, .sm_values = clk_values, - // .smbus = &g_sMaster2, - // .smbus_status = &eStatus2, .xSem = NULL, .stack_size = 4096U, }; @@ -484,7 +482,7 @@ struct sm_command_t sm_command_clkr0a[] = { {1, 0x00, 0x11, 1, "STICKY_FLG", 0x2f, "", PM_STATUS}, // page 0x00 }; -uint16_t clkr0a_values[NDEVICES_CLKR0A * NPAGES_CLKR0A * NCOMMANDS_CLKR0A]; +uint16_t clkr0a_values[NDEVICES_CLKR0A * NPAGES_CLKR0A * NCOMMANDS_CLK_TMPR0A]; struct MonitorI2CTaskArgs_t clockr0a_args = { .name = "CLKR0A", @@ -492,13 +490,11 @@ struct MonitorI2CTaskArgs_t clockr0a_args = { .i2c_dev = I2C_DEVICE_CLK, .n_devices = NDEVICES_CLKR0A, .commands = sm_command_clkr0a, - .n_commands = NCOMMANDS_CLKR0A, - .n_values = NDEVICES_CLKR0A * NPAGES_CLKR0A * NCOMMANDS_CLKR0A, + .n_commands = NCOMMANDS_CLK_TMPR0A, + .n_values = NDEVICES_CLKR0A * NPAGES_CLKR0A * NCOMMANDS_CLK_TMPR0A, .n_pages = NPAGES_CLKR0A, .selpage_reg = CLK_SELPAGE_REG, .sm_values = clkr0a_values, - // .smbus = &g_sMaster2, - // .smbus_status = &eStatus2, .xSem = NULL, .stack_size = 4096U, }; diff --git a/projects/cm_mcu/MonUtils.c b/projects/cm_mcu/MonUtils.c index c497d6da..7d32d589 100644 --- a/projects/cm_mcu/MonUtils.c +++ b/projects/cm_mcu/MonUtils.c @@ -1,3 +1,4 @@ +#include "MonitorI2CTask.h" #include "MonitorTaskI2C_new.h" #include "MonI2C_addresses.h" #include "FireflyUtils.h" diff --git a/projects/cm_mcu/MonitorI2CTask.h b/projects/cm_mcu/MonitorI2CTask.h index 2b13e6a8..6af88c27 100644 --- a/projects/cm_mcu/MonitorI2CTask.h +++ b/projects/cm_mcu/MonitorI2CTask.h @@ -85,11 +85,11 @@ extern struct MonitorI2CTaskArgs_t ffl12_f2_args; extern struct MonitorI2CTaskArgs_t ffl4_f2_args; #define NDEVICES_CLK (4) -#define NCOMMANDS_CLK 7 // number of commands +//#define NCOMMANDS_CLK 7 // number of commands #define NCOMMANDS_FLG_CLK 1 // number of sticky commands #define NPAGES_CLK 1 // #define NDEVICES_CLKR0A (1) -#define NCOMMANDS_CLKR0A 7 // number of commands +//#define NCOMMANDS_CLKR0A 7 // number of commands #define NCOMMANDS_FLG_CLKR0A 2 // number of sticky commands #define NPAGES_CLKR0A 1 // diff --git a/projects/cm_mcu/MonitorTaskI2C_new.h b/projects/cm_mcu/MonitorTaskI2C_new.h index 5c5461c7..beac301b 100644 --- a/projects/cm_mcu/MonitorTaskI2C_new.h +++ b/projects/cm_mcu/MonitorTaskI2C_new.h @@ -9,18 +9,7 @@ #include "FreeRTOS.h" // IWYU pragma: keep #include "semphr.h" #include "Tasks.h" -#include "FireflyUtils.h" -struct sm_command_new_t { - int reg_size; // number of bytes of register/command - unsigned char page; // I2C page address - unsigned char command; // I2c register address - int size; // number of bytes to read - char *name; // text describing command - uint16_t bit_mask; // begin bit mask - char *units; // units for pretty printing - enum pm_type type; // how to decode command (L11 or bitfield or ...) -}; struct i2c_reg_command_t { int reg_size; // number of bytes of register/command @@ -55,53 +44,6 @@ struct MonitorI2CTaskArgs_new_t { MonTaskI2CTypeFcnPointer typeCallback; // callback for type check }; -#define FF_SELPAGE_REG 0x7f -#define CLK_SELPAGE_REG 0x1 - -#ifndef REV2 -#define NDEVICES_FFL4_F1 (3) -#else // REV2 -#define NDEVICES_FFL4_F1 (4) -#endif // REV 2 -#define NCOMMANDS_FFL4_F1 8 // number of commands -#define NPAGES_FFL4_F1 1 // number of pages on the 4-channel firefly ports - -#ifndef REV2 -#define NDEVICES_FFL12_F1 (8) -#else // REV1 -#define NDEVICES_FFL12_F1 (6) -#endif // REV 2 -#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 NDEVICES_FFL4_F2 (10) -#else // REV1 -#define NDEVICES_FFL4_F2 (4) -#endif // REV 2 -#define NCOMMANDS_FFL4_F2 8 // number of commands -#define NPAGES_FFL4_F2 1 // number of pages on the 4-channel firefly ports - -#ifndef REV2 -#define NDEVICES_FFL12_F2 (4) -#else // REV1 -#define NDEVICES_FFL12_F2 (6) -#endif // REV 2 -#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]; -extern struct dev_moni2c_addr_t ffl4_f1_moni2c_addrs[NFIREFLIES_DAQ_F1]; -extern struct dev_moni2c_addr_t ffl12_f2_moni2c_addrs[NFIREFLIES_IT_F2]; -extern struct dev_moni2c_addr_t ffl4_f2_moni2c_addrs[NFIREFLIES_DAQ_F2]; - -#define NDEVICES_CLK (4) -#define NCOMMANDS_FLG_CLK 1 // number of sticky commands -#define NPAGES_CLK 1 // -#define NDEVICES_CLKR0A (1) -#define NCOMMANDS_CLKR0A 7 // number of commands -#define NCOMMANDS_FLG_CLKR0A 2 // number of sticky commands -#define NPAGES_CLKR0A 1 // // for autogenerated code #define DEVICE_CERNB 0x01 diff --git a/sm_cm_config/data/MON_I2C_rev2.yml b/sm_cm_config/data/MON_I2C_rev2.yml index a95e77da..4ba2f9f5 100644 --- a/sm_cm_config/data/MON_I2C_rev2.yml +++ b/sm_cm_config/data/MON_I2C_rev2.yml @@ -7,6 +7,7 @@ metadata: devices: - name: Fireflies ndevices: NFIREFLIES + ndevice_types: 4 prefix: FF config: # - name: "bob" # register name @@ -26,7 +27,7 @@ devices: mask: 0xFF units: "" type: PM_STATUS - devices: [CERNB, 14G, 25G4, 25G12] + devicetypes: [CERNB, 14G, 25G4, 25G12] - name: FF_TEMPERATURE reg_size: 1 page: 0 @@ -35,7 +36,7 @@ devices: mask: 0xFF units: C type: PM_NONVOLTAGE - devices: [14G, 25G12, 25G4, CERNB] + devicetypes: [14G, 25G12, 25G4, CERNB] - name: FF_LOS_ALARM reg_size: 1 page: 0 @@ -44,7 +45,7 @@ devices: mask: 0xFFFF units: "" type: PM_STATUS - devices: [25G12, 25G4] + devicetypes: [25G12, 25G4] - name: FF_OPT_POWER_CH1 reg_size: 1 page: 0 @@ -53,9 +54,46 @@ devices: mask: 0xFFFF units: uW type: PM_VOLTAGE - devices: [25G4, 25G12] + devicetypes: [25G4, 25G12] + - name: FF_OPT_POWER_CH2 + reg_size: 1 + page: 0 + reg_address: [-1, -1, 0x24, 0xe2] + size: 2 + mask: 0xFFFF + units: uW + type: PM_VOLTAGE + devicetypes: [25G4, 25G12] + - name: FF_OPT_POWER_CH3 + reg_size: 1 + page: 0 + reg_address: [-1, -1, 0x26, 0xe0] + size: 2 + mask: 0xFFFF + units: uW + type: PM_VOLTAGE + devicetypes: [25G4, 25G12] + - name: FF_OPT_POWER_CH4 + reg_size: 1 + page: 0 + reg_address: [-1, -1, 0x28, 0xde] + size: 2 + mask: 0xFFFF + units: uW + type: PM_VOLTAGE + devicetypes: [25G4, 25G12] + - name: FF_OPT_POWER_CH5 + reg_size: 1 + page: 0 + reg_address: [-1, -1, -1, 0xdc] + size: 2 + mask: 0xFFFF + units: uW + type: PM_VOLTAGE + devicetypes: [25G12] - name: Clocks ndevices: NDEVICES_CLK + ndevice_types: 2 prefix: CLK config: - name: CLK_PN_BASE @@ -66,7 +104,7 @@ devices: mask: 0xFFFF units: "" type: PM_STATUS - devices: [SI5395, SI5341] + devicetypes: [SI5395, SI5341] - name: CLK_DEVICE_REV reg_size: 1 page: 0 @@ -75,7 +113,7 @@ devices: mask: 0xFF units: "" type: PM_STATUS - devices: [SI5395, SI5341] + devicetypes: [SI5395, SI5341] - name: CLK_I2C_ADDR reg_size: 1 page: 0 @@ -84,7 +122,7 @@ devices: mask: 0xFF units: "" type: PM_STATUS - devices: [SI5395, SI5341] + devicetypes: [SI5395, SI5341] - name: CLK_STATUS reg_size: 1 page: 0 @@ -93,7 +131,7 @@ devices: mask: 0xFF units: "" type: PM_STATUS - devices: [SI5341] + devicetypes: [SI5341] - name: CLK_LOL reg_size: 1 page: 0 @@ -102,4 +140,31 @@ devices: mask: 0x02 units: "" type: PM_STATUS - devices: [SI5395] + devicetypes: [SI5395] + - name: CLK_LOSXAXB + reg_size: 1 + page: 0 + reg_address: 0xB + size: 1 + mask: 0x02 + units: "" + type: PM_STATUS + devicetypes: [SI5395] + - name: CLK_LOSOOF_IN + reg_size: 1 + page: 0 + reg_address: 0xD + size: 1 + mask: 0x0ff + units: "" + type: PM_STATUS + devicetypes: [SI5395] + - name: CLK_STICKY_FLG + reg_size: 1 + page: 0 + reg_address: 0x11 + size: 1 + mask: 0x02f + units: "" + type: PM_STATUS + devicetypes: [SI5395, SI5341] diff --git a/sm_cm_config/src/mon_generate.py b/sm_cm_config/src/mon_generate.py index 8dc028e8..9cdb5087 100755 --- a/sm_cm_config/src/mon_generate.py +++ b/sm_cm_config/src/mon_generate.py @@ -80,7 +80,8 @@ def write_boilderplate(fout: io.TextIOWrapper): print(r"#define MON_I2C_ADDRESSES_H", file=fout_header) print("#include ", file=fout_header) print("#include \"MonitorTaskI2C_new.h\"", file=fout_header) - #print("#include \"MonI2C_addresses.h\"", file=fout_header) + print("#include \"FireflyUtils.h\"", file=fout_source) + print("#include \"MonitorI2CTask.h\"", file=fout_source) with open(args.input_files[0], encoding="ascii") as f: @@ -90,6 +91,7 @@ def write_boilderplate(fout: io.TextIOWrapper): data = yaml.load(f, Loader=yaml.FullLoader) for d in data['devices']: ndev = d['ndevices'] + ndev_types = d['ndevice_types'] prefix = d['prefix'] config = d['config'] ncommands = len(config) @@ -98,14 +100,16 @@ def write_boilderplate(fout: io.TextIOWrapper): print(f"#define {prefix}_NOT_COVERED (-1)", file=fout_source) print(f"struct i2c_reg_command_t sm_command_test_{prefix}[NCOMMANDS_{prefix}] = {{", file=fout_source) - print(f"extern struct i2c_reg_command_t sm_command_test_{prefix}[];", file=fout_header) + print(f"extern struct i2c_reg_command_t sm_command_test_{prefix}[NCOMMANDS_{prefix}];", + file=fout_header) for c in config: reg_list = c['reg_address'] #print(f"reg list is >{reg_list}<") - # if reg_list is an integer, convert it to a list of 4 integers - # this handles the case where all 4 types share the same address + # if reg_list is an integer, convert it to a list of ndev_types integers + # this handles the case where all ndev types share the same address if isinstance(reg_list, int): - reg_list = [reg_list, reg_list, reg_list, reg_list] + reg_list = [reg_list]*int(ndev_types) + #print(f"reg list is >{reg_list}<") reg_list_str = '{' for r in reg_list: if r > 0: @@ -141,7 +145,7 @@ def write_boilderplate(fout: io.TextIOWrapper): print(f"uint16_t get_{c['name']}_mask(void);", file=fout_header) print(f"uint16_t get_{c['name']}_mask(void) {{", file=fout_source) print(r" return ", end="", file=fout_source) - for d in c['devices']: + for d in c['devicetypes']: print(f"DEVICE_{d} | ", end="", file=fout_source) print(r"0;", file=fout_source) print(r"}", file=fout_source) From dc67bb20b2bcc9e043af510652e0c690f942772f Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Wed, 22 May 2024 12:56:12 -0400 Subject: [PATCH 21/71] clang-format --- projects/cm_mcu/LocalTasks.c | 2 +- projects/cm_mcu/MonitorI2CTask.h | 12 ++++++------ projects/cm_mcu/MonitorTaskI2C_new.h | 2 -- projects/cm_mcu/commands/SensorControl.c | 2 +- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/projects/cm_mcu/LocalTasks.c b/projects/cm_mcu/LocalTasks.c index 289b8edc..b10b6e90 100644 --- a/projects/cm_mcu/LocalTasks.c +++ b/projects/cm_mcu/LocalTasks.c @@ -29,7 +29,7 @@ #include "I2CCommunication.h" #include "common/log.h" -#define NCOMMANDS_CLK_TMP 7 +#define NCOMMANDS_CLK_TMP 7 #define NCOMMANDS_CLK_TMPR0A 7 #ifdef REV1 diff --git a/projects/cm_mcu/MonitorI2CTask.h b/projects/cm_mcu/MonitorI2CTask.h index 6af88c27..59fee628 100644 --- a/projects/cm_mcu/MonitorI2CTask.h +++ b/projects/cm_mcu/MonitorI2CTask.h @@ -84,12 +84,12 @@ extern struct MonitorI2CTaskArgs_t ffl4_f1_args; extern struct MonitorI2CTaskArgs_t ffl12_f2_args; extern struct MonitorI2CTaskArgs_t ffl4_f2_args; -#define NDEVICES_CLK (4) -//#define NCOMMANDS_CLK 7 // number of commands -#define NCOMMANDS_FLG_CLK 1 // number of sticky commands -#define NPAGES_CLK 1 // -#define NDEVICES_CLKR0A (1) -//#define NCOMMANDS_CLKR0A 7 // number of commands +#define NDEVICES_CLK (4) +// #define NCOMMANDS_CLK 7 // number of commands +#define NCOMMANDS_FLG_CLK 1 // number of sticky commands +#define NPAGES_CLK 1 // +#define NDEVICES_CLKR0A (1) +// #define NCOMMANDS_CLKR0A 7 // number of commands #define NCOMMANDS_FLG_CLKR0A 2 // number of sticky commands #define NPAGES_CLKR0A 1 // diff --git a/projects/cm_mcu/MonitorTaskI2C_new.h b/projects/cm_mcu/MonitorTaskI2C_new.h index beac301b..bd1bf697 100644 --- a/projects/cm_mcu/MonitorTaskI2C_new.h +++ b/projects/cm_mcu/MonitorTaskI2C_new.h @@ -10,7 +10,6 @@ #include "semphr.h" #include "Tasks.h" - struct i2c_reg_command_t { int reg_size; // number of bytes of register/command unsigned char page; // I2C page address @@ -44,7 +43,6 @@ struct MonitorI2CTaskArgs_new_t { MonTaskI2CTypeFcnPointer typeCallback; // callback for type check }; - // for autogenerated code #define DEVICE_CERNB 0x01 #define DEVICE_14G 0x02 diff --git a/projects/cm_mcu/commands/SensorControl.c b/projects/cm_mcu/commands/SensorControl.c index d587780e..9c933c49 100644 --- a/projects/cm_mcu/commands/SensorControl.c +++ b/projects/cm_mcu/commands/SensorControl.c @@ -900,7 +900,7 @@ BaseType_t ff_temp(int argc, char **argv, char *m) } } n = 0; - for ( ; n < NFIREFLIES; ++n ) { + for (; n < NFIREFLIES; ++n) { if (isEnabledFF(n)) { uint8_t val = get_FF_TEMPERATURE_data(n); copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%17s: %2d", ff_moni2c_addrs[whichff].name, val); From 1939c57176d718d6e2caa70e87ded2cf3b564065 Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Thu, 23 May 2024 09:53:41 -0400 Subject: [PATCH 22/71] work in progress --- projects/cm_mcu/MonUtils.c | 9 +++++++- projects/cm_mcu/MonitorTaskI2C_new.c | 5 ++-- projects/cm_mcu/cm_mcu.c | 21 +++++++++-------- projects/cm_mcu/commands/SensorControl.c | 29 ++++++++++++++++-------- 4 files changed, 41 insertions(+), 23 deletions(-) diff --git a/projects/cm_mcu/MonUtils.c b/projects/cm_mcu/MonUtils.c index 7d32d589..8e072f24 100644 --- a/projects/cm_mcu/MonUtils.c +++ b/projects/cm_mcu/MonUtils.c @@ -8,6 +8,7 @@ // for 4 channel parts, there is one XCVR part int FireflyType(int device) { + device = device %NFIREFLIES_F1; // F1 and F2 devices are the same. switch (device) { case 0: case 1: @@ -46,6 +47,12 @@ int ClockType(int device) } } +bool isEnabledFF_F2(int device) +{ + // firefly devices on F2 are devices 10-19 + return isEnabledFF(device+NFIREFLIES_F1); +} + struct MonitorI2CTaskArgs_new_t ff_f1_args = { .name = "FF_F1", .devices = ff_moni2c_addrs_f1, @@ -71,7 +78,7 @@ struct MonitorI2CTaskArgs_new_t ff_f2_args = { .xSem = NULL, .stack_size = 4096U, .typeCallback = FireflyType, - .presentCallback = isEnabledFF, + .presentCallback = isEnabledFF_F2, }; #endif // REV2 diff --git a/projects/cm_mcu/MonitorTaskI2C_new.c b/projects/cm_mcu/MonitorTaskI2C_new.c index 861b7f8e..8a352b31 100644 --- a/projects/cm_mcu/MonitorTaskI2C_new.c +++ b/projects/cm_mcu/MonitorTaskI2C_new.c @@ -120,8 +120,9 @@ void MonitorI2CTask_new(void *parameters) uint8_t last_page_reg_value = 0xff; // what kind of device is this - int devtype = args->typeCallback(device); - uint32_t devtype_mask = 0x1U << devtype; + uint32_t devtype_mask = args->typeCallback(device); + uint32_t clz = __builtin_clz(devtype_mask); + uint32_t devtype = 32 - __builtin_clz( devtype_mask); // highest bit set FIXME: this is backwards // Loop to read I2C registers/commands for (int c = 0; c < args->n_commands; ++c) { // check if the command is for this device diff --git a/projects/cm_mcu/cm_mcu.c b/projects/cm_mcu/cm_mcu.c index b7d371d0..3a3f5fee 100644 --- a/projects/cm_mcu/cm_mcu.c +++ b/projects/cm_mcu/cm_mcu.c @@ -294,19 +294,20 @@ __attribute__((noreturn)) int main(void) #endif // REV1 xTaskCreate(ADCMonitorTask, "ADC", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 4, NULL); - xTaskCreate(MonitorI2CTask, ffl12_f1_args.name, 2 * configMINIMAL_STACK_SIZE, &ffl12_f1_args, tskIDLE_PRIORITY + 4, - NULL); - xTaskCreate(MonitorI2CTask, ffl4_f1_args.name, 2 * configMINIMAL_STACK_SIZE, &ffl4_f1_args, tskIDLE_PRIORITY + 4, - NULL); - xTaskCreate(MonitorI2CTask, ffl12_f2_args.name, 2 * configMINIMAL_STACK_SIZE, &ffl12_f2_args, tskIDLE_PRIORITY + 4, - NULL); - xTaskCreate(MonitorI2CTask, ffl4_f2_args.name, 2 * configMINIMAL_STACK_SIZE, &ffl4_f2_args, tskIDLE_PRIORITY + 4, - NULL); +// xTaskCreate(MonitorI2CTask, ffl12_f1_args.name, 2 * configMINIMAL_STACK_SIZE, &ffl12_f1_args, tskIDLE_PRIORITY + 4, +// NULL); +// xTaskCreate(MonitorI2CTask, ffl4_f1_args.name, 2 * configMINIMAL_STACK_SIZE, &ffl4_f1_args, tskIDLE_PRIORITY + 4, +// NULL); +// xTaskCreate(MonitorI2CTask, ffl12_f2_args.name, 2 * configMINIMAL_STACK_SIZE, &ffl12_f2_args, tskIDLE_PRIORITY + 4, +// NULL); +// xTaskCreate(MonitorI2CTask, ffl4_f2_args.name, 2 * configMINIMAL_STACK_SIZE, &ffl4_f2_args, tskIDLE_PRIORITY + 4, +// NULL); #ifdef REV2 xTaskCreate(MonitorI2CTask_new, ff_f1_args.name, 2 * configMINIMAL_STACK_SIZE, &ff_f1_args, tskIDLE_PRIORITY + 4, NULL); - xTaskCreate(MonitorI2CTask_new, ff_f2_args.name, 2 * configMINIMAL_STACK_SIZE, &ff_f1_args, tskIDLE_PRIORITY + 4, - NULL); + // these get stored to the wrong location +// xTaskCreate(MonitorI2CTask_new, ff_f2_args.name, 2 * configMINIMAL_STACK_SIZE, &ff_f2_args, tskIDLE_PRIORITY + 4, +// NULL); xTaskCreate(MonitorI2CTask, clock_args.name, 2 * configMINIMAL_STACK_SIZE, &clock_args, tskIDLE_PRIORITY + 4, NULL); diff --git a/projects/cm_mcu/commands/SensorControl.c b/projects/cm_mcu/commands/SensorControl.c index 9c933c49..d561d93b 100644 --- a/projects/cm_mcu/commands/SensorControl.c +++ b/projects/cm_mcu/commands/SensorControl.c @@ -859,9 +859,9 @@ BaseType_t ff_temp(int argc, char **argv, char *m) int copied = 0; static int whichff = 0; - static int n = 0; + static int nn=0, n = 0; - if (whichff == 0) { + if (nn == 0) { // check for stale data TickType_t now = pdTICKS_TO_S(xTaskGetTickCount()); @@ -874,6 +874,7 @@ BaseType_t ff_temp(int argc, char **argv, char *m) copied += snprintf(m + copied, SCRATCH_SIZE - copied, "FF Temperature:\r\n"); } +#if 0 int i1 = 1; // 1 for temperature for (; n < NFIREFLY_ARG; ++n) { @@ -899,22 +900,30 @@ BaseType_t ff_temp(int argc, char **argv, char *m) return pdTRUE; } } - n = 0; - for (; n < NFIREFLIES; ++n) { - if (isEnabledFF(n)) { - uint8_t val = get_FF_TEMPERATURE_data(n); - copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%17s: %2d", ff_moni2c_addrs[whichff].name, val); + copied += snprintf(m+copied, SCRATCH_SIZE - copied, "-------\r\n"); +#endif + //static int nn = 0; + for (; nn < NFIREFLIES; ++nn) { + if (isEnabledFF(nn)) { + uint8_t val = get_FF_TEMPERATURE_data(nn); + copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%17s: %2d", ff_moni2c_addrs[nn].name, val); } else // dummy value - copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%17s: %2s", ff_moni2c_addrs[whichff].name, "--"); + copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%17s: %2s", ff_moni2c_addrs[nn].name, "--"); if ((SCRATCH_SIZE - copied) < 20) { ++whichff; return pdTRUE; } + bool isTx = (strstr(ff_moni2c_addrs[nn].name, "Tx") != NULL); + if (isTx) + copied += snprintf(m + copied, SCRATCH_SIZE - copied, "\t"); + else + copied += snprintf(m + copied, SCRATCH_SIZE - copied, "\r\n"); } - } + nn = 0; + //} - if (whichff % 2 == 1) { + if (nn % 2 == 1) { m[copied++] = '\r'; m[copied++] = '\n'; m[copied] = '\0'; From 80d34bb3581784769068ab92ca45f778178950a4 Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Thu, 23 May 2024 12:08:21 -0400 Subject: [PATCH 23/71] adapt to two sets of data arrays --- projects/cm_mcu/MonUtils.c | 8 +- projects/cm_mcu/MonitorTaskI2C_new.c | 1 - sm_cm_config/data/MON_I2C_rev2.yml | 185 ++++++++++++++------------- sm_cm_config/src/mon_generate.py | 61 ++++++--- 4 files changed, 143 insertions(+), 112 deletions(-) diff --git a/projects/cm_mcu/MonUtils.c b/projects/cm_mcu/MonUtils.c index 8e072f24..f697ed6e 100644 --- a/projects/cm_mcu/MonUtils.c +++ b/projects/cm_mcu/MonUtils.c @@ -58,8 +58,8 @@ struct MonitorI2CTaskArgs_new_t ff_f1_args = { .devices = ff_moni2c_addrs_f1, .i2c_dev = I2C_DEVICE_F1, .n_devices = NFIREFLIES_F1, - .commands = sm_command_test_FF, - .n_commands = NCOMMANDS_FF, + .commands = sm_command_test_FF_F1, + .n_commands = NCOMMANDS_FF_F1, .selpage_reg = FF_SELPAGE_REG, .xSem = NULL, .stack_size = 4096U, @@ -72,8 +72,8 @@ struct MonitorI2CTaskArgs_new_t ff_f2_args = { .devices = ff_moni2c_addrs_f2, .i2c_dev = I2C_DEVICE_F2, .n_devices = NFIREFLIES_F2, - .commands = sm_command_test_FF, - .n_commands = NCOMMANDS_FF, + .commands = sm_command_test_FF_F2, + .n_commands = NCOMMANDS_FF_F2, .selpage_reg = FF_SELPAGE_REG, .xSem = NULL, .stack_size = 4096U, diff --git a/projects/cm_mcu/MonitorTaskI2C_new.c b/projects/cm_mcu/MonitorTaskI2C_new.c index 8a352b31..26630cc4 100644 --- a/projects/cm_mcu/MonitorTaskI2C_new.c +++ b/projects/cm_mcu/MonitorTaskI2C_new.c @@ -121,7 +121,6 @@ void MonitorI2CTask_new(void *parameters) // what kind of device is this uint32_t devtype_mask = args->typeCallback(device); - uint32_t clz = __builtin_clz(devtype_mask); uint32_t devtype = 32 - __builtin_clz( devtype_mask); // highest bit set FIXME: this is backwards // Loop to read I2C registers/commands for (int c = 0; c < args->n_commands; ++c) { diff --git a/sm_cm_config/data/MON_I2C_rev2.yml b/sm_cm_config/data/MON_I2C_rev2.yml index 4ba2f9f5..c71ee814 100644 --- a/sm_cm_config/data/MON_I2C_rev2.yml +++ b/sm_cm_config/data/MON_I2C_rev2.yml @@ -4,99 +4,100 @@ metadata: - cm_hw_rev: 2A - revision: 1 +# these registers are shared between the two FF tasks +define: &FF_SHARED_REGS + - name: STATUS_REG # register name + reg_size: 1 # size of register address in bytes + page: 0 # page of register + reg_address: 0x2 # register address + size: 2 # size of data in register in bytes + mask: 0xFF # mask for valid bits + units: "" # units for display + type: PM_STATUS # type of data + devicetypes: [CERNB, 14G, 25G4, 25G12] # device types that use this register + - name: TEMPERATURE + reg_size: 1 + page: 0 + reg_address: 0x16 + size: 2 + mask: 0xFF + units: C + type: PM_NONVOLTAGE + devicetypes: [14G, 25G12, 25G4, CERNB] + - name: LOS_ALARM + reg_size: 1 + page: 0 + reg_address: 0x07 + size: 2 + mask: 0xFFFF + units: "" + type: PM_STATUS + devicetypes: [25G12, 25G4] + - name: OPT_POWER_CH1 + reg_size: 1 + page: 0 + reg_address: [-1, -1, 0x22, 0xe4] + size: 2 + mask: 0xFFFF + units: uW + type: PM_VOLTAGE + devicetypes: [25G4, 25G12] + - name: OPT_POWER_CH2 + reg_size: 1 + page: 0 + reg_address: [-1, -1, 0x24, 0xe2] + size: 2 + mask: 0xFFFF + units: uW + type: PM_VOLTAGE + devicetypes: [25G4, 25G12] + - name: OPT_POWER_CH3 + reg_size: 1 + page: 0 + reg_address: [-1, -1, 0x26, 0xe0] + size: 2 + mask: 0xFFFF + units: uW + type: PM_VOLTAGE + devicetypes: [25G4, 25G12] + - name: OPT_POWER_CH4 + reg_size: 1 + page: 0 + reg_address: [-1, -1, 0x28, 0xde] + size: 2 + mask: 0xFFFF + units: uW + type: PM_VOLTAGE + devicetypes: [25G4, 25G12] + - name: OPT_POWER_CH5 + reg_size: 1 + page: 0 + reg_address: [-1, -1, -1, 0xdc] + size: 2 + mask: 0xFFFF + units: uW + type: PM_VOLTAGE + devicetypes: [25G12] + devices: - - name: Fireflies - ndevices: NFIREFLIES + - name: Fireflies_F1 + ndevices: NFIREFLIES_F1 + ndevice_types: 4 + prefix: FF_F1 + config: + *FF_SHARED_REGS + - name: Fireflies_F2 + ndevices: NFIREFLIES_F2 ndevice_types: 4 - prefix: FF + prefix: FF_F2 config: - # - name: "bob" # register name - # reg_size: 1 # size of register address - # page: 0 - # reg_address: 0x1 # actual register address by device type - # size: 0 # how many bytes to read - # bit_mask: 0xFFFF # ?? - # units: A - # type: Linear11 # bitfield, linear11, linear16 - # devices: # list of devices that have this register. 14G, 25G-12, 25G-4, CERN-B. - - name: FF_STATUS_REG - reg_size: 1 - page: 0 - reg_address: 0x2 - size: 2 - mask: 0xFF - units: "" - type: PM_STATUS - devicetypes: [CERNB, 14G, 25G4, 25G12] - - name: FF_TEMPERATURE - reg_size: 1 - page: 0 - reg_address: 0x16 - size: 2 - mask: 0xFF - units: C - type: PM_NONVOLTAGE - devicetypes: [14G, 25G12, 25G4, CERNB] - - name: FF_LOS_ALARM - reg_size: 1 - page: 0 - reg_address: 0x07 - size: 2 - mask: 0xFFFF - units: "" - type: PM_STATUS - devicetypes: [25G12, 25G4] - - name: FF_OPT_POWER_CH1 - reg_size: 1 - page: 0 - reg_address: [-1, -1, 0x22, 0xe4] - size: 2 - mask: 0xFFFF - units: uW - type: PM_VOLTAGE - devicetypes: [25G4, 25G12] - - name: FF_OPT_POWER_CH2 - reg_size: 1 - page: 0 - reg_address: [-1, -1, 0x24, 0xe2] - size: 2 - mask: 0xFFFF - units: uW - type: PM_VOLTAGE - devicetypes: [25G4, 25G12] - - name: FF_OPT_POWER_CH3 - reg_size: 1 - page: 0 - reg_address: [-1, -1, 0x26, 0xe0] - size: 2 - mask: 0xFFFF - units: uW - type: PM_VOLTAGE - devicetypes: [25G4, 25G12] - - name: FF_OPT_POWER_CH4 - reg_size: 1 - page: 0 - reg_address: [-1, -1, 0x28, 0xde] - size: 2 - mask: 0xFFFF - units: uW - type: PM_VOLTAGE - devicetypes: [25G4, 25G12] - - name: FF_OPT_POWER_CH5 - reg_size: 1 - page: 0 - reg_address: [-1, -1, -1, 0xdc] - size: 2 - mask: 0xFFFF - units: uW - type: PM_VOLTAGE - devicetypes: [25G12] + *FF_SHARED_REGS - name: Clocks ndevices: NDEVICES_CLK ndevice_types: 2 prefix: CLK config: - - name: CLK_PN_BASE + - name: PN_BASE reg_size: 1 page: 0 reg_address: 0x2 @@ -105,7 +106,7 @@ devices: units: "" type: PM_STATUS devicetypes: [SI5395, SI5341] - - name: CLK_DEVICE_REV + - name: DEVICE_REV reg_size: 1 page: 0 reg_address: 0x5 @@ -114,7 +115,7 @@ devices: units: "" type: PM_STATUS devicetypes: [SI5395, SI5341] - - name: CLK_I2C_ADDR + - name: I2C_ADDR reg_size: 1 page: 0 reg_address: 0xB @@ -123,7 +124,7 @@ devices: units: "" type: PM_STATUS devicetypes: [SI5395, SI5341] - - name: CLK_STATUS + - name: STATUS reg_size: 1 page: 0 reg_address: 0x35 @@ -132,7 +133,7 @@ devices: units: "" type: PM_STATUS devicetypes: [SI5341] - - name: CLK_LOL + - name: LOL reg_size: 1 page: 0 reg_address: 0xE @@ -141,7 +142,7 @@ devices: units: "" type: PM_STATUS devicetypes: [SI5395] - - name: CLK_LOSXAXB + - name: LOSXAXB reg_size: 1 page: 0 reg_address: 0xB @@ -150,7 +151,7 @@ devices: units: "" type: PM_STATUS devicetypes: [SI5395] - - name: CLK_LOSOOF_IN + - name: LOSOOF_IN reg_size: 1 page: 0 reg_address: 0xD @@ -159,7 +160,7 @@ devices: units: "" type: PM_STATUS devicetypes: [SI5395] - - name: CLK_STICKY_FLG + - name: STICKY_FLG reg_size: 1 page: 0 reg_address: 0x11 diff --git a/sm_cm_config/src/mon_generate.py b/sm_cm_config/src/mon_generate.py index 9cdb5087..c0ad407f 100755 --- a/sm_cm_config/src/mon_generate.py +++ b/sm_cm_config/src/mon_generate.py @@ -19,9 +19,9 @@ def parse_args() -> argparse.Namespace: help='increase output verbosity') parser.add_argument('-o', '--output', type=str, help='output file name', default="MonI2C_addresses.c") -#this argument is required - parser.add_argument('input_files', metavar='file', type=str, - nargs='+', help='input yaml file names') + # this argument is required + parser.add_argument('input_file', metavar='file', type=str, + help='input yaml file names') return parser.parse_args() @@ -52,7 +52,7 @@ def write_boilderplate(fout: io.TextIOWrapper): # addr_template = Template("{$reg_size, $page, $reg_address, $size, \"$name\"," # " $mask, \"$units\", $type, get_${name}_mask, set_${name}_data}, ") addr_template = Template("{$reg_size, $page, $reg_list, $size, \"$name\"," - " $mask, \"$units\", $type, get_${name}_mask, set_${name}_data}, ") + " $mask, \"$units\", $type, get_${prefix}_${name}_mask, set_${prefix}_${name}_data}, ") # output file names: header file and c source file # make sure that the output file ends with .c. Print error message and exit if it doesn't if not args.output.endswith(".c"): @@ -84,11 +84,14 @@ def write_boilderplate(fout: io.TextIOWrapper): print("#include \"MonitorI2CTask.h\"", file=fout_source) - with open(args.input_files[0], encoding="ascii") as f: + with open(args.input_file, encoding="ascii") as f: # generate the list of registers to access # loop over devices first data = yaml.load(f, Loader=yaml.FullLoader) + for k in data.keys(): + print(f"key is {k}") + for d in data['devices']: ndev = d['ndevices'] ndev_types = d['ndevice_types'] @@ -117,39 +120,67 @@ def write_boilderplate(fout: io.TextIOWrapper): else: reg_list_str += f"{prefix}_NOT_COVERED, " reg_list_str += "}" - s = addr_template.substitute(c, reg_list=reg_list_str) + s = addr_template.substitute(c, reg_list=reg_list_str, prefix=prefix) print(s, file=fout_source) print(r"};", file=fout_source) # generate the arrays to store the data print(r"// Arrays to store the data", file=fout_source) + prefix = d['prefix'] for c in config: - print(f"static uint16_t {c['name']}_data[{ndev}] = {{0}};", file=fout_source) + data_name = f"{prefix}_{c['name']}_data" + print(f"static uint16_t {data_name}[{ndev}] = {{0}};", file=fout_source) # generate access functions print(r"// Access functions", file=fout_source) for c in config: - set_fcn_name = f"set_{c['name']}_data" + data_name = f"{prefix}_{c['name']}_data" + set_fcn_name = f"set_{prefix}_{c['name']}_data" + get_fcn_name = f"get_{prefix}_{c['name']}_data" # getter - print(f"uint16_t get_{c['name']}_data(int which);", file=fout_header) - print(f"uint16_t get_{c['name']}_data(int which) {{", file=fout_source) - print(f" return {c['name']}_data[which];", file=fout_source) + print(f"uint16_t {get_fcn_name}(int which);", file=fout_header) + print(f"uint16_t {get_fcn_name}(int which) {{", file=fout_source) + print(f" return {data_name}[which];", file=fout_source) print(r"}", file=fout_source) # setter print(f"void {set_fcn_name}(uint16_t data, int which);", file=fout_header) print(f"void {set_fcn_name}(uint16_t data, int which) {{", file=fout_source) - print(f" {c['name']}_data[which] = data;", file=fout_source) + print(f" {data_name}[which] = data;", file=fout_source) print(r"}", file=fout_source) # using the devices field, generate a function that returns a mask of the devices print(r"// Function to return a mask of the devices for each command", file=fout_source) for c in config: - print(f"uint16_t get_{c['name']}_mask(void);", file=fout_header) - print(f"uint16_t get_{c['name']}_mask(void) {{", file=fout_source) + get_mask_fcn_name = f"get_{prefix}_{c['name']}_mask" + print(f"uint16_t {get_mask_fcn_name}(void);", file=fout_header) + print(f"uint16_t {get_mask_fcn_name}(void) {{", file=fout_source) print(r" return ", end="", file=fout_source) for d in c['devicetypes']: print(f"DEVICE_{d} | ", end="", file=fout_source) print(r"0;", file=fout_source) print(r"}", file=fout_source) - # closing header guard + # special: for the firefly devices, generate a list of functions that + # return either the data in the F1 array or the data in the F2 array, + # depending on if the argument is >= than or less than 10 + print(r"// Functions to return the data in the F1 or F2 arrays", file=fout_source) + config = data['define'] #['FF_SHARED_REGS'] + #print(config) + for c in config: + print(c) + data_name_f1 = f"FF_F1_{c['name']}_data" + data_name_f2 = f"FF_F2_{c['name']}_data" + get_fcn_name_f1 = f"get_F1_{c['name']}_data" + get_fcn_name_f2 = f"get_F2_{c['name']}_data" + get_fcn_name = f"get_FF_{c['name']}_data" + # write get_fcn_name header to the header file + print(f"uint16_t {get_fcn_name}(int which);", file=fout_header) + # write body of get_fcn_name to the source file + print(f"uint16_t {get_fcn_name}(int which) {{", file=fout_source) + print( " if (which < NFIREFLIES_F1) {{", file=fout_source) + print(f" return {data_name_f1}[which];", file=fout_source) + print( " }} else {{", file=fout_source) + print(f" return {data_name_f2}[which - NFIREFLIES_F1];", file=fout_source) + print( " }}", file=fout_source) + print(r"}", file=fout_source) + # closing header guard print(r"#endif// MON_I2C_ADDRESSES_H", file=fout_header) # reformat the c file using clang-format From df67d03105d1699a90b6d8bdcc38b7cd6f5cd95f Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Thu, 23 May 2024 15:11:07 -0400 Subject: [PATCH 24/71] formatting and cleanup --- projects/cm_mcu/FireflyUtils.c | 8 ++--- projects/cm_mcu/MonUtils.c | 4 +-- projects/cm_mcu/MonitorTaskI2C_new.c | 2 +- projects/cm_mcu/clocksynth.c | 6 ++-- projects/cm_mcu/cm_mcu.c | 7 ++--- projects/cm_mcu/commands/SensorControl.c | 40 ++++++++++++------------ 6 files changed, 33 insertions(+), 34 deletions(-) diff --git a/projects/cm_mcu/FireflyUtils.c b/projects/cm_mcu/FireflyUtils.c index 009c60b5..3322b7aa 100644 --- a/projects/cm_mcu/FireflyUtils.c +++ b/projects/cm_mcu/FireflyUtils.c @@ -148,10 +148,10 @@ void readFFpresent(void) ((present_FFL12_BOTTOM_F1)); // 6 bits #elif defined(REV2) - present_FFL12_F1 = present_FFL12_F1 & 0x3FU; // bottom 6 bits - present_FFL12_F2 = present_FFL12_F2 & 0x3FU; // bottom 6 bits - present_FFL4_F1 = (present_FFL4_F1 >> 4) & 0xFU; // bits 4-7 - present_FFL4_F2 = (present_FFL4_F2 >> 4) & 0xFU; // bits 4-7 + present_FFL12_F1 = present_FFL12_F1 & 0x3FU; // bottom 6 bits + present_FFL12_F2 = present_FFL12_F2 & 0x3FU; // bottom 6 bits + present_FFL4_F1 = (present_FFL4_F1 >> 4) & 0xFU; // bits 4-7 + present_FFL4_F2 = (present_FFL4_F2 >> 4) & 0xFU; // bits 4-7 uint32_t ff_combined_present = ((present_FFL4_F2) << 16) | // 4 bits ((present_FFL12_F2) << 10) | // 6 bits diff --git a/projects/cm_mcu/MonUtils.c b/projects/cm_mcu/MonUtils.c index f697ed6e..a44ef6af 100644 --- a/projects/cm_mcu/MonUtils.c +++ b/projects/cm_mcu/MonUtils.c @@ -8,7 +8,7 @@ // for 4 channel parts, there is one XCVR part int FireflyType(int device) { - device = device %NFIREFLIES_F1; // F1 and F2 devices are the same. + device = device % NFIREFLIES_F1; // F1 and F2 devices are the same. switch (device) { case 0: case 1: @@ -50,7 +50,7 @@ int ClockType(int device) bool isEnabledFF_F2(int device) { // firefly devices on F2 are devices 10-19 - return isEnabledFF(device+NFIREFLIES_F1); + return isEnabledFF(device + NFIREFLIES_F1); } struct MonitorI2CTaskArgs_new_t ff_f1_args = { diff --git a/projects/cm_mcu/MonitorTaskI2C_new.c b/projects/cm_mcu/MonitorTaskI2C_new.c index 26630cc4..d82d09e1 100644 --- a/projects/cm_mcu/MonitorTaskI2C_new.c +++ b/projects/cm_mcu/MonitorTaskI2C_new.c @@ -121,7 +121,7 @@ void MonitorI2CTask_new(void *parameters) // what kind of device is this uint32_t devtype_mask = args->typeCallback(device); - uint32_t devtype = 32 - __builtin_clz( devtype_mask); // highest bit set FIXME: this is backwards + uint32_t devtype = 32 - __builtin_clz(devtype_mask); // highest bit set FIXME: this is backwards // Loop to read I2C registers/commands for (int c = 0; c < args->n_commands; ++c) { // check if the command is for this device diff --git a/projects/cm_mcu/clocksynth.c b/projects/cm_mcu/clocksynth.c index 86631bd7..ef8f6735 100644 --- a/projects/cm_mcu/clocksynth.c +++ b/projects/cm_mcu/clocksynth.c @@ -104,7 +104,7 @@ void getClockProgram(int device, char progname_clkdesgid[CLOCK_PROGNAME_REG_NAME CLOCK_CHANGEPAGE_REG_ADDR, 1, page); // now read out the six bytes of data in two reads - const uint8_t reg = (CLOCK_PROGNAME_REG_ADDR_START) & 0xFF; + const uint8_t reg = (CLOCK_PROGNAME_REG_ADDR_START)&0xFF; uint16_t init_postamble_page = 32 * (device + 1) - 1; // read the addresses in EEPROM that store the number of registers in Preamble-register, Register, and Postamble-register list per a clock config file @@ -131,10 +131,10 @@ void getClockProgram(int device, char progname_clkdesgid[CLOCK_PROGNAME_REG_NAME // as eepromdata[0] and eepromdat[1],respectively // third byte from three addresses in EEPROM is a value byte - apollo_i2c_ctl_reg_r(CLOCK_I2C_DEV, CLOCK_I2C_EEPROM_ADDR, 2, eeprom_progname_reg + ((i) * 3), 3, tempdata); + apollo_i2c_ctl_reg_r(CLOCK_I2C_DEV, CLOCK_I2C_EEPROM_ADDR, 2, eeprom_progname_reg + ((i)*3), 3, tempdata); eepromdata[0] |= ((tempdata[0] >> (16)) & 0xFF) << (i * 8); // third byte from three addresses in EEPROM is a value byte - apollo_i2c_ctl_reg_r(CLOCK_I2C_DEV, CLOCK_I2C_EEPROM_ADDR, 2, eeprom_progname_reg + 12 + ((i) * 3), 3, tempdata); + apollo_i2c_ctl_reg_r(CLOCK_I2C_DEV, CLOCK_I2C_EEPROM_ADDR, 2, eeprom_progname_reg + 12 + ((i)*3), 3, tempdata); eepromdata[1] |= ((tempdata[0] >> (16)) & 0xFF) << (i * 8); } } diff --git a/projects/cm_mcu/cm_mcu.c b/projects/cm_mcu/cm_mcu.c index 3a3f5fee..6b550086 100644 --- a/projects/cm_mcu/cm_mcu.c +++ b/projects/cm_mcu/cm_mcu.c @@ -137,7 +137,7 @@ void SystemInitInterrupts(void) #if defined(REV1) initI2C6(g_ui32SysClock); // controller for FPGAs #elif defined(REV2) - initI2C5(g_ui32SysClock); // controller for FPGAs + initI2C5(g_ui32SysClock); // controller for FPGAs #endif // smbus @@ -305,9 +305,8 @@ __attribute__((noreturn)) int main(void) #ifdef REV2 xTaskCreate(MonitorI2CTask_new, ff_f1_args.name, 2 * configMINIMAL_STACK_SIZE, &ff_f1_args, tskIDLE_PRIORITY + 4, NULL); - // these get stored to the wrong location -// xTaskCreate(MonitorI2CTask_new, ff_f2_args.name, 2 * configMINIMAL_STACK_SIZE, &ff_f2_args, tskIDLE_PRIORITY + 4, -// NULL); + xTaskCreate(MonitorI2CTask_new, ff_f2_args.name, 2 * configMINIMAL_STACK_SIZE, &ff_f2_args, tskIDLE_PRIORITY + 4, + NULL); xTaskCreate(MonitorI2CTask, clock_args.name, 2 * configMINIMAL_STACK_SIZE, &clock_args, tskIDLE_PRIORITY + 4, NULL); diff --git a/projects/cm_mcu/commands/SensorControl.c b/projects/cm_mcu/commands/SensorControl.c index d561d93b..9a6ae742 100644 --- a/projects/cm_mcu/commands/SensorControl.c +++ b/projects/cm_mcu/commands/SensorControl.c @@ -859,7 +859,7 @@ BaseType_t ff_temp(int argc, char **argv, char *m) int copied = 0; static int whichff = 0; - static int nn=0, n = 0; + static int nn = 0;//, n = 0; if (nn == 0) { // check for stale data @@ -902,25 +902,25 @@ BaseType_t ff_temp(int argc, char **argv, char *m) } copied += snprintf(m+copied, SCRATCH_SIZE - copied, "-------\r\n"); #endif - //static int nn = 0; - for (; nn < NFIREFLIES; ++nn) { - if (isEnabledFF(nn)) { - uint8_t val = get_FF_TEMPERATURE_data(nn); - copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%17s: %2d", ff_moni2c_addrs[nn].name, val); - } - else // dummy value - copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%17s: %2s", ff_moni2c_addrs[nn].name, "--"); - if ((SCRATCH_SIZE - copied) < 20) { - ++whichff; - return pdTRUE; - } - bool isTx = (strstr(ff_moni2c_addrs[nn].name, "Tx") != NULL); - if (isTx) - copied += snprintf(m + copied, SCRATCH_SIZE - copied, "\t"); - else - copied += snprintf(m + copied, SCRATCH_SIZE - copied, "\r\n"); + // static int nn = 0; + for (; nn < NFIREFLIES; ++nn) { + if (isEnabledFF(nn)) { + uint8_t val = get_FF_TEMPERATURE_data(nn); + copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%17s: %2d", ff_moni2c_addrs[nn].name, val); } - nn = 0; + else // dummy value + copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%17s: %2s", ff_moni2c_addrs[nn].name, "--"); + if ((SCRATCH_SIZE - copied) < 20) { + ++whichff; + return pdTRUE; + } + bool isTx = (strstr(ff_moni2c_addrs[nn].name, "Tx") != NULL); + if (isTx) + copied += snprintf(m + copied, SCRATCH_SIZE - copied, "\t"); + else + copied += snprintf(m + copied, SCRATCH_SIZE - copied, "\r\n"); + } + nn = 0; //} if (nn % 2 == 1) { @@ -929,7 +929,7 @@ BaseType_t ff_temp(int argc, char **argv, char *m) m[copied] = '\0'; } whichff = 0; - n = 0; + //n = 0; return pdFALSE; } From 081f873f002f6af39a1b598adf1d4a32468e6c91 Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Thu, 23 May 2024 16:55:15 -0400 Subject: [PATCH 25/71] clang complaint --- projects/cm_mcu/commands/SensorControl.c | 6 +++--- sm_cm_config/src/mcu_generate.py | 6 ++++++ sm_cm_config/src/mon_generate.py | 3 --- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/projects/cm_mcu/commands/SensorControl.c b/projects/cm_mcu/commands/SensorControl.c index 9a6ae742..be22a287 100644 --- a/projects/cm_mcu/commands/SensorControl.c +++ b/projects/cm_mcu/commands/SensorControl.c @@ -858,7 +858,7 @@ BaseType_t ff_temp(int argc, char **argv, char *m) // argument handling int copied = 0; - static int whichff = 0; + //static int whichff = 0; static int nn = 0;//, n = 0; if (nn == 0) { @@ -911,7 +911,7 @@ BaseType_t ff_temp(int argc, char **argv, char *m) else // dummy value copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%17s: %2s", ff_moni2c_addrs[nn].name, "--"); if ((SCRATCH_SIZE - copied) < 20) { - ++whichff; + //++whichff; return pdTRUE; } bool isTx = (strstr(ff_moni2c_addrs[nn].name, "Tx") != NULL); @@ -928,7 +928,7 @@ BaseType_t ff_temp(int argc, char **argv, char *m) m[copied++] = '\n'; m[copied] = '\0'; } - whichff = 0; + //whichff = 0; //n = 0; return pdFALSE; diff --git a/sm_cm_config/src/mcu_generate.py b/sm_cm_config/src/mcu_generate.py index 209dec10..2276ceaf 100644 --- a/sm_cm_config/src/mcu_generate.py +++ b/sm_cm_config/src/mcu_generate.py @@ -1,5 +1,6 @@ #! /usr/bin/env python """ Generate the C code for the microcontroller using the yaml files in the data directory""" +import datetime import os import sys import argparse @@ -42,6 +43,11 @@ print(r"// This file contains the addresses of the zynqmon data", file=fout) print(r"// and the C calls to initialize the zynqmon data", file=fout) print(r"//", file=fout) + # Print timestamp to output file + timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") + print(f"// Generated: {timestamp}", file=fout) + print(r"//", file=fout) + print("#include \"Tasks.h\"", file=fout) # include the header file we will write later print(f"#include \"{header_fname}\"", file=fout) diff --git a/sm_cm_config/src/mon_generate.py b/sm_cm_config/src/mon_generate.py index c0ad407f..356d24e2 100755 --- a/sm_cm_config/src/mon_generate.py +++ b/sm_cm_config/src/mon_generate.py @@ -89,8 +89,6 @@ def write_boilderplate(fout: io.TextIOWrapper): # generate the list of registers to access # loop over devices first data = yaml.load(f, Loader=yaml.FullLoader) - for k in data.keys(): - print(f"key is {k}") for d in data['devices']: ndev = d['ndevices'] @@ -164,7 +162,6 @@ def write_boilderplate(fout: io.TextIOWrapper): config = data['define'] #['FF_SHARED_REGS'] #print(config) for c in config: - print(c) data_name_f1 = f"FF_F1_{c['name']}_data" data_name_f2 = f"FF_F2_{c['name']}_data" get_fcn_name_f1 = f"get_F1_{c['name']}_data" From 08f68eff3f1c637524a153a41cca283429e39723 Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Mon, 27 May 2024 17:53:32 -0400 Subject: [PATCH 26/71] fix b04 laser off bug and add ff_dump_names --- projects/cm_mcu/CommandLineTask.c | 6 +++ projects/cm_mcu/MonUtils.h | 2 + projects/cm_mcu/MonitorTaskI2C_new.c | 2 +- projects/cm_mcu/Semaphore.c | 2 +- projects/cm_mcu/commands/SensorControl.c | 59 +++++++++++++++++++++--- projects/cm_mcu/commands/SensorControl.h | 1 + 6 files changed, 64 insertions(+), 8 deletions(-) diff --git a/projects/cm_mcu/CommandLineTask.c b/projects/cm_mcu/CommandLineTask.c index 55e91d91..d029f7bb 100644 --- a/projects/cm_mcu/CommandLineTask.c +++ b/projects/cm_mcu/CommandLineTask.c @@ -305,6 +305,12 @@ static struct command_t commands[] = { "reset ff muxes, 1 or 2 for F1 or F2\r\n", 1, }, + { + "ff_dump_names", + ff_dump_names, + "dump name registers\r\n", + 0, + }, #endif // REV2 { "ff_optpow", diff --git a/projects/cm_mcu/MonUtils.h b/projects/cm_mcu/MonUtils.h index 587ee6d9..1d374392 100644 --- a/projects/cm_mcu/MonUtils.h +++ b/projects/cm_mcu/MonUtils.h @@ -6,4 +6,6 @@ extern struct MonitorI2CTaskArgs_new_t ff_f1_args; extern struct MonitorI2CTaskArgs_new_t ff_f2_args; +int FireflyType(int device); + #endif // MONUTILS_H diff --git a/projects/cm_mcu/MonitorTaskI2C_new.c b/projects/cm_mcu/MonitorTaskI2C_new.c index d82d09e1..a195fd4f 100644 --- a/projects/cm_mcu/MonitorTaskI2C_new.c +++ b/projects/cm_mcu/MonitorTaskI2C_new.c @@ -88,7 +88,7 @@ void MonitorI2CTask_new(void *parameters) log_debug(LOG_MONI2C, "%s: device %d not present\r\n", args->name, device); continue; } - log_debug(LOG_MONI2C, "%s: device %d powercheck\r\n", args->name, device); + log_debug(LOG_MONI2C, "%s: device %d pwr chk\r\n", args->name, device); if (getPowerControlState() != POWER_ON) { if (good) { log_info(LOG_MONI2C, "%s: PWR off. Disable I2Cmon.\r\n", args->name); diff --git a/projects/cm_mcu/Semaphore.c b/projects/cm_mcu/Semaphore.c index 56f32710..997c9c10 100644 --- a/projects/cm_mcu/Semaphore.c +++ b/projects/cm_mcu/Semaphore.c @@ -60,10 +60,10 @@ SemaphoreHandle_t getSemaphore(int number) int acquireI2CSemaphoreTime(SemaphoreHandle_t s, TickType_t tickWaits) { - int retval = pdTRUE; if (s == NULL) { return pdFAIL; } + int retval = pdTRUE; int tries = 0; while (xSemaphoreTake(s, tickWaits) == pdFALSE) { ++tries; diff --git a/projects/cm_mcu/commands/SensorControl.c b/projects/cm_mcu/commands/SensorControl.c index 9a6ae742..e7ed6ea3 100644 --- a/projects/cm_mcu/commands/SensorControl.c +++ b/projects/cm_mcu/commands/SensorControl.c @@ -17,6 +17,7 @@ #include "common/smbus_helper.h" #include "Tasks.h" #include "projdefs.h" +#include "MonUtils.h" int read_ff_register(const char *name, uint16_t packed_reg_addr, uint8_t *value, size_t size, int i2c_device) { @@ -85,9 +86,9 @@ static int write_ff_register(const char *name, uint8_t reg, uint16_t value, int } int res; - SemaphoreHandle_t s = i2c4_sem; + SemaphoreHandle_t s = getSemaphore(4); if (i2c_device == I2C_DEVICE_F2) { - s = i2c3_sem; + s = getSemaphore(3); } if (acquireI2CSemaphore(s) == pdFAIL) { @@ -124,9 +125,9 @@ static int disable_transmit(bool disable, int num_ff) { int ret = 0, i = num_ff, imax = num_ff + 1; // i and imax are used as limits for the loop below. By default, only iterate once, with i=num_ff. - uint16_t value = 0xfff; + uint16_t value = 0xfffU; if (disable == false) - value = 0x0; + value = 0x0U; if (num_ff == NFIREFLIES) { // if NFIREFLIES is given for num_ff, loop over ALL transmitters. i = 0; imax = NFIREFLIES; @@ -143,10 +144,10 @@ static int disable_transmit(bool disable, int num_ff) } if (strstr(ff_moni2c_addrs[i].name, "XCVR") != NULL) { - value = 0xf; + value &= 0x000fU; // only 4 LSB matter, so mask out others ret += write_ff_register(ff_moni2c_addrs[i].name, ECU0_25G_XVCR_TX_DISABLE_REG, value, 1, i2c_dev); } - else if (strstr(ff_moni2c_addrs[i].name, "Tx") != NULL) { + else if (strstr(ff_moni2c_addrs[i].name, "Tx") != NULL) { // FIXME: check for CERNB vs 25G ret += write_ff_register(ff_moni2c_addrs[i].name, ECU0_14G_TX_DISABLE_REG, value, 2, i2c_dev); } } @@ -1437,3 +1438,49 @@ BaseType_t psmon_reg(int argc, char **argv, char *m) } return pdFALSE; } + +//#define VENDOR_START_BIT_FFDAQ 168 +//#define VENDOR_STOP_BIT_FFDAQ 184 +//#define VENDOR_START_BIT_FF12 171 +//#define VENDOR_STOP_BIT_FF12 187 +#define VENDOR_COUNT_FFDAQ (VENDOR_STOP_BIT_FFDAQ-VENDOR_START_BIT_FFDAQ) +#define VENDOR_COUNT_FF12 (VENDOR_STOP_BIT_FF12-VENDOR_START_BIT_FF12) + +BaseType_t ff_dump_names(int argc, char **argv, char *m) +{ + int copied = 0; + copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%s: ID registers\r\n", argv[0]); + static int i = 0; + for (; i < NFIREFLIES; ++i) { + if (!isEnabledFF(i)) {// skip the FF if it's not enabled via the FF config + continue; + } + + char name[20]; + memset(name, '\0', 20); + int type = FireflyType(i); + int startReg = VENDOR_START_BIT_FFDAQ; + int count = VENDOR_COUNT_FFDAQ; + if ( type == DEVICE_CERNB || type == DEVICE_25G12 ) { + startReg = VENDOR_START_BIT_FF12; + count = VENDOR_COUNT_FF12; + } + int ret = 0; + for (unsigned char c = 0; c < count; ++c ) { + uint8_t v; + ret += read_arbitrary_ff_register(startReg + c, i, &v, 1); + name[c] = v; + } + if ( ret != 0 ) { + snprintf(m + copied, SCRATCH_SIZE - copied, "%s: read failed\r\n", argv[0]); + return pdFALSE; + } + copied += snprintf(m+copied, SCRATCH_SIZE - copied, "%02d:\t%s\r\n", i, name); + if ((SCRATCH_SIZE - copied) < 25 && (i < NFIREFLIES)) { + ++i; + return pdTRUE; + } + } + i = 0; + return pdFALSE; +} diff --git a/projects/cm_mcu/commands/SensorControl.h b/projects/cm_mcu/commands/SensorControl.h index 3fbf3e8e..3e8b0da2 100644 --- a/projects/cm_mcu/commands/SensorControl.h +++ b/projects/cm_mcu/commands/SensorControl.h @@ -55,6 +55,7 @@ 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); BaseType_t ff_mux_reset(int argc, char **argv, char *m); +BaseType_t ff_dump_names(int argc, char **argv, char *m); // Clocks BaseType_t clkmon_ctl(int argc, char **argv, char *m); From 8ca43253c86b847670079f1fea19035cbabfe611 Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Mon, 27 May 2024 22:27:00 -0400 Subject: [PATCH 27/71] add clock task --- common/utils.c | 2 ++ common/utils.h | 4 ++-- projects/cm_mcu/MonUtils.c | 15 +++++++++++++++ projects/cm_mcu/MonUtils.h | 8 +++++--- projects/cm_mcu/MonitorTaskI2C_new.c | 3 ++- projects/cm_mcu/cm_mcu.c | 2 ++ 6 files changed, 28 insertions(+), 6 deletions(-) diff --git a/common/utils.c b/common/utils.c index 300ea0cb..776753cd 100644 --- a/common/utils.c +++ b/common/utils.c @@ -4,6 +4,8 @@ * Created on: May 9, 2019 * Author: wittich */ +#include +#include #include "common/utils.h" #include "common/pinsel.h" diff --git a/common/utils.h b/common/utils.h index e3469895..422acf67 100644 --- a/common/utils.h +++ b/common/utils.h @@ -13,8 +13,8 @@ #include #include -#include "math.h" -#include "stdlib.h" +#include // IWYU pragma: keep (for fmaxf, fmax, fmaxl) +#include // IWYU pragma: keep (for abs, labs, llabs, fabs, fabsf) // write, read or toggle GPIO pin by name void write_gpio_pin(int pin, uint8_t value); diff --git a/projects/cm_mcu/MonUtils.c b/projects/cm_mcu/MonUtils.c index a44ef6af..f187e28b 100644 --- a/projects/cm_mcu/MonUtils.c +++ b/projects/cm_mcu/MonUtils.c @@ -2,6 +2,7 @@ #include "MonitorTaskI2C_new.h" #include "MonI2C_addresses.h" #include "FireflyUtils.h" +#include "Tasks.h" #include "MonUtils.h" // for 12 channel parts, there is one Tx and Rx device. @@ -81,4 +82,18 @@ struct MonitorI2CTaskArgs_new_t ff_f2_args = { .presentCallback = isEnabledFF_F2, }; +struct MonitorI2CTaskArgs_new_t clk_args = { + .name = "CLK", + .devices = clk_moni2c_addrs, // FIXME: this doesn't include R0A + .i2c_dev = I2C_DEVICE_CLK, + .n_devices = NDEVICES_CLK, + .commands = sm_command_test_CLK, + .n_commands = NCOMMANDS_CLK, + .selpage_reg = CLK_SELPAGE_REG, + .xSem = NULL, + .stack_size = 4096U, + .typeCallback = ClockType, + .presentCallback = NULL, +}; + #endif // REV2 diff --git a/projects/cm_mcu/MonUtils.h b/projects/cm_mcu/MonUtils.h index 1d374392..08e15fd9 100644 --- a/projects/cm_mcu/MonUtils.h +++ b/projects/cm_mcu/MonUtils.h @@ -3,9 +3,11 @@ #include "MonitorTaskI2C_new.h" -extern struct MonitorI2CTaskArgs_new_t ff_f1_args; -extern struct MonitorI2CTaskArgs_new_t ff_f2_args; - int FireflyType(int device); +// firefly monitoring +extern struct MonitorI2CTaskArgs_new_t ff_f1_args; +extern struct MonitorI2CTaskArgs_new_t ff_f2_args; +// clock monitoring +extern struct MonitorI2CTaskArgs_new_t clk_args; #endif // MONUTILS_H diff --git a/projects/cm_mcu/MonitorTaskI2C_new.c b/projects/cm_mcu/MonitorTaskI2C_new.c index a195fd4f..3f9a021a 100644 --- a/projects/cm_mcu/MonitorTaskI2C_new.c +++ b/projects/cm_mcu/MonitorTaskI2C_new.c @@ -84,7 +84,8 @@ void MonitorI2CTask_new(void *parameters) // loop over devices in the device-type instance // ------------------------------- for (int device = 0; device < args->n_devices; ++device) { - if (args->presentCallback && !args->presentCallback(device)) { + // if there is a present call back and it reurns false, skip this device + if (args->presentCallback && !args->presentCallback(device)) { log_debug(LOG_MONI2C, "%s: device %d not present\r\n", args->name, device); continue; } diff --git a/projects/cm_mcu/cm_mcu.c b/projects/cm_mcu/cm_mcu.c index 6b550086..59158891 100644 --- a/projects/cm_mcu/cm_mcu.c +++ b/projects/cm_mcu/cm_mcu.c @@ -307,6 +307,8 @@ __attribute__((noreturn)) int main(void) NULL); xTaskCreate(MonitorI2CTask_new, ff_f2_args.name, 2 * configMINIMAL_STACK_SIZE, &ff_f2_args, tskIDLE_PRIORITY + 4, NULL); + xTaskCreate(MonitorI2CTask_new, clk_args.name, 2 * configMINIMAL_STACK_SIZE, &clk_args, tskIDLE_PRIORITY + 4, + NULL); xTaskCreate(MonitorI2CTask, clock_args.name, 2 * configMINIMAL_STACK_SIZE, &clock_args, tskIDLE_PRIORITY + 4, NULL); From 5b91e1ba006d7d8d297c43f7b68fc065750c48cd Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Tue, 28 May 2024 11:07:39 -0400 Subject: [PATCH 28/71] Update SensorControl.c --- projects/cm_mcu/commands/SensorControl.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/projects/cm_mcu/commands/SensorControl.c b/projects/cm_mcu/commands/SensorControl.c index 6fef86e1..5173f715 100644 --- a/projects/cm_mcu/commands/SensorControl.c +++ b/projects/cm_mcu/commands/SensorControl.c @@ -10,6 +10,7 @@ #include "FireflyUtils.h" #include "I2CCommunication.h" #include "MonI2C_addresses.h" +#include "common/log.h" #include "common/utils.h" #include "parameters.h" #include "SensorControl.h" @@ -65,6 +66,14 @@ int read_ff_register(const char *name, uint16_t packed_reg_addr, uint8_t *value, SMBUS_get_error(res), ff_moni2c_addrs[ff].name); } } + if (!res) { // clear the mux + muxmask = 0x0U; + res = apollo_i2c_ctl_w(i2c_device, ff_moni2c_addrs[ff].mux_addr, 1, muxmask); + if (res !=0) { + log_warn(LOG_SERVICE, "%s: Mux clear error %d (%s) (ff=%s) ...\r\n", __func__, res, + SMBUS_get_error(res), ff_moni2c_addrs[ff].name); + } + } // release the semaphore if (xSemaphoreGetMutexHolder(s) == xTaskGetCurrentTaskHandle()) @@ -114,6 +123,14 @@ static int write_ff_register(const char *name, uint8_t reg, uint16_t value, int SMBUS_get_error(res), ff_moni2c_addrs[ff].name); } } + if (!res) { // clear the mux + muxmask = 0x0U; + res = apollo_i2c_ctl_w(i2c_device, ff_moni2c_addrs[ff].mux_addr, 1, muxmask); + if (res != 0) { + log_warn(LOG_SERVICE, "%s: Mux clear error %d (%s) (ff=%s) ...\r\n", __func__, res, + SMBUS_get_error(res), ff_moni2c_addrs[ff].name); + } + } // release the semaphore if (xSemaphoreGetMutexHolder(s) == xTaskGetCurrentTaskHandle()) @@ -176,10 +193,10 @@ static int disable_receivers(bool disable, int num_ff) i2c_dev = I2C_DEVICE_F2; } if (strstr(ff_moni2c_addrs[i].name, "XCVR") != NULL) { - value = 0xf; + value &= 0x000fU; // only 4 LSB matter, so mask out others ret += write_ff_register(ff_moni2c_addrs[i].name, ECU0_25G_XVCR_RX_DISABLE_REG, value, 1, i2c_dev); } - else if (strstr(ff_moni2c_addrs[i].name, "Rx") != NULL) { + else if (strstr(ff_moni2c_addrs[i].name, "Rx") != NULL) { // FIXME: check for CERNB vs 25G ret += write_ff_register(ff_moni2c_addrs[i].name, ECU0_14G_RX_DISABLE_REG, value, 2, i2c_dev); } } From 85053c19884b8b7a586e02c61c460927843bb4b2 Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Tue, 28 May 2024 14:04:12 -0400 Subject: [PATCH 29/71] clock mon doesn't crash --- projects/cm_mcu/MonitorTaskI2C_new.c | 7 ++++++- projects/cm_mcu/Tasks.h | 3 --- projects/cm_mcu/cm_mcu.c | 9 +++++---- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/projects/cm_mcu/MonitorTaskI2C_new.c b/projects/cm_mcu/MonitorTaskI2C_new.c index 3f9a021a..007a0969 100644 --- a/projects/cm_mcu/MonitorTaskI2C_new.c +++ b/projects/cm_mcu/MonitorTaskI2C_new.c @@ -60,6 +60,11 @@ void MonitorI2CTask_new(void *parameters) // watchdog info task_watchdog_register_task(kWatchdogTaskID_MonitorI2CTask); + // ensure that the semaphore has been set up + if (!args->xSem) { + log_error(LOG_MONI2C, "%s: no sem\r\n", args->name); + } + // wait for the power to come up vTaskDelayUntil(&(args->updateTick), pdMS_TO_TICKS(5000)); @@ -74,7 +79,7 @@ void MonitorI2CTask_new(void *parameters) // grab the semaphore to ensure unique access to I2C controller if (args->xSem != NULL) { if (acquireI2CSemaphore(args->xSem) == pdFAIL) { - log_debug(LOG_SERVICE, "%s could'nt get sem; delay & continue\r\n", args->name); + log_debug(LOG_MONI2C, "%s could'nt get sem; delay & continue\r\n", args->name); vTaskDelayUntil(&(args->updateTick), pdMS_TO_TICKS(10)); // wait continue; } diff --git a/projects/cm_mcu/Tasks.h b/projects/cm_mcu/Tasks.h index a929a873..c0e7711b 100644 --- a/projects/cm_mcu/Tasks.h +++ b/projects/cm_mcu/Tasks.h @@ -12,13 +12,10 @@ #define PROJECTS_CM_MCU_TASKS_H_ #include "FreeRTOS.h" // IWYU pragma: keep -// #include "FreeRTOSConfig.h" #include "queue.h" #include "semphr.h" #include "common/log.h" -// #include "driverlib/eeprom.h" -// #include "common/printf.h" #include #include "clocksynth.h" diff --git a/projects/cm_mcu/cm_mcu.c b/projects/cm_mcu/cm_mcu.c index 59158891..d7c34d9b 100644 --- a/projects/cm_mcu/cm_mcu.c +++ b/projects/cm_mcu/cm_mcu.c @@ -253,6 +253,7 @@ __attribute__((noreturn)) int main(void) #ifdef REV2 ff_f1_args.xSem = i2c4_sem; ff_f2_args.xSem = i2c3_sem; + clk_args.xSem = i2c2_sem; clock_args.xSem = i2c2_sem; clockr0a_args.xSem = i2c2_sem; #endif // REV2 @@ -310,10 +311,10 @@ __attribute__((noreturn)) int main(void) xTaskCreate(MonitorI2CTask_new, clk_args.name, 2 * configMINIMAL_STACK_SIZE, &clk_args, tskIDLE_PRIORITY + 4, NULL); - xTaskCreate(MonitorI2CTask, clock_args.name, 2 * configMINIMAL_STACK_SIZE, &clock_args, tskIDLE_PRIORITY + 4, - NULL); - xTaskCreate(MonitorI2CTask, clockr0a_args.name, 2 * configMINIMAL_STACK_SIZE, &clockr0a_args, tskIDLE_PRIORITY + 4, - NULL); +// xTaskCreate(MonitorI2CTask, clock_args.name, 2 * configMINIMAL_STACK_SIZE, &clock_args, tskIDLE_PRIORITY + 4, +// NULL); +// xTaskCreate(MonitorI2CTask, clockr0a_args.name, 2 * configMINIMAL_STACK_SIZE, &clockr0a_args, tskIDLE_PRIORITY + 4, +// NULL); #endif // REV2 xTaskCreate(MonitorTask, dcdc_args.name, 2 * configMINIMAL_STACK_SIZE, &dcdc_args, tskIDLE_PRIORITY + 4, NULL); From 663c00f439163504c837e7b5df1df664587caf65 Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Tue, 28 May 2024 14:05:38 -0400 Subject: [PATCH 30/71] clang-format --- common/utils.h | 4 +-- projects/cm_mcu/FireflyUtils.c | 8 +++--- projects/cm_mcu/MonitorTaskI2C_new.c | 2 +- projects/cm_mcu/clocksynth.c | 6 ++--- projects/cm_mcu/cm_mcu.c | 2 +- projects/cm_mcu/commands/SensorControl.c | 32 ++++++++++++------------ 6 files changed, 27 insertions(+), 27 deletions(-) diff --git a/common/utils.h b/common/utils.h index 422acf67..680ab81d 100644 --- a/common/utils.h +++ b/common/utils.h @@ -13,7 +13,7 @@ #include #include -#include // IWYU pragma: keep (for fmaxf, fmax, fmaxl) +#include // IWYU pragma: keep (for fmaxf, fmax, fmaxl) #include // IWYU pragma: keep (for abs, labs, llabs, fabs, fabsf) // write, read or toggle GPIO pin by name @@ -127,7 +127,7 @@ bool checkStale(unsigned oldTime, unsigned newTime); void float_to_ints(float val, int *tens, int *fraction); // this will suffer from the double evaluation bug -//#define MAX(a,b) (a)>(b)?(a):(b) +// #define MAX(a,b) (a)>(b)?(a):(b) // instead use these functions and a _generic macro // this is overkill, but I'm parking it here because I never remember this exists. inline int max(int const x, int const y) diff --git a/projects/cm_mcu/FireflyUtils.c b/projects/cm_mcu/FireflyUtils.c index 3322b7aa..009c60b5 100644 --- a/projects/cm_mcu/FireflyUtils.c +++ b/projects/cm_mcu/FireflyUtils.c @@ -148,10 +148,10 @@ void readFFpresent(void) ((present_FFL12_BOTTOM_F1)); // 6 bits #elif defined(REV2) - present_FFL12_F1 = present_FFL12_F1 & 0x3FU; // bottom 6 bits - present_FFL12_F2 = present_FFL12_F2 & 0x3FU; // bottom 6 bits - present_FFL4_F1 = (present_FFL4_F1 >> 4) & 0xFU; // bits 4-7 - present_FFL4_F2 = (present_FFL4_F2 >> 4) & 0xFU; // bits 4-7 + present_FFL12_F1 = present_FFL12_F1 & 0x3FU; // bottom 6 bits + present_FFL12_F2 = present_FFL12_F2 & 0x3FU; // bottom 6 bits + present_FFL4_F1 = (present_FFL4_F1 >> 4) & 0xFU; // bits 4-7 + present_FFL4_F2 = (present_FFL4_F2 >> 4) & 0xFU; // bits 4-7 uint32_t ff_combined_present = ((present_FFL4_F2) << 16) | // 4 bits ((present_FFL12_F2) << 10) | // 6 bits diff --git a/projects/cm_mcu/MonitorTaskI2C_new.c b/projects/cm_mcu/MonitorTaskI2C_new.c index 007a0969..8a8d413f 100644 --- a/projects/cm_mcu/MonitorTaskI2C_new.c +++ b/projects/cm_mcu/MonitorTaskI2C_new.c @@ -90,7 +90,7 @@ void MonitorI2CTask_new(void *parameters) // ------------------------------- for (int device = 0; device < args->n_devices; ++device) { // if there is a present call back and it reurns false, skip this device - if (args->presentCallback && !args->presentCallback(device)) { + if (args->presentCallback && !args->presentCallback(device)) { log_debug(LOG_MONI2C, "%s: device %d not present\r\n", args->name, device); continue; } diff --git a/projects/cm_mcu/clocksynth.c b/projects/cm_mcu/clocksynth.c index ef8f6735..86631bd7 100644 --- a/projects/cm_mcu/clocksynth.c +++ b/projects/cm_mcu/clocksynth.c @@ -104,7 +104,7 @@ void getClockProgram(int device, char progname_clkdesgid[CLOCK_PROGNAME_REG_NAME CLOCK_CHANGEPAGE_REG_ADDR, 1, page); // now read out the six bytes of data in two reads - const uint8_t reg = (CLOCK_PROGNAME_REG_ADDR_START)&0xFF; + const uint8_t reg = (CLOCK_PROGNAME_REG_ADDR_START) & 0xFF; uint16_t init_postamble_page = 32 * (device + 1) - 1; // read the addresses in EEPROM that store the number of registers in Preamble-register, Register, and Postamble-register list per a clock config file @@ -131,10 +131,10 @@ void getClockProgram(int device, char progname_clkdesgid[CLOCK_PROGNAME_REG_NAME // as eepromdata[0] and eepromdat[1],respectively // third byte from three addresses in EEPROM is a value byte - apollo_i2c_ctl_reg_r(CLOCK_I2C_DEV, CLOCK_I2C_EEPROM_ADDR, 2, eeprom_progname_reg + ((i)*3), 3, tempdata); + apollo_i2c_ctl_reg_r(CLOCK_I2C_DEV, CLOCK_I2C_EEPROM_ADDR, 2, eeprom_progname_reg + ((i) * 3), 3, tempdata); eepromdata[0] |= ((tempdata[0] >> (16)) & 0xFF) << (i * 8); // third byte from three addresses in EEPROM is a value byte - apollo_i2c_ctl_reg_r(CLOCK_I2C_DEV, CLOCK_I2C_EEPROM_ADDR, 2, eeprom_progname_reg + 12 + ((i)*3), 3, tempdata); + apollo_i2c_ctl_reg_r(CLOCK_I2C_DEV, CLOCK_I2C_EEPROM_ADDR, 2, eeprom_progname_reg + 12 + ((i) * 3), 3, tempdata); eepromdata[1] |= ((tempdata[0] >> (16)) & 0xFF) << (i * 8); } } diff --git a/projects/cm_mcu/cm_mcu.c b/projects/cm_mcu/cm_mcu.c index d7c34d9b..eff573fb 100644 --- a/projects/cm_mcu/cm_mcu.c +++ b/projects/cm_mcu/cm_mcu.c @@ -137,7 +137,7 @@ void SystemInitInterrupts(void) #if defined(REV1) initI2C6(g_ui32SysClock); // controller for FPGAs #elif defined(REV2) - initI2C5(g_ui32SysClock); // controller for FPGAs + initI2C5(g_ui32SysClock); // controller for FPGAs #endif // smbus diff --git a/projects/cm_mcu/commands/SensorControl.c b/projects/cm_mcu/commands/SensorControl.c index 5173f715..2c2d480e 100644 --- a/projects/cm_mcu/commands/SensorControl.c +++ b/projects/cm_mcu/commands/SensorControl.c @@ -69,7 +69,7 @@ int read_ff_register(const char *name, uint16_t packed_reg_addr, uint8_t *value, if (!res) { // clear the mux muxmask = 0x0U; res = apollo_i2c_ctl_w(i2c_device, ff_moni2c_addrs[ff].mux_addr, 1, muxmask); - if (res !=0) { + if (res != 0) { log_warn(LOG_SERVICE, "%s: Mux clear error %d (%s) (ff=%s) ...\r\n", __func__, res, SMBUS_get_error(res), ff_moni2c_addrs[ff].name); } @@ -876,8 +876,8 @@ BaseType_t ff_temp(int argc, char **argv, char *m) // argument handling int copied = 0; - //static int whichff = 0; - static int nn = 0;//, n = 0; + // static int whichff = 0; + static int nn = 0; //, n = 0; if (nn == 0) { // check for stale data @@ -946,8 +946,8 @@ BaseType_t ff_temp(int argc, char **argv, char *m) m[copied++] = '\n'; m[copied] = '\0'; } - //whichff = 0; - //n = 0; + // whichff = 0; + // n = 0; return pdFALSE; } @@ -1456,12 +1456,12 @@ BaseType_t psmon_reg(int argc, char **argv, char *m) return pdFALSE; } -//#define VENDOR_START_BIT_FFDAQ 168 -//#define VENDOR_STOP_BIT_FFDAQ 184 -//#define VENDOR_START_BIT_FF12 171 -//#define VENDOR_STOP_BIT_FF12 187 -#define VENDOR_COUNT_FFDAQ (VENDOR_STOP_BIT_FFDAQ-VENDOR_START_BIT_FFDAQ) -#define VENDOR_COUNT_FF12 (VENDOR_STOP_BIT_FF12-VENDOR_START_BIT_FF12) +// #define VENDOR_START_BIT_FFDAQ 168 +// #define VENDOR_STOP_BIT_FFDAQ 184 +// #define VENDOR_START_BIT_FF12 171 +// #define VENDOR_STOP_BIT_FF12 187 +#define VENDOR_COUNT_FFDAQ (VENDOR_STOP_BIT_FFDAQ - VENDOR_START_BIT_FFDAQ) +#define VENDOR_COUNT_FF12 (VENDOR_STOP_BIT_FF12 - VENDOR_START_BIT_FF12) BaseType_t ff_dump_names(int argc, char **argv, char *m) { @@ -1469,7 +1469,7 @@ BaseType_t ff_dump_names(int argc, char **argv, char *m) copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%s: ID registers\r\n", argv[0]); static int i = 0; for (; i < NFIREFLIES; ++i) { - if (!isEnabledFF(i)) {// skip the FF if it's not enabled via the FF config + if (!isEnabledFF(i)) { // skip the FF if it's not enabled via the FF config continue; } @@ -1478,21 +1478,21 @@ BaseType_t ff_dump_names(int argc, char **argv, char *m) int type = FireflyType(i); int startReg = VENDOR_START_BIT_FFDAQ; int count = VENDOR_COUNT_FFDAQ; - if ( type == DEVICE_CERNB || type == DEVICE_25G12 ) { + if (type == DEVICE_CERNB || type == DEVICE_25G12) { startReg = VENDOR_START_BIT_FF12; count = VENDOR_COUNT_FF12; } int ret = 0; - for (unsigned char c = 0; c < count; ++c ) { + for (unsigned char c = 0; c < count; ++c) { uint8_t v; ret += read_arbitrary_ff_register(startReg + c, i, &v, 1); name[c] = v; } - if ( ret != 0 ) { + if (ret != 0) { snprintf(m + copied, SCRATCH_SIZE - copied, "%s: read failed\r\n", argv[0]); return pdFALSE; } - copied += snprintf(m+copied, SCRATCH_SIZE - copied, "%02d:\t%s\r\n", i, name); + copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%02d:\t%s\r\n", i, name); if ((SCRATCH_SIZE - copied) < 25 && (i < NFIREFLIES)) { ++i; return pdTRUE; From 001c597b471dce009e3e34f6e88156235a340944 Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Wed, 29 May 2024 16:00:24 -0400 Subject: [PATCH 31/71] transition to new i2c mon task --- projects/cm_mcu/FireflyUtils.c | 328 +++++----- projects/cm_mcu/FireflyUtils.h | 10 +- projects/cm_mcu/InitTask.c | 2 +- projects/cm_mcu/LocalTasks.c | 746 +++++++---------------- projects/cm_mcu/Makefile | 1 - projects/cm_mcu/MonUtils.c | 3 +- projects/cm_mcu/MonUtils.h | 4 + projects/cm_mcu/MonitorI2CTask.c | 222 ------- projects/cm_mcu/MonitorI2CTask.h | 99 --- projects/cm_mcu/MonitorTaskI2C_new.c | 3 +- projects/cm_mcu/MonitorTaskI2C_new.h | 8 + projects/cm_mcu/PowerSupplyTask.c | 4 +- projects/cm_mcu/Tasks.h | 4 +- projects/cm_mcu/ZynqMonTask.c | 34 +- projects/cm_mcu/clocksynth.c | 74 +-- projects/cm_mcu/cm_mcu.c | 19 - projects/cm_mcu/commands/BoardCommands.c | 1 + projects/cm_mcu/commands/SensorControl.c | 455 ++++++++------ projects/cm_mcu/commands/parameters.h | 1 - sm_cm_config/data/MON_I2C_rev2.yml | 11 +- sm_cm_config/src/mon_generate.py | 35 +- 21 files changed, 768 insertions(+), 1296 deletions(-) delete mode 100644 projects/cm_mcu/MonitorI2CTask.c delete mode 100644 projects/cm_mcu/MonitorI2CTask.h diff --git a/projects/cm_mcu/FireflyUtils.c b/projects/cm_mcu/FireflyUtils.c index 009c60b5..61f802a3 100644 --- a/projects/cm_mcu/FireflyUtils.c +++ b/projects/cm_mcu/FireflyUtils.c @@ -12,11 +12,13 @@ #include #include // memset +#include "MonI2C_addresses.h" +#include "MonUtils.h" +#include "MonitorTaskI2C_new.h" #include "common/log.h" #include "Semaphore.h" #include "I2CCommunication.h" -#include "MonitorI2CTask.h" #include "common/smbus_helper.h" #include "driverlib/eeprom.h" #include "FireflyUtils.h" @@ -186,14 +188,12 @@ bool isEnabledFF(int ff) unsigned isFFStale(void) { TickType_t now = pdTICKS_TO_S(xTaskGetTickCount()); - TickType_t last[4]; - last[0] = pdTICKS_TO_S(ffl12_f1_args.updateTick); - last[1] = pdTICKS_TO_S(ffl4_f1_args.updateTick); - last[2] = pdTICKS_TO_S(ffl12_f2_args.updateTick); - last[3] = pdTICKS_TO_S(ffl4_f2_args.updateTick); + TickType_t last[2]; + last[0] = pdTICKS_TO_S(ff_f1_args.updateTick); + last[1] = pdTICKS_TO_S(ff_f2_args.updateTick); unsigned mask = 0U; - for (int ff_t = 0; ff_t < 4; ++ff_t) { + for (int ff_t = 0; ff_t < 2; ++ff_t) { if (checkStale(last[ff_t], now)) { mask |= (1U << ff_t); } @@ -209,67 +209,47 @@ TickType_t getFFupdateTick(int mask) if (__builtin_popcount(mask) == 0) { log_warn(LOG_SERVICE, "empty mask\r\n"); } - if (mask & 0x1U) { - return ffl12_f1_args.updateTick; + else if (mask & 0x1U) { + return ff_f1_args.updateTick; } else if (mask & 0x02U) { - return ffl4_f1_args.updateTick; - } - else if (mask & 0x04U) { - return ffl12_f2_args.updateTick; - } - else { - return ffl4_f2_args.updateTick; + return ff_f2_args.updateTick; } + log_warn(LOG_SERVICE, "invalid mask\r\n"); + return 0; } uint16_t getFFtemp(const uint8_t i) { - int i1 = 1; - uint16_t val; configASSERT(i < NFIREFLIES); - if (i < NFIREFLIES_IT_F1) { - int index = i * (ffl12_f1_args.n_commands * ffl12_f1_args.n_pages) + i1; - val = ffl12_f1_args.sm_values[index]; - } - - else if (NFIREFLIES_IT_F1 <= i && i < NFIREFLIES_IT_F1 + NFIREFLIES_DAQ_F1) { - int index = (i - NFIREFLIES_IT_F1) * (ffl4_f1_args.n_commands * ffl4_f1_args.n_pages) + i1; - val = ffl4_f1_args.sm_values[index]; - } - - else if (NFIREFLIES_F1 <= i && i < NFIREFLIES_F1 + NFIREFLIES_IT_F2) { - int index = (i - NFIREFLIES_F1) * (ffl12_f2_args.n_commands * ffl12_f2_args.n_pages) + i1; - val = ffl12_f2_args.sm_values[index]; - } - else { - int index = (i - NFIREFLIES_F1 - NFIREFLIES_IT_F2) * (ffl4_f2_args.n_commands * ffl4_f2_args.n_pages) + i1; - val = ffl4_f2_args.sm_values[index]; - } - - return val; + return get_FF_TEMPERATURE_data(i); } #ifdef REV2 -uint16_t getFFavgoptpow(const uint8_t i) +float getFFavgoptpow(const uint8_t i) { - uint16_t avg_val = 0; uint16_t sum_val = 0; configASSERT(i < NFIREFLIES); - for (int n = 0; n < 4; ++n) { - if (ff_moni2c_arg[n].int_idx <= i && i < ff_moni2c_arg[n].int_idx + ff_moni2c_arg[n].num_dev) { - for (int i1 = 4; i1 < ff_moni2c_arg[n].arg->n_commands; ++i1) { - int dev = i - ff_moni2c_arg[n].int_idx + ff_moni2c_arg[n].dev_int_idx; - int index = dev * (ff_moni2c_arg[n].arg->n_commands * ff_moni2c_arg[n].arg->n_pages) + i1; - sum_val += ff_moni2c_arg[n].arg->sm_values[index]; - } - avg_val = sum_val / (ff_moni2c_arg[n].arg->n_commands - 4); - } + sum_val += get_FF_OPT_POWER_CH1_data(i); + sum_val += get_FF_OPT_POWER_CH2_data(i); + sum_val += get_FF_OPT_POWER_CH3_data(i); + sum_val += get_FF_OPT_POWER_CH4_data(i); + sum_val += get_FF_OPT_POWER_CH5_data(i); + // sum_val += get_FF_OPT_POWER_CH6_data(i); + // sum_val += get_FF_OPT_POWER_CH7_data(i); + // sum_val += get_FF_OPT_POWER_CH8_data(i); + // sum_val += get_FF_OPT_POWER_CH9_data(i); + // sum_val += get_FF_OPT_POWER_CH10_data(i); + // sum_val += get_FF_OPT_POWER_CH11_data(i); + // sum_val += get_FF_OPT_POWER_CH12_data(i); + + float nchannels = 12.; + if (FireflyType(i) == DEVICE_25G4) { + nchannels = 4.; } - - return avg_val; + return sum_val / nchannels; } uint16_t getFFpresentbit(const uint8_t i) @@ -283,115 +263,153 @@ uint16_t getFFpresentbit(const uint8_t i) return val; } -extern struct sm_command_t sm_command_fflit_f1[]; -extern struct sm_command_t sm_command_fflit_f2[]; - -void getFFpart(void) +uint32_t ff_map_25gb_parts(void) { - // Write device vendor part for identifying FF device - uint8_t nstring = VENDOR_STOP_BIT_FF12 - VENDOR_START_BIT_FF12 + 1; - char vendor_string[nstring]; - uint8_t data; - - SemaphoreHandle_t semaphores[2] = {i2c4_sem, i2c3_sem}; - const int ff_ndev_offset[2] = {0, NFIREFLIES_IT_F1 + NFIREFLIES_DAQ_F1}; - const uint32_t ndevices[2] = {NDEVICES_FFL12_F1 / 2, NDEVICES_FFL12_F2 / 2}; - const uint32_t dev_present_mask[2] = {present_FFL12_F1, present_FFL12_F2}; - const uint32_t dev_xmit_4v0_sel[2] = {f1_ff12xmit_4v0_sel, f2_ff12xmit_4v0_sel}; - - struct MonitorI2CTaskArgs_t args_st[2] = {ffl12_f1_args, ffl12_f2_args}; - - for (int f = 0; f < 2; ++f) { - - // grab the semaphore to ensure unique access to I2C controller - // otherwise, block its operations indefinitely until it's available - acquireI2CSemaphoreBlock(semaphores[f]); - uint32_t tmp_ffpart_bit_mask = 0U; - bool detect_ff = false; - for (uint32_t n = 0; n < ndevices[f]; n++) { - uint8_t vendor_data_rxch[4]; - int8_t vendor_part_rxch[17]; - - data = 0x1U << args_st[f].devices[(2 * n) + 1].mux_bit; - log_debug(LOG_SERVICE, "Mux set to 0x%02x\r\n", data); - int rmux = apollo_i2c_ctl_w(args_st[f].i2c_dev, args_st[f].devices[(2 * n) + 1].mux_addr, 1, data); - if (rmux != 0) { - log_warn(LOG_SERVICE, "Mux write error %s\r\n", SMBUS_get_error(rmux)); - } - for (uint8_t i = VENDOR_START_BIT_FF12; i < VENDOR_STOP_BIT_FF12; i++) { - uint32_t vendor_char_rxch; - int res = apollo_i2c_ctl_reg_r(args_st[f].i2c_dev, args_st[f].devices[(2 * n) + 1].dev_addr, 1, (uint16_t)i, 1, &vendor_char_rxch); - if (res != 0) { - log_warn(LOG_SERVICE, "GetFFpart read Error %s, break\r\n", SMBUS_get_error(res)); - vendor_part_rxch[i - VENDOR_START_BIT_FF12] = 0; - break; - } - for (int j = 0; j < 4; ++j) { - vendor_data_rxch[j] = (vendor_char_rxch >> (3 - j) * 8) & 0xFF; - } - convert_8_t tmp1; - tmp1.us = vendor_data_rxch[3]; // change from uint_8 to int8_t, preserving bit pattern - vendor_part_rxch[i - VENDOR_START_BIT_FF12] = tmp1.s; - vendor_part_rxch[i - VENDOR_START_BIT_FF12 + 1] = '\0'; // null-terminated - } - - char *vendor_string_rxch = (char *)vendor_part_rxch; - - if ((dev_present_mask[f] & (1 << (2 * n))) == 0) { // check that there is a FF installed in this ch - if (!detect_ff) { - detect_ff = true; - if (strstr(vendor_string_rxch, "14") == NULL && strstr(vendor_string_rxch, "CRRNB") == NULL) { // the first 25Gbs 12-ch detected on FPGA1(2) - tmp_ffpart_bit_mask = tmp_ffpart_bit_mask | (0x1U << n); // bit 1 for a 25Gbs ch and assign to a Bit-mask of Firefly 12-ch part - } - else { - if (f == 0) - ffl12_f1_args.commands = sm_command_fflit_f1; // if the 14Gbsp 12-ch part is found, change the set of commands to sm_command_fflit_f1 - else - ffl12_f2_args.commands = sm_command_fflit_f2; // if the 14Gbsp 12-ch part is found, change the set of commands to sm_command_fflit_f2 - } - log_info(LOG_SERVICE, "Getting Firefly 12-ch part (FPGA%d): %s \r\n:", f + 1, vendor_string_rxch); - strncpy(vendor_string, vendor_string_rxch, nstring); - } - else { - if (strstr(vendor_string_rxch, "14") == NULL && strstr(vendor_string_rxch, "CRRNB") == NULL) { - tmp_ffpart_bit_mask = tmp_ffpart_bit_mask | (0x1U << n); // bit 1 for a 25Gbs ch and assign to a Bit-mask of Firefly 12-ch part - } - else { - if (strncmp(vendor_string_rxch, vendor_string, nstring) != 0) { - log_info(LOG_SERVICE, "Different Firefly 12-ch part(FPGA%d) on %s \r\n:", f + 1, ff_moni2c_addrs[(2 * n) + 1 + ff_ndev_offset[f]].name); - log_info(LOG_SERVICE, "with %s \r\n:", vendor_string_rxch); - } - } - } - } - else { - log_info(LOG_SERVICE, "No Firefly 12-ch part(FPGA%d) on %s \r\n:", f + 1, ff_moni2c_addrs[(2 * n) + 1 + ff_ndev_offset[f]].name); - } - memset(vendor_data_rxch, 0, sizeof(vendor_data_rxch)); - memset(vendor_part_rxch, 0, sizeof(vendor_part_rxch)); - rmux = apollo_i2c_ctl_w(args_st[f].i2c_dev, args_st[f].devices[(2 * n) + 1].mux_addr, 1, 0); - if (rmux != 0) { - log_warn(LOG_SERVICE, "Mux write error %s\r\n", SMBUS_get_error(rmux)); - } - log_debug(LOG_SERVICE, "%s: reset mux\r\n", args_st[f].devices[(2 * n) + 1].name); + uint32_t ff_25gb_parts = 0U; + for (int i = 0; i < NFIREFLIES; ++i) { + if (!isEnabledFF(i)) { // skip the FF if it's not enabled via the FF config + continue; } - - log_debug(LOG_SERVICE, "Bit-mask of Firefly 12-ch part (FPGA%d): 0x%02x \r\n:", f + 1, tmp_ffpart_bit_mask); - log_debug(LOG_SERVICE, "Bit-mask of xmit_3v8_sel(FPGA%d): 0x%02x \r\n:", f + 1, dev_xmit_4v0_sel[f]); - // Warning if 25Gbs found but is connected to 3.3V or Non-25Gbs found but is connected to 3.8V - if ((dev_xmit_4v0_sel[f] ^ tmp_ffpart_bit_mask) != 0U) { - log_warn(LOG_SERVICE, "FPGA%d 12-ch FFs have unmatched xmit_3v8_sel(0x%02x) and 12-ch ff-mask(0x%02x) \r\n", f + 1, dev_xmit_4v0_sel[f], tmp_ffpart_bit_mask); + // skip 4 channel parts + if (FireflyType(i) == DEVICE_25G4) { + continue; } - if (f == 0) - ff_bitmask_args[0].ffpart_bit_mask = tmp_ffpart_bit_mask; - else - ff_bitmask_args[2].ffpart_bit_mask = tmp_ffpart_bit_mask; - - // if we have a semaphore, give it - if (xSemaphoreGetMutexHolder(semaphores[f]) == xTaskGetCurrentTaskHandle()) { - xSemaphoreGive(semaphores[f]); + char name[17]; + memset(name, '\0', 17); + int startReg = VENDOR_START_BIT_FF12; + int count = VENDOR_COUNT_FF12; + int ret = 0; + // build up name of the device (vendor string) + for (unsigned char c = 0; c < count; ++c) { + uint8_t v; + ret += read_arbitrary_ff_register(startReg + c, i, &v, 1); + name[c] = v; + } + if (ret != 0) { + log_error(LOG_SERVICE, "Error reading vendor string for FF %d\r\n", i); + // what to do? FIXME: return error? + } + if (strstr(name, "14") == NULL && + strstr(name, "CRRNB") == NULL && strstr(name, "CERNB") == NULL) { + ff_25gb_parts |= (0x1U << i); } } + return ff_25gb_parts; +} + +// currently this function does the following +// decide which commands to run for the 12 channel part, i.e., +// decide if we have CERN-B or 25 Gbps part on the 12 channel sites +// it then sets the command struct in the MonitorI2CTaskArgs_t struct +// nad also sets a bitmask to show which 12 channel sites have 25 Gbps part +void getFFpart(void) +{ + return; + // // Write device vendor part for identifying FF device + // uint8_t nstring = VENDOR_STOP_BIT_FF12 - VENDOR_START_BIT_FF12 + 1; + // char vendor_string[nstring]; + // uint8_t data; + + // SemaphoreHandle_t semaphores[2] = {i2c4_sem, i2c3_sem}; + // const int ff_ndev_offset[2] = {0, NFIREFLIES_IT_F1 + NFIREFLIES_DAQ_F1}; + // const uint32_t ndevices[2] = {NDEVICES_FFL12_F1 / 2, NDEVICES_FFL12_F2 / 2}; + // const uint32_t dev_present_mask[2] = {present_FFL12_F1, present_FFL12_F2}; + // const uint32_t dev_xmit_4v0_sel[2] = {f1_ff12xmit_4v0_sel, f2_ff12xmit_4v0_sel}; + + // struct MonitorI2CTaskArgs_t args_st[2] = {ffl12_f1_args, ffl12_f2_args}; + + // for (int f = 0; f < 2; ++f) { // loop over FPGAs + + // // grab the semaphore to ensure unique access to I2C controller + // // otherwise, block its operations indefinitely until it's available + // acquireI2CSemaphoreBlock(semaphores[f]); + // uint32_t tmp_ffpart_bit_mask = 0U; + // bool detect_ff = false; + // for (uint32_t n = 0; n < ndevices[f]; n++) { + // uint8_t vendor_data_rxch[4]; + // int8_t vendor_part_rxch[17]; + + // data = 0x1U << args_st[f].devices[(2 * n) + 1].mux_bit; + // log_debug(LOG_SERVICE, "Mux set to 0x%02x\r\n", data); + // int rmux = apollo_i2c_ctl_w(args_st[f].i2c_dev, args_st[f].devices[(2 * n) + 1].mux_addr, 1, data); + // if (rmux != 0) { + // log_warn(LOG_SERVICE, "Mux write error %s\r\n", SMBUS_get_error(rmux)); + // } + // for (uint8_t i = VENDOR_START_BIT_FF12; i < VENDOR_STOP_BIT_FF12; i++) { + // uint32_t vendor_char_rxch; + // int res = apollo_i2c_ctl_reg_r(args_st[f].i2c_dev, args_st[f].devices[(2 * n) + 1].dev_addr, 1, (uint16_t)i, 1, &vendor_char_rxch); + // if (res != 0) { + // log_warn(LOG_SERVICE, "GetFFpart read Error %s, break\r\n", SMBUS_get_error(res)); + // vendor_part_rxch[i - VENDOR_START_BIT_FF12] = 0; + // break; + // } + // for (int j = 0; j < 4; ++j) { + // vendor_data_rxch[j] = (vendor_char_rxch >> (3 - j) * 8) & 0xFF; + // } + // convert_8_t tmp1; + // tmp1.us = vendor_data_rxch[3]; // change from uint_8 to int8_t, preserving bit pattern + // vendor_part_rxch[i - VENDOR_START_BIT_FF12] = tmp1.s; + // vendor_part_rxch[i - VENDOR_START_BIT_FF12 + 1] = '\0'; // null-terminated + // } + + // char *vendor_string_rxch = (char *)vendor_part_rxch; + + // if ((dev_present_mask[f] & (1 << (2 * n))) == 0) { // check that there is a FF installed in this ch + // if (!detect_ff) { + // detect_ff = true; + // if (strstr(vendor_string_rxch, "14") == NULL && strstr(vendor_string_rxch, "CRRNB") == NULL) { // the first 25Gbs 12-ch detected on FPGA1(2) + // tmp_ffpart_bit_mask = tmp_ffpart_bit_mask | (0x1U << n); // bit 1 for a 25Gbs ch and assign to a Bit-mask of Firefly 12-ch part + // } + // else { + // if (f == 0) + // ffl12_f1_args.commands = sm_command_fflit_f1; // if the 14Gbsp 12-ch part is found, change the set of commands to sm_command_fflit_f1 + // else + // ffl12_f2_args.commands = sm_command_fflit_f2; // if the 14Gbsp 12-ch part is found, change the set of commands to sm_command_fflit_f2 + // } + // log_info(LOG_SERVICE, "Getting Firefly 12-ch part (FPGA%d): %s \r\n:", f + 1, vendor_string_rxch); + // strncpy(vendor_string, vendor_string_rxch, nstring); + // } + // else { + // if (strstr(vendor_string_rxch, "14") == NULL && strstr(vendor_string_rxch, "CRRNB") == NULL) { + // tmp_ffpart_bit_mask = tmp_ffpart_bit_mask | (0x1U << n); // bit 1 for a 25Gbs ch and assign to a Bit-mask of Firefly 12-ch part + // } + // else { + // if (strncmp(vendor_string_rxch, vendor_string, nstring) != 0) { + // log_info(LOG_SERVICE, "Different Firefly 12-ch part(FPGA%d) on %s \r\n:", f + 1, ff_moni2c_addrs[(2 * n) + 1 + ff_ndev_offset[f]].name); + // log_info(LOG_SERVICE, "with %s \r\n:", vendor_string_rxch); + // } + // } + // } + // } + // else { + // log_info(LOG_SERVICE, "No Firefly 12-ch part(FPGA%d) on %s \r\n:", f + 1, ff_moni2c_addrs[(2 * n) + 1 + ff_ndev_offset[f]].name); + // } + // memset(vendor_data_rxch, 0, sizeof(vendor_data_rxch)); + // memset(vendor_part_rxch, 0, sizeof(vendor_part_rxch)); + // rmux = apollo_i2c_ctl_w(args_st[f].i2c_dev, args_st[f].devices[(2 * n) + 1].mux_addr, 1, 0); + // if (rmux != 0) { + // log_warn(LOG_SERVICE, "Mux write error %s\r\n", SMBUS_get_error(rmux)); + // } + // log_debug(LOG_SERVICE, "%s: reset mux\r\n", args_st[f].devices[(2 * n) + 1].name); + // } + + // log_debug(LOG_SERVICE, "Bit-mask of Firefly 12-ch part (FPGA%d): 0x%02x \r\n:", f + 1, tmp_ffpart_bit_mask); + // log_debug(LOG_SERVICE, "Bit-mask of xmit_3v8_sel(FPGA%d): 0x%02x \r\n:", f + 1, dev_xmit_4v0_sel[f]); + // // Warning if 25Gbs found but is connected to 3.3V or Non-25Gbs found but is connected to 3.8V + // if ((dev_xmit_4v0_sel[f] ^ tmp_ffpart_bit_mask) != 0U) { + // log_warn(LOG_SERVICE, "FPGA%d 12-ch FFs have unmatched xmit_3v8_sel(0x%02x) and 12-ch ff-mask(0x%02x) \r\n", f + 1, dev_xmit_4v0_sel[f], tmp_ffpart_bit_mask); + // } + + // if (f == 0) + // ff_bitmask_args[0].ffpart_bit_mask = tmp_ffpart_bit_mask; + // else + // ff_bitmask_args[2].ffpart_bit_mask = tmp_ffpart_bit_mask; + + // // if we have a semaphore, give it + // if (xSemaphoreGetMutexHolder(semaphores[f]) == xTaskGetCurrentTaskHandle()) { + // xSemaphoreGive(semaphores[f]); + // } + // } } #endif diff --git a/projects/cm_mcu/FireflyUtils.h b/projects/cm_mcu/FireflyUtils.h index 182d4014..c68296cd 100644 --- a/projects/cm_mcu/FireflyUtils.h +++ b/projects/cm_mcu/FireflyUtils.h @@ -32,14 +32,18 @@ #define CLK_PAGE_COMMAND 1 #define NFIREFLIES (NFIREFLIES_F1 + NFIREFLIES_F2) +// register address of the first and last entry of the +// device identifier in the memory map of the FF devices #define VENDOR_START_BIT_FFDAQ 168 #define VENDOR_STOP_BIT_FFDAQ 184 #define VENDOR_START_BIT_FF12 171 #define VENDOR_STOP_BIT_FF12 187 +#define VENDOR_COUNT_FFDAQ (VENDOR_STOP_BIT_FFDAQ - VENDOR_START_BIT_FFDAQ) +#define VENDOR_COUNT_FF12 (VENDOR_STOP_BIT_FF12 - VENDOR_START_BIT_FF12) struct arg_moni2c_ff_t { char *ff_part; // ff part - struct MonitorI2CTaskArgs_t *arg; // ff arg + struct MonitorTaskI2CArgs_t *arg; // ff arg uint8_t int_idx; // start idx of this arg in ff_moni2c_addrs uint8_t dev_int_idx; // start idx of the device in its arg uint8_t num_dev; // number of devices in this ff arg. @@ -57,7 +61,7 @@ bool isEnabledFF(int ff); void setFFmask(uint32_t ff_combined_mask); void readFFpresent(void); uint16_t getFFtemp(const uint8_t i); -uint16_t getFFavgoptpow(const uint8_t i); +float getFFavgoptpow(const uint8_t i); uint16_t getFFpresentbit(const uint8_t i); #ifdef REV2 void getFFpart(void); @@ -68,6 +72,8 @@ unsigned isFFStale(void); TickType_t getFFupdateTick(int ff_t); void init_registers_ff(void); +uint16_t read_arbitrary_ff_register(uint16_t regnumber, int num_ff, uint8_t *value, uint8_t size); + extern uint32_t ff_PRESENT_mask; extern uint32_t ff_USER_mask; #ifdef REV2 diff --git a/projects/cm_mcu/InitTask.c b/projects/cm_mcu/InitTask.c index 82df59c0..c4c830b2 100644 --- a/projects/cm_mcu/InitTask.c +++ b/projects/cm_mcu/InitTask.c @@ -10,6 +10,7 @@ #include #include +#include "FireflyUtils.h" #include "FreeRTOS.h" #include "FreeRTOSConfig.h" #include "task.h" @@ -20,7 +21,6 @@ #include "common/utils.h" #include "common/log.h" #include "Tasks.h" -#include "MonitorI2CTask.h" #include "Semaphore.h" #include "clocksynth.h" diff --git a/projects/cm_mcu/LocalTasks.c b/projects/cm_mcu/LocalTasks.c index b10b6e90..fca9c068 100644 --- a/projects/cm_mcu/LocalTasks.c +++ b/projects/cm_mcu/LocalTasks.c @@ -15,11 +15,11 @@ #include // struct tm #include "FireflyUtils.h" +#include "MonitorTaskI2C_new.h" #include "driverlib/hibernate.h" #include "Tasks.h" #include "MonitorTask.h" -#include "MonitorI2CTask.h" #include "InterruptHandlers.h" #include "Semaphore.h" @@ -66,7 +66,36 @@ struct dev_moni2c_addr_t ff_moni2c_addrs[NFIREFLIES] = { {"V12 12 Tx GTY", FF_I2CMUX_2_ADDR, 4, 0x50}, // {"V12 12 Rx GTY", FF_I2CMUX_2_ADDR, 5, 0x54}, // }; - +struct dev_moni2c_addr_t ff_moni2c_addrs_f1[NFIREFLIES_F1] = { + {"K01 12 Tx GTH", FF_I2CMUX_1_ADDR, 0, 0x50}, // + {"K01 12 Rx GTH", FF_I2CMUX_1_ADDR, 1, 0x54}, // + {"K02 12 Tx GTH", FF_I2CMUX_1_ADDR, 2, 0x50}, // + {"K02 12 Rx GTH", FF_I2CMUX_1_ADDR, 3, 0x54}, // + {"K03 12 Tx GTH", FF_I2CMUX_1_ADDR, 4, 0x50}, // + {"K03 12 Rx GTH", FF_I2CMUX_1_ADDR, 5, 0x54}, // + {"K04 4 XCVR GTY", FF_I2CMUX_2_ADDR, 0, 0x50}, // + {"K05 4 XCVR GTY", FF_I2CMUX_2_ADDR, 1, 0x50}, // + {"K06 4 XCVR GTY", FF_I2CMUX_2_ADDR, 2, 0x50}, // + {"K07 12 Tx GTY", FF_I2CMUX_2_ADDR, 3, 0x50}, // + {"K07 12 Rx GTY", FF_I2CMUX_2_ADDR, 4, 0x54}, // +}; +struct dev_moni2c_addr_t ff_moni2c_addrs_f2[NFIREFLIES_F2] = { + {"V01 4 XCVR GTY", FF_I2CMUX_1_ADDR, 0, 0x50}, // + {"V02 4 XCVR GTY", FF_I2CMUX_1_ADDR, 1, 0x50}, // + {"V03 4 XCVR GTY", FF_I2CMUX_1_ADDR, 2, 0x50}, // + {"V04 4 XCVR GTY", FF_I2CMUX_1_ADDR, 3, 0x50}, // + {"V05 4 XCVR GTY", FF_I2CMUX_1_ADDR, 4, 0x50}, // + {"V06 4 XCVR GTY", FF_I2CMUX_1_ADDR, 5, 0x50}, // + {"V07 4 XCVR GTY", FF_I2CMUX_2_ADDR, 0, 0x50}, // + {"V08 4 XCVR GTY", FF_I2CMUX_2_ADDR, 1, 0x50}, // + {"V09 4 XCVR GTY", FF_I2CMUX_2_ADDR, 2, 0x50}, // + {"V10 4 XCVR GTY", FF_I2CMUX_2_ADDR, 3, 0x50}, // + {"V11 12 Tx GTY", FF_I2CMUX_1_ADDR, 6, 0x50}, // + {"V11 12 Rx GTY", FF_I2CMUX_1_ADDR, 7, 0x54}, // + {"V12 12 Tx GTY", FF_I2CMUX_2_ADDR, 4, 0x50}, // + {"V12 12 Rx GTY", FF_I2CMUX_2_ADDR, 5, 0x54}, // +}; +#if 0 struct arg_moni2c_ff_t ff_moni2c_arg[NFIREFLY_ARG] = { {"FFL12", &ffl12_f1_args, 0, 0, 6}, // {"FFL4", &ffl4_f1_args, 6, 0, 3}, // @@ -74,7 +103,7 @@ struct arg_moni2c_ff_t ff_moni2c_arg[NFIREFLY_ARG] = { {"FFL4", &ffl4_f2_args, 11, 0, 10}, // {"FFL12", &ffl12_f2_args, 21, 0, 4}, // }; - +#endif // 0 #elif defined(REV2) // ------------------------------------------------- // @@ -130,12 +159,14 @@ struct dev_moni2c_addr_t ff_moni2c_addrs_f2[NFIREFLIES_F2] = { }; +#if 0 struct arg_moni2c_ff_t ff_moni2c_arg[NFIREFLY_ARG] = { {"FFL12", &ffl12_f1_args, 0, 0, 6}, // {"FFL4", &ffl4_f1_args, 6, 0, 4}, // {"FFL12", &ffl12_f2_args, 10, 0, 6}, // {"FFL4", &ffl4_f2_args, 16, 0, 4}, // }; +#endif // 0 #else #error "Define either Rev1 or Rev2" #endif @@ -147,17 +178,18 @@ struct dev_moni2c_addr_t ffl4_f1_moni2c_addrs[NFIREFLIES_DAQ_F1] = { {"K05 4 XCVR GTY", FF_I2CMUX_2_ADDR, 1, 0x50}, // {"K06 4 XCVR GTY", FF_I2CMUX_2_ADDR, 2, 0x50}, // }; -#elif defined(REV2) -struct dev_moni2c_addr_t ffl4_f1_moni2c_addrs[NFIREFLIES_DAQ_F1] = { - {"F1_4 4 XCVR", FF_I2CMUX_1_ADDR, 2, 0x50}, // - {"F1_5 4 XCVR", FF_I2CMUX_2_ADDR, 0, 0x50}, // - {"F1_6 4 XCVR", FF_I2CMUX_2_ADDR, 1, 0x50}, // - {"F1_7 4 XCVR", FF_I2CMUX_2_ADDR, 2, 0x50}, // -}; -#else -#error "Define either Rev1 or Rev2" +// #elif defined(REV2) +// struct dev_moni2c_addr_t ffl4_f1_moni2c_addrs[NFIREFLIES_DAQ_F1] = { +// {"F1_4 4 XCVR", FF_I2CMUX_1_ADDR, 2, 0x50}, // +// {"F1_5 4 XCVR", FF_I2CMUX_2_ADDR, 0, 0x50}, // +// {"F1_6 4 XCVR", FF_I2CMUX_2_ADDR, 1, 0x50}, // +// {"F1_7 4 XCVR", FF_I2CMUX_2_ADDR, 2, 0x50}, // +// }; +// #else +// #error "Define either Rev1 or Rev2" #endif +#if 0 struct sm_command_t sm_command_ffl4_f1[] = { {1, 0x00, 0x02, 2, "FF_STATUS_REG", 0xff, "", PM_STATUS}, {1, 0x00, 0x16, 2, "FF_TEMPERATURE", 0xff, "C", PM_STATUS}, @@ -234,7 +266,7 @@ struct sm_command_t sm_command_fflot_f1[] = { {2, 0x01, 0xce, 2, "FF_CH12_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, }; - +#endif // 0 #ifdef REV1 struct dev_moni2c_addr_t ffl12_f1_moni2c_addrs[NFIREFLIES_IT_F1] = { {"K01 12 Tx GTH", FF_I2CMUX_1_ADDR, 0, 0x50}, // @@ -258,7 +290,7 @@ struct dev_moni2c_addr_t ffl12_f1_moni2c_addrs[NFIREFLIES_IT_F1] = { #else #error "Define either Rev1 or Rev2" #endif - +#if 0 uint16_t ffl12_f1_values[NDEVICES_FFL12_F1 * NCOMMANDS_FFL12_F1]; struct MonitorI2CTaskArgs_t ffl12_f1_args = { @@ -277,7 +309,7 @@ struct MonitorI2CTaskArgs_t ffl12_f1_args = { .xSem = NULL, .stack_size = 4096U, }; - +#endif // 0 // FFDAQV arguments for monitoring i2c task of 4-channel firefly ports connected to FPGA2 #ifdef REV1 struct dev_moni2c_addr_t ffl4_f2_moni2c_addrs[NFIREFLIES_DAQ_F2] = { @@ -292,90 +324,90 @@ struct dev_moni2c_addr_t ffl4_f2_moni2c_addrs[NFIREFLIES_DAQ_F2] = { {"V09 4 XCVR GTY", FF_I2CMUX_2_ADDR, 2, 0x50}, // {"V10 4 XCVR GTY", FF_I2CMUX_2_ADDR, 3, 0x50}, // }; -#elif defined(REV2) -struct dev_moni2c_addr_t ffl4_f2_moni2c_addrs[NFIREFLIES_DAQ_F2] = { - {"F2_4 4 XCVR", FF_I2CMUX_1_ADDR, 2, 0x50}, // - {"F2_5 4 XCVR", FF_I2CMUX_2_ADDR, 0, 0x50}, // - {"F2_6 4 XCVR", FF_I2CMUX_2_ADDR, 1, 0x50}, // - {"F2_7 4 XCVR", FF_I2CMUX_2_ADDR, 2, 0x50}, // -}; -#else -#error "Define either Rev1 or Rev2" +// #elif defined(REV2) +// struct dev_moni2c_addr_t ffl4_f2_moni2c_addrs[NFIREFLIES_DAQ_F2] = { +// {"F2_4 4 XCVR", FF_I2CMUX_1_ADDR, 2, 0x50}, // +// {"F2_5 4 XCVR", FF_I2CMUX_2_ADDR, 0, 0x50}, // +// {"F2_6 4 XCVR", FF_I2CMUX_2_ADDR, 1, 0x50}, // +// {"F2_7 4 XCVR", FF_I2CMUX_2_ADDR, 2, 0x50}, // +// }; +// #else +// #error "Define either Rev1 or Rev2" #endif -struct sm_command_t sm_command_ffl4_f2[] = { - {1, 0x00, 0x02, 2, "FF_STATUS_REG", 0xff, "", PM_STATUS}, - {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, 2, "FF_CH01_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, // read 4 Rx-ch registers with increasing addresses - {2, 0x00, 0x24, 2, "FF_CH02_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, - {2, 0x00, 0x26, 2, "FF_CH03_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, - {2, 0x00, 0x28, 2, "FF_CH04_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, -}; -uint16_t ffl4_f2_values[NDEVICES_FFL4_F2 * NCOMMANDS_FFL4_F2]; - -struct MonitorI2CTaskArgs_t ffl4_f2_args = { - .name = "F2_4", - .devices = ffl4_f2_moni2c_addrs, - .i2c_dev = I2C_DEVICE_F2, - .n_devices = NDEVICES_FFL4_F2, - .commands = sm_command_ffl4_f2, - .n_commands = NCOMMANDS_FFL4_F2, - .n_values = NDEVICES_FFL4_F2 * NPAGES_FFL4_F2 * NCOMMANDS_FFL4_F2, - .n_pages = NPAGES_FFL4_F2, - .selpage_reg = FF_SELPAGE_REG, - .sm_values = ffl4_f2_values, - // .smbus = &g_sMaster3, - // .smbus_status = &eStatus3, - .xSem = NULL, - .stack_size = 4096U, -}; - -// FF12V arguments for monitoring i2c task of 12-channel firefly ports connected to FPGA2 - -// register maps for IT-DTC Fireflies 12-ch part -- future will be CERN-B but currently is 14Gbps ECUO -struct sm_command_t sm_command_fflit_f2[] = { - {1, 0x00, 0x02, 2, "FF_STATUS_REG", 0xff, "", PM_STATUS}, - {1, 0x00, 0x16, 2, "FF_TEMPERATURE", 0xff, "C", PM_STATUS}, - {2, 0x00, 0x07, 2, "FF_LOS_ALARM", 0xffff, "", PM_STATUS}, - {2, 0x00, 0x14, 2, "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, "0.1uW", PM_STATUS}, - {1, 0x00, 0x00, 1, "FF_CH02_OPT_POW", 0xff, "0.1uW", PM_STATUS}, - {1, 0x00, 0x00, 1, "FF_CH03_OPT_POW", 0xff, "0.1uW", PM_STATUS}, - {1, 0x00, 0x00, 1, "FF_CH04_OPT_POW", 0xff, "0.1uW", PM_STATUS}, - {1, 0x00, 0x00, 1, "FF_CH05_OPT_POW", 0xff, "0.1uW", PM_STATUS}, - {1, 0x00, 0x00, 1, "FF_CH06_OPT_POW", 0xff, "0.1uW", PM_STATUS}, - {1, 0x00, 0x00, 1, "FF_CH07_OPT_POW", 0xff, "0.1uW", PM_STATUS}, - {1, 0x00, 0x00, 1, "FF_CH08_OPT_POW", 0xff, "0.1uW", PM_STATUS}, - {1, 0x00, 0x00, 1, "FF_CH09_OPT_POW", 0xff, "0.1uW", PM_STATUS}, - {1, 0x00, 0x00, 1, "FF_CH10_OPT_POW", 0xff, "0.1uW", PM_STATUS}, - {1, 0x00, 0x00, 1, "FF_CH11_OPT_POW", 0xff, "0.1uW", PM_STATUS}, - {1, 0x00, 0x00, 1, "FF_CH12_OPT_POW", 0xff, "0.1uW", 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** -struct sm_command_t sm_command_fflot_f2[] = { - {1, 0x00, 0x02, 2, "FF_STATUS_REG", 0xff, "", PM_STATUS}, - {1, 0x00, 0x16, 2, "FF_TEMPERATURE", 0xff, "C", PM_STATUS}, - {2, 0x00, 0x07, 2, "FF_LOS_ALARM", 0xffff, "", PM_STATUS}, - {2, 0x00, 0x14, 2, "FF_CDR_LOL_ALARM", 0xffff, "", PM_STATUS}, - {2, 0x01, 0xe4, 2, "FF_CH01_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, // read 12 Rx-ch registers with decreasing addresses - {2, 0x01, 0xe2, 2, "FF_CH02_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, - {2, 0x01, 0xe0, 2, "FF_CH03_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, - {2, 0x01, 0xde, 2, "FF_CH04_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, - {2, 0x01, 0xdc, 2, "FF_CH05_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, - {2, 0x01, 0xda, 2, "FF_CH06_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, - {2, 0x01, 0xd8, 2, "FF_CH07_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, - {2, 0x01, 0xd6, 2, "FF_CH08_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, - {2, 0x01, 0xd4, 2, "FF_CH09_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, - {2, 0x01, 0xd2, 2, "FF_CH10_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, - {2, 0x01, 0xd0, 2, "FF_CH11_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, - {2, 0x01, 0xce, 2, "FF_CH12_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, -}; +// struct sm_command_t sm_command_ffl4_f2[] = { +// {1, 0x00, 0x02, 2, "FF_STATUS_REG", 0xff, "", PM_STATUS}, +// {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, 2, "FF_CH01_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, // read 4 Rx-ch registers with increasing addresses +// {2, 0x00, 0x24, 2, "FF_CH02_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, +// {2, 0x00, 0x26, 2, "FF_CH03_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, +// {2, 0x00, 0x28, 2, "FF_CH04_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, +// }; +// uint16_t ffl4_f2_values[NDEVICES_FFL4_F2 * NCOMMANDS_FFL4_F2]; + +// struct MonitorI2CTaskArgs_t ffl4_f2_args = { +// .name = "F2_4", +// .devices = ffl4_f2_moni2c_addrs, +// .i2c_dev = I2C_DEVICE_F2, +// .n_devices = NDEVICES_FFL4_F2, +// .commands = sm_command_ffl4_f2, +// .n_commands = NCOMMANDS_FFL4_F2, +// .n_values = NDEVICES_FFL4_F2 * NPAGES_FFL4_F2 * NCOMMANDS_FFL4_F2, +// .n_pages = NPAGES_FFL4_F2, +// .selpage_reg = FF_SELPAGE_REG, +// .sm_values = ffl4_f2_values, +// // .smbus = &g_sMaster3, +// // .smbus_status = &eStatus3, +// .xSem = NULL, +// .stack_size = 4096U, +// }; + +// // FF12V arguments for monitoring i2c task of 12-channel firefly ports connected to FPGA2 + +// // register maps for IT-DTC Fireflies 12-ch part -- future will be CERN-B but currently is 14Gbps ECUO +// struct sm_command_t sm_command_fflit_f2[] = { +// {1, 0x00, 0x02, 2, "FF_STATUS_REG", 0xff, "", PM_STATUS}, +// {1, 0x00, 0x16, 2, "FF_TEMPERATURE", 0xff, "C", PM_STATUS}, +// {2, 0x00, 0x07, 2, "FF_LOS_ALARM", 0xffff, "", PM_STATUS}, +// {2, 0x00, 0x14, 2, "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, "0.1uW", PM_STATUS}, +// {1, 0x00, 0x00, 1, "FF_CH02_OPT_POW", 0xff, "0.1uW", PM_STATUS}, +// {1, 0x00, 0x00, 1, "FF_CH03_OPT_POW", 0xff, "0.1uW", PM_STATUS}, +// {1, 0x00, 0x00, 1, "FF_CH04_OPT_POW", 0xff, "0.1uW", PM_STATUS}, +// {1, 0x00, 0x00, 1, "FF_CH05_OPT_POW", 0xff, "0.1uW", PM_STATUS}, +// {1, 0x00, 0x00, 1, "FF_CH06_OPT_POW", 0xff, "0.1uW", PM_STATUS}, +// {1, 0x00, 0x00, 1, "FF_CH07_OPT_POW", 0xff, "0.1uW", PM_STATUS}, +// {1, 0x00, 0x00, 1, "FF_CH08_OPT_POW", 0xff, "0.1uW", PM_STATUS}, +// {1, 0x00, 0x00, 1, "FF_CH09_OPT_POW", 0xff, "0.1uW", PM_STATUS}, +// {1, 0x00, 0x00, 1, "FF_CH10_OPT_POW", 0xff, "0.1uW", PM_STATUS}, +// {1, 0x00, 0x00, 1, "FF_CH11_OPT_POW", 0xff, "0.1uW", PM_STATUS}, +// {1, 0x00, 0x00, 1, "FF_CH12_OPT_POW", 0xff, "0.1uW", 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** +// struct sm_command_t sm_command_fflot_f2[] = { +// {1, 0x00, 0x02, 2, "FF_STATUS_REG", 0xff, "", PM_STATUS}, +// {1, 0x00, 0x16, 2, "FF_TEMPERATURE", 0xff, "C", PM_STATUS}, +// {2, 0x00, 0x07, 2, "FF_LOS_ALARM", 0xffff, "", PM_STATUS}, +// {2, 0x00, 0x14, 2, "FF_CDR_LOL_ALARM", 0xffff, "", PM_STATUS}, +// {2, 0x01, 0xe4, 2, "FF_CH01_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, // read 12 Rx-ch registers with decreasing addresses +// {2, 0x01, 0xe2, 2, "FF_CH02_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, +// {2, 0x01, 0xe0, 2, "FF_CH03_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, +// {2, 0x01, 0xde, 2, "FF_CH04_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, +// {2, 0x01, 0xdc, 2, "FF_CH05_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, +// {2, 0x01, 0xda, 2, "FF_CH06_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, +// {2, 0x01, 0xd8, 2, "FF_CH07_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, +// {2, 0x01, 0xd6, 2, "FF_CH08_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, +// {2, 0x01, 0xd4, 2, "FF_CH09_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, +// {2, 0x01, 0xd2, 2, "FF_CH10_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, +// {2, 0x01, 0xd0, 2, "FF_CH11_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, +// {2, 0x01, 0xce, 2, "FF_CH12_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, +// }; #ifdef REV1 struct dev_moni2c_addr_t ffl12_f2_moni2c_addrs[NFIREFLIES_IT_F2] = { @@ -397,24 +429,24 @@ struct dev_moni2c_addr_t ffl12_f2_moni2c_addrs[NFIREFLIES_IT_F2] = { #error "Define either Rev1 or Rev2" #endif -uint16_t ffl12_f2_values[NDEVICES_FFL12_F2 * NCOMMANDS_FFL12_F2]; - -struct MonitorI2CTaskArgs_t ffl12_f2_args = { - .name = "F2_12", - .devices = ffl12_f2_moni2c_addrs, - .i2c_dev = I2C_DEVICE_F2, - .n_devices = NDEVICES_FFL12_F2, - .commands = sm_command_fflot_f2, // 25Gbps by default but if the 14Gbsp 12-ch part is found, the set of commands is changed in INIT task - .n_commands = NCOMMANDS_FFL12_F2, - .n_values = NDEVICES_FFL12_F2 * NPAGES_FFL12_F2 * NCOMMANDS_FFL12_F2, - .n_pages = NPAGES_FFL12_F2, - .selpage_reg = FF_SELPAGE_REG, - .sm_values = ffl12_f2_values, - // .smbus = &g_sMaster3, - // .smbus_status = &eStatus3, - .xSem = NULL, - .stack_size = 4096U, -}; +// uint16_t ffl12_f2_values[NDEVICES_FFL12_F2 * NCOMMANDS_FFL12_F2]; + +// struct MonitorI2CTaskArgs_t ffl12_f2_args = { +// .name = "F2_12", +// .devices = ffl12_f2_moni2c_addrs, +// .i2c_dev = I2C_DEVICE_F2, +// .n_devices = NDEVICES_FFL12_F2, +// .commands = sm_command_fflot_f2, // 25Gbps by default but if the 14Gbsp 12-ch part is found, the set of commands is changed in INIT task +// .n_commands = NCOMMANDS_FFL12_F2, +// .n_values = NDEVICES_FFL12_F2 * NPAGES_FFL12_F2 * NCOMMANDS_FFL12_F2, +// .n_pages = NPAGES_FFL12_F2, +// .selpage_reg = FF_SELPAGE_REG, +// .sm_values = ffl12_f2_values, +// // .smbus = &g_sMaster3, +// // .smbus_status = &eStatus3, +// .xSem = NULL, +// .stack_size = 4096U, +// }; #ifdef REV2 // Clock arguments for monitoring task @@ -427,426 +459,86 @@ struct clk_program_t clkprog_args[] = { {"", ""}, // }; -struct dev_moni2c_addr_t clk_moni2c_addrs[CLOCK_NUM_SI5395] = { +// struct dev_moni2c_addr_t clk_moni2c_addrs[CLOCK_NUM_SI5395] = { +// {"r0b", 0x70, 1, 0x6b, 0x264E}, // CLK R0B : Si5395-REVA #regs = 587 (read at 0x1F7D in EEPROM) if change, addr 0x264E will have to change +// {"r1a", 0x70, 2, 0x6b, 0x464E}, // CLK R1A : Si5395-REVA #regs = 587 (read at 0x5F7D in EEPROM) if change, addr 0x464E will have to change +// {"r1b", 0x70, 3, 0x6b, 0x664E}, // CLK R1B : Si5395-REVA #regs = 584 (read at 0x7F7D in EEPROM) if change, addr 0x664E will have to change +// {"r1c", 0x70, 4, 0x6b, 0x864E}, // CLK R1C : Si5395-REVA #regs = 587 (read at 0x9F7D in EEPROM) if change, addr 0x864E will have to change +// }; +struct dev_moni2c_addr_t clk_moni2c_addrs[NDEVICES_CLK] = { + {"r0a", 0x70, 0, 0x77, 0x45D}, // CLK R0A : Si5341-REVD with #regs = 378 (read at 0x1F7D in EEPROM) if change, addr 0x45D will have to change {"r0b", 0x70, 1, 0x6b, 0x264E}, // CLK R0B : Si5395-REVA #regs = 587 (read at 0x1F7D in EEPROM) if change, addr 0x264E will have to change {"r1a", 0x70, 2, 0x6b, 0x464E}, // CLK R1A : Si5395-REVA #regs = 587 (read at 0x5F7D in EEPROM) if change, addr 0x464E will have to change {"r1b", 0x70, 3, 0x6b, 0x664E}, // CLK R1B : Si5395-REVA #regs = 584 (read at 0x7F7D in EEPROM) if change, addr 0x664E will have to change {"r1c", 0x70, 4, 0x6b, 0x864E}, // CLK R1C : Si5395-REVA #regs = 587 (read at 0x9F7D in EEPROM) if change, addr 0x864E will have to change }; -struct sm_command_t sm_command_clk[NCOMMANDS_CLK_TMP] = { - // device information on page 0 : table 16.2 and 16.4 - {1, 0x00, 0x02, 2, "PN_BASE", 0xffff, "", PM_STATUS}, // page 0x00 - {1, 0x00, 0x05, 1, "DEVICE_REV", 0xff, "", PM_STATUS}, // page 0x00 - {1, 0x00, 0x0B, 1, "I2C_ADDR", 0x7f, "", PM_STATUS}, // page 0x00 - // internal statuses on page 0 : table 16.8 and 16.9 - {1, 0x00, 0x0C, 1, "LOSXAXB", 0x02, "", PM_STATUS}, // page 0x00 - {1, 0x00, 0x0D, 1, "LOSOOF_IN", 0xff, "", PM_STATUS}, // page 0x00 - {1, 0x00, 0x0E, 1, "LOL", 0x02, "", PM_STATUS}, // page 0x00 - // internal error flags : table 16.12 - {1, 0x00, 0x11, 1, "STICKY_FLG", 0x27, "", PM_STATUS}, // page 0x00 -}; - -uint16_t clk_values[NDEVICES_CLK * NPAGES_CLK * NCOMMANDS_CLK_TMP]; - -struct MonitorI2CTaskArgs_t clock_args = { - .name = "CLKSI", - .devices = clk_moni2c_addrs, - .i2c_dev = I2C_DEVICE_CLK, - .n_devices = NDEVICES_CLK, - .commands = sm_command_clk, - .n_commands = NCOMMANDS_CLK_TMP, - .n_values = NDEVICES_CLK * NPAGES_CLK * NCOMMANDS_CLK_TMP, - .n_pages = NPAGES_CLK, - .selpage_reg = CLK_SELPAGE_REG, - .sm_values = clk_values, - .xSem = NULL, - .stack_size = 4096U, -}; - -struct dev_moni2c_addr_t clkr0a_moni2c_addrs[CLOCK_NUM_SI5341] = { - {"r0a", 0x70, 0, 0x77, 0x45D}, // CLK R0A : Si5341-REVD with #regs = 378 (read at 0x1F7D in EEPROM) if change, addr 0x45D will have to change -}; - -struct sm_command_t sm_command_clkr0a[] = { - // device information on page 0 : table 14.4 and 14.6 - {1, 0x00, 0x02, 2, "PN_BASE", 0xffff, "", PM_STATUS}, // page 0x00 - {1, 0x00, 0x05, 1, "DEVICE_REV", 0xff, "", PM_STATUS}, // page 0x00 - {1, 0x00, 0x0B, 1, "I2C_ADDR", 0xff, "", PM_STATUS}, // page 0x00 - // internal statuses on page 0 : table 14.5 - {1, 0x00, 0x0C, 1, "STATUS", 0x35, "", PM_STATUS}, // page 0x00 - {1, 0x00, 0x0D, 1, "LOS", 0x15, "", PM_STATUS}, // page 0x00 - // sticky bits of status bits : table 14.12 - {1, 0x00, 0x12, 1, "LOSIN_FLG", 0xf, "", PM_STATUS}, // page 0x00 - // sticky bits of status bits : table 14.12 - {1, 0x00, 0x11, 1, "STICKY_FLG", 0x2f, "", PM_STATUS}, // page 0x00 -}; - -uint16_t clkr0a_values[NDEVICES_CLKR0A * NPAGES_CLKR0A * NCOMMANDS_CLK_TMPR0A]; - -struct MonitorI2CTaskArgs_t clockr0a_args = { - .name = "CLKR0A", - .devices = clkr0a_moni2c_addrs, - .i2c_dev = I2C_DEVICE_CLK, - .n_devices = NDEVICES_CLKR0A, - .commands = sm_command_clkr0a, - .n_commands = NCOMMANDS_CLK_TMPR0A, - .n_values = NDEVICES_CLKR0A * NPAGES_CLKR0A * NCOMMANDS_CLK_TMPR0A, - .n_pages = NPAGES_CLKR0A, - .selpage_reg = CLK_SELPAGE_REG, - .sm_values = clkr0a_values, - .xSem = NULL, - .stack_size = 4096U, -}; +// struct sm_command_t sm_command_clk[NCOMMANDS_CLK_TMP] = { +// // device information on page 0 : table 16.2 and 16.4 +// {1, 0x00, 0x02, 2, "PN_BASE", 0xffff, "", PM_STATUS}, // page 0x00 +// {1, 0x00, 0x05, 1, "DEVICE_REV", 0xff, "", PM_STATUS}, // page 0x00 +// {1, 0x00, 0x0B, 1, "I2C_ADDR", 0x7f, "", PM_STATUS}, // page 0x00 +// // internal statuses on page 0 : table 16.8 and 16.9 +// {1, 0x00, 0x0C, 1, "LOSXAXB", 0x02, "", PM_STATUS}, // page 0x00 +// {1, 0x00, 0x0D, 1, "LOSOOF_IN", 0xff, "", PM_STATUS}, // page 0x00 +// {1, 0x00, 0x0E, 1, "LOL", 0x02, "", PM_STATUS}, // page 0x00 +// // internal error flags : table 16.12 +// {1, 0x00, 0x11, 1, "STICKY_FLG", 0x27, "", PM_STATUS}, // page 0x00 +// }; + +// uint16_t clk_values[NDEVICES_CLK * NPAGES_CLK * NCOMMANDS_CLK_TMP]; + +// struct MonitorI2CTaskArgs_t clock_args = { +// .name = "CLKSI", +// .devices = clk_moni2c_addrs, +// .i2c_dev = I2C_DEVICE_CLK, +// .n_devices = NDEVICES_CLK, +// .commands = sm_command_clk, +// .n_commands = NCOMMANDS_CLK_TMP, +// .n_values = NDEVICES_CLK * NPAGES_CLK * NCOMMANDS_CLK_TMP, +// .n_pages = NPAGES_CLK, +// .selpage_reg = CLK_SELPAGE_REG, +// .sm_values = clk_values, +// .xSem = NULL, +// .stack_size = 4096U, +// }; + +// struct dev_moni2c_addr_t clkr0a_moni2c_addrs[CLOCK_NUM_SI5341] = { +// {"r0a", 0x70, 0, 0x77, 0x45D}, // CLK R0A : Si5341-REVD with #regs = 378 (read at 0x1F7D in EEPROM) if change, addr 0x45D will have to change +// }; + +// struct sm_command_t sm_command_clkr0a[] = { +// // device information on page 0 : table 14.4 and 14.6 +// {1, 0x00, 0x02, 2, "PN_BASE", 0xffff, "", PM_STATUS}, // page 0x00 +// {1, 0x00, 0x05, 1, "DEVICE_REV", 0xff, "", PM_STATUS}, // page 0x00 +// {1, 0x00, 0x0B, 1, "I2C_ADDR", 0xff, "", PM_STATUS}, // page 0x00 +// // internal statuses on page 0 : table 14.5 +// {1, 0x00, 0x0C, 1, "STATUS", 0x35, "", PM_STATUS}, // page 0x00 +// {1, 0x00, 0x0D, 1, "LOS", 0x15, "", PM_STATUS}, // page 0x00 +// // sticky bits of status bits : table 14.12 +// {1, 0x00, 0x12, 1, "LOSIN_FLG", 0xf, "", PM_STATUS}, // page 0x00 +// // sticky bits of status bits : table 14.12 +// {1, 0x00, 0x11, 1, "STICKY_FLG", 0x2f, "", PM_STATUS}, // page 0x00 +// }; + +// uint16_t clkr0a_values[NDEVICES_CLKR0A * NPAGES_CLKR0A * NCOMMANDS_CLK_TMPR0A]; + +// struct MonitorI2CTaskArgs_t clockr0a_args = { +// .name = "CLKR0A", +// .devices = clkr0a_moni2c_addrs, +// .i2c_dev = I2C_DEVICE_CLK, +// .n_devices = NDEVICES_CLKR0A, +// .commands = sm_command_clkr0a, +// .n_commands = NCOMMANDS_CLK_TMPR0A, +// .n_values = NDEVICES_CLKR0A * NPAGES_CLKR0A * NCOMMANDS_CLK_TMPR0A, +// .n_pages = NPAGES_CLKR0A, +// .selpage_reg = CLK_SELPAGE_REG, +// .sm_values = clkr0a_values, +// .xSem = NULL, +// .stack_size = 4096U, +// }; #endif // REV2 -#if 0 -void setFFmask(uint32_t ff_combined_present) -{ - - log_info(LOG_SERVICE, "Setting a bit mask of enabled Fireflys to 1 \r\n"); - - // int32_t data = (~ff_combined_present) & 0xFFFFFU; // the bit value for an FF mask is an inverted bit value of the PRESENT signals -#ifdef REV1 - uint32_t data = (~ff_combined_present) & 0x1FFFFFFU; -#elif defined(REV2) - uint32_t data = (~ff_combined_present) & 0xFFFFFU; -#endif // REV1 - ff_USER_mask = read_eeprom_single(EEPROM_ID_FF_ADDR); - ff_PRESENT_mask = data; - uint64_t block = EEPROMBlockFromAddr(ADDR_FF); - - uint64_t unlock = EPRMMessage((uint64_t)EPRM_UNLOCK_BLOCK, block, PASS); - xQueueSendToBack(xEPRMQueue_in, &unlock, portMAX_DELAY); - - uint64_t message = EPRMMessage((uint64_t)EPRM_WRITE_SINGLE, ADDR_FF, data); - xQueueSendToBack(xEPRMQueue_in, &message, portMAX_DELAY); - - uint64_t lock = EPRMMessage((uint64_t)EPRM_LOCK_BLOCK, block << 32, 0); - xQueueSendToBack(xEPRMQueue_in, &lock, portMAX_DELAY); - - return; -} - -void readFFpresent(void) -{ - // grab the semaphore to ensure unique access to I2C controller - // otherwise, block its operations indefinitely until it's available - acquireI2CSemaphoreBlock(i2c4_sem); - -#ifdef REV1 - // to port 7 - apollo_i2c_ctl_w(4, 0x70, 1, 0x80); - apollo_i2c_ctl_reg_r(4, 0x20, 1, 0x01, 1, &present_FFL12_F1); - // to port 6 - apollo_i2c_ctl_w(4, 0x71, 1, 0x40); - apollo_i2c_ctl_reg_r(4, 0x21, 1, 0x00, 1, &present_FFL4_F1); -#elif defined(REV2) - // to port 7 - apollo_i2c_ctl_w(4, 0x70, 1, 0x80); - apollo_i2c_ctl_reg_r(4, 0x20, 1, 0x01, 1, &present_FFL12_F1); - // to port 6 - apollo_i2c_ctl_w(4, 0x71, 1, 0x40); - apollo_i2c_ctl_reg_r(4, 0x21, 1, 0x00, 1, &present_FFL4_F1); - apollo_i2c_ctl_reg_r(4, 0x21, 1, 0x01, 1, &f1_ff12xmit_4v0_sel); // reading FPGA1 12-ch xmit FF's power-supply physical selection (i.e either 3.3v or 4.0v) -#endif - - // if we have a semaphore, give it - if (xSemaphoreGetMutexHolder(i2c4_sem) == xTaskGetCurrentTaskHandle()) { - xSemaphoreGive(i2c4_sem); - } - - // grab the semaphore to ensure unique access to I2C controller - // otherwise, block its operations indefinitely until it's available - acquireI2CSemaphoreBlock(i2c3_sem); - -#ifdef REV1 - // to port 0 - apollo_i2c_ctl_w(3, 0x72, 1, 0x01); - apollo_i2c_ctl_reg_r(3, 0x20, 1, 0x01, 1, &present_0X20_F2); - // to port 1 - apollo_i2c_ctl_w(3, 0x72, 1, 0x02); - apollo_i2c_ctl_reg_r(3, 0x21, 1, 0x01, 1, &present_0X21_F2); -#elif defined(REV2) - // to port 7 - apollo_i2c_ctl_w(3, 0x70, 1, 0x80); - apollo_i2c_ctl_reg_r(3, 0x20, 1, 0x01, 1, &present_FFL12_F2); - // to port 6 - apollo_i2c_ctl_w(3, 0x71, 1, 0x40); - apollo_i2c_ctl_reg_r(3, 0x21, 1, 0x00, 1, &present_FFL4_F2); - apollo_i2c_ctl_reg_r(3, 0x21, 1, 0x01, 1, &f2_ff12xmit_4v0_sel); // reading FPGA2 12-ch xmit FF's power-supply physical selection (i.e either 3.3v or 4.0v) - -#endif - // if we have a semaphore, give it - if (xSemaphoreGetMutexHolder(i2c3_sem) == xTaskGetCurrentTaskHandle()) { - xSemaphoreGive(i2c3_sem); - } - -#ifdef REV1 - uint32_t present_FFL12_BOTTOM_F1 = present_FFL12_F1 & 0x3FU; // bottom 6 bits - uint32_t present_FFL12_TOP_F1 = (present_FFL12_F1 >> 6) & 0x3U; // top 2 bits - present_FFL4_F1 = (present_FFL4_F1 >> 5) & 0x7U; // bits 5-7 - present_FFL12_0X20_F2 = (present_0X20_F2 >> 6) & 0x3U; // bit 6-7 - present_FFL4_0X20_F2 = present_0X20_F2 & 0x3FU; // bottom 6 bits - present_FFL12_0X21_F2 = (present_0X21_F2 >> 4) & 0x3U; // bit 4-5 - present_FFL4_0X21_F2 = (present_0X21_F2 >> 2) & 0xFU; // bit 4 bits - - uint32_t ff_combined_present = ((present_FFL12_0X21_F2) << 23) | // 2 bits - ((present_FFL12_0X20_F2) << 21) | // 2 bits - ((present_FFL4_0X21_F2) << 17) | // 4 bits - ((present_FFL4_0X20_F2) << 11) | // 6 bits - ((present_FFL12_TOP_F1) << 9) | // 2 bits - (present_FFL4_F1) << 6 | // 3 bits - ((present_FFL12_BOTTOM_F1)); // 6 bits - -#elif defined(REV2) - present_FFL12_F1 = present_FFL12_F1 & 0x3FU; // bottom 6 bits - present_FFL12_F2 = present_FFL12_F2 & 0x3FU; // bottom 6 bits - present_FFL4_F1 = (present_FFL4_F1 >> 4) & 0xFU; // bits 4-7 - present_FFL4_F2 = (present_FFL4_F2 >> 4) & 0xFU; // bits 4-7 - - uint32_t ff_combined_present = ((present_FFL4_F2) << 16) | // 4 bits - ((present_FFL12_F2) << 10) | // 6 bits - (present_FFL4_F1) << 6 | // 4 bits - ((present_FFL12_F1)); // 6 bits - - ff_bitmask_args[1].present_bit_mask = (~present_FFL4_F1) & 0xFU; // 4 bits - ff_bitmask_args[0].present_bit_mask = (~present_FFL12_F1) & 0x3FU; // 6 bits - ff_bitmask_args[3].present_bit_mask = (~present_FFL4_F2) & 0xFU; // 4 bits - ff_bitmask_args[2].present_bit_mask = (~present_FFL12_F2) & 0x3FU; // 6 bits - - f1_ff12xmit_4v0_sel = (f1_ff12xmit_4v0_sel >> 4) & 0x7; // bits 4-6 - f2_ff12xmit_4v0_sel = (f2_ff12xmit_4v0_sel >> 4) & 0x7; // bits 4-6 -#endif - - setFFmask(ff_combined_present); -} - -bool isEnabledFF(int ff) -{ - // firefly config stored in on-board EEPROM via user input - // and firefly config via PRESENT signals at the first boot - // must be true for a firefly to be enabled. - if (!((1 << ff) & ff_PRESENT_mask) || !((1 << ff) & ff_USER_mask)) { - return false; - } - else { - return true; - } -} - -unsigned isFFStale(void) -{ - TickType_t now = pdTICKS_TO_S(xTaskGetTickCount()); - TickType_t last[4]; - last[0] = pdTICKS_TO_S(ffl12_f1_args.updateTick); - last[1] = pdTICKS_TO_S(ffl4_f1_args.updateTick); - last[2] = pdTICKS_TO_S(ffl12_f2_args.updateTick); - last[3] = pdTICKS_TO_S(ffl4_f2_args.updateTick); - - unsigned mask = 0U; - for (int ff_t = 0; ff_t < 4; ++ff_t) { - if (checkStale(last[ff_t], now)) { - mask |= (1U << ff_t); - } - } - - return mask; // bits set for stale tasks. no bits set == not stale. -} - -// this will return the tick of the _lowest_ set bit. -TickType_t getFFupdateTick(int mask) -{ - log_debug(LOG_SERVICE, "mask = %x\r\n", mask); - if (__builtin_popcount(mask) == 0) { - log_warn(LOG_SERVICE, "empty mask\r\n"); - } - if (mask & 0x1U) { - return ffl12_f1_args.updateTick; - } - else if (mask & 0x02U) { - return ffl4_f1_args.updateTick; - } - else if (mask & 0x04U) { - return ffl12_f2_args.updateTick; - } - else { - return ffl4_f2_args.updateTick; - } -} - -uint16_t getFFtemp(const uint8_t i) -{ - int i1 = 1; - int8_t val; - configASSERT(i < NFIREFLIES); - if (i < NFIREFLIES_IT_F1) { - int index = i * (ffl12_f1_args.n_commands * ffl12_f1_args.n_pages) + i1; - val = ffl12_f1_args.sm_values[index]; - } - - else if (NFIREFLIES_IT_F1 <= i && i < NFIREFLIES_IT_F1 + NFIREFLIES_DAQ_F1) { - int index = (i - NFIREFLIES_IT_F1) * (ffl4_f1_args.n_commands * ffl4_f1_args.n_pages) + i1; - val = ffl4_f1_args.sm_values[index]; - } - - else if (NFIREFLIES_F1 <= i && i < NFIREFLIES_F1 + NFIREFLIES_IT_F2) { - int index = (i - NFIREFLIES_F1) * (ffl12_f2_args.n_commands * ffl12_f2_args.n_pages) + i1; - val = ffl12_f2_args.sm_values[index]; - } - else { - int index = (i - NFIREFLIES_F1 - NFIREFLIES_IT_F2) * (ffl4_f2_args.n_commands * ffl4_f2_args.n_pages) + i1; - val = ffl4_f2_args.sm_values[index]; - } - - return val; -} - -#ifdef REV2 -uint16_t getFFavgoptpow(const uint8_t i) -{ - - uint16_t avg_val = 0; - uint16_t sum_val = 0; - configASSERT(i < NFIREFLIES); - - for (int n = 0; n < 4; ++n) { - if (ff_moni2c_arg[n].int_idx <= i && i < ff_moni2c_arg[n].int_idx + ff_moni2c_arg[n].num_dev) { - for (int i1 = 4; i1 < ff_moni2c_arg[n].arg->n_commands; ++i1) { - int dev = i - ff_moni2c_arg[n].int_idx + ff_moni2c_arg[n].dev_int_idx; - int index = dev * (ff_moni2c_arg[n].arg->n_commands * ff_moni2c_arg[n].arg->n_pages) + i1; - sum_val += ff_moni2c_arg[n].arg->sm_values[index]; - } - avg_val = sum_val / (ff_moni2c_arg[n].arg->n_commands - 4); - } - } - - return avg_val; -} - -uint16_t getFFpresentbit(const uint8_t i) -{ - if (i > 3) { - log_warn(LOG_SERVICE, "caught %d > total fireflies %d\r\n", i, NFIREFLIES); - return 56; - } - uint16_t val = ff_bitmask_args[i].present_bit_mask; - - return val; -} - -void getFFpart(void) -{ - // Write device vendor part for identifying FF device - uint8_t nstring = VENDOR_STOP_BIT_FF12 - VENDOR_START_BIT_FF12 + 1; - char vendor_string[nstring]; - uint8_t data; - - SemaphoreHandle_t semaphores[2] = {i2c4_sem, i2c3_sem}; - const int ff_ndev_offset[2] = {0, NFIREFLIES_IT_F1 + NFIREFLIES_DAQ_F1}; - const uint32_t ndevices[2] = {NDEVICES_FFL12_F1 / 2, NDEVICES_FFL12_F2 / 2}; - const uint32_t dev_present_mask[2] = {present_FFL12_F1, present_FFL12_F2}; - const uint32_t dev_xmit_4v0_sel[2] = {f1_ff12xmit_4v0_sel, f2_ff12xmit_4v0_sel}; - - struct MonitorI2CTaskArgs_t args_st[2] = {ffl12_f1_args, ffl12_f2_args}; - - for (int f = 0; f < 2; ++f) { - - // grab the semaphore to ensure unique access to I2C controller - // otherwise, block its operations indefinitely until it's available - acquireI2CSemaphoreBlock(semaphores[f]); - uint32_t tmp_ffpart_bit_mask = 0U; - bool detect_ff = false; - for (uint8_t n = 0; n < ndevices[f]; n++) { - uint8_t vendor_data_rxch[4]; - int8_t vendor_part_rxch[17]; - - data = 0x1U << args_st[f].devices[(2 * n) + 1].mux_bit; - log_debug(LOG_SERVICE, "Mux set to 0x%02x\r\n", data); - int rmux = apollo_i2c_ctl_w(args_st[f].i2c_dev, args_st[f].devices[(2 * n) + 1].mux_addr, 1, data); - if (rmux != 0) { - log_warn(LOG_SERVICE, "Mux write error %s\r\n", SMBUS_get_error(rmux)); - } - for (uint8_t i = VENDOR_START_BIT_FF12; i < VENDOR_STOP_BIT_FF12; i++) { - uint32_t vendor_char_rxch; - int res = apollo_i2c_ctl_reg_r(args_st[f].i2c_dev, args_st[f].devices[(2 * n) + 1].dev_addr, 1, (uint16_t)i, 1, &vendor_char_rxch); - if (res != 0) { - log_warn(LOG_SERVICE, "GetFFpart read Error %s, break\r\n", SMBUS_get_error(res)); - vendor_part_rxch[i - VENDOR_START_BIT_FF12] = 0; - break; - } - for (int j = 0; j < 4; ++j) { - vendor_data_rxch[j] = (vendor_char_rxch >> (3 - j) * 8) & 0xFF; - } - - convert_8_t tmp1; - tmp1.us = vendor_data_rxch[3]; // change from uint_8 to int8_t, preserving bit pattern - vendor_part_rxch[i - VENDOR_START_BIT_FF12] = tmp1.s; - vendor_part_rxch[i - VENDOR_START_BIT_FF12 + 1] = '\0'; // null-terminated - } - - char *vendor_string_rxch = (char *)vendor_part_rxch; - - if ((dev_present_mask[f] & (1 << (2 * n))) == 0) { // check that there is a FF installed in this ch - if (!detect_ff) { - detect_ff = true; - if (strstr(vendor_string_rxch, "14") == NULL && strstr(vendor_string_rxch, "CRRNB") == NULL) { // the first 25Gbs 12-ch detected on FPGA1(2) - tmp_ffpart_bit_mask = tmp_ffpart_bit_mask | (0x1U << n); // bit 1 for a 25Gbs ch and assign to a Bit-mask of Firefly 12-ch part - } - else { - if (f == 0) - ffl12_f1_args.commands = sm_command_fflit_f1; // if the 14Gbsp 12-ch part is found, change the set of commands to sm_command_fflit_f1 - else - ffl12_f2_args.commands = sm_command_fflit_f2; // if the 14Gbsp 12-ch part is found, change the set of commands to sm_command_fflit_f2 - } - log_info(LOG_SERVICE, "Getting Firefly 12-ch part (FPGA%d): %s \r\n:", f + 1, vendor_string_rxch); - strncpy(vendor_string, vendor_string_rxch, nstring); - } - else { - if (strstr(vendor_string_rxch, "14") == NULL && strstr(vendor_string_rxch, "CRRNB") == NULL) { - tmp_ffpart_bit_mask = tmp_ffpart_bit_mask | (0x1U << n); // bit 1 for a 25Gbs ch and assign to a Bit-mask of Firefly 12-ch part - } - else { - if (strncmp(vendor_string_rxch, vendor_string, nstring) != 0) { - log_info(LOG_SERVICE, "Different Firefly 12-ch part(FPGA%d) on %s \r\n:", f + 1, ff_moni2c_addrs[(2 * n) + 1 + ff_ndev_offset[f]].name); - log_info(LOG_SERVICE, "with %s \r\n:", vendor_string_rxch); - } - } - } - } - else { - log_info(LOG_SERVICE, "No Firefly 12-ch part(FPGA%d) on %s \r\n:", f + 1, ff_moni2c_addrs[(2 * n) + 1 + ff_ndev_offset[f]].name); - } - memset(vendor_data_rxch, 0, sizeof(vendor_data_rxch)); - memset(vendor_part_rxch, 0, sizeof(vendor_part_rxch)); - rmux = apollo_i2c_ctl_w(args_st[f].i2c_dev, args_st[f].devices[(2 * n) + 1].mux_addr, 1, 0); - if (rmux != 0) { - log_warn(LOG_SERVICE, "Mux write error %s\r\n", SMBUS_get_error(rmux)); - } - log_debug(LOG_SERVICE, "%s: reset mux\r\n", args_st[f].devices[(2 * n) + 1].name); - } - - log_debug(LOG_SERVICE, "Bit-mask of Firefly 12-ch part (FPGA%d): 0x%02x \r\n:", f + 1, tmp_ffpart_bit_mask); - log_debug(LOG_SERVICE, "Bit-mask of xmit_3v8_sel(FPGA%d): 0x%02x \r\n:", f + 1, dev_xmit_4v0_sel[f]); - // Warning if 25Gbs found but is connected to 3.3V or Non-25Gbs found but is connected to 3.8V - if ((dev_xmit_4v0_sel[f] ^ tmp_ffpart_bit_mask) != 0U) { - log_warn(LOG_SERVICE, "FPGA%d 12-ch FFs have unmatched xmit_3v8_sel(0x%02x) and 12-ch ff-mask(0x%02x) \r\n", f + 1, dev_xmit_4v0_sel[f], tmp_ffpart_bit_mask); - } - - if (f == 0) - ff_bitmask_args[0].ffpart_bit_mask = tmp_ffpart_bit_mask; - else - ff_bitmask_args[2].ffpart_bit_mask = tmp_ffpart_bit_mask; - - // if we have a semaphore, give it - if (xSemaphoreGetMutexHolder(semaphores[f]) == xTaskGetCurrentTaskHandle()) { - xSemaphoreGive(semaphores[f]); - } - } -} -#endif -#endif - #define FPGA_MON_NDEVICES_PER_FPGA 2 #define FPGA_MON_NFPGA 2 #define FPGA_MON_NDEVICES 8 diff --git a/projects/cm_mcu/Makefile b/projects/cm_mcu/Makefile index 73161f8b..c16245b9 100644 --- a/projects/cm_mcu/Makefile +++ b/projects/cm_mcu/Makefile @@ -165,7 +165,6 @@ ${COMPILER}/cm_mcu.axf: ${COMPILER}/PowerSupplyTask.o ${COMPILER}/cm_mcu.axf: ${COMPILER}/ADCMonitorTask.o ${COMPILER}/cm_mcu.axf: ${COMPILER}/MonitorTask.o ${COMPILER}/cm_mcu.axf: ${COMPILER}/MonitorTaskI2C_new.o -${COMPILER}/cm_mcu.axf: ${COMPILER}/MonitorI2CTask.o ${COMPILER}/cm_mcu.axf: ${COMPILER}/I2CSlaveTask.o ${COMPILER}/cm_mcu.axf: ${COMPILER}/GenericAlarmTask.o ${COMPILER}/cm_mcu.axf: ${COMPILER}/AlarmUtilities.o diff --git a/projects/cm_mcu/MonUtils.c b/projects/cm_mcu/MonUtils.c index f187e28b..556f2d0c 100644 --- a/projects/cm_mcu/MonUtils.c +++ b/projects/cm_mcu/MonUtils.c @@ -1,10 +1,10 @@ -#include "MonitorI2CTask.h" #include "MonitorTaskI2C_new.h" #include "MonI2C_addresses.h" #include "FireflyUtils.h" #include "Tasks.h" #include "MonUtils.h" +#ifdef REV2 // for 12 channel parts, there is one Tx and Rx device. // for 4 channel parts, there is one XCVR part int FireflyType(int device) @@ -31,7 +31,6 @@ int FireflyType(int device) } } -#ifdef REV2 // For rev2 clocks there is one 5341 and 4 5395s int ClockType(int device) { diff --git a/projects/cm_mcu/MonUtils.h b/projects/cm_mcu/MonUtils.h index 08e15fd9..2368ac1e 100644 --- a/projects/cm_mcu/MonUtils.h +++ b/projects/cm_mcu/MonUtils.h @@ -4,10 +4,14 @@ #include "MonitorTaskI2C_new.h" int FireflyType(int device); +int ClockType(int device); // firefly monitoring extern struct MonitorI2CTaskArgs_new_t ff_f1_args; extern struct MonitorI2CTaskArgs_new_t ff_f2_args; // clock monitoring extern struct MonitorI2CTaskArgs_new_t clk_args; + +extern struct dev_moni2c_addr_t clk_moni2c_addrs[NDEVICES_CLK]; + #endif // MONUTILS_H diff --git a/projects/cm_mcu/MonitorI2CTask.c b/projects/cm_mcu/MonitorI2CTask.c deleted file mode 100644 index 82e0c5e8..00000000 --- a/projects/cm_mcu/MonitorI2CTask.c +++ /dev/null @@ -1,222 +0,0 @@ -/* - * MonitorI2CTask.c - * - * Created on: June 30, 2022 - * Author: pkotamnives - * Monitor temperatures, and statuses of firefly ports via I2C BUS - * pass in addresses via parameter to the task. - */ - -// includes for types -#include -#include -#include -#include - -// FreeRTOS -#include "FreeRTOS.h" // IWYU pragma: keep -#include "FreeRTOSConfig.h" -#include "task.h" - -// local includes -#include "common/smbus_helper.h" -#include "MonitorI2CTask.h" -#include "common/log.h" -#include "Tasks.h" -#include "I2CCommunication.h" -#include "Semaphore.h" - -// local prototype - -// read-only accessor functions for Firefly names and values. - -bool getFFch_low(uint8_t val, int channel) -{ - configASSERT(channel < 8); - if (!((1 << channel) & val)) { - return false; - } - return true; -} - -bool getFFch_high(uint8_t val, int channel) -{ - configASSERT(channel >= 8); - if (!((1 << (channel - 8)) & val)) { - return false; - } - return true; -} - -// Monitor registers of FF temperatures, voltages, currents, and ClK statuses via I2C -void MonitorI2CTask(void *parameters) -{ - - struct MonitorI2CTaskArgs_t *args = parameters; - - configASSERT(args->name != 0); - - // watchdog info - task_watchdog_register_task(kWatchdogTaskID_MonitorI2CTask); - - // wait for the power to come up - vTaskDelayUntil(&(args->updateTick), pdMS_TO_TICKS(5000)); - - int IsCLK = (strstr(args->name, "CLK") != NULL); // the instance is of CLK-device type - int IsFF12 = (strstr(args->name, "_12") != NULL); // the instance is of FF 12-ch part type - int IsFFDAQ = (strstr(args->name, "_4") != NULL); // the instance is of FF 4-ch part type - - // initialize to the current tick time - args->updateTick = xTaskGetTickCount(); - - bool good = false; - for (;;) { - - log_debug(LOG_MONI2C, "%s: grab sem\r\n", args->name); - - // grab the semaphore to ensure unique access to I2C controller - if (args->xSem != NULL) { - if (acquireI2CSemaphore(args->xSem) == pdFAIL) { - log_debug(LOG_SERVICE, "%s could'nt get sem; delay & continue\r\n", args->name); - vTaskDelayUntil(&(args->updateTick), pdMS_TO_TICKS(10)); // wait - continue; - } - } - - // ------------------------------- - // loop over devices in the device-type instance - // ------------------------------- - for (int device = 0; device < args->n_devices; ++device) { - log_debug(LOG_MONI2C, "%s: device %d powercheck\r\n", args->name, device); - - if (getPowerControlState() != POWER_ON) { - if (good) { - log_info(LOG_MONI2C, "%s: PWR off. Disable I2Cmon.\r\n", args->name); - good = false; - task_watchdog_unregister_task(kWatchdogTaskID_MonitorI2CTask); - } - if (xSemaphoreGetMutexHolder(args->xSem) == xTaskGetCurrentTaskHandle()) { - xSemaphoreGive(args->xSem); - } - break; - } - else if (getPowerControlState() == POWER_ON) { // power is on, and ... - if (!good) { // ... was not good, but is now good - task_watchdog_register_task(kWatchdogTaskID_MonitorI2CTask); - log_info(LOG_MONI2C, "%s: PWR on. (Re)start I2Cmon.\r\n", args->name); - good = true; - } - } - - // for firefly devices, skip if FF is not enabled - if (!IsCLK) { // Fireflies need to be checked if the links are connected or not - if (args->i2c_dev == I2C_DEVICE_F1) { // FPGA #1 -#ifdef REV1 - int NFIREFLIES_IT_F1_P1 = NFIREFLIES_IT_F1 - 2; - if (!isEnabledFF((IsFFDAQ * (device + NFIREFLIES_IT_F1_P1)) + (IsFF12 * (device < NFIREFLIES_IT_F1 - 3) * (device)) + (IsFF12 * (device > NFIREFLIES_IT_F1 - 3) * (device + NFIREFLIES_DAQ_F1)))) // skip the FF if it's not enabled via the FF config - continue; -#elif defined(REV2) - if (!isEnabledFF((IsFFDAQ * (device + NFIREFLIES_IT_F1)) + (IsFF12 * (device)))) // skip the FF if it's not enabled via the FF config - continue; -#else -#error "Define either Rev1 or Rev2" -#endif - } - if (args->i2c_dev == I2C_DEVICE_F2) { // FPGA #2 -#ifdef REV1 - if (!isEnabledFF(NFIREFLIES_F1 + (IsFFDAQ * (device)) + (IsFF12 * (device + NFIREFLIES_DAQ_F2)))) // skip the FF if it's not enabled via the FF config - continue; -#elif defined(REV2) - if (!isEnabledFF(NFIREFLIES_F1 + (IsFFDAQ * (device + NFIREFLIES_IT_F2)) + (IsFF12 * (device)))) // skip the FF if it's not enabled via the FF config - continue; -#else -#error "Define either Rev1 or Rev2" -#endif - } - } - - // for firefly devices, check the reset pin - if (!IsCLK) { - // mux setting - int result = apollo_i2c_ctl_w(args->i2c_dev, 0x71, 1, 0x40); - if (result) { - log_warn(LOG_MONI2C, "mux err %d\r\n", result); - break; - } - uint32_t val; - // reading reset-FF pin - int res = apollo_i2c_ctl_reg_r(args->i2c_dev, 0x21, 1, 0x3, 1, &val); - if (res) { - log_warn(LOG_MONI2C, "%s read reset-FF pin failed %d\r\n", args->name, res); - break; - } - if ((val & 0x1) != 0x1) { - log_warn(LOG_MONI2C, "%s reset-FF pin is down \r\n", args->name); - break; - } - } - - // select the appropriate output for the mux - uint8_t data; - data = 0x1U << args->devices[device].mux_bit; - log_debug(LOG_MONI2C, "Mux set to 0x%02x\r\n", data); - int res = apollo_i2c_ctl_w(args->i2c_dev, args->devices[device].mux_addr, 1, data); - if (res != 0) { - log_warn(LOG_MONI2C, "Mux write error %s, break (instance=%s,ps=%d)\r\n", SMBUS_get_error(res), args->name, device); - break; - } - - // Read I2C registers/commands - for (int c = 0; c < args->n_commands; ++c) { - - int index = device * (args->n_commands * args->n_pages) + c; - - log_debug(LOG_MONI2C, "%s: reg %s\r\n", args->name, args->commands[c].name); - uint8_t page_reg_value = args->commands[c].page; - int r = apollo_i2c_ctl_reg_w(args->i2c_dev, args->devices[device].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[device].name, SMBUS_get_error(r)); - break; - } - - uint32_t output_raw; - int res = apollo_i2c_ctl_reg_r(args->i2c_dev, args->devices[device].dev_addr, args->commands[c].reg_size, - args->commands[c].command, args->commands[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[c].name, SMBUS_get_error(res), device); - args->sm_values[index] = 0xffff; - break; - } - else { - uint16_t masked_output = output_raw & args->commands[c].bit_mask; - args->sm_values[index] = masked_output; - } - - } // loop over commands - - log_debug(LOG_MONI2C, "%s: end loop commands\r\n", args->name); - args->updateTick = xTaskGetTickCount(); // current time in ticks - - res = apollo_i2c_ctl_w(args->i2c_dev, args->devices[device].mux_addr, 1, 0); - if (res != 0) { - log_warn(LOG_MONI2C, "Mux write error %s, break (instance=%s,ps=%d)\r\n", SMBUS_get_error(res), args->name, device); - break; - } - log_debug(LOG_MONI2C, "%s: reset mux\r\n", args->name); - - } // loop over devices - - // if we have a semaphore, give it - if (xSemaphoreGetMutexHolder(args->xSem) == xTaskGetCurrentTaskHandle()) { - xSemaphoreGive(args->xSem); - } - - // monitor stack usage for this task - CHECK_TASK_STACK_USAGE(args->stack_size); - - // task_watchdog_feed_task(kWatchdogTaskID_MonitorI2CTask); - vTaskDelayUntil(&(args->updateTick), pdMS_TO_TICKS(250)); - } // infinite loop for task -} diff --git a/projects/cm_mcu/MonitorI2CTask.h b/projects/cm_mcu/MonitorI2CTask.h deleted file mode 100644 index 59fee628..00000000 --- a/projects/cm_mcu/MonitorI2CTask.h +++ /dev/null @@ -1,99 +0,0 @@ -/* - * MonitorI2CTask.h - * - * Created on: June 30, 2022 - * Author: pkotamnives - */ - -#ifndef PROJECTS_CM_MCU_MONITORI2CTASK_H_ -#define PROJECTS_CM_MCU_MONITORI2CTASK_H_ - -#include "FreeRTOS.h" // IWYU pragma: keep -#include "semphr.h" -#include "Tasks.h" -#include "FireflyUtils.h" - -struct sm_command_t { - int reg_size; // number of bytes of register/command - unsigned char page; // I2C page address - unsigned char command; // I2c register address - int size; // number of bytes to read - char *name; // text describing command - uint16_t bit_mask; // begin bit mask - char *units; // units for pretty printing - enum pm_type type; // how to decode command (L11 or bitfield or ...) -}; - -struct MonitorI2CTaskArgs_t { - const char *name; // name to be assigned to the task - struct dev_moni2c_addr_t *devices; // list of devices to query - int i2c_dev; // i2c controller # - int n_devices; // number of devices - struct sm_command_t *commands; // list of commands - const uint8_t n_commands; // number of commands - const int n_values; // number of results - const uint8_t n_pages; // number of pages to loop over - const uint16_t selpage_reg; // register for selecting page - uint16_t *sm_values; - TickType_t updateTick; // last update time, in ticks - SemaphoreHandle_t xSem; // semaphore for controlling access to device - UBaseType_t stack_size; // stack size of task -}; - -#define FF_SELPAGE_REG 0x7f -#define CLK_SELPAGE_REG 0x1 - -#ifndef REV2 -#define NDEVICES_FFL4_F1 (3) -#else // REV2 -#define NDEVICES_FFL4_F1 (4) -#endif // REV 2 -#define NCOMMANDS_FFL4_F1 8 // number of commands -#define NPAGES_FFL4_F1 1 // number of pages on the 4-channel firefly ports - -#ifndef REV2 -#define NDEVICES_FFL12_F1 (8) -#else // REV1 -#define NDEVICES_FFL12_F1 (6) -#endif // REV 2 -#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 NDEVICES_FFL4_F2 (10) -#else // REV1 -#define NDEVICES_FFL4_F2 (4) -#endif // REV 2 -#define NCOMMANDS_FFL4_F2 8 // number of commands -#define NPAGES_FFL4_F2 1 // number of pages on the 4-channel firefly ports - -#ifndef REV2 -#define NDEVICES_FFL12_F2 (4) -#else // REV1 -#define NDEVICES_FFL12_F2 (6) -#endif // REV 2 -#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]; -extern struct dev_moni2c_addr_t ffl4_f1_moni2c_addrs[NFIREFLIES_DAQ_F1]; -extern struct dev_moni2c_addr_t ffl12_f2_moni2c_addrs[NFIREFLIES_IT_F2]; -extern struct dev_moni2c_addr_t ffl4_f2_moni2c_addrs[NFIREFLIES_DAQ_F2]; -extern struct MonitorI2CTaskArgs_t ffl12_f1_args; -extern struct MonitorI2CTaskArgs_t ffl4_f1_args; -extern struct MonitorI2CTaskArgs_t ffl12_f2_args; -extern struct MonitorI2CTaskArgs_t ffl4_f2_args; - -#define NDEVICES_CLK (4) -// #define NCOMMANDS_CLK 7 // number of commands -#define NCOMMANDS_FLG_CLK 1 // number of sticky commands -#define NPAGES_CLK 1 // -#define NDEVICES_CLKR0A (1) -// #define NCOMMANDS_CLKR0A 7 // number of commands -#define NCOMMANDS_FLG_CLKR0A 2 // number of sticky commands -#define NPAGES_CLKR0A 1 // - -extern struct MonitorI2CTaskArgs_t clock_args; -extern struct MonitorI2CTaskArgs_t clockr0a_args; - -#endif /* PROJECTS_CM_MCU_MONITORI2CTASK_H_ */ diff --git a/projects/cm_mcu/MonitorTaskI2C_new.c b/projects/cm_mcu/MonitorTaskI2C_new.c index 8a8d413f..4c08fabf 100644 --- a/projects/cm_mcu/MonitorTaskI2C_new.c +++ b/projects/cm_mcu/MonitorTaskI2C_new.c @@ -29,7 +29,7 @@ // local prototype // read-only accessor functions for Firefly names and values. -#if 0 + bool getFFch_low(uint8_t val, int channel) { configASSERT(channel < 8); @@ -47,7 +47,6 @@ bool getFFch_high(uint8_t val, int channel) } return true; } -#endif // Monitor registers of FF temperatures, voltages, currents, and ClK statuses via I2C void MonitorI2CTask_new(void *parameters) diff --git a/projects/cm_mcu/MonitorTaskI2C_new.h b/projects/cm_mcu/MonitorTaskI2C_new.h index bd1bf697..b9474187 100644 --- a/projects/cm_mcu/MonitorTaskI2C_new.h +++ b/projects/cm_mcu/MonitorTaskI2C_new.h @@ -21,6 +21,7 @@ struct i2c_reg_command_t { enum pm_type type; // how to decode command (L11 or bitfield or ...) uint16_t (*devicelist)(void); void (*storeData)(uint16_t data, int which); // store data in location which + uint16_t (*retrieveData)(int which); // retrieve data from location which }; // how to find an I2C device, with a mux infront of it. @@ -43,6 +44,11 @@ struct MonitorI2CTaskArgs_new_t { MonTaskI2CTypeFcnPointer typeCallback; // callback for type check }; +#define FF_SELPAGE_REG 0x7f +#define CLK_SELPAGE_REG 0x1 + +#define NDEVICES_CLK 5 + // for autogenerated code #define DEVICE_CERNB 0x01 #define DEVICE_14G 0x02 @@ -53,4 +59,6 @@ struct MonitorI2CTaskArgs_new_t { #define DEVICE_NONE 0x80 +extern struct dev_moni2c_addr_t clk_moni2c_addrs[NDEVICES_CLK]; + #endif /* PROJECTS_CM_MCU_MONITORI2CTASKNEW_H_ */ diff --git a/projects/cm_mcu/PowerSupplyTask.c b/projects/cm_mcu/PowerSupplyTask.c index d2906033..39eb4a3e 100644 --- a/projects/cm_mcu/PowerSupplyTask.c +++ b/projects/cm_mcu/PowerSupplyTask.c @@ -12,6 +12,7 @@ #include // local includes +#include "FireflyUtils.h" #include "Tasks.h" #include "common/i2c_reg.h" #include "common/pinout.h" @@ -25,9 +26,6 @@ #include "FreeRTOSConfig.h" #include "queue.h" -// getFFpart includes -#include "MonitorI2CTask.h" - void Print(const char *); // Holds the handle of the created queue for the power supply task. diff --git a/projects/cm_mcu/Tasks.h b/projects/cm_mcu/Tasks.h index c0e7711b..608ae0eb 100644 --- a/projects/cm_mcu/Tasks.h +++ b/projects/cm_mcu/Tasks.h @@ -303,8 +303,8 @@ int init_registers_clk(void); #define CLOCK_NUM_SI5341 1 #define CLOCK_NUM_SI5395 4 -extern struct dev_moni2c_addr_t clkr0a_moni2c_addrs[CLOCK_NUM_SI5341]; -extern struct dev_moni2c_addr_t clk_moni2c_addrs[CLOCK_NUM_SI5395]; +// extern struct dev_moni2c_addr_t clkr0a_moni2c_addrs[CLOCK_NUM_SI5341]; +// extern struct dev_moni2c_addr_t clk_moni2c_addrs[NDEVICES_CLK]; // configuring clock initalization int init_load_clk(int clk_n); diff --git a/projects/cm_mcu/ZynqMonTask.c b/projects/cm_mcu/ZynqMonTask.c index 9a9db462..1be720dd 100644 --- a/projects/cm_mcu/ZynqMonTask.c +++ b/projects/cm_mcu/ZynqMonTask.c @@ -14,6 +14,8 @@ #include // to be moved +#include "FireflyUtils.h" +#include "MonUtils.h" #include "inc/hw_memmap.h" #include "driverlib/rom.h" @@ -26,7 +28,6 @@ #include "Tasks.h" #include "MonitorTask.h" -#include "MonitorI2CTask.h" #include "clocksynth.h" #include "common/log.h" @@ -427,8 +428,8 @@ void zm_set_firefly_info(struct zynqmon_data_t data[], int start) data[ll].data.us = 0xff; // special stale value } else { - data[ll].data.us = getFFavgoptpow(j); // sensor value and type - log_debug(LOG_SERVICE, "opt power ? for ff %d: 0x%02x\r\n", j, getFFavgoptpow(j)); + data[ll].data.us = (uint16_t)getFFavgoptpow(j); // sensor value and type + log_debug(LOG_SERVICE, "opt power ? for ff %d: 0x%02x\r\n", j, data[ll].data.us); } data[ll].sensor = ll + start; ++ll; @@ -530,29 +531,24 @@ void zm_set_clock(struct zynqmon_data_t data[], int start, int n) // MonitorI2CTask values -- clock chips // update times, in seconds. If the data is stale, send NaN // n=1 is r0a and n=0 is else - struct MonitorI2CTaskArgs_t args_st[2] = {clockr0a_args, clock_args}; + // struct MonitorI2CTaskArgs_t args_st[2] = {clockr0a_args, clock_args}; - TickType_t last = pdTICKS_TO_S(args_st[n].updateTick); + TickType_t last = pdTICKS_TO_S(clk_args.updateTick); TickType_t now = pdTICKS_TO_S(xTaskGetTickCount()); bool stale = checkStale(last, now); int ll = 0; - for (int j = 0; j < args_st[n].n_devices; ++j) { // loop over supplies - for (int l = 0; l < args_st[n].n_pages; ++l) { // loop over register pages - for (int k = 0; k < args_st[n].n_commands; ++k) { // loop over clock commands FIXME : don't send sticky-bit ones - int index = - (j * args_st[n].n_commands * args_st[n].n_pages) + k; - - if (stale) { - data[ll].data.us = 56; // special stale value - } - else { - data[ll].data.us = args_st[n].sm_values[index]; - } - data[ll].sensor = ll + start; - ++ll; + for (int j = 0; j < clk_args.n_devices; ++j) { // loop over supplies + for (int k = 0; k < clk_args.n_commands; ++k) { + if (stale) { + data[ll].data.us = 56; // special stale value + } + else { + data[ll].data.us = clk_args.commands[j].retrieveData(j); } + data[ll].sensor = ll + start; + ++ll; } } } diff --git a/projects/cm_mcu/clocksynth.c b/projects/cm_mcu/clocksynth.c index 86631bd7..94b97032 100644 --- a/projects/cm_mcu/clocksynth.c +++ b/projects/cm_mcu/clocksynth.c @@ -7,16 +7,21 @@ #include #include +#include "MonitorTaskI2C_new.h" #include "common/smbus_helper.h" -#include "Semaphore.h" #include "clocksynth.h" -#include "common/utils.h" #include "I2CCommunication.h" -#include "MonitorI2CTask.h" #include "Tasks.h" #ifdef REV2 +#define SYN_NDEVICES_CLK 4 +#define SYN_NDEVICES_CLKR0A (1) +#define NCOMMANDS_FLG_CLK 1 // number of sticky commands +#define NCOMMANDS_FLG_CLKR0A 2 // number of sticky commands + +extern struct dev_moni2c_addr_t clk_moni2c_addrs[NDEVICES_CLK]; + // must grab and release the semaphore in a larger scope when calling this function int clear_clk_stickybits(void) { @@ -28,38 +33,25 @@ int clear_clk_stickybits(void) return 1; } - int status = -99; - - const uint8_t nsupplies[2] = {NDEVICES_CLKR0A, NDEVICES_CLK}; - const uint8_t ncommands[2] = {NCOMMANDS_FLG_CLKR0A, NCOMMANDS_FLG_CLK}; - const uint8_t dev_addr[2] = {CLOCK_SYNTH5341_I2C_ADDRESS, CLOCK_SYNTH5395_I2C_ADDRESS}; - - struct MonitorI2CTaskArgs_t args_st[2] = {clockr0a_args, clock_args}; - struct dev_moni2c_addr_t *dev_st[2] = {clkr0a_moni2c_addrs, clk_moni2c_addrs}; - - // Clear sticky flags of clock synth 5341 and 5395 status monitor (raised high after reset) - for (int n = 0; n < 2; ++n) { - - for (uint8_t i = 0; i < nsupplies[n]; i++) { - uint8_t data = 0x1U << dev_st[n][i].mux_bit; - int res = apollo_i2c_ctl_w(CLOCK_I2C_BASE, dev_st[n][i].mux_addr, 1, data); - if (res != 0) - log_warn(LOG_SERVICE, "Mux write error %s, break (instance=%s,ps=%d)\r\n", SMBUS_get_error(res), dev_st[n][i].name, i); - - for (uint8_t c = 0; c < ncommands[n]; c++) { - uint8_t page_reg_value = args_st[n].commands[args_st[n].n_commands - c - 1].page; - int res = apollo_i2c_ctl_reg_w(CLOCK_I2C_BASE, dev_addr[n], 1, CLOCK_CHANGEPAGE_REG_ADDR, 1, page_reg_value); - - if (res != 0) - log_error(LOG_SERVICE, "%s: page fail %s\r\n", args_st[n].name, SMBUS_get_error(res)); - - status = apollo_i2c_ctl_reg_w(CLOCK_I2C_BASE, dev_addr[n], 1, args_st[n].commands[args_st[n].n_commands - c - 1].command, 1, 0); - if (status != 0) - return status; - } + for (int i = 0; i < NDEVICES_CLK; ++i) { + // set the mux + int res = apollo_i2c_ctl_w(CLOCK_I2C_BASE, clk_moni2c_addrs[i].mux_addr, 1, + 1 << clk_moni2c_addrs[i].mux_bit); + if (res != 0) { + log_warn(LOG_SERVICE, "Mux error %s, break (instance=%s)\r\n", SMBUS_get_error(res), + clk_moni2c_addrs[i].name); + return res; + } + // clear the sticky flag + res = apollo_i2c_ctl_reg_w(CLOCK_I2C_BASE, clk_moni2c_addrs[i].dev_addr, 1, + CLOCK_SYNTH_STICKY_FLAG_REGISTER, 1, 0); + if (res != 0) { + log_warn(LOG_SERVICE, "Sticky flag error %s, break (instance=%s)\r\n", SMBUS_get_error(res), + clk_moni2c_addrs[i].name); + return res; } } - return status; + return 0; } // return the string that corresponds to the programmed file. If @@ -80,18 +72,10 @@ void getClockProgram(int device, char progname_clkdesgid[CLOCK_PROGNAME_REG_NAME uint16_t eeprom_progname_reg; // In Rev2 device 0 and devices 1-5 are different and hence are stored in different arrays // for monitoring purposes - if (device == 0) { - mux_addr = clkr0a_moni2c_addrs[0].mux_addr; - mux_bit = clkr0a_moni2c_addrs[0].mux_bit; - dev_addr = clkr0a_moni2c_addrs[0].dev_addr; - eeprom_progname_reg = clkr0a_moni2c_addrs[0].eeprom_progname_reg; - } - else { - mux_addr = clk_moni2c_addrs[device - 1].mux_addr; - mux_bit = clk_moni2c_addrs[device - 1].mux_bit; - dev_addr = clk_moni2c_addrs[device - 1].dev_addr; - eeprom_progname_reg = clk_moni2c_addrs[device - 1].eeprom_progname_reg; - } + mux_addr = clk_moni2c_addrs[device].mux_addr; + mux_bit = clk_moni2c_addrs[device].mux_bit; + dev_addr = clk_moni2c_addrs[device].dev_addr; + eeprom_progname_reg = clk_moni2c_addrs[device].eeprom_progname_reg; // set mux bit int status = apollo_i2c_ctl_w(CLOCK_I2C_DEV, mux_addr, 1, 1 << mux_bit); if (status != 0) { diff --git a/projects/cm_mcu/cm_mcu.c b/projects/cm_mcu/cm_mcu.c index eff573fb..72234340 100644 --- a/projects/cm_mcu/cm_mcu.c +++ b/projects/cm_mcu/cm_mcu.c @@ -26,7 +26,6 @@ #include "common/log.h" #include "CommandLineTask.h" #include "InterruptHandlers.h" -#include "MonitorI2CTask.h" #include "MonitorTask.h" #include "MonUtils.h" #include "Tasks.h" @@ -246,16 +245,10 @@ __attribute__((noreturn)) int main(void) initSemaphores(); dcdc_args.xSem = i2c1_sem; fpga_args.xSem = i2c5_sem; - ffl12_f1_args.xSem = i2c4_sem; - ffl4_f1_args.xSem = i2c4_sem; - ffl12_f2_args.xSem = i2c3_sem; - ffl4_f2_args.xSem = i2c3_sem; #ifdef REV2 ff_f1_args.xSem = i2c4_sem; ff_f2_args.xSem = i2c3_sem; clk_args.xSem = i2c2_sem; - clock_args.xSem = i2c2_sem; - clockr0a_args.xSem = i2c2_sem; #endif // REV2 // Create the stream buffers that sends data from the interrupt to the // task, and create the task. @@ -295,14 +288,6 @@ __attribute__((noreturn)) int main(void) #endif // REV1 xTaskCreate(ADCMonitorTask, "ADC", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 4, NULL); -// xTaskCreate(MonitorI2CTask, ffl12_f1_args.name, 2 * configMINIMAL_STACK_SIZE, &ffl12_f1_args, tskIDLE_PRIORITY + 4, -// NULL); -// xTaskCreate(MonitorI2CTask, ffl4_f1_args.name, 2 * configMINIMAL_STACK_SIZE, &ffl4_f1_args, tskIDLE_PRIORITY + 4, -// NULL); -// xTaskCreate(MonitorI2CTask, ffl12_f2_args.name, 2 * configMINIMAL_STACK_SIZE, &ffl12_f2_args, tskIDLE_PRIORITY + 4, -// NULL); -// xTaskCreate(MonitorI2CTask, ffl4_f2_args.name, 2 * configMINIMAL_STACK_SIZE, &ffl4_f2_args, tskIDLE_PRIORITY + 4, -// NULL); #ifdef REV2 xTaskCreate(MonitorI2CTask_new, ff_f1_args.name, 2 * configMINIMAL_STACK_SIZE, &ff_f1_args, tskIDLE_PRIORITY + 4, NULL); @@ -311,10 +296,6 @@ __attribute__((noreturn)) int main(void) xTaskCreate(MonitorI2CTask_new, clk_args.name, 2 * configMINIMAL_STACK_SIZE, &clk_args, tskIDLE_PRIORITY + 4, NULL); -// xTaskCreate(MonitorI2CTask, clock_args.name, 2 * configMINIMAL_STACK_SIZE, &clock_args, tskIDLE_PRIORITY + 4, -// NULL); -// xTaskCreate(MonitorI2CTask, clockr0a_args.name, 2 * configMINIMAL_STACK_SIZE, &clockr0a_args, tskIDLE_PRIORITY + 4, -// NULL); #endif // REV2 xTaskCreate(MonitorTask, dcdc_args.name, 2 * configMINIMAL_STACK_SIZE, &dcdc_args, tskIDLE_PRIORITY + 4, NULL); diff --git a/projects/cm_mcu/commands/BoardCommands.c b/projects/cm_mcu/commands/BoardCommands.c index ab4e7a36..323ae9ab 100644 --- a/projects/cm_mcu/commands/BoardCommands.c +++ b/projects/cm_mcu/commands/BoardCommands.c @@ -9,6 +9,7 @@ #include #include +#include "FireflyUtils.h" #include "commands/parameters.h" #include "common/utils.h" #include "driverlib/gpio.h" // IWYU pragma: keep diff --git a/projects/cm_mcu/commands/SensorControl.c b/projects/cm_mcu/commands/SensorControl.c index 2c2d480e..222db280 100644 --- a/projects/cm_mcu/commands/SensorControl.c +++ b/projects/cm_mcu/commands/SensorControl.c @@ -10,6 +10,7 @@ #include "FireflyUtils.h" #include "I2CCommunication.h" #include "MonI2C_addresses.h" +#include "MonitorTaskI2C_new.h" #include "common/log.h" #include "common/utils.h" #include "parameters.h" @@ -265,7 +266,7 @@ static int write_arbitrary_ff_register(uint16_t regnumber, uint8_t value, int nu } // read a SINGLE firefly register, one byte only -static uint16_t read_arbitrary_ff_register(uint16_t regnumber, int num_ff, uint8_t *value, uint8_t size) +uint16_t read_arbitrary_ff_register(uint16_t regnumber, int num_ff, uint8_t *value, uint8_t size) { if (num_ff >= NFIREFLIES) { return -1; @@ -657,7 +658,6 @@ BaseType_t ff_status(int argc, char **argv, char *m) int copied = 0; static int whichff = 0; - static int n = 0; if (whichff == 0) { // check for stale data @@ -672,7 +672,6 @@ BaseType_t ff_status(int argc, char **argv, char *m) copied += snprintf(m + copied, SCRATCH_SIZE - copied, "FF STATUS:\r\n"); } - int i1 = 0; // 0 for status #ifdef REV2 int nTx = -1; // order of Tx ch // print out the "present" bits on first pass @@ -686,65 +685,104 @@ BaseType_t ff_status(int argc, char **argv, char *m) } } #endif // REV2 - for (; n < NFIREFLY_ARG; ++n) { - struct MonitorI2CTaskArgs_t *ff_arg = ff_moni2c_arg[n].arg; - for (; whichff < ff_moni2c_arg[n].int_idx + ff_moni2c_arg[n].num_dev; ++whichff) { - int dev = whichff - ff_moni2c_arg[n].int_idx + ff_moni2c_arg[n].dev_int_idx; - if (isEnabledFF(ff_moni2c_arg[n].int_idx + dev)) { - int index = dev * (ff_arg->n_commands * ff_arg->n_pages) + i1; - uint8_t val = ff_arg->sm_values[index]; - copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%17s: 0x%02x", ff_moni2c_addrs[whichff].name, val); - } - else // dummy value - copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%17s: %4s", ff_moni2c_addrs[whichff].name, "--"); - - bool isTx = (strstr(ff_moni2c_addrs[whichff].name, "Tx") != NULL); - if (isTx) { + for (; whichff < NFIREFLIES; ++whichff) { + if (isEnabledFF(whichff)) { + uint8_t val = get_FF_STATUS_REG_data(whichff); + copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%17s: 0x%02x", ff_moni2c_addrs[whichff].name, val); + } + else { // dummy value + copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%17s: %4s", ff_moni2c_addrs[whichff].name, "--"); + } + bool isTx = (strstr(ff_moni2c_addrs[whichff].name, "Tx") != NULL); + if (isTx) { #ifdef REV1 - copied += snprintf(m + copied, SCRATCH_SIZE - copied, "\t"); + copied += snprintf(m + copied, SCRATCH_SIZE - copied, "\t"); #elif defined(REV2) // REV1 - nTx += 1; - uint8_t ff_4v0_sel = 1 << (nTx % (NFIREFLIES_IT_F1 / 2)); - if (nTx < (NFIREFLIES_IT_F1 / 2)) - ff_4v0_sel &= f1_ff12xmit_4v0_sel; - else - ff_4v0_sel &= f2_ff12xmit_4v0_sel; - copied += snprintf(m + copied, SCRATCH_SIZE - copied, " 3v8?(%x) \t", ff_4v0_sel >> (nTx % (NFIREFLIES_IT_F1 / 2))); + nTx += 1; + uint8_t ff_4v0_sel = 1 << (nTx % (NFIREFLIES_IT_F1 / 2)); + if (nTx < (NFIREFLIES_IT_F1 / 2)) + ff_4v0_sel &= f1_ff12xmit_4v0_sel; + else + ff_4v0_sel &= f2_ff12xmit_4v0_sel; + copied += snprintf(m + copied, SCRATCH_SIZE - copied, " 3v8?(%x) \t", ff_4v0_sel >> (nTx % (NFIREFLIES_IT_F1 / 2))); #endif // REV2 - } - else { - copied += snprintf(m + copied, SCRATCH_SIZE - copied, "\r\n"); - } - if ((SCRATCH_SIZE - copied) < 20) { - ++whichff; - return pdTRUE; - } + } + else { + copied += snprintf(m + copied, SCRATCH_SIZE - copied, "\r\n"); + } + if ((SCRATCH_SIZE - copied) < 20) { + ++whichff; + return pdTRUE; } } - if (whichff % 2 == 1) { m[copied++] = '\r'; m[copied++] = '\n'; m[copied] = '\0'; } whichff = 0; - n = 0; return pdFALSE; } +// for (; n < NFIREFLY_ARG; ++n) { +// struct MonitorI2CTaskArgs_t *ff_arg = ff_moni2c_arg[n].arg; +// for (; whichff < ff_moni2c_arg[n].int_idx + ff_moni2c_arg[n].num_dev; ++whichff) { +// int dev = whichff - ff_moni2c_arg[n].int_idx + ff_moni2c_arg[n].dev_int_idx; +// if (isEnabledFF(ff_moni2c_arg[n].int_idx + dev)) { +// int index = dev * (ff_arg->n_commands * ff_arg->n_pages) + i1; +// uint8_t val = ff_arg->sm_values[index]; +// copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%17s: 0x%02x", ff_moni2c_addrs[whichff].name, val); +// } +// else // dummy value +// copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%17s: %4s", ff_moni2c_addrs[whichff].name, "--"); + +// bool isTx = (strstr(ff_moni2c_addrs[whichff].name, "Tx") != NULL); +// if (isTx) { +// #ifdef REV1 +// copied += snprintf(m + copied, SCRATCH_SIZE - copied, "\t"); +// #elif defined(REV2) // REV1 +// nTx += 1; +// uint8_t ff_4v0_sel = 1 << (nTx % (NFIREFLIES_IT_F1 / 2)); +// if (nTx < (NFIREFLIES_IT_F1 / 2)) +// ff_4v0_sel &= f1_ff12xmit_4v0_sel; +// else +// ff_4v0_sel &= f2_ff12xmit_4v0_sel; +// copied += snprintf(m + copied, SCRATCH_SIZE - copied, " 3v8?(%x) \t", ff_4v0_sel >> (nTx % (NFIREFLIES_IT_F1 / 2))); +// #endif // REV2 +// } +// else { +// copied += snprintf(m + copied, SCRATCH_SIZE - copied, "\r\n"); +// } +// if ((SCRATCH_SIZE - copied) < 20) { +// ++whichff; +// return pdTRUE; +// } +// } +// } + +// if (whichff % 2 == 1) { +// m[copied++] = '\r'; +// m[copied++] = '\n'; +// m[copied] = '\0'; +// } +// whichff = 0; +// n = 0; + +// return pdFALSE; +// } + BaseType_t ff_los_alarm(int argc, char **argv, char *m) { int copied = 0; static int whichff = 0; - static int n = 0; + // static int n = 0; if (whichff == 0) { // check for stale data - TickType_t now = pdTICKS_TO_S(xTaskGetTickCount()); - if (isFFStale()) { + TickType_t now = pdTICKS_TO_S(xTaskGetTickCount()); TickType_t last = pdTICKS_TO_S(getFFupdateTick(isFFStale())); int mins = (now - last) / 60; copied += snprintf(m + copied, SCRATCH_SIZE - copied, @@ -753,51 +791,65 @@ BaseType_t ff_los_alarm(int argc, char **argv, char *m) copied += snprintf(m + copied, SCRATCH_SIZE - copied, "FIREFLY LOS ALARM:\r\n"); } - int i1 = 2; // 2 for los_alarm - uint8_t i2cdata[2]; - - for (; n < NFIREFLY_ARG; ++n) { - struct MonitorI2CTaskArgs_t *ff_arg = ff_moni2c_arg[n].arg; - - for (; whichff < ff_moni2c_arg[n].int_idx + ff_moni2c_arg[n].num_dev; ++whichff) { - int dev = whichff - ff_moni2c_arg[n].int_idx + ff_moni2c_arg[n].dev_int_idx; - copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%s ", ff_moni2c_addrs[whichff].name); - if (!isEnabledFF(ff_moni2c_arg[n].int_idx + dev)) { - copied += snprintf(m + copied, SCRATCH_SIZE - copied, "------------"); - } - else { - int index = dev * (ff_arg->n_commands * ff_arg->n_pages) + i1; - i2cdata[0] = (ff_arg->sm_values[index]) & 0xFFU; - i2cdata[1] = (ff_arg->sm_values[index] >> 8) & 0xFFU; - for (size_t i = 0; i < 8; i++) { - int alarm = getFFch_low(i2cdata[0], i) ? 1 : 0; - copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%d", alarm); - } - if (strstr(ff_moni2c_arg[n].ff_part, "FFL12") != NULL) { - for (size_t i = 8; i < 12; i++) { - int alarm = getFFch_high(i2cdata[1], i) ? 1 : 0; - copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%d", alarm); - } - } - } - bool isTx = (strstr(ff_moni2c_addrs[whichff].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; - return pdTRUE; - } + for (; whichff < NFIREFLIES; ++whichff) { + uint16_t val = get_FF_LOS_ALARM_data(whichff); + copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%17s: 0x%04x", + ff_moni2c_addrs[whichff].name, val); + bool isTx = (strstr(ff_moni2c_addrs[whichff].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; + return pdTRUE; } } + + // int i1 = 2; // 2 for los_alarm + // uint8_t i2cdata[2]; + + // for (; n < NFIREFLY_ARG; ++n) { + // struct MonitorI2CTaskArgs_t *ff_arg = ff_moni2c_arg[n].arg; + + // for (; whichff < ff_moni2c_arg[n].int_idx + ff_moni2c_arg[n].num_dev; ++whichff) { + // int dev = whichff - ff_moni2c_arg[n].int_idx + ff_moni2c_arg[n].dev_int_idx; + // copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%s ", ff_moni2c_addrs[whichff].name); + // if (!isEnabledFF(ff_moni2c_arg[n].int_idx + dev)) { + // copied += snprintf(m + copied, SCRATCH_SIZE - copied, "------------"); + // } + // else { + // int index = dev * (ff_arg->n_commands * ff_arg->n_pages) + i1; + // i2cdata[0] = (ff_arg->sm_values[index]) & 0xFFU; + // i2cdata[1] = (ff_arg->sm_values[index] >> 8) & 0xFFU; + // for (size_t i = 0; i < 8; i++) { + // int alarm = getFFch_low(i2cdata[0], i) ? 1 : 0; + // copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%d", alarm); + // } + // if (strstr(ff_moni2c_arg[n].ff_part, "FFL12") != NULL) { + // for (size_t i = 8; i < 12; i++) { + // int alarm = getFFch_high(i2cdata[1], i) ? 1 : 0; + // copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%d", alarm); + // } + // } + // } + // bool isTx = (strstr(ff_moni2c_addrs[whichff].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; + // return pdTRUE; + // } + // } + // } if (whichff % 2 == 1) { m[copied++] = '\r'; m[copied++] = '\n'; m[copied] = '\0'; } whichff = 0; - n = 0; return pdFALSE; } @@ -807,13 +859,11 @@ BaseType_t ff_cdr_lol_alarm(int argc, char **argv, char *m) int copied = 0; static int whichff = 0; - static int n = 0; if (whichff == 0) { // check for stale data - TickType_t now = pdTICKS_TO_S(xTaskGetTickCount()); - if (isFFStale()) { + TickType_t now = pdTICKS_TO_S(xTaskGetTickCount()); TickType_t last = pdTICKS_TO_S(getFFupdateTick(isFFStale())); int mins = (now - last) / 60; copied += snprintf(m + copied, SCRATCH_SIZE - copied, @@ -822,51 +872,67 @@ BaseType_t ff_cdr_lol_alarm(int argc, char **argv, char *m) copied += snprintf(m + copied, SCRATCH_SIZE - copied, "FIREFLY CDR LOL ALARM:\r\n"); } - int i1 = 3; // 3 for cdr_lol_alarm - uint8_t i2cdata[2]; - - for (; n < NFIREFLY_ARG; ++n) { - struct MonitorI2CTaskArgs_t *ff_arg = ff_moni2c_arg[n].arg; - - for (; whichff < ff_moni2c_arg[n].int_idx + ff_moni2c_arg[n].num_dev; ++whichff) { - int dev = whichff - ff_moni2c_arg[n].int_idx + ff_moni2c_arg[n].dev_int_idx; - copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%s ", ff_moni2c_addrs[whichff].name); - if (!isEnabledFF(ff_moni2c_arg[n].int_idx + dev)) { - copied += snprintf(m + copied, SCRATCH_SIZE - copied, "------------"); - } - else { - int index = dev * (ff_arg->n_commands * ff_arg->n_pages) + i1; - i2cdata[0] = (ff_arg->sm_values[index]) & 0xFFU; - i2cdata[1] = (ff_arg->sm_values[index] >> 8) & 0xFFU; - for (size_t i = 0; i < 8; i++) { - int alarm = getFFch_low(i2cdata[0], i) ? 1 : 0; - copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%d", alarm); - } - if (strstr(ff_moni2c_arg[n].ff_part, "FFL12") != NULL) { - for (size_t i = 8; i < 12; i++) { - int alarm = getFFch_high(i2cdata[1], i) ? 1 : 0; - copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%d", alarm); - } - } - } - bool isTx = (strstr(ff_moni2c_addrs[whichff].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; - return pdTRUE; - } + for (; whichff < NFIREFLIES; ++whichff) { + if (FireflyType(whichff) == DEVICE_25G12 || FireflyType(whichff) == DEVICE_25G4) { + uint16_t val = get_FF_CDR_LOL_ALARM_data(whichff); + copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%17s: 0x%04x", ff_moni2c_addrs[whichff].name, val); + } + else { + copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%17s: %4s", ff_moni2c_addrs[whichff].name, "--"); + } + bool isTx = (strstr(ff_moni2c_addrs[whichff].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; + return pdTRUE; } } + + // for (; n < NFIREFLY_ARG; ++n) { + // struct MonitorI2CTaskArgs_t *ff_arg = ff_moni2c_arg[n].arg; + + // for (; whichff < ff_moni2c_arg[n].int_idx + ff_moni2c_arg[n].num_dev; ++whichff) { + // int dev = whichff - ff_moni2c_arg[n].int_idx + ff_moni2c_arg[n].dev_int_idx; + // copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%s ", ff_moni2c_addrs[whichff].name); + // if (!isEnabledFF(ff_moni2c_arg[n].int_idx + dev)) { + // copied += snprintf(m + copied, SCRATCH_SIZE - copied, "------------"); + // } + // else { + // int index = dev * (ff_arg->n_commands * ff_arg->n_pages) + i1; + // i2cdata[0] = (ff_arg->sm_values[index]) & 0xFFU; + // i2cdata[1] = (ff_arg->sm_values[index] >> 8) & 0xFFU; + // for (size_t i = 0; i < 8; i++) { + // int alarm = getFFch_low(i2cdata[0], i) ? 1 : 0; + // copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%d", alarm); + // } + // if (strstr(ff_moni2c_arg[n].ff_part, "FFL12") != NULL) { + // for (size_t i = 8; i < 12; i++) { + // int alarm = getFFch_high(i2cdata[1], i) ? 1 : 0; + // copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%d", alarm); + // } + // } + // } + // bool isTx = (strstr(ff_moni2c_addrs[whichff].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; + // return pdTRUE; + // } + // } + // } if (whichff % 2 == 1) { m[copied++] = '\r'; m[copied++] = '\n'; m[copied] = '\0'; } whichff = 0; - n = 0; + // n = 0; return pdFALSE; } @@ -952,20 +1018,24 @@ BaseType_t ff_temp(int argc, char **argv, char *m) return pdFALSE; } +// loop over all channels on all devices and show optical power BaseType_t ff_optpow(int argc, char **argv, char *m) { // argument handling + snprintf(m, SCRATCH_SIZE, "FF Optical Power: to be implemented anew\r\n"); + return pdFALSE; + // it appears that this in its current implementation prints optical power of every channel on every device. + // that would be over 100 channels, which is too much for a single command. +#if 0 int copied = 0; - static int whichff = 0; static int n = 0; static int i1 = 4; if (whichff == 0) { // check for stale data - TickType_t now = pdTICKS_TO_S(xTaskGetTickCount()); - if (isFFStale()) { + TickType_t now = pdTICKS_TO_S(xTaskGetTickCount()); TickType_t last = pdTICKS_TO_S(getFFupdateTick(isFFStale())); int mins = (now - last) / 60; copied += snprintf(m + copied, SCRATCH_SIZE - copied, @@ -974,6 +1044,63 @@ BaseType_t ff_optpow(int argc, char **argv, char *m) copied += snprintf(m + copied, SCRATCH_SIZE - copied, "FF Optical Power:\r\n"); } + for (; whichff < NFIREFLIES; ++whichff) { + // skip transmitters + if (strstr(ff_moni2c_addrs[whichff].name, "Tx") != NULL) + continue; + // skip if not enabled or present + if (!isEnabledFF(whichff)) + continue; + // loop over all channels. for XCVR, 4 channels. for Tx devices, 12 channels + int maxchan = 12; + if (FireflyType(whichff)==DEVICE_25G4) { + maxchan = 4; + } + uint16_t val; + // firefly channels are labled 1-12 + for ( int c = 1; c <= maxchan; ++c) { + switch (c) { + case 1: + val = get_FF_OPT_POWER_CH1_data(c); + break; + case 2: + val = get_FF_OPT_POWER_CH2_data(c); + break; + case 3: + val = get_FF_F1_OPT_POWER_CH3_data(c); + break; + case 4: + val = get_FF_F1_OPT_POWER_CH4_data(c); + break; + case 5: + val = get_FF_F1_OPT_POWER_CH5_data(c); + break; + default: + val = 0; + break; + // case 6: + // val = get_FF_F1_OPT_POWER_CH6_data(c); + // break; + // case 7: + // val = get_FF_F1_OPT_POWER_CH7_data(c); + // break; + // case 8: + // val = get_FF_F1_OPT_POWER_CH8_data(c); + // break; + // case 9: + // val = get_FF_F1_OPT_POWER_CH9_data(c); + // break; + // case 10: + // val = get_FF_F1_OPT_POWER_CH10_data(c); + // break; + // case 11: + // val = get_FF_F1_OPT_POWER_CH11_data(c); + // break; + // case 12: + // val = get_FF_F1_OPT_POWER_CH12_data(c); + // break; + } + } for (; n < NFIREFLY_ARG; ++n) { struct MonitorI2CTaskArgs_t *ff_arg = ff_moni2c_arg[n].arg; for (; whichff < ff_moni2c_arg[n].int_idx + ff_moni2c_arg[n].num_dev; ++whichff) { @@ -1028,7 +1155,8 @@ BaseType_t ff_optpow(int argc, char **argv, char *m) i1 = 4; return pdFALSE; } - +#endif // 0 +} // this command takes up to two arguments BaseType_t ff_ctl(int argc, char **argv, char *m) { @@ -1213,82 +1341,53 @@ BaseType_t clkmon_ctl(int argc, char **argv, char *m) // print out header once if (c == 0) { const char *clk_ids[5] = {"0A", "0B", "1A", "1B", "1C"}; - copied += snprintf(m + copied, SCRATCH_SIZE - copied, "Monitoring SI clock with id R%s\r\n", + copied += snprintf(m + copied, SCRATCH_SIZE - copied, "Clock R%s\r\n", clk_ids[i]); char *header = "REG_TABLE"; copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%-15s REG_ADDR BIT_MASK VALUE \r\n", header); } // update times, in seconds TickType_t now = pdTICKS_TO_MS(xTaskGetTickCount()) / 1000; - TickType_t last = pdTICKS_TO_MS(clockr0a_args.updateTick) / 1000; + TickType_t last = pdTICKS_TO_MS(clk_args.updateTick) / 1000; if (checkStale(last, now)) { unsigned mins = (now - last) / 60; copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%s: stale data, last update %u minutes ago\r\n", argv[0], mins); } - // i = 0 corresponds to SI5341, others to SI5395 - if (i == 0) { - - for (; c < clockr0a_args.n_commands; ++c) { - uint16_t val = clockr0a_args.sm_values[c]; - copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%-15s : 0x%04x 0x%04x 0x%04x\r\n", - clockr0a_args.commands[c].name, clockr0a_args.commands[c].command, - clockr0a_args.commands[c].bit_mask, val); - // copied += snprintf(m + copied, SCRATCH_SIZE - copied, "\r\n"); - if ((SCRATCH_SIZE - copied) < 50) { - ++c; - return pdTRUE; - } + for (; c < clk_args.n_commands; ++c) { + // check if device i has this command + if (!(clk_args.commands[c].devicelist() & ClockType(i))) { + continue; } - if (c % 2 == 1) { - m[copied++] = '\r'; - m[copied++] = '\n'; - m[copied] = '\0'; + uint16_t val = clk_args.commands[c].retrieveData(i); + copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%-15s : 0x%04x 0x%04x 0x%04x\r\n", + clk_args.commands[c].name, clk_args.commands[c].command[ClockType(i)], + clk_args.commands[c].bit_mask, val); + if ((SCRATCH_SIZE - copied) < 20) { + ++c; + return pdTRUE; } - c = 0; + } + if (c % 2 == 1) { + m[copied++] = '\r'; + m[copied++] = '\n'; + m[copied] = '\0'; + } + c = 0; #ifdef REV2 - copied += snprintf(m + copied, SCRATCH_SIZE - copied, "Program (read from clock chip): %s", clkprog_args[0].progname_clkdesgid); - if (strncmp(clkprog_args[0].progname_clkdesgid, "5395ABP1", 3) == 0 || strncmp(clkprog_args[0].progname_clkdesgid, "5341ABP1", 3) == 0) { - copied += snprintf(m + copied, SCRATCH_SIZE - copied, " (not found)"); - } - - snprintf(m + copied, SCRATCH_SIZE - copied, "\r\nProgram (read from eeprom): %s\r\n", clkprog_args[0].progname_eeprom); -#endif + copied += snprintf(m + copied, SCRATCH_SIZE - copied, "Program (read from clock chip): %s", clkprog_args[0].progname_clkdesgid); + if (strncmp(clkprog_args[0].progname_clkdesgid, "5395ABP1", 3) == 0 || strncmp(clkprog_args[0].progname_clkdesgid, "5341ABP1", 3) == 0) { + copied += snprintf(m + copied, SCRATCH_SIZE - copied, " (not found)"); } - // i = 0 corresponds to SI5341, others to SI5395 - else { - for (; c < clock_args.n_commands; ++c) { - uint16_t val = clock_args.sm_values[(i - 1) * (clock_args.n_commands * clock_args.n_pages) + c]; - copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%-15s : 0x%04x 0x%04x 0x%04x\r\n", clock_args.commands[c].name, clock_args.commands[c].command, clock_args.commands[c].bit_mask, val); - if ((SCRATCH_SIZE - copied) < 50) { - ++c; - return pdTRUE; - } - } - if (c % 2 == 1) { - m[copied++] = '\r'; - m[copied++] = '\n'; - m[copied] = '\0'; - } - c = 0; -#ifdef REV2 - copied += snprintf(m + copied, SCRATCH_SIZE - copied, "Program (read from clock chip): %s", clkprog_args[i].progname_clkdesgid); - if (strncmp(clkprog_args[i].progname_clkdesgid, "5395ABP1", 3) == 0 || strncmp(clkprog_args[i].progname_clkdesgid, "5341ABP1", 3) == 0) { - copied += snprintf(m + copied, SCRATCH_SIZE - copied, " (not found)"); - } - snprintf(m + copied, SCRATCH_SIZE - copied, "\r\nProgram (read from eeprom): %s\r\n", clkprog_args[i].progname_eeprom); + snprintf(m + copied, SCRATCH_SIZE - copied, "\r\nProgram (read from eeprom): %s\r\n", clkprog_args[0].progname_eeprom); #endif - } return pdFALSE; } -extern struct MonitorI2CTaskArgs_t clock_args; -extern struct MonitorI2CTaskArgs_t clockr0a_args; - BaseType_t fpga_ctl(int argc, char **argv, char *m) { if (argc == 2) { @@ -1456,13 +1555,7 @@ BaseType_t psmon_reg(int argc, char **argv, char *m) return pdFALSE; } -// #define VENDOR_START_BIT_FFDAQ 168 -// #define VENDOR_STOP_BIT_FFDAQ 184 -// #define VENDOR_START_BIT_FF12 171 -// #define VENDOR_STOP_BIT_FF12 187 -#define VENDOR_COUNT_FFDAQ (VENDOR_STOP_BIT_FFDAQ - VENDOR_START_BIT_FFDAQ) -#define VENDOR_COUNT_FF12 (VENDOR_STOP_BIT_FF12 - VENDOR_START_BIT_FF12) - +// this command takes no arguments BaseType_t ff_dump_names(int argc, char **argv, char *m) { int copied = 0; @@ -1473,8 +1566,8 @@ BaseType_t ff_dump_names(int argc, char **argv, char *m) continue; } - char name[20]; - memset(name, '\0', 20); + char name[17]; + memset(name, '\0', 17); int type = FireflyType(i); int startReg = VENDOR_START_BIT_FFDAQ; int count = VENDOR_COUNT_FFDAQ; diff --git a/projects/cm_mcu/commands/parameters.h b/projects/cm_mcu/commands/parameters.h index 507c5d52..b9f9abf4 100644 --- a/projects/cm_mcu/commands/parameters.h +++ b/projects/cm_mcu/commands/parameters.h @@ -40,7 +40,6 @@ #include "driverlib/uart.h" #include "MonitorTask.h" -#include "MonitorI2CTask.h" #include "CommandLineTask.h" #include "I2CCommunication.h" #include "Tasks.h" diff --git a/sm_cm_config/data/MON_I2C_rev2.yml b/sm_cm_config/data/MON_I2C_rev2.yml index c71ee814..6e7065da 100644 --- a/sm_cm_config/data/MON_I2C_rev2.yml +++ b/sm_cm_config/data/MON_I2C_rev2.yml @@ -9,7 +9,7 @@ define: &FF_SHARED_REGS - name: STATUS_REG # register name reg_size: 1 # size of register address in bytes page: 0 # page of register - reg_address: 0x2 # register address + reg_address: 0x2 # register address, if list: [ cernb, 14g, 25g4, 25g12] size: 2 # size of data in register in bytes mask: 0xFF # mask for valid bits units: "" # units for display @@ -33,6 +33,15 @@ define: &FF_SHARED_REGS units: "" type: PM_STATUS devicetypes: [25G12, 25G4] + - name: CDR_LOL_ALARM + reg_size: 1 + page: 0 + reg_address: [-1, -1, 0x5, 0x14] + size: 2 + mask: 0xFFFF + units: "" + type: PM_STATUS + devicetypes: [25G4, 25G12] - name: OPT_POWER_CH1 reg_size: 1 page: 0 diff --git a/sm_cm_config/src/mon_generate.py b/sm_cm_config/src/mon_generate.py index 356d24e2..5e2517c1 100755 --- a/sm_cm_config/src/mon_generate.py +++ b/sm_cm_config/src/mon_generate.py @@ -52,7 +52,8 @@ def write_boilderplate(fout: io.TextIOWrapper): # addr_template = Template("{$reg_size, $page, $reg_address, $size, \"$name\"," # " $mask, \"$units\", $type, get_${name}_mask, set_${name}_data}, ") addr_template = Template("{$reg_size, $page, $reg_list, $size, \"$name\"," - " $mask, \"$units\", $type, get_${prefix}_${name}_mask, set_${prefix}_${name}_data}, ") + " $mask, \"$units\", $type, get_${prefix}_${name}_mask," + " set_${prefix}_${name}_data, get_${prefix}_${name}_data},") # output file names: header file and c source file # make sure that the output file ends with .c. Print error message and exit if it doesn't if not args.output.endswith(".c"): @@ -81,7 +82,7 @@ def write_boilderplate(fout: io.TextIOWrapper): print("#include ", file=fout_header) print("#include \"MonitorTaskI2C_new.h\"", file=fout_header) print("#include \"FireflyUtils.h\"", file=fout_source) - print("#include \"MonitorI2CTask.h\"", file=fout_source) + #print("#include \"MonitorI2CTask.h\"", file=fout_source) with open(args.input_file, encoding="ascii") as f: @@ -164,19 +165,25 @@ def write_boilderplate(fout: io.TextIOWrapper): for c in config: data_name_f1 = f"FF_F1_{c['name']}_data" data_name_f2 = f"FF_F2_{c['name']}_data" - get_fcn_name_f1 = f"get_F1_{c['name']}_data" - get_fcn_name_f2 = f"get_F2_{c['name']}_data" + get_fcn_name_f1 = f"get_FF_F1_{c['name']}_data" + get_fcn_name_f2 = f"get_FF_F2_{c['name']}_data" get_fcn_name = f"get_FF_{c['name']}_data" - # write get_fcn_name header to the header file - print(f"uint16_t {get_fcn_name}(int which);", file=fout_header) - # write body of get_fcn_name to the source file - print(f"uint16_t {get_fcn_name}(int which) {{", file=fout_source) - print( " if (which < NFIREFLIES_F1) {{", file=fout_source) - print(f" return {data_name_f1}[which];", file=fout_source) - print( " }} else {{", file=fout_source) - print(f" return {data_name_f2}[which - NFIREFLIES_F1];", file=fout_source) - print( " }}", file=fout_source) - print(r"}", file=fout_source) + # write a preprocessor macro that uses a trigram to select the correct function + print(f"#define {get_fcn_name}(which) \\", + file=fout_header) + print(f" ((which) < NFIREFLIES_F1 ? {get_fcn_name_f1}((which)) : {get_fcn_name_f2}((which) - NFIREFLIES_F1))", + file=fout_header) + + # # write get_fcn_name header to the header file + # print(f"uint16_t {get_fcn_name}(int which);", file=fout_header) + # # write body of get_fcn_name to the source file + # print(f"uint16_t {get_fcn_name}(int which) {{", file=fout_source) + # print( " if (which < NFIREFLIES_F1) {{", file=fout_source) + # print(f" return {data_name_f1}[which];", file=fout_source) + # print( " }} else {{", file=fout_source) + # print(f" return {data_name_f2}[which - NFIREFLIES_F1];", file=fout_source) + # print( " }}", file=fout_source) + # print(r"}", file=fout_source) # closing header guard print(r"#endif// MON_I2C_ADDRESSES_H", file=fout_header) From b7ccfc95a4e32cb8327143bef911790fc1c88536 Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Wed, 29 May 2024 21:55:23 -0400 Subject: [PATCH 32/71] bug fixes --- projects/cm_mcu/FireflyUtils.c | 37 ++++++++++++++++++++---- projects/cm_mcu/FireflyUtils.h | 1 + projects/cm_mcu/MonitorTaskI2C_new.c | 2 +- projects/cm_mcu/MonitorTaskI2C_new.h | 4 +-- projects/cm_mcu/PowerSupplyTask.c | 1 + projects/cm_mcu/commands/SensorControl.c | 9 +++--- 6 files changed, 41 insertions(+), 13 deletions(-) diff --git a/projects/cm_mcu/FireflyUtils.c b/projects/cm_mcu/FireflyUtils.c index 61f802a3..8054ff8d 100644 --- a/projects/cm_mcu/FireflyUtils.c +++ b/projects/cm_mcu/FireflyUtils.c @@ -263,22 +263,25 @@ uint16_t getFFpresentbit(const uint8_t i) return val; } +// figure out which parts are 25G and which are not, for 12 channel parts uint32_t ff_map_25gb_parts(void) { uint32_t ff_25gb_parts = 0U; + uint32_t ff_25gb_pairs = 0U; for (int i = 0; i < NFIREFLIES; ++i) { if (!isEnabledFF(i)) { // skip the FF if it's not enabled via the FF config continue; } - // skip 4 channel parts - if (FireflyType(i) == DEVICE_25G4) { - continue; - } char name[17]; memset(name, '\0', 17); - int startReg = VENDOR_START_BIT_FF12; - int count = VENDOR_COUNT_FF12; + int startReg = VENDOR_START_BIT_FFDAQ; + int count = VENDOR_COUNT_FFDAQ; + int type = FireflyType(i); + if (type == DEVICE_CERNB || type == DEVICE_25G12) { + startReg = VENDOR_START_BIT_FF12; + count = VENDOR_COUNT_FF12; + } int ret = 0; // build up name of the device (vendor string) for (unsigned char c = 0; c < count; ++c) { @@ -290,11 +293,33 @@ uint32_t ff_map_25gb_parts(void) log_error(LOG_SERVICE, "Error reading vendor string for FF %d\r\n", i); // what to do? FIXME: return error? } + log_info(LOG_SERVICE, "F%d FF%02d: %s\r\n", i/10+1, i%10, name); + // skip 4 channel parts + if (type == DEVICE_25G4) { + continue; + } if (strstr(name, "14") == NULL && strstr(name, "CRRNB") == NULL && strstr(name, "CERNB") == NULL) { ff_25gb_parts |= (0x1U << i); + int ipair = i/2; // counts pairs of 12 channel devices + ff_25gb_pairs |= (0x1U << ipair); } } + log_info(LOG_SERVICE, "ff 25G12 mask: 0x%08lx\r\n", ff_25gb_parts); + // these masks have one bit per pair of receiver/transceiver + ff_bitmask_args[0].ffpart_bit_mask = ff_25gb_pairs & 0x7U; + ff_bitmask_args[2].ffpart_bit_mask = (ff_25gb_pairs>>10) & 0x7U; + // check if the 4v switch settings match + // F1 + if (ff_bitmask_args[0].ffpart_bit_mask != f1_ff12xmit_4v0_sel) { + log_error(LOG_SERVICE, "4v switch and part mismatch F1: 0x%x != 0x%x\r\n", + ff_bitmask_args[0].ffpart_bit_mask,f1_ff12xmit_4v0_sel); + } + // F2 + if (ff_bitmask_args[2].ffpart_bit_mask != f2_ff12xmit_4v0_sel) { + log_error(LOG_SERVICE, "4v switch and part mismatch F2: 0x%x != 0x%x\r\n", + ff_bitmask_args[2].ffpart_bit_mask,f2_ff12xmit_4v0_sel); + } return ff_25gb_parts; } diff --git a/projects/cm_mcu/FireflyUtils.h b/projects/cm_mcu/FireflyUtils.h index c68296cd..2debe817 100644 --- a/projects/cm_mcu/FireflyUtils.h +++ b/projects/cm_mcu/FireflyUtils.h @@ -65,6 +65,7 @@ float getFFavgoptpow(const uint8_t i); uint16_t getFFpresentbit(const uint8_t i); #ifdef REV2 void getFFpart(void); +uint32_t ff_map_25gb_parts(void); #endif uint8_t getFFstatus(const uint8_t i); diff --git a/projects/cm_mcu/MonitorTaskI2C_new.c b/projects/cm_mcu/MonitorTaskI2C_new.c index 4c08fabf..975d1bb4 100644 --- a/projects/cm_mcu/MonitorTaskI2C_new.c +++ b/projects/cm_mcu/MonitorTaskI2C_new.c @@ -126,7 +126,7 @@ void MonitorI2CTask_new(void *parameters) // what kind of device is this uint32_t devtype_mask = args->typeCallback(device); - uint32_t devtype = 32 - __builtin_clz(devtype_mask); // highest bit set FIXME: this is backwards + uint32_t devtype = 31 - __builtin_clz(devtype_mask); // highest bit set FIXME: this is backwards // Loop to read I2C registers/commands for (int c = 0; c < args->n_commands; ++c) { // check if the command is for this device diff --git a/projects/cm_mcu/MonitorTaskI2C_new.h b/projects/cm_mcu/MonitorTaskI2C_new.h index b9474187..7d54fd13 100644 --- a/projects/cm_mcu/MonitorTaskI2C_new.h +++ b/projects/cm_mcu/MonitorTaskI2C_new.h @@ -54,8 +54,8 @@ struct MonitorI2CTaskArgs_new_t { #define DEVICE_14G 0x02 #define DEVICE_25G4 0x04 #define DEVICE_25G12 0x08 -#define DEVICE_SI5395 0x10 -#define DEVICE_SI5341 0x20 +#define DEVICE_SI5341 0x01 +#define DEVICE_SI5395 0x02 #define DEVICE_NONE 0x80 diff --git a/projects/cm_mcu/PowerSupplyTask.c b/projects/cm_mcu/PowerSupplyTask.c index 39eb4a3e..98a9458a 100644 --- a/projects/cm_mcu/PowerSupplyTask.c +++ b/projects/cm_mcu/PowerSupplyTask.c @@ -408,6 +408,7 @@ void PowerSupplyTask(void *parameters) // check 12-ch FF parts from vendors on FPGA1/2 vTaskDelay(pdMS_TO_TICKS(1000)); getFFpart(); + ff_map_25gb_parts(); UBaseType_t ffmask[2] = {0xe, 0xe}; if ((f1_ff12xmit_4v0_sel ^ ff_bitmask_args[0].ffpart_bit_mask) == 0x0U && (f2_ff12xmit_4v0_sel ^ ff_bitmask_args[2].ffpart_bit_mask) == 0x0U) { int ret = enable_3v8(ffmask, false); // enable v38 diff --git a/projects/cm_mcu/commands/SensorControl.c b/projects/cm_mcu/commands/SensorControl.c index 222db280..28005e17 100644 --- a/projects/cm_mcu/commands/SensorControl.c +++ b/projects/cm_mcu/commands/SensorControl.c @@ -1362,8 +1362,9 @@ BaseType_t clkmon_ctl(int argc, char **argv, char *m) continue; } uint16_t val = clk_args.commands[c].retrieveData(i); + int devtype = 31 - __builtin_clz(ClockType(i)); copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%-15s : 0x%04x 0x%04x 0x%04x\r\n", - clk_args.commands[c].name, clk_args.commands[c].command[ClockType(i)], + clk_args.commands[c].name, clk_args.commands[c].command[devtype], clk_args.commands[c].bit_mask, val); if ((SCRATCH_SIZE - copied) < 20) { ++c; @@ -1377,12 +1378,12 @@ BaseType_t clkmon_ctl(int argc, char **argv, char *m) } c = 0; #ifdef REV2 - copied += snprintf(m + copied, SCRATCH_SIZE - copied, "Program (read from clock chip): %s", clkprog_args[0].progname_clkdesgid); - if (strncmp(clkprog_args[0].progname_clkdesgid, "5395ABP1", 3) == 0 || strncmp(clkprog_args[0].progname_clkdesgid, "5341ABP1", 3) == 0) { + copied += snprintf(m + copied, SCRATCH_SIZE - copied, "Program (read from clock chip): %s", clkprog_args[i].progname_clkdesgid); + if (strncmp(clkprog_args[i].progname_clkdesgid, "5395ABP1", 3) == 0 || strncmp(clkprog_args[i].progname_clkdesgid, "5341ABP1", 3) == 0) { copied += snprintf(m + copied, SCRATCH_SIZE - copied, " (not found)"); } - snprintf(m + copied, SCRATCH_SIZE - copied, "\r\nProgram (read from eeprom): %s\r\n", clkprog_args[0].progname_eeprom); + snprintf(m + copied, SCRATCH_SIZE - copied, "\r\nProgram (read from eeprom): %s\r\n", clkprog_args[i].progname_eeprom); #endif return pdFALSE; From afcbbbf17ba75db675b2a770711393dd7eb186bb Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Thu, 30 May 2024 09:27:50 -0400 Subject: [PATCH 33/71] fix rev1 build and format. also fix make format for deleted files --- Makefile | 4 +-- projects/cm_mcu/FireflyUtils.c | 10 +++--- projects/cm_mcu/MonUtils.c | 57 +++++++++++++++++++++++++++++++++- 3 files changed, 63 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 78a175ca..adf2da79 100644 --- a/Makefile +++ b/Makefile @@ -44,9 +44,9 @@ check-for-pr: format # 2nd dollar sign in grep is to pass along a single dollar sign to make format: - run-clang-format.py $(shell git diff --name-only master | egrep '.[ch]$$') + run-clang-format.py $(shell git diff --diff-filter=AM --name-only master | egrep '.[ch]$$') format-apply: - run-clang-format.py -i $(shell git diff --name-only master | egrep '.[ch]$$') + run-clang-format.py -i $(shell git diff --diff-filter=AM --name-only master | egrep '.[ch]$$') .PHONY: all clean $(DIRS) $(DIRSCLEAN) check-and-reinit-submodules diff --git a/projects/cm_mcu/FireflyUtils.c b/projects/cm_mcu/FireflyUtils.c index 8054ff8d..d59df3bb 100644 --- a/projects/cm_mcu/FireflyUtils.c +++ b/projects/cm_mcu/FireflyUtils.c @@ -293,7 +293,7 @@ uint32_t ff_map_25gb_parts(void) log_error(LOG_SERVICE, "Error reading vendor string for FF %d\r\n", i); // what to do? FIXME: return error? } - log_info(LOG_SERVICE, "F%d FF%02d: %s\r\n", i/10+1, i%10, name); + log_info(LOG_SERVICE, "F%d FF%02d: %s\r\n", i / 10 + 1, i % 10, name); // skip 4 channel parts if (type == DEVICE_25G4) { continue; @@ -301,24 +301,24 @@ uint32_t ff_map_25gb_parts(void) if (strstr(name, "14") == NULL && strstr(name, "CRRNB") == NULL && strstr(name, "CERNB") == NULL) { ff_25gb_parts |= (0x1U << i); - int ipair = i/2; // counts pairs of 12 channel devices + int ipair = i / 2; // counts pairs of 12 channel devices ff_25gb_pairs |= (0x1U << ipair); } } log_info(LOG_SERVICE, "ff 25G12 mask: 0x%08lx\r\n", ff_25gb_parts); // these masks have one bit per pair of receiver/transceiver ff_bitmask_args[0].ffpart_bit_mask = ff_25gb_pairs & 0x7U; - ff_bitmask_args[2].ffpart_bit_mask = (ff_25gb_pairs>>10) & 0x7U; + ff_bitmask_args[2].ffpart_bit_mask = (ff_25gb_pairs >> 10) & 0x7U; // check if the 4v switch settings match // F1 if (ff_bitmask_args[0].ffpart_bit_mask != f1_ff12xmit_4v0_sel) { log_error(LOG_SERVICE, "4v switch and part mismatch F1: 0x%x != 0x%x\r\n", - ff_bitmask_args[0].ffpart_bit_mask,f1_ff12xmit_4v0_sel); + ff_bitmask_args[0].ffpart_bit_mask, f1_ff12xmit_4v0_sel); } // F2 if (ff_bitmask_args[2].ffpart_bit_mask != f2_ff12xmit_4v0_sel) { log_error(LOG_SERVICE, "4v switch and part mismatch F2: 0x%x != 0x%x\r\n", - ff_bitmask_args[2].ffpart_bit_mask,f2_ff12xmit_4v0_sel); + ff_bitmask_args[2].ffpart_bit_mask, f2_ff12xmit_4v0_sel); } return ff_25gb_parts; } diff --git a/projects/cm_mcu/MonUtils.c b/projects/cm_mcu/MonUtils.c index 556f2d0c..1f75427a 100644 --- a/projects/cm_mcu/MonUtils.c +++ b/projects/cm_mcu/MonUtils.c @@ -4,7 +4,59 @@ #include "Tasks.h" #include "MonUtils.h" -#ifdef REV2 +#ifdef REV1 +int FireflyType(int device) +{ + switch (device) { + case 0: + case 1: + case 2: + case 3: + case 4: + case 5: + case 9: + case 10: + case 21: + case 22: + case 23: + case 24: + // in Rev1 there is no 3.8V so we cheat and call all of these CERN-B + return DEVICE_CERNB; + case 6: + case 7: + case 8: + case 11: + case 12: + case 13: + case 14: + case 15: + case 16: + case 17: + case 18: + case 19: + case 20: + return DEVICE_25G4; + default: + return DEVICE_NONE; + } +} + +// For rev2 clocks there is one 5341 and 4 5395s +int ClockType(int device) +{ + switch (device) { + case 0: + return DEVICE_SI5341; + case 1: + case 2: + case 3: + case 4: + return DEVICE_SI5395; + default: + return DEVICE_NONE; + } +} +#elif defined(REV2) // for 12 channel parts, there is one Tx and Rx device. // for 4 channel parts, there is one XCVR part int FireflyType(int device) @@ -47,6 +99,8 @@ int ClockType(int device) } } +#endif // REV2 + bool isEnabledFF_F2(int device) { // firefly devices on F2 are devices 10-19 @@ -81,6 +135,7 @@ struct MonitorI2CTaskArgs_new_t ff_f2_args = { .presentCallback = isEnabledFF_F2, }; +#ifdef REV2 struct MonitorI2CTaskArgs_new_t clk_args = { .name = "CLK", .devices = clk_moni2c_addrs, // FIXME: this doesn't include R0A From e97c1b77dfe4d6404ff50e918a954d9b5ae0fe86 Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Thu, 30 May 2024 11:14:39 -0400 Subject: [PATCH 34/71] remove _new and clean unused --- projects/cm_mcu/FireflyUtils.c | 16 +- projects/cm_mcu/LocalTasks.c | 285 +----------------- projects/cm_mcu/Makefile | 2 +- projects/cm_mcu/MonUtils.c | 8 +- projects/cm_mcu/MonUtils.h | 8 +- ...{MonitorTaskI2C_new.c => MonitorTaskI2C.c} | 8 +- projects/cm_mcu/MonitorTaskI2C.h | 64 ++++ projects/cm_mcu/Tasks.h | 2 +- projects/cm_mcu/clocksynth.c | 2 +- projects/cm_mcu/cm_mcu.c | 6 +- projects/cm_mcu/commands/SensorControl.c | 36 +-- sm_cm_config/data/MON_I2C_rev2.yml | 73 ++++- sm_cm_config/src/mon_generate.py | 4 +- 13 files changed, 163 insertions(+), 351 deletions(-) rename projects/cm_mcu/{MonitorTaskI2C_new.c => MonitorTaskI2C.c} (97%) create mode 100644 projects/cm_mcu/MonitorTaskI2C.h diff --git a/projects/cm_mcu/FireflyUtils.c b/projects/cm_mcu/FireflyUtils.c index d59df3bb..145783e4 100644 --- a/projects/cm_mcu/FireflyUtils.c +++ b/projects/cm_mcu/FireflyUtils.c @@ -14,7 +14,7 @@ #include "MonI2C_addresses.h" #include "MonUtils.h" -#include "MonitorTaskI2C_new.h" +#include "MonitorTaskI2C.h" #include "common/log.h" #include "Semaphore.h" @@ -237,13 +237,13 @@ float getFFavgoptpow(const uint8_t i) sum_val += get_FF_OPT_POWER_CH3_data(i); sum_val += get_FF_OPT_POWER_CH4_data(i); sum_val += get_FF_OPT_POWER_CH5_data(i); - // sum_val += get_FF_OPT_POWER_CH6_data(i); - // sum_val += get_FF_OPT_POWER_CH7_data(i); - // sum_val += get_FF_OPT_POWER_CH8_data(i); - // sum_val += get_FF_OPT_POWER_CH9_data(i); - // sum_val += get_FF_OPT_POWER_CH10_data(i); - // sum_val += get_FF_OPT_POWER_CH11_data(i); - // sum_val += get_FF_OPT_POWER_CH12_data(i); + sum_val += get_FF_OPT_POWER_CH6_data(i); + sum_val += get_FF_OPT_POWER_CH7_data(i); + sum_val += get_FF_OPT_POWER_CH8_data(i); + sum_val += get_FF_OPT_POWER_CH9_data(i); + sum_val += get_FF_OPT_POWER_CH10_data(i); + sum_val += get_FF_OPT_POWER_CH11_data(i); + sum_val += get_FF_OPT_POWER_CH12_data(i); float nchannels = 12.; if (FireflyType(i) == DEVICE_25G4) { diff --git a/projects/cm_mcu/LocalTasks.c b/projects/cm_mcu/LocalTasks.c index fca9c068..3a2ac03e 100644 --- a/projects/cm_mcu/LocalTasks.c +++ b/projects/cm_mcu/LocalTasks.c @@ -15,7 +15,7 @@ #include // struct tm #include "FireflyUtils.h" -#include "MonitorTaskI2C_new.h" +#include "MonitorTaskI2C.h" #include "driverlib/hibernate.h" #include "Tasks.h" @@ -95,15 +95,6 @@ struct dev_moni2c_addr_t ff_moni2c_addrs_f2[NFIREFLIES_F2] = { {"V12 12 Tx GTY", FF_I2CMUX_2_ADDR, 4, 0x50}, // {"V12 12 Rx GTY", FF_I2CMUX_2_ADDR, 5, 0x54}, // }; -#if 0 -struct arg_moni2c_ff_t ff_moni2c_arg[NFIREFLY_ARG] = { - {"FFL12", &ffl12_f1_args, 0, 0, 6}, // - {"FFL4", &ffl4_f1_args, 6, 0, 3}, // - {"FFL12", &ffl12_f1_args, 9, 6, 2}, // - {"FFL4", &ffl4_f2_args, 11, 0, 10}, // - {"FFL12", &ffl12_f2_args, 21, 0, 4}, // -}; -#endif // 0 #elif defined(REV2) // ------------------------------------------------- // @@ -159,14 +150,6 @@ struct dev_moni2c_addr_t ff_moni2c_addrs_f2[NFIREFLIES_F2] = { }; -#if 0 -struct arg_moni2c_ff_t ff_moni2c_arg[NFIREFLY_ARG] = { - {"FFL12", &ffl12_f1_args, 0, 0, 6}, // - {"FFL4", &ffl4_f1_args, 6, 0, 4}, // - {"FFL12", &ffl12_f2_args, 10, 0, 6}, // - {"FFL4", &ffl4_f2_args, 16, 0, 4}, // -}; -#endif // 0 #else #error "Define either Rev1 or Rev2" #endif @@ -189,84 +172,6 @@ struct dev_moni2c_addr_t ffl4_f1_moni2c_addrs[NFIREFLIES_DAQ_F1] = { // #error "Define either Rev1 or Rev2" #endif -#if 0 -struct sm_command_t sm_command_ffl4_f1[] = { - {1, 0x00, 0x02, 2, "FF_STATUS_REG", 0xff, "", PM_STATUS}, - {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, 2, "FF_CH01_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, // read 4 Rx-ch registers with increasing addresses - {2, 0x00, 0x24, 2, "FF_CH02_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, - {2, 0x00, 0x26, 2, "FF_CH03_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, - {2, 0x00, 0x28, 2, "FF_CH04_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, -}; - -uint16_t ffl4_f1_values[NDEVICES_FFL4_F1 * NCOMMANDS_FFL4_F1]; - -struct MonitorI2CTaskArgs_t ffl4_f1_args = { - .name = "F1_4", - .devices = ffl4_f1_moni2c_addrs, - .i2c_dev = I2C_DEVICE_F1, - .n_devices = NDEVICES_FFL4_F1, - .commands = sm_command_ffl4_f1, - .n_commands = NCOMMANDS_FFL4_F1, - .n_values = NDEVICES_FFL4_F1 * NPAGES_FFL4_F1 * NCOMMANDS_FFL4_F1, - .n_pages = NPAGES_FFL4_F1, - .selpage_reg = FF_SELPAGE_REG, - .sm_values = ffl4_f1_values, - // .smbus = &g_sMaster4, - // .smbus_status = &eStatus4, - .xSem = NULL, - .stack_size = 4096U, -}; - -// FF12 arguments for monitoring i2c task of 12-channel firefly ports connected to FPGA1 - -// register maps for IT-DTC Fireflies 12-ch part -- future will be CERN-B but currently is 14Gbps ECUO -struct sm_command_t sm_command_fflit_f1[] = { - {1, 0x00, 0x02, 2, "FF_STATUS_REG", 0xff, "", PM_STATUS}, - {1, 0x00, 0x16, 2, "FF_TEMPERATURE", 0xff, "C", PM_STATUS}, - {2, 0x00, 0x07, 2, "FF_LOS_ALARM", 0xffff, "", PM_STATUS}, - {2, 0x00, 0x14, 2, "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, "0.1uW", PM_STATUS}, - {1, 0x00, 0x00, 1, "FF_CH02_OPT_POW", 0xff, "0.1uW", PM_STATUS}, - {1, 0x00, 0x00, 1, "FF_CH03_OPT_POW", 0xff, "0.1uW", PM_STATUS}, - {1, 0x00, 0x00, 1, "FF_CH04_OPT_POW", 0xff, "0.1uW", PM_STATUS}, - {1, 0x00, 0x00, 1, "FF_CH05_OPT_POW", 0xff, "0.1uW", PM_STATUS}, - {1, 0x00, 0x00, 1, "FF_CH06_OPT_POW", 0xff, "0.1uW", PM_STATUS}, - {1, 0x00, 0x00, 1, "FF_CH07_OPT_POW", 0xff, "0.1uW", PM_STATUS}, - {1, 0x00, 0x00, 1, "FF_CH08_OPT_POW", 0xff, "0.1uW", PM_STATUS}, - {1, 0x00, 0x00, 1, "FF_CH09_OPT_POW", 0xff, "0.1uW", PM_STATUS}, - {1, 0x00, 0x00, 1, "FF_CH10_OPT_POW", 0xff, "0.1uW", PM_STATUS}, - {1, 0x00, 0x00, 1, "FF_CH11_OPT_POW", 0xff, "0.1uW", PM_STATUS}, - {1, 0x00, 0x00, 1, "FF_CH12_OPT_POW", 0xff, "0.1uW", 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** -struct sm_command_t sm_command_fflot_f1[] = { - {1, 0x00, 0x02, 2, "FF_STATUS_REG", 0xff, "", PM_STATUS}, - {1, 0x00, 0x16, 2, "FF_TEMPERATURE", 0xff, "C", PM_STATUS}, - {2, 0x00, 0x07, 2, "FF_LOS_ALARM", 0xffff, "", PM_STATUS}, - {2, 0x00, 0x14, 2, "FF_CDR_LOL_ALARM", 0xffff, "", PM_STATUS}, - {2, 0x01, 0xe4, 2, "FF_CH01_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, // read 12 Rx-ch registers with decreasing addresses - {2, 0x01, 0xe2, 2, "FF_CH02_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, - {2, 0x01, 0xe0, 2, "FF_CH03_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, - {2, 0x01, 0xde, 2, "FF_CH04_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, - {2, 0x01, 0xdc, 2, "FF_CH05_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, - {2, 0x01, 0xda, 2, "FF_CH06_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, - {2, 0x01, 0xd8, 2, "FF_CH07_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, - {2, 0x01, 0xd6, 2, "FF_CH08_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, - {2, 0x01, 0xd4, 2, "FF_CH09_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, - {2, 0x01, 0xd2, 2, "FF_CH10_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, - {2, 0x01, 0xd0, 2, "FF_CH11_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, - {2, 0x01, 0xce, 2, "FF_CH12_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, - -}; -#endif // 0 #ifdef REV1 struct dev_moni2c_addr_t ffl12_f1_moni2c_addrs[NFIREFLIES_IT_F1] = { {"K01 12 Tx GTH", FF_I2CMUX_1_ADDR, 0, 0x50}, // @@ -290,26 +195,6 @@ struct dev_moni2c_addr_t ffl12_f1_moni2c_addrs[NFIREFLIES_IT_F1] = { #else #error "Define either Rev1 or Rev2" #endif -#if 0 -uint16_t ffl12_f1_values[NDEVICES_FFL12_F1 * NCOMMANDS_FFL12_F1]; - -struct MonitorI2CTaskArgs_t ffl12_f1_args = { - .name = "F1_12", - .devices = ffl12_f1_moni2c_addrs, - .i2c_dev = I2C_DEVICE_F1, - .n_devices = NDEVICES_FFL12_F1, - .commands = sm_command_fflot_f1, // 25Gbps by default but if the 14Gbsp 12-ch part is found, the set of commands is changed in INIT task - .n_commands = NCOMMANDS_FFL12_F1, - .n_values = NDEVICES_FFL12_F1 * NPAGES_FFL12_F1 * NCOMMANDS_FFL12_F1, - .n_pages = NPAGES_FFL12_F1, - .selpage_reg = FF_SELPAGE_REG, - .sm_values = ffl12_f1_values, - // .smbus = &g_sMaster4, - // .smbus_status = &eStatus4, - .xSem = NULL, - .stack_size = 4096U, -}; -#endif // 0 // FFDAQV arguments for monitoring i2c task of 4-channel firefly ports connected to FPGA2 #ifdef REV1 struct dev_moni2c_addr_t ffl4_f2_moni2c_addrs[NFIREFLIES_DAQ_F2] = { @@ -324,90 +209,10 @@ struct dev_moni2c_addr_t ffl4_f2_moni2c_addrs[NFIREFLIES_DAQ_F2] = { {"V09 4 XCVR GTY", FF_I2CMUX_2_ADDR, 2, 0x50}, // {"V10 4 XCVR GTY", FF_I2CMUX_2_ADDR, 3, 0x50}, // }; -// #elif defined(REV2) -// struct dev_moni2c_addr_t ffl4_f2_moni2c_addrs[NFIREFLIES_DAQ_F2] = { -// {"F2_4 4 XCVR", FF_I2CMUX_1_ADDR, 2, 0x50}, // -// {"F2_5 4 XCVR", FF_I2CMUX_2_ADDR, 0, 0x50}, // -// {"F2_6 4 XCVR", FF_I2CMUX_2_ADDR, 1, 0x50}, // -// {"F2_7 4 XCVR", FF_I2CMUX_2_ADDR, 2, 0x50}, // -// }; // #else // #error "Define either Rev1 or Rev2" #endif -// struct sm_command_t sm_command_ffl4_f2[] = { -// {1, 0x00, 0x02, 2, "FF_STATUS_REG", 0xff, "", PM_STATUS}, -// {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, 2, "FF_CH01_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, // read 4 Rx-ch registers with increasing addresses -// {2, 0x00, 0x24, 2, "FF_CH02_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, -// {2, 0x00, 0x26, 2, "FF_CH03_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, -// {2, 0x00, 0x28, 2, "FF_CH04_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, -// }; -// uint16_t ffl4_f2_values[NDEVICES_FFL4_F2 * NCOMMANDS_FFL4_F2]; - -// struct MonitorI2CTaskArgs_t ffl4_f2_args = { -// .name = "F2_4", -// .devices = ffl4_f2_moni2c_addrs, -// .i2c_dev = I2C_DEVICE_F2, -// .n_devices = NDEVICES_FFL4_F2, -// .commands = sm_command_ffl4_f2, -// .n_commands = NCOMMANDS_FFL4_F2, -// .n_values = NDEVICES_FFL4_F2 * NPAGES_FFL4_F2 * NCOMMANDS_FFL4_F2, -// .n_pages = NPAGES_FFL4_F2, -// .selpage_reg = FF_SELPAGE_REG, -// .sm_values = ffl4_f2_values, -// // .smbus = &g_sMaster3, -// // .smbus_status = &eStatus3, -// .xSem = NULL, -// .stack_size = 4096U, -// }; - -// // FF12V arguments for monitoring i2c task of 12-channel firefly ports connected to FPGA2 - -// // register maps for IT-DTC Fireflies 12-ch part -- future will be CERN-B but currently is 14Gbps ECUO -// struct sm_command_t sm_command_fflit_f2[] = { -// {1, 0x00, 0x02, 2, "FF_STATUS_REG", 0xff, "", PM_STATUS}, -// {1, 0x00, 0x16, 2, "FF_TEMPERATURE", 0xff, "C", PM_STATUS}, -// {2, 0x00, 0x07, 2, "FF_LOS_ALARM", 0xffff, "", PM_STATUS}, -// {2, 0x00, 0x14, 2, "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, "0.1uW", PM_STATUS}, -// {1, 0x00, 0x00, 1, "FF_CH02_OPT_POW", 0xff, "0.1uW", PM_STATUS}, -// {1, 0x00, 0x00, 1, "FF_CH03_OPT_POW", 0xff, "0.1uW", PM_STATUS}, -// {1, 0x00, 0x00, 1, "FF_CH04_OPT_POW", 0xff, "0.1uW", PM_STATUS}, -// {1, 0x00, 0x00, 1, "FF_CH05_OPT_POW", 0xff, "0.1uW", PM_STATUS}, -// {1, 0x00, 0x00, 1, "FF_CH06_OPT_POW", 0xff, "0.1uW", PM_STATUS}, -// {1, 0x00, 0x00, 1, "FF_CH07_OPT_POW", 0xff, "0.1uW", PM_STATUS}, -// {1, 0x00, 0x00, 1, "FF_CH08_OPT_POW", 0xff, "0.1uW", PM_STATUS}, -// {1, 0x00, 0x00, 1, "FF_CH09_OPT_POW", 0xff, "0.1uW", PM_STATUS}, -// {1, 0x00, 0x00, 1, "FF_CH10_OPT_POW", 0xff, "0.1uW", PM_STATUS}, -// {1, 0x00, 0x00, 1, "FF_CH11_OPT_POW", 0xff, "0.1uW", PM_STATUS}, -// {1, 0x00, 0x00, 1, "FF_CH12_OPT_POW", 0xff, "0.1uW", 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** -// struct sm_command_t sm_command_fflot_f2[] = { -// {1, 0x00, 0x02, 2, "FF_STATUS_REG", 0xff, "", PM_STATUS}, -// {1, 0x00, 0x16, 2, "FF_TEMPERATURE", 0xff, "C", PM_STATUS}, -// {2, 0x00, 0x07, 2, "FF_LOS_ALARM", 0xffff, "", PM_STATUS}, -// {2, 0x00, 0x14, 2, "FF_CDR_LOL_ALARM", 0xffff, "", PM_STATUS}, -// {2, 0x01, 0xe4, 2, "FF_CH01_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, // read 12 Rx-ch registers with decreasing addresses -// {2, 0x01, 0xe2, 2, "FF_CH02_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, -// {2, 0x01, 0xe0, 2, "FF_CH03_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, -// {2, 0x01, 0xde, 2, "FF_CH04_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, -// {2, 0x01, 0xdc, 2, "FF_CH05_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, -// {2, 0x01, 0xda, 2, "FF_CH06_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, -// {2, 0x01, 0xd8, 2, "FF_CH07_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, -// {2, 0x01, 0xd6, 2, "FF_CH08_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, -// {2, 0x01, 0xd4, 2, "FF_CH09_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, -// {2, 0x01, 0xd2, 2, "FF_CH10_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, -// {2, 0x01, 0xd0, 2, "FF_CH11_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, -// {2, 0x01, 0xce, 2, "FF_CH12_OPT_POW", 0xffff, "0.1uW", PM_STATUS}, -// }; #ifdef REV1 struct dev_moni2c_addr_t ffl12_f2_moni2c_addrs[NFIREFLIES_IT_F2] = { @@ -429,24 +234,6 @@ struct dev_moni2c_addr_t ffl12_f2_moni2c_addrs[NFIREFLIES_IT_F2] = { #error "Define either Rev1 or Rev2" #endif -// uint16_t ffl12_f2_values[NDEVICES_FFL12_F2 * NCOMMANDS_FFL12_F2]; - -// struct MonitorI2CTaskArgs_t ffl12_f2_args = { -// .name = "F2_12", -// .devices = ffl12_f2_moni2c_addrs, -// .i2c_dev = I2C_DEVICE_F2, -// .n_devices = NDEVICES_FFL12_F2, -// .commands = sm_command_fflot_f2, // 25Gbps by default but if the 14Gbsp 12-ch part is found, the set of commands is changed in INIT task -// .n_commands = NCOMMANDS_FFL12_F2, -// .n_values = NDEVICES_FFL12_F2 * NPAGES_FFL12_F2 * NCOMMANDS_FFL12_F2, -// .n_pages = NPAGES_FFL12_F2, -// .selpage_reg = FF_SELPAGE_REG, -// .sm_values = ffl12_f2_values, -// // .smbus = &g_sMaster3, -// // .smbus_status = &eStatus3, -// .xSem = NULL, -// .stack_size = 4096U, -// }; #ifdef REV2 // Clock arguments for monitoring task @@ -459,12 +246,6 @@ struct clk_program_t clkprog_args[] = { {"", ""}, // }; -// struct dev_moni2c_addr_t clk_moni2c_addrs[CLOCK_NUM_SI5395] = { -// {"r0b", 0x70, 1, 0x6b, 0x264E}, // CLK R0B : Si5395-REVA #regs = 587 (read at 0x1F7D in EEPROM) if change, addr 0x264E will have to change -// {"r1a", 0x70, 2, 0x6b, 0x464E}, // CLK R1A : Si5395-REVA #regs = 587 (read at 0x5F7D in EEPROM) if change, addr 0x464E will have to change -// {"r1b", 0x70, 3, 0x6b, 0x664E}, // CLK R1B : Si5395-REVA #regs = 584 (read at 0x7F7D in EEPROM) if change, addr 0x664E will have to change -// {"r1c", 0x70, 4, 0x6b, 0x864E}, // CLK R1C : Si5395-REVA #regs = 587 (read at 0x9F7D in EEPROM) if change, addr 0x864E will have to change -// }; struct dev_moni2c_addr_t clk_moni2c_addrs[NDEVICES_CLK] = { {"r0a", 0x70, 0, 0x77, 0x45D}, // CLK R0A : Si5341-REVD with #regs = 378 (read at 0x1F7D in EEPROM) if change, addr 0x45D will have to change {"r0b", 0x70, 1, 0x6b, 0x264E}, // CLK R0B : Si5395-REVA #regs = 587 (read at 0x1F7D in EEPROM) if change, addr 0x264E will have to change @@ -473,70 +254,6 @@ struct dev_moni2c_addr_t clk_moni2c_addrs[NDEVICES_CLK] = { {"r1c", 0x70, 4, 0x6b, 0x864E}, // CLK R1C : Si5395-REVA #regs = 587 (read at 0x9F7D in EEPROM) if change, addr 0x864E will have to change }; -// struct sm_command_t sm_command_clk[NCOMMANDS_CLK_TMP] = { -// // device information on page 0 : table 16.2 and 16.4 -// {1, 0x00, 0x02, 2, "PN_BASE", 0xffff, "", PM_STATUS}, // page 0x00 -// {1, 0x00, 0x05, 1, "DEVICE_REV", 0xff, "", PM_STATUS}, // page 0x00 -// {1, 0x00, 0x0B, 1, "I2C_ADDR", 0x7f, "", PM_STATUS}, // page 0x00 -// // internal statuses on page 0 : table 16.8 and 16.9 -// {1, 0x00, 0x0C, 1, "LOSXAXB", 0x02, "", PM_STATUS}, // page 0x00 -// {1, 0x00, 0x0D, 1, "LOSOOF_IN", 0xff, "", PM_STATUS}, // page 0x00 -// {1, 0x00, 0x0E, 1, "LOL", 0x02, "", PM_STATUS}, // page 0x00 -// // internal error flags : table 16.12 -// {1, 0x00, 0x11, 1, "STICKY_FLG", 0x27, "", PM_STATUS}, // page 0x00 -// }; - -// uint16_t clk_values[NDEVICES_CLK * NPAGES_CLK * NCOMMANDS_CLK_TMP]; - -// struct MonitorI2CTaskArgs_t clock_args = { -// .name = "CLKSI", -// .devices = clk_moni2c_addrs, -// .i2c_dev = I2C_DEVICE_CLK, -// .n_devices = NDEVICES_CLK, -// .commands = sm_command_clk, -// .n_commands = NCOMMANDS_CLK_TMP, -// .n_values = NDEVICES_CLK * NPAGES_CLK * NCOMMANDS_CLK_TMP, -// .n_pages = NPAGES_CLK, -// .selpage_reg = CLK_SELPAGE_REG, -// .sm_values = clk_values, -// .xSem = NULL, -// .stack_size = 4096U, -// }; - -// struct dev_moni2c_addr_t clkr0a_moni2c_addrs[CLOCK_NUM_SI5341] = { -// {"r0a", 0x70, 0, 0x77, 0x45D}, // CLK R0A : Si5341-REVD with #regs = 378 (read at 0x1F7D in EEPROM) if change, addr 0x45D will have to change -// }; - -// struct sm_command_t sm_command_clkr0a[] = { -// // device information on page 0 : table 14.4 and 14.6 -// {1, 0x00, 0x02, 2, "PN_BASE", 0xffff, "", PM_STATUS}, // page 0x00 -// {1, 0x00, 0x05, 1, "DEVICE_REV", 0xff, "", PM_STATUS}, // page 0x00 -// {1, 0x00, 0x0B, 1, "I2C_ADDR", 0xff, "", PM_STATUS}, // page 0x00 -// // internal statuses on page 0 : table 14.5 -// {1, 0x00, 0x0C, 1, "STATUS", 0x35, "", PM_STATUS}, // page 0x00 -// {1, 0x00, 0x0D, 1, "LOS", 0x15, "", PM_STATUS}, // page 0x00 -// // sticky bits of status bits : table 14.12 -// {1, 0x00, 0x12, 1, "LOSIN_FLG", 0xf, "", PM_STATUS}, // page 0x00 -// // sticky bits of status bits : table 14.12 -// {1, 0x00, 0x11, 1, "STICKY_FLG", 0x2f, "", PM_STATUS}, // page 0x00 -// }; - -// uint16_t clkr0a_values[NDEVICES_CLKR0A * NPAGES_CLKR0A * NCOMMANDS_CLK_TMPR0A]; - -// struct MonitorI2CTaskArgs_t clockr0a_args = { -// .name = "CLKR0A", -// .devices = clkr0a_moni2c_addrs, -// .i2c_dev = I2C_DEVICE_CLK, -// .n_devices = NDEVICES_CLKR0A, -// .commands = sm_command_clkr0a, -// .n_commands = NCOMMANDS_CLK_TMPR0A, -// .n_values = NDEVICES_CLKR0A * NPAGES_CLKR0A * NCOMMANDS_CLK_TMPR0A, -// .n_pages = NPAGES_CLKR0A, -// .selpage_reg = CLK_SELPAGE_REG, -// .sm_values = clkr0a_values, -// .xSem = NULL, -// .stack_size = 4096U, -// }; #endif // REV2 #define FPGA_MON_NDEVICES_PER_FPGA 2 diff --git a/projects/cm_mcu/Makefile b/projects/cm_mcu/Makefile index c16245b9..bae3e4c5 100644 --- a/projects/cm_mcu/Makefile +++ b/projects/cm_mcu/Makefile @@ -164,7 +164,7 @@ ${COMPILER}/cm_mcu.axf: ${COMPILER}/EEPROMTask.o ${COMPILER}/cm_mcu.axf: ${COMPILER}/PowerSupplyTask.o ${COMPILER}/cm_mcu.axf: ${COMPILER}/ADCMonitorTask.o ${COMPILER}/cm_mcu.axf: ${COMPILER}/MonitorTask.o -${COMPILER}/cm_mcu.axf: ${COMPILER}/MonitorTaskI2C_new.o +${COMPILER}/cm_mcu.axf: ${COMPILER}/MonitorTaskI2C.o ${COMPILER}/cm_mcu.axf: ${COMPILER}/I2CSlaveTask.o ${COMPILER}/cm_mcu.axf: ${COMPILER}/GenericAlarmTask.o ${COMPILER}/cm_mcu.axf: ${COMPILER}/AlarmUtilities.o diff --git a/projects/cm_mcu/MonUtils.c b/projects/cm_mcu/MonUtils.c index 1f75427a..0d3ccd43 100644 --- a/projects/cm_mcu/MonUtils.c +++ b/projects/cm_mcu/MonUtils.c @@ -1,4 +1,4 @@ -#include "MonitorTaskI2C_new.h" +#include "MonitorTaskI2C.h" #include "MonI2C_addresses.h" #include "FireflyUtils.h" #include "Tasks.h" @@ -107,7 +107,7 @@ bool isEnabledFF_F2(int device) return isEnabledFF(device + NFIREFLIES_F1); } -struct MonitorI2CTaskArgs_new_t ff_f1_args = { +struct MonitorTaskI2CArgs_t ff_f1_args = { .name = "FF_F1", .devices = ff_moni2c_addrs_f1, .i2c_dev = I2C_DEVICE_F1, @@ -121,7 +121,7 @@ struct MonitorI2CTaskArgs_new_t ff_f1_args = { .presentCallback = isEnabledFF, }; -struct MonitorI2CTaskArgs_new_t ff_f2_args = { +struct MonitorTaskI2CArgs_t ff_f2_args = { .name = "FF_F2", .devices = ff_moni2c_addrs_f2, .i2c_dev = I2C_DEVICE_F2, @@ -136,7 +136,7 @@ struct MonitorI2CTaskArgs_new_t ff_f2_args = { }; #ifdef REV2 -struct MonitorI2CTaskArgs_new_t clk_args = { +struct MonitorTaskI2CArgs_t clk_args = { .name = "CLK", .devices = clk_moni2c_addrs, // FIXME: this doesn't include R0A .i2c_dev = I2C_DEVICE_CLK, diff --git a/projects/cm_mcu/MonUtils.h b/projects/cm_mcu/MonUtils.h index 2368ac1e..e55dad73 100644 --- a/projects/cm_mcu/MonUtils.h +++ b/projects/cm_mcu/MonUtils.h @@ -1,16 +1,16 @@ #ifndef MONUTILS_H #define MONUTILS_H -#include "MonitorTaskI2C_new.h" +#include "MonitorTaskI2C.h" int FireflyType(int device); int ClockType(int device); // firefly monitoring -extern struct MonitorI2CTaskArgs_new_t ff_f1_args; -extern struct MonitorI2CTaskArgs_new_t ff_f2_args; +extern struct MonitorTaskI2CArgs_t ff_f1_args; +extern struct MonitorTaskI2CArgs_t ff_f2_args; // clock monitoring -extern struct MonitorI2CTaskArgs_new_t clk_args; +extern struct MonitorTaskI2CArgs_t clk_args; extern struct dev_moni2c_addr_t clk_moni2c_addrs[NDEVICES_CLK]; diff --git a/projects/cm_mcu/MonitorTaskI2C_new.c b/projects/cm_mcu/MonitorTaskI2C.c similarity index 97% rename from projects/cm_mcu/MonitorTaskI2C_new.c rename to projects/cm_mcu/MonitorTaskI2C.c index 975d1bb4..13af51e3 100644 --- a/projects/cm_mcu/MonitorTaskI2C_new.c +++ b/projects/cm_mcu/MonitorTaskI2C.c @@ -1,5 +1,5 @@ /* - * MonitorI2CTask_new.c + * MonitorTaskI2C.c * * Created on: June 30, 2022 * Author: pkotamnives @@ -20,7 +20,7 @@ // local includes #include "common/smbus_helper.h" -#include "MonitorTaskI2C_new.h" +#include "MonitorTaskI2C.h" #include "common/log.h" #include "Tasks.h" #include "I2CCommunication.h" @@ -49,10 +49,10 @@ bool getFFch_high(uint8_t val, int channel) } // Monitor registers of FF temperatures, voltages, currents, and ClK statuses via I2C -void MonitorI2CTask_new(void *parameters) +void MonitorTaskI2C(void *parameters) { - struct MonitorI2CTaskArgs_new_t *args = parameters; + struct MonitorTaskI2CArgs_t *args = parameters; configASSERT(args->name != 0); diff --git a/projects/cm_mcu/MonitorTaskI2C.h b/projects/cm_mcu/MonitorTaskI2C.h new file mode 100644 index 00000000..31aca1fe --- /dev/null +++ b/projects/cm_mcu/MonitorTaskI2C.h @@ -0,0 +1,64 @@ +/* + * MonitorI2CTask.h + * + */ + +#ifndef PROJECTS_CM_MCU_MONITORI2CTASKNEW_H_ +#define PROJECTS_CM_MCU_MONITORI2CTASKNEW_H_ + +#include "FreeRTOS.h" // IWYU pragma: keep +#include "semphr.h" +#include "Tasks.h" + +struct i2c_reg_command_t { + int reg_size; // number of bytes of register/command + unsigned char page; // I2C page address + unsigned char command[4]; // I2c register address + int size; // number of bytes to read + char *name; // text describing command + uint16_t bit_mask; // begin bit mask + char *units; // units for pretty printing + enum pm_type type; // how to decode command (L11 or bitfield or ...) + uint16_t (*devicelist)(void); + void (*storeData)(uint16_t data, int which); // store data in location which + uint16_t (*retrieveData)(int which); // retrieve data from location which +}; + +// how to find an I2C device, with a mux infront of it. + +typedef bool (*MonTaskFcnPointer)(int device); +typedef int (*MonTaskI2CTypeFcnPointer)(int); // what kind of device we have (i.e., for FF, CERN-B, B04, Y12-14, Y12-25, etc.) + +struct MonitorTaskI2CArgs_t { + const char *name; // name to be assigned to the task + struct dev_moni2c_addr_t *devices; // list of devices to query + int i2c_dev; // i2c controller # + int n_devices; // number of devices + struct i2c_reg_command_t *commands; // list of commands + const uint8_t n_commands; // number of commands + const uint16_t selpage_reg; // register for selecting page + TickType_t updateTick; // last update time, in ticks + SemaphoreHandle_t xSem; // semaphore for controlling access to device + UBaseType_t stack_size; // stack size of task + MonTaskFcnPointer presentCallback; // callback for present check + MonTaskI2CTypeFcnPointer typeCallback; // callback for type check +}; + +#define FF_SELPAGE_REG 0x7f +#define CLK_SELPAGE_REG 0x1 + +#define NDEVICES_CLK 5 + +// for autogenerated code +#define DEVICE_CERNB 0x01 +#define DEVICE_14G 0x02 +#define DEVICE_25G4 0x04 +#define DEVICE_25G12 0x08 +#define DEVICE_SI5341 0x01 +#define DEVICE_SI5395 0x02 + +#define DEVICE_NONE 0x80 + +extern struct dev_moni2c_addr_t clk_moni2c_addrs[NDEVICES_CLK]; + +#endif /* PROJECTS_CM_MCU_MONITORI2CTASKNEW_H_ */ diff --git a/projects/cm_mcu/Tasks.h b/projects/cm_mcu/Tasks.h index 608ae0eb..e6ca4c90 100644 --- a/projects/cm_mcu/Tasks.h +++ b/projects/cm_mcu/Tasks.h @@ -112,7 +112,7 @@ void LGA80D_init(void); // --- Semi-generic PMBUS based I2C task void MonitorTask(void *parameters); void MonitorI2CTask(void *parameters); -void MonitorI2CTask_new(void *parameters); +void MonitorTaskI2C(void *parameters); #ifdef REV1 #define N_PM_ADDRS_DCDC 5 #elif defined(REV2) // REV2 diff --git a/projects/cm_mcu/clocksynth.c b/projects/cm_mcu/clocksynth.c index 94b97032..c05bbecb 100644 --- a/projects/cm_mcu/clocksynth.c +++ b/projects/cm_mcu/clocksynth.c @@ -7,7 +7,7 @@ #include #include -#include "MonitorTaskI2C_new.h" +#include "MonitorTaskI2C.h" #include "common/smbus_helper.h" #include "clocksynth.h" #include "I2CCommunication.h" diff --git a/projects/cm_mcu/cm_mcu.c b/projects/cm_mcu/cm_mcu.c index 72234340..696374fd 100644 --- a/projects/cm_mcu/cm_mcu.c +++ b/projects/cm_mcu/cm_mcu.c @@ -289,11 +289,11 @@ __attribute__((noreturn)) int main(void) xTaskCreate(ADCMonitorTask, "ADC", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 4, NULL); #ifdef REV2 - xTaskCreate(MonitorI2CTask_new, ff_f1_args.name, 2 * configMINIMAL_STACK_SIZE, &ff_f1_args, tskIDLE_PRIORITY + 4, + xTaskCreate(MonitorTaskI2C, ff_f1_args.name, 2 * configMINIMAL_STACK_SIZE, &ff_f1_args, tskIDLE_PRIORITY + 4, NULL); - xTaskCreate(MonitorI2CTask_new, ff_f2_args.name, 2 * configMINIMAL_STACK_SIZE, &ff_f2_args, tskIDLE_PRIORITY + 4, + xTaskCreate(MonitorTaskI2C, ff_f2_args.name, 2 * configMINIMAL_STACK_SIZE, &ff_f2_args, tskIDLE_PRIORITY + 4, NULL); - xTaskCreate(MonitorI2CTask_new, clk_args.name, 2 * configMINIMAL_STACK_SIZE, &clk_args, tskIDLE_PRIORITY + 4, + xTaskCreate(MonitorTaskI2C, clk_args.name, 2 * configMINIMAL_STACK_SIZE, &clk_args, tskIDLE_PRIORITY + 4, NULL); #endif // REV2 diff --git a/projects/cm_mcu/commands/SensorControl.c b/projects/cm_mcu/commands/SensorControl.c index 28005e17..d1431382 100644 --- a/projects/cm_mcu/commands/SensorControl.c +++ b/projects/cm_mcu/commands/SensorControl.c @@ -10,7 +10,7 @@ #include "FireflyUtils.h" #include "I2CCommunication.h" #include "MonI2C_addresses.h" -#include "MonitorTaskI2C_new.h" +#include "MonitorTaskI2C.h" #include "common/log.h" #include "common/utils.h" #include "parameters.h" @@ -942,8 +942,7 @@ BaseType_t ff_temp(int argc, char **argv, char *m) // argument handling int copied = 0; - // static int whichff = 0; - static int nn = 0; //, n = 0; + static int nn = 0; if (nn == 0) { // check for stale data @@ -958,35 +957,6 @@ BaseType_t ff_temp(int argc, char **argv, char *m) copied += snprintf(m + copied, SCRATCH_SIZE - copied, "FF Temperature:\r\n"); } -#if 0 - int i1 = 1; // 1 for temperature - - for (; n < NFIREFLY_ARG; ++n) { - struct MonitorI2CTaskArgs_t *ff_arg = ff_moni2c_arg[n].arg; - for (; whichff < ff_moni2c_arg[n].int_idx + ff_moni2c_arg[n].num_dev; ++whichff) { - int dev = whichff - ff_moni2c_arg[n].int_idx + ff_moni2c_arg[n].dev_int_idx; - if (isEnabledFF(ff_moni2c_arg[n].int_idx + dev)) { - int index = dev * (ff_arg->n_commands * ff_arg->n_pages) + i1; - uint8_t val = ff_arg->sm_values[index]; - copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%17s: %2d", ff_moni2c_addrs[whichff].name, val); - } - else // dummy value - copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%17s: %2s", ff_moni2c_addrs[whichff].name, "--"); - - bool isTx = (strstr(ff_moni2c_addrs[whichff].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; - copied = 0; - return pdTRUE; - } - } - copied += snprintf(m+copied, SCRATCH_SIZE - copied, "-------\r\n"); -#endif - // static int nn = 0; for (; nn < NFIREFLIES; ++nn) { if (isEnabledFF(nn)) { uint8_t val = get_FF_TEMPERATURE_data(nn); @@ -1012,8 +982,6 @@ BaseType_t ff_temp(int argc, char **argv, char *m) m[copied++] = '\n'; m[copied] = '\0'; } - // whichff = 0; - // n = 0; return pdFALSE; } diff --git a/sm_cm_config/data/MON_I2C_rev2.yml b/sm_cm_config/data/MON_I2C_rev2.yml index 6e7065da..eb80f247 100644 --- a/sm_cm_config/data/MON_I2C_rev2.yml +++ b/sm_cm_config/data/MON_I2C_rev2.yml @@ -45,7 +45,7 @@ define: &FF_SHARED_REGS - name: OPT_POWER_CH1 reg_size: 1 page: 0 - reg_address: [-1, -1, 0x22, 0xe4] + reg_address: [-1, -1, 34, 228] size: 2 mask: 0xFFFF units: uW @@ -54,7 +54,7 @@ define: &FF_SHARED_REGS - name: OPT_POWER_CH2 reg_size: 1 page: 0 - reg_address: [-1, -1, 0x24, 0xe2] + reg_address: [-1, -1, 36, 226] size: 2 mask: 0xFFFF units: uW @@ -63,7 +63,7 @@ define: &FF_SHARED_REGS - name: OPT_POWER_CH3 reg_size: 1 page: 0 - reg_address: [-1, -1, 0x26, 0xe0] + reg_address: [-1, -1, 38, 224] size: 2 mask: 0xFFFF units: uW @@ -72,7 +72,7 @@ define: &FF_SHARED_REGS - name: OPT_POWER_CH4 reg_size: 1 page: 0 - reg_address: [-1, -1, 0x28, 0xde] + reg_address: [-1, -1, 40, 222] size: 2 mask: 0xFFFF units: uW @@ -81,7 +81,70 @@ define: &FF_SHARED_REGS - name: OPT_POWER_CH5 reg_size: 1 page: 0 - reg_address: [-1, -1, -1, 0xdc] + reg_address: [-1, -1, -1, 220] + size: 2 + mask: 0xFFFF + units: uW + type: PM_VOLTAGE + devicetypes: [25G12] + - name: OPT_POWER_CH6 + reg_size: 1 + page: 0 + reg_address: [-1, -1, -1, 218] + size: 2 + mask: 0xFFFF + units: uW + type: PM_VOLTAGE + devicetypes: [25G12] + - name: OPT_POWER_CH7 + reg_size: 1 + page: 0 + reg_address: [-1, -1, -1, 216] + size: 2 + mask: 0xFFFF + units: uW + type: PM_VOLTAGE + devicetypes: [25G12] + - name: OPT_POWER_CH8 + reg_size: 1 + page: 0 + reg_address: [-1, -1, -1, 214] + size: 2 + mask: 0xFFFF + units: uW + type: PM_VOLTAGE + devicetypes: [25G12] + - name: OPT_POWER_CH9 + reg_size: 1 + page: 0 + reg_address: [-1, -1, -1, 212] + size: 2 + mask: 0xFFFF + units: uW + type: PM_VOLTAGE + devicetypes: [25G12] + - name: OPT_POWER_CH10 + reg_size: 1 + page: 0 + reg_address: [-1, -1, -1, 210] + size: 2 + mask: 0xFFFF + units: uW + type: PM_VOLTAGE + devicetypes: [25G12] + - name: OPT_POWER_CH11 + reg_size: 1 + page: 0 + reg_address: [-1, -1, -1, 208] + size: 2 + mask: 0xFFFF + units: uW + type: PM_VOLTAGE + devicetypes: [25G12] + - name: OPT_POWER_CH12 + reg_size: 1 + page: 0 + reg_address: [-1, -1, -1, 206] size: 2 mask: 0xFFFF units: uW diff --git a/sm_cm_config/src/mon_generate.py b/sm_cm_config/src/mon_generate.py index 5e2517c1..777c5934 100755 --- a/sm_cm_config/src/mon_generate.py +++ b/sm_cm_config/src/mon_generate.py @@ -74,13 +74,13 @@ def write_boilderplate(fout: io.TextIOWrapper): write_boilderplate(fout_source) write_boilderplate(fout_header) print(f"#include \"{header_fname}\"", file=fout_source) - #print("#include \"MonitorTaskI2C_new.h\"", file=fout_source) + #print("#include \"MonitorTaskI2C.h\"", file=fout_source) # header file print(r"#ifndef MON_I2C_ADDRESSES_H", file=fout_header) print(r"#define MON_I2C_ADDRESSES_H", file=fout_header) print("#include ", file=fout_header) - print("#include \"MonitorTaskI2C_new.h\"", file=fout_header) + print("#include \"MonitorTaskI2C.h\"", file=fout_header) print("#include \"FireflyUtils.h\"", file=fout_source) #print("#include \"MonitorI2CTask.h\"", file=fout_source) From 0ce7788d340d4a902eb563a9e7dfea5573fdd2c9 Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Thu, 30 May 2024 11:25:35 -0400 Subject: [PATCH 35/71] format checks --- Makefile | 4 ++-- build_all.sh | 1 + projects/cm_mcu/LocalTasks.c | 2 -- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index adf2da79..e441c3af 100644 --- a/Makefile +++ b/Makefile @@ -44,9 +44,9 @@ check-for-pr: format # 2nd dollar sign in grep is to pass along a single dollar sign to make format: - run-clang-format.py $(shell git diff --diff-filter=AM --name-only master | egrep '.[ch]$$') + run-clang-format.py $(shell git diff --diff-filter=AM --name-only master | egrep '\.[ch]$$') format-apply: - run-clang-format.py -i $(shell git diff --diff-filter=AM --name-only master | egrep '.[ch]$$') + run-clang-format.py -i $(shell git diff --diff-filter=AM --name-only master | egrep '\.[ch]$$') .PHONY: all clean $(DIRS) $(DIRSCLEAN) check-and-reinit-submodules diff --git a/build_all.sh b/build_all.sh index 23fe27b7..b43e331a 100755 --- a/build_all.sh +++ b/build_all.sh @@ -21,5 +21,6 @@ make COMPILER=clang clean make -j REV1=1 COMPILER=clang > /dev/null make COMPILER=clang clean make -j REV2=1 COMPILER=clang > /dev/null +make format > /dev/null echo "all build succeeded." diff --git a/projects/cm_mcu/LocalTasks.c b/projects/cm_mcu/LocalTasks.c index 3a2ac03e..633d9043 100644 --- a/projects/cm_mcu/LocalTasks.c +++ b/projects/cm_mcu/LocalTasks.c @@ -213,7 +213,6 @@ struct dev_moni2c_addr_t ffl4_f2_moni2c_addrs[NFIREFLIES_DAQ_F2] = { // #error "Define either Rev1 or Rev2" #endif - #ifdef REV1 struct dev_moni2c_addr_t ffl12_f2_moni2c_addrs[NFIREFLIES_IT_F2] = { {"V11 12 Tx GTY", FF_I2CMUX_1_ADDR, 6, 0x50}, // @@ -234,7 +233,6 @@ struct dev_moni2c_addr_t ffl12_f2_moni2c_addrs[NFIREFLIES_IT_F2] = { #error "Define either Rev1 or Rev2" #endif - #ifdef REV2 // Clock arguments for monitoring task From 5868012cc3432cf4951cd390735993b185dfb1fb Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Fri, 31 May 2024 09:47:58 -0400 Subject: [PATCH 36/71] speed up initial check of FF types w 4 byte reads --- projects/cm_mcu/FireflyUtils.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/projects/cm_mcu/FireflyUtils.c b/projects/cm_mcu/FireflyUtils.c index 145783e4..a7b2d9f5 100644 --- a/projects/cm_mcu/FireflyUtils.c +++ b/projects/cm_mcu/FireflyUtils.c @@ -19,7 +19,6 @@ #include "Semaphore.h" #include "I2CCommunication.h" -#include "common/smbus_helper.h" #include "driverlib/eeprom.h" #include "FireflyUtils.h" @@ -284,10 +283,13 @@ uint32_t ff_map_25gb_parts(void) } int ret = 0; // build up name of the device (vendor string) - for (unsigned char c = 0; c < count; ++c) { - uint8_t v; - ret += read_arbitrary_ff_register(startReg + c, i, &v, 1); - name[c] = v; + for (unsigned char c = 0; c < count/4; ++c) { + uint8_t v[4]; + ret += read_arbitrary_ff_register(startReg + 4*c, i, v, 4); + name[4 * c] = v[0]; + name[4 * c + 1] = v[1]; + name[4 * c + 2] = v[2]; + name[4 * c + 3] = v[3]; } if (ret != 0) { log_error(LOG_SERVICE, "Error reading vendor string for FF %d\r\n", i); From d258b1ec1201f733357038ab99402dbca8363cd6 Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Fri, 31 May 2024 09:49:19 -0400 Subject: [PATCH 37/71] further cleanups --- .clangd | 3 ++- projects/cm_mcu/I2CCommunication.c | 18 +----------------- projects/cm_mcu/InitTask.c | 4 ---- projects/cm_mcu/LocalTasks.c | 3 --- projects/cm_mcu/MonUtils.c | 2 +- projects/cm_mcu/MonitorTaskI2C.c | 21 --------------------- projects/cm_mcu/PowerSupplyTask.c | 4 +--- projects/cm_mcu/Tasks.h | 2 +- projects/cm_mcu/ZynqMonTask.c | 8 +++----- projects/cm_mcu/commands/SensorControl.c | 4 ++-- projects/cm_mcu/commands/SensorControl.h | 2 +- 11 files changed, 12 insertions(+), 59 deletions(-) diff --git a/.clangd b/.clangd index 8cd23b26..8011e789 100644 --- a/.clangd +++ b/.clangd @@ -2,4 +2,5 @@ Diagnostics: ClangTidy: Add: modernize* Remove: readability-braces-around-statements - +CompileFlags: + Add: [-Wunused-parameter] diff --git a/projects/cm_mcu/I2CCommunication.c b/projects/cm_mcu/I2CCommunication.c index 6a66a2fd..3ae49d45 100644 --- a/projects/cm_mcu/I2CCommunication.c +++ b/projects/cm_mcu/I2CCommunication.c @@ -7,28 +7,14 @@ #include #include -#include "inc/hw_types.h" -#include "inc/hw_memmap.h" -#include "inc/hw_nvic.h" -#include "driverlib/rom.h" -#include "driverlib/rom_map.h" -#include "driverlib/systick.h" -#include "driverlib/sysctl.h" -#include "driverlib/eeprom.h" // local includes -#include "common/i2c_reg.h" -#include "common/LocalUart.h" -#include "common/power_ctl.h" -#include "common/pinsel.h" #include "common/smbus.h" -#include "common/utils.h" -#include "common/microrl.h" #include "common/log.h" // FreeRTOS includes #include "FreeRTOSConfig.h" -#include "FreeRTOS.h" +#include "FreeRTOS.h" // IWYU pragma: keep #include "stream_buffer.h" #include "queue.h" @@ -36,8 +22,6 @@ #include #include -// TivaWare includes -#include "driverlib/uart.h" #include "Tasks.h" #include "I2CCommunication.h" diff --git a/projects/cm_mcu/InitTask.c b/projects/cm_mcu/InitTask.c index c4c830b2..647d7697 100644 --- a/projects/cm_mcu/InitTask.c +++ b/projects/cm_mcu/InitTask.c @@ -11,13 +11,9 @@ #include #include "FireflyUtils.h" -#include "FreeRTOS.h" -#include "FreeRTOSConfig.h" #include "task.h" #include "driverlib/rom.h" -#include "driverlib/eeprom.h" -#include "driverlib/sysctl.h" #include "common/utils.h" #include "common/log.h" #include "Tasks.h" diff --git a/projects/cm_mcu/LocalTasks.c b/projects/cm_mcu/LocalTasks.c index 633d9043..1906c649 100644 --- a/projects/cm_mcu/LocalTasks.c +++ b/projects/cm_mcu/LocalTasks.c @@ -29,9 +29,6 @@ #include "I2CCommunication.h" #include "common/log.h" -#define NCOMMANDS_CLK_TMP 7 -#define NCOMMANDS_CLK_TMPR0A 7 - #ifdef REV1 // ------------------------------------------------- // diff --git a/projects/cm_mcu/MonUtils.c b/projects/cm_mcu/MonUtils.c index 0d3ccd43..23a3da73 100644 --- a/projects/cm_mcu/MonUtils.c +++ b/projects/cm_mcu/MonUtils.c @@ -138,7 +138,7 @@ struct MonitorTaskI2CArgs_t ff_f2_args = { #ifdef REV2 struct MonitorTaskI2CArgs_t clk_args = { .name = "CLK", - .devices = clk_moni2c_addrs, // FIXME: this doesn't include R0A + .devices = clk_moni2c_addrs, .i2c_dev = I2C_DEVICE_CLK, .n_devices = NDEVICES_CLK, .commands = sm_command_test_CLK, diff --git a/projects/cm_mcu/MonitorTaskI2C.c b/projects/cm_mcu/MonitorTaskI2C.c index 13af51e3..f05e6295 100644 --- a/projects/cm_mcu/MonitorTaskI2C.c +++ b/projects/cm_mcu/MonitorTaskI2C.c @@ -26,27 +26,6 @@ #include "I2CCommunication.h" #include "Semaphore.h" -// local prototype - -// read-only accessor functions for Firefly names and values. - -bool getFFch_low(uint8_t val, int channel) -{ - configASSERT(channel < 8); - if (!((1 << channel) & val)) { - return false; - } - return true; -} - -bool getFFch_high(uint8_t val, int channel) -{ - configASSERT(channel >= 8); - if (!((1 << (channel - 8)) & val)) { - return false; - } - return true; -} // Monitor registers of FF temperatures, voltages, currents, and ClK statuses via I2C void MonitorTaskI2C(void *parameters) diff --git a/projects/cm_mcu/PowerSupplyTask.c b/projects/cm_mcu/PowerSupplyTask.c index 98a9458a..87c28536 100644 --- a/projects/cm_mcu/PowerSupplyTask.c +++ b/projects/cm_mcu/PowerSupplyTask.c @@ -14,15 +14,13 @@ // local includes #include "FireflyUtils.h" #include "Tasks.h" -#include "common/i2c_reg.h" -#include "common/pinout.h" #include "common/pinsel.h" #include "common/power_ctl.h" #include "common/utils.h" #include "common/log.h" // FreeRTOS includes -#include "FreeRTOS.h" +#include "FreeRTOS.h" // IWYU pragma: keep #include "FreeRTOSConfig.h" #include "queue.h" diff --git a/projects/cm_mcu/Tasks.h b/projects/cm_mcu/Tasks.h index e6ca4c90..85a84167 100644 --- a/projects/cm_mcu/Tasks.h +++ b/projects/cm_mcu/Tasks.h @@ -276,7 +276,7 @@ void zm_set_firefly_info(struct zynqmon_data_t data[], int start); void zm_set_adcmon(struct zynqmon_data_t data[], int start); void zm_set_psmon_legacy(struct zynqmon_data_t data[], int start); void zm_set_psmon(struct zynqmon_data_t data[], int start); -void zm_set_clock(struct zynqmon_data_t data[], int start, int n); +void zm_set_clock(struct zynqmon_data_t data[], int start); void zm_set_fpga(struct zynqmon_data_t data[], int start); void zm_set_allclk(struct zynqmon_data_t data[], int start); diff --git a/projects/cm_mcu/ZynqMonTask.c b/projects/cm_mcu/ZynqMonTask.c index 1be720dd..a03b8c17 100644 --- a/projects/cm_mcu/ZynqMonTask.c +++ b/projects/cm_mcu/ZynqMonTask.c @@ -300,7 +300,7 @@ void zm_set_firefly_temps(struct zynqmon_data_t data[], int start) #ifdef REV2 uint16_t getFFtXdisablebit(const uint8_t i) { - return 56; // FIXME + return 56; // FIXME: reimplement this #ifdef NOTDEF if (i > NFIREFLIES_F1 + NFIREFLIES_F2) { log_warn(LOG_SERVICE, "caught %d > total fireflies %d\r\n", i, NFIREFLIES); @@ -526,12 +526,10 @@ void zm_set_psmon(struct zynqmon_data_t data[], int start) } } -void zm_set_clock(struct zynqmon_data_t data[], int start, int n) +void zm_set_clock(struct zynqmon_data_t data[], int start) { // MonitorI2CTask values -- clock chips - // update times, in seconds. If the data is stale, send NaN - // n=1 is r0a and n=0 is else - // struct MonitorI2CTaskArgs_t args_st[2] = {clockr0a_args, clock_args}; + // update times, in seconds. If the data is stale, send 56 TickType_t last = pdTICKS_TO_S(clk_args.updateTick); TickType_t now = pdTICKS_TO_S(xTaskGetTickCount()); diff --git a/projects/cm_mcu/commands/SensorControl.c b/projects/cm_mcu/commands/SensorControl.c index d1431382..945bf549 100644 --- a/projects/cm_mcu/commands/SensorControl.c +++ b/projects/cm_mcu/commands/SensorControl.c @@ -265,7 +265,7 @@ static int write_arbitrary_ff_register(uint16_t regnumber, uint8_t value, int nu return ret; } -// read a SINGLE firefly register, one byte only +// read a SINGLE firefly register, size bytes (up to 4 bytes) uint16_t read_arbitrary_ff_register(uint16_t regnumber, int num_ff, uint8_t *value, uint8_t size) { if (num_ff >= NFIREFLIES) { @@ -278,7 +278,7 @@ uint16_t read_arbitrary_ff_register(uint16_t regnumber, int num_ff, uint8_t *val else { i2c_dev = I2C_DEVICE_F2; } - int ret = read_ff_register(ff_moni2c_addrs[num_ff].name, regnumber, value, 1, i2c_dev); + int ret = read_ff_register(ff_moni2c_addrs[num_ff].name, regnumber, value, size, i2c_dev); return ret; } diff --git a/projects/cm_mcu/commands/SensorControl.h b/projects/cm_mcu/commands/SensorControl.h index 3e8b0da2..99af5585 100644 --- a/projects/cm_mcu/commands/SensorControl.h +++ b/projects/cm_mcu/commands/SensorControl.h @@ -7,7 +7,7 @@ #ifndef SENSOR_CONTROL_H_ #define SENSOR_CONTROL_H_ -#include "parameters.h" +#include "FreeRTOS.h" // IWYU pragma: keep // Register definitions // ------------------------------------------------- From 5bc5d5e67e65a3a50062d5234eaf918305cf78fc Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Tue, 28 May 2024 11:07:39 -0400 Subject: [PATCH 38/71] Update SensorControl.c --- projects/cm_mcu/commands/SensorControl.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/projects/cm_mcu/commands/SensorControl.c b/projects/cm_mcu/commands/SensorControl.c index 000f6b71..8a7c2401 100644 --- a/projects/cm_mcu/commands/SensorControl.c +++ b/projects/cm_mcu/commands/SensorControl.c @@ -62,6 +62,14 @@ int read_ff_register(const char *name, uint16_t packed_reg_addr, uint8_t *value, SMBUS_get_error(res), ff_moni2c_addrs[ff].name); } } + if (!res) { // clear the mux + muxmask = 0x0U; + res = apollo_i2c_ctl_w(i2c_device, ff_moni2c_addrs[ff].mux_addr, 1, muxmask); + if (res !=0) { + log_warn(LOG_SERVICE, "%s: Mux clear error %d (%s) (ff=%s) ...\r\n", __func__, res, + SMBUS_get_error(res), ff_moni2c_addrs[ff].name); + } + } // release the semaphore if (xSemaphoreGetMutexHolder(s) == xTaskGetCurrentTaskHandle()) @@ -111,6 +119,14 @@ static int write_ff_register(const char *name, uint8_t reg, uint16_t value, int SMBUS_get_error(res), ff_moni2c_addrs[ff].name); } } + if (!res) { // clear the mux + muxmask = 0x0U; + res = apollo_i2c_ctl_w(i2c_device, ff_moni2c_addrs[ff].mux_addr, 1, muxmask); + if (res != 0) { + log_warn(LOG_SERVICE, "%s: Mux clear error %d (%s) (ff=%s) ...\r\n", __func__, res, + SMBUS_get_error(res), ff_moni2c_addrs[ff].name); + } + } // release the semaphore if (xSemaphoreGetMutexHolder(s) == xTaskGetCurrentTaskHandle()) @@ -173,10 +189,10 @@ static int disable_receivers(bool disable, int num_ff) i2c_dev = I2C_DEVICE_F2; } if (strstr(ff_moni2c_addrs[i].name, "XCVR") != NULL) { - value = 0xf; + value &= 0x000fU; // only 4 LSB matter, so mask out others ret += write_ff_register(ff_moni2c_addrs[i].name, ECU0_25G_XVCR_RX_DISABLE_REG, value, 1, i2c_dev); } - else if (strstr(ff_moni2c_addrs[i].name, "Rx") != NULL) { + else if (strstr(ff_moni2c_addrs[i].name, "Rx") != NULL) { // FIXME: check for CERNB vs 25G ret += write_ff_register(ff_moni2c_addrs[i].name, ECU0_14G_RX_DISABLE_REG, value, 2, i2c_dev); } } From c9b55107339c1226ab7003e3cd4eb8350172ce8f Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Fri, 31 May 2024 16:52:25 -0400 Subject: [PATCH 39/71] sync yaml files, reimplement disable bit sending --- projects/cm_mcu/MonitorTaskI2C.h | 6 ++-- projects/cm_mcu/ZynqMonTask.c | 30 ++-------------- sm_cm_config/data/MON_I2C_rev2.yml | 9 +++++ sm_cm_config/data/PL_MEM_CM_rev2.yml | 53 ++++++++++++++-------------- 4 files changed, 41 insertions(+), 57 deletions(-) diff --git a/projects/cm_mcu/MonitorTaskI2C.h b/projects/cm_mcu/MonitorTaskI2C.h index 31aca1fe..a0169f93 100644 --- a/projects/cm_mcu/MonitorTaskI2C.h +++ b/projects/cm_mcu/MonitorTaskI2C.h @@ -3,8 +3,8 @@ * */ -#ifndef PROJECTS_CM_MCU_MONITORI2CTASKNEW_H_ -#define PROJECTS_CM_MCU_MONITORI2CTASKNEW_H_ +#ifndef PROJECTS_CM_MCU_MONITORTASKI2C_H_ +#define PROJECTS_CM_MCU_MONITORTASKI2C_H_ #include "FreeRTOS.h" // IWYU pragma: keep #include "semphr.h" @@ -61,4 +61,4 @@ struct MonitorTaskI2CArgs_t { extern struct dev_moni2c_addr_t clk_moni2c_addrs[NDEVICES_CLK]; -#endif /* PROJECTS_CM_MCU_MONITORI2CTASKNEW_H_ */ +#endif /* PROJECTS_CM_MCU_MONITORTASKI2C_H_ */ diff --git a/projects/cm_mcu/ZynqMonTask.c b/projects/cm_mcu/ZynqMonTask.c index a03b8c17..da076893 100644 --- a/projects/cm_mcu/ZynqMonTask.c +++ b/projects/cm_mcu/ZynqMonTask.c @@ -15,6 +15,7 @@ // to be moved #include "FireflyUtils.h" +#include "MonI2C_addresses.h" #include "MonUtils.h" #include "inc/hw_memmap.h" #include "driverlib/rom.h" @@ -300,34 +301,7 @@ void zm_set_firefly_temps(struct zynqmon_data_t data[], int start) #ifdef REV2 uint16_t getFFtXdisablebit(const uint8_t i) { - return 56; // FIXME: reimplement this -#ifdef NOTDEF - if (i > NFIREFLIES_F1 + NFIREFLIES_F2) { - log_warn(LOG_SERVICE, "caught %d > total fireflies %d\r\n", i, NFIREFLIES); - return 56; - } - uint8_t val = 56; - int i2c_dev; - if (!isEnabledFF(i)) // skip the FF if it's not enabled via the FF config - return val; - if (i < NFIREFLIES_F1) { - i2c_dev = I2C_DEVICE_F1; - } - else { - i2c_dev = I2C_DEVICE_F2; - } - int ret = -99; - if (strstr(ff_moni2c_addrs[i].name, "XCVR") != NULL) { - ret = read_ff_register(ff_moni2c_addrs[i].name, ECU0_25G_XVCR_TX_DISABLE_REG, &val, 1, i2c_dev); - } - else if (strstr(ff_moni2c_addrs[i].name, "Tx") != NULL) { - ret = read_ff_register(ff_moni2c_addrs[i].name, ECU0_14G_TX_DISABLE_REG, &val, 1, i2c_dev); - } - if (ret != 0) - return 56; - else - return val; -#endif // NOTDEF + return get_FF_CHANNEL_DISABLE_data(i); } // updated once per loop. // For each firefly device, send diff --git a/sm_cm_config/data/MON_I2C_rev2.yml b/sm_cm_config/data/MON_I2C_rev2.yml index eb80f247..8f133a42 100644 --- a/sm_cm_config/data/MON_I2C_rev2.yml +++ b/sm_cm_config/data/MON_I2C_rev2.yml @@ -150,6 +150,15 @@ define: &FF_SHARED_REGS units: uW type: PM_VOLTAGE devicetypes: [25G12] + - name: CHANNEL_DISABLE + reg_size: 1 + page: 0 + reg_address: [52, 52, 86, 52] + size: 2 + mask: 0xFFF + units: "" + type: PM_STATUS + devicetypes: [CERNB, 14G, 25G4, 25G12] devices: - name: Fireflies_F1 diff --git a/sm_cm_config/data/PL_MEM_CM_rev2.yml b/sm_cm_config/data/PL_MEM_CM_rev2.yml index bac3097e..676d0c36 100644 --- a/sm_cm_config/data/PL_MEM_CM_rev2.yml +++ b/sm_cm_config/data/PL_MEM_CM_rev2.yml @@ -130,44 +130,45 @@ config: - F2_TEMP_SLR1 - F2_TEMP_SLR2 - F2_TEMP_SLR3 - - name: clkmonr0a - start: 186 - count: 8 - type: uint16_t - extra: Table=CM_CLK_MON;Status=1 - mcu_call: clock - mcu_extra_call: 0 - names: - - R0A - postfixes: - - PN_BASE0 - - PN_BASE1 - - DEVICE_REV - - I2C_ADDR - - STATUS_OR_LOSXAXB - - LOS_OR_LOSOOF_IN - - LOSIN_FLG_OR_LOL - - STICKY_FLG + # - name: clkmonr0a + # start: 186 + # count: 8 + # type: uint16_t + # extra: Table=CM_CLK_MON;Status=1 + # mcu_call: clock + # mcu_extra_call: 0 + # names: + # - R0A + # postfixes: + # - PN_BASE0 + # - PN_BASE1 + # - DEVICE_REV + # - I2C_ADDR + # - STATUS_OR_LOSXAXB + # - LOS_OR_LOSOOF_IN + # - LOSIN_FLG_OR_LOL + # - STICKY_FLG - name: clkmon - start: 195 - count: 32 + start: 186 + count: 40 type: uint16_t extra: Table=CM_CLK_MON;Status=1 mcu_call: clock - mcu_extra_call: 1 + mcu_extra_call: null names: + - ROA - R0B - R1A - R1B - R1C postfixes: - - PN_BASE0 - - PN_BASE1 + - PN_BASE - DEVICE_REV - I2C_ADDR - - STATUS_OR_LOSXAXB - - LOS_OR_LOSOOF_IN - - LOSIN_FLG_OR_LOL + - STATUS + - LOL + - LOSXAXB + - LOSOOF_IN - STICKY_FLG - name: clkr0aconfigversion start: 228 From 7625d226e02f9f727fc5da86a49cf1f778e4b659 Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Fri, 31 May 2024 17:20:29 -0400 Subject: [PATCH 40/71] formatting, sizes --- projects/cm_mcu/FireflyUtils.c | 6 +++--- projects/cm_mcu/I2CCommunication.c | 1 - projects/cm_mcu/MonUtils.c | 2 +- projects/cm_mcu/MonitorTaskI2C.c | 1 - 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/projects/cm_mcu/FireflyUtils.c b/projects/cm_mcu/FireflyUtils.c index a7b2d9f5..fdad4541 100644 --- a/projects/cm_mcu/FireflyUtils.c +++ b/projects/cm_mcu/FireflyUtils.c @@ -283,10 +283,10 @@ uint32_t ff_map_25gb_parts(void) } int ret = 0; // build up name of the device (vendor string) - for (unsigned char c = 0; c < count/4; ++c) { + for (int c = 0; c < count / 4; ++c) { uint8_t v[4]; - ret += read_arbitrary_ff_register(startReg + 4*c, i, v, 4); - name[4 * c] = v[0]; + ret += read_arbitrary_ff_register(startReg + 4 * c, i, v, 4); + name[4 * c] = v[0]; name[4 * c + 1] = v[1]; name[4 * c + 2] = v[2]; name[4 * c + 3] = v[3]; diff --git a/projects/cm_mcu/I2CCommunication.c b/projects/cm_mcu/I2CCommunication.c index 3ae49d45..6141c1f6 100644 --- a/projects/cm_mcu/I2CCommunication.c +++ b/projects/cm_mcu/I2CCommunication.c @@ -22,7 +22,6 @@ #include #include - #include "Tasks.h" #include "I2CCommunication.h" #include "common/smbus_helper.h" diff --git a/projects/cm_mcu/MonUtils.c b/projects/cm_mcu/MonUtils.c index 23a3da73..5b6d253e 100644 --- a/projects/cm_mcu/MonUtils.c +++ b/projects/cm_mcu/MonUtils.c @@ -138,7 +138,7 @@ struct MonitorTaskI2CArgs_t ff_f2_args = { #ifdef REV2 struct MonitorTaskI2CArgs_t clk_args = { .name = "CLK", - .devices = clk_moni2c_addrs, + .devices = clk_moni2c_addrs, .i2c_dev = I2C_DEVICE_CLK, .n_devices = NDEVICES_CLK, .commands = sm_command_test_CLK, diff --git a/projects/cm_mcu/MonitorTaskI2C.c b/projects/cm_mcu/MonitorTaskI2C.c index f05e6295..4c745239 100644 --- a/projects/cm_mcu/MonitorTaskI2C.c +++ b/projects/cm_mcu/MonitorTaskI2C.c @@ -26,7 +26,6 @@ #include "I2CCommunication.h" #include "Semaphore.h" - // Monitor registers of FF temperatures, voltages, currents, and ClK statuses via I2C void MonitorTaskI2C(void *parameters) { From 788ce069bccdfdeb7c9b2d7f2e35d4a73031339e Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Fri, 31 May 2024 23:18:34 -0400 Subject: [PATCH 41/71] wip --- projects/cm_mcu/CommandLineTask.c | 2 +- projects/cm_mcu/ZynqMonTask.c | 2 +- projects/cm_mcu/commands/SensorControl.c | 163 +++++------------------ sm_cm_config/data/PL_MEM_CM_rev2.yml | 17 ++- sm_cm_config/src/xml_generate.py | 30 +++-- 5 files changed, 67 insertions(+), 147 deletions(-) diff --git a/projects/cm_mcu/CommandLineTask.c b/projects/cm_mcu/CommandLineTask.c index d029f7bb..76474a11 100644 --- a/projects/cm_mcu/CommandLineTask.c +++ b/projects/cm_mcu/CommandLineTask.c @@ -315,7 +315,7 @@ static struct command_t commands[] = { { "ff_optpow", ff_optpow, - "Showing the FF per-ch optical power \r\n", + "Showing avg FF optical power\r\n", 0, }, { diff --git a/projects/cm_mcu/ZynqMonTask.c b/projects/cm_mcu/ZynqMonTask.c index da076893..90edabdc 100644 --- a/projects/cm_mcu/ZynqMonTask.c +++ b/projects/cm_mcu/ZynqMonTask.c @@ -517,7 +517,7 @@ void zm_set_clock(struct zynqmon_data_t data[], int start) data[ll].data.us = 56; // special stale value } else { - data[ll].data.us = clk_args.commands[j].retrieveData(j); + data[ll].data.us = clk_args.commands[k].retrieveData(j); } data[ll].sensor = ll + start; ++ll; diff --git a/projects/cm_mcu/commands/SensorControl.c b/projects/cm_mcu/commands/SensorControl.c index 945bf549..4c089a53 100644 --- a/projects/cm_mcu/commands/SensorControl.c +++ b/projects/cm_mcu/commands/SensorControl.c @@ -989,142 +989,41 @@ BaseType_t ff_temp(int argc, char **argv, char *m) // loop over all channels on all devices and show optical power BaseType_t ff_optpow(int argc, char **argv, char *m) { - // argument handling - snprintf(m, SCRATCH_SIZE, "FF Optical Power: to be implemented anew\r\n"); - return pdFALSE; - // it appears that this in its current implementation prints optical power of every channel on every device. - // that would be over 100 channels, which is too much for a single command. -#if 0 + // takes no arguments + static int i = 0; int copied = 0; - static int whichff = 0; - static int n = 0; - static int i1 = 4; - - if (whichff == 0) { - // check for stale data - if (isFFStale()) { - TickType_t now = pdTICKS_TO_S(xTaskGetTickCount()); - TickType_t last = pdTICKS_TO_S(getFFupdateTick(isFFStale())); - int mins = (now - last) / 60; - copied += snprintf(m + copied, SCRATCH_SIZE - copied, - "%s: stale data, last update %d minutes ago\r\n", argv[0], mins); - } - copied += snprintf(m + copied, SCRATCH_SIZE - copied, "FF Optical Power:\r\n"); + if ( i == 0 ) { + copied += snprintf(m, SCRATCH_SIZE, "FF average Optical Power\r\n"); } - - for (; whichff < NFIREFLIES; ++whichff) { - // skip transmitters - if (strstr(ff_moni2c_addrs[whichff].name, "Tx") != NULL) - continue; - // skip if not enabled or present - if (!isEnabledFF(whichff)) - continue; - // loop over all channels. for XCVR, 4 channels. for Tx devices, 12 channels - int maxchan = 12; - if (FireflyType(whichff)==DEVICE_25G4) { - maxchan = 4; - } - uint16_t val; - // firefly channels are labled 1-12 - for ( int c = 1; c <= maxchan; ++c) { - switch (c) { - case 1: - val = get_FF_OPT_POWER_CH1_data(c); - break; - case 2: - val = get_FF_OPT_POWER_CH2_data(c); - break; - case 3: - val = get_FF_F1_OPT_POWER_CH3_data(c); - break; - case 4: - val = get_FF_F1_OPT_POWER_CH4_data(c); - break; - case 5: - val = get_FF_F1_OPT_POWER_CH5_data(c); - break; - default: - val = 0; - break; - // case 6: - // val = get_FF_F1_OPT_POWER_CH6_data(c); - // break; - // case 7: - // val = get_FF_F1_OPT_POWER_CH7_data(c); - // break; - // case 8: - // val = get_FF_F1_OPT_POWER_CH8_data(c); - // break; - // case 9: - // val = get_FF_F1_OPT_POWER_CH9_data(c); - // break; - // case 10: - // val = get_FF_F1_OPT_POWER_CH10_data(c); - // break; - // case 11: - // val = get_FF_F1_OPT_POWER_CH11_data(c); - // break; - // case 12: - // val = get_FF_F1_OPT_POWER_CH12_data(c); - // break; - } - } - for (; n < NFIREFLY_ARG; ++n) { - struct MonitorI2CTaskArgs_t *ff_arg = ff_moni2c_arg[n].arg; - for (; whichff < ff_moni2c_arg[n].int_idx + ff_moni2c_arg[n].num_dev; ++whichff) { - - int dev = whichff - ff_moni2c_arg[n].int_idx + ff_moni2c_arg[n].dev_int_idx; - - if (strstr(ff_moni2c_addrs[whichff].name, "Tx") != NULL) - continue; - if (isEnabledFF(ff_moni2c_arg[n].int_idx + dev)) { - i1 = 4; - copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%17s: \r\n", ff_moni2c_addrs[whichff].name); - for (; i1 < ff_arg->n_commands; ++i1) { - int index = dev * (ff_arg->n_commands * ff_arg->n_pages) + i1; - uint8_t val = ff_arg->sm_values[index]; - if ((SCRATCH_SIZE - copied) < 20) { - return pdTRUE; - } - - if ((i1 - 4) % 6 == 0) - copied += snprintf(m + copied, SCRATCH_SIZE - copied, "CH%2d: %2d \t", i1 - 3, val); - else if ((i1 - 4) % 6 == 1) - copied += snprintf(m + copied, SCRATCH_SIZE - copied, "CH%2d: %2d \t", i1 - 3, val); - else if ((i1 - 4) % 6 == 2) - copied += snprintf(m + copied, SCRATCH_SIZE - copied, "CH%2d: %2d \t", i1 - 3, val); - else if ((i1 - 4) % 6 == 3) - copied += snprintf(m + copied, SCRATCH_SIZE - copied, "CH%2d: %2d \t", i1 - 3, val); - else if ((i1 - 4) % 6 == 4) - copied += snprintf(m + copied, SCRATCH_SIZE - copied, "CH%2d: %2d \t", i1 - 3, val); - else - copied += snprintf(m + copied, SCRATCH_SIZE - copied, "CH%2d: %2d \r\n", i1 - 3, val); - } - - copied += snprintf(m + copied, SCRATCH_SIZE - copied, "\r\n"); - } - else // dummy value - copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%17s: %2s \r\n", ff_moni2c_addrs[whichff].name, "--"); - - if ((SCRATCH_SIZE - copied) < 20) { - ++whichff; - return pdTRUE; - } + for (; i < NFIREFLIES; ++i ) { + bool isTx = (strstr(ff_moni2c_addrs[i].name, "Tx") != NULL); + if (isEnabledFF(i) && !isTx ) { + float val = getFFavgoptpow(i); + int tens, frac; + float_to_ints(val, &tens, &frac); + copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%17s: % 5d.%02d", + ff_moni2c_addrs[i].name, tens, frac); } - } - - if (whichff % 2 == 1) { - m[copied++] = '\r'; - m[copied++] = '\n'; - m[copied] = '\0'; - } - whichff = 0; - n = 0; - i1 = 4; + else { + copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%17s: ---", + ff_moni2c_addrs[i].name); + } + if (isTx) { + copied += snprintf(m + copied, SCRATCH_SIZE - copied, "\t\t"); + } + else { + copied += snprintf(m + copied, SCRATCH_SIZE - copied, "\r\n"); + } + if ((SCRATCH_SIZE - copied) < 20) { + ++i; + return pdTRUE; + } + } // loop over NFIREFLIES + i = 0; return pdFALSE; -} -#endif // 0 -} +} + + // this command takes up to two arguments BaseType_t ff_ctl(int argc, char **argv, char *m) { diff --git a/sm_cm_config/data/PL_MEM_CM_rev2.yml b/sm_cm_config/data/PL_MEM_CM_rev2.yml index 676d0c36..969643a2 100644 --- a/sm_cm_config/data/PL_MEM_CM_rev2.yml +++ b/sm_cm_config/data/PL_MEM_CM_rev2.yml @@ -13,6 +13,7 @@ config: mcu_extra_call: null type: uint16_t extra: Table=CM_FF_MON;Status=1 + default_col: null # if null, then column header names: - F1_P1_Tx12 - F1_P1_Rx12 @@ -45,6 +46,7 @@ config: mcu_call: uptime mcu_extra_call: null extra: Table=CM_MON;Column=Minutes;Status=1 + default_col: null names: - MCU_UPTIME - name: psmon @@ -54,6 +56,7 @@ config: mcu_extra_call: null type: fp16 extra: Table=CM_MON;Status=2 + default_col: null names: - 1V8 - 3V3 @@ -83,6 +86,7 @@ config: size: 5 mcu_call: gitversion mcu_extra_call: null + default_col: null names: - MCU_FW_VER - name: adcmon @@ -90,8 +94,9 @@ config: count: 21 mcu_call: adcmon mcu_extra_call: null + default_col: ADC type: fp16 - extra: Table=CM_MON;Status=1;Column=ADC + extra: Table=CM_MON;Status=1 names: - VCC_V120 - VCC_MV33 @@ -118,7 +123,8 @@ config: start: 177 count: 8 type: fp16 - extra: Table=CM_MON;Column=Temp_C;Status=2; + extra: Table=CM_MON;Status=2 + default_col: TEMP_C mcu_call: fpga mcu_extra_call: null names: @@ -155,6 +161,7 @@ config: extra: Table=CM_CLK_MON;Status=1 mcu_call: clock mcu_extra_call: null + default_col: null names: - ROA - R0B @@ -176,6 +183,7 @@ config: type: char size: 2 mcu_call: clkconfigversion + default_col: null mcu_extra_call: 0 names: - MCU_CLKR0A_VER @@ -185,6 +193,7 @@ config: type: char size: 2 mcu_call: clkconfigversion + default_col: null mcu_extra_call: 1 names: - MCU_CLKR0B_VER @@ -194,6 +203,7 @@ config: type: char size: 2 mcu_call: clkconfigversion + default_col: null mcu_extra_call: 2 names: - MCU_CLKR1A_VER @@ -203,6 +213,7 @@ config: type: char size: 2 mcu_call: clkconfigversion + default_col: null mcu_extra_call: 3 names: - MCU_CLKR1B_VER @@ -212,6 +223,7 @@ config: type: char size: 2 mcu_call: clkconfigversion + default_col: null mcu_extra_call: 4 names: - MCU_CLKR1C_VER @@ -220,6 +232,7 @@ config: count: 8 type: uint16_t extra: Table=CM_FFARGV_MON;Status=1 + default_col: null mcu_call: firefly_bits mcu_extra_call: null names: diff --git a/sm_cm_config/src/xml_generate.py b/sm_cm_config/src/xml_generate.py index 320fbe99..1e626546 100644 --- a/sm_cm_config/src/xml_generate.py +++ b/sm_cm_config/src/xml_generate.py @@ -16,6 +16,7 @@ def make_node(parent: ET.Element, myid: str, thedict: dict, addr2: int, bit: int #I disable this check because as far as I can tell it's wrong thenode = ET.SubElement(parent, 'node') myid = myid.replace(' ', '_') + print(f"myid: {myid}") thenode.set('id', myid) #address is half of the sensor address since these are 32 bit addresses theaddr = int(addr2/2) @@ -57,7 +58,16 @@ def make_node(parent: ET.Element, myid: str, thedict: dict, addr2: int, bit: int extra = thedict['extra'] if not "Column" in extra: #this semicolon asks for no semicolon in extra when postfixes are included - extra = extra + ";Column=" + myid + if 'default_col' in thedict and thedict['default_col'] is not None: + colid = thedict['default_col'] + else: + colid = myid + # for some special patterns, generate a different column id + if myid.lower().startswith("cur_"): + colid = "IOUT" + elif "temp" in myid.lower(): + colid = "TEMP_C" + extra = extra + ";Column=" + colid if not "Row" in extra: if parent_id != "": extra = "Row=" + parent_id + ";" + extra @@ -155,8 +165,8 @@ def yaml_file(filename): cm = ET.Element('node') cm.set('id', 'CM') cm.set('address', '0x00000000') -prev_addr = 0x0 #keep track of the most recent address that comes into a pair of bytes for 8-bit masking -prev_j = 0x0 #keep track of the order of postfixes in each name node +prev_addr = 0x0 #keep track of the most recent address that comes into a pair of bytes for 8-bit masking +prev_j = 0x0 #keep track of the order of postfixes in each name node prev_bit = 0x0 #keep track of the even or odd order of bytes globally sent for masking #% % config = y['config'] @@ -166,8 +176,6 @@ def yaml_file(filename): start = c['start'] count = c['count'] for n in names: # loop over names of sensors within a category - if (n=="R0B" and start!=prev_start+prev_count+1): #clkmonr0a and clkmon are from the same function in zynqmontask - print("warning: the start address of clkmon should continue from clkr0a") if 'postfixes' in c: postfixes = c['postfixes'] j = 0 @@ -178,7 +186,7 @@ def yaml_file(filename): i += 1 j += 1 continue - if (bit == 1 and j == 0): #the previous name node has odd bytes so this postfix node uses the previous postfix address but masks off the lower byte + if (bit == 1 and j == 0): #the previous name node has odd bytes so this postfix node uses the previous postfix address but masks off the lower byte pp = node = ET.SubElement(cm, 'node') pp.set('id', n) pp.set('address', str(hex(prev_addr))) @@ -188,15 +196,15 @@ def yaml_file(filename): pp.set('id', n) pp.set('address', str(hex(addr))) node = make_node(pp, p, c, j, bit, n) - else: # any non-first byte in a name node - if (prev_bit == 0): #the upper byte of the previous postfix node + else: # any non-first byte in a name node + if prev_bit == 0: #the upper byte of the previous postfix node node = make_node(pp, p, c, j, bit, n) - else : #the low byte with an increasing postfix node by one + else : #the low byte with an increasing postfix node by one node = make_node(pp, p, c, j+1, bit, n) if (prev_bit == bit and prev_addr == addr and prev_addr != 0) : print("warning : please check if masks overlapped at node ", n, " addr ", hex(prev_addr)) prev_addr = addr - prev_j = j + prev_j = j prev_bit = bit i += 1 j += 1 @@ -205,7 +213,7 @@ def yaml_file(filename): if (prev_bit == (start+i)%2 and prev_addr == int((start+i)/2) and prev_addr != 0) : print("warning : please check if masks overlapped at node ", n, " addr ", hex(prev_addr)) prev_addr = int((start + i)/2) - prev_bit = (start+i)%2 + prev_bit = (start+i)%2 i += 1 prev_start = start prev_count = count From 53147183d605e0b2c2f2e71c822aca585be20357 Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Sat, 1 Jun 2024 22:08:54 -0400 Subject: [PATCH 42/71] cleanup and fix Rev1 --- common/utils.c | 4 +- projects/cm_mcu/CommandLineTask.c | 2 +- projects/cm_mcu/FireflyUtils.c | 130 ++--------------------- projects/cm_mcu/PowerSupplyTask.c | 1 - projects/cm_mcu/clocksynth.c | 6 +- projects/cm_mcu/cm_mcu.c | 2 +- projects/cm_mcu/commands/SensorControl.c | 130 +---------------------- sm_cm_config/src/xml_generate.py | 17 +-- 8 files changed, 29 insertions(+), 263 deletions(-) diff --git a/common/utils.c b/common/utils.c index 776753cd..486ca22a 100644 --- a/common/utils.c +++ b/common/utils.c @@ -9,13 +9,11 @@ #include "common/utils.h" #include "common/pinsel.h" -#include "common/printf.h" -#include "driverlib/gpio.h" #include "driverlib/rom.h" #include "driverlib/rom_map.h" #include "driverlib/debug.h" #include "driverlib/eeprom.h" -#include "FreeRTOS.h" +#include "FreeRTOS.h" // IWYU pragma: keep #include "Tasks.h" typedef struct error_buffer_t error_buffer_t; diff --git a/projects/cm_mcu/CommandLineTask.c b/projects/cm_mcu/CommandLineTask.c index 76474a11..bcfcf515 100644 --- a/projects/cm_mcu/CommandLineTask.c +++ b/projects/cm_mcu/CommandLineTask.c @@ -311,13 +311,13 @@ static struct command_t commands[] = { "dump name registers\r\n", 0, }, -#endif // REV2 { "ff_optpow", ff_optpow, "Showing avg FF optical power\r\n", 0, }, +#endif // REV2 { "ff_temp", ff_temp, diff --git a/projects/cm_mcu/FireflyUtils.c b/projects/cm_mcu/FireflyUtils.c index fdad4541..c36bd942 100644 --- a/projects/cm_mcu/FireflyUtils.c +++ b/projects/cm_mcu/FireflyUtils.c @@ -149,10 +149,10 @@ void readFFpresent(void) ((present_FFL12_BOTTOM_F1)); // 6 bits #elif defined(REV2) - present_FFL12_F1 = present_FFL12_F1 & 0x3FU; // bottom 6 bits - present_FFL12_F2 = present_FFL12_F2 & 0x3FU; // bottom 6 bits - present_FFL4_F1 = (present_FFL4_F1 >> 4) & 0xFU; // bits 4-7 - present_FFL4_F2 = (present_FFL4_F2 >> 4) & 0xFU; // bits 4-7 + present_FFL12_F1 = present_FFL12_F1 & 0x3FU; // bottom 6 bits + present_FFL12_F2 = present_FFL12_F2 & 0x3FU; // bottom 6 bits + present_FFL4_F1 = (present_FFL4_F1 >> 4) & 0xFU; // bits 4-7 + present_FFL4_F2 = (present_FFL4_F2 >> 4) & 0xFU; // bits 4-7 uint32_t ff_combined_present = ((present_FFL4_F2) << 16) | // 4 bits ((present_FFL12_F2) << 10) | // 6 bits @@ -244,11 +244,11 @@ float getFFavgoptpow(const uint8_t i) sum_val += get_FF_OPT_POWER_CH11_data(i); sum_val += get_FF_OPT_POWER_CH12_data(i); - float nchannels = 12.; + float nchannels = 12.f; if (FireflyType(i) == DEVICE_25G4) { - nchannels = 4.; + nchannels = 4.f; } - return sum_val / nchannels; + return (float)sum_val / nchannels; } uint16_t getFFpresentbit(const uint8_t i) @@ -263,6 +263,7 @@ uint16_t getFFpresentbit(const uint8_t i) } // figure out which parts are 25G and which are not, for 12 channel parts +// sets ff_bitmask_args[0].ffpart_bit_mask and ff_bitmask_args[2].ffpart_bit_mask uint32_t ff_map_25gb_parts(void) { uint32_t ff_25gb_parts = 0U; @@ -324,119 +325,4 @@ uint32_t ff_map_25gb_parts(void) } return ff_25gb_parts; } - -// currently this function does the following -// decide which commands to run for the 12 channel part, i.e., -// decide if we have CERN-B or 25 Gbps part on the 12 channel sites -// it then sets the command struct in the MonitorI2CTaskArgs_t struct -// nad also sets a bitmask to show which 12 channel sites have 25 Gbps part -void getFFpart(void) -{ - return; - // // Write device vendor part for identifying FF device - // uint8_t nstring = VENDOR_STOP_BIT_FF12 - VENDOR_START_BIT_FF12 + 1; - // char vendor_string[nstring]; - // uint8_t data; - - // SemaphoreHandle_t semaphores[2] = {i2c4_sem, i2c3_sem}; - // const int ff_ndev_offset[2] = {0, NFIREFLIES_IT_F1 + NFIREFLIES_DAQ_F1}; - // const uint32_t ndevices[2] = {NDEVICES_FFL12_F1 / 2, NDEVICES_FFL12_F2 / 2}; - // const uint32_t dev_present_mask[2] = {present_FFL12_F1, present_FFL12_F2}; - // const uint32_t dev_xmit_4v0_sel[2] = {f1_ff12xmit_4v0_sel, f2_ff12xmit_4v0_sel}; - - // struct MonitorI2CTaskArgs_t args_st[2] = {ffl12_f1_args, ffl12_f2_args}; - - // for (int f = 0; f < 2; ++f) { // loop over FPGAs - - // // grab the semaphore to ensure unique access to I2C controller - // // otherwise, block its operations indefinitely until it's available - // acquireI2CSemaphoreBlock(semaphores[f]); - // uint32_t tmp_ffpart_bit_mask = 0U; - // bool detect_ff = false; - // for (uint32_t n = 0; n < ndevices[f]; n++) { - // uint8_t vendor_data_rxch[4]; - // int8_t vendor_part_rxch[17]; - - // data = 0x1U << args_st[f].devices[(2 * n) + 1].mux_bit; - // log_debug(LOG_SERVICE, "Mux set to 0x%02x\r\n", data); - // int rmux = apollo_i2c_ctl_w(args_st[f].i2c_dev, args_st[f].devices[(2 * n) + 1].mux_addr, 1, data); - // if (rmux != 0) { - // log_warn(LOG_SERVICE, "Mux write error %s\r\n", SMBUS_get_error(rmux)); - // } - // for (uint8_t i = VENDOR_START_BIT_FF12; i < VENDOR_STOP_BIT_FF12; i++) { - // uint32_t vendor_char_rxch; - // int res = apollo_i2c_ctl_reg_r(args_st[f].i2c_dev, args_st[f].devices[(2 * n) + 1].dev_addr, 1, (uint16_t)i, 1, &vendor_char_rxch); - // if (res != 0) { - // log_warn(LOG_SERVICE, "GetFFpart read Error %s, break\r\n", SMBUS_get_error(res)); - // vendor_part_rxch[i - VENDOR_START_BIT_FF12] = 0; - // break; - // } - // for (int j = 0; j < 4; ++j) { - // vendor_data_rxch[j] = (vendor_char_rxch >> (3 - j) * 8) & 0xFF; - // } - // convert_8_t tmp1; - // tmp1.us = vendor_data_rxch[3]; // change from uint_8 to int8_t, preserving bit pattern - // vendor_part_rxch[i - VENDOR_START_BIT_FF12] = tmp1.s; - // vendor_part_rxch[i - VENDOR_START_BIT_FF12 + 1] = '\0'; // null-terminated - // } - - // char *vendor_string_rxch = (char *)vendor_part_rxch; - - // if ((dev_present_mask[f] & (1 << (2 * n))) == 0) { // check that there is a FF installed in this ch - // if (!detect_ff) { - // detect_ff = true; - // if (strstr(vendor_string_rxch, "14") == NULL && strstr(vendor_string_rxch, "CRRNB") == NULL) { // the first 25Gbs 12-ch detected on FPGA1(2) - // tmp_ffpart_bit_mask = tmp_ffpart_bit_mask | (0x1U << n); // bit 1 for a 25Gbs ch and assign to a Bit-mask of Firefly 12-ch part - // } - // else { - // if (f == 0) - // ffl12_f1_args.commands = sm_command_fflit_f1; // if the 14Gbsp 12-ch part is found, change the set of commands to sm_command_fflit_f1 - // else - // ffl12_f2_args.commands = sm_command_fflit_f2; // if the 14Gbsp 12-ch part is found, change the set of commands to sm_command_fflit_f2 - // } - // log_info(LOG_SERVICE, "Getting Firefly 12-ch part (FPGA%d): %s \r\n:", f + 1, vendor_string_rxch); - // strncpy(vendor_string, vendor_string_rxch, nstring); - // } - // else { - // if (strstr(vendor_string_rxch, "14") == NULL && strstr(vendor_string_rxch, "CRRNB") == NULL) { - // tmp_ffpart_bit_mask = tmp_ffpart_bit_mask | (0x1U << n); // bit 1 for a 25Gbs ch and assign to a Bit-mask of Firefly 12-ch part - // } - // else { - // if (strncmp(vendor_string_rxch, vendor_string, nstring) != 0) { - // log_info(LOG_SERVICE, "Different Firefly 12-ch part(FPGA%d) on %s \r\n:", f + 1, ff_moni2c_addrs[(2 * n) + 1 + ff_ndev_offset[f]].name); - // log_info(LOG_SERVICE, "with %s \r\n:", vendor_string_rxch); - // } - // } - // } - // } - // else { - // log_info(LOG_SERVICE, "No Firefly 12-ch part(FPGA%d) on %s \r\n:", f + 1, ff_moni2c_addrs[(2 * n) + 1 + ff_ndev_offset[f]].name); - // } - // memset(vendor_data_rxch, 0, sizeof(vendor_data_rxch)); - // memset(vendor_part_rxch, 0, sizeof(vendor_part_rxch)); - // rmux = apollo_i2c_ctl_w(args_st[f].i2c_dev, args_st[f].devices[(2 * n) + 1].mux_addr, 1, 0); - // if (rmux != 0) { - // log_warn(LOG_SERVICE, "Mux write error %s\r\n", SMBUS_get_error(rmux)); - // } - // log_debug(LOG_SERVICE, "%s: reset mux\r\n", args_st[f].devices[(2 * n) + 1].name); - // } - - // log_debug(LOG_SERVICE, "Bit-mask of Firefly 12-ch part (FPGA%d): 0x%02x \r\n:", f + 1, tmp_ffpart_bit_mask); - // log_debug(LOG_SERVICE, "Bit-mask of xmit_3v8_sel(FPGA%d): 0x%02x \r\n:", f + 1, dev_xmit_4v0_sel[f]); - // // Warning if 25Gbs found but is connected to 3.3V or Non-25Gbs found but is connected to 3.8V - // if ((dev_xmit_4v0_sel[f] ^ tmp_ffpart_bit_mask) != 0U) { - // log_warn(LOG_SERVICE, "FPGA%d 12-ch FFs have unmatched xmit_3v8_sel(0x%02x) and 12-ch ff-mask(0x%02x) \r\n", f + 1, dev_xmit_4v0_sel[f], tmp_ffpart_bit_mask); - // } - - // if (f == 0) - // ff_bitmask_args[0].ffpart_bit_mask = tmp_ffpart_bit_mask; - // else - // ff_bitmask_args[2].ffpart_bit_mask = tmp_ffpart_bit_mask; - - // // if we have a semaphore, give it - // if (xSemaphoreGetMutexHolder(semaphores[f]) == xTaskGetCurrentTaskHandle()) { - // xSemaphoreGive(semaphores[f]); - // } - // } -} #endif diff --git a/projects/cm_mcu/PowerSupplyTask.c b/projects/cm_mcu/PowerSupplyTask.c index 87c28536..e143ecc2 100644 --- a/projects/cm_mcu/PowerSupplyTask.c +++ b/projects/cm_mcu/PowerSupplyTask.c @@ -405,7 +405,6 @@ void PowerSupplyTask(void *parameters) else { // check 12-ch FF parts from vendors on FPGA1/2 vTaskDelay(pdMS_TO_TICKS(1000)); - getFFpart(); ff_map_25gb_parts(); UBaseType_t ffmask[2] = {0xe, 0xe}; if ((f1_ff12xmit_4v0_sel ^ ff_bitmask_args[0].ffpart_bit_mask) == 0x0U && (f2_ff12xmit_4v0_sel ^ ff_bitmask_args[2].ffpart_bit_mask) == 0x0U) { diff --git a/projects/cm_mcu/clocksynth.c b/projects/cm_mcu/clocksynth.c index c05bbecb..a7c10f3a 100644 --- a/projects/cm_mcu/clocksynth.c +++ b/projects/cm_mcu/clocksynth.c @@ -88,7 +88,7 @@ void getClockProgram(int device, char progname_clkdesgid[CLOCK_PROGNAME_REG_NAME CLOCK_CHANGEPAGE_REG_ADDR, 1, page); // now read out the six bytes of data in two reads - const uint8_t reg = (CLOCK_PROGNAME_REG_ADDR_START) & 0xFF; + const uint8_t reg = (CLOCK_PROGNAME_REG_ADDR_START)&0xFF; uint16_t init_postamble_page = 32 * (device + 1) - 1; // read the addresses in EEPROM that store the number of registers in Preamble-register, Register, and Postamble-register list per a clock config file @@ -115,10 +115,10 @@ void getClockProgram(int device, char progname_clkdesgid[CLOCK_PROGNAME_REG_NAME // as eepromdata[0] and eepromdat[1],respectively // third byte from three addresses in EEPROM is a value byte - apollo_i2c_ctl_reg_r(CLOCK_I2C_DEV, CLOCK_I2C_EEPROM_ADDR, 2, eeprom_progname_reg + ((i) * 3), 3, tempdata); + apollo_i2c_ctl_reg_r(CLOCK_I2C_DEV, CLOCK_I2C_EEPROM_ADDR, 2, eeprom_progname_reg + ((i)*3), 3, tempdata); eepromdata[0] |= ((tempdata[0] >> (16)) & 0xFF) << (i * 8); // third byte from three addresses in EEPROM is a value byte - apollo_i2c_ctl_reg_r(CLOCK_I2C_DEV, CLOCK_I2C_EEPROM_ADDR, 2, eeprom_progname_reg + 12 + ((i) * 3), 3, tempdata); + apollo_i2c_ctl_reg_r(CLOCK_I2C_DEV, CLOCK_I2C_EEPROM_ADDR, 2, eeprom_progname_reg + 12 + ((i)*3), 3, tempdata); eepromdata[1] |= ((tempdata[0] >> (16)) & 0xFF) << (i * 8); } } diff --git a/projects/cm_mcu/cm_mcu.c b/projects/cm_mcu/cm_mcu.c index 696374fd..101b0e10 100644 --- a/projects/cm_mcu/cm_mcu.c +++ b/projects/cm_mcu/cm_mcu.c @@ -136,7 +136,7 @@ void SystemInitInterrupts(void) #if defined(REV1) initI2C6(g_ui32SysClock); // controller for FPGAs #elif defined(REV2) - initI2C5(g_ui32SysClock); // controller for FPGAs + initI2C5(g_ui32SysClock); // controller for FPGAs #endif // smbus diff --git a/projects/cm_mcu/commands/SensorControl.c b/projects/cm_mcu/commands/SensorControl.c index 4c089a53..9014b545 100644 --- a/projects/cm_mcu/commands/SensorControl.c +++ b/projects/cm_mcu/commands/SensorControl.c @@ -725,53 +725,6 @@ BaseType_t ff_status(int argc, char **argv, char *m) return pdFALSE; } -// for (; n < NFIREFLY_ARG; ++n) { -// struct MonitorI2CTaskArgs_t *ff_arg = ff_moni2c_arg[n].arg; -// for (; whichff < ff_moni2c_arg[n].int_idx + ff_moni2c_arg[n].num_dev; ++whichff) { -// int dev = whichff - ff_moni2c_arg[n].int_idx + ff_moni2c_arg[n].dev_int_idx; -// if (isEnabledFF(ff_moni2c_arg[n].int_idx + dev)) { -// int index = dev * (ff_arg->n_commands * ff_arg->n_pages) + i1; -// uint8_t val = ff_arg->sm_values[index]; -// copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%17s: 0x%02x", ff_moni2c_addrs[whichff].name, val); -// } -// else // dummy value -// copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%17s: %4s", ff_moni2c_addrs[whichff].name, "--"); - -// bool isTx = (strstr(ff_moni2c_addrs[whichff].name, "Tx") != NULL); -// if (isTx) { -// #ifdef REV1 -// copied += snprintf(m + copied, SCRATCH_SIZE - copied, "\t"); -// #elif defined(REV2) // REV1 -// nTx += 1; -// uint8_t ff_4v0_sel = 1 << (nTx % (NFIREFLIES_IT_F1 / 2)); -// if (nTx < (NFIREFLIES_IT_F1 / 2)) -// ff_4v0_sel &= f1_ff12xmit_4v0_sel; -// else -// ff_4v0_sel &= f2_ff12xmit_4v0_sel; -// copied += snprintf(m + copied, SCRATCH_SIZE - copied, " 3v8?(%x) \t", ff_4v0_sel >> (nTx % (NFIREFLIES_IT_F1 / 2))); -// #endif // REV2 -// } -// else { -// copied += snprintf(m + copied, SCRATCH_SIZE - copied, "\r\n"); -// } -// if ((SCRATCH_SIZE - copied) < 20) { -// ++whichff; -// return pdTRUE; -// } -// } -// } - -// if (whichff % 2 == 1) { -// m[copied++] = '\r'; -// m[copied++] = '\n'; -// m[copied] = '\0'; -// } -// whichff = 0; -// n = 0; - -// return pdFALSE; -// } - BaseType_t ff_los_alarm(int argc, char **argv, char *m) { int copied = 0; @@ -806,44 +759,6 @@ BaseType_t ff_los_alarm(int argc, char **argv, char *m) } } - // int i1 = 2; // 2 for los_alarm - // uint8_t i2cdata[2]; - - // for (; n < NFIREFLY_ARG; ++n) { - // struct MonitorI2CTaskArgs_t *ff_arg = ff_moni2c_arg[n].arg; - - // for (; whichff < ff_moni2c_arg[n].int_idx + ff_moni2c_arg[n].num_dev; ++whichff) { - // int dev = whichff - ff_moni2c_arg[n].int_idx + ff_moni2c_arg[n].dev_int_idx; - // copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%s ", ff_moni2c_addrs[whichff].name); - // if (!isEnabledFF(ff_moni2c_arg[n].int_idx + dev)) { - // copied += snprintf(m + copied, SCRATCH_SIZE - copied, "------------"); - // } - // else { - // int index = dev * (ff_arg->n_commands * ff_arg->n_pages) + i1; - // i2cdata[0] = (ff_arg->sm_values[index]) & 0xFFU; - // i2cdata[1] = (ff_arg->sm_values[index] >> 8) & 0xFFU; - // for (size_t i = 0; i < 8; i++) { - // int alarm = getFFch_low(i2cdata[0], i) ? 1 : 0; - // copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%d", alarm); - // } - // if (strstr(ff_moni2c_arg[n].ff_part, "FFL12") != NULL) { - // for (size_t i = 8; i < 12; i++) { - // int alarm = getFFch_high(i2cdata[1], i) ? 1 : 0; - // copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%d", alarm); - // } - // } - // } - // bool isTx = (strstr(ff_moni2c_addrs[whichff].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; - // return pdTRUE; - // } - // } - // } if (whichff % 2 == 1) { m[copied++] = '\r'; m[copied++] = '\n'; @@ -890,42 +805,6 @@ BaseType_t ff_cdr_lol_alarm(int argc, char **argv, char *m) return pdTRUE; } } - - // for (; n < NFIREFLY_ARG; ++n) { - // struct MonitorI2CTaskArgs_t *ff_arg = ff_moni2c_arg[n].arg; - - // for (; whichff < ff_moni2c_arg[n].int_idx + ff_moni2c_arg[n].num_dev; ++whichff) { - // int dev = whichff - ff_moni2c_arg[n].int_idx + ff_moni2c_arg[n].dev_int_idx; - // copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%s ", ff_moni2c_addrs[whichff].name); - // if (!isEnabledFF(ff_moni2c_arg[n].int_idx + dev)) { - // copied += snprintf(m + copied, SCRATCH_SIZE - copied, "------------"); - // } - // else { - // int index = dev * (ff_arg->n_commands * ff_arg->n_pages) + i1; - // i2cdata[0] = (ff_arg->sm_values[index]) & 0xFFU; - // i2cdata[1] = (ff_arg->sm_values[index] >> 8) & 0xFFU; - // for (size_t i = 0; i < 8; i++) { - // int alarm = getFFch_low(i2cdata[0], i) ? 1 : 0; - // copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%d", alarm); - // } - // if (strstr(ff_moni2c_arg[n].ff_part, "FFL12") != NULL) { - // for (size_t i = 8; i < 12; i++) { - // int alarm = getFFch_high(i2cdata[1], i) ? 1 : 0; - // copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%d", alarm); - // } - // } - // } - // bool isTx = (strstr(ff_moni2c_addrs[whichff].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; - // return pdTRUE; - // } - // } - // } if (whichff % 2 == 1) { m[copied++] = '\r'; m[copied++] = '\n'; @@ -992,12 +871,12 @@ BaseType_t ff_optpow(int argc, char **argv, char *m) // takes no arguments static int i = 0; int copied = 0; - if ( i == 0 ) { + if (i == 0) { copied += snprintf(m, SCRATCH_SIZE, "FF average Optical Power\r\n"); } - for (; i < NFIREFLIES; ++i ) { + for (; i < NFIREFLIES; ++i) { bool isTx = (strstr(ff_moni2c_addrs[i].name, "Tx") != NULL); - if (isEnabledFF(i) && !isTx ) { + if (isEnabledFF(i) && !isTx) { float val = getFFavgoptpow(i); int tens, frac; float_to_ints(val, &tens, &frac); @@ -1021,8 +900,7 @@ BaseType_t ff_optpow(int argc, char **argv, char *m) } // loop over NFIREFLIES i = 0; return pdFALSE; -} - +} // this command takes up to two arguments BaseType_t ff_ctl(int argc, char **argv, char *m) diff --git a/sm_cm_config/src/xml_generate.py b/sm_cm_config/src/xml_generate.py index 1e626546..b54e40c4 100644 --- a/sm_cm_config/src/xml_generate.py +++ b/sm_cm_config/src/xml_generate.py @@ -165,9 +165,10 @@ def yaml_file(filename): cm = ET.Element('node') cm.set('id', 'CM') cm.set('address', '0x00000000') -prev_addr = 0x0 #keep track of the most recent address that comes into a pair of bytes for 8-bit masking -prev_j = 0x0 #keep track of the order of postfixes in each name node -prev_bit = 0x0 #keep track of the even or odd order of bytes globally sent for masking +# keep track of the most recent address that comes into a pair of bytes for 8-bit masking +prev_addr = 0x0 +prev_j = 0x0 # keep track of the order of postfixes in each name node +prev_bit = 0x0 # keep track of the even or odd order of bytes globally sent for masking #% % config = y['config'] for c in config: # loop over entries in configuration (sensor category) @@ -186,7 +187,9 @@ def yaml_file(filename): i += 1 j += 1 continue - if (bit == 1 and j == 0): #the previous name node has odd bytes so this postfix node uses the previous postfix address but masks off the lower byte + # the previous name node has odd bytes so this postfix node uses the + # previous postfix address but masks off the lower byte + if (bit == 1 and j == 0): pp = node = ET.SubElement(cm, 'node') pp.set('id', n) pp.set('address', str(hex(prev_addr))) @@ -202,7 +205,8 @@ def yaml_file(filename): else : #the low byte with an increasing postfix node by one node = make_node(pp, p, c, j+1, bit, n) if (prev_bit == bit and prev_addr == addr and prev_addr != 0) : - print("warning : please check if masks overlapped at node ", n, " addr ", hex(prev_addr)) + print("warning : please check if masks overlapped at node ", + n, " addr ", hex(prev_addr)) prev_addr = addr prev_j = j prev_bit = bit @@ -211,7 +215,8 @@ def yaml_file(filename): else: make_node(cm, n, c, start+i, (start+i)%2, "") if (prev_bit == (start+i)%2 and prev_addr == int((start+i)/2) and prev_addr != 0) : - print("warning : please check if masks overlapped at node ", n, " addr ", hex(prev_addr)) + print("warning : please check if masks overlapped at node ", n, + " addr ", hex(prev_addr)) prev_addr = int((start + i)/2) prev_bit = (start+i)%2 i += 1 From 6439b431ce79460bf36aa5ba01ba61a1a2201915 Mon Sep 17 00:00:00 2001 From: pwittich Date: Sun, 2 Jun 2024 02:31:28 +0000 Subject: [PATCH 43/71] Committing clang-format changes --- projects/cm_mcu/FireflyUtils.c | 8 ++++---- projects/cm_mcu/clocksynth.c | 6 +++--- projects/cm_mcu/cm_mcu.c | 2 +- sm_cm_config/src/xml_generate.py | 14 +++++++------- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/projects/cm_mcu/FireflyUtils.c b/projects/cm_mcu/FireflyUtils.c index c36bd942..9f74ccc2 100644 --- a/projects/cm_mcu/FireflyUtils.c +++ b/projects/cm_mcu/FireflyUtils.c @@ -149,10 +149,10 @@ void readFFpresent(void) ((present_FFL12_BOTTOM_F1)); // 6 bits #elif defined(REV2) - present_FFL12_F1 = present_FFL12_F1 & 0x3FU; // bottom 6 bits - present_FFL12_F2 = present_FFL12_F2 & 0x3FU; // bottom 6 bits - present_FFL4_F1 = (present_FFL4_F1 >> 4) & 0xFU; // bits 4-7 - present_FFL4_F2 = (present_FFL4_F2 >> 4) & 0xFU; // bits 4-7 + present_FFL12_F1 = present_FFL12_F1 & 0x3FU; // bottom 6 bits + present_FFL12_F2 = present_FFL12_F2 & 0x3FU; // bottom 6 bits + present_FFL4_F1 = (present_FFL4_F1 >> 4) & 0xFU; // bits 4-7 + present_FFL4_F2 = (present_FFL4_F2 >> 4) & 0xFU; // bits 4-7 uint32_t ff_combined_present = ((present_FFL4_F2) << 16) | // 4 bits ((present_FFL12_F2) << 10) | // 6 bits diff --git a/projects/cm_mcu/clocksynth.c b/projects/cm_mcu/clocksynth.c index a7c10f3a..c05bbecb 100644 --- a/projects/cm_mcu/clocksynth.c +++ b/projects/cm_mcu/clocksynth.c @@ -88,7 +88,7 @@ void getClockProgram(int device, char progname_clkdesgid[CLOCK_PROGNAME_REG_NAME CLOCK_CHANGEPAGE_REG_ADDR, 1, page); // now read out the six bytes of data in two reads - const uint8_t reg = (CLOCK_PROGNAME_REG_ADDR_START)&0xFF; + const uint8_t reg = (CLOCK_PROGNAME_REG_ADDR_START) & 0xFF; uint16_t init_postamble_page = 32 * (device + 1) - 1; // read the addresses in EEPROM that store the number of registers in Preamble-register, Register, and Postamble-register list per a clock config file @@ -115,10 +115,10 @@ void getClockProgram(int device, char progname_clkdesgid[CLOCK_PROGNAME_REG_NAME // as eepromdata[0] and eepromdat[1],respectively // third byte from three addresses in EEPROM is a value byte - apollo_i2c_ctl_reg_r(CLOCK_I2C_DEV, CLOCK_I2C_EEPROM_ADDR, 2, eeprom_progname_reg + ((i)*3), 3, tempdata); + apollo_i2c_ctl_reg_r(CLOCK_I2C_DEV, CLOCK_I2C_EEPROM_ADDR, 2, eeprom_progname_reg + ((i) * 3), 3, tempdata); eepromdata[0] |= ((tempdata[0] >> (16)) & 0xFF) << (i * 8); // third byte from three addresses in EEPROM is a value byte - apollo_i2c_ctl_reg_r(CLOCK_I2C_DEV, CLOCK_I2C_EEPROM_ADDR, 2, eeprom_progname_reg + 12 + ((i)*3), 3, tempdata); + apollo_i2c_ctl_reg_r(CLOCK_I2C_DEV, CLOCK_I2C_EEPROM_ADDR, 2, eeprom_progname_reg + 12 + ((i) * 3), 3, tempdata); eepromdata[1] |= ((tempdata[0] >> (16)) & 0xFF) << (i * 8); } } diff --git a/projects/cm_mcu/cm_mcu.c b/projects/cm_mcu/cm_mcu.c index 101b0e10..696374fd 100644 --- a/projects/cm_mcu/cm_mcu.c +++ b/projects/cm_mcu/cm_mcu.c @@ -136,7 +136,7 @@ void SystemInitInterrupts(void) #if defined(REV1) initI2C6(g_ui32SysClock); // controller for FPGAs #elif defined(REV2) - initI2C5(g_ui32SysClock); // controller for FPGAs + initI2C5(g_ui32SysClock); // controller for FPGAs #endif // smbus diff --git a/sm_cm_config/src/xml_generate.py b/sm_cm_config/src/xml_generate.py index b54e40c4..edefe7e9 100644 --- a/sm_cm_config/src/xml_generate.py +++ b/sm_cm_config/src/xml_generate.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/ usr / bin / env python """Generate XML file from YAML input""" import xml.etree.ElementTree as ET from pprint import pprint @@ -6,13 +6,13 @@ import os import yaml -zm_num_entries = 1024 +zm_num_entries = 1024 #% % def make_node(parent: ET.Element, myid: str, thedict: dict, addr2: int, bit: int, parent_id: str) -> ET.Element: """create the node to be inserted into the xml tree""" -# pylint: disable=too-many-branches +#pylint : disable = too - many - branches #I disable this check because as far as I can tell it's wrong thenode = ET.SubElement(parent, 'node') myid = myid.replace(' ', '_') @@ -62,7 +62,7 @@ def make_node(parent: ET.Element, myid: str, thedict: dict, addr2: int, bit: int colid = thedict['default_col'] else: colid = myid - # for some special patterns, generate a different column id +#for some special patterns, generate a different column id if myid.lower().startswith("cur_"): colid = "IOUT" elif "temp" in myid.lower(): @@ -165,7 +165,7 @@ def yaml_file(filename): cm = ET.Element('node') cm.set('id', 'CM') cm.set('address', '0x00000000') -# keep track of the most recent address that comes into a pair of bytes for 8-bit masking +#keep track of the most recent address that comes into a pair of bytes for 8 - bit masking prev_addr = 0x0 prev_j = 0x0 # keep track of the order of postfixes in each name node prev_bit = 0x0 # keep track of the even or odd order of bytes globally sent for masking @@ -187,8 +187,8 @@ def yaml_file(filename): i += 1 j += 1 continue - # the previous name node has odd bytes so this postfix node uses the - # previous postfix address but masks off the lower byte +#the previous name node has odd bytes so this postfix node uses the +#previous postfix address but masks off the lower byte if (bit == 1 and j == 0): pp = node = ET.SubElement(cm, 'node') pp.set('id', n) From fc3e85c423cafd2f04e20a86cb78dd7f00ab1ecf Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Sat, 1 Jun 2024 22:42:06 -0400 Subject: [PATCH 44/71] Update xml_generate.py --- sm_cm_config/src/xml_generate.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sm_cm_config/src/xml_generate.py b/sm_cm_config/src/xml_generate.py index edefe7e9..f50d9201 100644 --- a/sm_cm_config/src/xml_generate.py +++ b/sm_cm_config/src/xml_generate.py @@ -1,4 +1,4 @@ -#!/ usr / bin / env python +#!/usr/bin/env python """Generate XML file from YAML input""" import xml.etree.ElementTree as ET from pprint import pprint @@ -12,7 +12,7 @@ def make_node(parent: ET.Element, myid: str, thedict: dict, addr2: int, bit: int, parent_id: str) -> ET.Element: """create the node to be inserted into the xml tree""" -#pylint : disable = too - many - branches +#pylint: disable=too-many-branches #I disable this check because as far as I can tell it's wrong thenode = ET.SubElement(parent, 'node') myid = myid.replace(' ', '_') From c2f7ae808a086423da23044285abb294771cbe2a Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Sun, 2 Jun 2024 09:43:19 -0400 Subject: [PATCH 45/71] update `FireflyType` for live check on 25G --- projects/cm_mcu/MonUtils.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/projects/cm_mcu/MonUtils.c b/projects/cm_mcu/MonUtils.c index 5b6d253e..c1d17ac2 100644 --- a/projects/cm_mcu/MonUtils.c +++ b/projects/cm_mcu/MonUtils.c @@ -61,6 +61,7 @@ int ClockType(int device) // for 4 channel parts, there is one XCVR part int FireflyType(int device) { + bool isF1 = device < NFIREFLIES_F1; device = device % NFIREFLIES_F1; // F1 and F2 devices are the same. switch (device) { case 0: @@ -69,9 +70,13 @@ int FireflyType(int device) case 3: case 4: case 5: { - // FIXME: this should be a check on CERN-B or ECUO-[RT]12-25 - // with a function call - return DEVICE_CERNB; + uint8_t mask = ff_bitmask_args[0].ffpart_bit_mask; // default to F1 + if ( ! isF1 ) + mask = ff_bitmask_args[2].ffpart_bit_mask; + if (mask&(0x1U< Date: Sun, 2 Jun 2024 09:43:27 -0400 Subject: [PATCH 46/71] cleanup --- projects/cm_mcu/MonitorTaskI2C_new.h | 64 ---------------------------- projects/cm_mcu/Tasks.h | 2 - sm_cm_config/src/xml_generate.py | 1 - 3 files changed, 67 deletions(-) delete mode 100644 projects/cm_mcu/MonitorTaskI2C_new.h diff --git a/projects/cm_mcu/MonitorTaskI2C_new.h b/projects/cm_mcu/MonitorTaskI2C_new.h deleted file mode 100644 index 7d54fd13..00000000 --- a/projects/cm_mcu/MonitorTaskI2C_new.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * MonitorI2CTask_new.h - * - */ - -#ifndef PROJECTS_CM_MCU_MONITORI2CTASKNEW_H_ -#define PROJECTS_CM_MCU_MONITORI2CTASKNEW_H_ - -#include "FreeRTOS.h" // IWYU pragma: keep -#include "semphr.h" -#include "Tasks.h" - -struct i2c_reg_command_t { - int reg_size; // number of bytes of register/command - unsigned char page; // I2C page address - unsigned char command[4]; // I2c register address - int size; // number of bytes to read - char *name; // text describing command - uint16_t bit_mask; // begin bit mask - char *units; // units for pretty printing - enum pm_type type; // how to decode command (L11 or bitfield or ...) - uint16_t (*devicelist)(void); - void (*storeData)(uint16_t data, int which); // store data in location which - uint16_t (*retrieveData)(int which); // retrieve data from location which -}; - -// how to find an I2C device, with a mux infront of it. - -typedef bool (*MonTaskFcnPointer)(int device); -typedef int (*MonTaskI2CTypeFcnPointer)(int); // what kind of device we have (i.e., for FF, CERN-B, B04, Y12-14, Y12-25, etc.) - -struct MonitorI2CTaskArgs_new_t { - const char *name; // name to be assigned to the task - struct dev_moni2c_addr_t *devices; // list of devices to query - int i2c_dev; // i2c controller # - int n_devices; // number of devices - struct i2c_reg_command_t *commands; // list of commands - const uint8_t n_commands; // number of commands - const uint16_t selpage_reg; // register for selecting page - TickType_t updateTick; // last update time, in ticks - SemaphoreHandle_t xSem; // semaphore for controlling access to device - UBaseType_t stack_size; // stack size of task - MonTaskFcnPointer presentCallback; // callback for present check - MonTaskI2CTypeFcnPointer typeCallback; // callback for type check -}; - -#define FF_SELPAGE_REG 0x7f -#define CLK_SELPAGE_REG 0x1 - -#define NDEVICES_CLK 5 - -// for autogenerated code -#define DEVICE_CERNB 0x01 -#define DEVICE_14G 0x02 -#define DEVICE_25G4 0x04 -#define DEVICE_25G12 0x08 -#define DEVICE_SI5341 0x01 -#define DEVICE_SI5395 0x02 - -#define DEVICE_NONE 0x80 - -extern struct dev_moni2c_addr_t clk_moni2c_addrs[NDEVICES_CLK]; - -#endif /* PROJECTS_CM_MCU_MONITORI2CTASKNEW_H_ */ diff --git a/projects/cm_mcu/Tasks.h b/projects/cm_mcu/Tasks.h index 85a84167..581e2a28 100644 --- a/projects/cm_mcu/Tasks.h +++ b/projects/cm_mcu/Tasks.h @@ -303,8 +303,6 @@ int init_registers_clk(void); #define CLOCK_NUM_SI5341 1 #define CLOCK_NUM_SI5395 4 -// extern struct dev_moni2c_addr_t clkr0a_moni2c_addrs[CLOCK_NUM_SI5341]; -// extern struct dev_moni2c_addr_t clk_moni2c_addrs[NDEVICES_CLK]; // configuring clock initalization int init_load_clk(int clk_n); diff --git a/sm_cm_config/src/xml_generate.py b/sm_cm_config/src/xml_generate.py index f50d9201..75943b55 100644 --- a/sm_cm_config/src/xml_generate.py +++ b/sm_cm_config/src/xml_generate.py @@ -16,7 +16,6 @@ def make_node(parent: ET.Element, myid: str, thedict: dict, addr2: int, bit: int #I disable this check because as far as I can tell it's wrong thenode = ET.SubElement(parent, 'node') myid = myid.replace(' ', '_') - print(f"myid: {myid}") thenode.set('id', myid) #address is half of the sensor address since these are 32 bit addresses theaddr = int(addr2/2) From eef0448968f2f33ccd45454ac1ddea5985a21827 Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Sun, 2 Jun 2024 09:55:31 -0400 Subject: [PATCH 47/71] error checking --- projects/cm_mcu/FireflyUtils.c | 2 +- projects/cm_mcu/MonUtils.c | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/projects/cm_mcu/FireflyUtils.c b/projects/cm_mcu/FireflyUtils.c index 9f74ccc2..100894ba 100644 --- a/projects/cm_mcu/FireflyUtils.c +++ b/projects/cm_mcu/FireflyUtils.c @@ -254,7 +254,7 @@ float getFFavgoptpow(const uint8_t i) uint16_t getFFpresentbit(const uint8_t i) { if (i > 3) { - log_warn(LOG_SERVICE, "caught %d > total fireflies %d\r\n", i, NFIREFLIES); + log_error(LOG_SERVICE, "caught %d > total fireflies %d\r\n", i, NFIREFLIES); return 56; } uint16_t val = ff_bitmask_args[i].present_bit_mask; diff --git a/projects/cm_mcu/MonUtils.c b/projects/cm_mcu/MonUtils.c index c1d17ac2..a02397ee 100644 --- a/projects/cm_mcu/MonUtils.c +++ b/projects/cm_mcu/MonUtils.c @@ -2,6 +2,7 @@ #include "MonI2C_addresses.h" #include "FireflyUtils.h" #include "Tasks.h" +#include "common/log.h" #include "MonUtils.h" #ifdef REV1 @@ -71,12 +72,17 @@ int FireflyType(int device) case 4: case 5: { uint8_t mask = ff_bitmask_args[0].ffpart_bit_mask; // default to F1 - if ( ! isF1 ) + int thistype; + if (!isF1) mask = ff_bitmask_args[2].ffpart_bit_mask; - if (mask&(0x1U< Date: Mon, 3 Jun 2024 09:08:32 -0400 Subject: [PATCH 48/71] minor tweaks --- projects/cm_mcu/MonUtils.c | 7 ++++--- projects/cm_mcu/commands/SensorControl.c | 8 +++++++- sm_cm_config/data/MON_I2C_rev2.yml | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/projects/cm_mcu/MonUtils.c b/projects/cm_mcu/MonUtils.c index a02397ee..42761cfc 100644 --- a/projects/cm_mcu/MonUtils.c +++ b/projects/cm_mcu/MonUtils.c @@ -71,17 +71,18 @@ int FireflyType(int device) case 3: case 4: case 5: { + // this mask is set in pairs uint8_t mask = ff_bitmask_args[0].ffpart_bit_mask; // default to F1 int thistype; - if (!isF1) + if (!isF1) mask = ff_bitmask_args[2].ffpart_bit_mask; - if (mask & (0x1U << device)) { + if (mask & (0x1U << (device/2))) { thistype = DEVICE_25G12; } else { thistype = DEVICE_CERNB; } - log_debug(LOG_SERVICE, "%s: device %d is type %d", __func__, device, thistype); + log_debug(LOG_SERVICE, "%s: device %d is type %d\r\n", __func__, device, thistype); return thistype; } case 6: diff --git a/projects/cm_mcu/commands/SensorControl.c b/projects/cm_mcu/commands/SensorControl.c index 9014b545..b4e10a32 100644 --- a/projects/cm_mcu/commands/SensorControl.c +++ b/projects/cm_mcu/commands/SensorControl.c @@ -1331,7 +1331,13 @@ BaseType_t ff_dump_names(int argc, char **argv, char *m) snprintf(m + copied, SCRATCH_SIZE - copied, "%s: read failed\r\n", argv[0]); return pdFALSE; } - copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%02d:\t%s\r\n", i, name); + copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%17s:%s", ff_moni2c_addrs[i].name, name); + + bool isTx = (strstr(ff_moni2c_addrs[i].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) < 25 && (i < NFIREFLIES)) { ++i; return pdTRUE; diff --git a/sm_cm_config/data/MON_I2C_rev2.yml b/sm_cm_config/data/MON_I2C_rev2.yml index 8f133a42..2a2e4066 100644 --- a/sm_cm_config/data/MON_I2C_rev2.yml +++ b/sm_cm_config/data/MON_I2C_rev2.yml @@ -42,7 +42,7 @@ define: &FF_SHARED_REGS units: "" type: PM_STATUS devicetypes: [25G4, 25G12] - - name: OPT_POWER_CH1 + - name: OPT_POWER_CH1 # FIXME: 25G12 is on different page than 25G4 >:-| reg_size: 1 page: 0 reg_address: [-1, -1, 34, 228] From 21c86311d2a632304dea0b668b56e757f0b380d7 Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Mon, 3 Jun 2024 09:47:28 -0400 Subject: [PATCH 49/71] allow for different pages for a command Optical power is on different pages for B04 and ECUO1225, sigh --- projects/cm_mcu/MonitorTaskI2C.c | 2 +- projects/cm_mcu/MonitorTaskI2C.h | 2 +- sm_cm_config/data/MON_I2C_rev2.yml | 24 +-- sm_cm_config/src/mon_generate.py | 316 ++++++++++++++--------------- 4 files changed, 172 insertions(+), 172 deletions(-) diff --git a/projects/cm_mcu/MonitorTaskI2C.c b/projects/cm_mcu/MonitorTaskI2C.c index 4c745239..27f96c4c 100644 --- a/projects/cm_mcu/MonitorTaskI2C.c +++ b/projects/cm_mcu/MonitorTaskI2C.c @@ -115,7 +115,7 @@ void MonitorTaskI2C(void *parameters) // set page register if it's different than the last time log_debug(LOG_MONI2C, "%s: reg %s\r\n", args->name, args->commands[c].name); - uint8_t page_reg_value = args->commands[c].page; + uint8_t page_reg_value = args->commands[c].page[devtype]; if (page_reg_value != last_page_reg_value) { int r = apollo_i2c_ctl_reg_w(args->i2c_dev, args->devices[device].dev_addr, 1, args->selpage_reg, 1, page_reg_value); if (r != 0) { diff --git a/projects/cm_mcu/MonitorTaskI2C.h b/projects/cm_mcu/MonitorTaskI2C.h index a0169f93..bb74e2af 100644 --- a/projects/cm_mcu/MonitorTaskI2C.h +++ b/projects/cm_mcu/MonitorTaskI2C.h @@ -12,7 +12,7 @@ struct i2c_reg_command_t { int reg_size; // number of bytes of register/command - unsigned char page; // I2C page address + unsigned char page[4]; // I2C page address unsigned char command[4]; // I2c register address int size; // number of bytes to read char *name; // text describing command diff --git a/sm_cm_config/data/MON_I2C_rev2.yml b/sm_cm_config/data/MON_I2C_rev2.yml index 2a2e4066..881b8ca6 100644 --- a/sm_cm_config/data/MON_I2C_rev2.yml +++ b/sm_cm_config/data/MON_I2C_rev2.yml @@ -44,7 +44,7 @@ define: &FF_SHARED_REGS devicetypes: [25G4, 25G12] - name: OPT_POWER_CH1 # FIXME: 25G12 is on different page than 25G4 >:-| reg_size: 1 - page: 0 + page: [0, 0, 0, 1] reg_address: [-1, -1, 34, 228] size: 2 mask: 0xFFFF @@ -53,7 +53,7 @@ define: &FF_SHARED_REGS devicetypes: [25G4, 25G12] - name: OPT_POWER_CH2 reg_size: 1 - page: 0 + page: [0, 0, 0, 1] reg_address: [-1, -1, 36, 226] size: 2 mask: 0xFFFF @@ -62,7 +62,7 @@ define: &FF_SHARED_REGS devicetypes: [25G4, 25G12] - name: OPT_POWER_CH3 reg_size: 1 - page: 0 + page: [0, 0, 0, 1] reg_address: [-1, -1, 38, 224] size: 2 mask: 0xFFFF @@ -71,7 +71,7 @@ define: &FF_SHARED_REGS devicetypes: [25G4, 25G12] - name: OPT_POWER_CH4 reg_size: 1 - page: 0 + page: [0, 0, 0, 1] reg_address: [-1, -1, 40, 222] size: 2 mask: 0xFFFF @@ -80,7 +80,7 @@ define: &FF_SHARED_REGS devicetypes: [25G4, 25G12] - name: OPT_POWER_CH5 reg_size: 1 - page: 0 + page: [0, 0, 0, 1] reg_address: [-1, -1, -1, 220] size: 2 mask: 0xFFFF @@ -89,7 +89,7 @@ define: &FF_SHARED_REGS devicetypes: [25G12] - name: OPT_POWER_CH6 reg_size: 1 - page: 0 + page: [0, 0, 0, 1] reg_address: [-1, -1, -1, 218] size: 2 mask: 0xFFFF @@ -98,7 +98,7 @@ define: &FF_SHARED_REGS devicetypes: [25G12] - name: OPT_POWER_CH7 reg_size: 1 - page: 0 + page: [0, 0, 0, 1] reg_address: [-1, -1, -1, 216] size: 2 mask: 0xFFFF @@ -107,7 +107,7 @@ define: &FF_SHARED_REGS devicetypes: [25G12] - name: OPT_POWER_CH8 reg_size: 1 - page: 0 + page: [0, 0, 0, 1] reg_address: [-1, -1, -1, 214] size: 2 mask: 0xFFFF @@ -116,7 +116,7 @@ define: &FF_SHARED_REGS devicetypes: [25G12] - name: OPT_POWER_CH9 reg_size: 1 - page: 0 + page: [0, 0, 0, 1] reg_address: [-1, -1, -1, 212] size: 2 mask: 0xFFFF @@ -125,7 +125,7 @@ define: &FF_SHARED_REGS devicetypes: [25G12] - name: OPT_POWER_CH10 reg_size: 1 - page: 0 + page: [0, 0, 0, 1] reg_address: [-1, -1, -1, 210] size: 2 mask: 0xFFFF @@ -134,7 +134,7 @@ define: &FF_SHARED_REGS devicetypes: [25G12] - name: OPT_POWER_CH11 reg_size: 1 - page: 0 + page: [0, 0, 0, 1] reg_address: [-1, -1, -1, 208] size: 2 mask: 0xFFFF @@ -143,7 +143,7 @@ define: &FF_SHARED_REGS devicetypes: [25G12] - name: OPT_POWER_CH12 reg_size: 1 - page: 0 + page: [0, 0, 0, 1] reg_address: [-1, -1, -1, 206] size: 2 mask: 0xFFFF diff --git a/sm_cm_config/src/mon_generate.py b/sm_cm_config/src/mon_generate.py index 777c5934..ae1e5f91 100755 --- a/sm_cm_config/src/mon_generate.py +++ b/sm_cm_config/src/mon_generate.py @@ -39,163 +39,163 @@ def write_boilderplate(fout: io.TextIOWrapper): print(f"// Generated: {timestamp}", file=fout) print(r"//", file=fout) -####################################### -# -# parse the command line arguments -# -####################################### -args = parse_args() - -if args.output and args.verbose: - print('Output file name:', args.output) - -# addr_template = Template("{$reg_size, $page, $reg_address, $size, \"$name\"," -# " $mask, \"$units\", $type, get_${name}_mask, set_${name}_data}, ") -addr_template = Template("{$reg_size, $page, $reg_list, $size, \"$name\"," - " $mask, \"$units\", $type, get_${prefix}_${name}_mask," - " set_${prefix}_${name}_data, get_${prefix}_${name}_data},") -# output file names: header file and c source file -# make sure that the output file ends with .c. Print error message and exit if it doesn't -if not args.output.endswith(".c"): - print(f"Output file name {args.output} does not end with .c") - sys.exit(1) -source_fname = args.output -header_fname = args.output[:-2] + '.h' - -####################################### -# -# end of processing command line arguments -# -####################################### - -# open output c source file for writing -with open(source_fname, 'w', encoding="ascii") as fout_source, \ - open(header_fname, 'w', encoding="ascii") as fout_header: - write_boilderplate(fout_source) - write_boilderplate(fout_header) - print(f"#include \"{header_fname}\"", file=fout_source) - #print("#include \"MonitorTaskI2C.h\"", file=fout_source) - - # header file - print(r"#ifndef MON_I2C_ADDRESSES_H", file=fout_header) - print(r"#define MON_I2C_ADDRESSES_H", file=fout_header) - print("#include ", file=fout_header) - print("#include \"MonitorTaskI2C.h\"", file=fout_header) - print("#include \"FireflyUtils.h\"", file=fout_source) - #print("#include \"MonitorI2CTask.h\"", file=fout_source) - - - with open(args.input_file, encoding="ascii") as f: - - # generate the list of registers to access - # loop over devices first - data = yaml.load(f, Loader=yaml.FullLoader) - - for d in data['devices']: - ndev = d['ndevices'] - ndev_types = d['ndevice_types'] - prefix = d['prefix'] - config = d['config'] - ncommands = len(config) - print(f"#define NCOMMANDS_{prefix} {ncommands}", file=fout_header) - print(f"// {prefix} has {ndev} devices and {ncommands} commands", file=fout_source) - print(f"#define {prefix}_NOT_COVERED (-1)", file=fout_source) - print(f"struct i2c_reg_command_t sm_command_test_{prefix}[NCOMMANDS_{prefix}] = {{", - file=fout_source) - print(f"extern struct i2c_reg_command_t sm_command_test_{prefix}[NCOMMANDS_{prefix}];", - file=fout_header) - for c in config: - reg_list = c['reg_address'] - #print(f"reg list is >{reg_list}<") - # if reg_list is an integer, convert it to a list of ndev_types integers - # this handles the case where all ndev types share the same address - if isinstance(reg_list, int): - reg_list = [reg_list]*int(ndev_types) +def int_to_list(ndev_types, prefix, var_list: list) -> str: + """Convert an integer to a list of integers of length ndev_types""" + if isinstance(var_list, int): + var_list = [var_list]*int(ndev_types) + var_list_str = '{' + for r in var_list: + if r >= 0: + var_list_str += f"{r}, " + else: + var_list_str += f"{prefix}_NOT_COVERED, " + var_list_str += "}" + return var_list_str + +# main program +def main(): + """generate the C source file for the MCU Mon I2C addresses and initialization calls""" + ####################################### + # + # parse the command line arguments + # + ####################################### + args = parse_args() + + if args.output and args.verbose: + print('Output file name:', args.output) + + addr_template = Template("{$reg_size, $page, $reg_list, $size, \"$name\"," + " $mask, \"$units\", $type, get_${prefix}_${name}_mask," + " set_${prefix}_${name}_data, get_${prefix}_${name}_data},") + # output file names: header file and c source file + # make sure that the output file ends with .c. Print error message and exit if it doesn't + if not args.output.endswith(".c"): + print(f"Output file name {args.output} does not end with .c") + sys.exit(1) + source_fname = args.output + header_fname = args.output[:-2] + '.h' + + ####################################### + # + # end of processing command line arguments + # + ####################################### + + # open output c source file for writing + with open(source_fname, 'w', encoding="ascii") as fout_source, \ + open(header_fname, 'w', encoding="ascii") as fout_header: + write_boilderplate(fout_source) + write_boilderplate(fout_header) + print(f"#include \"{header_fname}\"", file=fout_source) + + # header file + print(r"#ifndef MON_I2C_ADDRESSES_H", file=fout_header) + print(r"#define MON_I2C_ADDRESSES_H", file=fout_header) + print("#include ", file=fout_header) + print("#include \"MonitorTaskI2C.h\"", file=fout_header) + print("#include \"FireflyUtils.h\"", file=fout_source) + + with open(args.input_file, encoding="ascii") as f: + + # generate the list of registers to access + # loop over devices first + data = yaml.load(f, Loader=yaml.FullLoader) + + for d in data['devices']: + ndev = d['ndevices'] + ndev_types = d['ndevice_types'] + prefix = d['prefix'] + config = d['config'] + ncommands = len(config) + print(f"#define NCOMMANDS_{prefix} {ncommands}", file=fout_header) + print(f"// {prefix} has {ndev} devices and {ncommands} commands", file=fout_source) + print(f"#define {prefix}_NOT_COVERED (-1)", file=fout_source) + print(f"struct i2c_reg_command_t sm_command_test_{prefix}[NCOMMANDS_{prefix}] = {{", + file=fout_source) + print(f"extern struct i2c_reg_command_t sm_command_test_{prefix}[NCOMMANDS_{prefix}];", + file=fout_header) + for c in config: + reg_list = c['reg_address'] #print(f"reg list is >{reg_list}<") - reg_list_str = '{' - for r in reg_list: - if r > 0: - reg_list_str += f"{r}, " - else: - reg_list_str += f"{prefix}_NOT_COVERED, " - reg_list_str += "}" - s = addr_template.substitute(c, reg_list=reg_list_str, prefix=prefix) - print(s, file=fout_source) - print(r"};", file=fout_source) - - # generate the arrays to store the data - print(r"// Arrays to store the data", file=fout_source) - prefix = d['prefix'] - for c in config: - data_name = f"{prefix}_{c['name']}_data" - print(f"static uint16_t {data_name}[{ndev}] = {{0}};", file=fout_source) - # generate access functions - print(r"// Access functions", file=fout_source) - for c in config: - data_name = f"{prefix}_{c['name']}_data" - set_fcn_name = f"set_{prefix}_{c['name']}_data" - get_fcn_name = f"get_{prefix}_{c['name']}_data" - # getter - print(f"uint16_t {get_fcn_name}(int which);", file=fout_header) - print(f"uint16_t {get_fcn_name}(int which) {{", file=fout_source) - print(f" return {data_name}[which];", file=fout_source) - print(r"}", file=fout_source) - # setter - print(f"void {set_fcn_name}(uint16_t data, int which);", file=fout_header) - print(f"void {set_fcn_name}(uint16_t data, int which) {{", file=fout_source) - print(f" {data_name}[which] = data;", file=fout_source) - print(r"}", file=fout_source) - # using the devices field, generate a function that returns a mask of the devices - print(r"// Function to return a mask of the devices for each command", file=fout_source) + # if reg_list is an integer, convert it to a list of ndev_types integers + # this handles the case where all ndev types share the same address + reg_list_str = int_to_list(ndev_types, prefix, reg_list) + # ditto for the page + page_list = c['page'] + page_list_str = int_to_list(ndev_types, prefix, page_list) + s = addr_template.substitute(c, reg_list=reg_list_str, prefix=prefix, + page=page_list_str) + print(s, file=fout_source) + print(r"};", file=fout_source) + + # generate the arrays to store the data + print(r"// Arrays to store the data", file=fout_source) + prefix = d['prefix'] + for c in config: + data_name = f"{prefix}_{c['name']}_data" + print(f"static uint16_t {data_name}[{ndev}] = {{0}};", file=fout_source) + # generate access functions + print(r"// Access functions", file=fout_source) + for c in config: + data_name = f"{prefix}_{c['name']}_data" + set_fcn_name = f"set_{prefix}_{c['name']}_data" + get_fcn_name = f"get_{prefix}_{c['name']}_data" + # getter + print(f"uint16_t {get_fcn_name}(int which);", file=fout_header) + print(f"uint16_t {get_fcn_name}(int which) {{", file=fout_source) + print(f" return {data_name}[which];", file=fout_source) + print(r"}", file=fout_source) + # setter + print(f"void {set_fcn_name}(uint16_t data, int which);", file=fout_header) + print(f"void {set_fcn_name}(uint16_t data, int which) {{", file=fout_source) + print(f" {data_name}[which] = data;", file=fout_source) + print(r"}", file=fout_source) + # using the devices field, generate a function that returns a mask of the devices + print(r"// Function to return a mask of the devices for each command", + file=fout_source) + for c in config: + get_mask_fcn_name = f"get_{prefix}_{c['name']}_mask" + print(f"uint16_t {get_mask_fcn_name}(void);", file=fout_header) + print(f"uint16_t {get_mask_fcn_name}(void) {{", file=fout_source) + print(r" return ", end="", file=fout_source) + for d in c['devicetypes']: + print(f"DEVICE_{d} | ", end="", file=fout_source) + print(r"0;", file=fout_source) + print(r"}", file=fout_source) + # special: for the firefly devices, generate a list of functions that + # return either the data in the F1 array or the data in the F2 array, + # depending on if the argument is >= than or less than NFIREFLIES_F1 + print(r"// Functions to return the data in the F1 or F2 arrays", file=fout_source) + config = data['define'] #['FF_SHARED_REGS'] + #print(config) for c in config: - get_mask_fcn_name = f"get_{prefix}_{c['name']}_mask" - print(f"uint16_t {get_mask_fcn_name}(void);", file=fout_header) - print(f"uint16_t {get_mask_fcn_name}(void) {{", file=fout_source) - print(r" return ", end="", file=fout_source) - for d in c['devicetypes']: - print(f"DEVICE_{d} | ", end="", file=fout_source) - print(r"0;", file=fout_source) - print(r"}", file=fout_source) - # special: for the firefly devices, generate a list of functions that - # return either the data in the F1 array or the data in the F2 array, - # depending on if the argument is >= than or less than 10 - print(r"// Functions to return the data in the F1 or F2 arrays", file=fout_source) - config = data['define'] #['FF_SHARED_REGS'] - #print(config) - for c in config: - data_name_f1 = f"FF_F1_{c['name']}_data" - data_name_f2 = f"FF_F2_{c['name']}_data" - get_fcn_name_f1 = f"get_FF_F1_{c['name']}_data" - get_fcn_name_f2 = f"get_FF_F2_{c['name']}_data" - get_fcn_name = f"get_FF_{c['name']}_data" - # write a preprocessor macro that uses a trigram to select the correct function - print(f"#define {get_fcn_name}(which) \\", - file=fout_header) - print(f" ((which) < NFIREFLIES_F1 ? {get_fcn_name_f1}((which)) : {get_fcn_name_f2}((which) - NFIREFLIES_F1))", - file=fout_header) - - # # write get_fcn_name header to the header file - # print(f"uint16_t {get_fcn_name}(int which);", file=fout_header) - # # write body of get_fcn_name to the source file - # print(f"uint16_t {get_fcn_name}(int which) {{", file=fout_source) - # print( " if (which < NFIREFLIES_F1) {{", file=fout_source) - # print(f" return {data_name_f1}[which];", file=fout_source) - # print( " }} else {{", file=fout_source) - # print(f" return {data_name_f2}[which - NFIREFLIES_F1];", file=fout_source) - # print( " }}", file=fout_source) - # print(r"}", file=fout_source) - # closing header guard - print(r"#endif// MON_I2C_ADDRESSES_H", file=fout_header) - -# reformat the c file using clang-format -# -style=file:$HOME/src/apollo_cm_mcu/.clang-format -# if the clang-format fails, we just ignore it -try: - r = subprocess.run(["clang-format", "-i", source_fname, header_fname], check=False) - if r.returncode != 0 and args.verbose: - print('clang-format failed') - if args.verbose: - print('clang-format complete') -except FileNotFoundError as e: - if args.verbose: - print(f"clang-format not found: {e}") + data_name_f1 = f"FF_F1_{c['name']}_data" + data_name_f2 = f"FF_F2_{c['name']}_data" + get_fcn_name_f1 = f"get_{data_name_f1}" + get_fcn_name_f2 = f"get_{data_name_f2}" + get_fcn_name = f"get_FF_{c['name']}_data" + # write a preprocessor macro that uses a trigram to select the correct function + print(f"#define {get_fcn_name}(which) \\", + file=fout_header) + print(f" ((which) < NFIREFLIES_F1 ? {get_fcn_name_f1}((which)) : {get_fcn_name_f2}((which) - NFIREFLIES_F1))", + file=fout_header) + + # closing header guard + print(r"#endif// MON_I2C_ADDRESSES_H", file=fout_header) + + # reformat the c file using clang-format + # -style=file:$HOME/src/apollo_cm_mcu/.clang-format + # if the clang-format fails, we just ignore it + try: + r = subprocess.run(["clang-format", "-i", source_fname, header_fname], check=False) + if r.returncode != 0 and args.verbose: + print('clang-format failed') + if args.verbose: + print('clang-format complete') + except FileNotFoundError as e: + if args.verbose: + print(f"clang-format not found: {e}") + +if __name__ == '__main__': + main() From 3992ba44019e34047f6cfbedd60901f7b78b1c86 Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Mon, 3 Jun 2024 09:47:36 -0400 Subject: [PATCH 50/71] cleanup --- Makefile | 2 +- projects/cm_mcu/MonUtils.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index e441c3af..93387138 100644 --- a/Makefile +++ b/Makefile @@ -42,7 +42,7 @@ check-for-pr: format @./buildall.sh -# 2nd dollar sign in grep is to pass along a single dollar sign to make +# 2nd dollar sign in grep command is to pass along a single dollar sign to egrep itself format: run-clang-format.py $(shell git diff --diff-filter=AM --name-only master | egrep '\.[ch]$$') diff --git a/projects/cm_mcu/MonUtils.c b/projects/cm_mcu/MonUtils.c index 42761cfc..40383b64 100644 --- a/projects/cm_mcu/MonUtils.c +++ b/projects/cm_mcu/MonUtils.c @@ -76,7 +76,7 @@ int FireflyType(int device) int thistype; if (!isF1) mask = ff_bitmask_args[2].ffpart_bit_mask; - if (mask & (0x1U << (device/2))) { + if (mask & (0x1U << (device / 2))) { thistype = DEVICE_25G12; } else { From ba989b95653070b29e4c595471b3052eaf4b6210 Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Tue, 4 Jun 2024 16:14:22 -0400 Subject: [PATCH 51/71] reduce scope and label active low --- projects/cm_mcu/FireflyUtils.c | 100 +++++++++++++++++++-------------- 1 file changed, 59 insertions(+), 41 deletions(-) diff --git a/projects/cm_mcu/FireflyUtils.c b/projects/cm_mcu/FireflyUtils.c index 100894ba..a299b175 100644 --- a/projects/cm_mcu/FireflyUtils.c +++ b/projects/cm_mcu/FireflyUtils.c @@ -36,30 +36,17 @@ struct ff_bit_mask_t ff_bitmask_args[4] = { }; #endif -// outputs from *_PRESENT pins for constructing ff_PRESENT_mask -#ifdef REV1 -// 4.05 I2C KU15P OPTICS -uint32_t present_FFL4_F1, present_FFL12_F1, - // 4.06 I2C VU7P OPTICS (the I/O expanders at 0x20 and 0x21 have mixed 4-ch (ffl4) and 12-ch (FFL12) pins) - present_0X20_F2, present_0X21_F2, present_FFL4_0X20_F2, present_FFL12_0X20_F2, - present_FFL4_0X21_F2, present_FFL12_0X21_F2 = 0; -#elif defined(REV2) -// 4.05 I2C FPGA31 OPTICS -uint32_t present_FFL4_F1, present_FFL12_F1, - // 4.06 I2C FPGA2 OPTICS - present_FFL4_F2, present_FFL12_F2 = 0; -#endif // REV2 void setFFmask(uint32_t ff_combined_present) { - log_info(LOG_SERVICE, "Setting a bit mask of enabled Fireflys to 1 \r\n"); + log_info(LOG_SERVICE, "%s:FF EEPROM masks\r\n"); // int32_t data = (~ff_combined_present) & 0xFFFFFU; // the bit value for an FF mask is an inverted bit value of the PRESENT signals #ifdef REV1 uint32_t data = (~ff_combined_present) & 0x1FFFFFFU; #elif defined(REV2) - uint32_t data = (~ff_combined_present) & 0xFFFFFU; + uint32_t data = (ff_combined_present) & 0xFFFFFU; #endif // REV1 ff_USER_mask = read_eeprom_single(EEPROM_ID_FF_ADDR); ff_PRESENT_mask = data; @@ -79,6 +66,20 @@ void setFFmask(uint32_t ff_combined_present) void readFFpresent(void) { + // outputs from *_PRESENT pins for constructing ff_PRESENT_mask +#ifdef REV1 + // 4.05 I2C KU15P OPTICS + uint32_t present_FFL4_F1, present_FFL12_F1, + // 4.06 I2C VU7P OPTICS (the I/O expanders at 0x20 and 0x21 have mixed 4-ch (ffl4) and 12-ch (FFL12) pins) + present_0X20_F2, present_0X21_F2, present_FFL4_0X20_F2, present_FFL12_0X20_F2, + present_FFL4_0X21_F2, present_FFL12_0X21_F2 = 0; +#elif defined(REV2) + // 4.05 I2C FPGA31 OPTICS + uint32_t present_FFL4_F1_bar, present_FFL12_F1_bar, + // 4.06 I2C FPGA2 OPTICS + present_FFL4_F2_bar, present_FFL12_F2_bar = 0; +#endif // REV2 + // grab the semaphore to ensure unique access to I2C controller // otherwise, block its operations indefinitely until it's available acquireI2CSemaphoreBlock(i2c4_sem); @@ -93,11 +94,13 @@ void readFFpresent(void) #elif defined(REV2) // to port 7 apollo_i2c_ctl_w(4, 0x70, 1, 0x80); - apollo_i2c_ctl_reg_r(4, 0x20, 1, 0x01, 1, &present_FFL12_F1); + apollo_i2c_ctl_reg_r(4, 0x20, 1, 0x01, 1, &present_FFL12_F1_bar); // active low // to port 6 apollo_i2c_ctl_w(4, 0x71, 1, 0x40); - apollo_i2c_ctl_reg_r(4, 0x21, 1, 0x00, 1, &present_FFL4_F1); + apollo_i2c_ctl_reg_r(4, 0x21, 1, 0x00, 1, &present_FFL4_F1_bar); // active low apollo_i2c_ctl_reg_r(4, 0x21, 1, 0x01, 1, &f1_ff12xmit_4v0_sel); // reading FPGA1 12-ch xmit FF's power-supply physical selection (i.e either 3.3v or 4.0v) + f1_ff12xmit_4v0_sel = (f1_ff12xmit_4v0_sel >> 4) & 0x7; // bits 4-6 + #endif // if we have a semaphore, give it @@ -119,11 +122,12 @@ void readFFpresent(void) #elif defined(REV2) // to port 7 apollo_i2c_ctl_w(3, 0x70, 1, 0x80); - apollo_i2c_ctl_reg_r(3, 0x20, 1, 0x01, 1, &present_FFL12_F2); + apollo_i2c_ctl_reg_r(3, 0x20, 1, 0x01, 1, &present_FFL12_F2_bar); // active low // to port 6 apollo_i2c_ctl_w(3, 0x71, 1, 0x40); - apollo_i2c_ctl_reg_r(3, 0x21, 1, 0x00, 1, &present_FFL4_F2); + apollo_i2c_ctl_reg_r(3, 0x21, 1, 0x00, 1, &present_FFL4_F2_bar); // active low apollo_i2c_ctl_reg_r(3, 0x21, 1, 0x01, 1, &f2_ff12xmit_4v0_sel); // reading FPGA2 12-ch xmit FF's power-supply physical selection (i.e either 3.3v or 4.0v) + f2_ff12xmit_4v0_sel = (f2_ff12xmit_4v0_sel >> 4) & 0x7; // bits 4-6 #endif // if we have a semaphore, give it @@ -149,23 +153,30 @@ void readFFpresent(void) ((present_FFL12_BOTTOM_F1)); // 6 bits #elif defined(REV2) - present_FFL12_F1 = present_FFL12_F1 & 0x3FU; // bottom 6 bits - present_FFL12_F2 = present_FFL12_F2 & 0x3FU; // bottom 6 bits - present_FFL4_F1 = (present_FFL4_F1 >> 4) & 0xFU; // bits 4-7 - present_FFL4_F2 = (present_FFL4_F2 >> 4) & 0xFU; // bits 4-7 - - uint32_t ff_combined_present = ((present_FFL4_F2) << 16) | // 4 bits - ((present_FFL12_F2) << 10) | // 6 bits - (present_FFL4_F1) << 6 | // 4 bits - ((present_FFL12_F1)); // 6 bits - - ff_bitmask_args[1].present_bit_mask = (~present_FFL4_F1) & 0xFU; // 4 bits - ff_bitmask_args[0].present_bit_mask = (~present_FFL12_F1) & 0x3FU; // 6 bits - ff_bitmask_args[3].present_bit_mask = (~present_FFL4_F2) & 0xFU; // 4 bits - ff_bitmask_args[2].present_bit_mask = (~present_FFL12_F2) & 0x3FU; // 6 bits - - f1_ff12xmit_4v0_sel = (f1_ff12xmit_4v0_sel >> 4) & 0x7; // bits 4-6 - f2_ff12xmit_4v0_sel = (f2_ff12xmit_4v0_sel >> 4) & 0x7; // bits 4-6 + present_FFL12_F1_bar = present_FFL12_F1_bar & 0x3FU; // bottom 6 bits + present_FFL12_F2_bar = present_FFL12_F2_bar & 0x3FU; // bottom 6 bits + present_FFL4_F1_bar = (present_FFL4_F1_bar >> 4) & 0xFU; // bits 4-7 + present_FFL4_F2_bar = (present_FFL4_F2_bar >> 4) & 0xFU; // bits 4-7 + + // active low + uint32_t ff_combined_present_bar = ((present_FFL4_F2_bar) << 16) | // 4 bits + ((present_FFL12_F2_bar) << 10) | // 6 bits + (present_FFL4_F1_bar) << 6 | // 4 bits + ((present_FFL12_F1_bar)); // 6 bits + uint32_t ff_combined_present = ~ff_combined_present_bar; // make active high + // masks are active high + ff_bitmask_args[1].present_bit_mask = (~present_FFL4_F1_bar) & 0xFU; // 4 bits + ff_bitmask_args[0].present_bit_mask = (~present_FFL12_F1_bar) & 0x3FU; // 6 bits + ff_bitmask_args[3].present_bit_mask = (~present_FFL4_F2_bar) & 0xFU; // 4 bits + ff_bitmask_args[2].present_bit_mask = (~present_FFL12_F2_bar) & 0x3FU; // 6 bits + + // dump all the masks using log_info + log_info(LOG_SERVICE, "F1 4v0 switch: 0x%x\r\n", f1_ff12xmit_4v0_sel); + log_info(LOG_SERVICE, "F2 4v0 switch: 0x%x\r\n", f2_ff12xmit_4v0_sel); + log_info(LOG_SERVICE, "F1 12-ch FF mask: 0x%02x\r\n", ff_bitmask_args[0].present_bit_mask); + log_info(LOG_SERVICE, "F1 4-ch FF mask: 0x%02x\r\n", ff_bitmask_args[1].present_bit_mask); + log_info(LOG_SERVICE, "F2 12-ch FF mask: 0x%02x\r\n", ff_bitmask_args[2].present_bit_mask); + log_info(LOG_SERVICE, "F2 4-ch FF mask: 0x%02x\r\n", ff_bitmask_args[3].present_bit_mask); #endif setFFmask(ff_combined_present); @@ -309,19 +320,26 @@ uint32_t ff_map_25gb_parts(void) } } log_info(LOG_SERVICE, "ff 25G12 mask: 0x%08lx\r\n", ff_25gb_parts); - // these masks have one bit per pair of receiver/transceiver - ff_bitmask_args[0].ffpart_bit_mask = ff_25gb_pairs & 0x7U; - ff_bitmask_args[2].ffpart_bit_mask = (ff_25gb_pairs >> 10) & 0x7U; + // these masks have one bit per pair of receiver/transceiver FIXME: do they? + // ff_bitmask_args[0].ffpart_bit_mask = ff_25gb_pairs & 0x7U; + // ff_bitmask_args[2].ffpart_bit_mask = (ff_25gb_pairs >> 5) & 0x7U; + ff_bitmask_args[0].ffpart_bit_mask = ff_25gb_parts & 0x3fU; // six bits + ff_bitmask_args[2].ffpart_bit_mask = (ff_25gb_parts >> 10) & 0x3fU; + // dump the masks + log_info(LOG_SERVICE, "F1 25G12 mask: 0x%02x\r\n", ff_bitmask_args[0].ffpart_bit_mask); + log_info(LOG_SERVICE, "F2 25G12 mask: 0x%02x\r\n", ff_bitmask_args[2].ffpart_bit_mask); + log_info(LOG_SERVICE, "Fx 25G12 pair mask: 0x%02x\r\n", ff_25gb_pairs); + log_info(LOG_SERVICE, "Fx 25G12 mask: 0x%02x\r\n", ff_25gb_parts); // check if the 4v switch settings match // F1 if (ff_bitmask_args[0].ffpart_bit_mask != f1_ff12xmit_4v0_sel) { log_error(LOG_SERVICE, "4v switch and part mismatch F1: 0x%x != 0x%x\r\n", - ff_bitmask_args[0].ffpart_bit_mask, f1_ff12xmit_4v0_sel); + f1_ff12xmit_4v0_sel, ff_bitmask_args[0].ffpart_bit_mask); } // F2 if (ff_bitmask_args[2].ffpart_bit_mask != f2_ff12xmit_4v0_sel) { log_error(LOG_SERVICE, "4v switch and part mismatch F2: 0x%x != 0x%x\r\n", - ff_bitmask_args[2].ffpart_bit_mask, f2_ff12xmit_4v0_sel); + f2_ff12xmit_4v0_sel, ff_bitmask_args[2].ffpart_bit_mask); } return ff_25gb_parts; } From a6cce464f109d959b871b07c3fca5808d1973e1e Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Tue, 4 Jun 2024 16:15:30 -0400 Subject: [PATCH 52/71] clean up comments --- projects/cm_mcu/FireflyUtils.h | 3 +-- projects/cm_mcu/PowerSupplyTask.c | 10 +++++++--- projects/cm_mcu/commands/SensorControl.c | 4 ++-- sm_cm_config/data/MON_I2C_rev2.yml | 2 +- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/projects/cm_mcu/FireflyUtils.h b/projects/cm_mcu/FireflyUtils.h index 2debe817..dc72fb25 100644 --- a/projects/cm_mcu/FireflyUtils.h +++ b/projects/cm_mcu/FireflyUtils.h @@ -58,7 +58,6 @@ extern struct arg_moni2c_ff_t ff_moni2c_arg[NFIREFLY_ARG]; bool getFFch_low(uint8_t val, int channel); bool getFFch_high(uint8_t val, int channel); bool isEnabledFF(int ff); -void setFFmask(uint32_t ff_combined_mask); void readFFpresent(void); uint16_t getFFtemp(const uint8_t i); float getFFavgoptpow(const uint8_t i); @@ -90,7 +89,7 @@ extern struct ff_bit_mask_t ff_bitmask_args[NFIREFLY_ARG]; #ifdef REV1 extern uint32_t present_0X20_F2, present_0X21_F2, present_FFLDAQ_F1, present_FFL12_F1, present_FFLDAQ_0X20_F2, present_FFL12_0X20_F2, present_FFLDAQ_0X21_F2, present_FFL12_0X21_F2; #elif defined(REV2) -extern uint32_t present_FFLDAQ_F1, present_FFL12_F1, present_FFLDAQ_F2, present_FFL12_F2; +extern uint32_t present_FFLDAQ_F1, present_FFL12_F1_bar, present_FFLDAQ_F2, present_FFL12_F2_bar; #endif // REV2 #endif // FIREFLYUTILS_H diff --git a/projects/cm_mcu/PowerSupplyTask.c b/projects/cm_mcu/PowerSupplyTask.c index e143ecc2..ff6db616 100644 --- a/projects/cm_mcu/PowerSupplyTask.c +++ b/projects/cm_mcu/PowerSupplyTask.c @@ -406,17 +406,21 @@ void PowerSupplyTask(void *parameters) // check 12-ch FF parts from vendors on FPGA1/2 vTaskDelay(pdMS_TO_TICKS(1000)); ff_map_25gb_parts(); - UBaseType_t ffmask[2] = {0xe, 0xe}; + UBaseType_t ffmask[2] = {0xe, 0xe}; // TODO why are these hardcoded? if ((f1_ff12xmit_4v0_sel ^ ff_bitmask_args[0].ffpart_bit_mask) == 0x0U && (f2_ff12xmit_4v0_sel ^ ff_bitmask_args[2].ffpart_bit_mask) == 0x0U) { int ret = enable_3v8(ffmask, false); // enable v38 - if (ret != 0) + if (ret != 0) { log_info(LOG_PWRCTL, "enable 3v8 failed with %d\r\n", ret); - else + } + else { log_info(LOG_PWRCTL, "enable 3v8 \r\n"); + } blade_power_ok(true); nextState = POWER_ON; } else { + log_info(LOG_PWRCTL, "FF 4V0 part check failed: %x!=%x||%x!=%x\r\n", + f1_ff12xmit_4v0_sel, ff_bitmask_args[0].ffpart_bit_mask, f2_ff12xmit_4v0_sel, ff_bitmask_args[2].ffpart_bit_mask); int ret = enable_3v8(ffmask, true); // disable v38 if (ret == 0) log_info(LOG_PWRCTL, "disable 3v8\r\n"); diff --git a/projects/cm_mcu/commands/SensorControl.c b/projects/cm_mcu/commands/SensorControl.c index b4e10a32..08231561 100644 --- a/projects/cm_mcu/commands/SensorControl.c +++ b/projects/cm_mcu/commands/SensorControl.c @@ -165,7 +165,7 @@ static int disable_transmit(bool disable, int num_ff) value &= 0x000fU; // only 4 LSB matter, so mask out others ret += write_ff_register(ff_moni2c_addrs[i].name, ECU0_25G_XVCR_TX_DISABLE_REG, value, 1, i2c_dev); } - else if (strstr(ff_moni2c_addrs[i].name, "Tx") != NULL) { // FIXME: check for CERNB vs 25G + else if (strstr(ff_moni2c_addrs[i].name, "Tx") != NULL) { // same for all 12 channel parts ret += write_ff_register(ff_moni2c_addrs[i].name, ECU0_14G_TX_DISABLE_REG, value, 2, i2c_dev); } } @@ -197,7 +197,7 @@ static int disable_receivers(bool disable, int num_ff) value &= 0x000fU; // only 4 LSB matter, so mask out others ret += write_ff_register(ff_moni2c_addrs[i].name, ECU0_25G_XVCR_RX_DISABLE_REG, value, 1, i2c_dev); } - else if (strstr(ff_moni2c_addrs[i].name, "Rx") != NULL) { // FIXME: check for CERNB vs 25G + else if (strstr(ff_moni2c_addrs[i].name, "Rx") != NULL) { // Same for CERNB vs 25G ret += write_ff_register(ff_moni2c_addrs[i].name, ECU0_14G_RX_DISABLE_REG, value, 2, i2c_dev); } } diff --git a/sm_cm_config/data/MON_I2C_rev2.yml b/sm_cm_config/data/MON_I2C_rev2.yml index 881b8ca6..a29e01fd 100644 --- a/sm_cm_config/data/MON_I2C_rev2.yml +++ b/sm_cm_config/data/MON_I2C_rev2.yml @@ -42,7 +42,7 @@ define: &FF_SHARED_REGS units: "" type: PM_STATUS devicetypes: [25G4, 25G12] - - name: OPT_POWER_CH1 # FIXME: 25G12 is on different page than 25G4 >:-| + - name: OPT_POWER_CH1 # 25G12 is on different page than 25G4 >:-| reg_size: 1 page: [0, 0, 0, 1] reg_address: [-1, -1, 34, 228] From c154dbbd91e054e4f024f044fe3dd9b1016caf45 Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Tue, 4 Jun 2024 16:16:23 -0400 Subject: [PATCH 53/71] clang-format --- projects/cm_mcu/FireflyUtils.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/cm_mcu/FireflyUtils.c b/projects/cm_mcu/FireflyUtils.c index a299b175..57661b72 100644 --- a/projects/cm_mcu/FireflyUtils.c +++ b/projects/cm_mcu/FireflyUtils.c @@ -163,8 +163,8 @@ void readFFpresent(void) ((present_FFL12_F2_bar) << 10) | // 6 bits (present_FFL4_F1_bar) << 6 | // 4 bits ((present_FFL12_F1_bar)); // 6 bits - uint32_t ff_combined_present = ~ff_combined_present_bar; // make active high - // masks are active high + uint32_t ff_combined_present = ~ff_combined_present_bar; // make active high + // masks are active high ff_bitmask_args[1].present_bit_mask = (~present_FFL4_F1_bar) & 0xFU; // 4 bits ff_bitmask_args[0].present_bit_mask = (~present_FFL12_F1_bar) & 0x3FU; // 6 bits ff_bitmask_args[3].present_bit_mask = (~present_FFL4_F2_bar) & 0xFU; // 4 bits From 0695e654d1bbdac50fdabaaf39b03b8bfe52773f Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Tue, 4 Jun 2024 22:35:02 -0400 Subject: [PATCH 54/71] WIP --- projects/cm_mcu/FireflyUtils.c | 28 +++++++++++++----- projects/cm_mcu/LocalTasks.c | 49 ++++++++++++++++++------------- projects/cm_mcu/MonUtils.c | 7 +++-- projects/cm_mcu/MonitorTaskI2C.c | 7 +++-- projects/cm_mcu/PowerSupplyTask.c | 11 ++++--- 5 files changed, 66 insertions(+), 36 deletions(-) diff --git a/projects/cm_mcu/FireflyUtils.c b/projects/cm_mcu/FireflyUtils.c index 57661b72..657e5d8f 100644 --- a/projects/cm_mcu/FireflyUtils.c +++ b/projects/cm_mcu/FireflyUtils.c @@ -40,7 +40,7 @@ struct ff_bit_mask_t ff_bitmask_args[4] = { void setFFmask(uint32_t ff_combined_present) { - log_info(LOG_SERVICE, "%s:FF EEPROM masks\r\n"); + log_info(LOG_SERVICE, "%s:FF EEPROM masks\r\n", __func__); // int32_t data = (~ff_combined_present) & 0xFFFFFU; // the bit value for an FF mask is an inverted bit value of the PRESENT signals #ifdef REV1 @@ -329,18 +329,32 @@ uint32_t ff_map_25gb_parts(void) log_info(LOG_SERVICE, "F1 25G12 mask: 0x%02x\r\n", ff_bitmask_args[0].ffpart_bit_mask); log_info(LOG_SERVICE, "F2 25G12 mask: 0x%02x\r\n", ff_bitmask_args[2].ffpart_bit_mask); log_info(LOG_SERVICE, "Fx 25G12 pair mask: 0x%02x\r\n", ff_25gb_pairs); - log_info(LOG_SERVICE, "Fx 25G12 mask: 0x%02x\r\n", ff_25gb_parts); + // pair mask into two parts + uint32_t pair_mask_low = ff_25gb_pairs & 0x7U; // 3 bits + uint32_t pair_mask_high = (ff_25gb_pairs >> 5) & 0x7U; // 3 pairs of Tx/Rx + 2 XCVRs = 5 shifts + log_info(LOG_SERVICE, "F1 25G pair mask: 0x%02x\r\n", pair_mask_low); + log_info(LOG_SERVICE, "F2 25G pair mask: 0x%02x\r\n", pair_mask_high); // check if the 4v switch settings match // F1 - if (ff_bitmask_args[0].ffpart_bit_mask != f1_ff12xmit_4v0_sel) { + if (pair_mask_low != f1_ff12xmit_4v0_sel) { log_error(LOG_SERVICE, "4v switch and part mismatch F1: 0x%x != 0x%x\r\n", - f1_ff12xmit_4v0_sel, ff_bitmask_args[0].ffpart_bit_mask); + f1_ff12xmit_4v0_sel, pair_mask_low); } // F2 - if (ff_bitmask_args[2].ffpart_bit_mask != f2_ff12xmit_4v0_sel) { + if (pair_mask_high != f2_ff12xmit_4v0_sel) { log_error(LOG_SERVICE, "4v switch and part mismatch F2: 0x%x != 0x%x\r\n", - f2_ff12xmit_4v0_sel, ff_bitmask_args[2].ffpart_bit_mask); + f2_ff12xmit_4v0_sel, pair_mask_high); } - return ff_25gb_parts; + // // F1 + // if (ff_bitmask_args[0].ffpart_bit_mask != f1_ff12xmit_4v0_sel) { + // log_error(LOG_SERVICE, "4v switch and part mismatch F1: 0x%x != 0x%x\r\n", + // f1_ff12xmit_4v0_sel, ff_bitmask_args[0].ffpart_bit_mask); + // } + // // F2 + // if (ff_bitmask_args[2].ffpart_bit_mask != f2_ff12xmit_4v0_sel) { + // log_error(LOG_SERVICE, "4v switch and part mismatch F2: 0x%x != 0x%x\r\n", + // f2_ff12xmit_4v0_sel, ff_bitmask_args[2].ffpart_bit_mask); + // } + return ff_25gb_pairs; } #endif diff --git a/projects/cm_mcu/LocalTasks.c b/projects/cm_mcu/LocalTasks.c index 1906c649..26047ef9 100644 --- a/projects/cm_mcu/LocalTasks.c +++ b/projects/cm_mcu/LocalTasks.c @@ -852,7 +852,8 @@ int init_registers_clk(void) } void init_registers_ff(void) { - + log_info(LOG_SERVICE, "%s\r\n", __func__); + int result; // ===================================================== // CMv2 Schematic 4.05 I2C FPGA#1 OPTICS @@ -864,9 +865,9 @@ void init_registers_ff(void) acquireI2CSemaphoreBlock(i2c4_sem); // # set first I2C switch on channel 4 (U14, address 0x70) to port 7 - apollo_i2c_ctl_w(4, 0x70, 1, 0x80); - apollo_i2c_ctl_reg_w(4, 0x20, 1, 0x06, 1, 0xff); // 11111111 [P07..P00] - apollo_i2c_ctl_reg_w(4, 0x20, 1, 0x07, 1, 0xff); // 11111111 [P17..P10] + result = apollo_i2c_ctl_w(4, 0x70, 1, 0x80); + result += apollo_i2c_ctl_reg_w(4, 0x20, 1, 0x06, 1, 0xff); // 11111111 [P07..P00] + result += apollo_i2c_ctl_reg_w(4, 0x20, 1, 0x07, 1, 0xff); // 11111111 [P17..P10] // 3b) U15 default output values (I2C address 0x20 on I2C channel #4) // All signals are inputs so nothing needs to be done. @@ -877,9 +878,9 @@ void init_registers_ff(void) // All other signals are inputs // # set second I2C switch on channel 4 (U17, address 0x71) to port 6 - apollo_i2c_ctl_w(4, 0x71, 1, 0x40); - apollo_i2c_ctl_reg_w(4, 0x21, 1, 0x06, 1, 0xff); // 11111111 [P07..P00] - apollo_i2c_ctl_reg_w(4, 0x21, 1, 0x07, 1, 0xf0); // 11110000 [P17..P10] + result += apollo_i2c_ctl_w(4, 0x71, 1, 0x40); + result += apollo_i2c_ctl_reg_w(4, 0x21, 1, 0x06, 1, 0xff); // 11111111 [P07..P00] + result += apollo_i2c_ctl_reg_w(4, 0x21, 1, 0x07, 1, 0xf0); // 11110000 [P17..P10] // 4b) U18 default output values (I2C address 0x21 on I2C channel #4) // The output on P10 should default to "1". @@ -889,9 +890,13 @@ void init_registers_ff(void) // 12-lane transmitter sites for FPGA#1. // # set second I2C switch on channel 4 (U17, address 0x71) to port 6 - apollo_i2c_ctl_w(4, 0x71, 1, 0x40); - apollo_i2c_ctl_reg_w(4, 0x21, 1, 0x02, 1, 0x00); // 00000000 [P07..P00] - apollo_i2c_ctl_reg_w(4, 0x21, 1, 0x03, 1, 0x01); // 00000001 [P17..P10] + result += apollo_i2c_ctl_w(4, 0x71, 1, 0x40); + result += apollo_i2c_ctl_reg_w(4, 0x21, 1, 0x02, 1, 0x00); // 00000000 [P07..P00] + result += apollo_i2c_ctl_reg_w(4, 0x21, 1, 0x03, 1, 0x01); // 00000001 [P17..P10] + + if (result) { + log_error(LOG_SERVICE, "\tFailed to initialize FPGA#1 optics\r\n"); + } // if we have a semaphore, give it if (xSemaphoreGetMutexHolder(i2c4_sem) == xTaskGetCurrentTaskHandle()) { @@ -901,7 +906,7 @@ void init_registers_ff(void) // grab the semaphore to ensure unique access to I2C controller // otherwise, block its operations indefinitely until it's available acquireI2CSemaphoreBlock(i2c3_sem); - + result = 0; // ===================================================== // CMv2 Schematic 4.06 I2C FPGA#2 OPTICS @@ -909,9 +914,9 @@ void init_registers_ff(void) // All signals are inputs. // # set first I2C switch on channel 3 (U9, address 0x70) to port 7 - apollo_i2c_ctl_w(3, 0x70, 1, 0x80); - apollo_i2c_ctl_reg_w(3, 0x20, 1, 0x06, 1, 0xff); // 11111111 [P07..P00] - apollo_i2c_ctl_reg_w(3, 0x20, 1, 0x07, 1, 0xff); // 11111111 [P17..P10] + result += apollo_i2c_ctl_w(3, 0x70, 1, 0x80); + result += apollo_i2c_ctl_reg_w(3, 0x20, 1, 0x06, 1, 0xff); // 11111111 [P07..P00] + result += apollo_i2c_ctl_reg_w(3, 0x20, 1, 0x07, 1, 0xff); // 11111111 [P17..P10] // 5b) U10 default output values (I2C address 0x20 on I2C channel #3) // All signals are inputs so nothing needs to be done. @@ -922,9 +927,9 @@ void init_registers_ff(void) // All other signals are inputs // # set second I2C switch on channel 3 (U11, address 0x71) to port 6 - apollo_i2c_ctl_w(3, 0x71, 1, 0x40); - apollo_i2c_ctl_reg_w(3, 0x21, 1, 0x06, 1, 0xff); // 11111111 [P07..P00] - apollo_i2c_ctl_reg_w(3, 0x21, 1, 0x07, 1, 0xf0); // 11110000 [P17..P10] + result += apollo_i2c_ctl_w(3, 0x71, 1, 0x40); + result += apollo_i2c_ctl_reg_w(3, 0x21, 1, 0x06, 1, 0xff); // 11111111 [P07..P00] + result += apollo_i2c_ctl_reg_w(3, 0x21, 1, 0x07, 1, 0xf0); // 11110000 [P17..P10] // 6b) U12 default output values (I2C address 0x21 on I2C channel #3) // The output on P10 should default to "1". @@ -934,9 +939,13 @@ void init_registers_ff(void) // 12-lane transmitter sites for FPGA#2. // # set second I2C switch on channel 3 (U11, address 0x71) to port 6 - apollo_i2c_ctl_w(3, 0x71, 1, 0x40); - apollo_i2c_ctl_reg_w(3, 0x21, 1, 0x02, 1, 0x00); // 00000000 [P07..P00] - apollo_i2c_ctl_reg_w(3, 0x21, 1, 0x03, 1, 0x01); // 00000001 [P17..P10] + result += apollo_i2c_ctl_w(3, 0x71, 1, 0x40); + result += apollo_i2c_ctl_reg_w(3, 0x21, 1, 0x02, 1, 0x00); // 00000000 [P07..P00] + result += apollo_i2c_ctl_reg_w(3, 0x21, 1, 0x03, 1, 0x01); // 00000001 [P17..P10] + + if (result) { + log_error(LOG_SERVICE, "\tFailed to initialize FPGA#2 optics\r\n"); + } // if we have a semaphore, give it if (xSemaphoreGetMutexHolder(i2c3_sem) == xTaskGetCurrentTaskHandle()) { diff --git a/projects/cm_mcu/MonUtils.c b/projects/cm_mcu/MonUtils.c index 40383b64..cc5f8ae7 100644 --- a/projects/cm_mcu/MonUtils.c +++ b/projects/cm_mcu/MonUtils.c @@ -71,18 +71,19 @@ int FireflyType(int device) case 3: case 4: case 5: { - // this mask is set in pairs + // //this mask is set in pairs uint8_t mask = ff_bitmask_args[0].ffpart_bit_mask; // default to F1 int thistype; if (!isF1) mask = ff_bitmask_args[2].ffpart_bit_mask; - if (mask & (0x1U << (device / 2))) { + if (mask & (0x1U << (device))) { thistype = DEVICE_25G12; } else { thistype = DEVICE_CERNB; } - log_debug(LOG_SERVICE, "%s: device %d is type %d\r\n", __func__, device, thistype); + log_debug(LOG_MONI2C , "%s: %s device %d is type %d (25G mask %x)\r\n", __func__, isF1?"F1":"F2", + device, thistype, mask); return thistype; } case 6: diff --git a/projects/cm_mcu/MonitorTaskI2C.c b/projects/cm_mcu/MonitorTaskI2C.c index 27f96c4c..61e5f3da 100644 --- a/projects/cm_mcu/MonitorTaskI2C.c +++ b/projects/cm_mcu/MonitorTaskI2C.c @@ -66,6 +66,7 @@ void MonitorTaskI2C(void *parameters) // loop over devices in the device-type instance // ------------------------------- for (int device = 0; device < args->n_devices; ++device) { + log_debug(LOG_MONI2C, "%s: device %s\r\n", args->name, args->devices[device].name); // if there is a present call back and it reurns false, skip this device if (args->presentCallback && !args->presentCallback(device)) { log_debug(LOG_MONI2C, "%s: device %d not present\r\n", args->name, device); @@ -110,13 +111,15 @@ void MonitorTaskI2C(void *parameters) // check if the command is for this device // what kind of device do we have (e.g., 4 ch FF, 12 ch 25 G FF, 12 ch CERN-B FF, etc.) if ((args->commands[c].devicelist() & devtype_mask) == 0) { + log_debug(LOG_MONI2C, "%s: command %s not for device %d (mask: %x this: %x)\r\n", + args->name, args->commands[c].name, device, args->commands[c].devicelist(), devtype_mask); continue; // not for me! } - + log_debug(LOG_MONI2C, "%s: >>reg %s\r\n", args->name, args->commands[c].name); // set page register if it's different than the last time - log_debug(LOG_MONI2C, "%s: reg %s\r\n", args->name, args->commands[c].name); uint8_t page_reg_value = args->commands[c].page[devtype]; if (page_reg_value != last_page_reg_value) { + log_debug(LOG_MONI2C, "%s: new page %d\r\n", args->name, page_reg_value); int r = apollo_i2c_ctl_reg_w(args->i2c_dev, args->devices[device].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[device].name, SMBUS_get_error(r)); diff --git a/projects/cm_mcu/PowerSupplyTask.c b/projects/cm_mcu/PowerSupplyTask.c index ff6db616..3eb3cd4a 100644 --- a/projects/cm_mcu/PowerSupplyTask.c +++ b/projects/cm_mcu/PowerSupplyTask.c @@ -405,9 +405,12 @@ void PowerSupplyTask(void *parameters) else { // check 12-ch FF parts from vendors on FPGA1/2 vTaskDelay(pdMS_TO_TICKS(1000)); - ff_map_25gb_parts(); - UBaseType_t ffmask[2] = {0xe, 0xe}; // TODO why are these hardcoded? - if ((f1_ff12xmit_4v0_sel ^ ff_bitmask_args[0].ffpart_bit_mask) == 0x0U && (f2_ff12xmit_4v0_sel ^ ff_bitmask_args[2].ffpart_bit_mask) == 0x0U) { + uint32_t ff_25gb_pairs = ff_map_25gb_parts(); + uint32_t pair_mask_low = ff_25gb_pairs & 0x7U; // 3 bits + uint32_t pair_mask_high = (ff_25gb_pairs >> 5) & 0x7U; // 3 pairs of Tx/Rx + 2 XCVRs = 5 shifts + + UBaseType_t ffmask[2] = {f1_ff12xmit_4v0_sel, f2_ff12xmit_4v0_sel}; + if ((f1_ff12xmit_4v0_sel == pair_mask_low) && (f2_ff12xmit_4v0_sel == pair_mask_high)) { int ret = enable_3v8(ffmask, false); // enable v38 if (ret != 0) { log_info(LOG_PWRCTL, "enable 3v8 failed with %d\r\n", ret); @@ -420,7 +423,7 @@ void PowerSupplyTask(void *parameters) } else { log_info(LOG_PWRCTL, "FF 4V0 part check failed: %x!=%x||%x!=%x\r\n", - f1_ff12xmit_4v0_sel, ff_bitmask_args[0].ffpart_bit_mask, f2_ff12xmit_4v0_sel, ff_bitmask_args[2].ffpart_bit_mask); + f1_ff12xmit_4v0_sel, pair_mask_low, f2_ff12xmit_4v0_sel, pair_mask_high); int ret = enable_3v8(ffmask, true); // disable v38 if (ret == 0) log_info(LOG_PWRCTL, "disable 3v8\r\n"); From 6299d1bda7c669c2a51f423a830b44692abb4590 Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Wed, 5 Jun 2024 17:50:27 -0400 Subject: [PATCH 55/71] per device optical power --- projects/cm_mcu/CommandLineTask.c | 6 ++ projects/cm_mcu/FireflyUtils.c | 118 +++++++++++++++++++---- projects/cm_mcu/FireflyUtils.h | 1 + projects/cm_mcu/commands/SensorControl.c | 28 +++++- projects/cm_mcu/commands/SensorControl.h | 1 + 5 files changed, 134 insertions(+), 20 deletions(-) diff --git a/projects/cm_mcu/CommandLineTask.c b/projects/cm_mcu/CommandLineTask.c index bcfcf515..d7eb17eb 100644 --- a/projects/cm_mcu/CommandLineTask.c +++ b/projects/cm_mcu/CommandLineTask.c @@ -317,6 +317,12 @@ static struct command_t commands[] = { "Showing avg FF optical power\r\n", 0, }, + { + "ff_optpow_dev", + ff_optpow_dev, + "Showing avg FF optical power\r\n", + 1, + }, #endif // REV2 { "ff_temp", diff --git a/projects/cm_mcu/FireflyUtils.c b/projects/cm_mcu/FireflyUtils.c index 657e5d8f..a496de00 100644 --- a/projects/cm_mcu/FireflyUtils.c +++ b/projects/cm_mcu/FireflyUtils.c @@ -236,31 +236,115 @@ uint16_t getFFtemp(const uint8_t i) } #ifdef REV2 +// returns optical power in uW +// not that the 4 channel and 12 channel data is encoded differently +// see the relevant data sheets and comments below +#define SWAP_BYTES(x) __builtin_bswap16(x) float getFFavgoptpow(const uint8_t i) { uint16_t sum_val = 0; configASSERT(i < NFIREFLIES); - sum_val += get_FF_OPT_POWER_CH1_data(i); - sum_val += get_FF_OPT_POWER_CH2_data(i); - sum_val += get_FF_OPT_POWER_CH3_data(i); - sum_val += get_FF_OPT_POWER_CH4_data(i); - sum_val += get_FF_OPT_POWER_CH5_data(i); - sum_val += get_FF_OPT_POWER_CH6_data(i); - sum_val += get_FF_OPT_POWER_CH7_data(i); - sum_val += get_FF_OPT_POWER_CH8_data(i); - sum_val += get_FF_OPT_POWER_CH9_data(i); - sum_val += get_FF_OPT_POWER_CH10_data(i); - sum_val += get_FF_OPT_POWER_CH11_data(i); - sum_val += get_FF_OPT_POWER_CH12_data(i); - - float nchannels = 12.f; if (FireflyType(i) == DEVICE_25G4) { - nchannels = 4.f; + sum_val += get_FF_OPT_POWER_CH1_data(i); + sum_val += get_FF_OPT_POWER_CH2_data(i); + sum_val += get_FF_OPT_POWER_CH3_data(i); + sum_val += get_FF_OPT_POWER_CH4_data(i); + float sum_valf = sum_val / 10.f; // LSB is 0.1 uW + float nchannels = 4.f; + return sum_valf / nchannels; } - return (float)sum_val / nchannels; + else { // this is a 12 channel part; do calculation even if CERN-B + sum_val += SWAP_BYTES(get_FF_OPT_POWER_CH1_data(i)); + sum_val += SWAP_BYTES(get_FF_OPT_POWER_CH2_data(i)); + sum_val += SWAP_BYTES(get_FF_OPT_POWER_CH3_data(i)); + sum_val += SWAP_BYTES(get_FF_OPT_POWER_CH4_data(i)); + sum_val += SWAP_BYTES(get_FF_OPT_POWER_CH5_data(i)); + sum_val += SWAP_BYTES(get_FF_OPT_POWER_CH6_data(i)); + sum_val += SWAP_BYTES(get_FF_OPT_POWER_CH7_data(i)); + sum_val += SWAP_BYTES(get_FF_OPT_POWER_CH8_data(i)); + sum_val += SWAP_BYTES(get_FF_OPT_POWER_CH9_data(i)); + sum_val += SWAP_BYTES(get_FF_OPT_POWER_CH10_data(i)); + sum_val += SWAP_BYTES(get_FF_OPT_POWER_CH11_data(i)); + sum_val += SWAP_BYTES(get_FF_OPT_POWER_CH12_data(i)); + float sumvalf = sum_val / 10.f; // LSB is 0.1 uW + float nchannels = 12.f; + return sumvalf / nchannels; + } +} + +// get optical power for a single channel +float getFFoptpow(const uint8_t i, const uint8_t ch) +{ + configASSERT(i < NFIREFLIES); + configASSERT(ch < 12); + float val; + if (FireflyType(i) == DEVICE_25G4) { + switch (ch) { + case 0: + val = get_FF_OPT_POWER_CH1_data(i); + break; + case 1: + val = get_FF_OPT_POWER_CH2_data(i); + break; + case 2: + val = get_FF_OPT_POWER_CH3_data(i); + break; + case 3: + val = get_FF_OPT_POWER_CH4_data(i); + break; + default: + val = -1; + break; + } + } + else { + switch (ch) { + case 0: + val = SWAP_BYTES(get_FF_OPT_POWER_CH1_data(i)); + break; + case 1: + val = SWAP_BYTES(get_FF_OPT_POWER_CH2_data(i)); + break; + case 2: + val = SWAP_BYTES(get_FF_OPT_POWER_CH3_data(i)); + break; + case 3: + val = SWAP_BYTES(get_FF_OPT_POWER_CH4_data(i)); + break; + case 4: + val = SWAP_BYTES(get_FF_OPT_POWER_CH5_data(i)); + break; + case 5: + val = SWAP_BYTES(get_FF_OPT_POWER_CH6_data(i)); + break; + case 6: + val = SWAP_BYTES(get_FF_OPT_POWER_CH7_data(i)); + break; + case 7: + val = SWAP_BYTES(get_FF_OPT_POWER_CH8_data(i)); + break; + case 8: + val = SWAP_BYTES(get_FF_OPT_POWER_CH9_data(i)); + break; + case 9: + val = SWAP_BYTES(get_FF_OPT_POWER_CH10_data(i)); + break; + case 10: + val = SWAP_BYTES(get_FF_OPT_POWER_CH11_data(i)); + break; + case 11: + val = SWAP_BYTES(get_FF_OPT_POWER_CH12_data(i)); + break; + default: + val = 0; + break; + } + } + return val / 10.f; // LSB is 0.1 uW } +#undef SWAP_BYTES uint16_t getFFpresentbit(const uint8_t i) { @@ -330,7 +414,7 @@ uint32_t ff_map_25gb_parts(void) log_info(LOG_SERVICE, "F2 25G12 mask: 0x%02x\r\n", ff_bitmask_args[2].ffpart_bit_mask); log_info(LOG_SERVICE, "Fx 25G12 pair mask: 0x%02x\r\n", ff_25gb_pairs); // pair mask into two parts - uint32_t pair_mask_low = ff_25gb_pairs & 0x7U; // 3 bits + uint32_t pair_mask_low = ff_25gb_pairs & 0x7U; // 3 bits uint32_t pair_mask_high = (ff_25gb_pairs >> 5) & 0x7U; // 3 pairs of Tx/Rx + 2 XCVRs = 5 shifts log_info(LOG_SERVICE, "F1 25G pair mask: 0x%02x\r\n", pair_mask_low); log_info(LOG_SERVICE, "F2 25G pair mask: 0x%02x\r\n", pair_mask_high); diff --git a/projects/cm_mcu/FireflyUtils.h b/projects/cm_mcu/FireflyUtils.h index dc72fb25..e21ac5e8 100644 --- a/projects/cm_mcu/FireflyUtils.h +++ b/projects/cm_mcu/FireflyUtils.h @@ -61,6 +61,7 @@ bool isEnabledFF(int ff); void readFFpresent(void); uint16_t getFFtemp(const uint8_t i); float getFFavgoptpow(const uint8_t i); +float getFFoptpow(const uint8_t i, const uint8_t ch); uint16_t getFFpresentbit(const uint8_t i); #ifdef REV2 void getFFpart(void); diff --git a/projects/cm_mcu/commands/SensorControl.c b/projects/cm_mcu/commands/SensorControl.c index 08231561..21290bce 100644 --- a/projects/cm_mcu/commands/SensorControl.c +++ b/projects/cm_mcu/commands/SensorControl.c @@ -143,7 +143,7 @@ static int disable_transmit(bool disable, int num_ff) { int ret = 0, i = num_ff, imax = num_ff + 1; // i and imax are used as limits for the loop below. By default, only iterate once, with i=num_ff. - uint16_t value = 0xfffU; + uint16_t value = 0xffffU; // see data sheet re how bits are arranged; do not set this to 0xfffU! if (disable == false) value = 0x0U; if (num_ff == NFIREFLIES) { // if NFIREFLIES is given for num_ff, loop over ALL transmitters. @@ -872,7 +872,7 @@ BaseType_t ff_optpow(int argc, char **argv, char *m) static int i = 0; int copied = 0; if (i == 0) { - copied += snprintf(m, SCRATCH_SIZE, "FF average Optical Power\r\n"); + copied += snprintf(m, SCRATCH_SIZE, "FF average Optical Power (uW)\r\n"); } for (; i < NFIREFLIES; ++i) { bool isTx = (strstr(ff_moni2c_addrs[i].name, "Tx") != NULL); @@ -902,7 +902,29 @@ BaseType_t ff_optpow(int argc, char **argv, char *m) return pdFALSE; } -// this command takes up to two arguments +// show optical power for all channels in a single device +BaseType_t ff_optpow_dev(int argc, char **argv, char *m) +{ + // takes one argument + BaseType_t whichFF = strtol(argv[1], NULL, 10); + int copied = 0; + if (whichFF >= NFIREFLIES) { + copied += snprintf(m, SCRATCH_SIZE, "%s: choose ff number less than %d\r\n", + argv[0], NFIREFLIES); + return pdFALSE; + } + copied += snprintf(m, SCRATCH_SIZE, "FF %s Optical Power (uW)\r\n", ff_moni2c_addrs[whichFF].name); + int nchannels = FireflyType(whichFF) == DEVICE_25G4 ? 4 : 12; + for (int i = 0; i < nchannels; ++i) { + float val = getFFoptpow(whichFF, i); + int tens, frac; + float_to_ints(val, &tens, &frac); + copied += snprintf(m + copied, SCRATCH_SIZE - copied, "Ch %02d: % 5d.%02d\r\n", i, tens, frac); + } + return pdFALSE; +} + +// this command takes up to two arguments. control firefly devices BaseType_t ff_ctl(int argc, char **argv, char *m) { // argument handling diff --git a/projects/cm_mcu/commands/SensorControl.h b/projects/cm_mcu/commands/SensorControl.h index 99af5585..9fe2a600 100644 --- a/projects/cm_mcu/commands/SensorControl.h +++ b/projects/cm_mcu/commands/SensorControl.h @@ -49,6 +49,7 @@ BaseType_t adc_ctl(int argc, char **argv, char *m); // Fireflies BaseType_t ff_ctl(int argc, char **argv, char *m); BaseType_t ff_optpow(int argc, char **argv, char *m); +BaseType_t ff_optpow_dev(int argc, char **argv, char *m); BaseType_t ff_temp(int argc, char **argv, char *m); BaseType_t ff_reset(int argc, char **argv, char *m); BaseType_t ff_status(int argc, char **argv, char *m); From 8ddabb63381f01d639b6b7d85154edc419b8ec14 Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Thu, 6 Jun 2024 19:14:27 -0400 Subject: [PATCH 56/71] add getopt* and byteswap as needed --- projects/cm_mcu/FireflyUtils.c | 70 +++++++++++++--------------------- 1 file changed, 27 insertions(+), 43 deletions(-) diff --git a/projects/cm_mcu/FireflyUtils.c b/projects/cm_mcu/FireflyUtils.c index a496de00..488174d2 100644 --- a/projects/cm_mcu/FireflyUtils.c +++ b/projects/cm_mcu/FireflyUtils.c @@ -11,6 +11,7 @@ #include #include #include // memset +#include #include "MonI2C_addresses.h" #include "MonUtils.h" @@ -242,36 +243,17 @@ uint16_t getFFtemp(const uint8_t i) #define SWAP_BYTES(x) __builtin_bswap16(x) float getFFavgoptpow(const uint8_t i) { - - uint16_t sum_val = 0; configASSERT(i < NFIREFLIES); + float sum_val = 0.f; + int ch_max = 12; if (FireflyType(i) == DEVICE_25G4) { - sum_val += get_FF_OPT_POWER_CH1_data(i); - sum_val += get_FF_OPT_POWER_CH2_data(i); - sum_val += get_FF_OPT_POWER_CH3_data(i); - sum_val += get_FF_OPT_POWER_CH4_data(i); - float sum_valf = sum_val / 10.f; // LSB is 0.1 uW - float nchannels = 4.f; - return sum_valf / nchannels; + ch_max = 4; } - else { // this is a 12 channel part; do calculation even if CERN-B - sum_val += SWAP_BYTES(get_FF_OPT_POWER_CH1_data(i)); - sum_val += SWAP_BYTES(get_FF_OPT_POWER_CH2_data(i)); - sum_val += SWAP_BYTES(get_FF_OPT_POWER_CH3_data(i)); - sum_val += SWAP_BYTES(get_FF_OPT_POWER_CH4_data(i)); - sum_val += SWAP_BYTES(get_FF_OPT_POWER_CH5_data(i)); - sum_val += SWAP_BYTES(get_FF_OPT_POWER_CH6_data(i)); - sum_val += SWAP_BYTES(get_FF_OPT_POWER_CH7_data(i)); - sum_val += SWAP_BYTES(get_FF_OPT_POWER_CH8_data(i)); - sum_val += SWAP_BYTES(get_FF_OPT_POWER_CH9_data(i)); - sum_val += SWAP_BYTES(get_FF_OPT_POWER_CH10_data(i)); - sum_val += SWAP_BYTES(get_FF_OPT_POWER_CH11_data(i)); - sum_val += SWAP_BYTES(get_FF_OPT_POWER_CH12_data(i)); - float sumvalf = sum_val / 10.f; // LSB is 0.1 uW - float nchannels = 12.f; - return sumvalf / nchannels; + for ( int ch = 0; ch < ch_max; ++ch) { + sum_val += getFFoptpow(i, ch); } + return sum_val / (float)ch_max; } // get optical power for a single channel @@ -283,62 +265,64 @@ float getFFoptpow(const uint8_t i, const uint8_t ch) if (FireflyType(i) == DEVICE_25G4) { switch (ch) { case 0: - val = get_FF_OPT_POWER_CH1_data(i); + val = SWAP_BYTES(get_FF_OPT_POWER_CH1_data(i)); break; case 1: - val = get_FF_OPT_POWER_CH2_data(i); + val = SWAP_BYTES(get_FF_OPT_POWER_CH2_data(i)); break; case 2: - val = get_FF_OPT_POWER_CH3_data(i); + val = SWAP_BYTES(get_FF_OPT_POWER_CH3_data(i)); break; case 3: - val = get_FF_OPT_POWER_CH4_data(i); + val = SWAP_BYTES(get_FF_OPT_POWER_CH4_data(i)); break; default: - val = -1; + log_warn(LOG_SERVICE, "%s: invalid channel %d\r\n", __func__, ch); + val = -999.f; break; } } else { switch (ch) { case 0: - val = SWAP_BYTES(get_FF_OPT_POWER_CH1_data(i)); + val = get_FF_OPT_POWER_CH1_data(i); break; case 1: - val = SWAP_BYTES(get_FF_OPT_POWER_CH2_data(i)); + val = get_FF_OPT_POWER_CH2_data(i); break; case 2: - val = SWAP_BYTES(get_FF_OPT_POWER_CH3_data(i)); + val = get_FF_OPT_POWER_CH3_data(i); break; case 3: - val = SWAP_BYTES(get_FF_OPT_POWER_CH4_data(i)); + val = get_FF_OPT_POWER_CH4_data(i); break; case 4: - val = SWAP_BYTES(get_FF_OPT_POWER_CH5_data(i)); + val = get_FF_OPT_POWER_CH5_data(i); break; case 5: - val = SWAP_BYTES(get_FF_OPT_POWER_CH6_data(i)); + val = get_FF_OPT_POWER_CH6_data(i); break; case 6: - val = SWAP_BYTES(get_FF_OPT_POWER_CH7_data(i)); + val = get_FF_OPT_POWER_CH7_data(i); break; case 7: - val = SWAP_BYTES(get_FF_OPT_POWER_CH8_data(i)); + val = get_FF_OPT_POWER_CH8_data(i); break; case 8: - val = SWAP_BYTES(get_FF_OPT_POWER_CH9_data(i)); + val = get_FF_OPT_POWER_CH9_data(i); break; case 9: - val = SWAP_BYTES(get_FF_OPT_POWER_CH10_data(i)); + val = get_FF_OPT_POWER_CH10_data(i); break; case 10: - val = SWAP_BYTES(get_FF_OPT_POWER_CH11_data(i)); + val = get_FF_OPT_POWER_CH11_data(i); break; case 11: - val = SWAP_BYTES(get_FF_OPT_POWER_CH12_data(i)); + val = get_FF_OPT_POWER_CH12_data(i); break; default: - val = 0; + log_warn(LOG_SERVICE, "%s: invalid channel %d\r\n", __func__, ch); + val = -999.f; break; } } From 42cd9a5db75605441ae84a77056067f5d20baeaa Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Thu, 6 Jun 2024 19:14:48 -0400 Subject: [PATCH 57/71] i2c comms with FF to 400 kHz --- common/i2c_reg.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/i2c_reg.c b/common/i2c_reg.c index 6d061b9e..21cf2239 100644 --- a/common/i2c_reg.c +++ b/common/i2c_reg.c @@ -171,7 +171,7 @@ void initI2C3(const uint32_t sysclockfreq) // the I2C3 module. The last parameter sets the I2C data transfer rate. // If false the data rate is set to 100kbps and if true the data rate will // be set to 400kbps. - MAP_I2CMasterInitExpClk(I2C3_BASE, sysclockfreq, false); + MAP_I2CMasterInitExpClk(I2C3_BASE, sysclockfreq, true); while (!MAP_SysCtlPeripheralReady(SYSCTL_PERIPH_I2C3)) ; @@ -212,7 +212,7 @@ void initI2C4(const uint32_t sysclockfreq) // the I2C4 module. The last parameter sets the I2C data transfer rate. // If false the data rate is set to 100kbps and if true the data rate will // be set to 400kbps. - MAP_I2CMasterInitExpClk(I2C4_BASE, sysclockfreq, false); + MAP_I2CMasterInitExpClk(I2C4_BASE, sysclockfreq, true); while (!MAP_SysCtlPeripheralReady(SYSCTL_PERIPH_I2C4)) ; From 1a4baf38aae514409891c0468b42928a9495272a Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Thu, 6 Jun 2024 20:43:26 -0400 Subject: [PATCH 58/71] new 3.3V FF command --- projects/cm_mcu/CommandLineTask.c | 12 ++++-- projects/cm_mcu/FireflyUtils.c | 26 ++++++------ projects/cm_mcu/commands/SensorControl.c | 52 +++++++++++++++++++++++- projects/cm_mcu/commands/SensorControl.h | 1 + sm_cm_config/data/MON_I2C_rev2.yml | 11 ++++- 5 files changed, 84 insertions(+), 18 deletions(-) diff --git a/projects/cm_mcu/CommandLineTask.c b/projects/cm_mcu/CommandLineTask.c index d7eb17eb..27cf2e4c 100644 --- a/projects/cm_mcu/CommandLineTask.c +++ b/projects/cm_mcu/CommandLineTask.c @@ -314,20 +314,26 @@ static struct command_t commands[] = { { "ff_optpow", ff_optpow, - "Showing avg FF optical power\r\n", + "Show avg FF optical power\r\n", 0, }, { "ff_optpow_dev", ff_optpow_dev, - "Showing avg FF optical power\r\n", + "Show dev FF optical power\r\n", 1, }, + { + "ff_volts", + ff_v3v3, + "Show FF 3v3 mon\r\n", + 0, + }, #endif // REV2 { "ff_temp", ff_temp, - "Showing FF temperatures\r\n", + "Show FF temperatures\r\n", 0, }, {"fpga", fpga_ctl, "Show state of FPGAs\r\n", diff --git a/projects/cm_mcu/FireflyUtils.c b/projects/cm_mcu/FireflyUtils.c index 488174d2..59872c91 100644 --- a/projects/cm_mcu/FireflyUtils.c +++ b/projects/cm_mcu/FireflyUtils.c @@ -285,40 +285,40 @@ float getFFoptpow(const uint8_t i, const uint8_t ch) else { switch (ch) { case 0: - val = get_FF_OPT_POWER_CH1_data(i); + val = SWAP_BYTES(get_FF_OPT_POWER_CH1_data(i)); break; case 1: - val = get_FF_OPT_POWER_CH2_data(i); + val = SWAP_BYTES(get_FF_OPT_POWER_CH2_data(i)); break; case 2: - val = get_FF_OPT_POWER_CH3_data(i); + val = SWAP_BYTES(get_FF_OPT_POWER_CH3_data(i)); break; case 3: - val = get_FF_OPT_POWER_CH4_data(i); + val = SWAP_BYTES(get_FF_OPT_POWER_CH4_data(i)); break; case 4: - val = get_FF_OPT_POWER_CH5_data(i); + val = SWAP_BYTES(get_FF_OPT_POWER_CH5_data(i)); break; case 5: - val = get_FF_OPT_POWER_CH6_data(i); + val = SWAP_BYTES(get_FF_OPT_POWER_CH6_data(i)); break; case 6: - val = get_FF_OPT_POWER_CH7_data(i); + val = SWAP_BYTES(get_FF_OPT_POWER_CH7_data(i)); break; case 7: - val = get_FF_OPT_POWER_CH8_data(i); + val = SWAP_BYTES(get_FF_OPT_POWER_CH8_data(i)); break; case 8: - val = get_FF_OPT_POWER_CH9_data(i); + val = SWAP_BYTES(get_FF_OPT_POWER_CH9_data(i)); break; case 9: - val = get_FF_OPT_POWER_CH10_data(i); + val = SWAP_BYTES(get_FF_OPT_POWER_CH10_data(i)); break; case 10: - val = get_FF_OPT_POWER_CH11_data(i); + val = SWAP_BYTES(get_FF_OPT_POWER_CH11_data(i)); break; case 11: - val = get_FF_OPT_POWER_CH12_data(i); + val = SWAP_BYTES(get_FF_OPT_POWER_CH12_data(i)); break; default: log_warn(LOG_SERVICE, "%s: invalid channel %d\r\n", __func__, ch); @@ -326,7 +326,7 @@ float getFFoptpow(const uint8_t i, const uint8_t ch) break; } } - return val / 10.f; // LSB is 0.1 uW + return val * 10.f; // LSB is 0.1 uW, we return uW } #undef SWAP_BYTES diff --git a/projects/cm_mcu/commands/SensorControl.c b/projects/cm_mcu/commands/SensorControl.c index 21290bce..4f4cdc37 100644 --- a/projects/cm_mcu/commands/SensorControl.c +++ b/projects/cm_mcu/commands/SensorControl.c @@ -854,7 +854,6 @@ BaseType_t ff_temp(int argc, char **argv, char *m) copied += snprintf(m + copied, SCRATCH_SIZE - copied, "\r\n"); } nn = 0; - //} if (nn % 2 == 1) { m[copied++] = '\r'; @@ -1094,6 +1093,57 @@ BaseType_t ff_ctl(int argc, char **argv, char *m) return pdFALSE; } +// firefly 3.3V monitor dumper +BaseType_t ff_v3v3(int argc, char **argv, char *m) +{ + // argument handling + int copied = 0; + + static int nn = 0; + + if (nn == 0) { + // check for stale data + TickType_t now = pdTICKS_TO_S(xTaskGetTickCount()); + + if (isFFStale()) { + TickType_t last = pdTICKS_TO_S(getFFupdateTick(isFFStale())); + int mins = (now - last) / 60; + copied += snprintf(m + copied, SCRATCH_SIZE - copied, + "%s: stale data, last update %d minutes ago\r\n", argv[0], mins); + } + copied += snprintf(m + copied, SCRATCH_SIZE - copied, "FF 3V3 Mon:\r\n"); + } + + for (; nn < NFIREFLIES; ++nn) { + copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%17s: ", ff_moni2c_addrs[nn].name); + if (isEnabledFF(nn)) { + float val = (float)__builtin_bswap16(get_FF_VCC3V3_data(nn)) * 100e-6f; // LSB is 100uV + int tens, frac; + float_to_ints(val, &tens, &frac); + copied += snprintf(m + copied, SCRATCH_SIZE - copied, "% 2d.%02d", tens, frac); + } + else // dummy value + copied += snprintf(m + copied, SCRATCH_SIZE - copied, " --- "); + bool isTx = (strstr(ff_moni2c_addrs[nn].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) < 50) { + return pdTRUE; + } + } + nn = 0; + + if (nn % 2 == 1) { + m[copied++] = '\r'; + m[copied++] = '\n'; + m[copied] = '\0'; + } + + return pdFALSE; +} + // dump clock monitor information BaseType_t clkmon_ctl(int argc, char **argv, char *m) { diff --git a/projects/cm_mcu/commands/SensorControl.h b/projects/cm_mcu/commands/SensorControl.h index 9fe2a600..3a39f615 100644 --- a/projects/cm_mcu/commands/SensorControl.h +++ b/projects/cm_mcu/commands/SensorControl.h @@ -57,6 +57,7 @@ BaseType_t ff_los_alarm(int argc, char **argv, char *m); BaseType_t ff_cdr_lol_alarm(int argc, char **argv, char *m); BaseType_t ff_mux_reset(int argc, char **argv, char *m); BaseType_t ff_dump_names(int argc, char **argv, char *m); +BaseType_t ff_v3v3(int argc, char **argv, char *m); // Clocks BaseType_t clkmon_ctl(int argc, char **argv, char *m); diff --git a/sm_cm_config/data/MON_I2C_rev2.yml b/sm_cm_config/data/MON_I2C_rev2.yml index a29e01fd..c9937ed8 100644 --- a/sm_cm_config/data/MON_I2C_rev2.yml +++ b/sm_cm_config/data/MON_I2C_rev2.yml @@ -19,11 +19,20 @@ define: &FF_SHARED_REGS reg_size: 1 page: 0 reg_address: 0x16 - size: 2 + size: 1 mask: 0xFF units: C type: PM_NONVOLTAGE devicetypes: [14G, 25G12, 25G4, CERNB] + - name: VCC3V3 + reg_size: 1 + page: 0 + reg_address: 26 + size: 2 + mask: 0xFFFF + units: V + type: PM_VOLTAGE + devicetypes: [14G, 25G12, 25G4, CERNB] - name: LOS_ALARM reg_size: 1 page: 0 From 9e1bd1fe7b156fea8ce1dd3656f993c4feb08c1f Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Thu, 6 Jun 2024 20:43:38 -0400 Subject: [PATCH 59/71] logging --- projects/cm_mcu/MonUtils.c | 2 +- projects/cm_mcu/MonitorTaskI2C.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/projects/cm_mcu/MonUtils.c b/projects/cm_mcu/MonUtils.c index cc5f8ae7..55ed077b 100644 --- a/projects/cm_mcu/MonUtils.c +++ b/projects/cm_mcu/MonUtils.c @@ -82,7 +82,7 @@ int FireflyType(int device) else { thistype = DEVICE_CERNB; } - log_debug(LOG_MONI2C , "%s: %s device %d is type %d (25G mask %x)\r\n", __func__, isF1?"F1":"F2", + log_debug(LOG_MONI2C, "%s: %s device %d is type %d (25G mask %x)\r\n", __func__, isF1 ? "F1" : "F2", device, thistype, mask); return thistype; } diff --git a/projects/cm_mcu/MonitorTaskI2C.c b/projects/cm_mcu/MonitorTaskI2C.c index 61e5f3da..dda09bd3 100644 --- a/projects/cm_mcu/MonitorTaskI2C.c +++ b/projects/cm_mcu/MonitorTaskI2C.c @@ -132,7 +132,8 @@ void MonitorTaskI2C(void *parameters) uint32_t output_raw; int res = apollo_i2c_ctl_reg_r(args->i2c_dev, args->devices[device].dev_addr, args->commands[c].reg_size, args->commands[c].command[devtype], args->commands[c].size, &output_raw); - + log_debug(LOG_MONI2C, "%s: dev%02d<name, device, args->commands[c].name, page_reg_value, + args->commands[c].command[devtype], output_raw); if (res != 0) { log_error(LOG_MONI2C, "%s: %s read Error %s, break (ps=%d)\r\n", args->name, args->commands[c].name, SMBUS_get_error(res), device); From 6389eeedd2c11a8316e4c896362b3fb54485508b Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Thu, 6 Jun 2024 20:44:15 -0400 Subject: [PATCH 60/71] update enable_3v8 for passing in mask of pairs --- projects/cm_mcu/LocalTasks.c | 43 +++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/projects/cm_mcu/LocalTasks.c b/projects/cm_mcu/LocalTasks.c index 26047ef9..a608cdc8 100644 --- a/projects/cm_mcu/LocalTasks.c +++ b/projects/cm_mcu/LocalTasks.c @@ -865,10 +865,13 @@ void init_registers_ff(void) acquireI2CSemaphoreBlock(i2c4_sem); // # set first I2C switch on channel 4 (U14, address 0x70) to port 7 - result = apollo_i2c_ctl_w(4, 0x70, 1, 0x80); + result = apollo_i2c_ctl_w(4, 0x70, 1, 0x80); result += apollo_i2c_ctl_reg_w(4, 0x20, 1, 0x06, 1, 0xff); // 11111111 [P07..P00] result += apollo_i2c_ctl_reg_w(4, 0x20, 1, 0x07, 1, 0xff); // 11111111 [P17..P10] + // clear first I2C switch on channel 4 + result += apollo_i2c_ctl_w(4, 0x70, 1, 0x0); + // 3b) U15 default output values (I2C address 0x20 on I2C channel #4) // All signals are inputs so nothing needs to be done. @@ -894,6 +897,8 @@ void init_registers_ff(void) result += apollo_i2c_ctl_reg_w(4, 0x21, 1, 0x02, 1, 0x00); // 00000000 [P07..P00] result += apollo_i2c_ctl_reg_w(4, 0x21, 1, 0x03, 1, 0x01); // 00000001 [P17..P10] + //clear 2nd I2C switch on channel 4 + result += apollo_i2c_ctl_w(4, 0x70, 1, 0x0); if (result) { log_error(LOG_SERVICE, "\tFailed to initialize FPGA#1 optics\r\n"); } @@ -918,6 +923,9 @@ void init_registers_ff(void) result += apollo_i2c_ctl_reg_w(3, 0x20, 1, 0x06, 1, 0xff); // 11111111 [P07..P00] result += apollo_i2c_ctl_reg_w(3, 0x20, 1, 0x07, 1, 0xff); // 11111111 [P17..P10] + // clear first I2C switch on channel 3 + result += apollo_i2c_ctl_w(3, 0x70, 1, 0x0); + // 5b) U10 default output values (I2C address 0x20 on I2C channel #3) // All signals are inputs so nothing needs to be done. @@ -943,6 +951,9 @@ void init_registers_ff(void) result += apollo_i2c_ctl_reg_w(3, 0x21, 1, 0x02, 1, 0x00); // 00000000 [P07..P00] result += apollo_i2c_ctl_reg_w(3, 0x21, 1, 0x03, 1, 0x01); // 00000001 [P17..P10] + // clear 2nd I2C switch on channel 3 + result += apollo_i2c_ctl_w(3, 0x71, 1, 0x0); + if (result) { log_error(LOG_SERVICE, "\tFailed to initialize FPGA#2 optics\r\n"); } @@ -1107,6 +1118,9 @@ int enable_3v8(UBaseType_t ffmask[2], bool turnOff) static const uint8_t muxaddr = 0x71; // address of mux on i2c bus static const uint8_t ioexp_addr = 0x21; // address of i/o expander on i2c bus static const uint8_t ioexp_reg_addr = 3; // register address in i/o expander + int result = 0; + // dump infput ffmask + log_debug(LOG_SERVICE, "ffmask[0] 0x%x, ffmask[1] 0x%x\r\n", ffmask[0], ffmask[1]); // loop over 2 i2c modules for (int i = 0; i < 2; ++i) { if (ffmask[i] == 0) { // this device is not selected @@ -1119,7 +1133,7 @@ int enable_3v8(UBaseType_t ffmask[2], bool turnOff) return SEM_ACCESS_ERROR; } // mux setting - int result = apollo_i2c_ctl_w(i2c_device[i], muxaddr, 1, muxbit); + result += apollo_i2c_ctl_w(i2c_device[i], muxaddr, 1, muxbit); if (result) { log_warn(LOG_SERVICE, "mux err %d\r\n", result); } @@ -1128,19 +1142,36 @@ int enable_3v8(UBaseType_t ffmask[2], bool turnOff) if (turnOff) { val = ~val; // invert bits when turning off } - val &= mask; // mask out extra bits extraneously set - val |= 0x01; // make sure active low reset bit stays deasserted (i.e., LSB is high) - result = apollo_i2c_ctl_reg_w(i2c_device[i], ioexp_addr, 1, ioexp_reg_addr, 1, val); + val = (val << 1) & mask; // set bits 1-3, and mask out extra bits extraneously set + val |= 0x01; // make sure active low reset bit stays deasserted (i.e., LSB is high) + result += apollo_i2c_ctl_reg_w(i2c_device[i], ioexp_addr, 1, ioexp_reg_addr, 1, val); if (result) { log_warn(LOG_SERVICE, "expand wr %d\r\n", result); } } + // read back the value to make sure it was set correctly + uint32_t val; + result += apollo_i2c_ctl_reg_r(i2c_device[i], ioexp_addr, 1, ioexp_reg_addr, 1, &val); + log_debug(LOG_SERVICE, "%s: read 3.8V val raw 0x%x\r\n", __func__, val); + val = (val & mask) >>1; // mask and shift + if (result) { + log_warn(LOG_SERVICE, "expand rd %d\r\n", result); + } + else if (val != ffmask[i]) { + log_error(LOG_SERVICE, "expand val 0x%x != 0x%x\r\n", val, ffmask[i]); + result = 1; + } + log_info(LOG_SERVICE, "%s: set 3.8V to val 0x%x (input 0x%x)\r\n", __func__, val, + ffmask[i]); + + // clear the mux + result += apollo_i2c_ctl_w(i2c_device[i], muxaddr, 1, 0); // if we have a semaphore, give it if (xSemaphoreGetMutexHolder(semaphores[i]) == xTaskGetCurrentTaskHandle()) { xSemaphoreGive(semaphores[i]); } } - return 0; + return result; } #endif // REV2 From 35e9390f28f2b0fae16afc83608fc437235ef170 Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Thu, 6 Jun 2024 20:44:38 -0400 Subject: [PATCH 61/71] clang-format --- projects/cm_mcu/FireflyUtils.c | 2 +- projects/cm_mcu/LocalTasks.c | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/projects/cm_mcu/FireflyUtils.c b/projects/cm_mcu/FireflyUtils.c index 59872c91..229f954e 100644 --- a/projects/cm_mcu/FireflyUtils.c +++ b/projects/cm_mcu/FireflyUtils.c @@ -250,7 +250,7 @@ float getFFavgoptpow(const uint8_t i) if (FireflyType(i) == DEVICE_25G4) { ch_max = 4; } - for ( int ch = 0; ch < ch_max; ++ch) { + for (int ch = 0; ch < ch_max; ++ch) { sum_val += getFFoptpow(i, ch); } return sum_val / (float)ch_max; diff --git a/projects/cm_mcu/LocalTasks.c b/projects/cm_mcu/LocalTasks.c index a608cdc8..3457a9b9 100644 --- a/projects/cm_mcu/LocalTasks.c +++ b/projects/cm_mcu/LocalTasks.c @@ -897,7 +897,7 @@ void init_registers_ff(void) result += apollo_i2c_ctl_reg_w(4, 0x21, 1, 0x02, 1, 0x00); // 00000000 [P07..P00] result += apollo_i2c_ctl_reg_w(4, 0x21, 1, 0x03, 1, 0x01); // 00000001 [P17..P10] - //clear 2nd I2C switch on channel 4 + // clear 2nd I2C switch on channel 4 result += apollo_i2c_ctl_w(4, 0x70, 1, 0x0); if (result) { log_error(LOG_SERVICE, "\tFailed to initialize FPGA#1 optics\r\n"); @@ -1119,7 +1119,7 @@ int enable_3v8(UBaseType_t ffmask[2], bool turnOff) static const uint8_t ioexp_addr = 0x21; // address of i/o expander on i2c bus static const uint8_t ioexp_reg_addr = 3; // register address in i/o expander int result = 0; - // dump infput ffmask + // dump infput ffmask log_debug(LOG_SERVICE, "ffmask[0] 0x%x, ffmask[1] 0x%x\r\n", ffmask[0], ffmask[1]); // loop over 2 i2c modules for (int i = 0; i < 2; ++i) { @@ -1153,7 +1153,7 @@ int enable_3v8(UBaseType_t ffmask[2], bool turnOff) uint32_t val; result += apollo_i2c_ctl_reg_r(i2c_device[i], ioexp_addr, 1, ioexp_reg_addr, 1, &val); log_debug(LOG_SERVICE, "%s: read 3.8V val raw 0x%x\r\n", __func__, val); - val = (val & mask) >>1; // mask and shift + val = (val & mask) >> 1; // mask and shift if (result) { log_warn(LOG_SERVICE, "expand rd %d\r\n", result); } @@ -1161,8 +1161,8 @@ int enable_3v8(UBaseType_t ffmask[2], bool turnOff) log_error(LOG_SERVICE, "expand val 0x%x != 0x%x\r\n", val, ffmask[i]); result = 1; } - log_info(LOG_SERVICE, "%s: set 3.8V to val 0x%x (input 0x%x)\r\n", __func__, val, - ffmask[i]); + log_info(LOG_SERVICE, "%s: set 3.8V to val 0x%x (input 0x%x)\r\n", __func__, val, + ffmask[i]); // clear the mux result += apollo_i2c_ctl_w(i2c_device[i], muxaddr, 1, 0); From 7e0cb1a6fdcc1a380127532327cd5e87a89cb79e Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Fri, 7 Jun 2024 16:01:37 -0400 Subject: [PATCH 62/71] Update FireflyUtils.c delete commented out code --- projects/cm_mcu/FireflyUtils.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/projects/cm_mcu/FireflyUtils.c b/projects/cm_mcu/FireflyUtils.c index 229f954e..52b79823 100644 --- a/projects/cm_mcu/FireflyUtils.c +++ b/projects/cm_mcu/FireflyUtils.c @@ -326,7 +326,7 @@ float getFFoptpow(const uint8_t i, const uint8_t ch) break; } } - return val * 10.f; // LSB is 0.1 uW, we return uW + return val * 10.f; // LSB is 0.1 uW, we return uW } #undef SWAP_BYTES @@ -388,9 +388,7 @@ uint32_t ff_map_25gb_parts(void) } } log_info(LOG_SERVICE, "ff 25G12 mask: 0x%08lx\r\n", ff_25gb_parts); - // these masks have one bit per pair of receiver/transceiver FIXME: do they? - // ff_bitmask_args[0].ffpart_bit_mask = ff_25gb_pairs & 0x7U; - // ff_bitmask_args[2].ffpart_bit_mask = (ff_25gb_pairs >> 5) & 0x7U; + // these masks have one bit per pair of receiver/transceiver ff_bitmask_args[0].ffpart_bit_mask = ff_25gb_parts & 0x3fU; // six bits ff_bitmask_args[2].ffpart_bit_mask = (ff_25gb_parts >> 10) & 0x3fU; // dump the masks @@ -413,16 +411,6 @@ uint32_t ff_map_25gb_parts(void) log_error(LOG_SERVICE, "4v switch and part mismatch F2: 0x%x != 0x%x\r\n", f2_ff12xmit_4v0_sel, pair_mask_high); } - // // F1 - // if (ff_bitmask_args[0].ffpart_bit_mask != f1_ff12xmit_4v0_sel) { - // log_error(LOG_SERVICE, "4v switch and part mismatch F1: 0x%x != 0x%x\r\n", - // f1_ff12xmit_4v0_sel, ff_bitmask_args[0].ffpart_bit_mask); - // } - // // F2 - // if (ff_bitmask_args[2].ffpart_bit_mask != f2_ff12xmit_4v0_sel) { - // log_error(LOG_SERVICE, "4v switch and part mismatch F2: 0x%x != 0x%x\r\n", - // f2_ff12xmit_4v0_sel, ff_bitmask_args[2].ffpart_bit_mask); - // } return ff_25gb_pairs; } #endif From 1f7ab8490541fa2df44dfb2f1b6e72604cadf698 Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Tue, 11 Jun 2024 11:29:52 -0400 Subject: [PATCH 63/71] fix byteswapp on optpow --- projects/cm_mcu/FireflyUtils.c | 110 ++++++++++++++------------------- 1 file changed, 47 insertions(+), 63 deletions(-) diff --git a/projects/cm_mcu/FireflyUtils.c b/projects/cm_mcu/FireflyUtils.c index 52b79823..7564de34 100644 --- a/projects/cm_mcu/FireflyUtils.c +++ b/projects/cm_mcu/FireflyUtils.c @@ -257,74 +257,58 @@ float getFFavgoptpow(const uint8_t i) } // get optical power for a single channel +// the datasheet for the 25G12 part says to byte swap, +// but the 4 channel part does not say to do so. +// However, trial and error shows that the 4 channel part +// does need byte swapping. float getFFoptpow(const uint8_t i, const uint8_t ch) { configASSERT(i < NFIREFLIES); configASSERT(ch < 12); float val; - if (FireflyType(i) == DEVICE_25G4) { - switch (ch) { - case 0: - val = SWAP_BYTES(get_FF_OPT_POWER_CH1_data(i)); - break; - case 1: - val = SWAP_BYTES(get_FF_OPT_POWER_CH2_data(i)); - break; - case 2: - val = SWAP_BYTES(get_FF_OPT_POWER_CH3_data(i)); - break; - case 3: - val = SWAP_BYTES(get_FF_OPT_POWER_CH4_data(i)); - break; - default: - log_warn(LOG_SERVICE, "%s: invalid channel %d\r\n", __func__, ch); - val = -999.f; - break; - } - } - else { - switch (ch) { - case 0: - val = SWAP_BYTES(get_FF_OPT_POWER_CH1_data(i)); - break; - case 1: - val = SWAP_BYTES(get_FF_OPT_POWER_CH2_data(i)); - break; - case 2: - val = SWAP_BYTES(get_FF_OPT_POWER_CH3_data(i)); - break; - case 3: - val = SWAP_BYTES(get_FF_OPT_POWER_CH4_data(i)); - break; - case 4: - val = SWAP_BYTES(get_FF_OPT_POWER_CH5_data(i)); - break; - case 5: - val = SWAP_BYTES(get_FF_OPT_POWER_CH6_data(i)); - break; - case 6: - val = SWAP_BYTES(get_FF_OPT_POWER_CH7_data(i)); - break; - case 7: - val = SWAP_BYTES(get_FF_OPT_POWER_CH8_data(i)); - break; - case 8: - val = SWAP_BYTES(get_FF_OPT_POWER_CH9_data(i)); - break; - case 9: - val = SWAP_BYTES(get_FF_OPT_POWER_CH10_data(i)); - break; - case 10: - val = SWAP_BYTES(get_FF_OPT_POWER_CH11_data(i)); - break; - case 11: - val = SWAP_BYTES(get_FF_OPT_POWER_CH12_data(i)); - break; - default: - log_warn(LOG_SERVICE, "%s: invalid channel %d\r\n", __func__, ch); - val = -999.f; - break; - } + // if i is for a 4 channel part and you ask for channel 5 + // or greater, well, good luck then. It's just zero. + switch (ch) { + case 0: + val = SWAP_BYTES(get_FF_OPT_POWER_CH1_data(i)); + break; + case 1: + val = SWAP_BYTES(get_FF_OPT_POWER_CH2_data(i)); + break; + case 2: + val = SWAP_BYTES(get_FF_OPT_POWER_CH3_data(i)); + break; + case 3: + val = SWAP_BYTES(get_FF_OPT_POWER_CH4_data(i)); + break; + case 4: + val = SWAP_BYTES(get_FF_OPT_POWER_CH5_data(i)); + break; + case 5: + val = SWAP_BYTES(get_FF_OPT_POWER_CH6_data(i)); + break; + case 6: + val = SWAP_BYTES(get_FF_OPT_POWER_CH7_data(i)); + break; + case 7: + val = SWAP_BYTES(get_FF_OPT_POWER_CH8_data(i)); + break; + case 8: + val = SWAP_BYTES(get_FF_OPT_POWER_CH9_data(i)); + break; + case 9: + val = SWAP_BYTES(get_FF_OPT_POWER_CH10_data(i)); + break; + case 10: + val = SWAP_BYTES(get_FF_OPT_POWER_CH11_data(i)); + break; + case 11: + val = SWAP_BYTES(get_FF_OPT_POWER_CH12_data(i)); + break; + default: + log_warn(LOG_SERVICE, "%s: invalid channel %d\r\n", __func__, ch); + val = -999.f; + break; } return val * 10.f; // LSB is 0.1 uW, we return uW } From 6ce5e592f947acb0ceb84a33c50bf29733f1dc87 Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Tue, 11 Jun 2024 11:30:27 -0400 Subject: [PATCH 64/71] remove check on 4.0V --- projects/cm_mcu/PowerSupplyTask.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/projects/cm_mcu/PowerSupplyTask.c b/projects/cm_mcu/PowerSupplyTask.c index 3eb3cd4a..49d74a54 100644 --- a/projects/cm_mcu/PowerSupplyTask.c +++ b/projects/cm_mcu/PowerSupplyTask.c @@ -494,10 +494,6 @@ void PowerSupplyTask(void *parameters) } } } -#ifdef REV2 // PG_4V0 is not helpful to read from. assert that PWR_FAILED - if ((f1_ff12xmit_4v0_sel ^ ff_bitmask_args[0].ffpart_bit_mask) != 0x0U || (f2_ff12xmit_4v0_sel ^ ff_bitmask_args[2].ffpart_bit_mask) != 0x0U) - setPSStatus(N_PS_OKS - 1, PWR_FAILED); -#endif if (currentState != nextState) { log_debug(LOG_PWRCTL, "%s: change from state %s to %s\r\n", pcTaskGetName(NULL), power_system_state_names[currentState], power_system_state_names[nextState]); From 6b1f40a04af2e084bbd59f7514dcd5f68a3cf3b2 Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Tue, 11 Jun 2024 11:30:54 -0400 Subject: [PATCH 65/71] housekeeping --- .clangd | 4 +- common/power_ctl.c | 7 +-- projects/cm_mcu/commands/SensorControl.c | 63 +++++++++++++----------- 3 files changed, 39 insertions(+), 35 deletions(-) diff --git a/.clangd b/.clangd index 8011e789..9be52102 100644 --- a/.clangd +++ b/.clangd @@ -2,5 +2,5 @@ Diagnostics: ClangTidy: Add: modernize* Remove: readability-braces-around-statements -CompileFlags: - Add: [-Wunused-parameter] +#CompileFlags: + #Add: [-Wunused-parameter] diff --git a/common/power_ctl.c b/common/power_ctl.c index 70a723a3..529b654d 100644 --- a/common/power_ctl.c +++ b/common/power_ctl.c @@ -5,17 +5,14 @@ * Author: wittich */ -#include #include "common/power_ctl.h" #include "common/pinsel.h" #include "common/utils.h" -#include "driverlib/rom_map.h" -#include "driverlib/sysctl.h" #ifdef USE_FREERTOS -#include "FreeRTOS.h" +#include "FreeRTOS.h" // IWYU pragma: keep #include "task.h" #endif // USE_FREERTOS @@ -73,7 +70,7 @@ struct gpio_pin_t oks[] = { // // ------------------------------------------ // if you update this you need to update N_PS_ENABLES -static const struct gpio_pin_t enables[] = { +static const struct gpio_pin_t enables[N_PS_ENABLES] = { { EN_F1_INT, "EN_F1_INT", 1}, { EN_F2_INT, "EN_F2_INT", 1}, { EN_1V8, "EN_1V8", 2}, diff --git a/projects/cm_mcu/commands/SensorControl.c b/projects/cm_mcu/commands/SensorControl.c index 4f4cdc37..ffbfa158 100644 --- a/projects/cm_mcu/commands/SensorControl.c +++ b/projects/cm_mcu/commands/SensorControl.c @@ -793,14 +793,14 @@ BaseType_t ff_cdr_lol_alarm(int argc, char **argv, char *m) copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%17s: 0x%04x", ff_moni2c_addrs[whichff].name, val); } else { - copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%17s: %4s", ff_moni2c_addrs[whichff].name, "--"); + copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%17s: %4s", ff_moni2c_addrs[whichff].name, " -- "); } bool isTx = (strstr(ff_moni2c_addrs[whichff].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) { + if ((SCRATCH_SIZE - copied) < 30) { ++whichff; return pdTRUE; } @@ -1376,41 +1376,48 @@ BaseType_t psmon_reg(int argc, char **argv, char *m) // this command takes no arguments BaseType_t ff_dump_names(int argc, char **argv, char *m) { - int copied = 0; - copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%s: ID registers\r\n", argv[0]); static int i = 0; + int copied = 0; + if ( i == 0 ) { // not if we are on 2nd iteration + copied += snprintf(m, SCRATCH_SIZE, "%s: ID registers\r\n", argv[0]); + } for (; i < NFIREFLIES; ++i) { - if (!isEnabledFF(i)) { // skip the FF if it's not enabled via the FF config - continue; - } - - char name[17]; - memset(name, '\0', 17); - int type = FireflyType(i); - int startReg = VENDOR_START_BIT_FFDAQ; - int count = VENDOR_COUNT_FFDAQ; - if (type == DEVICE_CERNB || type == DEVICE_25G12) { - startReg = VENDOR_START_BIT_FF12; - count = VENDOR_COUNT_FF12; - } - int ret = 0; - for (unsigned char c = 0; c < count; ++c) { - uint8_t v; - ret += read_arbitrary_ff_register(startReg + c, i, &v, 1); - name[c] = v; + copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%17s: ", ff_moni2c_addrs[i].name); + if (isEnabledFF(i)) { // process if enabled + + char name[17]; + memset(name, '\0', 17); + int type = FireflyType(i); + int startReg = VENDOR_START_BIT_FFDAQ; + int count = VENDOR_COUNT_FFDAQ; + if (type == DEVICE_CERNB || type == DEVICE_25G12) { + startReg = VENDOR_START_BIT_FF12; + count = VENDOR_COUNT_FF12; + } + int ret = 0; + for (unsigned char c = 0; c < count / 4; ++c) { // read name 4 chars at a time + uint8_t v[4]; + ret += read_arbitrary_ff_register(startReg + 4 * c, i, v, 4); + name[4 * c] = v[0]; + name[4 * c + 1] = v[1]; + name[4 * c + 2] = v[2]; + name[4 * c + 3] = v[3]; + } + if (ret != 0) { + snprintf(m + copied, SCRATCH_SIZE - copied, "%s: read failed\r\n", argv[0]); + return pdFALSE; + } + copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%s", name); } - if (ret != 0) { - snprintf(m + copied, SCRATCH_SIZE - copied, "%s: read failed\r\n", argv[0]); - return pdFALSE; + else { + copied += snprintf(m + copied, SCRATCH_SIZE - copied, "--------------"); } - copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%17s:%s", ff_moni2c_addrs[i].name, name); - bool isTx = (strstr(ff_moni2c_addrs[i].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) < 25 && (i < NFIREFLIES)) { + if ((SCRATCH_SIZE - copied) < 45 && (i < NFIREFLIES)) { ++i; return pdTRUE; } From 011d9b90b870a60b2f2d49c7a336df3fff6fa322 Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Tue, 11 Jun 2024 14:10:53 -0400 Subject: [PATCH 66/71] more monitoring registers --- projects/cm_mcu/CommandLineTask.c | 12 ++++ projects/cm_mcu/commands/SensorControl.c | 91 +++++++++++++++++++++++- projects/cm_mcu/commands/SensorControl.h | 2 + sm_cm_config/data/MON_I2C_rev2.yml | 31 +++++++- 4 files changed, 132 insertions(+), 4 deletions(-) diff --git a/projects/cm_mcu/CommandLineTask.c b/projects/cm_mcu/CommandLineTask.c index 27cf2e4c..831cefd1 100644 --- a/projects/cm_mcu/CommandLineTask.c +++ b/projects/cm_mcu/CommandLineTask.c @@ -299,6 +299,18 @@ static struct command_t commands[] = { 0, }, #ifdef REV2 + { + "ff_cdr_ena", + ff_cdr_enable_status, + "Show FF CDR enable status\r\n", + 0, + }, + { + "ff_ch_dis", + ff_ch_disable_status, + "Show FF ch disable status\r\n", + 0, + }, { "ff_mux_reset", ff_mux_reset, diff --git a/projects/cm_mcu/commands/SensorControl.c b/projects/cm_mcu/commands/SensorControl.c index ffbfa158..81cbc834 100644 --- a/projects/cm_mcu/commands/SensorControl.c +++ b/projects/cm_mcu/commands/SensorControl.c @@ -769,6 +769,49 @@ BaseType_t ff_los_alarm(int argc, char **argv, char *m) return pdFALSE; } +BaseType_t ff_ch_disable_status(int argc, char **argv, char *m) +{ + int copied = 0; + + static int whichff = 0; + + if (whichff == 0) { + // check for stale data + if (isFFStale()) { + TickType_t now = pdTICKS_TO_S(xTaskGetTickCount()); + TickType_t last = pdTICKS_TO_S(getFFupdateTick(isFFStale())); + int mins = (now - last) / 60; + copied += snprintf(m + copied, SCRATCH_SIZE - copied, + "%s: stale data, last update %d minutes ago\r\n", argv[0], mins); + } + copied += snprintf(m + copied, SCRATCH_SIZE - copied, "FIREFLY LOS ALARM:\r\n"); + } + + for (; whichff < NFIREFLIES; ++whichff) { + uint16_t val = get_FF_CHANNEL_DISABLE_data(whichff); + copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%17s: 0x%04x", + ff_moni2c_addrs[whichff].name, val); + bool isTx = (strstr(ff_moni2c_addrs[whichff].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; + return pdTRUE; + } + } + + if (whichff % 2 == 1) { + m[copied++] = '\r'; + m[copied++] = '\n'; + m[copied] = '\0'; + } + whichff = 0; + + return pdFALSE; +} + BaseType_t ff_cdr_lol_alarm(int argc, char **argv, char *m) { int copied = 0; @@ -788,12 +831,14 @@ BaseType_t ff_cdr_lol_alarm(int argc, char **argv, char *m) } for (; whichff < NFIREFLIES; ++whichff) { + copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%17s: ", + ff_moni2c_addrs[whichff].name); if (FireflyType(whichff) == DEVICE_25G12 || FireflyType(whichff) == DEVICE_25G4) { uint16_t val = get_FF_CDR_LOL_ALARM_data(whichff); - copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%17s: 0x%04x", ff_moni2c_addrs[whichff].name, val); + copied += snprintf(m + copied, SCRATCH_SIZE - copied, "0x%04x", val); } else { - copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%17s: %4s", ff_moni2c_addrs[whichff].name, " -- "); + copied += snprintf(m + copied, SCRATCH_SIZE - copied, " -- "); } bool isTx = (strstr(ff_moni2c_addrs[whichff].name, "Tx") != NULL); if (isTx) @@ -815,6 +860,48 @@ BaseType_t ff_cdr_lol_alarm(int argc, char **argv, char *m) return pdFALSE; } +BaseType_t ff_cdr_enable_status(int argc, char **argv, char *m) +{ + int copied = 0; + + static int whichff = 0; + + if (whichff == 0) { + // check for stale data + if (isFFStale()) { + TickType_t now = pdTICKS_TO_S(xTaskGetTickCount()); + TickType_t last = pdTICKS_TO_S(getFFupdateTick(isFFStale())); + int mins = (now - last) / 60; + copied += snprintf(m + copied, SCRATCH_SIZE - copied, + "%s: stale data, last update %d minutes ago\r\n", argv[0], mins); + } + copied += snprintf(m + copied, SCRATCH_SIZE - copied, "FF CDR Enable:\r\n"); + } + + for (; whichff < NFIREFLIES; ++whichff) { + uint16_t val = get_FF_CDR_ENABLE_data(whichff); + copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%17s: 0x%04x", + ff_moni2c_addrs[whichff].name, val); + bool isTx = (strstr(ff_moni2c_addrs[whichff].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; + return pdTRUE; + } + } + + if (whichff % 2 == 1) { + m[copied++] = '\r'; + m[copied++] = '\n'; + m[copied] = '\0'; + } + whichff = 0; + + return pdFALSE; +} BaseType_t ff_temp(int argc, char **argv, char *m) { diff --git a/projects/cm_mcu/commands/SensorControl.h b/projects/cm_mcu/commands/SensorControl.h index 3a39f615..01f2abdf 100644 --- a/projects/cm_mcu/commands/SensorControl.h +++ b/projects/cm_mcu/commands/SensorControl.h @@ -58,6 +58,8 @@ BaseType_t ff_cdr_lol_alarm(int argc, char **argv, char *m); BaseType_t ff_mux_reset(int argc, char **argv, char *m); BaseType_t ff_dump_names(int argc, char **argv, char *m); BaseType_t ff_v3v3(int argc, char **argv, char *m); +BaseType_t ff_ch_disable_status(int argc, char **argv, char *m); +BaseType_t ff_cdr_enable_status(int argc, char **argv, char *m); // Clocks BaseType_t clkmon_ctl(int argc, char **argv, char *m); diff --git a/sm_cm_config/data/MON_I2C_rev2.yml b/sm_cm_config/data/MON_I2C_rev2.yml index c9937ed8..2bfdca82 100644 --- a/sm_cm_config/data/MON_I2C_rev2.yml +++ b/sm_cm_config/data/MON_I2C_rev2.yml @@ -10,7 +10,7 @@ define: &FF_SHARED_REGS reg_size: 1 # size of register address in bytes page: 0 # page of register reg_address: 0x2 # register address, if list: [ cernb, 14g, 25g4, 25g12] - size: 2 # size of data in register in bytes + size: 2 # size of data in register in bytes, max 2 bytes mask: 0xFF # mask for valid bits units: "" # units for display type: PM_STATUS # type of data @@ -159,7 +159,7 @@ define: &FF_SHARED_REGS units: uW type: PM_VOLTAGE devicetypes: [25G12] - - name: CHANNEL_DISABLE + - name: CHANNEL_DISABLE # this is both Tx and on 25G12, not on 25G4 reg_size: 1 page: 0 reg_address: [52, 52, 86, 52] @@ -168,6 +168,33 @@ define: &FF_SHARED_REGS units: "" type: PM_STATUS devicetypes: [CERNB, 14G, 25G4, 25G12] + - name: POWER_ALARM_0 + reg_size: 1 + page: 0 + reg_address: [-1, -1, 9, 14] + size: 2 + mask: 0xFFFF + units: "" + type: PM_STATUS + devicetypes: [ 25G4, 25G12] + - name: POWER_ALARM_1 + reg_size: 1 + page: 0 + reg_address: [-1, -1, -1, 16] + size: 2 + mask: 0xFF + units: "" + type: PM_STATUS + devicetypes: [ 25G12] + - name: CDR_ENABLE + reg_size: 1 + page: 0 + reg_address: [-1, -1, 98, 74] + size: 2 + mask: 0xFFF + units: "" + type: PM_STATUS + devicetypes: [25G4, 25G12] devices: - name: Fireflies_F1 From 338a8f11dc504732aeb776e68facc44561ee5438 Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Tue, 11 Jun 2024 14:11:34 -0400 Subject: [PATCH 67/71] clang-format --- common/power_ctl.c | 2 -- projects/cm_mcu/FireflyUtils.c | 2 +- projects/cm_mcu/commands/SensorControl.c | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/common/power_ctl.c b/common/power_ctl.c index 529b654d..eec474b4 100644 --- a/common/power_ctl.c +++ b/common/power_ctl.c @@ -5,12 +5,10 @@ * Author: wittich */ - #include "common/power_ctl.h" #include "common/pinsel.h" #include "common/utils.h" - #ifdef USE_FREERTOS #include "FreeRTOS.h" // IWYU pragma: keep #include "task.h" diff --git a/projects/cm_mcu/FireflyUtils.c b/projects/cm_mcu/FireflyUtils.c index 7564de34..541edce2 100644 --- a/projects/cm_mcu/FireflyUtils.c +++ b/projects/cm_mcu/FireflyUtils.c @@ -310,7 +310,7 @@ float getFFoptpow(const uint8_t i, const uint8_t ch) val = -999.f; break; } - return val * 10.f; // LSB is 0.1 uW, we return uW + return val * 10.f; // LSB is 0.1 uW, we return uW } #undef SWAP_BYTES diff --git a/projects/cm_mcu/commands/SensorControl.c b/projects/cm_mcu/commands/SensorControl.c index 81cbc834..4708378c 100644 --- a/projects/cm_mcu/commands/SensorControl.c +++ b/projects/cm_mcu/commands/SensorControl.c @@ -1465,7 +1465,7 @@ BaseType_t ff_dump_names(int argc, char **argv, char *m) { static int i = 0; int copied = 0; - if ( i == 0 ) { // not if we are on 2nd iteration + if (i == 0) { // not if we are on 2nd iteration copied += snprintf(m, SCRATCH_SIZE, "%s: ID registers\r\n", argv[0]); } for (; i < NFIREFLIES; ++i) { From 931193a609bedcf742400c641a5718dcfe7fd2e0 Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Tue, 11 Jun 2024 14:31:17 -0400 Subject: [PATCH 68/71] clean up constants usage --- projects/cm_mcu/FireflyUtils.c | 8 ++++---- projects/cm_mcu/FireflyUtils.h | 12 ++++++------ projects/cm_mcu/commands/SensorControl.c | 16 +++++++++------- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/projects/cm_mcu/FireflyUtils.c b/projects/cm_mcu/FireflyUtils.c index 541edce2..3c28b878 100644 --- a/projects/cm_mcu/FireflyUtils.c +++ b/projects/cm_mcu/FireflyUtils.c @@ -338,12 +338,12 @@ uint32_t ff_map_25gb_parts(void) char name[17]; memset(name, '\0', 17); - int startReg = VENDOR_START_BIT_FFDAQ; - int count = VENDOR_COUNT_FFDAQ; + int startReg = FF_VENDOR_START_BIT_FFDAQ; + int count = FF_VENDOR_COUNT_FFDAQ; int type = FireflyType(i); if (type == DEVICE_CERNB || type == DEVICE_25G12) { - startReg = VENDOR_START_BIT_FF12; - count = VENDOR_COUNT_FF12; + startReg = FF_VENDOR_START_BIT_FF12; + count = FF_VENDOR_COUNT_FF12; } int ret = 0; // build up name of the device (vendor string) diff --git a/projects/cm_mcu/FireflyUtils.h b/projects/cm_mcu/FireflyUtils.h index e21ac5e8..27ba32fa 100644 --- a/projects/cm_mcu/FireflyUtils.h +++ b/projects/cm_mcu/FireflyUtils.h @@ -34,12 +34,12 @@ // register address of the first and last entry of the // device identifier in the memory map of the FF devices -#define VENDOR_START_BIT_FFDAQ 168 -#define VENDOR_STOP_BIT_FFDAQ 184 -#define VENDOR_START_BIT_FF12 171 -#define VENDOR_STOP_BIT_FF12 187 -#define VENDOR_COUNT_FFDAQ (VENDOR_STOP_BIT_FFDAQ - VENDOR_START_BIT_FFDAQ) -#define VENDOR_COUNT_FF12 (VENDOR_STOP_BIT_FF12 - VENDOR_START_BIT_FF12) +#define FF_VENDOR_START_BIT_FFDAQ 168 +#define FF_VENDOR_STOP_BIT_FFDAQ 184 +#define FF_VENDOR_START_BIT_FF12 171 +#define FF_VENDOR_STOP_BIT_FF12 187 +#define FF_VENDOR_COUNT_FFDAQ (FF_VENDOR_STOP_BIT_FFDAQ - FF_VENDOR_START_BIT_FFDAQ) +#define FF_VENDOR_COUNT_FF12 (FF_VENDOR_STOP_BIT_FF12 - FF_VENDOR_START_BIT_FF12) struct arg_moni2c_ff_t { char *ff_part; // ff part diff --git a/projects/cm_mcu/commands/SensorControl.c b/projects/cm_mcu/commands/SensorControl.c index 4708378c..966529fb 100644 --- a/projects/cm_mcu/commands/SensorControl.c +++ b/projects/cm_mcu/commands/SensorControl.c @@ -7,6 +7,8 @@ #include #include +#include + #include "FireflyUtils.h" #include "I2CCommunication.h" #include "MonI2C_addresses.h" @@ -1463,6 +1465,8 @@ BaseType_t psmon_reg(int argc, char **argv, char *m) // this command takes no arguments BaseType_t ff_dump_names(int argc, char **argv, char *m) { + // ensure at compile-time that the vendor count is the same + static_assert(FF_VENDOR_COUNT_FF12 == FF_VENDOR_COUNT_FFDAQ, "Vendor count mismatch"); static int i = 0; int copied = 0; if (i == 0) { // not if we are on 2nd iteration @@ -1472,17 +1476,15 @@ BaseType_t ff_dump_names(int argc, char **argv, char *m) copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%17s: ", ff_moni2c_addrs[i].name); if (isEnabledFF(i)) { // process if enabled - char name[17]; - memset(name, '\0', 17); + char name[FF_VENDOR_COUNT_FF12 + 1]; + memset(name, '\0', FF_VENDOR_COUNT_FF12 + 1); int type = FireflyType(i); - int startReg = VENDOR_START_BIT_FFDAQ; - int count = VENDOR_COUNT_FFDAQ; + int startReg = FF_VENDOR_START_BIT_FFDAQ; if (type == DEVICE_CERNB || type == DEVICE_25G12) { - startReg = VENDOR_START_BIT_FF12; - count = VENDOR_COUNT_FF12; + startReg = FF_VENDOR_START_BIT_FF12; } int ret = 0; - for (unsigned char c = 0; c < count / 4; ++c) { // read name 4 chars at a time + for (unsigned char c = 0; c < FF_VENDOR_COUNT_FF12 / 4; ++c) { // read name 4 chars at a time uint8_t v[4]; ret += read_arbitrary_ff_register(startReg + 4 * c, i, v, 4); name[4 * c] = v[0]; From 21bf34125384d69acc06b737ad41cfdc156d4632 Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Tue, 11 Jun 2024 15:03:29 -0400 Subject: [PATCH 69/71] Update FireflyUtils.c --- projects/cm_mcu/FireflyUtils.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/projects/cm_mcu/FireflyUtils.c b/projects/cm_mcu/FireflyUtils.c index 3c28b878..cabfcccc 100644 --- a/projects/cm_mcu/FireflyUtils.c +++ b/projects/cm_mcu/FireflyUtils.c @@ -11,7 +11,7 @@ #include #include #include // memset -#include +#include #include "MonI2C_addresses.h" #include "MonUtils.h" @@ -329,6 +329,7 @@ uint16_t getFFpresentbit(const uint8_t i) // sets ff_bitmask_args[0].ffpart_bit_mask and ff_bitmask_args[2].ffpart_bit_mask uint32_t ff_map_25gb_parts(void) { + static_assert(FF_VENDOR_COUNT_FFDAQ == FF_VENDOR_COUNT_FF12, "FF_VENDOR_COUNT_FFDAQ != FF_VENDOR_COUNT_FF12"); uint32_t ff_25gb_parts = 0U; uint32_t ff_25gb_pairs = 0U; for (int i = 0; i < NFIREFLIES; ++i) { @@ -336,18 +337,16 @@ uint32_t ff_map_25gb_parts(void) continue; } - char name[17]; - memset(name, '\0', 17); + char name[FF_VENDOR_START_BIT_FFDAQ + 1]; + memset(name, '\0', FF_VENDOR_START_BIT_FFDAQ + 1); int startReg = FF_VENDOR_START_BIT_FFDAQ; - int count = FF_VENDOR_COUNT_FFDAQ; int type = FireflyType(i); if (type == DEVICE_CERNB || type == DEVICE_25G12) { startReg = FF_VENDOR_START_BIT_FF12; - count = FF_VENDOR_COUNT_FF12; } int ret = 0; // build up name of the device (vendor string) - for (int c = 0; c < count / 4; ++c) { + for (BaseType_t c = 0; c < FF_VENDOR_COUNT_FF12 / 4; ++c) { uint8_t v[4]; ret += read_arbitrary_ff_register(startReg + 4 * c, i, v, 4); name[4 * c] = v[0]; From 00319b7f7e536f00942ed95686a051e386703257 Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Wed, 12 Jun 2024 14:50:47 -0400 Subject: [PATCH 70/71] Update FireflyUtils.c --- projects/cm_mcu/FireflyUtils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/cm_mcu/FireflyUtils.c b/projects/cm_mcu/FireflyUtils.c index cabfcccc..8913886a 100644 --- a/projects/cm_mcu/FireflyUtils.c +++ b/projects/cm_mcu/FireflyUtils.c @@ -240,7 +240,6 @@ uint16_t getFFtemp(const uint8_t i) // returns optical power in uW // not that the 4 channel and 12 channel data is encoded differently // see the relevant data sheets and comments below -#define SWAP_BYTES(x) __builtin_bswap16(x) float getFFavgoptpow(const uint8_t i) { configASSERT(i < NFIREFLIES); @@ -261,6 +260,7 @@ float getFFavgoptpow(const uint8_t i) // but the 4 channel part does not say to do so. // However, trial and error shows that the 4 channel part // does need byte swapping. +#define SWAP_BYTES(x) __builtin_bswap16(x) float getFFoptpow(const uint8_t i, const uint8_t ch) { configASSERT(i < NFIREFLIES); From 3bca61c6e3e6f40514dd11f25c24c3df08c6b78d Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Wed, 12 Jun 2024 16:26:47 -0400 Subject: [PATCH 71/71] remove dead code --- projects/cm_mcu/LocalTasks.c | 9 --------- 1 file changed, 9 deletions(-) diff --git a/projects/cm_mcu/LocalTasks.c b/projects/cm_mcu/LocalTasks.c index 3457a9b9..c7c43d74 100644 --- a/projects/cm_mcu/LocalTasks.c +++ b/projects/cm_mcu/LocalTasks.c @@ -158,15 +158,6 @@ struct dev_moni2c_addr_t ffl4_f1_moni2c_addrs[NFIREFLIES_DAQ_F1] = { {"K05 4 XCVR GTY", FF_I2CMUX_2_ADDR, 1, 0x50}, // {"K06 4 XCVR GTY", FF_I2CMUX_2_ADDR, 2, 0x50}, // }; -// #elif defined(REV2) -// struct dev_moni2c_addr_t ffl4_f1_moni2c_addrs[NFIREFLIES_DAQ_F1] = { -// {"F1_4 4 XCVR", FF_I2CMUX_1_ADDR, 2, 0x50}, // -// {"F1_5 4 XCVR", FF_I2CMUX_2_ADDR, 0, 0x50}, // -// {"F1_6 4 XCVR", FF_I2CMUX_2_ADDR, 1, 0x50}, // -// {"F1_7 4 XCVR", FF_I2CMUX_2_ADDR, 2, 0x50}, // -// }; -// #else -// #error "Define either Rev1 or Rev2" #endif #ifdef REV1