Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup and bugfixes #14

Merged
merged 2 commits into from
Sep 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions common/power_ctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ bool set_ps()
} // loop over 'ok' bits
if ( ! all_good ) {
// o tells you which one died.
Print("set_ps: Power supply check failed: ");
Print(pin_names[oks[o].name]);
Print(". Turning off all supplies at this level or lower.\n");
Print("set_ps: Power supply check failed. ");
// Print(pin_names[oks[o].name]);
Print(". Turning off all supplies at this level or lower.\r\n");
// turn off all supplies at current priority level or lower
// that is probably overkill since they should not all be
lowest_enabled_ps_prio = oks[o].priority - 1;
Expand Down Expand Up @@ -216,7 +216,7 @@ check_ps(void)
for ( int o = 0; o < N_PS_OKS; ++o ) {
if ( new_states[o] != states[o] && states[o] != PWR_UNKNOWN) {
static char tmp[128];
snprintf(tmp, 128, "check_ps: New failed supply %s (level %d)\n", pin_names[oks[o].name],
snprintf(tmp, 128, "check_ps: New failed supply %s (level %d)\r\n", pin_names[oks[o].name],
oks[o].priority);
Print(tmp);
}
Expand Down
2 changes: 1 addition & 1 deletion projects/project2/AlarmTask.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ uint32_t getAlarmStatus()
return status;
}

#define INITIAL_ALARM_TEMP 55.0 // in Celsius duh
#define INITIAL_ALARM_TEMP 65.0 // in Celsius duh
static float alarm_temp = INITIAL_ALARM_TEMP;

float getAlarmTemperature()
Expand Down
61 changes: 43 additions & 18 deletions projects/project2/CommandLineTask.c
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,15 @@ static BaseType_t adc_ctl(char *m, size_t s, const char *mm)
return pdFALSE;
}

// this command takes no arguments
static BaseType_t ver_ctl(char *m, size_t s, const char *mm)
{
int copied = 0;
copied += snprintf(m+copied, s-copied, "Version %s built at %s.\r\n",
gitVersion(), buildTime()) ;
return pdFALSE;
}


// this command takes no arguments
static BaseType_t ff_ctl(char *m, size_t s, const char *mm)
Expand All @@ -548,11 +557,16 @@ static BaseType_t ff_ctl(char *m, size_t s, const char *mm)
}
for ( ; whichff < NFIREFLIES; ++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, "\r\n");
else
const char *name = getFFname(whichff);
if ( val > 0 )
copied += snprintf(m+copied, s-copied, "%17s: %2d", name, val);
else // dummy value
copied += snprintf(m+copied, s-copied, "%17s: %2s", name, "--");
bool isTx = (strstr(name, "Tx") != NULL);
if ( isTx )
copied += snprintf(m+copied, s-copied, "\t");
else
copied += snprintf(m+copied, s-copied, "\r\n");
if ( (s-copied ) < 20 ) {
++whichff;
return pdTRUE;
Expand Down Expand Up @@ -912,6 +926,14 @@ CLI_Command_Definition_t sensor_summary_command = {
0
};

static
CLI_Command_Definition_t version_command = {
.pcCommand="version",
.pcHelpString="version\r\n Displays information about MCU firmware\r\n",
.pxCommandInterpreter = ver_ctl,
0
};



void vCommandLineTask( void *pvParameters )
Expand All @@ -928,22 +950,23 @@ void vCommandLineTask( void *pvParameters )
uint32_t uart_base = args->uart_base;

// register the commands
FreeRTOS_CLIRegisterCommand(&task_stats_command );
FreeRTOS_CLIRegisterCommand(&task_command );
FreeRTOS_CLIRegisterCommand(&adc_command );
FreeRTOS_CLIRegisterCommand(&alm_ctl_command );
FreeRTOS_CLIRegisterCommand(&ff_command );
FreeRTOS_CLIRegisterCommand(&fpga_command );
FreeRTOS_CLIRegisterCommand(&i2c_read_command );
FreeRTOS_CLIRegisterCommand(&i2c_set_dev_command );
FreeRTOS_CLIRegisterCommand(&i2c_read_reg_command );
FreeRTOS_CLIRegisterCommand(&i2c_set_dev_command );
FreeRTOS_CLIRegisterCommand(&i2c_write_command);
FreeRTOS_CLIRegisterCommand(&i2c_write_reg_command);
FreeRTOS_CLIRegisterCommand(&i2c_scan_command );
FreeRTOS_CLIRegisterCommand(&pwr_ctl_command );
FreeRTOS_CLIRegisterCommand(&led_ctl_command );
FreeRTOS_CLIRegisterCommand(&monitor_command );
FreeRTOS_CLIRegisterCommand(&adc_command );
FreeRTOS_CLIRegisterCommand(&ff_command );
FreeRTOS_CLIRegisterCommand(&fpga_command );
FreeRTOS_CLIRegisterCommand(&pwr_ctl_command );
FreeRTOS_CLIRegisterCommand(&sensor_summary_command);
FreeRTOS_CLIRegisterCommand(&alm_ctl_command );
FreeRTOS_CLIRegisterCommand(&task_stats_command );
FreeRTOS_CLIRegisterCommand(&task_command );
FreeRTOS_CLIRegisterCommand(&version_command );


/* Send a welcome message to the user knows they are connected. */
Expand All @@ -955,8 +978,14 @@ void vCommandLineTask( void *pvParameters )
Blocked state until a character is received. */
xStreamBufferReceive(uartStreamBuffer, &cRxedChar, 1, portMAX_DELAY);
UARTCharPut(uart_base, cRxedChar); // TODO this should use the Mutex

// ugh there has to be a better way of handling this
if ( cRxedChar == '\177') {
UARTCharPut(uart_base, '\b');
UARTCharPut(uart_base, ' ');
UARTCharPut(uart_base, '\b'); // I hate you screen
}
if( cRxedChar == '\n' || cRxedChar == '\r' ) {
UARTCharPut(uart_base, '\n');
if ( cInputIndex != 0 ) { // empty command -- skip

snprintf(pcOutputString, MAX_OUTPUT_LENGTH, "Calling command >%s<\r\n",
Expand Down Expand Up @@ -996,11 +1025,7 @@ void vCommandLineTask( void *pvParameters )
/* The if() clause performs the processing after a newline character
is received. This else clause performs the processing if any other
character is received. */

if( cRxedChar == '\r' ) {
/* Ignore carriage returns. */
}
else if( cRxedChar == '\b' ) {
if( cRxedChar == '\b' || cRxedChar == '\177' ) {
/* Backspace was pressed. Erase the last character in the input
buffer - if there are any. */
if( cInputIndex > 0 ) {
Expand Down
77 changes: 51 additions & 26 deletions projects/project2/FireFlyTask.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,24 @@ void Print(const char* str);
# define DPRINT(x)
#endif // DEBUG_FIF

// i2c addresses
// ECUO-B04 XCVR: 0x50 7 bit I2C address
// ECUO-T12 Tx: 0x50 7 bit I2C address
// ECUO-R12 Rx: 0x54 7 bit I2C address


struct dev_i2c_addr_t ff_i2c_addrs[NFIREFLIES] = {
{"K01 12 Tx GTH", 0x70, 0, 0x54},
{"K01 12 Rx GTH", 0x70, 1, 0x50},
{"K02 12 Tx GTH", 0x70, 2, 0x54},
{"K02 12 Rx GTH", 0x70, 3, 0x50},
{"K03 12 Tx GTH", 0x70, 4, 0x54},
{"K03 12 Rx GTH", 0x70, 5, 0x50},
{"K01 12 Tx GTH", 0x70, 0, 0x50},
{"K01 12 Rx GTH", 0x70, 1, 0x54},
{"K02 12 Tx GTH", 0x70, 2, 0x50},
{"K02 12 Rx GTH", 0x70, 3, 0x54},
{"K03 12 Tx GTH", 0x70, 4, 0x50},
{"K03 12 Rx GTH", 0x70, 5, 0x54},
{"K04 4 XCVR GTY", 0x71, 0, 0x50},
{"K05 4 XCVR GTY", 0x71, 1, 0x50},
{"K06 4 XCVR GTY", 0x71, 2, 0x50},
{"K07 12 Tx GTY", 0x71, 3, 0x54},
{"K07 12 Rx GTY", 0x71, 4, 0x50},
{"K07 12 Tx GTY", 0x71, 3, 0x50},
{"K07 12 Rx GTY", 0x71, 4, 0x54},
{"V01 4 XCVR GTY", 0x70, 0, 0x50},
{"V02 4 XCVR GTY", 0x70, 1, 0x50},
{"V03 4 XCVR GTY", 0x70, 2, 0x50},
Expand All @@ -68,14 +72,15 @@ struct dev_i2c_addr_t ff_i2c_addrs[NFIREFLIES] = {
{"V08 4 XCVR GTY", 0x71, 1, 0x50},
{"V09 4 XCVR GTY", 0x71, 2, 0x50},
{"V10 4 XCVR GTY", 0x71, 3, 0x50},
{"V11 12 Tx GTY", 0x70, 6, 0x54},
{"V11 12 Rx GTY", 0x70, 7, 0x50},
{"V12 12 Tx GTY", 0x71, 4, 0x54},
{"V12 12 Rx GTY", 0x71, 5, 0x50},
{"V11 12 Tx GTY", 0x70, 6, 0x50},
{"V11 12 Rx GTY", 0x70, 7, 0x54},
{"V12 12 Tx GTY", 0x71, 4, 0x50},
{"V12 12 Rx GTY", 0x71, 5, 0x54},
};

#define FF_TEMP_COMMAND_REG 0x16 // 8 bit 2's complement int, valid from 0-80 C, LSB is 1 deg C

// 8 bit 2's complement signed int, valid from 0-80 C, LSB is 1 deg C
// Same address for 4 XCVR and 12 Tx/Rx devices
#define FF_TEMP_COMMAND_REG 0x16
// I2C for VU7P optics
extern tSMBus g_sMaster3;
extern tSMBusStatus eStatus3 ;
Expand Down Expand Up @@ -150,7 +155,7 @@ void FireFlyTask(void *parameters)
}
if ( getPSStatus(5) != PWR_ON) {
if ( good ) {
Print("FIF: 3V3 died. Skipping I2C monitoring.\n");
Print("FIF: 3V3 died. Skipping I2C monitoring.\r\n");
good = false;
}
vTaskDelayUntil(&xLastWakeTime, pdMS_TO_TICKS(500));
Expand All @@ -163,18 +168,18 @@ void FireFlyTask(void *parameters)
char tmp[64];
// select the appropriate output for the mux
data[0] = 0x1U << ff_i2c_addrs[ff].mux_bit;
snprintf(tmp, 64, "FIF: Output of mux set to 0x%02x\n", data[0]);
snprintf(tmp, 64, "FIF: Output of mux set to 0x%02x\r\n", data[0]);
DPRINT(tmp);
tSMBusStatus r = SMBusMasterI2CWrite(smbus, ff_i2c_addrs[ff].mux_addr, data, 1);
if ( r != SMBUS_OK ) {
Print("FIF: I2CBus command failed (setting mux)\n");
Print("FIF: I2CBus command failed (setting mux)\r\n");
continue;
}
while ( SMBusStatusGet(smbus) == SMBUS_TRANSFER_IN_PROGRESS) {
vTaskDelayUntil( &xLastWakeTime, pdMS_TO_TICKS( 10 )); // wait
}
if ( *p_status != SMBUS_OK ) {
snprintf(tmp, 64, "FIF: Mux writing error %d, break out of loop (ps=%d) ...\n", *p_status, ff);
snprintf(tmp, 64, "FIF: Mux writing error %d, break out of loop (ps=%d) ...\r\n", *p_status, ff);
Print(tmp);
break;
}
Expand All @@ -183,18 +188,18 @@ void FireFlyTask(void *parameters)
data[0] = 0xAAU;
r = SMBusMasterI2CRead(smbus, ff_i2c_addrs[index].mux_addr, data, 1);
if ( r != SMBUS_OK ) {
Print("FIF: Read of MUX output failed\n");
Print("FIF: Read of MUX output failed\r\n");
}
while ( SMBusStatusGet(smbus) == SMBUS_TRANSFER_IN_PROGRESS) {
vTaskDelayUntil( &xLastWakeTime, pdMS_TO_TICKS( 10 )); // wait
}
if ( *p_status != SMBUS_OK ) {
snprintf(tmp, 64, "FIF: Mux read error %d, break out of loop (ps=%d) ...\n", *p_status, index);
snprintf(tmp, 64, "FIF: Mux read error %d, break out of loop (ps=%d) ...\r\n", *p_status, index);
Print(tmp);
break;
}
else {
snprintf(tmp, 64, "FIF: read back register on mux to be %02x\n", data[0]);
snprintf(tmp, 64, "FIF: read back register on mux to be %02x\r\n", data[0]);
DPRINT(tmp);
}
#endif // DEBUG_FIF
Expand All @@ -207,33 +212,53 @@ void FireFlyTask(void *parameters)
r = SMBusMasterI2CWriteRead(smbus, ff_i2c_addrs[ff].dev_addr, &reg_addr, 1, data, 1);

if ( r != SMBUS_OK ) {
snprintf(tmp, 64, "FIF: %s: SMBUS failed (master/bus busy, ps=%d,c=%d)\n", __func__, ff,c);
snprintf(tmp, 64, "FIF: %s: SMBUS failed (master/bus busy, ps=%d,c=%d)\r\n", __func__, ff,c);
DPRINT(tmp);
continue; // abort reading this register
}
while ( SMBusStatusGet(smbus) == SMBUS_TRANSFER_IN_PROGRESS) {
vTaskDelayUntil( &xLastWakeTime, pdMS_TO_TICKS( 10 )); // wait
}
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);
snprintf(tmp, 64, "FIF: %s: Error %d, break out of loop (ps=%d,c=%d) ...\r\n", __func__, *p_status, ff,c);
DPRINT(tmp);
break;
}
#ifdef DEBUG_FIF
snprintf(tmp, 64, "FIF: %d %s is 0x%02x\n", index, ff_i2c_addrs[index].name, data[0]);
snprintf(tmp, 64, "FIF: %d %s is 0x%02x\r\n", index, ff_i2c_addrs[index].name, data[0]);
DPRINT(tmp);
#endif // DEBUG_FIF
typedef union {
uint8_t us;
int8_t s;
} convert_8_t;
convert_8_t tmp; tmp.us = data[0]; // change from uint_8 to int8_t, preserving bit pattern
ff_temp[ff] = tmp.s;
convert_8_t tmp1; tmp1.us = data[0]; // change from uint_8 to int8_t, preserving bit pattern
ff_temp[ff] = tmp1.s;



// wait here for the x msec, where x is 2nd argument below.
vTaskDelayUntil( &xLastWakeTime, pdMS_TO_TICKS( 10 ) );
} // loop over commands

// clear the I2C mux
data[0] = 0x0;
snprintf(tmp, 64, "FIF: Output of mux set to 0x%02x (clear)\r\n", data[0]);
DPRINT(tmp);
r = SMBusMasterI2CWrite(smbus, ff_i2c_addrs[ff].mux_addr, data, 1);
if ( r != SMBUS_OK ) {
Print("FIF: I2CBus command failed (clearing mux)\r\n");
continue;
}
while ( SMBusStatusGet(smbus) == SMBUS_TRANSFER_IN_PROGRESS) {
vTaskDelayUntil( &xLastWakeTime, pdMS_TO_TICKS( 10 )); // wait
}
if ( *p_status != SMBUS_OK ) {
snprintf(tmp, 64, "FIF: Mux clearing error %d, break out of loop (ps=%d) ...\r\n", *p_status, ff);
Print(tmp);
break;
}

} // loop over firefly modules
update_max(); update_min();
vTaskDelayUntil( &xLastWakeTime, pdMS_TO_TICKS( 250 ) );
Expand Down
Loading