home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / hrtx11r0.zip / HRTX.H < prev    next >
C/C++ Source or Header  |  2001-05-30  |  13KB  |  394 lines

  1. ///////////////////////////////////////////////////////////////////////////////
  2. // HRTX.H
  3. //
  4. // (C) 2000 Dr J A Gow
  5. //
  6. // Extended High-Resolution Timer system
  7. //
  8. // Shared include file providing definitions of IOCtl and IDC interfaces to
  9. // HRTX. It is possible to use the include files shipped with the DDK to
  10. // communicate with this driver in order to maintain full compatibility
  11. // with the original. This file may, however, contains extensions to the
  12. // original protocol
  13. //
  14. ///////////////////////////////////////////////////////////////////////////////
  15.  
  16. #ifndef _HRTX_H_
  17. #define _HRTX_H_
  18.  
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22.  
  23. ///////////////////////////////////////////////////////////////////////////////
  24. // Useful defines..
  25.  
  26. //
  27. // IOCtl category for HRTX
  28.  
  29. #define HRTXIOCTL_CATEGORY              0x80
  30.  
  31. //
  32. // Maximum number of clients allowed
  33.  
  34. #define HRTX_MAX_CLIENTS                10
  35.  
  36. ///////////////////////////////////////////////////////////////////////////////
  37. // IDC Prototypes..
  38.  
  39. //
  40. // Prototype for driver callback function
  41.  
  42. typedef void (_far _loadds *FPFNHRTXCALLBACK)(void);
  43.  
  44. //
  45. // Prototype of HRTX IDC entry point
  46.  
  47. typedef int (_far _loadds _cdecl *FPFNHRTXIDC)(int Command, ULONG Parm1, ULONG Parm2);
  48.  
  49. ///////////////////////////////////////////////////////////////////////////////
  50. // Shared structures
  51.  
  52. //
  53. // Extended version information
  54.  
  55. typedef struct _VER {
  56.  
  57.         unsigned char   ver[7];
  58.         unsigned char   build[5];
  59.         unsigned char   desc[40];
  60.  
  61. } VER;
  62.  
  63. typedef VER *   PVER;
  64.  
  65. ///////////////////////////////////////////////////////////////////////////////
  66. // HRTX Error code defines
  67.  
  68. #define HRTXERR_NOERROR         0x00    // everything sings
  69. #define HRTXERR_MODONINT        0x01    // attempt to reset timer from IRQ or INIT thread
  70. #define HRTXERR_MAX_CLIENTS     0x02    // reached maximum number of clients
  71. #define HRTXERR_NOSUCHCLIENT    0x03    // no such client exists
  72. #define HRTXERR_BADPARAM        0x04    // invalid parameter
  73. #define HRTXERR_HRTCBFAIL       0x05    // problem attaching to the RTC callback
  74. #define HRTXERR_EARLYREGISTER   0x06    // attempt to register before task time
  75. #define HRTXERR_INVALIDHANDLE   0x07    // bad handle supplied
  76. #define HRTXERR_INVALIDCALLBACK 0x08    // supplied callback function address is zero
  77. #define HRTXERR_BADWAKE         0x09    // faulty wakeup
  78.  
  79. ///////////////////////////////////////////////////////////////////////////////
  80. // HRTX Versioning macros
  81. //
  82. // These are identical to those defined for the original TIMER0 and are here for
  83. // compatibility only. New code should use the HRTXxxxx_X_QUERYVERSION call
  84.  
  85. #define HRTVER_MAJOR(ver)     (((ver) & 0xC000) >> 14)
  86. #define HRTVER_MINOR(ver)     (((ver) & 0x3C00) >> 10)
  87. #define HRTVER_BUGFIX(ver)    (((ver) & 0x03C0) >> 6)
  88. #define HRTVER_PHASE(ver)     (((ver) & 0x0030) >> 4)
  89. #define HRTVER_BUILD(ver)     ((ver) & 0x000F)
  90.  
  91. #define HRTVER_DEVELOP        0
  92. #define HRTVER_ALPHA          1
  93. #define HRTVER_BETA           2
  94. #define HRTVER_RELEASE        3
  95.  
  96. /////////////////////////////
  97. // Ordered IOCtl functions //
  98. /////////////////////////////
  99.  
  100. ///////////////////////////////////////////////////////////////////////////////
  101. // IOCtl: 0x80  fctn 00:        HRTXIOCTL_QUERYVERSION
  102. //
  103. // Returns a composite version number
  104. //
  105. // ParmPacket:
  106. //
  107. // DataPacket: ULONG - version number to be returned
  108. //
  109. ///////////////////////////////////////////////////////////////////////////////
  110.  
  111. #define HRTXIOCTL_QUERYVERSION          0x00
  112.  
  113. ///////////////////////////////////////////////////////////////////////////////
  114. // IOCtl: 0x80  fctn 01:        HRTXIOCTL_GETRESOLUTION
  115. //
  116. // Returns the current timer resolution.
  117. //
  118. // ParmPacket:
  119. //
  120. // DataPacket: ULONG - resolution to be returned
  121. //
  122. ///////////////////////////////////////////////////////////////////////////////
  123.  
  124. #define HRTXIOCTL_GETRESOLUTION         0x01
  125.  
  126. ///////////////////////////////////////////////////////////////////////////////
  127. // IOCtl: 0x80  fctn 02:        HRTXIOCTL_SETRESOLUTION
  128. //
  129. // Sets the current timer resolution
  130. //
  131. // ParmPacket: ULONG containing timer resolution
  132. //
  133. // DataPacket:
  134. //
  135. ///////////////////////////////////////////////////////////////////////////////
  136.  
  137. #define HRTXIOCTL_SETRESOLUTION         0x02
  138.  
  139. ///////////////////////////////////////////////////////////////////////////////
  140. // IOCtl: 0x80  fctn 03:        HRTXIOCTL_GETPOINTER
  141. //
  142. // Returns a FAR16 (yeuch!) pointer to the timer count.
  143. // Use HRTXxxxx_X_QUERYCOUNTADDR for something a little more friendly..
  144. //
  145. // ParmPacket:
  146. //
  147. // DataPacket: pointer to FAR16 pointer to master millisecond count
  148. //
  149. ///////////////////////////////////////////////////////////////////////////////
  150.  
  151. #define HRTXIOCTL_GETPOINTER            0x03
  152.  
  153. ///////////////////////////////////////////////////////////////////////////////
  154. // IOCtl: 0x80  fctn 04:        HRTXIOCTL_FREEPOINTER
  155. //
  156. // Provided for compatibility reasons only - this function has no effect
  157. //
  158. // ParmPacket: none
  159. //
  160. // DataPacket: none
  161. //
  162. ///////////////////////////////////////////////////////////////////////////////
  163.  
  164. #define HRTXIOCTL_FREEPOINTER           0x04
  165.  
  166. ///////////////////////////////////////////////////////////////////////////////
  167. // IOCtl: 0x80  fctn 05:        HRTXIOCTL_BLOCKUNTIL
  168. //
  169. // Block the thread until the specified time has elapsed
  170. //
  171. // ParmPacket: ULONG containing time in ms to wait
  172. //
  173. // DataPacket:
  174. //
  175. ///////////////////////////////////////////////////////////////////////////////
  176.  
  177. #define HRTXIOCTL_BLOCKUNTIL            0x05
  178.  
  179. ///////////////////////////
  180. // Ordered IDC functions //
  181. ///////////////////////////
  182.  
  183. ///////////////////////////////////////////////////////////////////////////////
  184. // IDC:         fctn 00:        HRTXIDC_REGISTER
  185. //
  186. // Register a PDD with the extended high-resolution timer
  187. //
  188. // Parm1: FAR16 - Address of callback function
  189. //
  190. // Parm2: ULONG - Callback repeat time
  191. //
  192. ///////////////////////////////////////////////////////////////////////////////
  193.  
  194. #define HRTXIDC_REGISTER                0x00
  195.  
  196. ///////////////////////////////////////////////////////////////////////////////
  197. // IDC:         fctn 01:        HRTXIDC_DEREGISTER
  198. //
  199. // Deregister a PDD with the extended high-resolution timer
  200. //
  201. // Parm1: unused
  202. //
  203. // Parm2: unused
  204. //
  205. ///////////////////////////////////////////////////////////////////////////////
  206.  
  207. #define HRTXIDC_DEREGISTER              0x01
  208.  
  209. ///////////////////////////////////////////////////////////////////////////////
  210. // IDC:         fctn 02:        HRTXIDC_GETPOINTER
  211. //
  212. // Returns a FAR16 pointer to the timer count variable
  213. //
  214. // Parm1: FAR16 pointer to location to receive address of master ms count
  215. //
  216. // Parm2:
  217. //
  218. ///////////////////////////////////////////////////////////////////////////////
  219.  
  220. #define HRTXIDC_GETPOINTER              0x02
  221.  
  222.  
  223.  
  224. ///////////////////////////////////////////////////////////////////////////////
  225. // EXTENDED HRTX API IOCTLS and IDC functions
  226. //
  227. // All extended API calls are accessible from
  228. // both ring 3 and ring 0
  229. //
  230. // This API set is handle-based. When a timer is registered a handle is
  231. // returned, with which that particular timer may be accessed from any time,
  232. // any place, any where including IRQ. ( Martini timer :) )
  233. //
  234. // Each timer is encapsulated, so any operations on one client will not
  235. // affect any of the others.
  236. //
  237.  
  238.  
  239. ///////////////////////////////////////////////////////////////////////////////
  240. // IOCTL: 0x80  fctn 06         HRTXIOCTL_X_QUERYVERSION
  241. // IDC:         fctn 03         HRTXIDC_X_QUERYVERSION
  242. //
  243. // Fills the provided memory with the contents of the device version block as
  244. // defined in the VER structure
  245. //
  246. // Parm1/ParmPacket (none) : unused
  247. //
  248. // Parm2/DataPacket (PVER) : VER structure to fill.
  249. //
  250. ///////////////////////////////////////////////////////////////////////////////
  251.  
  252. #define HRTXIOCTL_X_QUERYVERSION        0x06
  253. #define HRTXIDC_X_QUERYVERSION          0x03
  254.  
  255. ///////////////////////////////////////////////////////////////////////////////
  256. // IOCTL: 0x80  fctn 07         HRTXIOCTL_X_QUERYCOMPATHANDLE
  257. // IDC:         fctn 04         HRTXIDC_X_QUERYCOMPATHANDLE
  258. //
  259. // Returns the handle of the timer allocated by the compatibility API, if one
  260. // exists.
  261. //
  262. // Parm1/ParmPacket (none)   : unused
  263. // Parm2/DataPacket (PULONG) : Pointer to ULONG to receive the handle
  264. //
  265. ///////////////////////////////////////////////////////////////////////////////
  266.  
  267. #define HRTXIOCTL_X_QUERYCOMPATHANDLE   0x07
  268. #define HRTXIDC_X_QUERYCOMPATHANDLE     0x04
  269.  
  270. ///////////////////////////////////////////////////////////////////////////////
  271. // IOCTL: 0x80  fctn 08         HRTXIOCTL_X_CREATETIMER
  272. // IDC:         fctn 05         HRTXIDC_X_CREATETIMER
  273. //
  274. // Creates a new timer and returns the handle to it. If the timer is not
  275. // created an error is returned
  276. //
  277. // IDC:
  278. //
  279. //      Parm1 (FAR16)  : Address of callback function
  280. //      Parm2 (USHORT) : On entry this should contain the callback
  281. //                       interval. On exit it will contain the handle of the
  282. //                       timer
  283. //
  284. // IOCTL:
  285. //
  286. //      ParmPacket (none)   : unused
  287. //      DataPacket (PULONG) : Pointer to ULONG to receive the handle.
  288. //
  289. ///////////////////////////////////////////////////////////////////////////////
  290.  
  291. #define HRTXIOCTL_X_CREATETIMER         0x08
  292. #define HRTXIDC_X_CREATETIMER           0x05
  293.  
  294. ///////////////////////////////////////////////////////////////////////////////
  295. // IOCTL: 0x80  fctn 09         HRTXIOCTL_X_DESTROYTIMER
  296. // IDC:         fctn 06         HRTXIDC_X_DESTROYTIMER
  297. //
  298. // Destroys the timer referenced by the handle
  299. //
  300. //
  301. // Parm1/ParmPacket (ULONG) : Handle of timer to destroy
  302. // Parm2/DataPacket (none)  : unused
  303. //
  304. ///////////////////////////////////////////////////////////////////////////////
  305.  
  306. #define HRTXIOCTL_X_DESTROYTIMER        0x09
  307. #define HRTXIDC_X_DESTROYTIMER          0x06
  308.  
  309. ///////////////////////////////////////////////////////////////////////////////
  310. // IDC: 0x80    fctn 07         HRTXIOCTL_X_MODIFYCALLBACKTIMER
  311. //
  312. // Modifies the callback interval of a timer. Only useful from ring-0 where
  313. // callback functions are used
  314. //
  315. // Parm1 (ULONG) : Handle of timer
  316. // Parm2 (USHORT) : New callback interval
  317. //
  318. ///////////////////////////////////////////////////////////////////////////////
  319.  
  320. #define HRTXIDC_X_MODIFYCALLBACKTIMER   0x07
  321.  
  322. ///////////////////////////////////////////////////////////////////////////////
  323. // IOCTL: 0x80  fctn 0a         HRTXIOCTL_X_SETRESOLUTION
  324. // IDC:         fctn 08         HRTXIDC_X_SETRESOLUTION
  325. //
  326. // Sets the resolution of the timer specified by the handle. Currently this
  327. // can be 1 (1ms resampled) or -1 (1/1024 s)
  328. //
  329. // Parm1/ParmPacket (ULONG) : Handle of timer
  330. // Parm2/DataPacket (ULONG) : Resolution to set
  331. //
  332. ///////////////////////////////////////////////////////////////////////////////
  333.  
  334. #define HRTXIOCTL_X_SETRESOLUTION       0x0a
  335. #define HRTXIDC_X_SETRESOLUTION         0x08
  336.  
  337. ///////////////////////////////////////////////////////////////////////////////
  338. // IOCTL: 0x80  fctn 0b         HRTXIOCTL_X_GETRESOLUTION
  339. // IDC:         fctn 09         HRTXIDC_X_GETRESOLUTION
  340. //
  341. // Returns the resolution of the timer specified by the handle
  342. //
  343. // Parm1/ParmPacket (ULONG) : Handle of timer
  344. // Parm2/DataPacket (PULONG): ULONG into which to place resolution
  345. //
  346. ///////////////////////////////////////////////////////////////////////////////
  347.  
  348. #define HRTXIOCTL_X_GETRESOLUTION       0x0b
  349. #define HRTXIDC_X_GETRESOLUTION         0x09
  350.  
  351. ///////////////////////////////////////////////////////////////////////////////
  352. // IOCTL: 0x80  fctn 0c         HRTXIOCTL_X_BLOCKTHREAD
  353. // IDC:         fctn 0a         HRTXIDC_X_BLOCKTHREAD
  354. //
  355. // Blocks the calling thread for a given length of time. This function will
  356. // return an error if called in an interrupt context
  357. //
  358. // Parm1/ParmPacket (ULONG) : Handle of timer
  359. // Parm2/DataPacket (ULONG) : Time to block for
  360. //
  361. ///////////////////////////////////////////////////////////////////////////////
  362.  
  363. #define HRTXIOCTL_X_BLOCKTHREAD         0x0c
  364. #define HRTXIDC_X_BLOCKTHREAD           0x0a
  365.  
  366. ///////////////////////////////////////////////////////////////////////////////
  367. // IOCTL: 0x80  fctn 0d         HRTXIOCTL_X_QUERYCOUNTADDR
  368. // IDC:         fctn 0a         HRTXIDC_X_QUERYCOUNTADDR
  369. //
  370. // Returns an address to the timer count variable for the specified timer.
  371. // For the IOCTL - returns a linear address
  372. // For the IDC   - returns a FAR16 address
  373. //
  374. // Parm1/ParmPacket (ULONG)  : Handle of timer
  375. // Parm2/DataPacket (PULONG) : Pointer to a DWORD location to receive the
  376. //                             address
  377. //
  378. ///////////////////////////////////////////////////////////////////////////////
  379.  
  380. #define HRTXIOCTL_X_QUERYCOUNTADDR      0x0d
  381. #define HRTXIDC_X_QUERYCOUNTADDR        0x0b
  382.  
  383. #ifdef __cplusplus
  384. }
  385. #endif
  386.  
  387.  
  388. //////////////////////
  389. // end of SHARED.H  //
  390. //////////////////////
  391.  
  392. #endif
  393.  
  394.