timer1.c
4.44 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#include <os.h>
#include <rmon.h>
#include <R4300.h>
#include "osprof.h"
/*
* timer1
*
* Tests for:
* osSetTimer
* osStopTimer
*
* Assumed working:
* osGetIntMask
* osCreateMesgQueue
* osRecvMessage
*
* Description:
* Setup couple of countdown timers and check that the messages are
* delivered when timers expire
* Check that countdown timers are not on the timer list anymore.
* Setup couple of interval timers and check that the messages are
* delivered every interval time
* Stop interval timer
* Check that message queue is empty
* Setup couple of interval and countdown timers and check that the
* message is delivered when countdown timer expire and the
* new messages are delivered every interval time
* Stop interval timer
* Check that message queue is empty
*/
#define NUM_MESSAGE 4
#define NUMBER_TIMER 3
static OSMesgQueue timerMesgQueue;
static OSMesg timerMesgBuf[NUM_MESSAGE];
static OSTimer mytimer[NUMBER_TIMER];
int
timer1(void)
{
OSMesg actualMesg, expectedMesg[NUMBER_TIMER];
int i = 0;
int j = 0;
int retValue;
int numFailures = 0;
u32 count1, count2;
/*
* Check out the Countdown timer.
*/
osCreateMesgQueue(&timerMesgQueue, timerMesgBuf, NUM_MESSAGE);
for (i= 0; i < NUMBER_TIMER; i++)
expectedMesg[0] = (OSMesg)i;
/* setup countdown timer */
rmonPrintf("Test countdown timer\n");
for (i= 0; i < NUMBER_TIMER; i++) {
osSetTimer(&mytimer[i], OS_USEC_TO_CYCLES(i*10+200), 0,
&timerMesgQueue, &expectedMesg[i]);
}
for (i= 0; i < NUMBER_TIMER; i++) {
(void)osRecvMesg(&timerMesgQueue, &actualMesg, OS_MESG_BLOCK);
if (&expectedMesg[i] != actualMesg) {
rmonPrintf("timer1: expected message 0x%x, actual 0x%x\n",
&expectedMesg[i], actualMesg);
numFailures++;
}
}
for (i= 0; i < NUMBER_TIMER; i++) {
retValue = osStopTimer(&mytimer[i]);
if (retValue != -1) {
rmonPrintf("timer1: Countdown timer should be removed after expired\n");
numFailures++;
}
}
/* setup interval timer */
rmonPrintf("Test interval timer\n");
for (i= 0; i < NUMBER_TIMER; i++) {
osSetTimer(&mytimer[i], 0, OS_USEC_TO_CYCLES(i*10+200),
&timerMesgQueue, &expectedMesg[i]);
}
for (i= 0,j=0; j < NUMBER_TIMER * 5 ; j++) {
(void)osRecvMesg(&timerMesgQueue, &actualMesg, OS_MESG_BLOCK);
if (&expectedMesg[i] != actualMesg) {
rmonPrintf("timer1: expected message 0x%x, actual 0x%x\n",
&expectedMesg[i], actualMesg);
numFailures++;
}
i++;
i = i % NUMBER_TIMER;
}
for (i= 0; i < NUMBER_TIMER; i++) {
retValue = osStopTimer(&mytimer[i]);
if (retValue) {
rmonPrintf("timer1: Interval timer should on the timer list\n");
numFailures++;
}
}
/*
* Verify that the message queue is now empty.
*/
retValue = osRecvMesg(&timerMesgQueue, &actualMesg, OS_MESG_NOBLOCK);
if (retValue != -1) {
rmonPrintf("timer1: expected return value %d, actual %d\n",
-1, retValue);
numFailures++;
}
/* setup interval timer and countdown timer */
rmonPrintf(" Test interval timer and countdown timer\n");
for (i= 0; i < NUMBER_TIMER; i++) {
osSetTimer(&mytimer[i], OS_USEC_TO_CYCLES((NUMBER_TIMER - i) *100),
i*10000+200000, &timerMesgQueue, &expectedMesg[i]);
}
/* check countdown timer first */
for (i= NUMBER_TIMER-1; i >= 0 ; i--) {
(void)osRecvMesg(&timerMesgQueue, &actualMesg, OS_MESG_BLOCK);
if (&expectedMesg[i] != actualMesg) {
rmonPrintf("timer1: expected message 0x%x, actual 0x%x\n",
&expectedMesg[i], actualMesg);
numFailures++;
}
}
for (i= 0,j=0; j < NUMBER_TIMER * 5 ; j++) {
(void)osRecvMesg(&timerMesgQueue, &actualMesg, OS_MESG_BLOCK);
if (&expectedMesg[i] != actualMesg) {
rmonPrintf("timer1: expected message 0x%x, actual 0x%x\n",
&expectedMesg[i], actualMesg);
numFailures++;
}
i++;
i = i % NUMBER_TIMER;
}
for (i= 0; i < NUMBER_TIMER; i++) {
retValue = osStopTimer(&mytimer[i]);
if (retValue) {
rmonPrintf("timer1: Interval timer should on the timer list\n");
numFailures++;
}
}
/*
* Verify that the message queue is now empty.
*/
retValue = osRecvMesg(&timerMesgQueue, &actualMesg, OS_MESG_NOBLOCK);
if (retValue != -1) {
rmonPrintf("timer1: expected return value %d, actual %d\n",
-1, retValue);
numFailures++;
}
return(numFailures);
}