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

Fix bug in how the PG is handled for the 3.8V firefly supply #189

Merged
merged 14 commits into from
Jun 28, 2023
Merged
59 changes: 31 additions & 28 deletions projects/cm_mcu/MonitorI2CTask.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,15 @@ void MonitorI2CTask(void *parameters)

bool good = false;
for (;;) {

log_debug(LOG_MONI2C, "%s: grab semaphore\r\n", args->name);

// grab the semaphore to ensure unique access to I2C controller
if (acquireI2CSemaphore(args->xSem) == pdFAIL) {
log_warn(LOG_SERVICE, "%s could not get semaphore in time; continue\r\n", args->name);
continue;
if (args->xSem != NULL) {
if (acquireI2CSemaphore(args->xSem) == pdFAIL) {
log_warn(LOG_SERVICE, "%s could not get semaphore in time; continue\r\n", args->name);
continue;
}
}
pwittich marked this conversation as resolved.
Show resolved Hide resolved

// -------------------------------
Expand All @@ -98,8 +101,33 @@ void MonitorI2CTask(void *parameters)
log_debug(LOG_MONI2C, "%s: device %d\r\n", args->name, ps);

if (ps == args->n_devices - 1 && getPowerControlState() != POWER_ON) { // avoid continues to infinite loops due to multi-threading when pwr is not on
pwittich marked this conversation as resolved.
Show resolved Hide resolved
if (xSemaphoreGetMutexHolder(args->xSem) == xTaskGetCurrentTaskHandle()) {
xSemaphoreGive(args->xSem);
}
break;
}

log_debug(LOG_MONI2C, "%s: powercheck\r\n", args->name);

if (getPowerControlState() != POWER_ON) {
if (good) {
log_info(LOG_MONI2C, "%s: PWR off. Disabling I2C monitoring.\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)starting I2C monitoring.\r\n", args->name);
good = true;
}
}

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
Expand All @@ -125,31 +153,6 @@ void MonitorI2CTask(void *parameters)
#endif
}
}
log_debug(LOG_MONI2C, "%s: powercheck\r\n", args->name);

if (getPowerControlState() != POWER_ON) {
if (good) {
log_info(LOG_MONI2C, "%s: PWR off. Disabling I2C monitoring.\r\n", args->name);
good = false;
task_watchdog_unregister_task(kWatchdogTaskID_MonitorI2CTask);
}
vTaskDelay(pdMS_TO_TICKS(500));
continue;
}
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)starting I2C monitoring.\r\n", args->name);
good = true;
}
}
// if the power state is unknown, don't do anything
else {
log_info(LOG_MONI2C, "%s: power state %d unknown\r\n", args->name,
getPowerControlState());
vTaskDelay(10);
continue;
}

if (!IsCLK) {
// mux setting
Expand Down
4 changes: 2 additions & 2 deletions projects/cm_mcu/PowerSupplyTask.c
Original file line number Diff line number Diff line change
Expand Up @@ -496,8 +496,8 @@ void PowerSupplyTask(void *parameters)
setPSStatus(N_PS_OKS - 1, PWR_FAILED);
#endif
if (currentState != nextState) {
log_info(LOG_PWRCTL, "%s: change from state %s to %s\r\n", pcTaskGetName(NULL),
power_system_state_names[currentState], power_system_state_names[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]);
}
currentState = nextState;

Expand Down