Only after paying money and being forced to learn, will you work hard to study it. It's really cheap.
I knew before that arm has 7 basic working modes:
FIQ, IRQ enter by interruption,
UNDEF, ABORT enter by program exception,
SVC enter by power-on and soft interrupt
, user enters by SVC handler
But there is also a system, which uses the same registers as user, but does not have SPSR, and can also execute privileged instructions
Such an alternative, it is not safe for OS to use it as user, and there is no automatic entry method when it is used as an exception or interrupt It is awkward
no matter how you look at it, of course, this is also realized after understanding, system is used to solve the problem of reentrant interrupts in arm
I searched and found that there is only one explanation about reentrant interrupts in arm on the Internet, and it does not consider it completely http://blog.chinaunix.net/u1/58640/showart_513501.html
The default interrupt handling function will push lr to the stack first, this article does not consider this point, and thinks the damage is serious
Such theoretical knowledge is rarely used in practice. Only those who pursue professionalism will delve into it, so that they can meet special requirements and do things that ordinary people cannot do.
First of all, the armcc keyword __irq cannot be used to write reentrant interrupts.
When the interrupt is reentrant, use BL to call the sub-function in the interrupt handling function. At this time, the problem comes. There are two situations.
If the sub-function is not declared in the __irq way and does not have the habit of pushing lr on the stack, then if there is another irq interrupt at this time, lr_irq will be flushed by the new value
, and it will fall into an endless loop.
If the sub-function is a good kid who will actively push lr on the stack, then only when the instruction of pushing lr is executed, the irq interrupt will cause the above problem, but the conditions for triggering the problem become very harsh.
So, at this time, the system mode is needed to save the world.
To write a reentrant interrupt, you must use the following assembly code
IRQHandler
;LR_IRQ ,SPSR_IRQ,r12 is pushed onto the stack to prevent the next IRQ interrupt from flushing it
sub lr,lr,#4
stmfd sp!,{lr}
mrs r14,spsr
STMFD sp!,{r12,r14}
; Read and clear interrupt controller interrupt source
; omit related code
mov r12,#IntBase
LDR r12,[r12,#IntSource]
;Switch to system mode and enable IRQ
mrs r14,cpsr
bic r14,r14,#0x9f
orr r14,r14,#0x1f
msr CPSR_c,r14
;Save r0-r3,LR_user to the user stack, then call the c subroutine, and pass the interrupt source r0 as a parameter to the c processing function
BL C_irq_handler;Looking at the name, you know that this c program is declared in the __irq form
; it is a good kid who can push LR on the stack by itself
LDMFD sp!,{r0-r3,lr}
;Switch to IRQ mode and disable IRQ
mrs r12,cpsr
bic r12,r12,#0x1f
orr r12,r12,#0x92
msr CPSR_c,r12
;Restore LR_irq, SPSR_irq and working register r12, then exit IRQ
LDMFD sp!,{r12,r14}
msr SPSR_csxf,r14
LDMFD sp!,{PC}^
Previous article:Nestable IRQ routines in traditional ARM
Next article:The role of R0-R15 registers in arm
Recommended ReadingLatest update time:2024-11-15 16:36
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
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- Using LTC2380 as a data acquisition card, the data jumps greatly
- EEWORLD University Hall ---- Low-speed ADC Hardware Trio
- Three failure modes of high-voltage connectors for new energy vehicles
- Is it necessary to take a shower for 10 minutes after a burn?
- Sensor Problems
- Latest solutions specifically for battery test equipment, 5G test equipment
- DCDC input capacitance waveform
- If anyone is willing to help improve the size of the building block library, we can share the profits in the future.
- EEWORLD University Hall ---- The second stop of the ADI Road theme tour of Shijian: Instruments
- The features of the SCI module are as follows (these functions can be set through the corresponding registers)