File tree Expand file tree Collapse file tree 1 file changed +50
-0
lines changed
TESTS/mbedmicro-rtos-mbed/event_flags Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include " mbed.h"
2
+ #include " greentea-client/test_env.h"
3
+ #include " rtos.h"
4
+
5
+ #if defined(MBED_RTOS_SINGLE_THREAD)
6
+ #error [NOT_SUPPORTED] test not supported
7
+ #endif
8
+
9
+ #define TEST_STACK_SIZE 512
10
+
11
+ #define EVENT_SET_VALUE 0x01
12
+ const int EVENT_TO_EMIT = 100 ;
13
+ const int EVENT_HANDLE_DELEY = 25 ;
14
+
15
+ DigitalOut led (LED1);
16
+ EventFlags event_flags ();
17
+
18
+ int events_counter = 0 ;
19
+
20
+ void led_thread () {
21
+ while (true ) {
22
+ // events flags that are reported as event are automatically cleared.
23
+ event_flags.wait (EVENT_SET_VALUE);
24
+ led = !led;
25
+ events_counter++;
26
+ }
27
+ }
28
+
29
+ int main (void ) {
30
+ GREENTEA_SETUP (20 , " default_auto" );
31
+
32
+ Thread thread (osPriorityNormal, TEST_STACK_SIZE);
33
+ thread.start (led_thread);
34
+
35
+ bool result = false ;
36
+
37
+ printf (" Handling %d events...\r\n " , EVENT_TO_EMIT);
38
+
39
+ while (true ) {
40
+ Thread::wait (2 * EVENT_HANDLE_DELEY);
41
+ event_flags.set (EVENT_SET_VALUE);
42
+ if (events_counter == EVENT_TO_EMIT) {
43
+ printf (" Handled %d events\r\n " , events_counter);
44
+ result = true ;
45
+ break ;
46
+ }
47
+ }
48
+ GREENTEA_TESTSUITE_RESULT (result);
49
+ return 0 ;
50
+ }
You can’t perform that action at this time.
0 commit comments