analogdevicesinc / Linduino

Code for the Linduino, An Arduino Uno-based board that is compatible with many Analog Devices evaluation boards
Other
99 stars 100 forks source link

LTC681x_reset_crc_count does not use data which says how many registers are available. #41

Open gudnimg opened 3 years ago

gudnimg commented 3 years ago

This is what the function looks like right now:

/* 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;
        }
    }
}
gudnimg commented 3 years ago

I created a separate issue for my comment about LTC681x_check_pec(). #43