Quality RTOS & Embedded Software

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


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 ]    [ Privacy ]    [ Sitemap ]    [ ]


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

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


Careers

FreeRTOS and other embedded software careers at AWS.



FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Renesas

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

Xilinx Microblaze and Zynq partner