rtel wrote on Saturday, December 11, 2004:
It sounds like you are using an older version of FreeRTOS. The portheap.c you mention was replaced in version 2.5.0 with three sample (and simple) memory management schemes.
If you are using the portheap.c as directly downloaded on an ATMega128 then I suspect you have a lot of unused memory you can make use of.
First I will answer the questions relating to your current version, then make some suggestions as how you can upgrade:
> 1. Are these the arrays that need changing?
Basically yes. The old portheap.c you are using maintained two pools of fixed size memory blocks. When the kernel wanted to allocated some memory it would use a block from the array of small blocks if appropriate, or the array of large blocks if there were no small blocks left of the allocation required a large block anyway.
>2. How do the array sizes relate to the number of tasks created? In another word, how many heapNUM_SMALL_BLOCKS and heapNUM_LARGE_BLOCKS need being allocated for one task?
Normally one small block and one large block for each task. Blocks are also used for queues and semaphores so there is not a one to one relationship.
>3. Does the kernel reserve some blocks?
Every call to pvPortMalloc() obtains a block from either array. The kernel call pvPortMalloc() when a task, queue or semaphore is created.
V2.5.0 onwards of FreeRTOS has replaced the portheap.c files with heap_1.c, heap_2.c and heap_3.c. These are described here:
Have a look at this page and decide which scheme is best for you. They all use one single array of memory from which blocks of any size can be allocated. The total size of the array is set by the constant portTOTAL_HEAP_SIZE, making configuration a lot easier as you only have one constant to set.
I suggest you download the latest version of FreeRTOS and either:
1) Use the latest version in its entirety this would be the preferred solution.
2) Just take the heap_x.c file from the latest version and use it in your project in place of portheap.c. You may need to replace the vTaskSuspendAll() and cTaskResumeAll() in heap_x.c with calls to portENTER_CRITICAL() and portEXIT_CRITICAL() respectively.
The other alternative of course is to keep the files you are using and increase the heapNUM_SMALL_BLOCKS and heapNUM_LARGE_BLOCKS constants.
I also suggest taking a look at the version history: