Hands-On RTOS with Microcontrollers by Brian Amos

Hands-On RTOS with Microcontrollers by Brian Amos

Author:Brian Amos
Language: eng
Format: mobi
Tags: COM041000 - COMPUTERS / Microprocessors, COM051060 - COMPUTERS / Programming Languages / C, COM067000 - COMPUTERS / Hardware / General
Publisher: Packt
Published: 2020-05-15T08:58:49+00:00


Important notes

Passing by reference can be more efficient than passing by value for moving large data structures around, but several things need to be kept in mind:

Keep the datatypes straight: Because the argument to a queue is of the void* data type, the compiler won't be able to warn you that you're supplying an address to a struct instead of to a pointer.

Keep the queued data around: Unlike passing data by value, when a queue holds pointers to the data, the underlying data passed to the queue needs to stay until it is used. This has the following implications: The data must not live on the stack—no local function variables! Although this can be made to work, it is generally a bad idea to define variables on a stack in the middle of a call chain and then push a pointer onto a queue. By the time the receiving task pulls the pointer off of the queue, the stack of the sending task is likely to have changed. Even if you do get this to work under some circumstances (such as when the receiving task has a higher priority than the sending task), you'll have created a very brittle system that is likely to break in a very subtle way in the future.

A stable storage location for the underlying variable is a must. Global and statically allocated variables are both acceptable. If you'd like to limit access to a variable, use static allocation inside a function. This will keep the variable in memory, just as if it was a global, but limit access to it:



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.