@@ -48,19 +48,22 @@ extern uint32_t SystemCoreClock;
48
48
* DELTA = TOLERANCE_FACTOR / SystemCoreClock * US_FACTOR
49
49
*
50
50
* e.g.
51
- * For K64F DELTA = (40000 / 120000000) * 1000000 = 333 [us]
52
- * For NUCLEO_F070RB DELTA = (40000 / 48000000) * 1000000 = 833 [us]
53
- * For NRF51_DK DELTA = (40000 / 16000000) * 1000000 = 2500 [us]
51
+ * For K64F DELTA = (80000 / 120000000) * 1000000 = 666 [us]
52
+ * For NUCLEO_F070RB DELTA = (80000 / 48000000) * 1000000 = 1666 [us]
53
+ * For NRF51_DK DELTA = (80000 / 16000000) * 1000000 = 5000 [us]
54
54
*/
55
55
#define US_PER_SEC 1000000
56
- #define TOLERANCE_FACTOR 40000 .0f
56
+ #define US_PER_MSEC 1000
57
+ #define TOLERANCE_FACTOR 80000 .0f
57
58
#define US_FACTOR 1000000 .0f
58
59
59
60
static const int delta_sys_clk_us = ((int ) (TOLERANCE_FACTOR / (float ) SystemCoreClock * US_FACTOR));
60
61
61
- #define DELTA_US delta_sys_clk_us
62
- #define DELTA_S ((float )delta_sys_clk_us/US_PER_SEC)
63
- #define DELTA_MS 1
62
+ /* When test performs time measurement using Timer in sequence, then measurement error accumulates
63
+ * in the successive attempts. */
64
+ #define DELTA_US (i ) (delta_sys_clk_us * i)
65
+ #define DELTA_S (i ) ((float )delta_sys_clk_us * i / US_PER_SEC)
66
+ #define DELTA_MS (i ) (1 + ( (i * delta_sys_clk_us) / US_PER_MSEC))
64
67
65
68
/* This test verifies if low power timer is stopped after
66
69
* creation.
@@ -75,19 +78,19 @@ void test_lptimer_creation()
75
78
76
79
/* Check results. */
77
80
TEST_ASSERT_EQUAL_FLOAT (0 , lp_timer.read ());
78
- TEST_ASSERT_EQUAL (0 , lp_timer.read_ms ());
79
- TEST_ASSERT_EQUAL (0 , lp_timer.read_us ());
80
- TEST_ASSERT_EQUAL (0 , lp_timer.read_high_resolution_us ());
81
+ TEST_ASSERT_EQUAL_INT32 (0 , lp_timer.read_ms ());
82
+ TEST_ASSERT_EQUAL_INT32 (0 , lp_timer.read_us ());
83
+ TEST_ASSERT_EQUAL_UINT64 (0 , lp_timer.read_high_resolution_us ());
81
84
82
85
/* Wait 10 ms.
83
86
* After that operation timer read routines should still return 0. */
84
87
wait_ms (10 );
85
88
86
89
/* Check results. */
87
90
TEST_ASSERT_EQUAL_FLOAT (0 , lp_timer.read ());
88
- TEST_ASSERT_EQUAL (0 , lp_timer.read_ms ());
89
- TEST_ASSERT_EQUAL (0 , lp_timer.read_us ());
90
- TEST_ASSERT_EQUAL (0 , lp_timer.read_high_resolution_us ());
91
+ TEST_ASSERT_EQUAL_INT32 (0 , lp_timer.read_ms ());
92
+ TEST_ASSERT_EQUAL_INT32 (0 , lp_timer.read_us ());
93
+ TEST_ASSERT_EQUAL_UINT64 (0 , lp_timer.read_high_resolution_us ());
91
94
}
92
95
93
96
/* This test verifies if read(), read_us(), read_ms(),
@@ -115,10 +118,10 @@ void test_lptimer_time_accumulation()
115
118
lp_timer.stop ();
116
119
117
120
/* Check results - totally 10 ms have elapsed. */
118
- TEST_ASSERT_FLOAT_WITHIN (DELTA_S, 0 .010f , lp_timer.read ());
119
- TEST_ASSERT_INT32_WITHIN (DELTA_MS, 10 , lp_timer.read_ms ());
120
- TEST_ASSERT_INT32_WITHIN (DELTA_US, 10000 , lp_timer.read_us ());
121
- TEST_ASSERT_UINT64_WITHIN (DELTA_US, 10000 , lp_timer.read_high_resolution_us ());
121
+ TEST_ASSERT_FLOAT_WITHIN (DELTA_S ( 1 ) , 0 .010f , lp_timer.read ());
122
+ TEST_ASSERT_INT32_WITHIN (DELTA_MS ( 1 ) , 10 , lp_timer.read_ms ());
123
+ TEST_ASSERT_INT32_WITHIN (DELTA_US ( 1 ) , 10000 , lp_timer.read_us ());
124
+ TEST_ASSERT_UINT64_WITHIN (DELTA_US ( 1 ) , 10000 , lp_timer.read_high_resolution_us ());
122
125
123
126
/* Wait 50 ms - this is done to show that time elapsed when
124
127
* the timer is stopped does not have influence on the
@@ -137,10 +140,10 @@ void test_lptimer_time_accumulation()
137
140
lp_timer.stop ();
138
141
139
142
/* Check results - totally 30 ms have elapsed. */
140
- TEST_ASSERT_FLOAT_WITHIN (2 * DELTA_S, 0 .030f , lp_timer.read ());
141
- TEST_ASSERT_INT32_WITHIN (DELTA_MS, 30 , lp_timer.read_ms ());
142
- TEST_ASSERT_INT32_WITHIN (2 * DELTA_US, 30000 , lp_timer.read_us ());
143
- TEST_ASSERT_UINT64_WITHIN (2 * DELTA_US, 30000 , lp_timer.read_high_resolution_us ());
143
+ TEST_ASSERT_FLOAT_WITHIN (DELTA_S ( 2 ) , 0 .030f , lp_timer.read ());
144
+ TEST_ASSERT_INT32_WITHIN (DELTA_MS ( 2 ) , 30 , lp_timer.read_ms ());
145
+ TEST_ASSERT_INT32_WITHIN (DELTA_US ( 2 ) , 30000 , lp_timer.read_us ());
146
+ TEST_ASSERT_UINT64_WITHIN (DELTA_US ( 2 ) , 30000 , lp_timer.read_high_resolution_us ());
144
147
145
148
/* Wait 50 ms - this is done to show that time elapsed when
146
149
* the timer is stopped does not have influence on the
@@ -158,10 +161,10 @@ void test_lptimer_time_accumulation()
158
161
lp_timer.stop ();
159
162
160
163
/* Check results - totally 60 ms have elapsed. */
161
- TEST_ASSERT_FLOAT_WITHIN (3 * DELTA_S, 0 .060f , lp_timer.read ());
162
- TEST_ASSERT_INT32_WITHIN (DELTA_MS, 60 , lp_timer.read_ms ());
163
- TEST_ASSERT_INT32_WITHIN (3 * DELTA_US, 60000 , lp_timer.read_us ());
164
- TEST_ASSERT_UINT64_WITHIN (3 * DELTA_US, 60000 , lp_timer.read_high_resolution_us ());
164
+ TEST_ASSERT_FLOAT_WITHIN (DELTA_S ( 3 ) , 0 .060f , lp_timer.read ());
165
+ TEST_ASSERT_INT32_WITHIN (DELTA_MS ( 3 ) , 60 , lp_timer.read_ms ());
166
+ TEST_ASSERT_INT32_WITHIN (DELTA_US ( 3 ) , 60000 , lp_timer.read_us ());
167
+ TEST_ASSERT_UINT64_WITHIN (DELTA_US ( 3 ) , 60000 , lp_timer.read_high_resolution_us ());
165
168
166
169
/* Wait 50 ms - this is done to show that time elapsed when
167
170
* the timer is stopped does not have influence on the
@@ -179,11 +182,11 @@ void test_lptimer_time_accumulation()
179
182
/* Stop the timer. */
180
183
lp_timer.stop ();
181
184
182
- /* Check results - totally 5060 ms have elapsed. */
183
- TEST_ASSERT_FLOAT_WITHIN (4 * DELTA_S, 1 .060f , lp_timer.read ());
184
- TEST_ASSERT_INT32_WITHIN (DELTA_MS, 1060 , lp_timer.read_ms ());
185
- TEST_ASSERT_INT32_WITHIN (4 * DELTA_US, 1060000 , lp_timer.read_us ());
186
- TEST_ASSERT_UINT64_WITHIN (4 * DELTA_US, 1060000 , lp_timer.read_high_resolution_us ());
185
+ /* Check results - totally 1060 ms have elapsed. */
186
+ TEST_ASSERT_FLOAT_WITHIN (DELTA_S ( 4 ) , 1 .060f , lp_timer.read ());
187
+ TEST_ASSERT_INT32_WITHIN (DELTA_MS ( 4 ) , 1060 , lp_timer.read_ms ());
188
+ TEST_ASSERT_INT32_WITHIN (DELTA_US ( 4 ) , 1060000 , lp_timer.read_us ());
189
+ TEST_ASSERT_UINT64_WITHIN (DELTA_US ( 4 ) , 1060000 , lp_timer.read_high_resolution_us ());
187
190
}
188
191
189
192
/* This test verifies if reset() function resets the
@@ -209,10 +212,10 @@ void test_lptimer_reset()
209
212
lp_timer.stop ();
210
213
211
214
/* Check results - totally 10 ms elapsed. */
212
- TEST_ASSERT_FLOAT_WITHIN (DELTA_S, 0 .010f , lp_timer.read ());
213
- TEST_ASSERT_INT32_WITHIN (DELTA_MS, 10 , lp_timer.read_ms ());
214
- TEST_ASSERT_INT32_WITHIN (DELTA_US, 10000 , lp_timer.read_us ());
215
- TEST_ASSERT_UINT64_WITHIN (DELTA_US, 10000 , lp_timer.read_high_resolution_us ());
215
+ TEST_ASSERT_FLOAT_WITHIN (DELTA_S ( 1 ) , 0 .010f , lp_timer.read ());
216
+ TEST_ASSERT_INT32_WITHIN (DELTA_MS ( 1 ) , 10 , lp_timer.read_ms ());
217
+ TEST_ASSERT_INT32_WITHIN (DELTA_US ( 1 ) , 10000 , lp_timer.read_us ());
218
+ TEST_ASSERT_UINT64_WITHIN (DELTA_US ( 1 ) , 10000 , lp_timer.read_high_resolution_us ());
216
219
217
220
/* Reset the timer - previous measured time should be lost now. */
218
221
lp_timer.reset ();
@@ -227,10 +230,10 @@ void test_lptimer_reset()
227
230
lp_timer.stop ();
228
231
229
232
/* Check results - 20 ms elapsed since the reset. */
230
- TEST_ASSERT_FLOAT_WITHIN (DELTA_S, 0 .020f , lp_timer.read ());
231
- TEST_ASSERT_INT32_WITHIN (DELTA_MS, 20 , lp_timer.read_ms ());
232
- TEST_ASSERT_INT32_WITHIN (DELTA_US, 20000 , lp_timer.read_us ());
233
- TEST_ASSERT_UINT64_WITHIN (DELTA_US, 20000 , lp_timer.read_high_resolution_us ());
233
+ TEST_ASSERT_FLOAT_WITHIN (DELTA_S ( 1 ) , 0 .020f , lp_timer.read ());
234
+ TEST_ASSERT_INT32_WITHIN (DELTA_MS ( 1 ) , 20 , lp_timer.read_ms ());
235
+ TEST_ASSERT_INT32_WITHIN (DELTA_US ( 1 ) , 20000 , lp_timer.read_us ());
236
+ TEST_ASSERT_UINT64_WITHIN (DELTA_US ( 1 ) , 20000 , lp_timer.read_high_resolution_us ());
234
237
}
235
238
236
239
/* This test verifies if calling start() for already
@@ -260,10 +263,10 @@ void test_lptimer_start_started_timer()
260
263
lp_timer.stop ();
261
264
262
265
/* Check results - 30 ms have elapsed since the first start. */
263
- TEST_ASSERT_FLOAT_WITHIN (2 * DELTA_S, 0 .030f , lp_timer.read ());
264
- TEST_ASSERT_INT32_WITHIN (DELTA_MS, 30 , lp_timer.read_ms ());
265
- TEST_ASSERT_INT32_WITHIN (2 * DELTA_US, 30000 , lp_timer.read_us ());
266
- TEST_ASSERT_UINT64_WITHIN (2 * DELTA_US, 30000 , lp_timer.read_high_resolution_us ());
266
+ TEST_ASSERT_FLOAT_WITHIN (DELTA_S ( 2 ) , 0 .030f , lp_timer.read ());
267
+ TEST_ASSERT_INT32_WITHIN (DELTA_MS ( 2 ) , 30 , lp_timer.read_ms ());
268
+ TEST_ASSERT_INT32_WITHIN (DELTA_US ( 2 ) , 30000 , lp_timer.read_us ());
269
+ TEST_ASSERT_UINT64_WITHIN (DELTA_US ( 2 ) , 30000 , lp_timer.read_high_resolution_us ());
267
270
}
268
271
269
272
/* This test verifies low power timer float operator.
@@ -287,7 +290,7 @@ void test_lptimer_float_operator()
287
290
lp_timer.stop ();
288
291
289
292
/* Check result - 10 ms elapsed. */
290
- TEST_ASSERT_FLOAT_WITHIN (DELTA_S, 0 .010f , (float )(lp_timer));
293
+ TEST_ASSERT_FLOAT_WITHIN (DELTA_S ( 1 ) , 0 .010f , (float )(lp_timer));
291
294
}
292
295
293
296
/* This test verifies if time counted by the low power timer is
@@ -313,10 +316,10 @@ void test_lptimer_time_measurement()
313
316
lp_timer.stop ();
314
317
315
318
/* Check results - wait_val_us us have elapsed. */
316
- TEST_ASSERT_FLOAT_WITHIN (DELTA_S, (float )wait_val_us / 1000000 , lp_timer.read ());
317
- TEST_ASSERT_INT32_WITHIN (DELTA_MS, wait_val_us / 1000 , lp_timer.read_ms ());
318
- TEST_ASSERT_INT32_WITHIN (DELTA_US, wait_val_us, lp_timer.read_us ());
319
- TEST_ASSERT_UINT64_WITHIN (DELTA_US, wait_val_us, lp_timer.read_high_resolution_us ());
319
+ TEST_ASSERT_FLOAT_WITHIN (DELTA_S ( 1 ) , (float )wait_val_us / 1000000 , lp_timer.read ());
320
+ TEST_ASSERT_INT32_WITHIN (DELTA_MS ( 1 ) , wait_val_us / 1000 , lp_timer.read_ms ());
321
+ TEST_ASSERT_INT32_WITHIN (DELTA_US ( 1 ) , wait_val_us, lp_timer.read_us ());
322
+ TEST_ASSERT_UINT64_WITHIN (DELTA_US ( 1 ) , wait_val_us, lp_timer.read_high_resolution_us ());
320
323
}
321
324
322
325
utest::v1::status_t test_setup (const size_t number_of_cases)
0 commit comments