Skip to content

Commit

Permalink
Housekeeping (#230)
Browse files Browse the repository at this point in the history
* add power_down to reset_mcu, bootloader calls.
* update to newer (higher) last stand temp thresholds
* add i2c mux clearing for init tasks
* workaround bug in xml_generate
* add board id info printout to InitTask
* fix bug in ff xmit off on F2 FF
* make alarm queue per task
  • Loading branch information
pwittich authored Jul 16, 2024
1 parent cbf154a commit 9210313
Show file tree
Hide file tree
Showing 22 changed files with 282 additions and 168 deletions.
10 changes: 6 additions & 4 deletions common/power_ctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,13 @@ bool disable_ps(void)
for (int o = 0; o < N_PS_OKS; ++o)
if (states[o] != PWR_DISABLED)
states[o] = PWR_OFF;
// this long delay (probably too long) allows all I2C tasks
// to finish their activity. For Rev2 of the CM (when the I2C
// pullups are from management power) this delay can be reduced or
// removed.
// this long delay (probably too long) allows all I2C tasks
// to finish their activity. For Rev2 of the CM (when the I2C
// pullups are from management power) this delay can be reduced or
// removed.
#ifdef REV1
vTaskDelay(pdMS_TO_TICKS(500));
#endif // REV1

// disable in reverse order
for (int prio = PS_NUM_PRIORITIES; prio > 0; --prio) {
Expand Down
56 changes: 35 additions & 21 deletions common/power_ctl.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,45 @@
#include <stdint.h>
#include <stdbool.h>

// these are all LED messages
#define PS_GOOD (1)
#define PS_BAD (2)
#define PS_ON (3)
#define PS_OFF (4)
#define PS_ERROR (5) // error generated by pwr_ctl
#define PS_STATUS (6)
// alarms
#define TEMP_ALARM (7)
#define TEMP_ALARM_CLEAR (8)
#define CURRENT_ALARM (9)
#define CURRENT_ALARM_CLEAR (10)
#define PS_ANYFAIL_ALARM (11)
#define PS_ANYFAIL_ALARM_CLEAR (12)
// X-macros for Alarm messages
#define X_MACRO_QUEUE_MESSAGES \
X(TEMP_ALARM, "Temperature Alarm") \
X(TEMP_ALARM_CLEAR, "Temperature Alarm Clear") \
X(CURRENT_ALARM, "Current Alarm") \
X(CURRENT_ALARM_CLEAR, "Current Alarm Clear") \
X(PS_ANYFAIL_ALARM, "Power Supply Any Fail Alarm") \
X(PS_ANYFAIL_ALARM_CLEAR, "Power Supply Any Fail Alarm Clear") \
X(PS_GOOD, "Power Supply Good") \
X(PS_BAD, "Power Supply Bad") \
X(PS_ON, "Power Supply On") \
X(PS_OFF, "Power Supply Off") \
X(PS_ERROR, "Power Supply Error") \
X(PS_STATUS, "Power Supply Status") \
X(HUH, "Undefined Message")

// alarms
// Generate enum and text arrays using X-macros
enum MsgQueue_Message {
#define X(name, text) name,
X_MACRO_QUEUE_MESSAGES
#undef X
};

#define HUH (99)
extern const char *msgqueue_message_text[];

#define X_MACRO_PS_STATES \
X(PWR_UNKNOWN) \
X(PWR_ON) \
X(PWR_OFF) \
X(PWR_DISABLED) \
X(PWR_FAILED)

// power supply state
enum ps_state { PWR_UNKNOWN,
PWR_ON,
PWR_OFF,
PWR_DISABLED,
PWR_FAILED };
enum ps_state {
#define X(name) name,
X_MACRO_PS_STATES
#undef X
};

enum ps_state getPSStatus(int i);
void setPSStatus(int i, enum ps_state theState);

Expand Down
49 changes: 29 additions & 20 deletions projects/cm_mcu/AlarmUtilities.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

extern struct MonitorTaskArgs_t fpga_args;

#define INITIAL_ALARM_TEMP_FF 45.0f // in Celsius duh
#define INITIAL_ALARM_TEMP_FF 50.0f // in Celsius duh
#define INITIAL_ALARM_TEMP_DCDC 70.0f
#define INITIAL_ALARM_TEMP_TM4C 70.0f
#define INITIAL_ALARM_TEMP_FPGA 70.0f
#define INITIAL_ALARM_TEMP_FPGA 81.0f
#define ALM_OVERTEMP_THRESHOLD 5.0f
// if the temperature is above the threshold by OVERTEMP_THRESHOLD
// a shutdown message is sent
Expand Down Expand Up @@ -65,21 +65,6 @@ int TempStatus(void)
++retval;
}

// FPGA
if (fpga_args.n_devices == 2) {
currentTemp[FPGA] = MAX(fpga_args.pm_values[0], fpga_args.pm_values[1]);
}
else {
currentTemp[FPGA] = fpga_args.pm_values[0];
}
excess_temp = currentTemp[FPGA] - getAlarmTemperature(FPGA);
if (excess_temp > 0.f) {
status_T |= ALM_STAT_FPGA_OVERTEMP;
retval++;
if (excess_temp > ALM_OVERTEMP_THRESHOLD)
++retval;
}

// DCDC. The first command is READ_TEMPERATURE_1.
// I am assuming it stays that way!!!!!!!!
currentTemp[DCDC] = -99.0f;
Expand All @@ -99,9 +84,30 @@ int TempStatus(void)
if (excess_temp > ALM_OVERTEMP_THRESHOLD)
++retval;
}
// tests below here require the power to be on
if (getPowerControlState() != POWER_ON) {
return retval;
}
// FPGA
if (fpga_args.n_devices == 2) {
currentTemp[FPGA] = MAX(fpga_args.pm_values[0], fpga_args.pm_values[1]);
}
else {
currentTemp[FPGA] = fpga_args.pm_values[0];
}
excess_temp = currentTemp[FPGA] - getAlarmTemperature(FPGA);
if (excess_temp > 0.f) {
status_T |= ALM_STAT_FPGA_OVERTEMP;
retval++;
if (excess_temp > ALM_OVERTEMP_THRESHOLD)
++retval;
}

