I am using FreeRTOS on Atmega1280. portSAVE_CONTEXT() on this port pushes 32 processor registers to task stack and loads stack pointer to TCB.
I have to save one additional variable from SRAM (it is RAMPZ). I have tried to add additional variable to TCB strucure to save it, but RTOS freezes after that. Also I have tried to push it on task stack. It doesn’t work also (it seems that stack size is limited somehow and can only save 32 registers).
Do you have any suggestions how to save this variable?
You will need to updated portSAVE_CONTEXT() and portRESTORE_CONTEXT() to push and pop the extra registers respectively, AND update pxPortInitialiseStack() to reflect the same changes.
If you want to save the RAMPZ then I would guess you are using a part that has a three byte program counter, so you will also need to update pxPortInitialiseStack() for the extra program counter byte. I think there are ports around where this has been done. You might try avrfreaks.net.
I guess it is simple to modify portSAVE_CONTEXT() and portRESTORE_CONTEXT(). But I have no idea how to modify pxPortInitialiseStack(). Should I add something like this
portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )
*pxTopOfStack = ( portSTACK_TYPE ) 0x031; /* R31 */
*pxTopOfStack = ( portSTACK_TYPE ) 0x032; /* one byte more for RAMPZ */
RAMPZ saving is requried to perform access to FLASH memory from several tasks (strings, bitmaps and tunes are stored there).
That looks to be correct if RAMPZ is then the first thing to be popped from the stack in portRESTORE_CONTEXT() and the last thing to be pushed to the stack in portSAVE_CONTEXT().
You can check by placing a break point at the start of a task function (on the function name or on the opening bracket of the function) then looking at RAMPZ in the debugger to check it contains 0x32.
If you have a port that is running on one of the extended AVR devices then I would like to encourage you to upload it to the FreeRTOS interactive site - see http://interactive.freertos.org
Do you mean AVR controllers with extended I/O space from $60 - $1FF in SRAM (only the ST/STS/STD and LD/LDS/LDD instructions can be used in this space)?
My port is running on Atmega1280. I have used port for Atmega323 and made only some minor changes related to tick counter. Port works fine, but I want to add saving of RAMPZ and EIND during context switch. Maybe after that it will be worth uploading.