There are many things to learn about ARM, and interrupts are definitely something that needs to be learned. Since the CPU introduced interrupts, we have truly entered the multi-tasking system and greatly improved work efficiency. Interrupts take up less CPU time than previous query methods, allowing the system to provide better performance. So what are interrupts like in S3C44B0? How do you respond when developing ARM programs? This is what I need to learn.
After checking the manual of S3C44B0, I found that it has 7 working modes, each of which is different. The most commonly used ones are SVC and IRQ modes. Before using the interrupt, you must initialize the stack pointer SP of each mode. If you do not initialize it, you will definitely get an error. When the CPU is initialized, you need to enter the IRQ mode in turn, initialize SP, and then enter the SVC mode to initialize SP. In this way, these two modes can be used. Then initialize the IRQ interrupt handler in the interrupt table of S3C44B0. This code is used to call different interrupt subroutines according to different interrupt bits.
For interrupt subroutines written in C language, some specific modifiers must be added, otherwise the C compiler will not generate a program suitable for running in interrupt mode. Since I don't know much about GCC, I debugged it for several days and found that the interrupt handler I wrote did not return. The reason is that without these interrupt modifiers, the GCC compiler did not generate a suitable return instruction. When I added the following:
void Eint4567Isr(void) __attribute__ ((interrupt ("IRQ")));
After the modification, a suitable interrupt handler will be generated. GCC will compile it into the following code:
sub lr, lr, #4 ;
stmdb sp!, {r0, r1, r2, r3, r4, ip, lr}
......
......
ldmia sp!, {r0, r1, r2, r3, r4, ip, pc}^
Since returning from IRQ mode to SVC mode requires LR to be reduced by 4, it is the instruction of PC. If the above interrupt modifier definition is not added, such code will not be generated, and such function cannot be used for interrupt processing.
Of course, I also compiled these codes, disassembled them, and found that they were different. Then it can also be achieved through embedded assembly. For example:
void foo(void)
{
asm volatile ( "sub lr, lr, #4" );
asm volatile ( "stmdb sp!, {r0, r1, r2, r3, r4, ip, lr}" );
......
......
asm volatile ( "ldmia sp!, {r0, r1, r2, r3, r4, ip, pc}" );
return;
}
Originally, before I found this definition, I manually added the above code to achieve it. This interrupt code taught me how to handle interrupts, from SVC to IRQ mode, and then from IRQ mode back to SVC mode. As long as I move from LR to PC, it will automatically switch back to SVC mode.
By looking up the GCC help documentation, the following link:
http://gcc.gnu.org/onlinedocs/gcc-4.0.0/gcc/Function-Attributes.html , you can see the interrupt function declaration in GCC.
5.24 Declaring Attributes of Functions
Variable Attributes ) and for types (see Type Attributes ).
You may also specify attributes with `__' preceding and following each keyword. This allows you to use them in header files without being concerned about a possible macro of the same name. For example, you may use __noreturn__ instead of noreturn.
See Attribute Syntax , for details of the exact syntax for using attributes.
Then look at its interrupt function declaration:
-
interrupt
-
Use this attribute on the ARM, AVR, C4x, M32R/D and Xstormy16 ports to indicate that the specified function is an interrupt handler. The compiler will generate function entry and exit sequences suitable for use in an interrupt handler when this attribute is present.
Note, interrupt handlers for the m68k, H8/300, H8/300H, H8S, and SH processors can be specified via the interrupt_handler attribute.
Note, on the AVR, interrupts will be enabled inside the function.
Note, for the ARM, you can specify the kind of interrupt to be handled by adding an optional parameter to the interrupt attribute like this:
void f () __attribute__ ((interrupt ("IRQ")));
Permissible values for this parameter are: IRQ, FIQ, SWI, ABORT and UNDEF.
In addition to using the IRQ interrupt method, you can also write FIQ, SWI, ABORT, and UNDEF interrupt processing functions.
Previous article:Learn ARM development(17)
Next article:最后一页
- 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
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- Switching Power Supply SPICE Simulation and Practical Design
- Analyzing the basic steps of FPGA power supply design
- [RVB2601 Creative Application Development] Audio Playback
- MSP430F5529&LCD1602 Program
- Bluetooth Direction Finding Technology Overview
- Problems affecting IC card reading distance
- How to design hollow fonts
- dB, why is it so important for RF engineers?
- [New Year's Flavor Competition] + Show off your New Year's Eve dinner and see where the Coke is. If you find it, you win a prize!
- 【RPi PICO】Calculate Mandelbrot Improved Version