settimer.c
2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/**************************************************************************
* *
* Copyright (C) 1994, Silicon Graphics, Inc. *
* *
* These coded instructions, statements, and computer programs contain *
* unpublished proprietary information of Silicon Graphics, Inc., and *
* are protected by Federal copyright law. They may not be disclosed *
* to third parties or copied or duplicated in any form, in whole or *
* in part, without the prior written consent of Silicon Graphics, Inc. *
* *
**************************************************************************/
#include <rmon.h>
#include "osint.h"
#include "viint.h"
/*
* This routine initializes the timer structure and starts the timer t.
* It implements both count-down timer and interval timer.
* If value is non-zero, it indicates the time to the next timer expiration.
* If interval is non-zero, it specifies a value to be used in reloading
* value when the timer expires.
*/
int
osSetTimer(OSTimer *t, OSTime value, OSTime interval, OSMesgQueue *mq,
OSMesg msg)
{
OSTime tim;
#if 1
OSTimer *temp;
u32 count, elapsed_cycles;
u32 savedMask;
#endif
#ifdef _DEBUG
/* Check that VI manager is running */
if (!__osViDevMgr.active) {
__osError(ERR_OSSETTIMER, 0);
return(0);
}
#endif
/* Initialize timer structure */
t->next = (OSTimer *)NULL;
t->prev = (OSTimer *)NULL;
t->interval = interval;
t->value = (value? value : interval);
t->mq = mq;
t->msg = msg;
#if 0
/* insert timer structure to timer list */
tim = __osInsertTimer(t);
/*
* If we've just put something at the head of the list,
* insure that a timer will go off at the right moment.
*/
if (__osTimerList->next == t)
__osSetTimerIntr(tim);
#else
savedMask = __osDisableInt();
/* insert timer structure to timer list */
if (__osTimerList->next == __osTimerList) {
;
}
else {
temp = __osTimerList->next;
count = osGetCount();
elapsed_cycles = count - __osTimerCounter;
/* Have enough ticks gone by since timer was set? */
if ((OSTime)elapsed_cycles < temp->value) {
/* not yet ready for next item on list */
temp->value -= (OSTime)elapsed_cycles;
} else {
temp->value = (OSTime)1;
/* error */
}
}
tim = __osInsertTimer(t);
/*
* If we've just put something at the head of the list,
* insure that a timer will go off at the right moment.
*/
__osSetTimerIntr(__osTimerList->next->value);
__osRestoreInt(savedMask);
#endif
return(0);
}