ASCII Serial Com
Serial communication library between computers, microcontrollers, FPGAs, etc. Uses only ASCII. Not the most efficient protocol, but meant to be easy to read
Loading...
Searching...
No Matches
test_millisec_timer.c
1#include "externals/unity.h"
2#include "millisec_timer.h"
3#include <stdio.h>
4
5#define MAXVAL 0xFFFFFFFF
6
7void setUp(void) {}
8
9void tearDown(void) {}
10
11void test_millisec_timer_not_wrap_once(void) {
12 millisec_timer timer;
13
14 ////////////////////////////////////////////////////
15
16 millisec_timer_set_rel(&timer, 0, 0);
17 TEST_ASSERT_TRUE(millisec_timer_is_expired(&timer, 0));
18
19 millisec_timer_set_rel(&timer, 0, 0);
20 TEST_ASSERT_TRUE(millisec_timer_is_expired(&timer, 1));
21
22 millisec_timer_set_rel(&timer, 0, 0);
23 TEST_ASSERT_TRUE(millisec_timer_is_expired(&timer, MAXVAL));
24
25 ////////////////////////////////////////////////////
26
27 millisec_timer_set_rel(&timer, 0, 1);
28 TEST_ASSERT_FALSE(millisec_timer_is_expired(&timer, 0));
29 TEST_ASSERT_TRUE(millisec_timer_is_expired(&timer, 1));
30 TEST_ASSERT_FALSE(millisec_timer_is_expired(&timer, 1));
31
32 millisec_timer_set_rel(&timer, 0, 1);
33 TEST_ASSERT_TRUE(millisec_timer_is_expired(&timer, 1));
34 TEST_ASSERT_FALSE(millisec_timer_is_expired(&timer, 1));
35
36 millisec_timer_set_rel(&timer, 0, 1);
37 TEST_ASSERT_TRUE(millisec_timer_is_expired(&timer, 2));
38 TEST_ASSERT_FALSE(millisec_timer_is_expired(&timer, 2));
39
40 ////////////////////////////////////////////////////
41
42 millisec_timer_set_rel(&timer, 0, 5000);
43 TEST_ASSERT_FALSE(millisec_timer_is_expired(&timer, 0));
44 TEST_ASSERT_FALSE(millisec_timer_is_expired(&timer, 5));
45 TEST_ASSERT_FALSE(millisec_timer_is_expired(&timer, 4999));
46 TEST_ASSERT_TRUE(millisec_timer_is_expired(&timer, 5000));
47 TEST_ASSERT_FALSE(millisec_timer_is_expired(&timer, 5000));
48 TEST_ASSERT_FALSE(millisec_timer_is_expired(&timer, 5001));
49 millisec_timer_set_rel(&timer, 0, 5000);
50 TEST_ASSERT_TRUE(millisec_timer_is_expired(&timer, 5000));
51 millisec_timer_set_rel(&timer, 0, 5000);
52 TEST_ASSERT_TRUE(millisec_timer_is_expired(&timer, 5001));
53
54 ////////////////////////////////////////////////////
55
56 millisec_timer_set_rel(&timer, 0, MAXVAL - 1);
57 TEST_ASSERT_FALSE(millisec_timer_is_expired(&timer, 0));
58 TEST_ASSERT_FALSE(millisec_timer_is_expired(&timer, 1));
59 TEST_ASSERT_FALSE(millisec_timer_is_expired(&timer, MAXVAL - 2));
60 TEST_ASSERT_TRUE(millisec_timer_is_expired(&timer, MAXVAL - 1));
61 TEST_ASSERT_FALSE(millisec_timer_is_expired(&timer, MAXVAL));
62 millisec_timer_set_rel(&timer, 0, MAXVAL - 1);
63 TEST_ASSERT_TRUE(millisec_timer_is_expired(&timer, MAXVAL));
64 TEST_ASSERT_FALSE(millisec_timer_is_expired(&timer, MAXVAL));
65
66 ////////////////////////////////////////////////////
67
68 millisec_timer_set_rel(&timer, 0, MAXVAL);
69 TEST_ASSERT_FALSE(millisec_timer_is_expired(&timer, 0));
70 TEST_ASSERT_FALSE(millisec_timer_is_expired(&timer, 1));
71 TEST_ASSERT_FALSE(millisec_timer_is_expired(&timer, MAXVAL - 2));
72 TEST_ASSERT_FALSE(millisec_timer_is_expired(&timer, MAXVAL - 1));
73 TEST_ASSERT_TRUE(millisec_timer_is_expired(&timer, MAXVAL));
74 TEST_ASSERT_FALSE(millisec_timer_is_expired(&timer, MAXVAL));
75
76 ////////////////////////////////////////////////////
77 ////////////////////////////////////////////////////
78
79 millisec_timer_set_rel(&timer, 5000, 0);
80 TEST_ASSERT_TRUE(millisec_timer_is_expired(&timer, MAXVAL));
81 TEST_ASSERT_FALSE(millisec_timer_is_expired(&timer, MAXVAL));
82 millisec_timer_set_rel(&timer, 5000, 0);
83 TEST_ASSERT_TRUE(millisec_timer_is_expired(&timer, 0));
84 TEST_ASSERT_FALSE(millisec_timer_is_expired(&timer, MAXVAL));
85 millisec_timer_set_rel(&timer, 5000, 0);
86 TEST_ASSERT_TRUE(millisec_timer_is_expired(&timer, 5000));
87 TEST_ASSERT_FALSE(millisec_timer_is_expired(&timer, MAXVAL));
88
89 ////////////////////////////////////////////////////
90
91 millisec_timer_set_rel(&timer, 5000, MAXVAL - 5000);
92 TEST_ASSERT_FALSE(millisec_timer_is_expired(&timer, 5000));
93 TEST_ASSERT_FALSE(millisec_timer_is_expired(&timer, MAXVAL - 1));
94 TEST_ASSERT_TRUE(millisec_timer_is_expired(&timer, MAXVAL));
95 TEST_ASSERT_FALSE(millisec_timer_is_expired(&timer, MAXVAL));
96 millisec_timer_set_rel(&timer, 5000, MAXVAL - 5000);
97 TEST_ASSERT_TRUE(
98 millisec_timer_is_expired(&timer, 0)); // is sortof wrap around
99 TEST_ASSERT_FALSE(millisec_timer_is_expired(&timer, 0));
100
101 ////////////////////////////////////////////////////
102 // all sortof wrap around
103
104 millisec_timer_set_rel(&timer, MAXVAL, 0);
105 TEST_ASSERT_TRUE(millisec_timer_is_expired(&timer, MAXVAL));
106 TEST_ASSERT_FALSE(millisec_timer_is_expired(&timer, MAXVAL));
107 millisec_timer_set_rel(&timer, MAXVAL, 0);
108 TEST_ASSERT_TRUE(millisec_timer_is_expired(&timer, 0));
109 TEST_ASSERT_FALSE(millisec_timer_is_expired(&timer, MAXVAL));
110 millisec_timer_set_rel(&timer, MAXVAL, 0);
111 TEST_ASSERT_TRUE(millisec_timer_is_expired(&timer, 5000));
112 TEST_ASSERT_FALSE(millisec_timer_is_expired(&timer, MAXVAL));
113}
114
115void test_millisec_timer_do_wrap_once(void) {
116 millisec_timer timer;
117
118 ////////////////////////////////////////////////////
119
120 millisec_timer_set_rel(&timer, 1, MAXVAL);
121 TEST_ASSERT_EQUAL_UINT32_MESSAGE(
122 1, timer.set_time,
123 "Checking the test is what it should be, not an error with millisec "
124 "timer but with the test");
125 TEST_ASSERT_EQUAL_UINT32_MESSAGE(
126 0, timer.expire_time,
127 "Checking the test is what it should be, not an error with millisec "
128 "timer but with the test");
129 TEST_ASSERT_FALSE(millisec_timer_is_expired(&timer, 1));
130 TEST_ASSERT_FALSE(millisec_timer_is_expired(&timer, 2));
131 TEST_ASSERT_FALSE(millisec_timer_is_expired(&timer, MAXVAL));
132 TEST_ASSERT_TRUE(millisec_timer_is_expired(&timer, 0));
133 TEST_ASSERT_FALSE(millisec_timer_is_expired(&timer, 0));
134
135 ////////////////////////////////////////////////////
136
137 millisec_timer_set_rel(&timer, 2, MAXVAL);
138 TEST_ASSERT_EQUAL_UINT32_MESSAGE(
139 2, timer.set_time,
140 "Checking the test is what it should be, not an error with millisec "
141 "timer but with the test");
142 TEST_ASSERT_EQUAL_UINT32_MESSAGE(
143 1, timer.expire_time,
144 "Checking the test is what it should be, not an error with millisec "
145 "timer but with the test");
146 TEST_ASSERT_FALSE(millisec_timer_is_expired(&timer, 2));
147 TEST_ASSERT_FALSE(millisec_timer_is_expired(&timer, 3));
148 TEST_ASSERT_FALSE(millisec_timer_is_expired(&timer, MAXVAL));
149 TEST_ASSERT_FALSE(millisec_timer_is_expired(&timer, 0));
150 TEST_ASSERT_TRUE(millisec_timer_is_expired(&timer, 1));
151 TEST_ASSERT_FALSE(millisec_timer_is_expired(&timer, 1));
152
153 ////////////////////////////////////////////////////
154
155 millisec_timer_set_rel(&timer, MAXVAL - 1, 2);
156 TEST_ASSERT_EQUAL_UINT32_MESSAGE(
157 MAXVAL - 1, timer.set_time,
158 "Checking the test is what it should be, not an error with millisec "
159 "timer but with the test");
160 TEST_ASSERT_EQUAL_UINT32_MESSAGE(
161 0, timer.expire_time,
162 "Checking the test is what it should be, not an error with millisec "
163 "timer but with the test");
164 TEST_ASSERT_FALSE(millisec_timer_is_expired(&timer, MAXVAL - 1));
165 TEST_ASSERT_FALSE(millisec_timer_is_expired(&timer, MAXVAL));
166 TEST_ASSERT_TRUE(millisec_timer_is_expired(&timer, 0));
167 TEST_ASSERT_FALSE(millisec_timer_is_expired(&timer, 0));
168 millisec_timer_set_rel(&timer, MAXVAL - 1, 2);
169 TEST_ASSERT_TRUE(millisec_timer_is_expired(&timer, 1));
170 TEST_ASSERT_FALSE(millisec_timer_is_expired(&timer, 1));
171 millisec_timer_set_rel(&timer, MAXVAL - 1, 2);
172 TEST_ASSERT_TRUE(millisec_timer_is_expired(&timer, MAXVAL - 2));
173 TEST_ASSERT_FALSE(millisec_timer_is_expired(&timer, MAXVAL - 2));
174
175 ////////////////////////////////////////////////////
176
177 millisec_timer_set_rel(&timer, MAXVAL, 1);
178 TEST_ASSERT_EQUAL_UINT32_MESSAGE(
179 MAXVAL, timer.set_time,
180 "Checking the test is what it should be, not an error with millisec "
181 "timer but with the test");
182 TEST_ASSERT_EQUAL_UINT32_MESSAGE(
183 0, timer.expire_time,
184 "Checking the test is what it should be, not an error with millisec "
185 "timer but with the test");
186 TEST_ASSERT_FALSE(millisec_timer_is_expired(&timer, MAXVAL));
187 TEST_ASSERT_TRUE(millisec_timer_is_expired(&timer, 0));
188 TEST_ASSERT_FALSE(millisec_timer_is_expired(&timer, 0));
189 millisec_timer_set_rel(&timer, MAXVAL, 1);
190 TEST_ASSERT_TRUE(millisec_timer_is_expired(&timer, 1));
191 TEST_ASSERT_FALSE(millisec_timer_is_expired(&timer, 1));
192 millisec_timer_set_rel(&timer, MAXVAL, 1);
193 TEST_ASSERT_TRUE(millisec_timer_is_expired(&timer, MAXVAL - 1));
194 TEST_ASSERT_FALSE(millisec_timer_is_expired(&timer, MAXVAL - 1));
195
196 ////////////////////////////////////////////////////
197
198 millisec_timer_set_rel(&timer, MAXVAL, 2);
199 TEST_ASSERT_EQUAL_UINT32_MESSAGE(
200 MAXVAL, timer.set_time,
201 "Checking the test is what it should be, not an error with millisec "
202 "timer but with the test");
203 TEST_ASSERT_EQUAL_UINT32_MESSAGE(
204 1, timer.expire_time,
205 "Checking the test is what it should be, not an error with millisec "
206 "timer but with the test");
207 TEST_ASSERT_FALSE(millisec_timer_is_expired(&timer, MAXVAL));
208 TEST_ASSERT_FALSE(millisec_timer_is_expired(&timer, 0));
209 TEST_ASSERT_TRUE(millisec_timer_is_expired(&timer, 1));
210 TEST_ASSERT_FALSE(millisec_timer_is_expired(&timer, 1));
211 millisec_timer_set_rel(&timer, MAXVAL, 2);
212 TEST_ASSERT_TRUE(millisec_timer_is_expired(&timer, 2));
213 TEST_ASSERT_FALSE(millisec_timer_is_expired(&timer, 2));
214 millisec_timer_set_rel(&timer, MAXVAL, 2);
215 TEST_ASSERT_TRUE(millisec_timer_is_expired(&timer, MAXVAL - 1));
216 TEST_ASSERT_FALSE(millisec_timer_is_expired(&timer, MAXVAL - 1));
217}
218
219void test_millisec_timer_not_wrap_repeat(void) {
220 millisec_timer timer;
221
222 ////////////////////////////////////////////////////
223
224 millisec_timer_set_rel(&timer, 0, 0);
225 TEST_ASSERT_TRUE(millisec_timer_is_expired_repeat(&timer, 0));
226 TEST_ASSERT_TRUE(millisec_timer_is_expired_repeat(&timer, 0));
227 TEST_ASSERT_TRUE(millisec_timer_is_expired_repeat(&timer, 0));
228
229 millisec_timer_set_rel(&timer, 0, 0);
230 TEST_ASSERT_TRUE(millisec_timer_is_expired_repeat(&timer, 1));
231 TEST_ASSERT_TRUE(millisec_timer_is_expired_repeat(&timer, 1));
232 TEST_ASSERT_TRUE(millisec_timer_is_expired_repeat(&timer, 1));
233
234 millisec_timer_set_rel(&timer, 0, 0);
235 TEST_ASSERT_TRUE(millisec_timer_is_expired_repeat(&timer, MAXVAL));
236 TEST_ASSERT_TRUE(millisec_timer_is_expired_repeat(&timer, MAXVAL));
237 TEST_ASSERT_TRUE(millisec_timer_is_expired_repeat(&timer, MAXVAL));
238
239 ////////////////////////////////////////////////////
240
241 millisec_timer_set_rel(&timer, 0, 1);
242 TEST_ASSERT_FALSE(millisec_timer_is_expired_repeat(&timer, 0));
243 TEST_ASSERT_TRUE(millisec_timer_is_expired_repeat(&timer, 1));
244 TEST_ASSERT_FALSE(millisec_timer_is_expired_repeat(&timer, 1));
245 TEST_ASSERT_TRUE(millisec_timer_is_expired_repeat(&timer, 2));
246 TEST_ASSERT_FALSE(millisec_timer_is_expired_repeat(&timer, 2));
247 TEST_ASSERT_TRUE(millisec_timer_is_expired_repeat(&timer, 3));
248 TEST_ASSERT_FALSE(millisec_timer_is_expired_repeat(&timer, 3));
249
250 millisec_timer_set_rel(&timer, 0, 1);
251 TEST_ASSERT_TRUE(millisec_timer_is_expired_repeat(&timer, 500));
252 TEST_ASSERT_TRUE(millisec_timer_is_expired_repeat(&timer, 500));
253 TEST_ASSERT_FALSE(millisec_timer_is_expired_repeat(&timer, 2));
254 TEST_ASSERT_TRUE(millisec_timer_is_expired_repeat(&timer, 3));
255 TEST_ASSERT_FALSE(millisec_timer_is_expired_repeat(&timer, 3));
256
257 millisec_timer_set_rel(&timer, 0, 1);
258 TEST_ASSERT_TRUE(millisec_timer_is_expired_repeat(&timer, MAXVAL));
259 TEST_ASSERT_FALSE(millisec_timer_is_expired_repeat(&timer, 1));
260
261 ////////////////////////////////////////////////////
262
263 millisec_timer_set_rel(&timer, 0, 5000);
264 TEST_ASSERT_FALSE(millisec_timer_is_expired_repeat(&timer, 0));
265 TEST_ASSERT_FALSE(millisec_timer_is_expired_repeat(&timer, 5));
266 TEST_ASSERT_FALSE(millisec_timer_is_expired_repeat(&timer, 4999));
267 TEST_ASSERT_TRUE(millisec_timer_is_expired_repeat(&timer, 5000));
268 TEST_ASSERT_FALSE(millisec_timer_is_expired_repeat(&timer, 5000));
269 TEST_ASSERT_FALSE(millisec_timer_is_expired_repeat(&timer, 5001));
270 TEST_ASSERT_TRUE(millisec_timer_is_expired_repeat(&timer, 10000));
271 TEST_ASSERT_FALSE(millisec_timer_is_expired_repeat(&timer, 10001));
272 TEST_ASSERT_TRUE(millisec_timer_is_expired_repeat(&timer, 15000));
273 TEST_ASSERT_FALSE(millisec_timer_is_expired_repeat(&timer, 15001));
274 TEST_ASSERT_TRUE(millisec_timer_is_expired_repeat(&timer, 30000));
275 TEST_ASSERT_FALSE(millisec_timer_is_expired_repeat(&timer, 24999));
276 TEST_ASSERT_TRUE(millisec_timer_is_expired_repeat(&timer, 30000));
277 millisec_timer_set_rel(&timer, 0, 5000);
278 TEST_ASSERT_TRUE(millisec_timer_is_expired_repeat(&timer, 5000));
279 millisec_timer_set_rel(&timer, 0, 5000);
280 TEST_ASSERT_TRUE(millisec_timer_is_expired_repeat(&timer, 5001));
281
282 ////////////////////////////////////////////////////
283
284 millisec_timer_set_rel(&timer, 0, MAXVAL - 1);
285 TEST_ASSERT_FALSE(millisec_timer_is_expired_repeat(&timer, 0));
286 TEST_ASSERT_FALSE(millisec_timer_is_expired_repeat(&timer, 1));
287 TEST_ASSERT_FALSE(millisec_timer_is_expired_repeat(&timer, MAXVAL - 2));
288 TEST_ASSERT_TRUE(millisec_timer_is_expired_repeat(&timer, MAXVAL - 1));
289 TEST_ASSERT_FALSE(millisec_timer_is_expired_repeat(&timer, MAXVAL));
290 millisec_timer_set_rel(&timer, 0, MAXVAL - 1);
291 TEST_ASSERT_TRUE(millisec_timer_is_expired_repeat(&timer, MAXVAL));
292 TEST_ASSERT_FALSE(millisec_timer_is_expired_repeat(&timer, MAXVAL));
293
294 ////////////////////////////////////////////////////
295
296 millisec_timer_set_rel(&timer, 0, MAXVAL);
297 TEST_ASSERT_FALSE(millisec_timer_is_expired_repeat(&timer, 0));
298 TEST_ASSERT_FALSE(millisec_timer_is_expired_repeat(&timer, 1));
299 TEST_ASSERT_FALSE(millisec_timer_is_expired_repeat(&timer, MAXVAL - 2));
300 TEST_ASSERT_FALSE(millisec_timer_is_expired_repeat(&timer, MAXVAL - 1));
301 TEST_ASSERT_TRUE(millisec_timer_is_expired_repeat(&timer, MAXVAL));
302 // now we've wrapped around
303 TEST_ASSERT_EQUAL_UINT32_MESSAGE(
304 MAXVAL, timer.set_time,
305 "Checking the test is what it should be, not an error with millisec "
306 "timer but with the test");
307 TEST_ASSERT_EQUAL_UINT32_MESSAGE(
308 MAXVAL - 1, timer.expire_time,
309 "Checking the test is what it should be, not an error with millisec "
310 "timer but with the test");
311 TEST_ASSERT_FALSE(millisec_timer_is_expired_repeat(&timer, 0));
312 TEST_ASSERT_FALSE(millisec_timer_is_expired_repeat(&timer, 1));
313 TEST_ASSERT_FALSE(millisec_timer_is_expired_repeat(&timer, MAXVAL - 2));
314 TEST_ASSERT_TRUE(millisec_timer_is_expired_repeat(&timer, MAXVAL - 1));
315 TEST_ASSERT_EQUAL_UINT32_MESSAGE(
316 MAXVAL - 1, timer.set_time,
317 "Checking the test is what it should be, not an error with millisec "
318 "timer but with the test");
319 TEST_ASSERT_EQUAL_UINT32_MESSAGE(
320 MAXVAL - 2, timer.expire_time,
321 "Checking the test is what it should be, not an error with millisec "
322 "timer but with the test");
323 TEST_ASSERT_FALSE(millisec_timer_is_expired_repeat(&timer, MAXVAL));
324 TEST_ASSERT_FALSE(millisec_timer_is_expired_repeat(&timer, 0));
325 TEST_ASSERT_FALSE(millisec_timer_is_expired_repeat(&timer, 1));
326 TEST_ASSERT_FALSE(millisec_timer_is_expired_repeat(&timer, MAXVAL - 3));
327 TEST_ASSERT_TRUE(millisec_timer_is_expired_repeat(&timer, MAXVAL - 2));
328
329 ////////////////////////////////////////////////////
330 ////////////////////////////////////////////////////
331
332 millisec_timer_set_rel(&timer, 5000, 0);
333 TEST_ASSERT_TRUE(millisec_timer_is_expired_repeat(&timer, MAXVAL));
334 TEST_ASSERT_TRUE(millisec_timer_is_expired_repeat(&timer, 0));
335 TEST_ASSERT_TRUE(millisec_timer_is_expired_repeat(&timer, 5000));
336
337 ////////////////////////////////////////////////////
338
339 millisec_timer_set_rel(&timer, 5000, 5000);
340 TEST_ASSERT_FALSE(millisec_timer_is_expired_repeat(&timer, 5000));
341 TEST_ASSERT_FALSE(millisec_timer_is_expired_repeat(&timer, 9999));
342 TEST_ASSERT_TRUE(millisec_timer_is_expired_repeat(&timer, 10000));
343 TEST_ASSERT_FALSE(millisec_timer_is_expired_repeat(&timer, 10000));
344 TEST_ASSERT_FALSE(millisec_timer_is_expired_repeat(&timer, 14999));
345 TEST_ASSERT_TRUE(millisec_timer_is_expired_repeat(&timer, 15000));
346 TEST_ASSERT_FALSE(millisec_timer_is_expired_repeat(&timer, 19999));
347 TEST_ASSERT_TRUE(millisec_timer_is_expired_repeat(&timer, 20000));
348 TEST_ASSERT_TRUE(millisec_timer_is_expired_repeat(&timer, MAXVAL));
349 TEST_ASSERT_FALSE(millisec_timer_is_expired_repeat(&timer, 29999));
350 TEST_ASSERT_TRUE(millisec_timer_is_expired_repeat(&timer, 30000));
351
352 ////////////////////////////////////////////////////
353
354 millisec_timer_set_rel(&timer, 5000, MAXVAL - 5000);
355 TEST_ASSERT_FALSE(millisec_timer_is_expired_repeat(&timer, 5000));
356 TEST_ASSERT_FALSE(millisec_timer_is_expired_repeat(&timer, MAXVAL - 1));
357 TEST_ASSERT_TRUE(millisec_timer_is_expired_repeat(&timer, MAXVAL));
358 TEST_ASSERT_EQUAL_HEX32_MESSAGE(
359 MAXVAL, timer.set_time,
360 "Checking the test is what it should be, not an error with millisec "
361 "timer but with the test");
362 TEST_ASSERT_EQUAL_HEX32_MESSAGE(
363 2 * MAXVAL - 5000, timer.expire_time,
364 "Checking the test is what it should be, not an error with millisec "
365 "timer but with the test");
366 TEST_ASSERT_FALSE(millisec_timer_is_expired_repeat(&timer, MAXVAL));
367 TEST_ASSERT_FALSE(
368 millisec_timer_is_expired_repeat(&timer, 2 * MAXVAL - 5001));
369 TEST_ASSERT_TRUE(millisec_timer_is_expired_repeat(&timer, 2 * MAXVAL - 5000));
370}
371
372void test_millisec_timer_do_wrap_repeat(void) {
373 millisec_timer timer;
374
375 ////////////////////////////////////////////////////
376
377 millisec_timer_set_rel(&timer, 1, MAXVAL);
378 TEST_ASSERT_EQUAL_UINT32_MESSAGE(
379 1, timer.set_time,
380 "Checking the test is what it should be, not an error with millisec "
381 "timer but with the test");
382 TEST_ASSERT_EQUAL_UINT32_MESSAGE(
383 0, timer.expire_time,
384 "Checking the test is what it should be, not an error with millisec "
385 "timer but with the test");
386 TEST_ASSERT_FALSE(millisec_timer_is_expired_repeat(&timer, 1));
387 TEST_ASSERT_FALSE(millisec_timer_is_expired_repeat(&timer, 2));
388 TEST_ASSERT_FALSE(millisec_timer_is_expired_repeat(&timer, MAXVAL));
389 TEST_ASSERT_TRUE(millisec_timer_is_expired_repeat(&timer, 0));
390 TEST_ASSERT_EQUAL_HEX32_MESSAGE(
391 0, timer.set_time,
392 "Checking the test is what it should be, not an error with millisec "
393 "timer but with the test");
394 TEST_ASSERT_EQUAL_HEX32_MESSAGE(
395 MAXVAL, timer.expire_time,
396 "Checking the test is what it should be, not an error with millisec "
397 "timer but with the test");
398 TEST_ASSERT_FALSE(millisec_timer_is_expired_repeat(&timer, 1));
399 TEST_ASSERT_FALSE(millisec_timer_is_expired_repeat(&timer, 2));
400 TEST_ASSERT_FALSE(millisec_timer_is_expired_repeat(&timer, MAXVAL - 1));
401 TEST_ASSERT_TRUE(millisec_timer_is_expired_repeat(&timer, MAXVAL));
402
403 ////////////////////////////////////////////////////
404
405 millisec_timer_set_rel(&timer, 2, MAXVAL);
406 TEST_ASSERT_EQUAL_UINT32_MESSAGE(
407 2, timer.set_time,
408 "Checking the test is what it should be, not an error with millisec "
409 "timer but with the test");
410 TEST_ASSERT_EQUAL_UINT32_MESSAGE(
411 1, timer.expire_time,
412 "Checking the test is what it should be, not an error with millisec "
413 "timer but with the test");
414 TEST_ASSERT_FALSE(millisec_timer_is_expired_repeat(&timer, 2));
415 TEST_ASSERT_FALSE(millisec_timer_is_expired_repeat(&timer, 3));
416 TEST_ASSERT_FALSE(millisec_timer_is_expired_repeat(&timer, MAXVAL));
417 TEST_ASSERT_FALSE(millisec_timer_is_expired_repeat(&timer, 0));
418 TEST_ASSERT_TRUE(millisec_timer_is_expired_repeat(&timer, 1));
419 TEST_ASSERT_EQUAL_UINT32_MESSAGE(
420 1, timer.set_time,
421 "Checking the test is what it should be, not an error with millisec "
422 "timer but with the test");
423 TEST_ASSERT_EQUAL_UINT32_MESSAGE(
424 0, timer.expire_time,
425 "Checking the test is what it should be, not an error with millisec "
426 "timer but with the test");
427 TEST_ASSERT_FALSE(millisec_timer_is_expired_repeat(&timer, 1));
428 TEST_ASSERT_FALSE(millisec_timer_is_expired_repeat(&timer, 1));
429 TEST_ASSERT_FALSE(millisec_timer_is_expired_repeat(&timer, 2));
430 TEST_ASSERT_FALSE(millisec_timer_is_expired_repeat(&timer, MAXVAL));
431 TEST_ASSERT_TRUE(millisec_timer_is_expired_repeat(&timer, 0));
432
433 ////////////////////////////////////////////////////
434
435 millisec_timer_set_rel(&timer, MAXVAL - 1, 2);
436 TEST_ASSERT_EQUAL_UINT32_MESSAGE(
437 MAXVAL - 1, timer.set_time,
438 "Checking the test is what it should be, not an error with millisec "
439 "timer but with the test");
440 TEST_ASSERT_EQUAL_UINT32_MESSAGE(
441 0, timer.expire_time,
442 "Checking the test is what it should be, not an error with millisec "
443 "timer but with the test");
444 TEST_ASSERT_FALSE(millisec_timer_is_expired_repeat(&timer, MAXVAL - 1));
445 TEST_ASSERT_FALSE(millisec_timer_is_expired_repeat(&timer, MAXVAL));
446 TEST_ASSERT_TRUE(millisec_timer_is_expired_repeat(&timer, 0));
447 TEST_ASSERT_EQUAL_UINT32_MESSAGE(
448 0, timer.set_time,
449 "Checking the test is what it should be, not an error with millisec "
450 "timer but with the test");
451 TEST_ASSERT_EQUAL_UINT32_MESSAGE(
452 2, timer.expire_time,
453 "Checking the test is what it should be, not an error with millisec "
454 "timer but with the test");
455 TEST_ASSERT_FALSE(millisec_timer_is_expired_repeat(&timer, 0));
456 TEST_ASSERT_TRUE(millisec_timer_is_expired_repeat(&timer, 2));
457
458 millisec_timer_set_rel(&timer, MAXVAL - 1, 2);
459 TEST_ASSERT_TRUE(millisec_timer_is_expired_repeat(&timer, 1));
460 TEST_ASSERT_FALSE(millisec_timer_is_expired_repeat(&timer, 1));
461 TEST_ASSERT_TRUE(millisec_timer_is_expired_repeat(&timer, MAXVAL));
462 millisec_timer_set_rel(&timer, MAXVAL - 1, 2);
463 TEST_ASSERT_TRUE(millisec_timer_is_expired_repeat(&timer, MAXVAL - 2));
464}
465
466int main(void) {
467 UNITY_BEGIN();
468 RUN_TEST(test_millisec_timer_not_wrap_once);
469 RUN_TEST(test_millisec_timer_do_wrap_once);
470 RUN_TEST(test_millisec_timer_not_wrap_repeat);
471 RUN_TEST(test_millisec_timer_do_wrap_repeat);
472 return UNITY_END();
473}
void millisec_timer_set_rel(millisec_timer *timer, const millisec_timer_unit_t now, const millisec_timer_unit_t rel)
Set timer to expire in the future.
bool millisec_timer_is_expired_repeat(millisec_timer *timer, const millisec_timer_unit_t now)
Check if timer has expired & if so, re-enable for the same interval.
bool millisec_timer_is_expired(millisec_timer *timer, const millisec_timer_unit_t now)
Check if timer has expired & if so, disable it.
Portable millisecond timer.
portable millisecond timer