Almost all programming languages have exceptions, and you can say that there are exceptions to the program. Today to learn about arm interrupt (Exception) processing, Lenovo to Java exceptions, hardware, how to implement the problem, the following for everyone to share.
one, arm's interruption.
1. Triggering an exception
2. Save the scene
3.CPU enters abnormal operation mode, program pointer (PC) jumps into exception entry (code address to handle exception)
A. Distinguishing the interrupt source
B. Perform logical processing
C. Clean-up work
4. Recovery site
Flowchart (from the 2440 data sheet) is as follows:
The working mode here, in fact, is that the CPU has a different set of registers under different circumstances. With different registers, the program can switch back and forth in different states. Such as:
The assembly code for the interrupt example is as follows:
b Reset
@****************** a bunch of setup codes have been omitted ************************************************* Reset:
Ldr sp, = 4096 @ Set the stack pointer, the following are C functions, need to set the stack before calling
BL Disable_watch_dog @ off watchdog, otherwise the CPU will continue to restart
MSR Cpsr_c, #0xd2 @ into break mode, the first two bits of D are 11, meaning that all interrupts are turned off
Ldr sp, = 3072 @ set interrupt mode stack pointer
MSR Cpsr_c, #0xd3 @ Enter management mode
Ldr sp, = 4096 @ Set the management mode stack pointer,
After reset, the CPU is in management mode,
The "Ldr sp, = 4096" At the front of the @ completes the same function, this sentence can be omitted
BL init_led @ gpio pins for initializing LEDs
BL INIT_IRQ @ Call interrupt initialization function, in init.c
MSR Cpsr_c, #0x53 @ set i-bit=0, IRQ interrupt
Ldr LR, =halt_loop @ set return address
LDR pc, =main @ call main function
Halt_loop:
b halt_loop
@ Interrupt function
HANDLEIRQ:
Sub LR, LR, #4 @ calculates the return address, as defined by the ARM architecture
Stmdb sp!, {R0-R12,LR} @ Save the register used, save the scene
@ Note that the SP at this time is the interrupt mode SP
The @ initial value is set above 3072
Ldr LR, =int_return @ Sets the return address after calling the ISR, which is the Eint_handle function
LDR pc, =eint_handle @ Call Interrupt service function, in interrupt.c
Int_return:
Ldmia sp!, {r0-r12,pc}^ @ interrupt return, ^ = copy spsr value to CPSR
The implementation of the Eint_handle function is to judge the button and then point the corresponding light, I do not copy the code here.
The source of MSR cpsr_c instruction values (from the full manual of embedded Linux application development):
second, the exception in Java, very simple.
try{
}catch (Exception e) {
}finally{
}
Do not care about what mode of operation, the code hit in the catch is executed, the code in the finally will be executed. Just write according to your own logic.
Interrupts in Java, thread has a interrupt method, but calling this method does not know what state the thread will break in, I have not used this way. If I need to interrupt, I usually write a state variable, and in the while I judge the interrupt state to do the processing.
third, the hardware implementation is interrupted.
Switches can be implemented with relays, such as:
The switch can be switched by a little voltage on the coil, which can trigger the switching of the working mode.
Smart Car 37: Exception in arm, JAVA, hardware implementation