#define pISR_EINT0 (*(unsigned *) (_ISR_STRATADDRESS+0x74))
The above statement casts the unsigned integer _ISR_STRATADDRESS+0x74 to a pointer to RAM, which can be accessed using the following statement:
pISR_EINT0 = (int)Eint0_ISR
To access an absolute address, typecast an integer to a pointer.
2. __irq:
In order to facilitate the use of high-level languages to write exception handling functions, the ARM compiler has made specific extensions to the exception handling functions. As long as the keyword _irq is used, the compiled function will meet the needs of exception response for scene protection and recovery.
3. Some basic principles for writing interrupt service routines:
√ Avoid doing floating-point operations in interrupt service routines: A good terminal reading program should follow the principle of being short and effective. Doing floating-point operations in interrupt service routines greatly violates this principle. At the same time, some processors/compilers do not allow floating-point operations in interrupt service routines.
√ The interrupt service routine cannot have a return value: Therefore, the interrupt service routine is defined as a return type of void, that is: void _irq Eint0_ISR(void);
√ The interrupt service function cannot pass parameters: so the parameter list is void, that is: void _irq Eint0_ISR(void);
4. Static:
A static variable is actually a global variable, but it has a scope. It can be used to save the intermediate state of the function where the variable is located during the call of the class, for example:
int cCout()
{
Static int loop = 0;
.......
loop++;
.......
}
The value of the loop variable will increase with the number of times the function is called. After the function exits, the value of loop still exists, but loop can only be accessed within the function (function scope), and the memory space of loop will only be allocated and initialized when the function is called for the first time. Each subsequent entry into the function will not allocate static, but directly use the last value. Within a module, a function declared as static can only be called by other functions within the module, and other functions outside the module cannot access it. It is a local global variable.
5. Constant:
If a variable or object is defined as a constant type, it cannot be updated after the definition (readable but not writable), that is, an initial value must be given to it when defining or describing the type.
Several points to note:
√ If const is on the left side of the asterisk (*), then const modifies the variable pointed to by the pointer, that is, the pointer points to a constant; such as: const int *a; or int const *a; These two situations are the same (the position of cost in the variable declarator does not matter). The pointer points to a constant and the content cannot be changed at this time, that is, there cannot be a write operation statement *a=3;
√If cost is on the right side of the model, cost is used to modify the pointer itself, that is, the pointer itself is a constant; for example: the statement int* const a; indicates that the pointer itself is a constant, but the content it points to is not a constant, that is, a++ is wrong.
√If there are const modifiers on both sides of the asterisk, such as: const int* const a;, it means that the pointer itself and the content pointed to by the pointer are both constants.
6. Volatile:
To define a volatile variable, the compiler has a technology called data flow analysis, which analyzes where the variables in the program are assigned, where they are used, and where they are invalidated. The analysis results can be used for optimizations such as constant merging and constant propagation. When the compiler checks that the code does not modify the value of the field, it is possible to provide the cache value of the last access when you access the field, which can improve the efficiency of the program, but sometimes these optimizations will cause problems and are not what our program needs. The characteristic is that the program operates on hardware registers. At this time, the volatile keyword can be used to prohibit these optimizations.
When to use volatile variables:
√Hardware registers are usually marked volatile because each read or write to them may have a different meaning;
√ Variables modified in the interrupt service program for detection by other programs need to be declared volatile; otherwise the compiler may update the variable once and then use the cached value each time without updating immediately;
√ Flags shared between tasks in a multitasking environment should be marked with the volatile keyword: When multiple threads access a field, the code hopes that these accesses can operate (read) the latest value of the field, and the operation of writing to the variable can be updated immediately; add the volatile keyword to the field, then any request (read/write) to the field will be executed immediately.
Previous article:The concept of ARM code domain and segment
Next article:ARM and 51 MCU communication
Recommended ReadingLatest update time:2024-11-16 13:42
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- How to self-test the fault of resistor parallel circuit?
- Single-supply applications
- Share a problem of MOS tubes being frequently damaged.
- A summary of DIY blood oximeters. It is really rewarding to read it.
- CMOS Analog Integrated Circuit Design and Simulation.pdf
- How to enter debugging without hardware in MDK5
- How many computer screens do you usually use?
- [National Technology N32G457 Review] 9 RT_Thread Studio drives CAN and the difficult journey of filling the pit!
- The first time I played with FPGA applications, I played with the TSL1401 linear array sensor
- MKI109V3+MKI182V2 unboxing