Other Parts Discussed in Thread: CC2530, Z-STACK
Hi,
I have a strange problem. I have a function that copies data from a received message to the heap using osal_mem_alloc. The first time through I always get a rogue value in the same place amongst good data when using osal_mem_alloc. Subsequent function calls work perfectly.
If I drop osal_mem_alloc and declare a simple array then it works perfectly from the start.
Here is what I'm doing:
//assign some heap space to pointer
historical_data_buffer_ptr = ((HISTORICAL_DATA_BUFFER *)osal_mem_alloc(length_of_data)); //*** this line changes the data in the incoming message- why?
//check that some heap space was assigned
if(historical_data_buffer_ptr != NULL)
{
//copy the data from the incoming message to the heap.
osal_memcpy(&historical_data_buffer_ptr->historical_buffer, &function_msg_in->incoming_msg.cmd.Data[HDR_DATA_LOCATION], length_of_data);
}
The only thing I can think of is that as the incoming message is also in the heap and not deallocated until after this function call. My heap allocation must be changing one byte of the incoming message, but how?
I'd like to use the dynamic heap but as it stands, I am forced to used a static array instead.
I am using z-stack home 1.2.1 on CC2530.
Any ideas any one?
Andy