Purpose: Simple application example with 2 threads communicating 32-bit integers through a Queue event-object.

Dependencies:   IHM_V2

Fork of mbed-os-example-mbed5-blinky by mbed-os-examples

/media/uploads/jacquesolivierklein/mbed-os-q-32-bits-tx-rx-2.png

Title : mbed-os-q-32-bits-tx-rx

Purpose: Simple application example with 2 threads communicating 32-bit integers through a Queue event-object. 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:
27:1fa50737793f
Parent:
22:af9dcf379926
Child:
28:5ac42b4bb038

File content as of revision 27:1fa50737793f:

// Title : mbed-os-q-32-bits-tx-rx
// Author: Jacques-Olivier Klein - IUT de CACHAN
// Date: 2018-02-10

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

#define THE_Q_SIZE 4

IHM ihm; 

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

void tx_q();
void rx_q();

Thread thread_tx_q;
Thread thread_rx_q;

Queue<int, THE_Q_SIZE> the_queue;

int main(void) 
{   ihm.LCD_clear();
    ihm.LCD_printf("q-32b-tx-rx-%s %s",__DATE__,__TIME__);
    printf("mbed-os-q-32-bits-tx-rx-%s %s\n\r",__DATE__,__TIME__);
    printf("DEFAULT_STACK_SIZE:%d\n\r", DEFAULT_STACK_SIZE); 

    thread_tx_q.start(tx_q); 
    thread_rx_q.start(rx_q); 
    
    while(1){   
        Thread::wait(3000);  
        L0=!L0;
        printf("*      [pid-%d]Main \n\r",Thread::gettid());
    }
}
 
void tx_q (){
    static int j=0;
    while (1){
        L1 = ! L1;
        printf("   *   Tx_q data:%d\n\r", j);
        the_queue.put((int*)j++);
        Thread::wait(1000);      
    }
}
     
void rx_q (){
    osEvent evt;
    while (true) {
        evt = the_queue.get();
        L2 = ! L2;
        if (evt.status == osEventMessage) {
            printf("      *Rx_q data:%d\n\r", evt.value.v);
        }
    }
}