// Fireflies. These are reported as ints but we are asked
// to report a float.
// if stale we ignore
if (isFFStale())
return retval;
BaseType_t imax_ff_temp = -99;
for (size_t i = 0; i < NFIREFLIES; ++i) {
int8_t v = getFFtemp(i);
Expand Down Expand Up @@ -130,7 +136,7 @@ void TempErrorLog(void)

void TempClearErrorLog(void)
{
log_info(LOG_ALM, "Temperature normal\r\n");
log_info(LOG_ALM, "Temperature error cleared\r\n");
errbuffer_put(EBUF_TEMP_NORMAL, 0);
}

Expand Down Expand Up @@ -197,7 +203,8 @@ int VoltStatus(void)

// compile-time sanity check on the flags being unique.
// I need the +1 in the 1<xx since the highest channel is 0-based counting.
static_assert((VALM_BASE_MASK ^ VALM_GEN_MASK ^ VALM_F1_MASK ^ VALM_F2_MASK) == ((1 << (VALM_HIGHEST_V_CH + 1)) - 1), "VALM masks not unique");
static_assert((VALM_BASE_MASK ^ VALM_GEN_MASK ^ VALM_F1_MASK ^ VALM_F2_MASK) == ((1 << (VALM_HIGHEST_V_CH + 1)) - 1),
"VALM masks not unique");

bool f1_enable = isFPGAF1_PRESENT();
bool f2_enable = isFPGAF2_PRESENT();
Expand Down Expand Up @@ -267,7 +274,9 @@ void VoltErrorLog(void)
log_warn(LOG_ALM, "Voltage high: status: 0x%04x at ADC ch %02d now +%02d.%02d %% off\r\n",
status_V, excess_volt_which_ch, tens, frac);
}
errbuffer_volt_high((uint8_t)currentVoltStatus[GEN], (uint8_t)currentVoltStatus[FPGA1], (uint8_t)currentVoltStatus[FPGA2]); // add voltage status as a data field in eeprom rather than its value
// add voltage status as a data field in eeprom rather than its value
errbuffer_volt_high((uint8_t)currentVoltStatus[GEN], (uint8_t)currentVoltStatus[FPGA1],
(uint8_t)currentVoltStatus[FPGA2]);
}

