Quality RTOS & Embedded Software

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




Loading

PIC18 task context is 2 bytes too long

Posted by Paul_Piak on August 1, 2008
Hello,

I think 2 bytes can be removed from the PIC18 task context save/restore macros.
When saving context, the FSR0 register is initialized to 0, which is the address of the first byte of the .tmpdata+.mathdata sections
These 2 sections are then saved to the stack by executing an application dependent number (portCOMPILER_MANAGED_MEMORY_SIZE) of
MOVFFPOSTINC0, PREINC1
instructions.
After saving .tmpdata+.mathdata, the value of FSR0 is equal to the address of the last byte in .tmpdata+.mathdata
This address is equal to the constant portCOMPILER_MANAGED_MEMORY_SIZE
Thus, at this point the contents of FSR0 is the same for every context switch. The value is the same every time, for each task in a single application.
Effectively a constant value is saved.
By definition, constants don't have to be saved on a stack, since they don't unexpectedly change.

When restoring the .tmpdata+.mathdata sections from the stack, first FSR0 is initialized to the address of the last byte in .tmpdata+.mathdata
This is now done by restoring FSR0 from the task stack. But we know FSR0 will always be restored to portCOMPILER_MANAGED_MEMORY_SIZE, since that is the location of the last byte of .tmpdata+.mathdata , which will be the first byte to be restored.

Total savings: 2 bytes RAM for each task stack and 2 instructions when saving the context (restoring context will be the same number of cycles because FSR0 has to be set to the constant value that was previously on the stack, but is now portCOMPILER_MANAGED_MEMORY_SIZE)


Paul

RE: PIC18 task context is 2 bytes too long

Posted by Paul_Piak on August 7, 2008
Is everybody still thinking about this?
If I'm not making sense, could someone tell me?
Paul

RE: PIC18 task context is 2 bytes too long

Posted by Richard on August 7, 2008
Sorry for the delay ... I will get around to looking at it.

Regards.


[ 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