How is this process implemented? Let's learn with questions!
The SWI instruction includes a 24-bit immediate value (interrupt call number), which indicates the specific call function that the user wants to request. Therefore, in the SWI exception interrupt, the interrupt call number must be read, and then the corresponding handler is called according to the interrupt number. This process can be divided into two steps:
1. SWI exception interrupt handler
Since it is operated at the bottom level, this exception interrupt handler must be written in assembly language, as described below:
area top_swi code readonly
export swi_headler
swi_headler
stmfd sp!, {r0-r12, lr} ; Save the register values from r0 to r12, lr
ldr r0, [lr, #-4] ; Get the address of the SWI instruction from the memory
bic r0, r0, #FF000000 ; Read the 24-bit interrupt call number
mov r1, sp
;===================================================
bl swi_service_func ; Call the function service function, see below
; The interrupt call number is passed in through the r0 register
; Parameters are passed in through register r1
;==================================================
ldmfd sp!, {r0-r12, pc}^ ; Restore r0 to r12 before the call, and leave the interrupt handler
end
2. Function service program
Write Using the interrupt call number obtained from the interrupt handler, we can write the following service function (for simplicity, we use C language)
void swi_service_func(unsigned int number, unsigned int *reg)
{
unsigned int reg1, reg2, reg3, reg4;
//Get the parameters passed in before SWI
reg1 = reg[0];
reg2 = reg[1];
reg3 = reg[2];
reg4 = reg[3];
switch (number) {
case 0:
// do something
break;
case 1:
// do something
break;
.
.
.
case n:
// do something
break;
default:
// do something
}
}
// Store the updated result in r0-r3
reg[0] = updata_reg1;
reg[1] = updata_reg2;
reg[2] = updata_reg3;
reg[3] = updata_reg4;
}
In this way, as long as the call break number is different, different function calls can be implemented. Isn’t it simple?
Previous article:Analysis of return address of ARM processor exception handling
Next article:ARM interrupt exception handling return
Recommended ReadingLatest update time:2024-11-16 22:47
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Thank you for your company in my spare time
- NXP imx8m series product data sheet (based on Mir MYD-JX8MX)
- Serial communication between Matlab and microcontroller
- CC2640 Software Architecture
- When installing the emulator in CCS, a prompt appears saying that the bh2usb.sys file is needed. Solution
- Discussion on unit conversion (repost)
- GD32L233C running RT-Thread Nano
- Common FPGA debugging techniques
- [ESP32-S2-Kaluga-1 Review] Use of the console component
- Communication failure