Interrupt Management Functions

T-Kernel/SM interrupt management functions are functions for disabling or enabling external interrupt, retrieving interrupt disable status, controlling interrupt controller, etc.

Interrupt handling is largely hardware-dependent, different on each system, and therefore difficult to standardize. The following are given as standard specification, but it may not be possible to follow these exactly on all systems. Implementors should comply with these specifications as much as possible; but where implementation is not feasible, full compliance is not mandatory. If functions not in the standard specification are added, however, the function names must be different from those given here. In any case, DI(), EI(), and isDI() must be implemented in accordance with the standard specification.

Interrupt management functions are provided as library functions or C language macros. These can be called from a task-independent portion and while dispatching and interrupts are disabled.

CPU Interrupt Control

These functions are for CPU external interrupt flag control. Generally they do not perform any operation on the interrupt controller.

DI(), EI(), and isDI() are C language macros.

DI - Disable External Interrupts

C Language Interface

#include <tk/tkernel.h>

DI (UINT intsts );

Parameter

UINT intsts Interrupt StatusVariable that stores the CPU external interrupt flag

Valid Context

Task portionQuasi-task portionTask-independent portion
YESYESYES

Description

Controls the external interrupt flag in the CPU and disables all external interrupts. Also stores the flag state in intsts before disabling interrupt.

This API is defined as a C language macro and intsts is not a pointer. Write a variable directly.

EI - Enable External Interrupt

C Language Interface

#include <tk/tkernel.h>

EI (UINT intsts );

Parameter

UINT intsts Interrupt StatusVariable that stores the CPU external interrupt flag

Valid Context

Task portionQuasi-task portionTask-independent portion
YESYESYES

Description

Controls the external interrupt flag in the CPU and reverts the flag state to intsts. That is, this API reverts the flag state to the state before disabling external interrupts by the previously executed DI(intsts).

If the state before executing DI(intsts) was the external-interrupt-enabled, the subsequent EI(intsts) enables external interrupts. On the other hand, if the state was already interrupt-disabled at the time DI(intsts) was executed, interrupt is not enabled by EI(intsts). However, if 0 is specified in intsts, the external interrupt flag in the CPU is set to the interrupt-enable state.

intsts must be either the value saved by DI() or 0. If any other value is specified, the subsequent correct behavior is not guaranteed.

isDI - Get Interrupt Disable Status

C Language Interface

#include <tk/tkernel.h>

BOOL disint = isDI (UINT intsts );

Parameter

UINT intsts Interrupt StatusVariable that stores the CPU external interrupt flag

Return Parameter

BOOL disint Interrupt Disabled StatusExternal interrupt disabled status

Valid Context

Task portionQuasi-task portionTask-independent portion
YESYESYES

Description

Checks the external interrupt flag in the CPU that was stored in intsts by the previously executed DI(), and returns TRUE (a value other than 0) if the flag status is determined as the interrupt-disabled by T-Kernel/OS, or FALSE otherwise.

intsts must be the value saved by DI(). If any other value is specified, the subsequent correct behavior is not guaranteed.

Example 4. Sample Usage of isDI

void foo()
{
        UINT    intsts;

        DI(intsts);

        if ( isDI(intsts) ) {
                /* Interrupt was already disabled at the time the above DI() was called */
        } else {
                /* Interrupt was enabled at the time the above DI() was called */
        }

        EI(intsts);
}

Control of Interrupt Controller

These functions control the interrupt controller. Generally they do not perform any operation with respect to the CPU interrupt flag.

typedef UINT    INTVEC;         /* Interrupt vector */

The specific details of the interrupt vectors (INTVEC) are implementation-dependent. Preferably, however, they should be the same numbers as the interrupt handler numbers specified with tk_def_int(), or should allow for simple conversion to and from those numbers.

DINTNO - Convert Interrupt Vector to Interrupt Handler Number

C Language Interface

#include <tk/tkernel.h>

