Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT




Loading

How to save addditional context

Posted by Yuriy Kulikov on April 16, 2010
Hello!
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?
Many thanks,
Yurij

RE: How to save addditional context

Posted by Dave on April 16, 2010
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.

RE: How to save addditional context

Posted by Yuriy Kulikov on April 16, 2010
Thanks davedoors!
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 )
{
//-----ORIGINAL CODE---------
.....................
*pxTopOfStack = ( portSTACK_TYPE ) 0x031;/* R31 */
pxTopOfStack--;
//additional code
*pxTopOfStack = ( portSTACK_TYPE ) 0x032;/* one byte more for RAMPZ */
pxTopOfStack--;
return pxTopOfStack;
}
RAMPZ saving is requried to perform access to FLASH memory from several tasks (strings, bitmaps and tunes are stored there).

RE: How to save addditional context

Posted by Dave on April 16, 2010
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.

RE: How to save addditional context

Posted by Richard on April 16, 2010
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

Regards.

RE: How to save addditional context

Posted by Yuriy Kulikov on April 16, 2010
richardbarry
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.

RE: How to save addditional context

Posted by Yuriy Kulikov on April 16, 2010
Thanks to everybody!
Looks like it works fine now. After some testing I will upload it.


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS