# Pragma code_seg non_banked interrupt description

Source: Internet
Author: User
There are two main methods to interrupt programming for mc9sdg128b:
The first is to use the symbol "trap_proc", and trap_proc prompts that the following functions of the compiler are interrupt service routines. The compiler ends this function with a special interrupt return instruction (for most processors, it is generally an RTI instruction ).
The second is to use the "interrupt" keyword, and the "interrupt" keyword is a keyword for a non-standard ANSI-C, so it cannot be supported by all ANSI-C compiler vendors. Similarly, for different compilers, the usage of the "interrupt" keyword may change. The "interrupt" keyword also prompts that the function below the compiler is an interrupt service routine.
Once the interrupt service function is written, you must associate the interrupt service routine with the interrupt vector table, which is achieved by initializing the interrupt vector table, you can initialize the interrupt vector table using the following two methods:
The first is to use the "vector address" or "vector" command in the PrM file. The connector provides two commands to initialize the interrupt vector table: vector address or vector. You use the vector address command to write the address of the interrupt service routine to the interrupt vector table.
The second is to use the "interrupt" keyword, when you write interrupt service routines, you can directly in the ANSI-C source file interrupt service routines and special interrupt number.
Below is the 16-bit free timer overflow Interrupt Processing of mc9sdg128b I wrote. Program , Debugged:
# Include /* Common defines and macros */
# Include /* Derivative information */
# Pragma link_info derivative "mc9s12dg128b"

Int intcount = 0;

Void timer_init (void)

{

Tscr2_pr0 = 1; // prescale factor is 128

Tscr2_pr1 = 1;

Tscr2_pr2 = 1;

Tscr2_toi = 1; // overflow enable

Tflg2_tof = 1;

Tscr1_ten = 1; // timer enable
}

# Pragma code_seg non_banked
Interrupt 16 void timer_interrupt_handle (void)
{

Intcount ++;

Tflg2_tof = 1; // clear interrupt flag
};
# Pragma code_seg default

Void main (void)
{

Enableinterrupts;

Timer_init ();

For (;;){}
}

The following is an interrupt service program written with the trap_proc symbol:
# Include /* Common defines and macros */
# Include /* Derivative information */
# Pragma link_info derivative "mc9s12dg128b"
Int intcount = 0;
Void timer_init (void)
{

Tscr2_pr0 = 1; // prescale factor is 128

Tscr2_pr1 = 1;

Tscr2_pr2 = 1;

Tscr2_toi = 1; // overflow enable

Tflg2_tof = 1;

Tscr1_ten = 1; // timer enable
}

# Pragma code_seg non_banked
# Pragma trap_proc
Void timer_interrupt_handle (void)
{

Intcount ++;

Tflg2_tof = 1;
};
# Pragma code_seg default

Void main (void)
{

Enableinterrupts;

Timer_init ();

For (;;){}
}

After writing the interrupt service program, you need to add the following sentence to the. PRM file:
Vector 16 timer_interrupt_handle
In this way, the service interruption program is associated with the corresponding interrupt number. This program has also been debugged.

The interrupt service routine must be located in the non-banked area. You can use "# pragma code_seg non_banked" to locate the interrupt service routine in the non-banked area. At the same time, make sure that "sectionnon_banked" cannot appear in the. PRM file. Add "# pragma code_seg default" at the end of the interrupted service routine. Otherwise, the subsequent functions will be located in the "non-banked" area.

Therefore, our service interruption routine must be surrounded by "# pragma code_seg non_banked" and "# pragma code_seg default.

Note:
IRQ is short for interrupt request.
Because the CPU continues to be busy during computer operation, when the hardware interface device starts or ends sending and receiving information, the CPU needs to process information computing, IRQ sends an interrupt request signal to the CPU, allowing the CPU to store ongoing work, and then suspends the work at hand to handle the requirements of peripheral hardware. This is the role of the interrupt request.

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.