![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Comments added and commented out outdated code
Dependencies: Peripherals SD_Lib Time_Lib_v2 Year3_Version5 BMP280 LCDFunctions TextLCD BME280 Serial_Lib
main.cpp@3:ef46c1ddefed, 2017-10-31 (annotated)
- Committer:
- noutram
- Date:
- Tue Oct 31 14:27:48 2017 +0000
- Revision:
- 3:ef46c1ddefed
- Parent:
- 2:3d65cd8d7089
- Child:
- 4:da63962bc0f1
Updated for stage-3;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
noutram | 0:90e393878517 | 1 | #include "mbed.h" |
noutram | 0:90e393878517 | 2 | |
noutram | 0:90e393878517 | 3 | #define RED_OFF 1 |
noutram | 0:90e393878517 | 4 | #define YELLOW_OFF 2 |
noutram | 0:90e393878517 | 5 | #define GREEN_OFF 4 |
noutram | 0:90e393878517 | 6 | #define ALL_OFF 7 |
noutram | 0:90e393878517 | 7 | |
noutram | 0:90e393878517 | 8 | //Function declarations |
noutram | 1:948bd552a2a2 | 9 | void Function1(); |
noutram | 1:948bd552a2a2 | 10 | void Function2(); |
noutram | 1:948bd552a2a2 | 11 | void Function3(); |
noutram | 1:948bd552a2a2 | 12 | void Function4(); |
noutram | 0:90e393878517 | 13 | |
noutram | 0:90e393878517 | 14 | //I/O |
noutram | 0:90e393878517 | 15 | DigitalOut onBoardLED(LED1); |
noutram | 3:ef46c1ddefed | 16 | DigitalOut redLED(PE_15); |
noutram | 3:ef46c1ddefed | 17 | DigitalOut yellowLED(PB_10); |
noutram | 3:ef46c1ddefed | 18 | DigitalOut greenLED(PB_11); |
noutram | 0:90e393878517 | 19 | |
noutram | 0:90e393878517 | 20 | DigitalIn onBoardSwitch(USER_BUTTON); |
noutram | 3:ef46c1ddefed | 21 | DigitalIn SW1(PE_12); |
noutram | 3:ef46c1ddefed | 22 | DigitalIn SW2(PE_14); |
noutram | 0:90e393878517 | 23 | |
noutram | 1:948bd552a2a2 | 24 | Thread t1; |
noutram | 1:948bd552a2a2 | 25 | Thread t2; |
noutram | 1:948bd552a2a2 | 26 | Thread t3; |
noutram | 1:948bd552a2a2 | 27 | Thread t4; |
noutram | 0:90e393878517 | 28 | |
noutram | 0:90e393878517 | 29 | //Thread ID |
noutram | 0:90e393878517 | 30 | osThreadId idMain; |
noutram | 0:90e393878517 | 31 | osThreadId id1; |
noutram | 0:90e393878517 | 32 | osThreadId id2; |
noutram | 0:90e393878517 | 33 | osThreadId id3; |
noutram | 0:90e393878517 | 34 | osThreadId id4; |
noutram | 0:90e393878517 | 35 | |
noutram | 1:948bd552a2a2 | 36 | void Function1() |
noutram | 0:90e393878517 | 37 | { |
noutram | 0:90e393878517 | 38 | while (true) { |
noutram | 0:90e393878517 | 39 | redLED = !redLED; |
noutram | 0:90e393878517 | 40 | if (redLED == 0) { |
noutram | 1:948bd552a2a2 | 41 | t2.signal_set(RED_OFF); |
noutram | 0:90e393878517 | 42 | } |
noutram | 0:90e393878517 | 43 | Thread::wait(1000); |
noutram | 0:90e393878517 | 44 | } |
noutram | 0:90e393878517 | 45 | } |
noutram | 0:90e393878517 | 46 | |
noutram | 1:948bd552a2a2 | 47 | void Function2() |
noutram | 0:90e393878517 | 48 | { |
noutram | 0:90e393878517 | 49 | while (true) { |
noutram | 0:90e393878517 | 50 | Thread::signal_wait(RED_OFF); |
noutram | 0:90e393878517 | 51 | yellowLED = !yellowLED; |
noutram | 0:90e393878517 | 52 | if (yellowLED == 0) { |
noutram | 1:948bd552a2a2 | 53 | t3.signal_set(YELLOW_OFF); |
noutram | 0:90e393878517 | 54 | } |
noutram | 0:90e393878517 | 55 | } |
noutram | 0:90e393878517 | 56 | } |
noutram | 0:90e393878517 | 57 | |
noutram | 0:90e393878517 | 58 | //Green Flashing |
noutram | 1:948bd552a2a2 | 59 | void Function3() |
noutram | 0:90e393878517 | 60 | { |
noutram | 0:90e393878517 | 61 | while (true) { |
noutram | 0:90e393878517 | 62 | Thread::signal_wait(YELLOW_OFF); |
noutram | 0:90e393878517 | 63 | greenLED = !greenLED; |
noutram | 0:90e393878517 | 64 | if (greenLED == 0) { |
noutram | 1:948bd552a2a2 | 65 | t4.signal_set(GREEN_OFF); |
noutram | 0:90e393878517 | 66 | } |
noutram | 0:90e393878517 | 67 | } |
noutram | 0:90e393878517 | 68 | } |
noutram | 0:90e393878517 | 69 | |
noutram | 0:90e393878517 | 70 | //This function waits for signals from all other threads |
noutram | 1:948bd552a2a2 | 71 | void Function4() |
noutram | 0:90e393878517 | 72 | { |
noutram | 0:90e393878517 | 73 | while (true) { |
noutram | 0:90e393878517 | 74 | Thread::signal_wait(GREEN_OFF); |
noutram | 0:90e393878517 | 75 | //Signal main thread |
noutram | 0:90e393878517 | 76 | osSignalSet(idMain, ALL_OFF); |
noutram | 0:90e393878517 | 77 | } |
noutram | 0:90e393878517 | 78 | } |
noutram | 0:90e393878517 | 79 | |
noutram | 0:90e393878517 | 80 | //Main thread |
noutram | 0:90e393878517 | 81 | int main() { |
noutram | 0:90e393878517 | 82 | redLED = 0; |
noutram | 0:90e393878517 | 83 | yellowLED = 0; |
noutram | 0:90e393878517 | 84 | greenLED = 0; |
noutram | 0:90e393878517 | 85 | |
noutram | 0:90e393878517 | 86 | //Main thread ID |
noutram | 0:90e393878517 | 87 | idMain = osThreadGetId(); //CMSIS RTOS call |
noutram | 0:90e393878517 | 88 | |
noutram | 1:948bd552a2a2 | 89 | // run threads |
noutram | 1:948bd552a2a2 | 90 | t4.start(Function4); |
noutram | 1:948bd552a2a2 | 91 | t1.start(Function1); |
noutram | 1:948bd552a2a2 | 92 | t2.start(Function2); |
noutram | 1:948bd552a2a2 | 93 | t3.start(Function3); |
noutram | 0:90e393878517 | 94 | |
noutram | 0:90e393878517 | 95 | |
noutram | 0:90e393878517 | 96 | //Thread ID |
noutram | 1:948bd552a2a2 | 97 | id1 = t1.gettid(); |
noutram | 1:948bd552a2a2 | 98 | id2 = t2.gettid(); |
noutram | 1:948bd552a2a2 | 99 | id3 = t3.gettid(); |
noutram | 1:948bd552a2a2 | 100 | id4 = t4.gettid(); |
noutram | 0:90e393878517 | 101 | |
noutram | 0:90e393878517 | 102 | while(1) { |
noutram | 0:90e393878517 | 103 | //Wait for the ALL_ON signal |
noutram | 0:90e393878517 | 104 | osSignalWait(ALL_OFF,osWaitForever); |
noutram | 0:90e393878517 | 105 | printf("ALL OFF\n"); |
noutram | 0:90e393878517 | 106 | } |
noutram | 0:90e393878517 | 107 | } |