source: cmedia/trunk/Drv16/irq.hpp@ 354

Last change on this file since 354 was 354, checked in by stevenhl, 17 years ago

Import untested baseline cmedia sources, work products and binaries
Binaries and work products should be deleted from repository.
once new builds are verified to work.

File size: 5.1 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// clude <stddef.h> //### NULL? to be removed
50
51// ###IHV: IRQ sharing flag. Set this to "0" for ISA bus, "1" for PCI
52// PCI and Microchannel environments (where hardware can share an IRQ level.
53const IRQ_HW_Sharing = 0;
54
55// Max num of int handlers per IRQ level.
56const MAX_HandlersPerIRQLevel = 3;
57
58
59// PFN_InterruptHandler: Pointer to an interrupt handler. This is a near
60// function which returns TRUE if it handled the interrupt, FALSE otherwise.
61
62// Rudi: __loadds __saveregs not required for an interrupt handler
63// typedef BOOL __far __loadds __saveregs (*PFN_InterruptHandler) ( int irqnr );
64
65typedef BOOL (*PFN_InterruptHandler) ( int irqnr, unsigned long param );
66
67class ISR_Entry {
68public:
69 BOOL bEnabled; // true <=> this handler is enabled.
70 PFN_InterruptHandler pfnHandler; // Handler within this driver.
71 ULONG ulParam;
72};
73
74
75class IRQ {
76
77 // Use this globally scoped function to create an IRQ object
78 // rather than calling a constructor. This function ensures that
79 // no more than one IRQ object is constructed per level.
80 friend IRQ* pMakeIRQ( unsigned irq_level );
81 friend IRQ* getIRQ( unsigned irq_level );
82
83public:
84
85 // Add an interrupt handler to the list.
86 BOOL bAddHandler ( PFN_InterruptHandler pfn, unsigned long userdata );
87
88 // Enable the named handler.
89 BOOL bEnableHandler ( PFN_InterruptHandler pfn );
90
91 // Disables the named handler.
92 BOOL bDisableHandler ( PFN_InterruptHandler pfn );
93
94 // Removes the interrupt handler from the list.
95 BOOL bRemoveHandler ( PFN_InterruptHandler pfn );
96
97 // Receives interrupt from kernel, then calls out to registered handlers.
98 // Runs in interrupt context.
99 void CallHandlers (void);
100
101 inline unsigned QueryLevel(void) const { return _usIRQLevel; };
102
103private:
104 // Data:
105
106 ISR_Entry _handlerList[ MAX_HandlersPerIRQLevel + 1 ];
107 // List of handlers associated with this interrupt.
108 // Used slots are always contiguous starting from
109 // slot 0. Null PFN entry inidicates free slot and end
110 // of list. The last slot in the array is an extra slot,
111 // guaranteed to be NULL.
112 USHORT _nEnabled; // Number of handlers currently enabled.
113 USHORT _usIRQLevel; // The IRQ level itself
114
115 USHORT _usSlotNo; // Rudi
116
117 // Methods:
118
119 // Constructor. Note that this is private; a client should use the
120 // pMakeIRQ() friend function to obtain a pointer to an IRQ object.
121 IRQ ( unsigned irq_level, unsigned slot_no );
122
123 // Destructor.
124 ~IRQ ( void );
125
126 // Find named handler in _handlerList[].
127 ISR_Entry* _pFindHandler( PFN_InterruptHandler pfn );
128
129
130};
131
132/* Note: do not call AddHandler, RemoveHandler, in an interrupt thread.
133 do not create or delete an IRQ object (or any object) in an interrupt thread
134*/
135
136#endif
Note: See TracBrowser for help on using the repository browser.