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

main.cpp

Committer:
jacquesolivierklein
Date:
2018-02-10
Revision:
28:db453b7b2b6f
Parent:
27:3546959ecd59
Child:
29:76fa085de35e

File content as of revision 28:db453b7b2b6f:

// Title : mbed-os-signals
// Author: Jacques-Olivier Klein - IUT de CACHAN
// Date: 2018-02-11

#include "mbed.h"
#include "IHM.h"

IHM ihm; 

DigitalOut L0 (PB_3) ;  // led L0
DigitalOut L1 (PA_7) ;  // led L1
DigitalOut L2 (PA_6) ;  // led L2
DigitalOut L6 (PA_0) ;  // led L6

InterruptIn BP0Interrupt(PA_9); 
InterruptIn BP1Interrupt(PA_10); 
InterruptIn BP2Interrupt(PB_0); 
InterruptIn BP3Interrupt(PB_7); 

void led6_thread_signal();

void isrBP0 ();
void isrBP1 ();
void isrBP2 ();
void isrBP3 ();

Thread thread_signal(osPriorityNormal,DEFAULT_STACK_SIZE );

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); 
      BP0Interrupt.mode(PullUp);
      BP0Interrupt.fall(&isrBP0);
      BP1Interrupt.mode(PullUp);
      BP1Interrupt.fall(&isrBP1);
      BP2Interrupt.mode(PullUp);
      BP2Interrupt.fall(&isrBP2);
      BP3Interrupt.mode(PullUp);
      BP3Interrupt.fall(&isrBP3);
       
    thread_signal.start(led6_thread_signal);   
 
    while(1){   
        Thread::wait(4000);  
        L6=!L6;
        printf("M     [pid-%d]Main \n\r",Thread::gettid());
    }
}

void led6_thread_signal(){   
    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());

    }
}

void isrBP0 (void){
    ihm.BAR_set(1);
    thread_signal.signal_set(0x1);
}

void isrBP1 (void){
    ihm.BAR_set(2);
    thread_signal.signal_set(0x2);
}

void isrBP2 (void){
    ihm.BAR_set(4);
    thread_signal.signal_set(0x4);
}

void isrBP3 (void){
    ihm.BAR_set(8);
    thread_signal.signal_set(0x8);
}