Purpose: Simple application example with 3 threads
Dependencies: IHM_V2
Purpose: Simple application example with 3 threads 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:23645b92579b, 2019-01-09 (annotated)
- Committer:
- jacquesolivierklein
- Date:
- Wed Jan 09 21:34:39 2019 +0000
- Revision:
- 29:23645b92579b
- Parent:
- 28:a0164609dcc0
update for mbed-os-5.11 (and Nboard IHM-V2)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jacquesolivierklein | 27:998da0f731ad | 1 | // Title : mbed-os-3-threads |
jacquesolivierklein | 27:998da0f731ad | 2 | // Author: Jacques-Olivier Klein - IUT de CACHAN |
jacquesolivierklein | 27:998da0f731ad | 3 | // Date: 2018-02-10 |
jacquesolivierklein | 27:998da0f731ad | 4 | |
Jonathan Austin |
0:2757d7abb7d9 | 5 | #include "mbed.h" |
jacquesolivierklein | 27:998da0f731ad | 6 | #include "IHM.h" |
Jonathan Austin |
0:2757d7abb7d9 | 7 | |
jacquesolivierklein | 27:998da0f731ad | 8 | IHM ihm; |
jacquesolivierklein | 27:998da0f731ad | 9 | |
jacquesolivierklein | 27:998da0f731ad | 10 | DigitalOut L0 (PB_3) ; // led L0 |
jacquesolivierklein | 27:998da0f731ad | 11 | DigitalOut L1 (PA_7) ; // led L1 |
jacquesolivierklein | 27:998da0f731ad | 12 | DigitalOut L2 (PA_6) ; // led L2 |
jacquesolivierklein | 27:998da0f731ad | 13 | |
jacquesolivierklein | 27:998da0f731ad | 14 | void led1_thread(); |
jacquesolivierklein | 27:998da0f731ad | 15 | void led2_thread(); |
Jonathan Austin |
0:2757d7abb7d9 | 16 | |
jacquesolivierklein | 28:a0164609dcc0 | 17 | Thread thread1 (osPriorityNormal,2*OS_STACK_SIZE ); |
jacquesolivierklein | 28:a0164609dcc0 | 18 | Thread thread2 (osPriorityNormal,2*OS_STACK_SIZE ); |
jacquesolivierklein | 27:998da0f731ad | 19 | |
jacquesolivierklein | 27:998da0f731ad | 20 | // main is the 1st thread |
jacquesolivierklein | 27:998da0f731ad | 21 | int main(void) |
jacquesolivierklein | 27:998da0f731ad | 22 | { ihm.LCD_clear(); |
jacquesolivierklein | 27:998da0f731ad | 23 | ihm.LCD_printf("3-threads-%s %s",__DATE__,__TIME__); |
jacquesolivierklein | 27:998da0f731ad | 24 | printf("mbed-os-3-threads-%s %s\n\r",__DATE__,__TIME__); |
jacquesolivierklein | 28:a0164609dcc0 | 25 | printf("DEFAULT_STACK_SIZE:%d\n\r", OS_STACK_SIZE); |
jacquesolivierklein | 27:998da0f731ad | 26 | |
jacquesolivierklein | 27:998da0f731ad | 27 | thread1.start(led1_thread); |
jacquesolivierklein | 27:998da0f731ad | 28 | thread2.start(led2_thread); |
jacquesolivierklein | 27:998da0f731ad | 29 | |
jacquesolivierklein | 27:998da0f731ad | 30 | while(1){ |
jacquesolivierklein | 27:998da0f731ad | 31 | L0=!L0; |
jacquesolivierklein | 28:a0164609dcc0 | 32 | printf("* [pid-%d]Main \n\r",osThreadGetId()); |
jacquesolivierklein | 28:a0164609dcc0 | 33 | wait(0.0200); |
Jonathan Austin |
0:2757d7abb7d9 | 34 | } |
Jonathan Austin |
0:2757d7abb7d9 | 35 | } |
Jonathan Austin |
1:846c97078558 | 36 | |
jacquesolivierklein | 27:998da0f731ad | 37 | void led1_thread(){ |
jacquesolivierklein | 27:998da0f731ad | 38 | while (1) { |
jacquesolivierklein | 27:998da0f731ad | 39 | L1 = ! L1; |
jacquesolivierklein | 28:a0164609dcc0 | 40 | printf(" * [pid-%d]led1_thread \n\r",osThreadGetId()); |
jacquesolivierklein | 28:a0164609dcc0 | 41 | wait(0.500); |
jacquesolivierklein | 27:998da0f731ad | 42 | } |
jacquesolivierklein | 27:998da0f731ad | 43 | } |
jacquesolivierklein | 27:998da0f731ad | 44 | |
jacquesolivierklein | 27:998da0f731ad | 45 | void led2_thread(){ |
jacquesolivierklein | 27:998da0f731ad | 46 | while (1) { |
jacquesolivierklein | 27:998da0f731ad | 47 | L2 = ! L2; |
jacquesolivierklein | 28:a0164609dcc0 | 48 | printf(" *[pid-%d]led2_thread \n\r",osThreadGetId()); |
jacquesolivierklein | 28:a0164609dcc0 | 49 | wait(2.500); |
jacquesolivierklein | 27:998da0f731ad | 50 | } |
jacquesolivierklein | 27:998da0f731ad | 51 | } |
jacquesolivierklein | 27:998da0f731ad | 52 | |
jacquesolivierklein | 28:a0164609dcc0 | 53 |