1.5.1 Exception and Interruption_Concept Introduction and Processing Flow

Publisher:EtherealMelodyLatest update time:2021-08-10 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The MCU normally runs in user mode, that is, in the main function we wrote. However, when some exceptions occur, such as incorrect instructions, data access problems, or reset and other abnormal situations, the CPU will enter a special mode for exception handling.

insert image description here

For example, we want to turn on the LED light when a button is pressed. If we poll the button status in the program, there may be a detection delay. The button is pressed but the program has not yet executed to the point where the button status is queried. By the time the program is executed, the button has been released, so we cannot achieve the desired effect.


In order to respond immediately, there is an exception in the MCU hardware, called interrupt. We can configure the button pin as an external interrupt pin. When the button is pressed, it enters the corresponding interrupt service program, changes the flag bit in the subroutine, processes it in the main program, and lights up the LED.


Before entering the interrupt service routine, we need to save the original program status, mainly the register status, and then jump to the interrupt service routine for processing. After processing, we need to jump back to the original program to continue running. Therefore, the interrupt handling process is as follows:


Save the scene (save various registers);

Call the handler (to handle the interrupt/exception);

Restore the scene (return to the original program and continue execution).

ARM's use of interrupts/exceptions:


First, you need to initialize: a. Set the interrupt source so that it can generate an interrupt; b. Set the interrupt controller (set whether to block, set the priority, etc.); c. Enable the interrupt master switch;

The interrupt is not triggered, so other programs are executed first;

An interrupt is generated, such as pressing a key. The interrupt controller will receive the signal, and then the interrupt controller will send a signal to the CPU;

After each instruction is executed, the CPU will detect whether an interrupt/exception occurs (this function is implemented by hardware);

Detect an exception/interrupt and start processing. For different exceptions, the CPU will jump to different addresses (exception vectors, there is an exception vector table) to execute the program; (at these addresses, there is only a jump instruction to jump to execute other functions. These functions need to save the scene, handle the exception (interrupt) and call the processing function to restore the scene).


The exception vector table of 2440 is as follows:

insert image description here
insert image description here

So, how to call the interrupt function?


Answer: I won’t say much, it’s very basic and you can understand it by looking at the pictures.

insert image description here

Reference address:1.5.1 Exception and Interruption_Concept Introduction and Processing Flow

Previous article:1.4.3 Relocation_Clearing the BSS segment using C language
Next article:1.5.2 Exceptions and Interrupts_CPU Mode_State and Registers

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号