![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
threads
main.cpp@30:0791059decff, 2019-10-15 (annotated)
- Committer:
- wf
- Date:
- Tue Oct 15 08:13:45 2019 +0000
- Revision:
- 30:0791059decff
- Parent:
- 28:a0164609dcc0
threads
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wf | 30:0791059decff | 1 | // NUClight_TEST1_V3 |
wf | 30:0791059decff | 2 | // Diese Software testet die verschiedenen Funktionen des M0 Boards |
wf | 30:0791059decff | 3 | // BULME Graz, by F. Wolf 05.10.2019 |
wf | 30:0791059decff | 4 | /* |
wf | 30:0791059decff | 5 | PIN-OUT-NUClight |
wf | 30:0791059decff | 6 | NUCLEO-L432KC |
wf | 30:0791059decff | 7 | RGB-rot D1|-------| VIn |
wf | 30:0791059decff | 8 | RGB-gruen D0| | GND |
wf | 30:0791059decff | 9 | NRST| | RST |
wf | 30:0791059decff | 10 | GND| | 5V0 |
wf | 30:0791059decff | 11 | LED1 <-D2| | A7 |
wf | 30:0791059decff | 12 | LED2 <-D3| | A6 -> LED7 |
wf | 30:0791059decff | 13 | SDA (I2C) (MPU6050 gyro) <- D4| | A5 |
wf | 30:0791059decff | 14 | SCL (I2C) (MPU6050 gyro) <- D5| | A4 |
wf | 30:0791059decff | 15 | LED3 <-D6| | A3 -> POTI |
wf | 30:0791059decff | 16 | nc D7| | A2 -> Taster |
wf | 30:0791059decff | 17 | nc D8| | A1 -> Taster |
wf | 30:0791059decff | 18 | LED4 D9| | A0 -> DS18B20 |
wf | 30:0791059decff | 19 | RGB-blau <- D10| | ARF |
wf | 30:0791059decff | 20 | LED5 <- D11| | 3V0 |
wf | 30:0791059decff | 21 | LED6 <- D12|-------| D13 -> LED8 |
wf | 30:0791059decff | 22 | |
wf | 30:0791059decff | 23 | RGB LED aktiv hight (1) |
wf | 30:0791059decff | 24 | */ |
wf | 30:0791059decff | 25 | |
Jonathan Austin |
0:2757d7abb7d9 | 26 | #include "mbed.h" |
wf | 30:0791059decff | 27 | |
Jonathan Austin |
0:2757d7abb7d9 | 28 | |
wf | 30:0791059decff | 29 | // ******** Definitionen ********** |
wf | 30:0791059decff | 30 | //Serial pc(USBTX, USBRX); |
wf | 30:0791059decff | 31 | Serial pc(SERIAL_TX,SERIAL_RX); |
jacquesolivierklein | 27:998da0f731ad | 32 | |
wf | 30:0791059decff | 33 | |
wf | 30:0791059decff | 34 | |
wf | 30:0791059decff | 35 | DigitalOut L0 (D2) ; // led L0 |
wf | 30:0791059decff | 36 | DigitalOut L1 (D3) ; // led L1 |
wf | 30:0791059decff | 37 | DigitalOut L2 (D6) ; // led L2 |
jacquesolivierklein | 27:998da0f731ad | 38 | |
jacquesolivierklein | 27:998da0f731ad | 39 | void led1_thread(); |
jacquesolivierklein | 27:998da0f731ad | 40 | void led2_thread(); |
Jonathan Austin |
0:2757d7abb7d9 | 41 | |
jacquesolivierklein | 28:a0164609dcc0 | 42 | Thread thread1 (osPriorityNormal,2*OS_STACK_SIZE ); |
jacquesolivierklein | 28:a0164609dcc0 | 43 | Thread thread2 (osPriorityNormal,2*OS_STACK_SIZE ); |
jacquesolivierklein | 27:998da0f731ad | 44 | |
jacquesolivierklein | 27:998da0f731ad | 45 | // main is the 1st thread |
jacquesolivierklein | 27:998da0f731ad | 46 | int main(void) |
wf | 30:0791059decff | 47 | { |
wf | 30:0791059decff | 48 | pc.printf("3-threads-%s %s",__DATE__,__TIME__); |
wf | 30:0791059decff | 49 | pc.printf("mbed-os-3-threads-%s %s\n\r",__DATE__,__TIME__); |
wf | 30:0791059decff | 50 | pc.printf("DEFAULT_STACK_SIZE:%d\n\r", OS_STACK_SIZE); |
jacquesolivierklein | 27:998da0f731ad | 51 | |
jacquesolivierklein | 27:998da0f731ad | 52 | thread1.start(led1_thread); |
jacquesolivierklein | 27:998da0f731ad | 53 | thread2.start(led2_thread); |
wf | 30:0791059decff | 54 | |
wf | 30:0791059decff | 55 | thread2.join(); // wartet bis thread2 fertig ist |
jacquesolivierklein | 27:998da0f731ad | 56 | |
jacquesolivierklein | 27:998da0f731ad | 57 | while(1){ |
jacquesolivierklein | 27:998da0f731ad | 58 | L0=!L0; |
wf | 30:0791059decff | 59 | pc.printf("* [pid-%d]Main \n\r",osThreadGetId()); |
jacquesolivierklein | 28:a0164609dcc0 | 60 | wait(0.0200); |
Jonathan Austin |
0:2757d7abb7d9 | 61 | } |
Jonathan Austin |
0:2757d7abb7d9 | 62 | } |
Jonathan Austin |
1:846c97078558 | 63 | |
jacquesolivierklein | 27:998da0f731ad | 64 | void led1_thread(){ |
wf | 30:0791059decff | 65 | |
wf | 30:0791059decff | 66 | |
jacquesolivierklein | 27:998da0f731ad | 67 | while (1) { |
jacquesolivierklein | 27:998da0f731ad | 68 | L1 = ! L1; |
wf | 30:0791059decff | 69 | pc.printf(" * [pid-%d]led1_thread_1 \n\r",osThreadGetId()); |
jacquesolivierklein | 28:a0164609dcc0 | 70 | wait(0.500); |
jacquesolivierklein | 27:998da0f731ad | 71 | } |
jacquesolivierklein | 27:998da0f731ad | 72 | } |
jacquesolivierklein | 27:998da0f731ad | 73 | |
jacquesolivierklein | 27:998da0f731ad | 74 | void led2_thread(){ |
jacquesolivierklein | 27:998da0f731ad | 75 | while (1) { |
jacquesolivierklein | 27:998da0f731ad | 76 | L2 = ! L2; |
wf | 30:0791059decff | 77 | pc.printf(" *[pid-%d]led2_thread_2 \n\r",osThreadGetId()); |
wf | 30:0791059decff | 78 | |
wf | 30:0791059decff | 79 | for(int i=0; i<100; i++) { |
wf | 30:0791059decff | 80 | pc.printf("Zahl %d\n", i+1); |
wf | 30:0791059decff | 81 | } |
wf | 30:0791059decff | 82 | |
wf | 30:0791059decff | 83 | |
jacquesolivierklein | 28:a0164609dcc0 | 84 | wait(2.500); |
wf | 30:0791059decff | 85 | |
wf | 30:0791059decff | 86 | |
jacquesolivierklein | 27:998da0f731ad | 87 | } |
jacquesolivierklein | 27:998da0f731ad | 88 | } |
jacquesolivierklein | 27:998da0f731ad | 89 | |
jacquesolivierklein | 28:a0164609dcc0 | 90 |