More memory on ATMega128
Posted by Nobody/Anonymous on December 11, 2004
Would you mind giving me a hand on FreeRTOS?
The FreeRTOS works fine to me in a project based on ATmega128 until recently that I would like to create one more task. It shows errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY when it is asked to create a new
I look at the output map file. There is still 1k not used. So look up the API, it is saying to change portTOTAL_HEAP_SIZE in portmacro.h. I could not find portTOTAL_HEAP_SIZE in it. Instead, I find
#define heapNUM_SMALL_BLOCKS ( 16 )
#define heapNUM_LARGE_BLOCKS ( 10 )
1. Are these the arrays that need changing?
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?
3. Does the kernel reserve some blocks?
Thanks in advance.
RE: More memory on ATMega128
Posted by Richard
on 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:
Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd..
See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.