Arm interrupt Analysis 2: interrupt handling on bare metal

Source: Internet
Author: User

Bare metal handling of eint4 interruptions

This is the bare metal processing of eint4 interrupt based on S3C2410. When the interrupt occurs, the LED light is reversed. The following is a circuit diagram.

The external key is connected to the eint4 pin of the CPU. That is, pressing the key causes an interruption.

 

According to the previous introduction, the interrupt handling process includes initialization interrupt, processing interrupt, and recovery interrupt.

I. Guide code

Int main (void)
{
Eint_init (); // initialize the external interrupt and interrupt controller
Irqenable (); // enable IRQ interruption (clearing the I-bit of the CPSR register)

While (1); // wait for external interruption
}

Ii. initialize the code function: eint_init.

Eint_init includes external interrupt initialization and interrupt controller initialization. Set the gpf4 pin to the External Interrupt eint4 function, drop along the trigger mode, and enable the interrupt to be allowed.
Void eint_init (void)
{
Rgpfcon = (rgpfcon & 0 xfffffcff) | (0x02 <8); // set the gpf4 pin to enable the eint4 function for external interruptions
Rextint0 = (0x2 <16); // set the External Interrupt eint4 to a descent edge trigger.

Vicvectaddr [4] = (uint32) irq_eint4; // interrupt vector Address Settings

Rpriority = 0x00000000; // use the default fixed priority.
Rintmod = 0x00000000; // all interruptions are IRQ interruptions
Rintmsk = ~ 0x0000010; // enable eint4 interruption (level 1)

Reintmask = ~ 0x0000010; // enable Level 2 interruption
}

3. Enable IRQ interrupt function: irqenable.

Function: Enable IRQ interruption (clearing the I-bit of the CPSR register). The Code is as follows:
; Enable IRQ interruption
Mrs r0, spsr
Bic r0, R0, # I _bit
MSR spsr_c, R0
Movs PC, LR

Iv. irq_exception interrupt exception handling program (implementing vector Interrupt Processing). The Code is as follows:
Void _ IRQ irq_exception (void) // pay attention to the _ IRQ before the function name. The compiler has special actions.
{
Void (* _ handler) (void );
Int irq_no;
Uint32 bak;

// Locate the current interrupt number
Bak = rintpnd; // read the value of intpnd
For (irq_no = 0; irq_no <32; irq_no ++)
{
Bak = Bak> 1;
If (BAK = 0) break; // obtain the highest priority
}

// Obtain and execute the interrupt service program address
_ Handler = (void (*) (void) vicvectaddr [irq_no];
_ Handler ();
}

5. interrupt handling function of eint4: irq_eint4.

Function: reverse the output signal of the led1 control port.
Void irq_eint4 (void)
{
// Reverse the output signal of the led1 control port
// Omit...

// Clear the interrupt mark
Reintpend = (1 <4); // clear the second-level interrupt identifier
Rsrcpnd = (1 <4); // clear the first-level interrupt identifier
Rintpnd = rintpnd; // clear the interrupt ID after the mask filter
}

From the code above, we can get the process of each stage: At the initialization stage, we need to set up a mask at the first level, and after the service is interrupted, we need to clear the interrupt mark at the first level.

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.