I need to align a buffer on a 4 byte boundary (means last 2 bits of the address must be zero). I’m currently declaring my buffer like this:
volatile unsigned char backBuffer[2][FRAME_SIZE] __attribute__ ((aligned(4)));
Abode code doesn’t align it, but the address is fixed.
Then I though of allocating memory and adjusting it to a boundary, like this:
volatile unsigned char* backBuffer[2];
backBuffer[0] = RLPext->malloc(FRAME_SIZE + 4);
backBuffer[1] = RLPext->malloc(FRAME_SIZE + 4);
while ((unsigned long)backBuffer[0] & 0x3)
backBuffer[0]++;
while ((unsigned long)backBuffer[1] & 0x3)
backBuffer[1]++;
but sometime, when I run the code one of the buffers is still not aligned correctly.
What am I missing?