void VoltClearErrorLog(void)
Expand Down
2 changes: 1 addition & 1 deletion projects/cm_mcu/AlarmUtilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ struct GenericAlarmParams_t {
int (*checkStatus)(void); // return 0 for normal, 1 for warn, >1 for error
void (*errorlog_registererror)(void);
void (*errorlog_clearerror)(void);
QueueHandle_t xAlmQueue;
UBaseType_t stack_size; // stack size of task
};

extern struct GenericAlarmParams_t tempAlarmTask;
extern struct GenericAlarmParams_t voltAlarmTask;
extern struct GenericAlarmParams_t currAlarmTask;

// temperature alarms
// first some commands for setting/getting the thresholds
Expand Down
6 changes: 3 additions & 3 deletions projects/cm_mcu/CommandLineTask.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
static char m[SCRATCH_SIZE];

// this command takes no arguments and never returns.
static BaseType_t bl_ctl(int argc, char **argv, char *m)
__attribute__((noreturn)) static BaseType_t bl_ctl(int argc, char **argv, char *m)
{
disable_ps();
Print("Jumping to bootloader\r\n");
ROM_SysCtlDelay(100000);
// this code is copied from the JumpToBootLoader()
Expand Down Expand Up @@ -54,8 +55,7 @@ static BaseType_t bl_ctl(int argc, char **argv, char *m)

// the above points to a memory location in flash.
#pragma GCC diagnostic pop
// shut up compiler warning. This will never get called
return pdFALSE;
__builtin_unreachable();
}

#ifdef REV2
Expand Down
4 changes: 1 addition & 3 deletions projects/cm_mcu/CommandLineTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@
// includes for types
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>

#include "FreeRTOS.h"
#include "FreeRTOSConfig.h"
#include "FreeRTOS.h" // IWYU pragma: keep
#include "stream_buffer.h"

// Command line interface
Expand Down
9 changes: 9 additions & 0 deletions projects/cm_mcu/FireflyUtils.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,23 @@ void readFFpresent(void)
// 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_w(4, 0x70, 1, 0x0);
// 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_w(4, 0x71, 1, 0x00);
#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_bar); // active low
apollo_i2c_ctl_w(4, 0x70, 1, 0x8); // clear the mux

// to port 6
apollo_i2c_ctl_w(4, 0x71, 1, 0x40);
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
apollo_i2c_ctl_w(4, 0x71, 1, 0x0); // clear the mux

#endif

Expand All @@ -117,18 +122,22 @@ void readFFpresent(void)
// to port 0
apollo_i2c_ctl_w(3, 0x72, 1, 0x01);
apollo_i2c_ctl_reg_r(3, 0x20, 1, 0x01, 1, &present_0X20_F2);
apollo_i2c_ctl_w(3, 0x72, 1, 0x0);
// to port 1
apollo_i2c_ctl_w(3, 0x72, 1, 0x02);
apollo_i2c_ctl_reg_r(3, 0x21, 1, 0x01, 1, &present_0X21_F2);
apollo_i2c_ctl_w(3, 0x72, 1, 0x0);
#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_bar); // active low
apollo_i2c_ctl_w(3, 0x70, 1, 0x0);
// to port 6
apollo_i2c_ctl_w(3, 0x71, 1, 0x40);
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
apollo_i2c_ctl_w(3, 0x71, 1, 0x40);

#endif
// if we have a semaphore, give it
Expand Down
Loading

0 comments on commit 9210313

Please sign in to comment.