Download STLite/OS20 Real-Time Kernel Reference Manual

Transcript
9 Interrupts
int asc_Status;
} asc_t;
volatile asc_t* asc0 = (asc_t*)0x20003000;
#define
#define
#define
#define
ASC_MODE_8D
ASC_STOP_1_0
ASC_RUN
ASC_RXEN
0x01
0x08
0x80
0x100
#define ASC_BAUD_9600
(40000000 / (16*9600))
#define ASC_RX_BUF_FULL
1
interrupt_init_controller((void*)INTERRUPT_CONTROLLER, 8,
(void*)INTERRUPT_LEVEL_CONTROLLER,
INTERRUPT_NUMBERS, INTERRUPT_INPUT_OFFSET);
interrupt_init(ASC_INTERRUPT_LEVEL, ser_stack, sizeof(ser_stack),
interrupt_trigger_mode_high_level, 0);
interrupt_enable_global();
if (interrupt_install(ASC0_INTERRUPT_NUMBER, ASC_INTERRUPT_LEVEL,
ser_handler, NULL) == 0) {
asc->asc_Control
= ASC_MODE_8D | ASC_STOP_1_0 | ASC_RUN | ASC_RXEN;
asc->asc_BaudRate
= ASC_BASE_9600;
asc->asc_intEnables = ASC_RX_BUF_FUL;
interrupt_enable(ASC_INTERRUPT_LEVEL);
}
If this example were transferred to a device with an ILC-2 or ILC-3 interrupt level
controller the call to interrupt_enable (last line) would become:interrupt_enable_number(ASC0_INTERRUPT_NUMBER);
In section 9.15 an example is given of how to remove this interrupt.
9.8
Locking out interrupts
All interrupts to the CPU can be globally disabled or re-enabled using the following two
commands:
#include <interrupt.h>
void interrupt_lock (void);
void interrupt_unlock (void);
These functions should always be called as a pair and will prevent any interrupts from
the interrupt controller having any effect on the currently executing task while the lock
is in place. These functions can be used to create a critical region in which the task
cannot be preempted by any other task or interrupt. Calls to interrupt_lock() can
be nested, and the lock will not be released until an equal number of calls to
interrupt_unlock() have been made.
Note: that locking out interrupts is slightly different from disabling an interrupt. Interrupts are locked by changing the ST20’s Enables register, which causes the CPU to
ignore the interrupt controller (and any other external device), while disabling an
155