Plymouth ELEC351 Group T
/
ELEC351_Group_T
FINAL PROJECT isn't it
Fork of ELEC351 by
main.cpp@48:244d6d81bb52, 2018-01-09 (annotated)
- Committer:
- thomasmorris
- Date:
- Tue Jan 09 00:37:01 2018 +0000
- Revision:
- 48:244d6d81bb52
- Parent:
- 47:6d128e500875
- Child:
- 49:d51f96a46cc3
HOLY SHIT IT WORKS
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
thomasmorris | 6:97f586597310 | 1 | /* |
thomasmorris | 6:97f586597310 | 2 | ELEC 351 Group T |
thomasmorris | 6:97f586597310 | 3 | Team Members : Christopher Hills, Thomas Morris |
thomasmorris | 42:ae1640bca2e1 | 4 | Current Verision 19 |
thomasmorris | 42:ae1640bca2e1 | 5 | Overiew: Working Tasks 1,2,3,5,6,7,8,9,10,11,12,13,14,15 |
thomasmorris | 8:0e4481b64353 | 6 | |
thomasmorris | 12:536eca338ae8 | 7 | Last Revision: Added Mail Box to serial |
thomasmorris | 8:0e4481b64353 | 8 | Todo: |
thomasmorris | 42:ae1640bca2e1 | 9 | Add functionality to SD card import chris's work on delete serial commnads |
thomasmorris | 42:ae1640bca2e1 | 10 | Commnet code |
thomasmorris | 42:ae1640bca2e1 | 11 | Check for race conditions |
thomasmorris | 42:ae1640bca2e1 | 12 | Move code around |
thomasmorris | 42:ae1640bca2e1 | 13 | Other fixes |
thomasmorris | 6:97f586597310 | 14 | */ |
thomasmorris | 6:97f586597310 | 15 | |
thomasmorris | 25:36699ed589ab | 16 | #include "SETUP.hpp" |
thomasmorris | 35:26b0a9b55d82 | 17 | #include "NETWORK.hpp" |
thomasmorris | 47:6d128e500875 | 18 | #include "FIFO.hpp" |
thomasmorris | 47:6d128e500875 | 19 | #include "SD_CARD.hpp" |
thomasmorris | 47:6d128e500875 | 20 | #include "SERIAL_COMMANDS.hpp" |
thomasmorris | 47:6d128e500875 | 21 | #include "SAMPLE.hpp" |
thomasmorris | 47:6d128e500875 | 22 | #include "THREADS.hpp" |
thomasmorris | 48:244d6d81bb52 | 23 | |
thomasmorris | 41:859b5e1e3d9a | 24 | void SD_Card()//Writes data to the SD card |
thomasmorris | 41:859b5e1e3d9a | 25 | { |
thomasmorris | 41:859b5e1e3d9a | 26 | while(1) |
thomasmorris | 41:859b5e1e3d9a | 27 | { |
thomasmorris | 48:244d6d81bb52 | 28 | Thread::signal_wait(1); |
thomasmorris | 42:ae1640bca2e1 | 29 | Thread::wait(Sample_Rate*1000); //Waits until a new is taken before checking again |
thomasmorris | 47:6d128e500875 | 30 | SD_Card_Write(); |
thomasmorris | 41:859b5e1e3d9a | 31 | } |
thomasmorris | 38:8d86e0d8a816 | 32 | } |
thomasmorris | 35:26b0a9b55d82 | 33 | void Network() |
thomasmorris | 8:0e4481b64353 | 34 | { |
thomasmorris | 35:26b0a9b55d82 | 35 | while(1) |
thomasmorris | 35:26b0a9b55d82 | 36 | { |
thomasmorris | 48:244d6d81bb52 | 37 | Thread::wait(NetworkWaitTime);//Waits Network Wait amount of time |
thomasmorris | 47:6d128e500875 | 38 | Networking(); |
thomasmorris | 35:26b0a9b55d82 | 39 | } |
chills | 13:db857b3744c6 | 40 | } |
thomasmorris | 47:6d128e500875 | 41 | void LCD_Output() |
thomasmorris | 30:4cde05cc7c4f | 42 | { |
thomasmorris | 30:4cde05cc7c4f | 43 | while(1) |
thomasmorris | 29:64b1f95a807c | 44 | { |
thomasmorris | 41:859b5e1e3d9a | 45 | Thread::wait(10);//Small wait |
thomasmorris | 47:6d128e500875 | 46 | LCD_Print_Output(); |
thomasmorris | 7:dfe19413fdc2 | 47 | } |
thomasmorris | 7:dfe19413fdc2 | 48 | } |
thomasmorris | 47:6d128e500875 | 49 | void Serial_Commands() |
thomasmorris | 22:eb4cc12087b2 | 50 | { |
thomasmorris | 47:6d128e500875 | 51 | while(1) |
thomasmorris | 47:6d128e500875 | 52 | { |
thomasmorris | 47:6d128e500875 | 53 | Serial_Commands_Output(); |
thomasmorris | 47:6d128e500875 | 54 | } |
thomasmorris | 42:ae1640bca2e1 | 55 | |
thomasmorris | 22:eb4cc12087b2 | 56 | } |
thomasmorris | 48:244d6d81bb52 | 57 | void LED_Logging() |
thomasmorris | 48:244d6d81bb52 | 58 | { |
thomasmorris | 48:244d6d81bb52 | 59 | while(1) |
thomasmorris | 48:244d6d81bb52 | 60 | { |
thomasmorris | 48:244d6d81bb52 | 61 | Yellow_led.switchOn(); |
thomasmorris | 48:244d6d81bb52 | 62 | if(Log_Value == 0) |
thomasmorris | 48:244d6d81bb52 | 63 | { |
thomasmorris | 48:244d6d81bb52 | 64 | Thread::wait(3000); |
thomasmorris | 48:244d6d81bb52 | 65 | } |
thomasmorris | 48:244d6d81bb52 | 66 | else if(Log_Value == 1) |
thomasmorris | 48:244d6d81bb52 | 67 | { |
thomasmorris | 48:244d6d81bb52 | 68 | Yellow_led.flash(0.2); |
thomasmorris | 48:244d6d81bb52 | 69 | Thread::wait(2800); |
thomasmorris | 48:244d6d81bb52 | 70 | } |
thomasmorris | 48:244d6d81bb52 | 71 | else if(Log_Value == 2) |
thomasmorris | 48:244d6d81bb52 | 72 | { |
thomasmorris | 48:244d6d81bb52 | 73 | Yellow_led.flash(0.2); |
thomasmorris | 48:244d6d81bb52 | 74 | Thread::wait(200); |
thomasmorris | 48:244d6d81bb52 | 75 | Yellow_led.flash(0.2); |
thomasmorris | 48:244d6d81bb52 | 76 | Thread::wait(2400); |
thomasmorris | 48:244d6d81bb52 | 77 | } |
thomasmorris | 48:244d6d81bb52 | 78 | else if(Log_Value == 3) |
thomasmorris | 48:244d6d81bb52 | 79 | { |
thomasmorris | 48:244d6d81bb52 | 80 | Yellow_led.flash(0.2); |
thomasmorris | 48:244d6d81bb52 | 81 | Thread::wait(200); |
thomasmorris | 48:244d6d81bb52 | 82 | Yellow_led.flash(0.2); |
thomasmorris | 48:244d6d81bb52 | 83 | Thread::wait(200); |
thomasmorris | 48:244d6d81bb52 | 84 | Yellow_led.flash(0.2); |
thomasmorris | 48:244d6d81bb52 | 85 | Thread::wait(2000); |
thomasmorris | 48:244d6d81bb52 | 86 | } |
thomasmorris | 48:244d6d81bb52 | 87 | else if(Log_Value == 4) |
thomasmorris | 48:244d6d81bb52 | 88 | { |
thomasmorris | 48:244d6d81bb52 | 89 | Yellow_led.flash(0.2); |
thomasmorris | 48:244d6d81bb52 | 90 | Thread::wait(200); |
thomasmorris | 48:244d6d81bb52 | 91 | Yellow_led.flash(0.2); |
thomasmorris | 48:244d6d81bb52 | 92 | Thread::wait(200); |
thomasmorris | 48:244d6d81bb52 | 93 | Yellow_led.flash(0.2); |
thomasmorris | 48:244d6d81bb52 | 94 | Thread::wait(200); |
thomasmorris | 48:244d6d81bb52 | 95 | Yellow_led.flash(0.2); |
thomasmorris | 48:244d6d81bb52 | 96 | Thread::wait(1600); |
thomasmorris | 48:244d6d81bb52 | 97 | } |
thomasmorris | 48:244d6d81bb52 | 98 | else if(Log_Value == 5) |
thomasmorris | 48:244d6d81bb52 | 99 | { |
thomasmorris | 48:244d6d81bb52 | 100 | Yellow_led.flash(0.2); |
thomasmorris | 48:244d6d81bb52 | 101 | Thread::wait(200); |
thomasmorris | 48:244d6d81bb52 | 102 | Yellow_led.flash(0.2); |
thomasmorris | 48:244d6d81bb52 | 103 | Thread::wait(200); |
thomasmorris | 48:244d6d81bb52 | 104 | Yellow_led.flash(0.2); |
thomasmorris | 48:244d6d81bb52 | 105 | Thread::wait(200); |
thomasmorris | 48:244d6d81bb52 | 106 | Yellow_led.flash(0.2); |
thomasmorris | 48:244d6d81bb52 | 107 | Thread::wait(200); |
thomasmorris | 48:244d6d81bb52 | 108 | Yellow_led.flash(0.2); |
thomasmorris | 48:244d6d81bb52 | 109 | Thread::wait(1200); |
thomasmorris | 48:244d6d81bb52 | 110 | } |
thomasmorris | 48:244d6d81bb52 | 111 | else |
thomasmorris | 48:244d6d81bb52 | 112 | { |
thomasmorris | 48:244d6d81bb52 | 113 | Log_Value = 0; |
thomasmorris | 48:244d6d81bb52 | 114 | } |
thomasmorris | 48:244d6d81bb52 | 115 | } |
thomasmorris | 48:244d6d81bb52 | 116 | } |
thomasmorris | 47:6d128e500875 | 117 | void Sample() |
thomasmorris | 5:2594b953f111 | 118 | { |
thomasmorris | 47:6d128e500875 | 119 | Sample_Event(); |
thomasmorris | 25:36699ed589ab | 120 | } |
thomasmorris | 25:36699ed589ab | 121 | int main() |
thomasmorris | 25:36699ed589ab | 122 | { |
thomasmorris | 37:7c4d7f206039 | 123 | set_time(1515352584); //Set RTC time to December 10 2017 |
thomasmorris | 30:4cde05cc7c4f | 124 | |
chills | 10:46946784326d | 125 | pc.baud(9600); //Sets the Serial Comms Baud Rate |
thomasmorris | 25:36699ed589ab | 126 | |
chills | 20:cbb71f84cff9 | 127 | LCD.Initialise(); |
thomasmorris | 28:09b5c46c8afd | 128 | LCD.DDRAM_Address(0x00); |
thomasmorris | 29:64b1f95a807c | 129 | |
thomasmorris | 25:36699ed589ab | 130 | post(); //Power on Self Test |
thomasmorris | 25:36699ed589ab | 131 | |
thomasmorris | 25:36699ed589ab | 132 | Sample_Rate = TimerInterval; |
chills | 24:7d2da96e05ad | 133 | //Run interrupt |
chills | 26:78f5e454e59f | 134 | Sampling_Timer.attach(&Sampling_ISR,Sample_Rate); |
chills | 24:7d2da96e05ad | 135 | |
thomasmorris | 5:2594b953f111 | 136 | t1.start(Sample); |
thomasmorris | 41:859b5e1e3d9a | 137 | t2.start(SD_Card); |
thomasmorris | 30:4cde05cc7c4f | 138 | t3.start(LCD_Output); |
thomasmorris | 35:26b0a9b55d82 | 139 | t4.start(Network); |
thomasmorris | 23:3c85d7f657a2 | 140 | t5.start(Serial_Commands); |
thomasmorris | 48:244d6d81bb52 | 141 | t6.start(LED_Logging); |
thomasmorris | 5:2594b953f111 | 142 | //Main thread ID |
thomasmorris | 25:36699ed589ab | 143 | |
thomasmorris | 5:2594b953f111 | 144 | idMain = osThreadGetId(); //CMSIS RTOS call |
thomasmorris | 25:36699ed589ab | 145 | |
thomasmorris | 5:2594b953f111 | 146 | //Thread ID |
thomasmorris | 5:2594b953f111 | 147 | id1 = t1.gettid(); |
thomasmorris | 5:2594b953f111 | 148 | id2 = t2.gettid(); |
thomasmorris | 21:3c078c799caa | 149 | id3 = t3.gettid(); |
thomasmorris | 21:3c078c799caa | 150 | id4 = t4.gettid(); |
chills | 24:7d2da96e05ad | 151 | id5 = t5.gettid(); |
thomasmorris | 48:244d6d81bb52 | 152 | id6 = t6.gettid(); |
thomasmorris | 25:36699ed589ab | 153 | |
thomasmorris | 48:244d6d81bb52 | 154 | |
thomasmorris | 48:244d6d81bb52 | 155 | while(true) |
thomasmorris | 48:244d6d81bb52 | 156 | { |
thomasmorris | 48:244d6d81bb52 | 157 | if(SD_CARD_DETECT.read() == 1) |
thomasmorris | 48:244d6d81bb52 | 158 | { |
thomasmorris | 48:244d6d81bb52 | 159 | t2.signal_set(0); |
thomasmorris | 48:244d6d81bb52 | 160 | } |
thomasmorris | 48:244d6d81bb52 | 161 | else if(SD_CARD_DETECT.read() == 0) |
thomasmorris | 48:244d6d81bb52 | 162 | { |
thomasmorris | 48:244d6d81bb52 | 163 | t2.signal_set(1); |
thomasmorris | 48:244d6d81bb52 | 164 | } |
thomasmorris | 48:244d6d81bb52 | 165 | else |
thomasmorris | 48:244d6d81bb52 | 166 | { |
thomasmorris | 48:244d6d81bb52 | 167 | t2.signal_set(1); |
thomasmorris | 48:244d6d81bb52 | 168 | } |
thomasmorris | 41:859b5e1e3d9a | 169 | if(onBoardSwitch == 1) |
thomasmorris | 41:859b5e1e3d9a | 170 | { |
thomasmorris | 48:244d6d81bb52 | 171 | SD_Card_Eject(); |
thomasmorris | 45:875f7e18a386 | 172 | Green_led.switchOn(); |
thomasmorris | 41:859b5e1e3d9a | 173 | } |
noutram | 0:36e89e3ed7c4 | 174 | } |
thomasmorris | 45:875f7e18a386 | 175 | } |