2. Under normal circumstances, ensure that this sub-function (and the functions called by this sub-function) are not called by other functions.
3. If this sub-function does need to be called by other functions, make this sub-function a re-entrant function.
* All problems with calling sub-functions in interrupts are caused by the re-entrant function problem.
Function: Screen display positioning show_sit
******************************************/
void show_sit(uchar screen,uchar row,uchar x_sit,uchar y_sit)reentrant{
}
Note: reentrant Keyword
================The following comes from the Internet and I think it’s very good========================
1) What is reentrancy?
Reentrant functions can be used concurrently by more than one task without worrying about data errors. In contrast, non-reentrant functions cannot be shared by more than one task unless mutual exclusion of the function is ensured (either by using semaphores or disabling interrupts in critical sections of the code). Reentrant functions can be interrupted at any time and resumed later without losing data. Reentrant functions either use local variables or protect their own data when using global variables.
2) Reentrant functions:
Do not hold static data for consecutive calls.
Do not return pointers to static data; all data is provided by the caller of the function.
Use local data or protect global data by making local copies of global data.
If you must access global variables, remember to use mutual exclusion semaphores to protect global variables.
Never call any non-reentrant functions.
3) Non-reentrant functions:
Static variables are used in the function, whether they are global static variables or local static variables.
The function returns static variables.
Non-reentrant functions are called in the function.
The function body uses static data structures;
the function body calls malloc() or free() functions;
the function body calls other standard I/O functions.
The function is a member function of a singleton and uses member variables that do not use thread-independent storage.
In general, if a function uses unprotected shared resources under reentrant conditions, it is not reentrant.
Mainly used in a multi-tasking environment, a reentrant function is simply a function that can be interrupted, that is, it can be interrupted at any time when it is executed, and transferred to the OS schedule to execute another section of code, and no errors will occur when returning control; non-reentrant functions use some system resources, such as the global variable area, interrupt vector table, etc., so if it is interrupted, problems may occur, and this type of function cannot run in a multi-tasking environment.
It can also be understood that reentry means repeated entry. First, it means that the function can be interrupted. Second, it means that it does not rely on any environment (including static) except for using the variables on its own stack. Such a function is purecode (pure code) reentrant, which allows multiple copies of the function to run. Since they use separate stacks, they will not interfere with each other. If you really need to access global variables (including static), you must pay attention to the implementation of mutual exclusion. Reentrant functions are very important in a parallel running environment, but generally you have to pay some performance cost for accessing global variables.
When writing a reentrant function, if global variables are used, they should be protected by disabling interrupts and semaphores (i.e. P, V operations).
Example: Assume Exam is a global variable of type int, and the function Squre_Exam returns the square of Exam. Then the following function is not reentrant.
unsigned int example( int para )
{
--------------------------------------------------
Previous article:Frequency and Duty Cycle
Next article:Differences between embedded C, standard C, and single-chip C
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Melexis launches ultra-low power automotive contactless micro-power switch chip
- Molex leverages SAP solutions to drive smart supply chain collaboration
- Pickering Launches New Future-Proof PXIe Single-Slot Controller for High-Performance Test and Measurement Applications
- Apple faces class action lawsuit from 40 million UK iCloud users, faces $27.6 billion in claims
- Apple faces class action lawsuit from 40 million UK iCloud users, faces $27.6 billion in claims
- The US asked TSMC to restrict the export of high-end chips, and the Ministry of Commerce responded
- The US asked TSMC to restrict the export of high-end chips, and the Ministry of Commerce responded
- ASML predicts that its revenue in 2030 will exceed 457 billion yuan! Gross profit margin 56-60%
- Detailed explanation of intelligent car body perception system
- How to solve the problem that the servo drive is not enabled
- The SDA and SCL of this clock IC can be connected to the MCU's normal IO! Does the 7th pin have to be connected to the interrupt port? If the MCU interrupt port...
- E1 can be burned on PCB using RFP software, but simulation connection cannot be made
- Considerations for selecting solid-state relays
- Download and get a gift: Explore 5G together and win a surprise~
- Motor drive control popular data download collection
- Pingtouge RVB2601 board initial evaluation
- PLC electrical automation training
- I was sorting out my drawers and saw this...
- AG9311DEMO board circuit design schematic diagram | PD TYPE-C to HDMI solution design principle question
- [Program source code] Freescale MAPS-K64 development board program example