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 3 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
18 changes: 6 additions & 12 deletions projects/cm_mcu/LocalTasks.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 @@ -1321,8 +1317,8 @@ int init_load_clk(int clk_n)
}

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 status_r + 1; // fail reading and exit
pkotamnives marked this conversation as resolved.
Show resolved Hide resolved
}

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
Expand All @@ -1334,8 +1330,8 @@ int init_load_clk(int clk_n)
}

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 status_r + 1; // fail reading and exit
pkotamnives marked this conversation as resolved.
Show resolved Hide resolved
}

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
Expand All @@ -1347,8 +1343,8 @@ int init_load_clk(int clk_n)
}

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 status_r + 1; // fail reading and exit
pkotamnives marked this conversation as resolved.
Show resolved Hide resolved
}

log_debug(LOG_SERVICE, "Start programming clock %s\r\n", clk_ids[clk_n]);
Expand Down Expand Up @@ -1376,8 +1372,6 @@ int init_load_clk(int clk_n)
return status_w;
}

xSemaphoreGive(clock_args.xSem);

return status_w;
}
#endif // REV2