![]() |
Home |
|
Installing Hardware Interrupt HandlersThe RTTarget-32 boot code installs default interrupt handlers for all 16 IRQs and disables all IRQs except 0, 1, and 2. The BOOTFLAGS command can be used to modify this behavior. The default interrupt handlers always execute at CPL 0 and behave as follows: On IRQ 0 (the timer interrupt), the master interrupt controller is merely reset. On IRQ 1 (the keyboard interrupt), the keyboard controller is read and the master interrupt controller is also reset. If the scan code pressed is the DEL key on the numeric keypad, function RTReboot is called. All other scan codes are ignored. The interrupt handlers on all other IRQs reset the interrupt controller(s) and display a warning message which contains the Interrupt Service Register values of the master and slave interrupt controllers. This warning indicates that an interrupt was triggered for which the application has not installed a handler. RTTarget-32's Win32 emulation library can install interrupt handlers using RTInstallSharedIRQHandler on IRQ 0 and 1, replacing the boot code's default handlers. The first call to GetTickCount will install a handler on IRQ 0. The handler simply increments an integer which is evaluated by function GetTickCount. The first call to any function that might read keyboard input (for example, any file I/O function, kbhit, getch, or any of the console I/O functions) will install a handler on IRQ 1 to read and interpret keyboard scan codes. This handler does not reboot the target on any scan code such as DEL or Ctrl-Alt-DEL. Applications wishing to install their own hardware interrupt handlers should usually use the high level handler functions RTInstallSharedIRQHandlerEx and RTRemoveSharedIRQHandlerEx. Example:#define IRQ 3 int RTKAPI IntHandler(void * P) // high level interrupt handler in C { int IOBase = *(int*)P; char Data; RTIn(IOBase+LSR); // clear line status errors Data = RTIn(IOBase+RXB); // get the received byte SaveInBuffer(Buffer, &Data); // and insert in mailbox } ... int main(void) { ... RTInstallSharedIRQHandlerEx(IRQ, IntHandler, &IOBase); // install handler // program device to start sending interrupts here ... // program device to stop sending interrupts here RTRemoveSharedIRQHandlerEx(IRQ, IntHandler, &IOBase); // uninstall handler ... } Demo program SerInt contains a complete example. Handlers for exceptions or software interrupts can be installed using RTSetIntVector and RTSetTrapVector. Direct access to the Interrupt Descriptor Table is supported through RTSaveVector and RTRestoreVector.
|