4.2.4.6 Disabling or enabling maskable interrupts

The CC-RH can disable the maskable interrupts in a C source.

This can be done in the following two ways.

-

Locally disabling interrupt in function

-

Disabling interrupts in entire function

(1)

Locally disabling interrupt in function

The "di instruction" and "ei instruction" of the assembler instruction can be used to disable an interrupt locally in a function described in C language. However, the CC-RH has functions that can control the interrupts in a C language source.

Table 4.18

Interrupt Control Function

Interrupt Control Function

Operation

Processing by CC-RH

__DI

Disables the acceptance of all maskable interrupts.

Generates di instruction.

__EI

Enables the acceptance of all maskable interrupts.

Generates ei instruction.

Example

How to use the __DI and __EI functions and the codes to be output are shown below.

-

C source

void func1(void) {
          :
        __DI();
        /*Describe processing to be performed with interrupt disabled.*/
        __EI();
          :
}

-

Output codes

_func1:
        -- prologue code
          :
        di
        -- processing to be performed with interrupt disabled
        ei
          :
        -- epilogue code
        jmp     [lp]

(2)

Disabling interrupts in entire function

The CC-RH has a "#pragma block_interrupt" directive that disables the interrupts of an entire function.

This directive is described as follows.

#pragma block_interrupt [(]function-name[)]

 

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

The interrupt to the function specified by "function-name" above is disabled. As explained in "(1) Locally disabling interrupt in function", __ DI()" can be described at the beginning of a function and "__ EI()", at the end. In this case, however, an interrupt to the prologue code and epilogue code output by the CC-RH cannot be disabled or enabled, and therefore, interrupts in the entire function cannot be disabled.

Using the #pragma block_interrupt directive, interrupts are disabled immediately before execution of the prologue code, and enabled immediately after execution of the epilogue code. As a result, interrupts in the entire function can be disabled.

Example

How to use the #pragma block_interrupt directive and the code that is output are shown below.

-

C source

#pragma block_interrupt func1
void func1(void) {
          :
        /*Describe processing to be performed with interrupt disabled.*/
          :
}

-

Output codes

_func1:
        di
        -- prologue code
          :
        -- processing to be performed with interrupt disabled
          :
        -- epilogue code
        ei
        jmp     [lp]

(3)

Notes on disabling interrupts in entire function

Note the following points when disabling interrupts in an entire function.

-

If an interrupt handler and a #pragma block_interrupt directive are specified for the same interrupt, the interrupt handler takes precedence, and the setting of disabling interrupts is ignored.

-

If the following functions are called in a function in which an interrupt is disabled, the interrupt is enabled when execution has returned from the call.

-

Function specified by #pragma block_interrupt.

-

Function that disables interrupt at the beginning and enables interrupt at the end.

-

Describe the #pragma block_interrupt directive before the function definition in the same file; otherwise an error occurs during compilation.

-

However, the order of prototype declaration of a function is not affected.

-

Neither #pragma inline nor inline expansion can be specified by an optimization option for the function specified by a #pragma block_interrupt directive. The inline expansion specification is ignored.

-

A code that manipulates the ep flag (that indicates exception processing is in progress) in the program status word (PSW) is not output even if #pragma block_interrupt is specified.