On Time RTOS-32 Documentation
Welcome
RTTarget-32
RTKernel-32
RTKernel-32 Programming Manual
Introduction
Multitasking, Real-Time, and RTKernel-32
Module RTKernel-32
Alternate APIs for RTKernel-32
Supplemental Modules
RTKernel-32 Drivers
Demo Programs
Advanced Topics
RTKernel-32's Debug Version
How to Create Threads
Interrupt Handling
Installing Shared Interrupt Handlers
Interrupt Handler for RTKSetIRQHandler
Avoid Polling
Preemptive or Cooperative Multitasking?
Waiting for Several Events
Avoid Large Message Types
Mutual Exclusion
Avoid Time Slicing
Cyclic Tasks (Timer)
Priorities
Starting Objects' Methods as Tasks
Performance and Interrupt Response Times
Multiprocessor Applications
OpenMP
Task Switches in Cooperative Scheduling
Writing Custom Kernel Drivers
Using the FPU in Interrupt Handlers
Typical Error Sources
Error and Information Messages
RTKernel-32 Reference Manual
RTFiles-32
RTIP-32
RTPEG-32
RTUSB-32
|
Installing Shared Interrupt Handlers
An interrupt handler to be installed with RTInstallSharedIRQHandlerEx should have the following structure:
- It should be declared as an int C/C++ function with one pointer parameter.
- The handler should determine which interrupt conditions (if any) are pending for the device and handle them all. If no interrupt conditions are active, then the interrupt was probably triggered by some other device and the handler should return 0 immediately. If one or more interrupt conditions have been handled and the interrupt is level (and not edge) triggered, a value > 0 should be returned.
- The handler can communicate with other tasks using mechanisms that cannot lead to blocking task switches.
Note that the handler will be called with interrupts enabled and that the handler should not call any interrupt controller specific functions.
Example:
int IRQ = 3;
int IOBase = 0x2F8;
int RTKAPI IntHandler(void * P) // high level interrupt handler
{
int IOBase = * (int*)P; // get the device context
int Count = 0;
while (RTIn(IOBase+IIR) & 0x0C) // receive int?
{
char Data = RTIn(IOBase+RXB); // get the received byte
RTKPutCond(Buffer, &Data); // and insert in mailbox
Count = 1;
}
return Count;
}
...
int main(void)
{
...
RTInstallSharedIRQHandlerEx(IRQ, IntHandler, &IOBase);
// program device to start sending interrupts here
...
// program device to stop sending interrupts here
RTRemoveSharedIRQHandlerEx(IRQ, IntHandler, &IOBase);
...
}
Interrupt Handling
Interrupt Handler for RTKSetIRQHandler
|