From 8c2bd00fa5f9a38f880520a8c7486a2965153d4e Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Mon, 22 Jul 2019 11:32:30 -0400 Subject: [PATCH 1/6] start of a task to monitor firefly samtec devices --- common/smbus_units.c | 23 ++++ projects/project2/FireFlyTask.c | 227 ++++++++++++++++++++++++++++++++ 2 files changed, 250 insertions(+) create mode 100644 common/smbus_units.c create mode 100644 projects/project2/FireFlyTask.c diff --git a/common/smbus_units.c b/common/smbus_units.c new file mode 100644 index 00000000..60f69918 --- /dev/null +++ b/common/smbus_units.c @@ -0,0 +1,23 @@ +/* + * smbus_units.c + * + * Created on: Jul 17, 2019 + * Author: pw94 + */ +#include "common/smbus_units.h" + +float linear11_to_float(linear11_val_t t) +{ + return t.linear.base * pow(2, t.linear.mantissa); +} + +float linear16u_to_float(uint16_t t ) +{ + const float mantissa = -13; + return 1.0*t*pow(2,mantissa); +} + +uint16_t float_to_linear11(float t) +{ + return (uint16_t)(t * (1 << 5)); +} diff --git a/projects/project2/FireFlyTask.c b/projects/project2/FireFlyTask.c new file mode 100644 index 00000000..d5e09b0c --- /dev/null +++ b/projects/project2/FireFlyTask.c @@ -0,0 +1,227 @@ +/* + * FireFlyTask.c + * + * Created on: July 16, 2019 + * Author: wittich + */ + +// includes for types +#include +#include +#include + +// memory mappings +#include "inc/hw_types.h" +#include "inc/hw_memmap.h" + +// FreeRTOS +#include "FreeRTOS.h" +#include "FreeRTOSConfig.h" +#include "task.h" + +// local includes +#include "common/i2c_reg.h" +#include "common/smbus.h" +#include "common/smbus_units.h" +#include "MonitorTask.h" + + +#define NFIREFLIES 8 +#define NPAGES_FF 2 +#define NCOMMANDS_FF 2 + +// local prototype +void Print(const char* str); + +//#define DEBUG_FIF +#ifdef DEBUG_FIF +// prototype of mutex'd print +# define DPRINT(x) Print(x) +#else // DEBUG_FIF +# define DPRINT(x) +#endif // DEBUG_FIF + + + +// Beware: you need to update NCOMMANDS_FF if you change +// the number of entries in this array. +struct pm_list pm_command_ff[] = { + { 0x8d, 2, "READ_TEMPERATURE_1", "C", PM_LINEAR11 }, + { 0x8f, 2, "READ_TEMPERATURE_3", "C", PM_LINEAR11 }, + { 0x88, 2, "READ_VIN", "V", PM_LINEAR11 }, + { 0x8B, 2, "READ_VOUT", "V", PM_LINEAR16U }, + { 0x8c, 2, "READ_IOUT", "A", PM_LINEAR11 }, + //{ 0x4F, 2, "OT_FAULT_LIMIT", "C", PM_LINEAR11}, + { 0x79, 2, "STATUS_WORD", "", PM_STATUS }, + //{ 0xE7, 2, "IOUT_AVG_OC_FAULT_LIMIT", "A", PM_LINEAR11 }, + { 0x95, 2, "READ_FREQUENCY", "Hz", PM_LINEAR11}, +}; + +// I2C for VU7P optics +extern tSMBus g_sMaster3; +extern tSMBusStatus eStatus3 ; +// I2C for KU15P optics +extern tSMBus g_sMaster4; +extern tSMBusStatus eStatus4 ; + +// pointers to controller info for the I2C masters +static tSMBus *masters[2] = {g_sMaster3, g_sMaster4}; +static tSMBusStatus *status[2] = {eStatus3, eStatus4}; + +float pm_values[NFIREFLIES*NPAGES_FF*NCOMMANDS_FF]; +static float pm_values_max[NFIREFLIES*NPAGES_FF*NCOMMANDS_FF]; +static float pm_values_min[NFIREFLIES*NPAGES_FF*NCOMMANDS_FF]; + +static +void update_max() { + for (int i = 0; i < NFIREFLIES*NPAGES_FF*NCOMMANDS_FF; ++i ) { + if ( pm_values_max[i] < pm_values[i]) + pm_values_max[i] = pm_values[i]; + } +} +static +void update_min() { + for (int i = 0; i < NFIREFLIES*NPAGES_FF*NCOMMANDS_FF; ++i ) { + if ( pm_values_min[i] > pm_values[i]) + pm_values_min[i] = pm_values[i]; + } +} + +// FireFly temperatures, voltages, currents, via I2C/PMBUS +void FireFlyTask(void *parameters) +{ + // initialize to the current tick time + TickType_t xLastWakeTime = xTaskGetTickCount(); + uint8_t data[2]; + + for ( int i = 0; i < NFIREFLIES*NPAGES_FF*NCOMMANDS_FF; ++i ) { + pm_values_max[i] = -99; + pm_values_min[i] = +99; + } + + vTaskDelayUntil( &xLastWakeTime, pdMS_TO_TICKS( 2500 ) ); + + + const uint8_t addrs[NFIREFLIES] = { 0x40, 0x44, 0x43, 0x46, 0x45}; + //const uint8_t supply_prios[NSUPPLIES] = {2, 1, 1, 1, 1}; + tSMBus *smbus = masters[0]; + tSMBusStatus *p_status = status[0]; + + for (;;) { + // loop over power supplies attached to the MUX + for ( uint8_t ff = 0; ff < NFIREFLIES; ++ ff ) { + char tmp[64]; + // select the appropriate output for the mux + data[0] = 0x1U< Date: Mon, 22 Jul 2019 11:33:12 -0400 Subject: [PATCH 2/6] start of a task to monitor firefly samtec devices --- common/smbus_units.h | 16 +++------------- projects/project2/ADCMonitorTask.c | 8 +++----- projects/project2/CommandLineTask.c | 12 ++++++------ projects/project2/Makefile | 2 ++ projects/project2/MonitorTask.c | 22 +++++++++++----------- projects/project2/MonitorTask.h | 6 +++--- projects/project2/project2.c | 9 +++++++-- 7 files changed, 35 insertions(+), 40 deletions(-) diff --git a/common/smbus_units.h b/common/smbus_units.h index 7a794fac..420d6c41 100644 --- a/common/smbus_units.h +++ b/common/smbus_units.h @@ -24,20 +24,10 @@ typedef union uint16_t raw; } linear11_val_t; -float linear11_to_float(linear11_val_t t) -{ - return t.linear.base * pow(2, t.linear.mantissa); -} +float linear11_to_float(linear11_val_t t); -float linear16u_to_float(uint16_t t ) -{ - const float mantissa = -13; - return 1.0*t*pow(2,mantissa); -} +float linear16u_to_float(uint16_t t ); -uint16_t float_to_linear11(float t) -{ - return (uint16_t)(t * (1 << 5)); -} +uint16_t float_to_linear11(float t); #endif // _COMMON_SMBUS_UNITS_H diff --git a/projects/project2/ADCMonitorTask.c b/projects/project2/ADCMonitorTask.c index cd4360c6..f83c5a8c 100644 --- a/projects/project2/ADCMonitorTask.c +++ b/projects/project2/ADCMonitorTask.c @@ -51,10 +51,8 @@ struct ADC_Info_t { float scale; // scaling, if needed, for signals bigger than 2.5V }; -// These are not in order of channel number but instead grouped by -// which ADC they have been assigned to in the TI PinMux tool. I could -// probably consider reassigning them in the PinMUX tool to make it more -// logical. +// parameters for how data is organized in the fADC arrays and how the +// sequencers are organized #define ADCs_ADC1_START 0 #define ADCs_ADC1_FIRST_SEQ_LENGTH 8 #define ADCs_ADC1_SECOND_SEQ_LENGTH 5 @@ -236,7 +234,7 @@ void initADC0SecondSequence() } -// playground to test various things +// ADC monitoring task. void ADCMonitorTask(void *parameters) { // initialize to the current tick time diff --git a/projects/project2/CommandLineTask.c b/projects/project2/CommandLineTask.c index 581c63d4..cb34c053 100644 --- a/projects/project2/CommandLineTask.c +++ b/projects/project2/CommandLineTask.c @@ -181,7 +181,7 @@ static BaseType_t i2c_ctl_reg_r(char *m, size_t s, const char *mm) if ( nbytes > MAX_BYTES ) nbytes = MAX_BYTES; snprintf(m, s, "i2c_ctl_reg_r: Read %d bytes from I2C address 0x%x, reg 0x%x\n", nbytes, address, reg_address); - Print(m); + DPRINT(m); tSMBusStatus r = SMBusMasterI2CWriteRead(p_sMaster,address,&txdata,1,data,nbytes); if (r != SMBUS_OK) { @@ -426,18 +426,18 @@ static BaseType_t mon_ctl(char *m, size_t s, const char *mm) p1[p1l] = 0x00; // terminate strings BaseType_t i1 = strtol(p1, NULL, 10); - if ( i1 < 0 || i1 >= NCOMMANDS ) { + if ( i1 < 0 || i1 >= NCOMMANDS_PS ) { snprintf(m, s, "%s: Invalid argument, must be between 0 and %d\n", __func__, - NCOMMANDS-1); + NCOMMANDS_PS-1); return pdFALSE; } int copied = 0; copied += snprintf(m+copied, s-copied, "%s\n", pm_command_dcdc[i1].name); - for (int ps = 0; ps < NSUPPLIES; ++ps) { + for (int ps = 0; ps < NSUPPLIES_PS; ++ps) { copied += snprintf(m+copied, s-copied, "SUPPLY %d\n", ps); - for (int page = 0; page < NPAGES; ++page ) { - float val = pm_values[ps*(NCOMMANDS*NPAGES)+page*NCOMMANDS+i1]; + for (int page = 0; page < NPAGES_PS; ++page ) { + float val = pm_values[ps*(NCOMMANDS_PS*NPAGES_PS)+page*NCOMMANDS_PS+i1]; int tens = val; int frac = ABS((val - tens)*100.0); diff --git a/projects/project2/Makefile b/projects/project2/Makefile index c4ecc721..6de837fa 100644 --- a/projects/project2/Makefile +++ b/projects/project2/Makefile @@ -77,11 +77,13 @@ ${COMPILER}/project2.axf: ${COMPILER}/i2c_reg.o ${COMPILER}/project2.axf: ${COMPILER}/uart.o ${COMPILER}/project2.axf: ${COMPILER}/utils.o ${COMPILER}/project2.axf: ${COMPILER}/smbus.o +${COMPILER}/project2.axf: ${COMPILER}/smbus_units.o ${COMPILER}/project2.axf: ${COMPILER}/power_ctl.o ${COMPILER}/project2.axf: ${COMPILER}/CommandLineTask.o ${COMPILER}/project2.axf: ${COMPILER}/PowerSupplyTask.o ${COMPILER}/project2.axf: ${COMPILER}/ADCMonitorTask.o ${COMPILER}/project2.axf: ${COMPILER}/MonitorTask.o +${COMPILER}/project2.axf: ${COMPILER}/FireFlyTask.o ${COMPILER}/project2.axf: ${COMPILER}/LedTask.o ${COMPILER}/project2.axf: ${COMPILER}/startup_${COMPILER}.o ## FreeRTOS diff --git a/projects/project2/MonitorTask.c b/projects/project2/MonitorTask.c index 5f2fb5c7..3f5cdb06 100644 --- a/projects/project2/MonitorTask.c +++ b/projects/project2/MonitorTask.c @@ -60,20 +60,20 @@ volatile tSMBusStatus eStatus3 = SMBUS_OK; volatile tSMBusStatus eStatus4 = SMBUS_OK; // TODO: move these to the right place volatile tSMBusStatus eStatus6 = SMBUS_OK; -float pm_values[NSUPPLIES*NPAGES*NCOMMANDS]; -static float pm_values_max[NSUPPLIES*NPAGES*NCOMMANDS]; -static float pm_values_min[NSUPPLIES*NPAGES*NCOMMANDS]; +float pm_values[NSUPPLIES_PS*NPAGES_PS*NCOMMANDS_PS]; +static float pm_values_max[NSUPPLIES_PS*NPAGES_PS*NCOMMANDS_PS]; +static float pm_values_min[NSUPPLIES_PS*NPAGES_PS*NCOMMANDS_PS]; static void update_max() { - for (int i = 0; i < NSUPPLIES*NPAGES*NCOMMANDS; ++i ) { + for (int i = 0; i < NSUPPLIES_PS*NPAGES_PS*NCOMMANDS_PS; ++i ) { if ( pm_values_max[i] < pm_values[i]) pm_values_max[i] = pm_values[i]; } } static void update_min() { - for (int i = 0; i < NSUPPLIES*NPAGES*NCOMMANDS; ++i ) { + for (int i = 0; i < NSUPPLIES_PS*NPAGES_PS*NCOMMANDS_PS; ++i ) { if ( pm_values_min[i] > pm_values[i]) pm_values_min[i] = pm_values[i]; } @@ -86,7 +86,7 @@ void MonitorTask(void *parameters) TickType_t xLastWakeTime = xTaskGetTickCount(); uint8_t data[2]; - for ( int i = 0; i < NSUPPLIES*NPAGES*NCOMMANDS; ++i ) { + for ( int i = 0; i < NSUPPLIES_PS*NPAGES_PS*NCOMMANDS_PS; ++i ) { pm_values_max[i] = -99; pm_values_min[i] = +99; } @@ -104,7 +104,7 @@ void MonitorTask(void *parameters) // 0x43 | KVCCINT | 1 // 0x46 | VVCCINT | 1 // 0x45 | VVCCINT | 1 - const uint8_t addrs[NSUPPLIES] = { 0x40, 0x44, 0x43, 0x46, 0x45}; + const uint8_t addrs[NSUPPLIES_PS] = { 0x40, 0x44, 0x43, 0x46, 0x45}; //const uint8_t supply_prios[NSUPPLIES] = {2, 1, 1, 1, 1}; for (;;) { @@ -122,7 +122,7 @@ void MonitorTask(void *parameters) // good = true; // } // loop over power supplies attached to the MUX - for ( uint8_t ps = 0; ps < NSUPPLIES; ++ ps ) { + for ( uint8_t ps = 0; ps < NSUPPLIES_PS; ++ ps ) { char tmp[64]; // select the appropriate output for the mux data[0] = 0x1U< Date: Mon, 12 Aug 2019 10:40:37 -0500 Subject: [PATCH 3/6] firefly monitor temperature task, not yet hooked in to main() --- projects/project2/FireFlyTask.c | 220 ++++++++++++++++---------------- 1 file changed, 113 insertions(+), 107 deletions(-) diff --git a/projects/project2/FireFlyTask.c b/projects/project2/FireFlyTask.c index d5e09b0c..b2fb1dce 100644 --- a/projects/project2/FireFlyTask.c +++ b/projects/project2/FireFlyTask.c @@ -26,9 +26,11 @@ #include "MonitorTask.h" -#define NFIREFLIES 8 -#define NPAGES_FF 2 -#define NCOMMANDS_FF 2 +#define NFIREFLIES_KU15P 11 +#define NFIREFLIES_VU7P 14 +#define NFIREFLIES (NFIREFLIES_KU15P+NFIREFLIES_VU7P) +#define NPAGES_FF 1 +#define NCOMMANDS_FF 1 // local prototype void Print(const char* str); @@ -41,22 +43,43 @@ void Print(const char* str); # define DPRINT(x) #endif // DEBUG_FIF +struct ff_i2c_addr_t { + char *name; + uint8_t mux_addr; // I2C address of the Mux + uint8_t mux_bit; // port of the mux; write value 0x1U< pm_values[i]) - pm_values_min[i] = pm_values[i]; + for (uint8_t i = 0; i < NFIREFLIES*NPAGES_FF*NCOMMANDS_FF; ++i ) { + if ( ff_temp_min[i] > ff_temp[i]) + ff_temp_min[i] = ff_temp[i]; } } +// read-only accessor functions for Firefly names and values. + +const char* getFFname(const uint8_t i) +{ + configASSERT(i>=0&&i=0&&i Date: Tue, 13 Aug 2019 10:09:38 -0500 Subject: [PATCH 4/6] add CLI for FF temperatures --- projects/project2/CommandLineTask.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/projects/project2/CommandLineTask.c b/projects/project2/CommandLineTask.c index cb34c053..2ba27225 100644 --- a/projects/project2/CommandLineTask.c +++ b/projects/project2/CommandLineTask.c @@ -469,6 +469,22 @@ static BaseType_t adc_ctl(char *m, size_t s, const char *mm) return pdFALSE; } +const char* getFFname(const uint8_t i); +int8_t getFFvalue(const uint8_t i); + + +// this command takes no arguments +static BaseType_t ff_ctl(char *m, size_t s, const char *mm) +{ + int copied = 0; + copied += snprintf(m+copied, s-copied, "FF temperatures\n"); + for ( int i = 0; i < 25; ++i ) { + uint8_t val = getFFvalue(i); + copied += snprintf(m+copied, s-copied, "%14s: %02d\n", getFFname(i), val); + + } + return pdFALSE; +} static @@ -697,6 +713,13 @@ CLI_Command_Definition_t task_command = { 2 }; +static +CLI_Command_Definition_t ff_command = { + .pcCommand="ff", + .pcHelpString="ff\n Displays a table showing the state of FF modules.\r\n", + .pxCommandInterpreter = ff_ctl, + 0 +}; extern StreamBufferHandle_t xUARTStreamBuffer; @@ -711,6 +734,7 @@ void vCommandLineTask( void *pvParameters ) // register the commands FreeRTOS_CLIRegisterCommand(&task_stats_command ); + FreeRTOS_CLIRegisterCommand(&task_command ); FreeRTOS_CLIRegisterCommand(&i2c_read_command ); FreeRTOS_CLIRegisterCommand(&i2c_set_dev_command ); FreeRTOS_CLIRegisterCommand(&i2c_read_reg_command ); @@ -720,8 +744,8 @@ void vCommandLineTask( void *pvParameters ) FreeRTOS_CLIRegisterCommand(&pwr_ctl_command ); FreeRTOS_CLIRegisterCommand(&led_ctl_command ); FreeRTOS_CLIRegisterCommand(&monitor_command ); - FreeRTOS_CLIRegisterCommand(&adc_command ); - FreeRTOS_CLIRegisterCommand(&task_command ); + FreeRTOS_CLIRegisterCommand(&adc_command ); + FreeRTOS_CLIRegisterCommand(&ff_command ); From 2ed5b747eb0ffaaed0e89cb0e50f3836b48d2946 Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Fri, 16 Aug 2019 11:35:38 -0400 Subject: [PATCH 5/6] Update MonitorTask.c silence gcc warning --- projects/project2/MonitorTask.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/project2/MonitorTask.c b/projects/project2/MonitorTask.c index 767c7ba7..7323e327 100644 --- a/projects/project2/MonitorTask.c +++ b/projects/project2/MonitorTask.c @@ -186,7 +186,7 @@ void MonitorTask(void *parameters) r = SMBusMasterByteWordRead(&g_sMaster1, addrs[ps], pm_command_dcdc[c].command, data, pm_command_dcdc[c].size); if ( r != SMBUS_OK ) { - snprintf(tmp, 64, "MON: SMBUS COMMAND failed (master or busy busy, (ps=%d,c=%d,p=%d)\n", ps,c,page); + snprintf(tmp, 64, "MON: SMBUS failed (master/bus busy, (ps=%d,c=%d,p=%d)\n", ps,c,page); Print(tmp); continue; // abort reading this register } From 80a6b4c740df878dfccdd03fd48f5160ca735818 Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Fri, 16 Aug 2019 21:53:05 -0400 Subject: [PATCH 6/6] debugged FF task with CLI --- projects/project2/CommandLineTask.c | 41 ++++++++++++++++++++++------- projects/project2/FireFlyTask.c | 8 +++--- 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/projects/project2/CommandLineTask.c b/projects/project2/CommandLineTask.c index 2ba27225..870ab1c6 100644 --- a/projects/project2/CommandLineTask.c +++ b/projects/project2/CommandLineTask.c @@ -458,14 +458,21 @@ float getADCvalue(const int i); static BaseType_t adc_ctl(char *m, size_t s, const char *mm) { int copied = 0; - copied += snprintf(m+copied, s-copied, "ADC outputs\n"); - for ( int i = 0; i < 21; ++i ) { - float val = getADCvalue(i); + static int whichadc = 0; + if ( whichadc == 0 ) { + copied += snprintf(m+copied, s-copied, "ADC outputs\n"); + } + for ( ; whichadc < 21; ++whichadc ) { + float val = getADCvalue(whichadc); int tens = val; int frac = ABS((val-tens)*100.); - copied += snprintf(m+copied, s-copied, "%14s: %02d.%02d\n", getADCname(i), tens, frac); - + copied += snprintf(m+copied, s-copied, "%14s: %02d.%02d\n", getADCname(whichadc), tens, frac); + if ( (s-copied) < 20 ) { + ++whichadc; + return pdTRUE; + } } + whichadc = 0; return pdFALSE; } @@ -477,12 +484,28 @@ int8_t getFFvalue(const uint8_t i); static BaseType_t ff_ctl(char *m, size_t s, const char *mm) { int copied = 0; - copied += snprintf(m+copied, s-copied, "FF temperatures\n"); - for ( int i = 0; i < 25; ++i ) { - uint8_t val = getFFvalue(i); - copied += snprintf(m+copied, s-copied, "%14s: %02d\n", getFFname(i), val); + static int whichff = 0; + if ( whichff == 0 ) { + copied += snprintf(m+copied, s-copied, "FF temperatures\n"); + } + for ( ; whichff < 25; ++whichff ) { + int8_t val = getFFvalue(whichff); + copied += snprintf(m+copied, s-copied, "%17s: %3d", getFFname(whichff), val); + if ( whichff%2 == 1 ) + copied += snprintf(m+copied, s-copied, "\n"); + else + copied += snprintf(m+copied, s-copied, "\t"); + if ( (s-copied ) < 20 ) { + ++whichff; + return pdTRUE; + } } + if ( whichff%2 ==1 ) { + m[copied++] = '\n'; + m[copied] = '\0'; + } + whichff = 0; return pdFALSE; } diff --git a/projects/project2/FireFlyTask.c b/projects/project2/FireFlyTask.c index b2fb1dce..fde70737 100644 --- a/projects/project2/FireFlyTask.c +++ b/projects/project2/FireFlyTask.c @@ -132,6 +132,7 @@ void FireFlyTask(void *parameters) for ( uint8_t i = 0; i < NFIREFLIES*NPAGES_FF*NCOMMANDS_FF; ++i ) { ff_temp_max[i] = -99; ff_temp_min[i] = +99; + ff_temp [i] = -55; } vTaskDelayUntil( &xLastWakeTime, pdMS_TO_TICKS( 2500 ) ); @@ -195,11 +196,12 @@ void FireFlyTask(void *parameters) for (int c = 0; c < NCOMMANDS_FF; ++c ) { data[0] = 0x0U; data[1] = 0x0U; - r = SMBusMasterI2CRead(smbus, ff_i2c_addrs[ff].dev_addr, data, 1); + uint8_t reg_addr = FF_TEMP_COMMAND_REG; + r = SMBusMasterI2CWriteRead(smbus, ff_i2c_addrs[ff].dev_addr, ®_addr, 1, data, 1); if ( r != SMBUS_OK ) { snprintf(tmp, 64, "FIF: %s: SMBUS failed (master/bus busy, ps=%d,c=%d)\n", __func__, ff,c); - Print(tmp); + DPRINT(tmp); continue; // abort reading this register } while ( SMBusStatusGet(smbus) == SMBUS_TRANSFER_IN_PROGRESS) { @@ -207,7 +209,7 @@ void FireFlyTask(void *parameters) } if ( *p_status != SMBUS_OK ) { snprintf(tmp, 64, "FIF: %s: Error %d, break out of loop (ps=%d,c=%d) ...\n", __func__, *p_status, ff,c); - Print(tmp); + DPRINT(tmp); break; } #ifdef DEBUG_FIF