|
|||||||||||
Technical Support Support Resources
Product Information |
RTX51: Reentrant FunctionsInformation in this article applies to:
QUESTIONHelp. I'm really confused by reentrant function in RTX51. My RTX51 manuals say that reentrant functions only work in the COMPACT memory model. However, many of the library routines are reentrant even in the SMALL and LARGE models. ANSWERFrequently, there is confusion over the difference between reentrant functions and functions that are reentrant. There are two distinct meanings of the word reentrant. In C51, you may declare functions using the reentrant keyword. For example:
This is a reentrant function that is declared using the reentrant keyword. The arguments (a, b, and c) and local variables (x, y, and z) are stored on a simulated stack in PDATA (the COMPACT memory model). If we did not specify COMPACT in the function declaration, the arguments and local variables would be stored in DATA, PDATA, or XDATA memory (depending on the default memory model -- SMALL, COMPACT, or LARGE). These functions are called reentrant functions. There are functions that, by their nature, are reentrant. These functions use only registers for arguments and local variables and are typically written in assembly. Many of the library routines in the C51 library are written this way. They are, therefore, functions that are reentrant, but they are not declared using the reentrant keyword. These functions are simply functions that are reentrant. In RTX51, you may only use the SMALL or LARGE memory model. The COMPACT memory model is not allowed for normal functions. It is REQUIRED, however, for reentrant functions. If you invoke library routines from multiple tasks, you must ensure that they can be re-entered. That means that either A) these routines only use registers (and are marked in the library section of the manual as functions that are reentrant) or B) you protect the non-reentrant routines with a semaphore. A library call that is included in a reentrant function is NOT reentrant. Routines that you write and call from multiple tasks must either A) be declared as reentrant functions like example 1 above using the COMPACT memory model (because that's all that RTX51 supports for reentrant functions), or B) be reentrant by nature by only using registers and not any fixed memory locations. SEE ALSO
Last Reviewed: Thursday, February 25, 2021 | ||||||||||
|
Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.