![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Proj 324 Final
Fork of ELEC351_Group_T by
main.cpp@47:6d128e500875, 2018-01-08 (annotated)
- Committer:
- thomasmorris
- Date:
- Mon Jan 08 21:53:40 2018 +0000
- Revision:
- 47:6d128e500875
- Parent:
- 46:bd9e7e40b3f9
- Child:
- 48:244d6d81bb52
FINAL working copy
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 | 41:859b5e1e3d9a | 23 | void SD_Card()//Writes data to the SD card |
thomasmorris | 41:859b5e1e3d9a | 24 | { |
thomasmorris | 41:859b5e1e3d9a | 25 | while(1) |
thomasmorris | 41:859b5e1e3d9a | 26 | { |
thomasmorris | 42:ae1640bca2e1 | 27 | Thread::wait(Sample_Rate*1000); //Waits until a new is taken before checking again |
thomasmorris | 47:6d128e500875 | 28 | SD_Card_Write(); |
thomasmorris | 41:859b5e1e3d9a | 29 | } |
thomasmorris | 38:8d86e0d8a816 | 30 | } |
thomasmorris | 35:26b0a9b55d82 | 31 | void Network() |
thomasmorris | 8:0e4481b64353 | 32 | { |
thomasmorris | 35:26b0a9b55d82 | 33 | while(1) |
thomasmorris | 35:26b0a9b55d82 | 34 | { |
thomasmorris | 41:859b5e1e3d9a | 35 | Thread::wait(NetworkWait);//Waits Network Wait amount of time |
thomasmorris | 47:6d128e500875 | 36 | Networking(); |
thomasmorris | 35:26b0a9b55d82 | 37 | } |
chills | 13:db857b3744c6 | 38 | } |
thomasmorris | 47:6d128e500875 | 39 | void LCD_Output() |
thomasmorris | 30:4cde05cc7c4f | 40 | { |
thomasmorris | 30:4cde05cc7c4f | 41 | while(1) |
thomasmorris | 29:64b1f95a807c | 42 | { |
thomasmorris | 41:859b5e1e3d9a | 43 | Thread::wait(10);//Small wait |
thomasmorris | 47:6d128e500875 | 44 | LCD_Print_Output(); |
thomasmorris | 7:dfe19413fdc2 | 45 | } |
thomasmorris | 7:dfe19413fdc2 | 46 | } |
thomasmorris | 47:6d128e500875 | 47 | void Serial_Commands() |
thomasmorris | 22:eb4cc12087b2 | 48 | { |
thomasmorris | 47:6d128e500875 | 49 | while(1) |
thomasmorris | 47:6d128e500875 | 50 | { |
thomasmorris | 47:6d128e500875 | 51 | Serial_Commands_Output(); |
thomasmorris | 47:6d128e500875 | 52 | } |
thomasmorris | 42:ae1640bca2e1 | 53 | |
thomasmorris | 22:eb4cc12087b2 | 54 | } |
thomasmorris | 5:2594b953f111 | 55 | |
thomasmorris | 47:6d128e500875 | 56 | void Sample() |
thomasmorris | 5:2594b953f111 | 57 | { |
thomasmorris | 47:6d128e500875 | 58 | Sample_Event(); |
thomasmorris | 25:36699ed589ab | 59 | } |
thomasmorris | 25:36699ed589ab | 60 | int main() |
thomasmorris | 25:36699ed589ab | 61 | { |
thomasmorris | 37:7c4d7f206039 | 62 | set_time(1515352584); //Set RTC time to December 10 2017 |
thomasmorris | 30:4cde05cc7c4f | 63 | |
chills | 10:46946784326d | 64 | pc.baud(9600); //Sets the Serial Comms Baud Rate |
thomasmorris | 25:36699ed589ab | 65 | |
chills | 20:cbb71f84cff9 | 66 | LCD.Initialise(); |
thomasmorris | 28:09b5c46c8afd | 67 | LCD.DDRAM_Address(0x00); |
thomasmorris | 29:64b1f95a807c | 68 | |
thomasmorris | 25:36699ed589ab | 69 | post(); //Power on Self Test |
thomasmorris | 25:36699ed589ab | 70 | |
noutram | 3:a88838ff33e7 | 71 | //Initialise the SD card (this needs to move) |
noutram | 1:e1cf7663f5ff | 72 | if ( sd.init() != 0) { |
thomasmorris | 45:875f7e18a386 | 73 | printf("SD Init failed \n"); |
thomasmorris | 28:09b5c46c8afd | 74 | LCD.Display_Clear(); |
thomasmorris | 28:09b5c46c8afd | 75 | LCD.Write_String("CANNOT INIT SD"); //Change me |
noutram | 1:e1cf7663f5ff | 76 | errorCode(FATAL); |
thomasmorris | 25:36699ed589ab | 77 | } |
noutram | 1:e1cf7663f5ff | 78 | //Create a filing system for SD Card |
thomasmorris | 25:36699ed589ab | 79 | FATFileSystem fs("sd", &sd); |
noutram | 0:36e89e3ed7c4 | 80 | |
noutram | 1:e1cf7663f5ff | 81 | //Open to WRITE |
thomasmorris | 41:859b5e1e3d9a | 82 | FILE* fp = fopen("/sd/test.csv","a");//test.csv is created in the SD Card |
noutram | 1:e1cf7663f5ff | 83 | if (fp == NULL) { |
noutram | 1:e1cf7663f5ff | 84 | error("Could not open file for write\n"); |
thomasmorris | 28:09b5c46c8afd | 85 | LCD.Display_Clear(); |
thomasmorris | 37:7c4d7f206039 | 86 | LCD.Write_String("CANNOT OPEN FILE"); |
noutram | 1:e1cf7663f5ff | 87 | errorCode(FATAL); |
noutram | 1:e1cf7663f5ff | 88 | } |
thomasmorris | 41:859b5e1e3d9a | 89 | //Close File |
thomasmorris | 41:859b5e1e3d9a | 90 | fclose(fp); |
thomasmorris | 37:7c4d7f206039 | 91 | int network_temp; |
thomasmorris | 37:7c4d7f206039 | 92 | network_temp = Network_Init(); |
thomasmorris | 37:7c4d7f206039 | 93 | if(network_temp == 1)//Sets up the network and checks if the network cable is not pluged in |
thomasmorris | 37:7c4d7f206039 | 94 | { |
thomasmorris | 37:7c4d7f206039 | 95 | error("Could not access network"); |
thomasmorris | 37:7c4d7f206039 | 96 | LCD.Display_Clear(); |
thomasmorris | 37:7c4d7f206039 | 97 | LCD.Write_String("Could not access network"); |
thomasmorris | 41:859b5e1e3d9a | 98 | errorCode(NETWORK_FATAL); |
thomasmorris | 37:7c4d7f206039 | 99 | } |
noutram | 3:a88838ff33e7 | 100 | //Last message before sampling begins |
thomasmorris | 28:09b5c46c8afd | 101 | LCD.Display_Clear(); |
thomasmorris | 35:26b0a9b55d82 | 102 | LCD.Write_String("READY PLAYER"); |
thomasmorris | 31:4a88bf97b53e | 103 | LCD.DDRAM_Address(0x40); |
thomasmorris | 35:26b0a9b55d82 | 104 | LCD.Write_String(" One "); |
thomasmorris | 31:4a88bf97b53e | 105 | LCD.DDRAM_Address(0x00); |
thomasmorris | 25:36699ed589ab | 106 | |
thomasmorris | 25:36699ed589ab | 107 | Sample_Rate = TimerInterval; |
chills | 24:7d2da96e05ad | 108 | //Run interrupt |
chills | 26:78f5e454e59f | 109 | Sampling_Timer.attach(&Sampling_ISR,Sample_Rate); |
chills | 24:7d2da96e05ad | 110 | |
thomasmorris | 5:2594b953f111 | 111 | t1.start(Sample); |
thomasmorris | 41:859b5e1e3d9a | 112 | t2.start(SD_Card); |
thomasmorris | 30:4cde05cc7c4f | 113 | t3.start(LCD_Output); |
thomasmorris | 35:26b0a9b55d82 | 114 | t4.start(Network); |
thomasmorris | 23:3c85d7f657a2 | 115 | t5.start(Serial_Commands); |
thomasmorris | 25:36699ed589ab | 116 | |
thomasmorris | 5:2594b953f111 | 117 | //Main thread ID |
thomasmorris | 25:36699ed589ab | 118 | |
thomasmorris | 5:2594b953f111 | 119 | idMain = osThreadGetId(); //CMSIS RTOS call |
thomasmorris | 25:36699ed589ab | 120 | |
thomasmorris | 5:2594b953f111 | 121 | //Thread ID |
thomasmorris | 5:2594b953f111 | 122 | id1 = t1.gettid(); |
thomasmorris | 5:2594b953f111 | 123 | id2 = t2.gettid(); |
thomasmorris | 21:3c078c799caa | 124 | id3 = t3.gettid(); |
thomasmorris | 21:3c078c799caa | 125 | id4 = t4.gettid(); |
chills | 24:7d2da96e05ad | 126 | id5 = t5.gettid(); |
thomasmorris | 25:36699ed589ab | 127 | |
noutram | 1:e1cf7663f5ff | 128 | while(true) { |
thomasmorris | 41:859b5e1e3d9a | 129 | if(onBoardSwitch == 1) |
thomasmorris | 41:859b5e1e3d9a | 130 | { |
thomasmorris | 41:859b5e1e3d9a | 131 | fclose(fp);//Close File |
thomasmorris | 41:859b5e1e3d9a | 132 | sd.deinit();//Close down |
thomasmorris | 41:859b5e1e3d9a | 133 | LCD.Display_Clear(); |
thomasmorris | 41:859b5e1e3d9a | 134 | LCD.DDRAM_Address(0x00); |
thomasmorris | 41:859b5e1e3d9a | 135 | LCD.Write_String("SD Card"); |
thomasmorris | 41:859b5e1e3d9a | 136 | LCD.DDRAM_Address(0x40); |
thomasmorris | 41:859b5e1e3d9a | 137 | LCD.Write_String("Unmounted"); |
thomasmorris | 41:859b5e1e3d9a | 138 | LCD.DDRAM_Address(0x00); |
chills | 46:bd9e7e40b3f9 | 139 | pc.printf("SD Card Unmounted\n"); |
thomasmorris | 45:875f7e18a386 | 140 | Green_led.switchOn(); |
thomasmorris | 41:859b5e1e3d9a | 141 | } |
noutram | 0:36e89e3ed7c4 | 142 | } |
thomasmorris | 45:875f7e18a386 | 143 | } |