@@ -36,7 +36,6 @@ using utest::v1::Case;
36
36
37
37
#define MAX_FLAG_POS 30
38
38
#define PROHIBITED_FLAG_POS 31
39
- static bool is_ticker_used = false ; /* This flag protects avoid calling ThisThread::sleep_for as it is not safe to call in IRQ mode. */
40
39
41
40
/* flags */
42
41
#define FLAG01 0x1FFF /* 00000000000000000001111111111111 */
@@ -45,14 +44,13 @@ static bool is_ticker_used = false; /* This flag protects avoid calling ThisThre
45
44
#define PROHIBITED_FLAG 0x80000000 /* 10000000000000000000000000000000 */
46
45
#define NO_FLAGS 0x0
47
46
48
- template <uint32_t flags, uint32_t wait_ms>
49
- void send_thread (EventFlags *ef)
47
+ void send_thread (EventFlags *ef, uint32_t flags, uint32_t wait_ms)
50
48
{
51
49
for (uint32_t i = 0 ; i <= MAX_FLAG_POS; i++) {
52
50
const uint32_t flag = flags & (1 << i);
53
51
if (flag) {
54
52
ef->set (flag);
55
- if (!is_ticker_used ) {
53
+ if (wait_ms != 0 ) {
56
54
ThisThread::sleep_for (wait_ms);
57
55
}
58
56
}
@@ -220,9 +218,9 @@ void test_multi_thread_all(void)
220
218
Thread thread1 (osPriorityNormal, THREAD_STACK_SIZE);
221
219
Thread thread2 (osPriorityNormal, THREAD_STACK_SIZE);
222
220
Thread thread3 (osPriorityNormal, THREAD_STACK_SIZE);
223
- thread1.start (callback ( send_thread<FLAG01, 1 >, &ef) );
224
- thread2.start (callback ( send_thread<FLAG02, 2 >, &ef) );
225
- thread3.start (callback ( send_thread<FLAG03, 3 >, &ef) );
221
+ thread1.start ([&] { send_thread (&ef, FLAG01, 1 ); } );
222
+ thread2.start ([&] { send_thread (&ef, FLAG02, 2 ); } );
223
+ thread3.start ([&] { send_thread (&ef, FLAG03, 3 ); } );
226
224
227
225
uint32_t ret = ef.wait_all (FLAG01 | FLAG02 | FLAG03);
228
226
TEST_ASSERT_EQUAL (FLAG01 | FLAG02 | FLAG03, ret);
@@ -241,9 +239,9 @@ void test_multi_thread_any(void)
241
239
Thread thread1 (osPriorityNormal, THREAD_STACK_SIZE);
242
240
Thread thread2 (osPriorityNormal, THREAD_STACK_SIZE);
243
241
Thread thread3 (osPriorityNormal, THREAD_STACK_SIZE);
244
- thread1.start (callback ( send_thread<FLAG01, 1 >, &ef) );
245
- thread2.start (callback ( send_thread<FLAG02, 1 >, &ef) );
246
- thread3.start (callback ( send_thread<FLAG03, 1 >, &ef) );
242
+ thread1.start ([&] { send_thread (&ef, FLAG01, 1 ); } );
243
+ thread2.start ([&] { send_thread (&ef, FLAG02, 1 ); } );
244
+ thread3.start ([&] { send_thread (&ef, FLAG03, 1 ); } );
247
245
248
246
for (int i = 0 ; i <= MAX_FLAG_POS; i++) {
249
247
uint32_t flag = 1 << i;
@@ -296,9 +294,9 @@ void test_multi_thread_any_no_clear(void)
296
294
Thread thread1 (osPriorityNormal, THREAD_STACK_SIZE);
297
295
Thread thread2 (osPriorityNormal, THREAD_STACK_SIZE);
298
296
Thread thread3 (osPriorityNormal, THREAD_STACK_SIZE);
299
- thread1.start (callback ( send_thread<FLAG01, 1 >, &ef) );
300
- thread2.start (callback ( send_thread<FLAG02, 1 >, &ef) );
301
- thread3.start (callback ( send_thread<FLAG03, 1 >, &ef) );
297
+ thread1.start ([&] { send_thread (&ef, FLAG01, 1 ); } );
298
+ thread2.start ([&] { send_thread (&ef, FLAG02, 1 ); } );
299
+ thread3.start ([&] { send_thread (&ef, FLAG03, 1 ); } );
302
300
303
301
for (int i = 0 ; i <= MAX_FLAG_POS; i++) {
304
302
uint32_t flag = 1 << i;
@@ -364,13 +362,11 @@ void test_multi_eventflags_all(void)
364
362
{
365
363
EventFlags ef;
366
364
Ticker t1, t2, t3;
367
- is_ticker_used = true ;
368
- t1.attach_us (callback (send_thread<FLAG01, 0 >, &ef), 3000 );
369
- t2.attach_us (callback (send_thread<FLAG02, 0 >, &ef), 4000 );
370
- t3.attach_us (callback (send_thread<FLAG03, 0 >, &ef), 5000 );
365
+ t1.attach_us ([&] { send_thread (&ef, FLAG01, 0 ); }, 3000 );
366
+ t2.attach_us ([&] { send_thread (&ef, FLAG02, 0 ); }, 4000 );
367
+ t3.attach_us ([&] { send_thread (&ef, FLAG03, 0 ); }, 5000 );
371
368
uint32_t ret = ef.wait_all (FLAG01 | FLAG02 | FLAG03, 20 , false );
372
369
TEST_ASSERT_EQUAL (FLAG01 | FLAG02 | FLAG03, ret);
373
- is_ticker_used = false ;
374
370
}
375
371
376
372
/* * Test if multi-event flag set cause wait_any to return
@@ -384,10 +380,9 @@ void test_multi_eventflags_any(void)
384
380
EventFlags ef;
385
381
uint32_t ret;
386
382
Ticker t1, t2, t3;
387
- is_ticker_used = true ;
388
- t1.attach_us (callback (send_thread<FLAG01, 0 >, &ef), 3000 );
389
- t2.attach_us (callback (send_thread<FLAG02, 0 >, &ef), 4000 );
390
- t3.attach_us (callback (send_thread<FLAG03, 0 >, &ef), 5000 );
383
+ t1.attach_us ([&] { send_thread (&ef, FLAG01, 0 ); }, 3000 );
384
+ t2.attach_us ([&] { send_thread (&ef, FLAG02, 0 ); }, 4000 );
385
+ t3.attach_us ([&] { send_thread (&ef, FLAG03, 0 ); }, 5000 );
391
386
392
387
for (int i = 0 ; i <= MAX_FLAG_POS; i++) {
393
388
uint32_t flag = 1 << i;
@@ -396,7 +391,6 @@ void test_multi_eventflags_any(void)
396
391
}
397
392
ret = ef.get ();
398
393
TEST_ASSERT_EQUAL (NO_FLAGS, ret);
399
- is_ticker_used = false ;
400
394
}
401
395
402
396
/* * Test if multi-event flag set cause wait_any(without clear) to return
@@ -410,10 +404,9 @@ void test_multi_eventflags_any_no_clear(void)
410
404
EventFlags ef;
411
405
uint32_t ret;
412
406
Ticker t1, t2, t3;
413
- is_ticker_used = true ;
414
- t1.attach_us (callback (send_thread<FLAG01, 0 >, &ef), 3000 );
415
- t2.attach_us (callback (send_thread<FLAG02, 0 >, &ef), 4000 );
416
- t3.attach_us (callback (send_thread<FLAG03, 0 >, &ef), 5000 );
407
+ t1.attach_us ([&] { send_thread (&ef, FLAG01, 0 ); }, 3000 );
408
+ t2.attach_us ([&] { send_thread (&ef, FLAG02, 0 ); }, 4000 );
409
+ t3.attach_us ([&] { send_thread (&ef, FLAG03, 0 ); }, 5000 );
417
410
418
411
for (int i = 0 ; i <= MAX_FLAG_POS; i++) {
419
412
uint32_t flag = 1 << i;
@@ -424,7 +417,6 @@ void test_multi_eventflags_any_no_clear(void)
424
417
}
425
418
ret = ef.get ();
426
419
TEST_ASSERT_EQUAL (NO_FLAGS, ret);
427
- is_ticker_used = false ;
428
420
}
429
421
430
422
utest::v1::status_t test_setup (const size_t number_of_cases)
0 commit comments