Sample example of using EventFlags in mbed-os threads
Dependencies: IHM_V2
Purpose: Sample example of using EventFlags in mbed-os threads
that trigger a thread thrgough its EventFlags. Target: L432KC / Nboard (from IUT-Cachan) Tested: YES (2019-01-09) Author: Jacques-Olivier Klein - IUT de CACHAN Date: 2018-02-10 rev. 2019-01-09 OS_STACK_SIZE=4096 Libraries: mbed-os rev5345:c966348(03jan2019) + IHMV2 (from IUT-Cachan) rev6:ad91067
Diff: main.cpp
- Revision:
- 31:2afcd3a7b307
- Parent:
- 29:76fa085de35e
- Child:
- 32:88edbd7e31e3
--- a/main.cpp Sun Feb 11 19:23:36 2018 +0000 +++ b/main.cpp Wed Jan 09 12:25:49 2019 +0000 @@ -1,11 +1,12 @@ -// Title : mbed-os-signals +// Title :mbed-os-eventflags (previously mbed-os-signals) // Author: Jacques-Olivier Klein - IUT de CACHAN -// Date: 2018-02-11 +// Date: 2018-02-11 rev. 2019-01-06 #include "mbed.h" #include "IHM.h" IHM ihm; +Mutex bargraph_mutex; DigitalOut L0 (PB_3) ; // led L0 DigitalOut L1 (PA_7) ; // led L1 @@ -24,14 +25,16 @@ void isrBP2 (); void isrBP3 (); -Thread thread_signal(osPriorityNormal,DEFAULT_STACK_SIZE ); +Thread thread_signal; + +EventFlags my_event_flags; int main(void) { ihm.LCD_clear(); ihm.LCD_printf("signal%s %s",__DATE__,__TIME__); printf("\n\rmbed-os-signal\n\r"); printf("\n\r%s - %s\n\r",__DATE__,__TIME__); - printf("DEFAULT_STACK_SIZE:%d\n\r", DEFAULT_STACK_SIZE); + printf("OS_STACK_SIZE:%d\n\r", OS_STACK_SIZE); BP0Interrupt.mode(PullUp); BP0Interrupt.fall(&isrBP0); BP1Interrupt.mode(PullUp); @@ -44,46 +47,36 @@ thread_signal.start(led_thread_signal); while(1){ - Thread::wait(4000); + wait(4.000); L6=!L6; - printf("M [pid-%d]Main \n\r",Thread::gettid()); + printf("M [pid-%d]Main \n\r",osThreadGetId()); } } void led_thread_signal(){ + uint32_t flags; while (true) { - Thread::signal_wait(0xF); // wait for 1 and 2 and 4 and 8 - L1=!L1; - L2=!L2; - L0=!L0; - printf(" S [pid-%d]led6_thread_signal \n\r",Thread::gettid()); - Thread::signal_wait(0); // wait for 1 or 2 or 4 or 8 or … or 128 - L1=!L1; - L2=!L2; - L0=!L0; - printf(" S [pid-%d]led6_thread_signal \n\r",Thread::gettid()); - + flags = my_event_flags.wait_any(0x3); // wait for 1 or 2 + ihm.BAR_set(flags); + printf(" S [pid-%d]led6_thread_signal <%d> 1 or 2 detected \n\r",osThreadGetId(),flags); + flags = my_event_flags.wait_all(0xC); // wait for 4 and 8 + ihm.BAR_set(flags); + printf(" S [pid-%d]led6_thread_signal <%d> 4 and 8 detected \n\r",osThreadGetId(),flags); } } void isrBP0 (void){ - ihm.BAR_set(1); - thread_signal.signal_set(0x1); + my_event_flags.set(0x1); } void isrBP1 (void){ - ihm.BAR_set(2); - thread_signal.signal_set(0x2); + my_event_flags.set(0x2); } void isrBP2 (void){ - ihm.BAR_set(4); - thread_signal.signal_set(0x4); + my_event_flags.set(0x4); } void isrBP3 (void){ - ihm.BAR_set(8); - thread_signal.signal_set(0x8); + my_event_flags.set(0x8); } - -