Plymouth ELEC351 Group T
/
ELEC351_Group_T
FINAL PROJECT isn't it
Fork of ELEC351 by
main.cpp@52:99915f5240b2, 2018-01-09 (annotated)
- Committer:
- thomasmorris
- Date:
- Tue Jan 09 22:27:49 2018 +0000
- Revision:
- 52:99915f5240b2
- Parent:
- 51:47f5db68500b
- Child:
- 53:71f59e195f06
ITS THE FINAL COMMIT MESSAGE DO DO DO DO DO
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 | 52:99915f5240b2 | 4 | Christopher Student Number : 10467175 |
thomasmorris | 52:99915f5240b2 | 5 | Thomas Student Number : 10427070 |
thomasmorris | 51:47f5db68500b | 6 | */ |
thomasmorris | 25:36699ed589ab | 7 | #include "SETUP.hpp" |
thomasmorris | 52:99915f5240b2 | 8 | |
thomasmorris | 52:99915f5240b2 | 9 | //Interrupt service routine for handling the timeout of SW1 |
thomasmorris | 52:99915f5240b2 | 10 | void SW1TimeOutHandler() { |
thomasmorris | 52:99915f5240b2 | 11 | SW1TimeOut.detach(); //Stop the timeout counter firing |
thomasmorris | 52:99915f5240b2 | 12 | SW1.fall(&SW1FallingEdge); //Now wait for a falling edge |
thomasmorris | 52:99915f5240b2 | 13 | } |
thomasmorris | 52:99915f5240b2 | 14 | //Interrupt service routive for SW2 falling edge (release) |
thomasmorris | 52:99915f5240b2 | 15 | void SW1FallingEdge() { |
thomasmorris | 52:99915f5240b2 | 16 | SW1.fall(NULL); //Disable this interrupt |
thomasmorris | 52:99915f5240b2 | 17 | SW1TimeOut.attach(&SW1TimeOutHandler, SW1_SW2_Timeout_Time); //Start timeout counter |
thomasmorris | 52:99915f5240b2 | 18 | } |
thomasmorris | 52:99915f5240b2 | 19 | //Interrupt service routine for handling the timeout of SW2 |
thomasmorris | 52:99915f5240b2 | 20 | void SW2TimeOutHandler() { |
thomasmorris | 52:99915f5240b2 | 21 | SW2TimeOut.detach(); //Stop the timeout counter firing |
thomasmorris | 52:99915f5240b2 | 22 | SW2.fall(&SW2FallingEdge); //Now wait for a falling edge |
thomasmorris | 52:99915f5240b2 | 23 | } |
thomasmorris | 52:99915f5240b2 | 24 | //Interrupt service routive for SW2 falling edge (release) |
thomasmorris | 52:99915f5240b2 | 25 | void SW2FallingEdge() { |
thomasmorris | 52:99915f5240b2 | 26 | SW2.fall(NULL); //Disable this interrupt |
thomasmorris | 52:99915f5240b2 | 27 | SW2TimeOut.attach(&SW2TimeOutHandler, SW1_SW2_Timeout_Time); //Start timeout counter |
thomasmorris | 52:99915f5240b2 | 28 | } |
thomasmorris | 52:99915f5240b2 | 29 | void SD_Card() //Writes data to the SD card |
thomasmorris | 41:859b5e1e3d9a | 30 | { |
thomasmorris | 41:859b5e1e3d9a | 31 | while(1) |
thomasmorris | 41:859b5e1e3d9a | 32 | { |
thomasmorris | 52:99915f5240b2 | 33 | Thread::signal_wait(SD_CARD_WRITE); //Wait till the SD Card Signal is set |
thomasmorris | 52:99915f5240b2 | 34 | Thread::wait(Sample_Rate*1000); //Waits until a new is taken before checking again |
thomasmorris | 52:99915f5240b2 | 35 | SD_Card_Write(); //Write Data to the SD Card |
thomasmorris | 41:859b5e1e3d9a | 36 | } |
thomasmorris | 38:8d86e0d8a816 | 37 | } |
thomasmorris | 35:26b0a9b55d82 | 38 | void Network() |
thomasmorris | 8:0e4481b64353 | 39 | { |
thomasmorris | 35:26b0a9b55d82 | 40 | while(1) |
thomasmorris | 35:26b0a9b55d82 | 41 | { |
thomasmorris | 52:99915f5240b2 | 42 | Thread::wait(NetworkWaitTime); //Waits Network Wait amount of time |
thomasmorris | 52:99915f5240b2 | 43 | Networking(); //Write to the Network |
thomasmorris | 35:26b0a9b55d82 | 44 | } |
chills | 13:db857b3744c6 | 45 | } |
thomasmorris | 47:6d128e500875 | 46 | void LCD_Output() |
thomasmorris | 30:4cde05cc7c4f | 47 | { |
thomasmorris | 30:4cde05cc7c4f | 48 | while(1) |
thomasmorris | 29:64b1f95a807c | 49 | { |
thomasmorris | 52:99915f5240b2 | 50 | LCD_Print_Output(); //Writes to the LCD |
thomasmorris | 7:dfe19413fdc2 | 51 | } |
thomasmorris | 7:dfe19413fdc2 | 52 | } |
thomasmorris | 47:6d128e500875 | 53 | void Serial_Commands() |
thomasmorris | 22:eb4cc12087b2 | 54 | { |
thomasmorris | 47:6d128e500875 | 55 | while(1) |
thomasmorris | 47:6d128e500875 | 56 | { |
thomasmorris | 52:99915f5240b2 | 57 | Serial_Commands_Output(); //Enable Serial Commands |
thomasmorris | 47:6d128e500875 | 58 | } |
thomasmorris | 22:eb4cc12087b2 | 59 | } |
thomasmorris | 48:244d6d81bb52 | 60 | void LED_Logging() |
thomasmorris | 48:244d6d81bb52 | 61 | { |
thomasmorris | 48:244d6d81bb52 | 62 | while(1) |
thomasmorris | 48:244d6d81bb52 | 63 | { |
thomasmorris | 52:99915f5240b2 | 64 | Log_Leds(); //Flashes the yellow led to indicate the logging mode |
thomasmorris | 48:244d6d81bb52 | 65 | } |
thomasmorris | 48:244d6d81bb52 | 66 | } |
thomasmorris | 47:6d128e500875 | 67 | void Sample() |
thomasmorris | 5:2594b953f111 | 68 | { |
thomasmorris | 52:99915f5240b2 | 69 | Sample_Event(); //Run Sample Event |
thomasmorris | 25:36699ed589ab | 70 | } |
thomasmorris | 25:36699ed589ab | 71 | int main() |
thomasmorris | 25:36699ed589ab | 72 | { |
thomasmorris | 52:99915f5240b2 | 73 | set_time(1515530152); //Sets time |
thomasmorris | 52:99915f5240b2 | 74 | pc.baud(9600); //Sets the Serial Comms Baud Rate |
thomasmorris | 52:99915f5240b2 | 75 | LCD.Initialise(); //Initialise the LCD |
thomasmorris | 52:99915f5240b2 | 76 | LCD.DDRAM_Address(0x00); //Set the LCD string entry point to top left |
thomasmorris | 52:99915f5240b2 | 77 | post(); //Power on Self Test |
thomasmorris | 52:99915f5240b2 | 78 | Sample_Rate = TimerInterval; //Define Sample Rate |
thomasmorris | 52:99915f5240b2 | 79 | Sampling_Timer.attach(&Sampling_ISR,Sample_Rate); //Start the sampler |
thomasmorris | 25:36699ed589ab | 80 | |
thomasmorris | 52:99915f5240b2 | 81 | //Start Threads |
thomasmorris | 5:2594b953f111 | 82 | t1.start(Sample); |
thomasmorris | 41:859b5e1e3d9a | 83 | t2.start(SD_Card); |
thomasmorris | 30:4cde05cc7c4f | 84 | t3.start(LCD_Output); |
thomasmorris | 35:26b0a9b55d82 | 85 | t4.start(Network); |
thomasmorris | 23:3c85d7f657a2 | 86 | t5.start(Serial_Commands); |
thomasmorris | 48:244d6d81bb52 | 87 | t6.start(LED_Logging); |
thomasmorris | 52:99915f5240b2 | 88 | |
thomasmorris | 52:99915f5240b2 | 89 | //Interrupts |
thomasmorris | 52:99915f5240b2 | 90 | SW1.fall(&SW1FallingEdge); |
thomasmorris | 52:99915f5240b2 | 91 | SW2.fall(&SW2FallingEdge); |
thomasmorris | 52:99915f5240b2 | 92 | |
thomasmorris | 5:2594b953f111 | 93 | //Main thread ID |
thomasmorris | 5:2594b953f111 | 94 | idMain = osThreadGetId(); //CMSIS RTOS call |
thomasmorris | 25:36699ed589ab | 95 | |
thomasmorris | 5:2594b953f111 | 96 | //Thread ID |
thomasmorris | 5:2594b953f111 | 97 | id1 = t1.gettid(); |
thomasmorris | 5:2594b953f111 | 98 | id2 = t2.gettid(); |
thomasmorris | 21:3c078c799caa | 99 | id3 = t3.gettid(); |
thomasmorris | 21:3c078c799caa | 100 | id4 = t4.gettid(); |
chills | 24:7d2da96e05ad | 101 | id5 = t5.gettid(); |
thomasmorris | 48:244d6d81bb52 | 102 | id6 = t6.gettid(); |
thomasmorris | 25:36699ed589ab | 103 | |
thomasmorris | 48:244d6d81bb52 | 104 | while(true) |
thomasmorris | 48:244d6d81bb52 | 105 | { |
thomasmorris | 52:99915f5240b2 | 106 | if(SD_CARD_DETECT.read() == 1) //Check if SD Card has been manually ejected |
thomasmorris | 48:244d6d81bb52 | 107 | { |
thomasmorris | 52:99915f5240b2 | 108 | SD_CARD_PRESENT = 0; //Sets the SD card to not present |
thomasmorris | 52:99915f5240b2 | 109 | t2.signal_set(DONT_WRITE_TO_SD_CARD); //Stop writing to SD Card |
thomasmorris | 52:99915f5240b2 | 110 | errorCode(SD_CARD_REMOVED); //Throws an error code |
thomasmorris | 48:244d6d81bb52 | 111 | } |
thomasmorris | 52:99915f5240b2 | 112 | else if(SD_CARD_DETECT.read() == 0) //Check if SD Card is present |
thomasmorris | 48:244d6d81bb52 | 113 | { |
thomasmorris | 52:99915f5240b2 | 114 | if(SD_CARD_PRESENT == 0) //Checks if the SD card is set to present |
thomasmorris | 52:99915f5240b2 | 115 | { |
thomasmorris | 52:99915f5240b2 | 116 | SD_Init();// //Inits the SD card if it was not already initialised |
thomasmorris | 52:99915f5240b2 | 117 | SD_CARD_PRESENT = 1; //Makes SD Card Present 1 to prevent the SD init from running over and over |
thomasmorris | 52:99915f5240b2 | 118 | } |
thomasmorris | 52:99915f5240b2 | 119 | t2.signal_set(SD_CARD_WRITE); //Enables the SD card to Write |
thomasmorris | 48:244d6d81bb52 | 120 | } |
thomasmorris | 48:244d6d81bb52 | 121 | else |
thomasmorris | 48:244d6d81bb52 | 122 | { |
thomasmorris | 52:99915f5240b2 | 123 | t2.signal_set(DONT_WRITE_TO_SD_CARD); //Else Dont Write to SD Card an Error has occured |
thomasmorris | 48:244d6d81bb52 | 124 | } |
thomasmorris | 41:859b5e1e3d9a | 125 | if(onBoardSwitch == 1) |
thomasmorris | 41:859b5e1e3d9a | 126 | { |
thomasmorris | 52:99915f5240b2 | 127 | SD_CARD_PRESENT = 0; //Sets the SD card to not present |
thomasmorris | 52:99915f5240b2 | 128 | t2.signal_set(DONT_WRITE_TO_SD_CARD); //Stop writing to SD Card |
thomasmorris | 52:99915f5240b2 | 129 | SD_Card_Eject(); //Ejects the SD Card |
thomasmorris | 52:99915f5240b2 | 130 | Green_led.switchOn(); //Turns on the green led |
thomasmorris | 41:859b5e1e3d9a | 131 | } |
noutram | 0:36e89e3ed7c4 | 132 | } |
thomasmorris | 45:875f7e18a386 | 133 | } |