Tool/software: TI C/C++ Compiler
Dear all, forum, TI,
We are currently working on a project that involves multiple microcontrollers. To minimize code work, me and my colleague are trying to reuse some code. My colleague wrote the attached buffer class (CircularBuffer implemented.h). The idea is to store incoming data from SCI or CAN in the interrupt service routine, and read from the buffer again when the CPU has 'time left' (ie not busy with an interrupt). The function push(data) pushes the new element into the buffer. With pop(), we read an element from the buffer. Before popping an element, we manually check if there is an element available by using the size() function. If the buffer is full, it just overwrites the first element again.
Now the issue: it seems that, when initializing multiple buffers in one class, the allocated memory is the same. At least, that is what is seems to do. What I did is the follwing: sending cyclically a known value over CANB to one mailbox, while sending zeros to the other mailboxes (all a unique ID). Then: reading using the interrupt and pushing in the separate buffers. Then, main pops the values from the seperate buffers and sends them over CANA using different mailboxes (and thus ID's again).
The issue: the data over CANA has sometimes the known value, sometimes the unwanted 0.
Related to this behaviour seems the following: all buffers seems to have the same address. I see the following for every buffer when halting the program during runtime with a breakpoint. The whole program is ran from flash.
Name : *(array)
Default:-4283498321
Hex:0xFFFFFFFF00AF00AF
Decimal:-4283498321
Octal:053600257
Binary:1111111111111111111111111111111100000000101011110000000010101111b
The buffers in the class are initialized as follows:
.h file:
CircularBuffer<int64_t, 100> IVTcurrentBuffer;
CircularBuffer<int64_t, 100> IVTvolt1Buffer;
CircularBuffer<int64_t, 100> IVTvolt2Buffer;
CircularBuffer<int64_t, 100> IVTvolt3Buffer;
CircularBuffer<int64_t, 100> IVTtempBuffer;
CircularBuffer<int64_t, 100> IVTpowerBuffer;
CircularBuffer<int64_t, 100> IVTenergyCntBuffer;
.cpp file:
IVTcurrentBuffer = CircularBuffer<int64_t, 100>();
IVTvolt1Buffer = CircularBuffer<int64_t, 100>();
IVTvolt2Buffer = CircularBuffer<int64_t, 100>();
IVTvolt3Buffer = CircularBuffer<int64_t, 100>();
IVTtempBuffer = CircularBuffer<int64_t, 100>();
IVTpowerBuffer = CircularBuffer<int64_t, 100>();
IVTenergyCntBuffer = CircularBuffer<int64_t, 100>();
My question is: can anyone see what is going on here with the memory allocation for different buffers that are using the same template? Otherwise, any other suggestions where this problem can be? I checked the ISRs from the CAN mailboxes, but they operate fine (tested with other sequences without the use of these type of buffers).
One final thing: my colleague is using an NXP MCP5744 and ran into an problem using malloc or calloc, so his version is included as well (CircularBuffer alternative.h), but running that code runs into an ILLEGAL_ISR. Any ideas why that would differ between the two microcontrollers (I am using the TMS320F28335).
Any idea would be appreciated! Jeroen