@@ -36,6 +36,7 @@ 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. */
39
40
40
41
/* flags */
41
42
#define FLAG01 0x1FFF /* 00000000000000000001111111111111 */
@@ -51,7 +52,9 @@ void send_thread(EventFlags *ef)
51
52
const uint32_t flag = flags & (1 << i);
52
53
if (flag) {
53
54
ef->set (flag);
54
- ThisThread::sleep_for (wait_ms);
55
+ if (!is_ticker_used) {
56
+ ThisThread::sleep_for (wait_ms);
57
+ }
55
58
}
56
59
}
57
60
}
@@ -349,7 +352,7 @@ void test_multi_thread_all_many_wait(void)
349
352
TEST_ASSERT_EQUAL (NO_FLAGS, ef.get ());
350
353
}
351
354
}
352
- #else
355
+ #endif
353
356
354
357
/* * Test if multi-event flag set cause wait_all to return
355
358
@@ -361,11 +364,13 @@ void test_multi_eventflags_all(void)
361
364
{
362
365
EventFlags ef;
363
366
Ticker t1, t2, t3;
367
+ is_ticker_used = true ;
364
368
t1.attach_us (callback (send_thread<FLAG01, 0 >, &ef), 3000 );
365
- t2.attach_us (callback (send_thread<FLAG02, 0 >, &ef), 5000 );
366
- t3.attach_us (callback (send_thread<FLAG03, 0 >, &ef), 6000 );
367
- uint32_t ret = ef.wait_all (FLAG01 | FLAG02 | FLAG03);
369
+ t2.attach_us (callback (send_thread<FLAG02, 0 >, &ef), 4000 );
370
+ t3.attach_us (callback (send_thread<FLAG03, 0 >, &ef), 5000 );
371
+ uint32_t ret = ef.wait_all (FLAG01 | FLAG02 | FLAG03, 20 , false );
368
372
TEST_ASSERT_EQUAL (FLAG01 | FLAG02 | FLAG03, ret);
373
+ is_ticker_used = false ;
369
374
}
370
375
371
376
/* * Test if multi-event flag set cause wait_any to return
@@ -374,12 +379,12 @@ void test_multi_eventflags_all(void)
374
379
When callbacks set specified flags
375
380
Then main thread waits until receive all of them
376
381
*/
377
-
378
382
void test_multi_eventflags_any (void )
379
383
{
380
384
EventFlags ef;
381
385
uint32_t ret;
382
386
Ticker t1, t2, t3;
387
+ is_ticker_used = true ;
383
388
t1.attach_us (callback (send_thread<FLAG01, 0 >, &ef), 3000 );
384
389
t2.attach_us (callback (send_thread<FLAG02, 0 >, &ef), 4000 );
385
390
t3.attach_us (callback (send_thread<FLAG03, 0 >, &ef), 5000 );
@@ -391,6 +396,7 @@ void test_multi_eventflags_any(void)
391
396
}
392
397
ret = ef.get ();
393
398
TEST_ASSERT_EQUAL (NO_FLAGS, ret);
399
+ is_ticker_used = false ;
394
400
}
395
401
396
402
/* * Test if multi-event flag set cause wait_any(without clear) to return
@@ -404,6 +410,7 @@ void test_multi_eventflags_any_no_clear(void)
404
410
EventFlags ef;
405
411
uint32_t ret;
406
412
Ticker t1, t2, t3;
413
+ is_ticker_used = true ;
407
414
t1.attach_us (callback (send_thread<FLAG01, 0 >, &ef), 3000 );
408
415
t2.attach_us (callback (send_thread<FLAG02, 0 >, &ef), 4000 );
409
416
t3.attach_us (callback (send_thread<FLAG03, 0 >, &ef), 5000 );
@@ -417,8 +424,9 @@ void test_multi_eventflags_any_no_clear(void)
417
424
}
418
425
ret = ef.get ();
419
426
TEST_ASSERT_EQUAL (NO_FLAGS, ret);
427
+ is_ticker_used = false ;
420
428
}
421
- # endif
429
+
422
430
utest::v1::status_t test_setup (const size_t number_of_cases)
423
431
{
424
432
GREENTEA_SETUP (10 , " default_auto" );
@@ -436,12 +444,11 @@ Case cases[] = {
436
444
Case (" Test multi-threaded wait_any" , test_multi_thread_any),
437
445
Case (" Test multi-threaded wait_all many wait" , test_multi_thread_all_many_wait),
438
446
Case (" Test multi-threaded wait_any timeout" , test_multi_thread_any_timeout),
439
- Case (" Test multi-threaded wait_any no clear" , test_multi_thread_any_no_clear)
440
- #else
447
+ Case (" Test multi-threaded wait_any no clear" , test_multi_thread_any_no_clear),
448
+ #endif
441
449
Case (" Test multi-eventflags wait_all" , test_multi_eventflags_all),
442
450
Case (" Test multi-eventflags wait_any" , test_multi_eventflags_any),
443
451
Case (" Test multi-eventflags wait_any no clear" , test_multi_eventflags_any_no_clear)
444
- #endif
445
452
};
446
453
447
454
utest::v1::Specification specification (test_setup, cases);
0 commit comments