Quality RTOS & Embedded Software

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


How to save addditional context

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

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 */
//additional code
*pxTopOfStack = ( portSTACK_TYPE ) 0x032;/* one byte more for RAMPZ */
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


RE: How to save addditional context

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

Latest News:

FreeRTOS V9.0.0 is now available for download.

Free TCP/IP and file system demos for the RTOS

Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

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

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

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

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists