FINAL PROJECT isn't it

Fork of ELEC351 by Plymouth ELEC351 Group T

Committer:
thomasmorris
Date:
Tue Jan 09 11:41:07 2018 +0000
Revision:
49:d51f96a46cc3
Parent:
48:244d6d81bb52
Child:
51:47f5db68500b
SD Card Working;

Who changed what in which revision?

UserRevisionLine numberNew 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 49:d51f96a46cc3 4 Current Verision 22
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 Commnet code
thomasmorris 42:ae1640bca2e1 10 Check for race conditions
thomasmorris 42:ae1640bca2e1 11 Other fixes
thomasmorris 6:97f586597310 12 */
thomasmorris 6:97f586597310 13
thomasmorris 25:36699ed589ab 14 #include "SETUP.hpp"
thomasmorris 35:26b0a9b55d82 15 #include "NETWORK.hpp"
thomasmorris 47:6d128e500875 16 #include "FIFO.hpp"
thomasmorris 47:6d128e500875 17 #include "SD_CARD.hpp"
thomasmorris 47:6d128e500875 18 #include "SERIAL_COMMANDS.hpp"
thomasmorris 47:6d128e500875 19 #include "SAMPLE.hpp"
thomasmorris 47:6d128e500875 20 #include "THREADS.hpp"
thomasmorris 41:859b5e1e3d9a 21 void SD_Card()//Writes data to the SD card
thomasmorris 41:859b5e1e3d9a 22 {
thomasmorris 41:859b5e1e3d9a 23 while(1)
thomasmorris 41:859b5e1e3d9a 24 {
thomasmorris 48:244d6d81bb52 25 Thread::signal_wait(1);
thomasmorris 42:ae1640bca2e1 26 Thread::wait(Sample_Rate*1000); //Waits until a new is taken before checking again
thomasmorris 47:6d128e500875 27 SD_Card_Write();
thomasmorris 41:859b5e1e3d9a 28 }
thomasmorris 38:8d86e0d8a816 29 }
thomasmorris 35:26b0a9b55d82 30 void Network()
thomasmorris 8:0e4481b64353 31 {
thomasmorris 35:26b0a9b55d82 32 while(1)
thomasmorris 35:26b0a9b55d82 33 {
thomasmorris 48:244d6d81bb52 34 Thread::wait(NetworkWaitTime);//Waits Network Wait amount of time
thomasmorris 47:6d128e500875 35 Networking();
thomasmorris 35:26b0a9b55d82 36 }
chills 13:db857b3744c6 37 }
thomasmorris 47:6d128e500875 38 void LCD_Output()
thomasmorris 30:4cde05cc7c4f 39 {
thomasmorris 30:4cde05cc7c4f 40 while(1)
thomasmorris 29:64b1f95a807c 41 {
thomasmorris 41:859b5e1e3d9a 42 Thread::wait(10);//Small wait
thomasmorris 47:6d128e500875 43 LCD_Print_Output();
thomasmorris 7:dfe19413fdc2 44 }
thomasmorris 7:dfe19413fdc2 45 }
thomasmorris 47:6d128e500875 46 void Serial_Commands()
thomasmorris 22:eb4cc12087b2 47 {
thomasmorris 47:6d128e500875 48 while(1)
thomasmorris 47:6d128e500875 49 {
thomasmorris 47:6d128e500875 50 Serial_Commands_Output();
thomasmorris 47:6d128e500875 51 }
thomasmorris 42:ae1640bca2e1 52
thomasmorris 22:eb4cc12087b2 53 }
thomasmorris 48:244d6d81bb52 54 void LED_Logging()
thomasmorris 48:244d6d81bb52 55 {
thomasmorris 48:244d6d81bb52 56 while(1)
thomasmorris 48:244d6d81bb52 57 {
thomasmorris 48:244d6d81bb52 58 if(Log_Value == 0)
thomasmorris 48:244d6d81bb52 59 {
thomasmorris 48:244d6d81bb52 60 Thread::wait(3000);
thomasmorris 48:244d6d81bb52 61 }
thomasmorris 48:244d6d81bb52 62 else if(Log_Value == 1)
thomasmorris 48:244d6d81bb52 63 {
thomasmorris 48:244d6d81bb52 64 Yellow_led.flash(0.2);
thomasmorris 48:244d6d81bb52 65 Thread::wait(2800);
thomasmorris 48:244d6d81bb52 66 }
thomasmorris 48:244d6d81bb52 67 else if(Log_Value == 2)
thomasmorris 48:244d6d81bb52 68 {
thomasmorris 48:244d6d81bb52 69 Yellow_led.flash(0.2);
thomasmorris 48:244d6d81bb52 70 Thread::wait(200);
thomasmorris 48:244d6d81bb52 71 Yellow_led.flash(0.2);
thomasmorris 48:244d6d81bb52 72 Thread::wait(2400);
thomasmorris 48:244d6d81bb52 73 }
thomasmorris 48:244d6d81bb52 74 else if(Log_Value == 3)
thomasmorris 48:244d6d81bb52 75 {
thomasmorris 48:244d6d81bb52 76 Yellow_led.flash(0.2);
thomasmorris 48:244d6d81bb52 77 Thread::wait(200);
thomasmorris 48:244d6d81bb52 78 Yellow_led.flash(0.2);
thomasmorris 48:244d6d81bb52 79 Thread::wait(200);
thomasmorris 48:244d6d81bb52 80 Yellow_led.flash(0.2);
thomasmorris 48:244d6d81bb52 81 Thread::wait(2000);
thomasmorris 48:244d6d81bb52 82 }
thomasmorris 48:244d6d81bb52 83 else if(Log_Value == 4)
thomasmorris 48:244d6d81bb52 84 {
thomasmorris 48:244d6d81bb52 85 Yellow_led.flash(0.2);
thomasmorris 48:244d6d81bb52 86 Thread::wait(200);
thomasmorris 48:244d6d81bb52 87 Yellow_led.flash(0.2);
thomasmorris 48:244d6d81bb52 88 Thread::wait(200);
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(1600);
thomasmorris 48:244d6d81bb52 93 }
thomasmorris 48:244d6d81bb52 94 else if(Log_Value == 5)
thomasmorris 48:244d6d81bb52 95 {
thomasmorris 48:244d6d81bb52 96 Yellow_led.flash(0.2);
thomasmorris 48:244d6d81bb52 97 Thread::wait(200);
thomasmorris 48:244d6d81bb52 98 Yellow_led.flash(0.2);
thomasmorris 48:244d6d81bb52 99 Thread::wait(200);
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(1200);
thomasmorris 48:244d6d81bb52 106 }
thomasmorris 48:244d6d81bb52 107 else
thomasmorris 48:244d6d81bb52 108 {
thomasmorris 48:244d6d81bb52 109 Log_Value = 0;
thomasmorris 48:244d6d81bb52 110 }
thomasmorris 48:244d6d81bb52 111 }
thomasmorris 48:244d6d81bb52 112 }
thomasmorris 47:6d128e500875 113 void Sample()
thomasmorris 5:2594b953f111 114 {
thomasmorris 47:6d128e500875 115 Sample_Event();
thomasmorris 25:36699ed589ab 116 }
thomasmorris 25:36699ed589ab 117 int main()
thomasmorris 25:36699ed589ab 118 {
thomasmorris 37:7c4d7f206039 119 set_time(1515352584); //Set RTC time to December 10 2017
thomasmorris 30:4cde05cc7c4f 120
chills 10:46946784326d 121 pc.baud(9600); //Sets the Serial Comms Baud Rate
thomasmorris 25:36699ed589ab 122
chills 20:cbb71f84cff9 123 LCD.Initialise();
thomasmorris 28:09b5c46c8afd 124 LCD.DDRAM_Address(0x00);
thomasmorris 29:64b1f95a807c 125
thomasmorris 25:36699ed589ab 126 post(); //Power on Self Test
thomasmorris 25:36699ed589ab 127
thomasmorris 25:36699ed589ab 128 Sample_Rate = TimerInterval;
chills 24:7d2da96e05ad 129 //Run interrupt
chills 26:78f5e454e59f 130 Sampling_Timer.attach(&Sampling_ISR,Sample_Rate);
chills 24:7d2da96e05ad 131
thomasmorris 5:2594b953f111 132 t1.start(Sample);
thomasmorris 41:859b5e1e3d9a 133 t2.start(SD_Card);
thomasmorris 30:4cde05cc7c4f 134 t3.start(LCD_Output);
thomasmorris 35:26b0a9b55d82 135 t4.start(Network);
thomasmorris 23:3c85d7f657a2 136 t5.start(Serial_Commands);
thomasmorris 48:244d6d81bb52 137 t6.start(LED_Logging);
thomasmorris 5:2594b953f111 138 //Main thread ID
thomasmorris 25:36699ed589ab 139
thomasmorris 5:2594b953f111 140 idMain = osThreadGetId(); //CMSIS RTOS call
thomasmorris 25:36699ed589ab 141
thomasmorris 5:2594b953f111 142 //Thread ID
thomasmorris 5:2594b953f111 143 id1 = t1.gettid();
thomasmorris 5:2594b953f111 144 id2 = t2.gettid();
thomasmorris 21:3c078c799caa 145 id3 = t3.gettid();
thomasmorris 21:3c078c799caa 146 id4 = t4.gettid();
chills 24:7d2da96e05ad 147 id5 = t5.gettid();
thomasmorris 48:244d6d81bb52 148 id6 = t6.gettid();
thomasmorris 25:36699ed589ab 149
thomasmorris 48:244d6d81bb52 150 while(true)
thomasmorris 48:244d6d81bb52 151 {
thomasmorris 48:244d6d81bb52 152 if(SD_CARD_DETECT.read() == 1)
thomasmorris 48:244d6d81bb52 153 {
thomasmorris 49:d51f96a46cc3 154 t2.signal_set(DONT_WRITE_TO_SD_CARD);
thomasmorris 49:d51f96a46cc3 155 errorCode(SD_CARD_REMOVED);
thomasmorris 48:244d6d81bb52 156 }
thomasmorris 48:244d6d81bb52 157 else if(SD_CARD_DETECT.read() == 0)
thomasmorris 48:244d6d81bb52 158 {
thomasmorris 49:d51f96a46cc3 159 t2.signal_set(SD_CARD_WRITE);
thomasmorris 48:244d6d81bb52 160 }
thomasmorris 48:244d6d81bb52 161 else
thomasmorris 48:244d6d81bb52 162 {
thomasmorris 49:d51f96a46cc3 163 t2.signal_set(SD_CARD_WRITE);
thomasmorris 48:244d6d81bb52 164 }
thomasmorris 41:859b5e1e3d9a 165 if(onBoardSwitch == 1)
thomasmorris 41:859b5e1e3d9a 166 {
thomasmorris 48:244d6d81bb52 167 SD_Card_Eject();
thomasmorris 45:875f7e18a386 168 Green_led.switchOn();
thomasmorris 41:859b5e1e3d9a 169 }
noutram 0:36e89e3ed7c4 170 }
thomasmorris 45:875f7e18a386 171 }