FreeRTOS Support Archive
The FreeRTOS support forum is used to obtain active support directly from Real
Time Engineers Ltd. In return for using our top quality software and services for
free, we request you play fair and do your bit to help others too! Sign up
to receive notifications of new support topics then help where you can.
This is a read only archive of threads posted to the FreeRTOS support forum.
The archive is updated every week, so will not always contain the very latest posts.
Use these archive pages to search previous posts. Use the Live FreeRTOS Forum
link to reply to a post, or start a new support thread.
[FreeRTOS Home] [Live FreeRTOS Forum] [FAQ] [Archive Top] [August 2010 Threads] 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!
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|