Learn to drive 18--interrupts yourself

Source: Internet
Author: User

1. Interrupt principle
When an event occurs, the hardware sets a register, and when the CPU executes an instruction, it looks at the register through hardware, interrupts the current program flow, jumps to a fixed address to handle the event, and then resumes execution of the interrupted program if it finds that the event of interest has occurred.

2. Interrupt Handling Process
(1) The interrupt controller collects interrupt signals from various peripherals and tells the CPU.
(2) The CPU saves the running environment of the current program (each register, etc.) and calls the Interrupt Service program (Isr,interrupt service Routine) to handle these interrupts.
(3) in the ISR by reading the interrupt controller, the peripheral register to identify which interrupt, and the corresponding processing.
(4) Clear interrupt: Through the read-write interrupt controller and peripheral related registers.
(5) Finally restore the operating environment of the interrupted program, continue to execute.


3. Steps to use interrupts
(1) Set the interrupt mode and the fast interrupt mode stack: When interrupt IRQ occurs, the CPU goes into interrupt mode, then the stack is used in interrupt mode (IRQ), when the fast interrupt Fiq occurs, the CPU goes into fast interrupt mode, then the stack in fast break mode is used.
(2) Prepare the interrupt handler function:
Set the jump function in the exception vector table when entering break mode or fast break mode;
For IRQ, read the value of the INTPND register or the Intoffset register to determine the source of the interrupt, and then handle it separately, for Fiq, because only one interrupt can be set to Fiq, you do not need to judge the interrupt source;
Clear interrupt, clear interrupt should start from the source, first, if necessary, the operation of specific peripherals to clear the interrupt signal, and then clear the SUBSRCPND, SRCPND register the corresponding bit (to the corresponding bit write 1), and finally, clear the corresponding bit in the INTPND register (to the corresponding bit write 1), The simplest approach is "INTPND = INTPND".
(3) When entering or exiting an IRQ or FIQ, the running environment of the interrupted program needs to be saved and resumed.
(4) According to the specific interruption, set up the relevant peripherals.
(5) for interrupts in "Request sources (without sub-register)", set the corresponding bit in the Intsubmsk register to 0.
(6) Determine how to use this interrupt: Fiq or IRQ.
If Fiq, the corresponding bit is set to 1 in the INTMOD register;
If it is an IRQ, the priority is set in the Riority register.
(7) If IRQ, the corresponding bit in the INTMSK register is set to 0 (Fiq is not controlled by the Intmsk register).
(8) Set the I-bit in the CPSR register to enable IRQ or Fiq.

Learn to drive 18--interrupts yourself

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.