source: sbliveos2/trunk/drv16/timer.hpp@ 724

Last change on this file since 724 was 142, checked in by ktk, 25 years ago

Import

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.0 KB
Line 
1/* $Id: timer.hpp 142 2000-04-23 14:55:46Z ktk $ */
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, ULONG ulStreamType );
48
49 // No destructor -- object never destroyed.
50
51 // Query state of timer. TIMER_Disabled inidicates internal failure.
52 const int eState ( void );
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 virtual int Start ( void ); // Start the operation
58 virtual int Stop ( void ); // Stop the operation
59 virtual int Pause ( void ); // Pause the operation
60 virtual int Resume ( void ); // Resume the operation
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 BOOL __far __loadds __saveregs _vTimerHook ( void );
92
93 // Perform the per tick, per timer object tasks.
94 VOID TIMER::_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 static int _eTechnology; // Timer technololgy being used, see enumeration above.
101 static USHORT _usTimerCount; // Value to write into the chip's countdown timer.
102 static USHORT _uInterval_mSec; // Expected interval between ticks, milliseconds.
103 static USHORT _uIntervalErr_uSec; // uSec error between requested uTargetMSec interval
104 // and acutal _uInterval_mSec.
105
106 // Data - unique per timer instance, but doesn't change after construction.
107 ULONG _ulStreamType; // Type of stream associated with this timer.
108 // Ref def'ns in stream.hpp.
109 ULONG _ctxHookHandle; // Handle for this context hook.
110
111 // Data - dynamic.
112 ULONG _ulTime; // Current time in milliSec (reflects pauses, etc).
113 ULONG _ulSchedTime; // Time to arm next context hook.
114 // "0" if we should arm hook on next tick.
115 USHORT _uCumulativeError; // Accumulated error, in uSec, of the
116 // elapsed time that we're reporting.
117 // Always in range of 0..1000 (1 mSec).
118 int _eState; // Internal Timer state, see enum above.
119};
120
121#endif // TIMER_INCLUDED
Note: See TracBrowser for help on using the repository browser.