C18 linker restrictions loosened

nobody wrote on Thursday, July 20, 2006:

Hi,

I studied the remarks by John Franklin about how to set up the linker script and modify heap_1.c to prevent variables leaking across page boundaries.

I think his solution is way too complex.

The goal is to get the heap in one memory section (which can cross multiple banks), and keep the rest of the variables from crossing a bank boundary.

This can simply be realised by combining no more banks than required for the heap.
Let’s say the desired heap is 2200 bytes

This is done by
#define configTOTAL_HEAP_SIZE            ( ( size_t ) 2200 )
in FreeRTOSConfig.h

As a result the variable ‘xHeap’ defined in heap_1.c will be 2204 bytes long because of the additional long variable in the struct.
In hexadecimal 2204 is 0x89C, which is the minimum required size of the memory region. (There are no other variables defined in heap_1.c, so this is all the memory required for de .udata_heap_1.o memory section)

It is now sufficient to define a region in the linker script which is between 0x89C and 0x900 long.
The rest of the banks will be left alone and have a length of 0x100, starting at a boundary.

The linker will automatically fit the .udata_heap_1.o memory section (containing the xHeap variable) into the first region with enough space. The remaining space in the combined region can be used by other memory sections.
(It is in this example _not_ allowed to define the region _larger_ than 0x900 bytes since other variables stored in the region can then cross a boundary.)

Conclusions:
- There is no need to modify the FreeRTOS library file heap_1.c with
#pragma udata heap_section
#pragma udata
- There is no need to define the combined region "PROTECTED"
- There is no need for a "SECTION    NAME=heap_section RAM=heapregion" mapping in the linker script

All that is required is to combine no more banks than strictly required to accomodate configTOTAL_HEAP_SIZE+4 bytes
It is allowed to oversize the region to the next bank boundary, and let the linker fill up the rest of the region. You don’t have to define your own (non-PROTECTED) region to fill up the bank if you don’t want to waste the remaining space.

Paul

nobody wrote on Thursday, July 20, 2006:

Makes sense.  Comments John?