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[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; backBuffer = RLPext->malloc(FRAME_SIZE + 4); backBuffer = RLPext->malloc(FRAME_SIZE + 4); while ((unsigned long)backBuffer & 0x3) backBuffer++; while ((unsigned long)backBuffer & 0x3) backBuffer++;
but sometime, when I run the code one of the buffers is still not aligned correctly.
What am I missing?