source: cmedia/trunk/Drv16/timer.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.0 KB
Line 
1/* $Id: timer.hpp,v 1.1 2000/04/23 14:55:21 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 * Timer object definition.
16 * @version %I%
17 * @context
18 * Unless otherwise noted, all interfaces are Ring-0, 16-bit, kernel stack.
19 * @notes
20 * @history
21 */
22
23#ifndef TIMER_INCLUDED
24#define TIMER_INCLUDED
25
26#ifndef OS2_INCLUDED
27#define INCL_NOPMAPI
28#include <os2.h>
29#endif
30
31#include "irq.hpp" // Object definition.
32#include "queue.hpp" // Object definition.
33
34extern PQUEUEHEAD pTimerList; // timer.cpp: List of all instantiated timers.
35
36
37// Define some states for a timer object.
38enum { TIMER_Disabled = 0, // Object &/or hardware not initialized.
39 TIMER_Stopped, // Object initialized & ready to run, but
40 // interrupt & timer clock _not_ running.
41 TIMER_Running }; // Interrupt & timer clock running.
42
43class TIMER : public QUEUEELEMENT {
44public:
45
46 // Constructor.
47 TIMER ( IRQ* pIRQ, USHORT uTargetMSec, USHORT usStreamType );
48
49 // No destructor -- object never destroyed.
50
51 // Query state of timer. TIMER_Disabled inidicates internal failure.
52 inline UCHAR eState ( void ) { return _eState; };
53
54 // Start, Stop, Pause, Resume functions. Define these to be consistent
55 // with the AUDIOHW class (although we aren't subclassed from AUDIOHW).
56 // Each function implements the appropraite verb on a Timer object.
57 inline int Start ( void ) { return _iStart(); };
58 inline int Stop ( void ) { return _iStop(); };
59 inline int Pause ( void ) { return _iStop(); };
60 inline int Resume ( void ) { return _iStart(); };
61
62 // Get current TIMER time (in milliseconds).
63 ULONG ulGetTime ( void );
64
65 // Set current TIMER time (in milliseconds).
66 void vSetTime ( ULONG ulTime );
67
68 // Schedule the next Context hook invocation, 0 for next tick.
69 // If specified time has already passed when vSchedule() called,
70 // Ctx hook will be set on next tick (will not return immed. into
71 // routine).
72 VOID vSchedule ( ULONG ulTime );
73
74private:
75 // Private member functions
76
77 // Internal workers for Start + Resume, Stop + Pause
78 int _iStart ( void );
79 int _iStop ( void );
80
81 // Returns TRUE if any Timer is in the TIMER_Running state.
82 static BOOL _isAnyRunning ( void );
83
84 // Start the generation of HW timer ticks on the chip.
85 static VOID _vStartHWTicks ( void );
86
87 // Start the generation of HW timer ticks on the chip.
88 static VOID _vStopHWTicks ( void );
89
90 // Handle tick. Runs in Interrupt context. Calls _vPerTickTasks().
91 static void __far __loadds __saveregs _vTimerHook ( void );
92
93 // Perform the per tick, per timer object tasks.
94 VOID _vPerTickTasks( void );
95
96private:
97 // Static data. All instantiated timers will use same interrupt mechanism,
98 // and these members are shared (hense, static) across all Timer objects.
99// static IRQ* _pIRQ; // IRQ object for the timer.
100
101 static UCHAR _eTechnology; // Timer technololgy being used, see enumeration above.
102 static USHORT _usTimerCount; // Value to write into the chip's countdown timer.
103 static USHORT _usInterval_mSec; // Expected interval between ticks, milliseconds.
104 static USHORT _usIntervalErr_uSec; // uSec error between requested uTargetMSec interval
105 // and acutal _uInterval_mSec.
106
107 // Data - unique per timer instance, but doesn't change after construction.
108 USHORT _usStreamType; // Type of stream associated with this timer.
109 // Ref def'ns in stream.hpp.
110 ULONG _ctxHookHandle; // Handle for this context hook.
111
112 // Data - dynamic.
113 ULONG _ulTime; // Current time in milliSec (reflects pauses, etc).
114 ULONG _ulSchedTime; // Time to arm next context hook.
115 // "0" if we should arm hook on next tick.
116 USHORT _usCumulativeError; // Accumulated error, in uSec, of the
117 // elapsed time that we're reporting.
118 // Always in range of 0..1000 (1 mSec).
119 UCHAR _eState; // Internal Timer state, see enum above.
120};
121
122#endif // TIMER_INCLUDED
123
Note: See TracBrowser for help on using the repository browser.