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 hardcode in InitTask from issue #148 #149

Merged
merged 4 commits into from
Oct 13, 2022
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
6 changes: 5 additions & 1 deletion projects/cm_mcu/CommandLineTask.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,12 @@ static BaseType_t init_load_clock_ctl(int argc, char **argv, char *m)
return pdFALSE;
}
copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%s is programming clock %s. \r\n", argv[0], clk_ids[i]);
int status = -1; // shut up clang compiler warning
int status = -1; // shut up clang compiler warning
// grab the semaphore to ensure unique access to I2C controller
while (xSemaphoreTake(clock_args.xSem, (TickType_t)10) == pdFALSE)
;
status = init_load_clk(i); // status is 0 if all registers can be written to a clock chip. otherwise, it implies that some write registers fail in a certain list.
xSemaphoreGive(clock_args.xSem);
if (status == 0) {
snprintf(m + copied, SCRATCH_SIZE - copied,
"clock synthesizer with id %s successfully programmed. \r\n", clk_ids[i]);
Expand Down
6 changes: 4 additions & 2 deletions projects/cm_mcu/InitTask.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@ void InitTask(void *parameters)
init_registers_clk(); // initalize I/O expander for clocks
log_info(LOG_SERVICE, "Clock I/O expander initialized\r\n");
#ifdef REV2
// grab the semaphore to ensure unique access to I2C controller
while (xSemaphoreTake(clock_args.xSem, (TickType_t)10) == pdFALSE)
;
for (int i = 0; i < 5; ++i) {
if (i == 1 || i == 4)
continue;
init_load_clk(i); // load each clock config from EEPROM
}
xSemaphoreGive(clock_args.xSem);
log_info(LOG_SERVICE, "Clocks configured\r\n");
getFFpart(); // the order of where to check FF part matters -- it won't be able to read anything if check sooner
#endif // REV2
Expand Down
26 changes: 7 additions & 19 deletions projects/cm_mcu/LocalTasks.c
Original file line number Diff line number Diff line change
Expand Up @@ -1289,7 +1289,7 @@ static int load_clk_registers(int reg_count, uint16_t reg_page, uint16_t i2c_add

int init_load_clk(int clk_n)
{

// this function requires semaphore give/take at a larger scope to handle its task.
while (getPowerControlState() != POWER_ON) {
vTaskDelay(pdMS_TO_TICKS(10)); // delay 10 ms
}
Expand All @@ -1299,10 +1299,6 @@ int init_load_clk(int clk_n)
if (clk_n == 0)
i2c_addrs = CLOCK_CHIP_R0A_I2C_ADDR;

// grab the semaphore to ensure unique access to I2C controller
while (xSemaphoreTake(clock_args.xSem, (TickType_t)10) == pdFALSE)
;

pkotamnives marked this conversation as resolved.
Show resolved Hide resolved
int status_r = apollo_i2c_ctl_w(CLOCK_I2C_DEV, CLOCK_I2C_MUX_ADDR, 1, 1 << clk_n);
if (status_r != 0) {
log_error(LOG_SERVICE, "Mux error: %s\r\n", SMBUS_get_error(status_r));
Expand All @@ -1316,68 +1312,60 @@ int init_load_clk(int clk_n)
status_r = apollo_i2c_ctl_reg_r(CLOCK_I2C_DEV, CLOCK_I2C_EEPROM_ADDR, 2, (init_postamble_page << 8) + 0x007C, 1, &PreambleList_row);
if (status_r != 0) {
log_error(LOG_SERVICE, "PreL read error: %s\r\n", SMBUS_get_error(status_r));
xSemaphoreGive(clock_args.xSem);
return status_r; // fail reading and exit
}

if (PreambleList_row == 0xff) {
log_warn(LOG_SERVICE, "Quit.. garbage EEPROM PreL\r\n");
return status_r; // fail reading and exit
log_warn(LOG_SERVICE, "Quit.. garbage EEPROM of %s PreL\r\n", clk_ids[clk_n]);
return 1; // fail reading and exit
}

uint32_t RegisterList_row; // the size of register list in a clock config file store at the end of the last eeprom page of a clock
status_r = apollo_i2c_ctl_reg_r(CLOCK_I2C_DEV, CLOCK_I2C_EEPROM_ADDR, 2, (init_postamble_page << 8) + 0x007D, 2, &RegisterList_row);
if (status_r != 0) {
log_error(LOG_SERVICE, "RL read error: %s\r\n", SMBUS_get_error(status_r));
xSemaphoreGive(clock_args.xSem);
return status_r; // fail reading and exit
}

if (RegisterList_row == 0xffff) {
log_warn(LOG_SERVICE, "Quit.. garbage EEPROM RegL\r\n");
return status_r; // fail reading and exit
log_warn(LOG_SERVICE, "Quit.. garbage EEPROM of %s RegL\r\n", clk_ids[clk_n]);
return 1; // fail reading and exit
}

uint32_t PostambleList_row; // the size of postamble list in a clock config file store at the end of the last eeprom page of a clock
status_r = apollo_i2c_ctl_reg_r(CLOCK_I2C_DEV, CLOCK_I2C_EEPROM_ADDR, 2, (init_postamble_page << 8) + 0x007F, 1, &PostambleList_row);
if (status_r != 0) {
log_error(LOG_SERVICE, "PosL read error: %s\r\n", SMBUS_get_error(status_r));
xSemaphoreGive(clock_args.xSem);
return status_r; // fail reading and exit
}

if (PostambleList_row == 0xff) {
log_warn(LOG_SERVICE, "Quit.. garbage EEPROM PostL\r\n");
return status_r; // fail reading and exit
log_warn(LOG_SERVICE, "Quit.. garbage EEPROM of %s PostL\r\n", clk_ids[clk_n]);
return 1; // fail reading and exit
}

log_debug(LOG_SERVICE, "Start programming clock %s\r\n", clk_ids[clk_n]);
log_debug(LOG_SERVICE, "Loading clock %s PreambleList from EEPROM\r\n", clk_ids[clk_n]);
int status_w = load_clk_registers(PreambleList_row, init_preamble_page, i2c_addrs);
if (status_w != 0) {
log_error(LOG_SERVICE, "PreL write error %d\r\n", status_w);
xSemaphoreGive(clock_args.xSem);
return status_w;
}
vTaskDelay(pdMS_TO_TICKS(330)); // 300 ms minimum delay
log_debug(LOG_SERVICE, "Loading clock %s RegisterList from EEPROM\r\n", clk_ids[clk_n]);
status_w = load_clk_registers(RegisterList_row, init_register_page, i2c_addrs);
if (status_w != 0) {
log_error(LOG_SERVICE, "RegL write error %d\r\n", status_w);
xSemaphoreGive(clock_args.xSem);
return status_w;
}
vTaskDelay(pdMS_TO_TICKS(330)); // 300 ms minimum delay
log_debug(LOG_SERVICE, "Loading clock %s PostambleList from EEPROM\r\n", clk_ids[clk_n]);
status_w = load_clk_registers(PostambleList_row, init_postamble_page, i2c_addrs);
if (status_w != 0) {
log_error(LOG_SERVICE, "PosL write error %d\r\n", status_w);
xSemaphoreGive(clock_args.xSem);
return status_w;
}

xSemaphoreGive(clock_args.xSem);

return status_w;
}
#endif // REV2