Sample example of using EventFlags in mbed-os threads

Dependencies:   IHM_V2

/media/uploads/jacquesolivierklein/mbed-os-eventflags.png

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

Committer:
jacquesolivierklein
Date:
Sat Feb 10 23:34:14 2018 +0000
Revision:
27:3546959ecd59
Parent:
22:af9dcf379926
Child:
28:db453b7b2b6f
initial

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jacquesolivierklein 27:3546959ecd59 1 // Title : mbed-os-signals
jacquesolivierklein 27:3546959ecd59 2 // Author: Jacques-Olivier Klein - IUT de CACHAN
jacquesolivierklein 27:3546959ecd59 3 // Date: 2018-02-11
jacquesolivierklein 27:3546959ecd59 4
Jonathan Austin 0:2757d7abb7d9 5 #include "mbed.h"
jacquesolivierklein 27:3546959ecd59 6 #include "IHM.h"
jacquesolivierklein 27:3546959ecd59 7
jacquesolivierklein 27:3546959ecd59 8 IHM ihm;
Jonathan Austin 0:2757d7abb7d9 9
jacquesolivierklein 27:3546959ecd59 10 DigitalOut L0 (PB_3) ; // led L0
jacquesolivierklein 27:3546959ecd59 11 DigitalOut L1 (PA_7) ; // led L1
jacquesolivierklein 27:3546959ecd59 12 DigitalOut L2 (PA_6) ; // led L2
jacquesolivierklein 27:3546959ecd59 13 DigitalOut L6 (PA_0) ; // led L6
jacquesolivierklein 27:3546959ecd59 14
jacquesolivierklein 27:3546959ecd59 15 InterruptIn BP0Interrupt(PA_9);
jacquesolivierklein 27:3546959ecd59 16 InterruptIn BP1Interrupt(PA_10);
jacquesolivierklein 27:3546959ecd59 17 InterruptIn BP2Interrupt(PB_0);
jacquesolivierklein 27:3546959ecd59 18 InterruptIn BP3Interrupt(PB_7);
jacquesolivierklein 27:3546959ecd59 19
jacquesolivierklein 27:3546959ecd59 20 void led6_thread_signal();
Jonathan Austin 0:2757d7abb7d9 21
jacquesolivierklein 27:3546959ecd59 22 void isrBP0 ();
jacquesolivierklein 27:3546959ecd59 23 void isrBP1 ();
jacquesolivierklein 27:3546959ecd59 24 void isrBP2 ();
jacquesolivierklein 27:3546959ecd59 25 void isrBP3 ();
jacquesolivierklein 27:3546959ecd59 26
jacquesolivierklein 27:3546959ecd59 27 Thread thread_signal(osPriorityNormal,DEFAULT_STACK_SIZE );
jacquesolivierklein 27:3546959ecd59 28
jacquesolivierklein 27:3546959ecd59 29 int main(void)
jacquesolivierklein 27:3546959ecd59 30 { ihm.LCD_clear();
jacquesolivierklein 27:3546959ecd59 31 ihm.LCD_printf("signal%s %s",__DATE__,__TIME__);
jacquesolivierklein 27:3546959ecd59 32 printf("\n\rmbed-os-signal\n\r");
jacquesolivierklein 27:3546959ecd59 33 printf("\n\r%s - %s\n\r",__DATE__,__TIME__);
jacquesolivierklein 27:3546959ecd59 34 printf("DEFAULT_STACK_SIZE:%d\n\r", DEFAULT_STACK_SIZE);
jacquesolivierklein 27:3546959ecd59 35 BP0Interrupt.mode(PullUp);
jacquesolivierklein 27:3546959ecd59 36 BP0Interrupt.fall(&isrBP0);
jacquesolivierklein 27:3546959ecd59 37 BP1Interrupt.mode(PullUp);
jacquesolivierklein 27:3546959ecd59 38 BP1Interrupt.fall(&isrBP1);
jacquesolivierklein 27:3546959ecd59 39 BP2Interrupt.mode(PullUp);
jacquesolivierklein 27:3546959ecd59 40 BP2Interrupt.fall(&isrBP2);
jacquesolivierklein 27:3546959ecd59 41 BP3Interrupt.mode(PullUp);
jacquesolivierklein 27:3546959ecd59 42 BP3Interrupt.fall(&isrBP3);
jacquesolivierklein 27:3546959ecd59 43
jacquesolivierklein 27:3546959ecd59 44 thread_signal.start(led6_thread_signal);
jacquesolivierklein 27:3546959ecd59 45
jacquesolivierklein 27:3546959ecd59 46 while(1){
jacquesolivierklein 27:3546959ecd59 47 Thread::wait(4000);
jacquesolivierklein 27:3546959ecd59 48 L6=!L6;
jacquesolivierklein 27:3546959ecd59 49 printf("M [pid-%d]Main \n\r",Thread::gettid());
Jonathan Austin 0:2757d7abb7d9 50 }
Jonathan Austin 0:2757d7abb7d9 51 }
Jonathan Austin 1:846c97078558 52
jacquesolivierklein 27:3546959ecd59 53 void led6_thread_signal(){
jacquesolivierklein 27:3546959ecd59 54 while (true) {
jacquesolivierklein 27:3546959ecd59 55 Thread::signal_wait(0xF);
jacquesolivierklein 27:3546959ecd59 56 L1=!L1;
jacquesolivierklein 27:3546959ecd59 57 L2=!L2;
jacquesolivierklein 27:3546959ecd59 58 L0=!L0;
jacquesolivierklein 27:3546959ecd59 59 printf(" S [pid-%d]led6_thread_signal \n\r",Thread::gettid());
jacquesolivierklein 27:3546959ecd59 60 }
jacquesolivierklein 27:3546959ecd59 61 }
jacquesolivierklein 27:3546959ecd59 62
jacquesolivierklein 27:3546959ecd59 63 void isrBP0 (void){
jacquesolivierklein 27:3546959ecd59 64 ihm.BAR_set(1);
jacquesolivierklein 27:3546959ecd59 65 thread_signal.signal_set(0x1);
jacquesolivierklein 27:3546959ecd59 66 }
jacquesolivierklein 27:3546959ecd59 67
jacquesolivierklein 27:3546959ecd59 68 void isrBP1 (void){
jacquesolivierklein 27:3546959ecd59 69 ihm.BAR_set(2);
jacquesolivierklein 27:3546959ecd59 70 thread_signal.signal_set(0x2);
jacquesolivierklein 27:3546959ecd59 71 }
jacquesolivierklein 27:3546959ecd59 72
jacquesolivierklein 27:3546959ecd59 73 void isrBP2 (void){
jacquesolivierklein 27:3546959ecd59 74 ihm.BAR_set(4);
jacquesolivierklein 27:3546959ecd59 75 thread_signal.signal_set(0x4);
jacquesolivierklein 27:3546959ecd59 76 }
jacquesolivierklein 27:3546959ecd59 77
jacquesolivierklein 27:3546959ecd59 78 void isrBP3 (void){
jacquesolivierklein 27:3546959ecd59 79 ihm.BAR_set(8);
jacquesolivierklein 27:3546959ecd59 80 thread_signal.signal_set(0x8);
jacquesolivierklein 27:3546959ecd59 81 }
jacquesolivierklein 27:3546959ecd59 82
jacquesolivierklein 27:3546959ecd59 83