![](/media/cache/group/logo-cachanx.jpg.50x50_q85.jpg)
Purpose: Simple application example with 2 threads communicating 5-byte buffers through a Mail event-object.
Dependencies: IHM_V2
Fork of mbed-os-example-mbed5-blinky by
Purpose: Simple application example with 2 threads communicating 5-byte buffers through a Mail 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@29:e8a6f4ab0fd5, 2019-01-09 (annotated)
- Committer:
- jacquesolivierklein
- Date:
- Wed Jan 09 12:26:12 2019 +0000
- Revision:
- 29:e8a6f4ab0fd5
- Parent:
- 28:9a6aff2af525
update for mbed-os-5.11 (and IHM-V2)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jacquesolivierklein | 27:da71f99ce831 | 1 | // Title: mbed-os-mail-5-Bytes-tx-rx |
jacquesolivierklein | 27:da71f99ce831 | 2 | // Author: Jacques-Olivier Klein - IUT de CACHAN |
jacquesolivierklein | 29:e8a6f4ab0fd5 | 3 | // Date: 2018-02-10 rev. 2019-01-06 |
jacquesolivierklein | 27:da71f99ce831 | 4 | |
Jonathan Austin |
0:2757d7abb7d9 | 5 | #include "mbed.h" |
jacquesolivierklein | 27:da71f99ce831 | 6 | #include "IHM.h" |
jacquesolivierklein | 27:da71f99ce831 | 7 | |
jacquesolivierklein | 27:da71f99ce831 | 8 | #define MY_MAIL_BUFFER_SIZE 5 |
jacquesolivierklein | 27:da71f99ce831 | 9 | #define MY_MAIL_NBER_OF_BUFFER 4 |
Jonathan Austin |
0:2757d7abb7d9 | 10 | |
jacquesolivierklein | 27:da71f99ce831 | 11 | typedef struct{ |
jacquesolivierklein | 27:da71f99ce831 | 12 | char message [MY_MAIL_BUFFER_SIZE] ; |
jacquesolivierklein | 27:da71f99ce831 | 13 | } Mail_Buffer_T; |
jacquesolivierklein | 27:da71f99ce831 | 14 | |
jacquesolivierklein | 27:da71f99ce831 | 15 | IHM ihm; |
jacquesolivierklein | 27:da71f99ce831 | 16 | |
jacquesolivierklein | 27:da71f99ce831 | 17 | DigitalOut L0 (PB_3) ; // led L0 |
jacquesolivierklein | 27:da71f99ce831 | 18 | DigitalOut L1 (PA_7) ; // led L1 |
jacquesolivierklein | 27:da71f99ce831 | 19 | DigitalOut L2 (PA_6) ; // led L2 |
jacquesolivierklein | 27:da71f99ce831 | 20 | |
jacquesolivierklein | 27:da71f99ce831 | 21 | void TxMail (); |
jacquesolivierklein | 27:da71f99ce831 | 22 | void RxMail (); |
jacquesolivierklein | 27:da71f99ce831 | 23 | |
jacquesolivierklein | 27:da71f99ce831 | 24 | Mail<Mail_Buffer_T, MY_MAIL_NBER_OF_BUFFER> my_mail_box; |
Jonathan Austin |
0:2757d7abb7d9 | 25 | |
jacquesolivierklein | 27:da71f99ce831 | 26 | Thread Thread_TxMail; |
jacquesolivierklein | 27:da71f99ce831 | 27 | Thread Thread_RxMail(osPriorityNormal,500); |
jacquesolivierklein | 27:da71f99ce831 | 28 | |
jacquesolivierklein | 27:da71f99ce831 | 29 | Semaphore mysemaphore(0); |
jacquesolivierklein | 27:da71f99ce831 | 30 | |
jacquesolivierklein | 27:da71f99ce831 | 31 | int main(void) |
jacquesolivierklein | 27:da71f99ce831 | 32 | { ihm.LCD_clear(); |
jacquesolivierklein | 27:da71f99ce831 | 33 | ihm.LCD_printf("Mail-5B-tx-rx-%s %s",__DATE__,__TIME__); |
jacquesolivierklein | 28:9a6aff2af525 | 34 | printf("\n\rmbed-os-mail-5-Bytes-tx-rx-%s %s\n\r",__DATE__,__TIME__); |
jacquesolivierklein | 29:e8a6f4ab0fd5 | 35 | printf("DEFAULT_STACK_SIZE:%d\n\r", OS_STACK_SIZE); |
jacquesolivierklein | 27:da71f99ce831 | 36 | |
jacquesolivierklein | 27:da71f99ce831 | 37 | Thread_TxMail.start(TxMail); |
jacquesolivierklein | 27:da71f99ce831 | 38 | Thread_RxMail.start(RxMail); |
jacquesolivierklein | 27:da71f99ce831 | 39 | |
jacquesolivierklein | 27:da71f99ce831 | 40 | while(1){ |
jacquesolivierklein | 29:e8a6f4ab0fd5 | 41 | wait(3.000); |
jacquesolivierklein | 27:da71f99ce831 | 42 | L0=!L0; |
jacquesolivierklein | 29:e8a6f4ab0fd5 | 43 | printf("M [pid-%d]Main \n\r",osThreadGetId()); |
Jonathan Austin |
0:2757d7abb7d9 | 44 | } |
Jonathan Austin |
0:2757d7abb7d9 | 45 | } |
Jonathan Austin |
1:846c97078558 | 46 | |
jacquesolivierklein | 27:da71f99ce831 | 47 | void TxMail (){ |
jacquesolivierklein | 27:da71f99ce831 | 48 | Mail_Buffer_T * p_buffer; |
jacquesolivierklein | 27:da71f99ce831 | 49 | char c = '!'; |
jacquesolivierklein | 27:da71f99ce831 | 50 | int i; |
jacquesolivierklein | 27:da71f99ce831 | 51 | while(1){ |
jacquesolivierklein | 27:da71f99ce831 | 52 | p_buffer = (Mail_Buffer_T *) my_mail_box.alloc(); |
jacquesolivierklein | 27:da71f99ce831 | 53 | for(i=0;i<MY_MAIL_BUFFER_SIZE-1;i++){ |
jacquesolivierklein | 27:da71f99ce831 | 54 | p_buffer->message[i]=c++; |
jacquesolivierklein | 27:da71f99ce831 | 55 | if (c=='}')c='!'; |
jacquesolivierklein | 27:da71f99ce831 | 56 | } |
jacquesolivierklein | 27:da71f99ce831 | 57 | p_buffer->message[MY_MAIL_BUFFER_SIZE-1]=0; |
jacquesolivierklein | 29:e8a6f4ab0fd5 | 58 | printf(" T [pid-%d]TxMail:<%s>\n\r",osThreadGetId(),p_buffer->message); |
jacquesolivierklein | 27:da71f99ce831 | 59 | my_mail_box.put(p_buffer); |
jacquesolivierklein | 27:da71f99ce831 | 60 | L1 = ! L1; |
jacquesolivierklein | 29:e8a6f4ab0fd5 | 61 | wait(2.000); |
jacquesolivierklein | 27:da71f99ce831 | 62 | } |
jacquesolivierklein | 27:da71f99ce831 | 63 | } |
jacquesolivierklein | 27:da71f99ce831 | 64 | |
jacquesolivierklein | 27:da71f99ce831 | 65 | void RxMail (){ |
jacquesolivierklein | 27:da71f99ce831 | 66 | Mail_Buffer_T * p_mail_buffer; |
jacquesolivierklein | 27:da71f99ce831 | 67 | Mail_Buffer_T local_buffer; |
jacquesolivierklein | 27:da71f99ce831 | 68 | while(1){ |
jacquesolivierklein | 27:da71f99ce831 | 69 | osEvent evt = my_mail_box.get(); |
jacquesolivierklein | 27:da71f99ce831 | 70 | L2 = ! L2; |
jacquesolivierklein | 27:da71f99ce831 | 71 | p_mail_buffer = (Mail_Buffer_T *)evt.value.p; |
jacquesolivierklein | 27:da71f99ce831 | 72 | memcpy ( &local_buffer,p_mail_buffer, MY_MAIL_BUFFER_SIZE); |
jacquesolivierklein | 27:da71f99ce831 | 73 | my_mail_box.free(p_mail_buffer); |
jacquesolivierklein | 29:e8a6f4ab0fd5 | 74 | printf(" R[pid-%d]RxMail:<%s>\n\r",osThreadGetId(),local_buffer.message); |
jacquesolivierklein | 27:da71f99ce831 | 75 | } |
jacquesolivierklein | 27:da71f99ce831 | 76 | } |