4.2.4.5 Interrupt/Exception processing handler

The CC-RH can describe an "Interrupt handler" or "Exception handler" that is called if an interrupt or exception occurs. This section explains how to describe these handlers.

(1)

Occurrence of interrupt/exception

If an interrupt or exception occurs in the RH850 family, the program jumps to a handler address corresponding to the interrupt or exception.

The arrangement of the handler addresses and the available interrupts vary depending on the device of the RH850. See the Relevant Device's User's Manual of each device for details.

 

How to describe interrupt servicing is explained specifically in "(3) Describing interrupt/exception handler".

(2)

Processing necessary in case of interrupt/exception

If an interrupt/exception occurs while a function is being executed, interrupt/exception processing must be immediately executed. When the interrupt/exception processing is completed, execution must return to the function that was interrupted.

Therefore, the register information at that time must be saved when an interrupt/exception occurs, and the register information must be restored when interrupt/exception processing is complete.

(3)

Describing interrupt/exception handler

The format in which an interrupt/exception handler is described does not differ from ordinary C functions, but the functions described in C must be recognized as an interrupt/exception handler by the CC-RH. With the CC-RH, an interrupt/exception handler is specified using the #pragma interrupt directive.

#pragma interrupt   [(]Function-name[(interrupt specification [, interrupt specification]...)] [,...] [)]

 

Describe functions that are described in the C language. In the case of a function, "void func1() {}", specify "func1".

Always give interrupt functions a return type of void.

The function exit code of an interrupt function is different from that of an ordinary function. You must therefore not call them in the same way as ordinary functions.

 

(a)

Define an interrupt function

You can define an interrupt function with either no parameters or one parameter.

Example 1.

Using no parameters

void i_func(void)
{
        :
}

Example 2.

Using one parameter

void i_func(unsigned long dummy)
{
        :
}

 

(b)

interrupt specification

The following interrupt specification can be specified.

enable=

Specifies whether multiplex interrupts are enabled. This can be set to true, false, or manual.

-

true

Output ei/di.

Outputs code to save or restore eipc/eipsw.

-

false (default)

Does not output ei/di.

Does not output code to save or restore eipc/eipsw.

-

manual

Does not output ei/di.

Outputs code to save or restore eipc/eipsw.

priority=

channel=

You can only specify one of either "priority" or "channel", but not both (writing both will cause a compilation error).

-

priority=

Specifies the exception trigger. You can write only one of the following tokens.

SYSERR/FETRAP/TRAP0/TRAP1/RIE/FPPNote 1/FPINote 1/FPINTNote 2/UCPOP/MIP/MDP/PIE/MAE/FENMI/FEINT/EIINT_PRIORITYX (X is 0 -15)

-

channel=

Specifies the interrupt channel. Select this if you are using the extended specification for interrupts.

Generates code determining the EI compiler to be used.

If you did not specify either "priority" or "channel", it will determine the EIINT.

fpu=

Specifies saving and restoration of fpepc/fpsr in the fpu context. This can be set to true, false, or auto.

-

true

Saves and restores fpepc/fpsr.

-

false

Does not save or restore fpepc/fpsr.

-

auto (default)

Interpreted as true when the -Xfloat=fpu option is specified.

Interpreted as false when -Xfloat=soft is specified.

callt=

Specifies saving/restoration of ctpc/ctpsw in the callt context. This can be set to true, false.

-

true (default)

Saves and restore ctpc/ctpsw.

-

false

Does not save or restore ctpc/ctpsw.

Note 1.

An error will occur if -Xcpu=g3mh option is specified.

Note 2.

An error will occur if -Xcpu=g3mh option is not specified.

 

If you write an interrupt specification, you must include a term to the right of the equals sign ("=").

For example, writing only "enable=" will cause a compilation error. The default interrupt specification signifies the behavior when individual interrupt specifications are not written.

 

(c)

Output code for EI level exception

