source: cmedia/trunk/Drv16/irq.hpp

Last change on this file was 553, checked in by rudi, 14 years ago

Adapt sourcecode to OpenWatcom

File size: 4.8 KB
Line 
1/* $Id: irq.hpp,v 1.1 2000/04/23 14:55:16 ktk Exp $ */
2
3/* SCCSID = %W% %E% */
4/****************************************************************************
5 * *
6 * Copyright (c) IBM Corporation 1994 - 1997. *
7 * *
8 * The following IBM OS/2 source code is provided to you solely for the *
9 * the purpose of assisting you in your development of OS/2 device drivers. *
10 * You may use this code in accordance with the IBM License Agreement *
11 * provided in the IBM Device Driver Source Kit for OS/2. *
12 * *
13 ****************************************************************************/
14/**@internal %W%
15 * IRQ object definition.
16 * @version %I%
17 * @context
18 * Unless otherwise noted, all interfaces are Ring-0, 16-bit, kernel stack.
19 *
20 * @notes The IRQ object permits multiple interrupt handlers, all located
21 * within this driver, to share an interrupt level. The IRQ object also
22 * handles the bookkeeping and handshaking associated with the kernel and
23 * with the PIC. EOI is not issued to the PIC until a handler is found
24 * which services the interrupt. If no handler indicates that the hardware
25 * interrupt has been serviced, then no EOI is issued and the return code
26 * back to the kernel indicates that the interrupt has not been serviced.
27 *
28 * @notes No public constructor is provided for this object. Use the
29 * pMakeIRQ( irq_level ) friend function to obtain a pointer to the IRQ object
30 * of interest.
31 *
32 * @notes A client of this object should register its interrupt service
33 * routine by the AddHandler() method, and then enable the handler via
34 * EnableHandler. The service routine must conform to the definition of a
35 * PFN_InterruptHandler, returning True if the interrupt was handled and
36 * False otherwise. Reference PFN_InterruptHandler definition below.
37 *
38 * @history
39 */
40
41#ifndef IRQ_INCLUDED
42#define IRQ_INCLUDED
43
44#ifndef OS2_INCLUDED
45#define INCL_NOPMAPI
46#include <os2.h>
47#endif
48
49
50// Max num of int handlers per IRQ level.
51const int MAX_HandlersPerIRQLevel = 3;
52
53
54// PFN_InterruptHandler: Pointer to an interrupt handler. This is a near
55// function which returns TRUE if it handled the interrupt, FALSE otherwise.
56
57// Rudi: __loadds __saveregs not required for an interrupt handler
58// typedef BOOL __far __loadds __saveregs (*PFN_InterruptHandler) ( int irqnr );
59
60typedef BOOL (*PFN_InterruptHandler) ( int irqnr, unsigned long param );
61
62class ISR_Entry {
63public:
64 BOOL bEnabled; // true <=> this handler is enabled.
65 PFN_InterruptHandler pfnHandler; // Handler within this driver.
66 ULONG ulParam;
67};
68
69
70class IRQ {
71
72 // Use this globally scoped function to create an IRQ object
73 // rather than calling a constructor. This function ensures that
74 // no more than one IRQ object is constructed per level.
75 friend IRQ* pMakeIRQ( unsigned irq_level );
76 friend IRQ* getIRQ( unsigned irq_level );
77
78public:
79
80 // Add an interrupt handler to the list.
81 BOOL bAddHandler ( PFN_InterruptHandler pfn, unsigned long userdata );
82
83 // Enable the named handler.
84 BOOL bEnableHandler ( PFN_InterruptHandler pfn );
85
86 // Disables the named handler.
87 BOOL bDisableHandler ( PFN_InterruptHandler pfn );
88
89 // Removes the interrupt handler from the list.
90 BOOL bRemoveHandler ( PFN_InterruptHandler pfn );
91
92 // Receives interrupt from kernel, then calls out to registered handlers.
93 // Runs in interrupt context.
94 void CallHandlers (void);
95
96 inline unsigned QueryLevel(void) const { return _usIRQLevel; };
97
98private:
99 // Data:
100
101 ISR_Entry _handlerList[ MAX_HandlersPerIRQLevel + 1 ];
102 // List of handlers associated with this interrupt.
103 // Used slots are always contiguous starting from
104 // slot 0. Null PFN entry inidicates free slot and end
105 // of list. The last slot in the array is an extra slot,
106 // guaranteed to be NULL.
107 USHORT _nEnabled; // Number of handlers currently enabled.
108 USHORT _usIRQLevel; // The IRQ level itself
109
110 USHORT _usSlotNo; // Rudi
111
112 // Methods:
113
114 // Constructor. Note that this is private; a client should use the
115 // pMakeIRQ() friend function to obtain a pointer to an IRQ object.
116 IRQ ( unsigned irq_level, unsigned slot_no );
117
118 // Destructor.
119 ~IRQ ( void );
120
121 // Find named handler in _handlerList[].
122 ISR_Entry* _pFindHandler( PFN_InterruptHandler pfn );
123
124
125};
126
127/* Note: do not call AddHandler, RemoveHandler, in an interrupt thread.
128 do not create or delete an IRQ object (or any object) in an interrupt thread
129*/
130
131#endif
Note: See TracBrowser for help on using the repository browser.