Research on ARM interrupt processing

Publisher:legend8Latest update time:2018-02-21 Source: eefocusKeywords:ARM Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

      The commonly used RISC processor in embedded systems is the ARM core, which has the characteristics of small size, low power consumption, low cost and high cost performance. However, no matter which model of ARM processor is used, and whether there is an operating system in the embedded system, interrupt processing, especially IRQ interrupt, is always necessary, and the core issue of interrupt processing is context preservation. Whether the context can be saved safely and efficiently will affect the performance and stability of an embedded system. The author analyzes and summarizes the context preservation technology of ordinary interrupt processing, task switching interrupt processing, re-entry interrupt processing and priority-based re-entry interrupt processing of ARM processors. To ensure the correctness of the theory, the core program code has been tested experimentally.

 

  1 Introduction to System Interrupt Processing

  There are two main types of interrupts in ARM processors: IRQ normal interrupts and FIQ fast interrupts. Fast interrupts are essentially not much different from normal interrupts, and they have many similarities in processing mechanisms. IRQ interrupts are the most frequent and have the greatest impact on system performance, so their research and processing are the most valuable.
 

  The following is a brief introduction to the working process of the ARM processor when an IRQ exception occurs. When an IRQ interrupt occurs, the hardware of the ARM processor automatically performs the following tasks:

  ①Save the CPSR value of the interrupted task mode to the SPSR register in the IRQ mode;

  ②Save the PC value of the interrupted task mode to the LR register in the IRQ mode;

  ③ Automatically switch the mode to IRQ mode, and set bit7 in CPSR to 1 to disable subsequent IRQ interrupts;

  ④PC is assigned the address value of 0x18, and the program will start executing from 0x18. Combined with Figure 1, we can better understand the working process of the ARM interrupt processing mechanism.

  

IRQ interrupt processing register storage diagram

 

  2 Normal interrupt processing

  Some ARM embedded systems may have relatively low requirements for interrupts, that is, after an interrupt occurs, the corresponding interrupt source is first queried, then the interrupt service is performed, and finally the program is returned from the interrupt service program to the interrupted location to continue running. How to ensure safe and efficient interrupt processing in such a simple application? "Safety" means that the context is intactly saved and not destroyed when an interrupt occurs, and "efficiency" means saving as few registers as possible (of course, it is based on safety). As shown in Figure 1, in ordinary interrupt processing, interrupt service can run in IRQ mode. According to the calling rules of ATPCS, the ARM compiler saves the R4~R11 registers in the subroutine call, so there is no need to save them again. Then the remaining registers must be saved to prevent them from being destroyed after returning from the interrupt service program. The processing code can be written in assembly language and C language.

  First, it is assumed that the IRQ stack has been correctly established in the initialization code.

  

program

 

  

  ; All services will be interrupted at the same time to improve efficiency

  LDMFD SP!, {R0-R3, R12, R14}; Restore context

  There is no need to save the SPSR in the above save context, because in a non-nested interrupt handler, it will not be destroyed by any order of interrupts.

  If you write the handler in C language, you can use the keyword IRQ to tell the compiler to do the following:

  ① Save the destroyed registers specified by ATPCS;

  ②Save registers used in other interrupt handlers;

  ③At the same time, (LR-4) is assigned to the program counter PC to realize the return of the interrupt program and restore the contents of the CPSR register.

  The C language program for ordinary interrupt processing can be written in the following format:

  

program

 

  It can be seen that whether it is written in C language or assembly language, their working principles are the same. Figure 2 shows the schematic diagram of ARM register saving during normal interrupt processing (the dotted line is stack push and save, and the solid line is stack pop and restore). The figure corresponds to the steps of program processing, which can help understand the process of saving the processor context.

  

Normal interrupt processing

3 Task Switching


 

  In embedded systems with operating systems, the occurrence of an interrupt requires saving the contents of all registers to the task stack. This is not based on safety considerations because the interrupt may cause a task switch. When a task switch occurs, the values ​​of all task registers must be saved to the task stack. The context of the next task will be restored from the task stack to the processor registers. The following is an analysis of this issue and the implementation program code is given. From the preservation of interrupt processing registers in Figure 1, it can be seen that after the interrupt occurs, the values ​​of the task's CPSR and PC registers are in the SPSR and LR of the IRQ mode, so it cannot be simply switched to the task running mode, otherwise the CPSR and PC will not be visible when the interrupted task returns (because they are saved in the dedicated registers of the IRQ mode and cannot be operated in other modes). At this time, you can consider setting some variable areas as a medium to transfer them to the stack of the task running mode.

 

  It is assumed that the task switch is executed in SVC mode. Combining the above analysis, we can have the schematic diagram of the save task switch shown in Figure 3 (the dotted line is the stack push save, the solid line is the stack pop restore; LR_Frame and SPSR_Frame are variable areas).

  

