@@ -53,12 +53,15 @@ static const int delta_sys_clk_us = ((int) (TOLERANCE_FACTOR / (float)SystemCore
53
53
#define DELTA_S ((float )delta_sys_clk_us/US_PER_SEC)
54
54
#define DELTA_MS 1
55
55
56
+ #define TICKER_FREQ_1MHZ 1000000
57
+ #define TICKER_BITS 32
58
+
56
59
static Timer *p_timer = NULL ;
57
60
58
61
/* Global variable used to simulate passage of time
59
62
* in case when timer which uses user ticker is tested.
60
63
*/
61
- static uint32_t curr_ticker_us_val ;
64
+ static uint32_t curr_ticker_ticks_val ;
62
65
63
66
/* User ticker interface function. */
64
67
static void stub_interface_init ()
@@ -71,7 +74,7 @@ static void stub_interface_init()
71
74
static uint32_t stub_ticker_read (void )
72
75
{
73
76
/* Simulate elapsed time. */
74
- return curr_ticker_us_val ;
77
+ return curr_ticker_ticks_val ;
75
78
}
76
79
77
80
/* User ticker interface function. */
@@ -98,6 +101,14 @@ static void stub_fire_interrupt(void)
98
101
/* do nothing. */
99
102
}
100
103
104
+ ticker_info_t info =
105
+ { TICKER_FREQ_1MHZ, TICKER_BITS };
106
+
107
+ const ticker_info_t * stub_get_info (void )
108
+ {
109
+ return &info;
110
+ }
111
+
101
112
/* User ticker event queue. */
102
113
static ticker_event_queue_t my_events = { 0 };
103
114
@@ -109,6 +120,7 @@ static const ticker_interface_t us_interface = {
109
120
.clear_interrupt = stub_clear_interrupt,
110
121
.set_interrupt = stub_set_interrupt,
111
122
.fire_interrupt = stub_fire_interrupt,
123
+ .get_info = stub_get_info,
112
124
};
113
125
114
126
/* User ticker data structure. */
@@ -195,7 +207,7 @@ void test_timer_creation_os_ticker()
195
207
* creation.
196
208
*
197
209
* Note: this function assumes that Timer uses user/fake ticker
198
- * which returns time value provided in curr_ticker_us_val
210
+ * which returns time value provided in curr_ticker_ticks_val
199
211
* global variable.
200
212
*
201
213
* Given Timer has been successfully created.
@@ -206,7 +218,7 @@ void test_timer_creation_user_ticker()
206
218
{
207
219
/* For timer which is using user ticker simulate timer
208
220
* creation time (irrelevant in case of os ticker). */
209
- curr_ticker_us_val = 10000 ;
221
+ curr_ticker_ticks_val = 10000 ;
210
222
211
223
/* Check results. */
212
224
TEST_ASSERT_EQUAL_FLOAT (0 , p_timer->read ());
@@ -216,7 +228,7 @@ void test_timer_creation_user_ticker()
216
228
217
229
/* Simulate that 10 ms has elapsed.
218
230
* After that operation timer read routines should still return 0. */
219
- curr_ticker_us_val += 10000 ;
231
+ curr_ticker_ticks_val += 10000 ;
220
232
221
233
/* Check results. */
222
234
TEST_ASSERT_EQUAL_FLOAT (0 , p_timer->read ());
@@ -229,7 +241,7 @@ void test_timer_creation_user_ticker()
229
241
* read_high_resolution_us() functions returns valid values.
230
242
*
231
243
* Note: this function assumes that Timer uses user/fake ticker
232
- * which returns time value provided in curr_ticker_us_val
244
+ * which returns time value provided in curr_ticker_ticks_val
233
245
* global variable.
234
246
*
235
247
* Given Timer has been successfully created and
@@ -241,13 +253,13 @@ void test_timer_creation_user_ticker()
241
253
void test_timer_time_accumulation_user_ticker ()
242
254
{
243
255
/* Simulate that current time is equal to 0 us. */
244
- curr_ticker_us_val = 0 ;
256
+ curr_ticker_ticks_val = 0 ;
245
257
246
258
/* Start the timer. */
247
259
p_timer->start ();
248
260
249
261
/* -- Simulate that current time is equal to 1 us -- */
250
- curr_ticker_us_val = 1 ;
262
+ curr_ticker_ticks_val = 1 ;
251
263
252
264
/* Stop the timer. */
253
265
p_timer->stop ();
@@ -259,13 +271,13 @@ void test_timer_time_accumulation_user_ticker()
259
271
TEST_ASSERT_EQUAL (1 , p_timer->read_high_resolution_us ());
260
272
261
273
/* Simulate that 100 us has elapsed between stop and start. */
262
- curr_ticker_us_val = 101 ;
274
+ curr_ticker_ticks_val = 101 ;
263
275
264
276
/* Start the timer. */
265
277
p_timer->start ();
266
278
267
279
/* -- Simulate that current time is equal to 225 us -- */
268
- curr_ticker_us_val = 225 ;
280
+ curr_ticker_ticks_val = 225 ;
269
281
270
282
/* Stop the timer. */
271
283
p_timer->stop ();
@@ -277,13 +289,13 @@ void test_timer_time_accumulation_user_ticker()
277
289
TEST_ASSERT_EQUAL (125 , p_timer->read_high_resolution_us ());
278
290
279
291
/* Simulate that 100 us has elapsed between stop and start. */
280
- curr_ticker_us_val = 325 ;
292
+ curr_ticker_ticks_val = 325 ;
281
293
282
294
/* Start the timer. */
283
295
p_timer->start ();
284
296
285
297
/* -- Simulate that current time is equal to 1200 us -- */
286
- curr_ticker_us_val = 1200 ;
298
+ curr_ticker_ticks_val = 1200 ;
287
299
288
300
/* Stop the timer. */
289
301
p_timer->stop ();
@@ -295,13 +307,13 @@ void test_timer_time_accumulation_user_ticker()
295
307
TEST_ASSERT_EQUAL (1000 , p_timer->read_high_resolution_us ());
296
308
297
309
/* Simulate that 100 us has elapsed between stop and start. */
298
- curr_ticker_us_val = 1300 ;
310
+ curr_ticker_ticks_val = 1300 ;
299
311
300
312
/* Start the timer. */
301
313
p_timer->start ();
302
314
303
315
/* -- Simulate that current time is equal to 125300 us -- */
304
- curr_ticker_us_val = 125300 ;
316
+ curr_ticker_ticks_val = 125300 ;
305
317
306
318
/* Stop the timer. */
307
319
p_timer->stop ();
@@ -313,13 +325,13 @@ void test_timer_time_accumulation_user_ticker()
313
325
TEST_ASSERT_EQUAL (125000 , p_timer->read_high_resolution_us ());
314
326
315
327
/* Simulate that 100 us has elapsed between stop and start. */
316
- curr_ticker_us_val = 125400 ;
328
+ curr_ticker_ticks_val = 125400 ;
317
329
318
330
/* Start the timer. */
319
331
p_timer->start ();
320
332
321
333
/* -- Simulate that current time is equal to 1000400 us -- */
322
- curr_ticker_us_val = 1000400 ;
334
+ curr_ticker_ticks_val = 1000400 ;
323
335
324
336
/* Stop the timer. */
325
337
p_timer->stop ();
@@ -331,13 +343,13 @@ void test_timer_time_accumulation_user_ticker()
331
343
TEST_ASSERT_EQUAL (1000000 , p_timer->read_high_resolution_us ());
332
344
333
345
/* Simulate that 100 us has elapsed between stop and start. */
334
- curr_ticker_us_val = 1000500 ;
346
+ curr_ticker_ticks_val = 1000500 ;
335
347
336
348
/* Start the timer. */
337
349
p_timer->start ();
338
350
339
351
/* -- Simulate that current time is equal to 125000500 us -- */
340
- curr_ticker_us_val = 125000500 ;
352
+ curr_ticker_ticks_val = 125000500 ;
341
353
342
354
/* Stop the timer. */
343
355
p_timer->stop ();
@@ -349,7 +361,7 @@ void test_timer_time_accumulation_user_ticker()
349
361
TEST_ASSERT_EQUAL (125000000 , p_timer->read_high_resolution_us ());
350
362
351
363
/* Simulate that 100 us has elapsed between stop and start. */
352
- curr_ticker_us_val = 125000600 ;
364
+ curr_ticker_ticks_val = 125000600 ;
353
365
354
366
/* Start the timer. */
355
367
p_timer->start ();
@@ -361,7 +373,7 @@ void test_timer_time_accumulation_user_ticker()
361
373
* while timers are based on 32-bit signed int microsecond counters,
362
374
* so timers can only count up to a maximum of 2^31-1 microseconds i.e.
363
375
* 2147483647 us (about 35 minutes). */
364
- curr_ticker_us_val = 2147484247 ;
376
+ curr_ticker_ticks_val = 2147484247 ;
365
377
366
378
/* Stop the timer. */
367
379
p_timer->stop ();
@@ -531,13 +543,13 @@ void test_timer_reset_user_ticker()
531
543
{
532
544
/* For timer which is using user ticker simulate set current
533
545
* time (irrelevant in case of os ticker). */
534
- curr_ticker_us_val = 0 ;
546
+ curr_ticker_ticks_val = 0 ;
535
547
536
548
/* First measure 10 ms delay. */
537
549
p_timer->start ();
538
550
539
551
/* Simulate that 10 ms have elapsed. */
540
- curr_ticker_us_val = 10000 ;
552
+ curr_ticker_ticks_val = 10000 ;
541
553
542
554
/* Stop the timer. */
543
555
p_timer->stop ();
@@ -555,7 +567,7 @@ void test_timer_reset_user_ticker()
555
567
p_timer->start ();
556
568
557
569
/* Simulate that 20 ms have elapsed. */
558
- curr_ticker_us_val = 30000 ;
570
+ curr_ticker_ticks_val = 30000 ;
559
571
560
572
/* Stop the timer. */
561
573
p_timer->stop ();
@@ -613,19 +625,19 @@ void test_timer_start_started_timer_user_ticker()
613
625
{
614
626
/* For timer which is using user ticker set current
615
627
* time (irrelevant in case of os ticker). */
616
- curr_ticker_us_val = 0 ;
628
+ curr_ticker_ticks_val = 0 ;
617
629
618
630
/* Start the timer. */
619
631
p_timer->start ();
620
632
621
633
/* Simulate that 10 ms have elapsed. */
622
- curr_ticker_us_val = 10000 ;
634
+ curr_ticker_ticks_val = 10000 ;
623
635
624
636
/* Now start timer again. */
625
637
p_timer->start ();
626
638
627
639
/* Simulate that 20 ms have elapsed. */
628
- curr_ticker_us_val = 30000 ;
640
+ curr_ticker_ticks_val = 30000 ;
629
641
630
642
/* Stop the timer. */
631
643
p_timer->stop ();
@@ -674,13 +686,13 @@ void test_timer_float_operator_user_ticker()
674
686
{
675
687
/* For timer which is using user ticker set current
676
688
* time (irrelevant in case of os ticker). */
677
- curr_ticker_us_val = 0 ;
689
+ curr_ticker_ticks_val = 0 ;
678
690
679
691
/* Start the timer. */
680
692
p_timer->start ();
681
693
682
694
/* Simulate that 10 ms have elapsed. */
683
- curr_ticker_us_val = 10000 ;
695
+ curr_ticker_ticks_val = 10000 ;
684
696
685
697
/* Stop the timer. */
686
698
p_timer->stop ();
0 commit comments