Part Number: TMS320F280025C
Tool/software: TI C/C++ Compiler
Hello,
I am currently using TMS320F280025C controlCARD evaluation module.
When free() is being executed in the following code, I am hitting illegal operation interrupt.
giving complete code for reference.
uint8_t *data;
data = (uint8_t *) malloc((12*total_ic)*sizeof(uint8_t)); for (uint8_t stat_reg = 1; stat_reg< 3; stat_reg++) //Executes once for each of the LTC681x stat voltage registers { data_counter = 0; rdstat_reg(stat_reg, total_ic,data); //Reads the raw status register data into the data[] array for (uint8_t current_ic = 0 ; current_ic < total_ic; current_ic++) // Executes for every LTC681x in the daisy chain { // current_ic is used as the IC counter if (ic->isospi_reverse == false) { c_ic = current_ic; } else { c_ic = total_ic - current_ic - 1; } if (stat_reg ==1) { for (uint8_t current_stat = 0; current_stat< STAT_IN_REG; current_stat++) // This loop parses the read back data into Status registers, { // it loops once for each of the 3 stat codes in the register parsed_stat = data[data_counter] + (data[data_counter+1]<<8); //Each stat codes is received as two bytes and is combined to create the parsed status code ic[c_ic].stat.stat_codes[current_stat] = parsed_stat; data_counter=data_counter+2; //Because stat codes are two bytes the data counter } } else if (stat_reg == 2) { parsed_stat = data[data_counter] + (data[data_counter+1]<<8); //Each stat is received as two bytes and is combined to create the parsed status code data_counter = data_counter +2; ic[c_ic].stat.stat_codes[3] = parsed_stat; ic[c_ic].stat.flags[0] = data[data_counter++]; ic[c_ic].stat.flags[1] = data[data_counter++]; ic[c_ic].stat.flags[2] = data[data_counter++]; ic[c_ic].stat.mux_fail[0] = (data[data_counter] & 0x02)>>1; ic[c_ic].stat.thsd[0] = data[data_counter++] & 0x01; } received_pec = (data[data_counter]<<8)+ data[data_counter+1]; //The received PEC for the current_ic is transmitted as the 7th and 8th //after the 6 status data bytes data_pec = pec15_calc(BYT_IN_REG, &data[current_ic*NUM_RX_BYT]); if (received_pec != data_pec) { pec_error = -1; //The pec_error variable is simply set negative if any PEC errors ic[c_ic].stat.pec_match[stat_reg-1]=1; //are detected in the received serial data } else { ic[c_ic].stat.pec_match[stat_reg-1]=0; } data_counter=data_counter+2; //Because the transmitted PEC code is 2 bytes long the data_counter //must be incremented by 2 bytes to point to the next ICs status data } } free(data);
I tried following code just to check if this problem occurs every time; just above malloc in previous code.
data = (uint8_t *) malloc((12));
data[0] = 5;
free(data);
but this code works and no error is observed.
Also variable data is never changed. and only accessed as pointer even in the function calls mentioned.
Can you please help understand where this code might be going wrong? OR what I need to do to make it work and why.
Thanks in advance.