Save task switching diagram

 

  Combined with the steps in the task switching interrupt processing in Figure 3, the corresponding interrupt processing program can be written in assembly language:

  

program

 

  

program

 

  4 Reentrancy Interrupts

  If you want to respond to other interrupt requests while processing an interrupt to shorten the interrupt latency, you must design a reentrant interrupt. Reentrant interrupts are a way to handle multiple interrupts, but they also bring new problems. In IRQ interrupt mode, if the IRQ interrupt is directly re-enabled, the return address of the subroutine is saved in LR_irq because a BL instruction is executed, and an interrupt occurs during this time. The new interrupt will load its return address into LR_irq, and the return address of the old interrupt subroutine will be overwritten, causing system disorder. This situation cannot be solved by pushing LR_irq onto the stack, such as the program statement:

  

program

 

  However, the possibility of an interrupt occurring before LR is saved cannot be ruled out. To solve the above problem of LR_irq being destroyed, the processor mode must be switched, and the most common mode is to switch to SVC processing mode. In SVC mode, the return address is saved in LR_SVC when a subroutine is called through BL. At this time, a new interrupt occurs (because it saves the return address to LR_irq instead of LR_SVC), and the subroutine return address in the old interrupt will not be destroyed. With the above principle analysis, the idea of ​​writing reentrant interrupt code is clear. However, in order to ensure the efficiency of processing, interrupts are allowed as early as possible to shorten the delay. After saving LR_irq and SPSR_irq, switch to SVC mode immediately and re-enable interrupts, as shown in Figure 4 (the dotted line is stack push save, and the solid line is stack pop restore).

  

Reentrant interrupt processing context saving diagram

 

  Combined with the processing steps in Figure 4, the assembly language program for reentrant interrupt processing can be written more clearly:

  

program


Keywords:ARM Reference address:Research on ARM interrupt processing

Previous article:Real-time U disk boot technology for embedded systems
Next article:BootLoader Design of ARM+Linux Embedded System

Recommended ReadingLatest update time:2024-11-16 21:36

ARM920T_ kernel und and svc abnormal mode analysis
1. Undefined exception mode 0. When executing undefined instructions, enter und mode and enter the process: The CPU jumps to address 0x4 to execute the code, and automatically saves the CPSR register value to the SPSR register. What we need to do is jump to another code at 0x4, use this code to complete the scene pr
[Microcontroller]
ARM920T_ kernel und and svc abnormal mode analysis
Introduction to ARM single-chip system features and embedded applications
1. Functional block diagram and functional block description EP7209 is the world's first digital audio decoder system-on-chip that supports both the popular MP3 standard and rapidly emerging Internet audio compression standards such as Microsoft Audio. Figure 1 is a functional block diagram of EP7209. As ca
[Microcontroller]
Design of portable multi-parameter gas detector for mines based on ARM
0 Preface During the mining process of coal mines, a large amount of toxic and harmful gases and flammable gases, such as CH4, CO, and H2S, will be released. When these gases accumulate to a certain concentration, it will cause breathing difficulties, suffocation and death, and even cause gas explosion accidents, se
[Microcontroller]
Design of portable multi-parameter gas detector for mines based on ARM
Communication interface design of ARM/DSP dual-core system
Introduction The core of embedded systems is embedded microprocessors and embedded operating systems. The hardware core of early embedded systems was various types of 8-bit and 16-bit single-chip microcomputers; in recent years, 32-bit processors have been widely used for their high performance and low price.
[Microcontroller]
Communication interface design of ARM/DSP dual-core system
6. ARM addressing mode
The addressing mode is for the source operand. 6.1 Immediate addressing The source operand is an immediate value Immediate number: The number starting with the # sign in the opcode is the immediate number. Immediate addressing: MOV R0, #0x300 Pseudo-instruction: LDR R0,=0x12345678 Notice: The immediate data is
[Microcontroller]
6. ARM addressing mode
Mobile Video Surveillance System Based on ARM
0 Introduction Traditional video surveillance systems generally adopt the C/S (Client/Server) structure of PC servers. The video server consists of a computing host and many disk arrays for storing videos, which is specially used for video storage and transmission. Streaming transmission adopts the principle of
[Microcontroller]
Mobile Video Surveillance System Based on ARM
Design of Embedded Network Interface Controller Based on ARM
1 Introduction As the most widely used local area network technology, Ethernet has been increasingly used in the fields of industrial automation and process control. Traditional control systems mostly use Ethernet in the information layer, while different fieldbuses or other dedicated networks are generally use
[Microcontroller]
Design of Embedded Network Interface Controller Based on ARM
Two boot modes of ARM (NAND FLASH. NOR FLASH)
Why are there two startup methods? This is determined by the different characteristics of the two types of FLASH. NAND FLASH has a large capacity and the cost of storing unit bit data is much lower, but NAND FLASH must be read and written according to a specific timing, so the CPU cannot directly address the data i
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号