1. Access the memory location of the absolute address:
#define pISR_EINT0 (*(unsigned *) (_ISR_STRATADDRESS+0x74))
The above statement casts the unsigned integer _ISR_STRATADDRESS+0x74 to a pointer, pointing to RAM, and then retrieves the instance pointing to the address. The following statement can be used to access it:
pISR_EINT0 = (unsigned int)Eint0_ISR, the address of the instance pointing to the address points to a function address that is cast to U32bit.
In order to access an absolute address, cast 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.
√ Interrupt service routines cannot have return values: Therefore, interrupt service routines are defined as returning types of void, that is: void _irq Eint0_ISR(void);
√ Interrupt service functions cannot pass parameters: Therefore, 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. For example:
int cCout()
{
Static int loop = 0;
.......
loop++;
.......
}
The value of the loop variable will increase with the number of calls to the function. After the function exits, the value of the loop still exists, but the loop can only be accessed in the function (function scope), and the memory space of the loop will only be allocated and initialized when the function is called for the first time. Each time the function is entered, it will not be allocated for static, but directly use the last value. In a module, a function declared as static can only be called by other functions in this module. Other functions outside the module have no access to 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 when defining or describing the type.
Several points to note:
√ If const is on the left side of the asterisk (*), 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 location of cost in the variable declarator is irrelevant), 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 modifies the pointer itself, that is, the pointer itself is a constant; such as: int* const a; statement indicates that the pointer itself is a constant, and 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 it points to are both constants.
6. Volatile:
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.
Occasions for using volatile variables:
√ Hardware registers usually need to be declared volatile, because each read and 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 use the cached value each time without updating it immediately;
√ Flags shared between tasks in a multi-tasking environment should be added 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, and any request (read/write) to the field will be executed immediately.
Previous article:Relationship between FCLK, HCKL and PCLK
Next article:Memory management mechanism of s3c2440
- 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
- Microchip Accelerates Real-Time Edge AI Deployment with NVIDIA Holoscan Platform
- Microchip Accelerates Real-Time Edge AI Deployment with NVIDIA Holoscan Platform
- Melexis launches ultra-low power automotive contactless micro-power switch chip
- 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
- Smooth configuration of bq4050
- Clock Oscillator Circuit Analysis
- pcb welding video
- Update pyboard firmware using STM32CubeProgrammer
- Battery Characteristics Analysis and Design Scheme in Smart Home
- Technical Title
- CS83702 single lithium battery 3.7V power supply built-in boost 18W mono class D amplifier IC
- 【Renovation of old things】 Graffiti desk lamp——lugl4313820
- Share the silkscreen search method of TI device models
- Some thoughts on the development of embedded technology