Abstract Mainly explain the accumulation of Internet of Things technology. After learning the first episode of serial port, I believe everyone has a general understanding of the application of the entire development board. This issue will explain the second episode of interrupts. This article starts from the definition, meaning and interrupt handling process of interrupts. , Classification, and interrupt examples to introduce interrupts, I hope it will be helpful to you.
1 What is an interrupt?
Let's take an example. It takes 5 minutes for Xiao Ming to boil water with gas in the kitchen. The main actions include receiving water, turning on the gas, waiting for the water to boil, and turning off the gas. While waiting for the water to boil, the courier came to deliver the courier, and Xiao Ming opened the door to sign for it. In this series of actions is an interruption process. details as follows;
(1) Xiao Ming: CPU
(2) Boiling water: main program
(3) Doorbell ringing: interrupt signal
(4) Open the door and find that it is express: check the interruption number
(5) Signing for express delivery: interrupt processing procedure
(6) Continue to boil water after signing for the courier: interrupt return
The so-called interrupt is the process in which the CPU is interrupted by some event during the execution of the main program, and then processes the event, and then continues to execute the main program after the processing.
2 Why is it interrupted?
Recalling the above example, because of the interrupt mechanism, Xiao Ming can handle multiple tasks at the same time, which improves its concurrent processing capabilities. The same is true for computers, which can improve the processing efficiency of the CPU. Of course, the advantages of interruption are more than that.
3 interrupt processing
(1) Save the scene
(2) Execute interrupt service routine
(3) Return from interrupt service
(4) Reply to the scene
Specific as shown in Figure 1
Figure 1 Interrupt processing flow chart
4 Classification of interrupts
(1) Non-maskable interrupt: Once a request is made, the CPU must respond unconditionally.
(2) Maskable interrupt: When a request is issued, the CPU can respond or not. In addition to being controlled by its own mask bit, there is also a general control, that is, the control of the interrupt enable flag (IF) in the CPU flag register. If the IF bit is 1, the CPU can respond, otherwise it will not respond.
5 GD32450i-EVAL interrupt/event controller (EXTI)
(1) GD32450i-EVAL integrates Cortex-M4. Cortex-M4 integrates a nested vector type interrupt controller to achieve efficient exception and interrupt handling. EXTI includes 23 independent edge detection circuits and can generate interrupt requests or wake-up events to the processor core. It provides three trigger types: rising edge, falling edge, and any edge trigger. Each edge detection circuit can be independent Configuration and shielding.
(2) Cortex-M4 set and nested vector interrupt controller prioritize and process all exceptions in processing mode. When an exception occurs, the system automatically pushes the current processor working state onto the stack, and automatically pops it out of the stack after the interrupt service routine is executed. Fetching the vector and pushing the stack in the current working state are carried out in parallel, thereby improving the efficiency of the interrupt entry. The processor supports tail biting interrupts, which can realize back-to-back interrupts, which greatly reduces the overhead caused by repeatedly switching the working state.
(3) EXTI trigger sources include 16 wires from I/O pins and 7 wires from internal modules. By configuring the SYSCFG_EXTISSx register, all GPIO pins can be selected as the trigger source of EXTI.
(4) The SysTick calibration value is set to 25000, and the SysTick frequency is always configured as HCLK/8. At this time, if the HCLK clock is configured as 200MHz, the SysTick interrupt will respond once every 1ms.
6 Interrupted initialization process
(1) Enable IO clock and configure I/O as input mode
gpio_mode_set(KEY_PORT[key_num], GPIO_MODE_INPUT, GPIO_PUPD_NONE,KEY_PIN[key_num]);
(2) Turn on the syscfg clock
(3) Set the mapping relationship between IO and interrupt line
(4) Configure NVIC and enable interrupt
nvic_irq_enable(KEY_IRQn[key_num], 2U, 0U);
(5) Initialize EXIT and select the corresponding trigger mode
exti_init(KEY_EXTI_LINE[key_num], EXTI_INTERRUPT, EXTI_TRIG_FALLING);
(6) Set interrupt handling function
Through the above steps, the interrupt response to the button is realized. Since the GPIO default state is low, the button is pulled to the high level after being pressed, and the system can detect the interrupt and determine that the button is pressed. When the Tamper button is pressed, the corresponding LED lights up, and goes out when it is pressed again. The method is relatively simple), the specific development board response is shown in the figure below. The call of the callback function can be seen in the interrupt vector table in the startup file.
Figure 2 LED lights off
Figure 3 LED lights are on
Author: Star 27