Im a new to FreeRTOS and was going through the source code. I found the following line of code in the heap_1.c file line no. 98:
/* Ensure the heap starts on a correctly aligned boundary. */ pucAlignedHeap = ( uint8_t * ) ( ( ( portPOINTER_SIZE_TYPE ) & ucHeap[ portBYTE_ALIGNMENT ] ) & ( ~( ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK ) ) );
I understand that pucAlignedHeap is getting assigned an aligned memory address from the beginning of the ucHeap array, but I’m confused why the statement uses ucHeap[ portBYTE_ALIGNMENT ] instead of ucHeap[ portBYTE_ALIGNMENT - 1 ].
For example if portBYTE_ALIGNMENT is 8 and portBYTE_ALIGNMENT_MASK is 7 and suppose ucHeap[ portBYTE_ALIGNMENT ] has an address
0x*******F, the aligned address variable, pucAlignedHeap will be getting assigned
0x*******8 which is basically the address of index 1 of the ucHeap array. That means 0th index of the array is not used even in the worst case. I believe there is something off with the way I’m visualising this. Please let me know what I’m missing.