The compiler inserts the following instructions at the entrance and exit of an EI level exception interrupt function. EIINT and FPI are some of the main corresponding items.
However, this is not inserted into all interrupt functions. Necessary processing is output in accordance with user-defined #pragma statements, compiler options, etc.

 

<1>

[Entrance code of interrupt functions]

(1) Allocates stack area for saving context

(2) Saves Caller-Save register used in interrupt function

(3) Saves EIPC and EIPSW

(4) If the function has a formal parameter, set EIIC to R6

(5) Enables multiplex interrupts

(6) Saves WCTPC and CTPSW

(7) Saves WFPEPC and FPSR

 

<2>

[Exit code of interrupt functions]

(8) Sets imprecise interrupt standby

(9) Restorse FPEPC and FPSR

(10) Restores CTPC and CTPSW

(11) Disables multiplex interrupts

(12) Restores EIPC and EIPSW

(13) Restores Caller-Save register used in interrupt function

(14) Frees stack area for saving context

(15) eiret

 

Below is a specific example of the output code. Numbers (1) to (15) in the code correspond to the numbered actions above.

Note that the instructions in the output code will not necessarily be identical to this example. The instructions, general-purpose registers, and other details may differ from this example.

 

Example 1.

Sample1: output of EI level exception

#pragma interrupt func1(enable=true, callt=true, fpu=true)
void func1(unsigned long eiic)
{
        User-coded processing;
}

 

Example 2.

Sample2: output of EI level exception
If there are no formal parameters, and interrupt multiplexing is set to manual (enable=manual)

#pragma interrupt func1(enable=true, callt=true, fpu=true)
void func1(unsigned long eiic)
 {
        User-coded processing;
}

 

(d)

Output code for FE level exception

The compiler inserts the following instructions at the entrance and exit of an FE level exception interrupt function. FEINT and PIE are some of the main corresponding items.
However, this is not inserted into all interrupt functions. Necessary processing is output in accordance with user-defined #pragma statements, compiler options, etc.

 

<1>

[Entrance code of interrupt functions]

(1) Allocates stack area for saving context

(2) Saves all Caller-Save register used in interrupt function

(3) If the function has a formal parameter, sets FEIC to R6

(4) Saves CTPC and CTPSW

(5) Saves FPEPC and FPSR

 

<2>

[Exit code of interrupt functions]

(6) Restores FPEPC and FPSR

(7) Restores CTPC and CTPSW

(8) Restores all Caller-Save register used in interrupt function

(9) Frees stack area for saving context

(10) feret

 

Below is a specific example of the output code. Numbers (1) to (10) in the code correspond to the numbered actions above.

Note that the instructions in the output code will not necessarily be identical to this example. The instructions, general-purpose registers, and other details may differ from this example.

 

Example

Sample output of FE level exception

#pragma interrupt func1(priority=feint, callt=true, fpu=true)
void func1(unsigned long feic)
{
        User-coded processing;
}

 

(e)

Output code for FE level exception (cannot recover/restore)

The compiler inserts the following instructions at the entrance and exit of an FE level exception (cannot recover/restore) interrupt function. FENMI and SYSERR are some of the main corresponding items.

<1>

[Entrance code of interrupt functions]

(1) If the function has a formal parameter, sets FEIC to R6

Nothing is output if the function does not have any parameters.

<2>

[Exit code of interrupt functions]

None

 

Remark

No saving or restoration of context is output.
Code the save and restore the Callee-Save register is also not output.
Take appropriate measures in the user program, such as calling abort() in the function to terminate the program.

 

Below is a specific example of the output code. Numbers (1) in the code correspond to the numbered actions above.

Example

Sample output of FE level exception (cannot recover/restore)

#pragma interrupt func1(priority=fenmi)
void func1(unsigned long feic)
{
        User-coded processing;
}

 

(4)

Notes on describing interrupt/exception handler

-

A function specified as an interrupt/exception handler cannot be expanded inline. The #pragma inline directive is ignored even if specified.