UINT dintno = DINTNO (INTVEC intvec );

Parameter

INTVEC intvec Interrupt VectorInterrupt vector

Return Parameter

UINT dintno Interrupt Handler NumberInterrupt handler number

Valid Context

Task portionQuasi-task portionTask-independent portion
YESYESYES

Description

Converts an interrupt vector to the corresponding interrupt handler number.

EnableInt - Enable Interrupts

C Language Interface

#include <tk/tkernel.h>

void EnableInt (INTVEC intvec );

void EnableInt (INTVEC intvec , INT level );

Parameter

INTVEC intvec Interrupt VectorInterrupt vector
INT level Interrupt Priority LevelInterrupt priority level

Valid Context

Task portionQuasi-task portionTask-independent portion
YESYESYES

Description

Enables the interrupt specified in intvec. In a system that allows interrupt priority level to be specified, the level parameter can be used to specify the interrupt priority level. The precise meaning of level is implementation-dependent.

Either methods with or without level shall be provided.

DisableInt - Disable Interrupts

C Language Interface

#include <tk/tkernel.h>

void DisableInt (INTVEC intvec );

Parameter

INTVEC intvec Interrupt VectorInterrupt vector

Valid Context

Task portionQuasi-task portionTask-independent portion
YESYESYES

Description

Disables the interrupt specified in intvec. Generally, interrupts raised while the interrupts are disabled are made pending, and are raised after interrupts are enabled by EnableInt() . ClearInt() must be used if it is desired to clear interrupts raised during interrupt-disabled-state.

ClearInt - Clear Interrupt

C Language Interface

#include <tk/tkernel.h>

void ClearInt (INTVEC intvec );

Parameter

INTVEC intvec Interrupt VectorInterrupt vector

Valid Context

Task portionQuasi-task portionTask-independent portion
YESYESYES

Description

Clears interrupts raised for intvec, if any.

EndOfInt - Issue EOI to Interrupt Controller

C Language Interface

#include <tk/tkernel.h>

void EndOfInt (INTVEC intvec );

Parameter

INTVEC intvec Interrupt VectorInterrupt vector

Valid Context

Task portionQuasi-task portionTask-independent portion
YESYESYES

Description

Issues EOI (End Of Interrupt) to the interrupt controller. intvec must be an interrupt for which EOI can be issued. Generally this must be executed at the end of an interrupt handler.

CheckInt - Check Interrupt

C Language Interface

#include <tk/tkernel.h>

BOOL rasint = CheckInt (INTVEC intvec );

Parameter

INTVEC intvec Interrupt VectorInterrupt vector

Return Parameter

BOOL rasint Interrupt Raised StatusExternal interrupt raised status

Valid Context

Task portionQuasi-task portionTask-independent portion
YESYESYES

Description

Checks whether an interrupt for intvec has been raised. If an interrupt for intvec has been raised, it returns TRUE (value other than 0), else returns FALSE.

SetIntMode - Set Interrupt Mode

C Language Interface

#include <tk/tkernel.h>

void SetIntMode (INTVEC intvec , UINT mode );

Parameter

INTVEC intvec Interrupt VectorInterrupt vector
UINT mode ModeInterrupt mode

Valid Context

Task portionQuasi-task portionTask-independent portion
YESYESYES

Description

Sets the interrupt specified in intvec for the mode specified in mode.

The settable modes and how to specify mode are implementation-dependent. The following is an example of settable modes:

mode := (IM_LEVEL || IM_EDGE) | (IM_HI || IM_LOW)
#define IM_LEVEL        0x0002          /* Level trigger */
#define IM_EDGE         0x0000          /* Edge trigger */
#define IM_HI           0x0000          /* H level/Interrupt at rising edge */
#define IM_LOW          0x0001          /* L level/Interrupt at falling edge */

If invalid mode is specified, the subsequent correct behavior is not guaranteed.

Difference from T-Kernel 1.0

This API was added in T-Kernel 2.0.