- IAR Embedded Workbench for RL78 5.20
- IAR C/C++ Development
- Functions
- Primitives for interrupts, concurrency, and OS-related programming
Primitives for interrupts, concurrency, and OS-related programming
The IAR C/C++ Compiler for RL78 provides the following primitives related to writing interrupt functions, concurrent functions, and OS-related functions:
The extended keywords:
__interrupt,__monitorThe pragma directives:
#pragma vector,#pragma bankThe intrinsic functions:
__enable_interrupt,__disable_interrupt, __get_interrupt_state,__set_interrupt_state.
Interrupt functions
In embedded systems, using interrupts is a method for handling external events immediately; for example, detecting that a button was pressed.
Interrupt service routines
In general, when an interrupt occurs in the code, the microcontroller immediately stops executing the code it runs, and starts executing an interrupt routine instead. It is important that the environment of the interrupted function is restored after the interrupt is handled—this includes the values of processor registers and the processor status register. This makes it possible to continue the execution of the original code after the code that handled the interrupt was executed.
the RL78 microcontroller supports many interrupt sources. For each interrupt source, an interrupt routine can be written. Each interrupt routine is associated with a vector number, which is specified in the documentation from the chip manufacturer. If you want to handle several different interrupts using the same interrupt routine, you can specify several interrupt vectors.
Interrupt vectors and the interrupt vector table
For the RL78microcontroller, the interrupt vector table always starts at the address 0x0 and is placed in the .intvec section. The interrupt vector is the offset into the interrupt vector table.
By default, the vector table is populated with a default interrupt handler which calls the abort function. For each interrupt source that has no explicit interrupt service routine, the default interrupt handler will be called. If you write your own service routine for a specific vector, that routine will override the default interrupt handler.
The header file iodevice.h, where device corresponds to the selected device, contains predefined names for the existing interrupt vectors.
Defining an interrupt function—an example
To define an interrupt function, the __interrupt keyword and the #pragma vector directive can be used. For example:
#pragma vector = INTP2_vect /* Symbol defined in I/O header file */
__interrupt void MyInterruptRoutine(void)
{
/* Do something */
}Note
An interrupt function must have the return type void, and it cannot specify any parameters.
Interrupt and C++ member functions
Only static member functions can be interrupt functions.