Skip to content

Commit

Permalink
add quit init clock loading if garbage EEPROM is detected (#138)
Browse files Browse the repository at this point in the history
* add quit init clock loading if garbage EEPROM is detected
  • Loading branch information
pkotamnives committed Aug 19, 2022
1 parent ee0605d commit 6cce566
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions projects/cm_mcu/LocalTasks.c
Original file line number Diff line number Diff line change
Expand Up @@ -703,32 +703,51 @@ int init_load_clk(int clk_n)
if (clk_n == 0)
i2c_addrs = CLOCK_CHIP_R0A_I2C_ADDR;

apollo_i2c_ctl_w(CLOCK_I2C_DEV, CLOCK_I2C_MUX_ADDR, 1, 1 << clk_n);
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));
return status_r; // fail reading and exit
}
uint16_t init_preamble_page = 32 * (clk_n);
uint16_t init_register_page = 32 * (clk_n) + 1;
uint16_t init_postamble_page = 32 * (clk_n + 1) - 1;

uint32_t PreambleList_row; // the size of preamble list in a clock config file store at the end of the last eeprom page of a clock
int status_r = apollo_i2c_ctl_reg_r(CLOCK_I2C_DEV, CLOCK_I2C_EEPROM_ADDR, 2, (init_postamble_page << 8) + 0x007C, 1, &PreambleList_row);
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));
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
}

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));
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
}

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));
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_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);
Expand Down

0 comments on commit 6cce566

Please sign in to comment.