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




Loading

question: macro or function?

Posted by Steven on August 6, 2010
Why is portSAVE_CONTEXT() implemented as a macro, and not as a function?

I am going to use a PIC18F4550 but I was thinking: if I use a function instead of a macro, I can save a little bit RAM (pic18f4550 doesnt have much RAM), what do you think?

RE: question: macro or function?

Posted by woops_ on August 6, 2010
Saving and restoring must usually be inline code to get the stack frame right. Function calls include hidden code.

RE: question: macro or function?

Posted by Richard Damon on August 6, 2010
If portSAVE_CONTEXT was a function, then when it returned it would have to "unsave" the context to get to the return address, in one sense, portYIELD does that, save context, swap context, restore new context, and all works just fine. It is some what tricky programming (if it is possible) to make a function that you can call that returns to you and in the process saves the processor state on the stack, and even if you could write it, changing the stack in this manner in arbitrary places could give the compiler problems. This is one reason why the rules for how you right your ISRs can be very precise and tricky, as the save context macro needs to know the conditions it is being used to make things work.

Another issue is that it really wouldn't save that much program memory, as there are normally only a few calls to this macro. As I mentioned, portYEILD does, and in some port, the interrupt handlers will call it. (on others the interrupt handlers call portYIELD to save the context).

RE: question: macro or function?

Posted by Steven on August 7, 2010
ok, now i see, thank you all!


[ 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