1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13:
14:
15: 16: 17: 18:
19:
20: #ifndef _TIMER_
21: #define _TIMER_
22:
23: #include <longlong.h>
24:
25: 26: 27:
28: #define to_msec(usec) ( ((usec) + (D)999) / 1000 )
29: #define to_usec(msec) ( (msec) * (D)1000 )
30:
31: #define to_usec_tmo(ms) ( ( (ms) > 0 )? to_usec(ms): (ms) )
32:
33: 34: 35:
36: typedef longlong LSYSTIM;
37:
38: Inline LSYSTIM toLSYSTIM( CONST SYSTIM *time )
39: {
40: LSYSTIM ltime;
41:
42: hilo_ll(ltime, time->hi, time->lo);
43:
44:
45: ltime = li_mul(ltime, 1000);
46:
47: return ltime;
48: }
49:
50: Inline SYSTIM toSYSTIM( LSYSTIM ltime, UINT *us )
51: {
52: SYSTIM time;
53: longlong t;
54:
55:
56: t = li_div(ltime, 1000);
57:
58: if ( us != NULL ) {
59:
60: *us = lltol(ll_sub(ltime, li_mul(t, 1000)));
61: }
62:
63: ll_hilo(time.hi, time.lo, t);
64:
65: return time;
66: }
67:
68: 69: 70:
71: typedef void (*CBACK)(void*);
72:
73: typedef struct timer_event_block {
74: QUEUE queue;
75: LSYSTIM time;
76: CBACK callback;
77: void *arg;
78: } TMEB;
79:
80: 81: 82:
83: IMPORT RELTIM_U TIMER_PERIOD;
84:
85: 86: 87:
88: IMPORT LSYSTIM current_time;
89: IMPORT LSYSTIM real_time_ofs;
90:
91:
92: #define real_time() ( ll_add(current_time, real_time_ofs) )
93:
94: 95: 96:
97: IMPORT ER timer_initialize( void );
98: IMPORT void timer_shutdown( void );
99:
100: 101: 102:
103: IMPORT RELTIM_U adjust_time( void );
104:
105: 106: 107:
108: IMPORT void timer_insert( TMEB *evt, TMO_U tmout, CBACK cback, void *arg );
109: IMPORT void timer_insert_reltim( TMEB *event, RELTIM_U tmout, CBACK callback, void *arg );
110: IMPORT void timer_insert_abs( TMEB *evt, LSYSTIM time, CBACK cback, void *arg );
111:
112: 113: 114:
115: Inline void timer_delete( TMEB *event )
116: {
117: QueRemove(&event->queue);
118: }
119:
120: #endif