/* Helper Function to reset PEC counters */
void LTC681x_reset_crc_count(uint8_t total_ic, //Number of ICs in the system
cell_asic *ic //A two dimensional array that stores the data
)
{
for (int current_ic = 0 ; current_ic < total_ic; current_ic++)
{
ic[current_ic].crc_count.pec_count = 0;
ic[current_ic].crc_count.cfgr_pec = 0;
for (int i=0; i<6; i++)
{
ic[current_ic].crc_count.cell_pec[i]=0;
}
for (int i=0; i<4; i++)
{
ic[current_ic].crc_count.aux_pec[i]=0;
}
for (int i=0; i<2; i++)
{
ic[current_ic].crc_count.stat_pec[i]=0;
}
}
}
We can make it more general like this:
/* Helper Function to reset PEC counters */
void LTC681x_reset_crc_count(uint8_t total_ic, //Number of ICs in the system
cell_asic *ic //A two dimensional array that stores the data
)
{
for (uint8_t current_ic = 0 ; current_ic < total_ic; current_ic++)
{
ic[current_ic].crc_count.pec_count = 0;
ic[current_ic].crc_count.cfgr_pec = 0;
for (uint8_t i = 0; i < ic[current_ic].ic_reg.num_cv_reg; i++)
{
ic[current_ic].crc_count.cell_pec[i] = 0;
}
for (uint8_t i = 0; i < ic[current_ic].ic_reg.num_gpio_reg; i++)
{
ic[current_ic].crc_count.aux_pec[i] = 0;
}
for (uint8_t i = 0; i < ic[current_ic].ic_reg.num_stat_reg; i++)
{
ic[current_ic].crc_count.stat_pec[i] = 0;
}
}
}
This is what the function looks like right now:
We can make it more general like this: