Repo. for the ELEC351 Coursework - Oliver Thompson

Dependencies:   BMP280 ELEC350-Practicals-FZ429- TextLCD watchdog_RTOS BME280 ntp-client

Committer:
O_Thom
Date:
Thu Dec 06 18:39:04 2018 +0000
Revision:
14:dbb0741ce576
Parent:
13:37a7c57f4641
Child:
18:a036c2e5ff89
Serial working - Terminal Formatting and Input Placement Pending

Who changed what in which revision?

UserRevisionLine numberNew contents of line
O_Thom 5:f87129ac8bf3 1 #include "mbed.h"
O_Thom 0:f9a18207d99c 2 #include "sample_hardware.hpp"
O_Thom 0:f9a18207d99c 3 #include "Sampler.hpp"
O_Thom 10:08c366434f2b 4 //#include <watchdog_RTOS.h>
O_Thom 10:08c366434f2b 5 #define WatchDogTimeout 2000
O_Thom 14:dbb0741ce576 6 #define SerialRxFlag 1
O_Thom 6:b7f6e0c0f646 7 void LCD_Thread(void);
O_Thom 6:b7f6e0c0f646 8 void SAMP_Thread(void);
O_Thom 6:b7f6e0c0f646 9 void SERIAL_Thread(void);
O_Thom 14:dbb0741ce576 10 void SERIAL_IRQ(void);
O_Thom 6:b7f6e0c0f646 11
O_Thom 6:b7f6e0c0f646 12 Thread tLCD, tSAMP, tSERIAL, tSD;
O_Thom 5:f87129ac8bf3 13
O_Thom 10:08c366434f2b 14 //Watchdog Initialisation - Implement Custom to only reset the thread which is faulty. Include a top level Watchdog to reset everything in Main
O_Thom 10:08c366434f2b 15 //Watchdog_RTOS SerialWatch;
O_Thom 10:08c366434f2b 16 //Watchdog_RTOS SampleWatch;
O_Thom 10:08c366434f2b 17 //Watchdog_RTOS LCDWatch;
O_Thom 10:08c366434f2b 18 //Watchdog_RTOS SDWatch;
O_Thom 10:08c366434f2b 19 //Watchdog_RTOS NetWatch;
O_Thom 10:08c366434f2b 20
O_Thom 10:08c366434f2b 21
O_Thom 10:08c366434f2b 22
O_Thom 6:b7f6e0c0f646 23 // Define member object
O_Thom 10:08c366434f2b 24 Sampler m_oSample;
O_Thom 10:08c366434f2b 25 // LCD Defined in Cpp due to use in Sampler.hpp
O_Thom 10:08c366434f2b 26
O_Thom 5:f87129ac8bf3 27
O_Thom 6:b7f6e0c0f646 28 int main()
O_Thom 6:b7f6e0c0f646 29 {
O_Thom 6:b7f6e0c0f646 30 tLCD.start(LCD_Thread);
O_Thom 6:b7f6e0c0f646 31 tSAMP.start(SAMP_Thread);
O_Thom 6:b7f6e0c0f646 32 tSERIAL.start(SERIAL_Thread);
O_Thom 9:654e14de9d74 33 //tSD.start(SD_Thread);
O_Thom 6:b7f6e0c0f646 34 Thread::wait(osWaitForever);
O_Thom 6:b7f6e0c0f646 35 }
O_Thom 0:f9a18207d99c 36
O_Thom 6:b7f6e0c0f646 37 void LCD_Thread()
O_Thom 6:b7f6e0c0f646 38 {
O_Thom 9:654e14de9d74 39 vector<int> ErrorCodes;
O_Thom 10:08c366434f2b 40 // LCDWatch.kick(WatchDogTimeout);
O_Thom 6:b7f6e0c0f646 41 while(1)
O_Thom 6:b7f6e0c0f646 42 {
O_Thom 10:08c366434f2b 43 // m_oDisplay.LCD_Queue.call_every(1500, LCDWatch.kick);
O_Thom 9:654e14de9d74 44 m_oDisplay.LCD_Queue.call_every(1000, &m_oDisplay, &LCD_Data::display_LCD); //Displays the current sensor information onto the LCD screen every x miliseconds
O_Thom 9:654e14de9d74 45 m_oDisplay.LCD_Queue.dispatch(); // Enters WAITING state when blocking
O_Thom 9:654e14de9d74 46 ErrorCodes.push_back(ERROR_LCD_EXIT); // Update Error Vector
O_Thom 9:654e14de9d74 47 m_oSerial.SERIAL_Queue.call(&m_oSerial, &Serialcomms::updateErrors, ErrorCodes); // Pass error vector to the serial thread
O_Thom 6:b7f6e0c0f646 48 }
O_Thom 6:b7f6e0c0f646 49 }
O_Thom 0:f9a18207d99c 50
O_Thom 6:b7f6e0c0f646 51 void SAMP_Thread()
O_Thom 9:654e14de9d74 52 {
O_Thom 9:654e14de9d74 53 vector<int> ErrorCodes;
O_Thom 10:08c366434f2b 54 // SamplerWatch.kick(WatchDogTimeout);
O_Thom 10:08c366434f2b 55
O_Thom 6:b7f6e0c0f646 56 while(1)
O_Thom 6:b7f6e0c0f646 57 {
O_Thom 10:08c366434f2b 58 // m_oSample.SAMP_Queue.call_every(1500, SamplerWatch.kick);
O_Thom 9:654e14de9d74 59 m_oSample.SAMP_Queue.call_every(500, &m_oSample, &Sampler::publishSample); // Publish sample
O_Thom 9:654e14de9d74 60 m_oSample.SAMP_Queue.dispatch(); // Enters WAITING state when blocking
O_Thom 9:654e14de9d74 61 ErrorCodes.push_back(ERROR_SAMPLER_EXIT); // Update Error Vector
O_Thom 9:654e14de9d74 62 m_oSerial.SERIAL_Queue.call(&m_oSerial, &Serialcomms::updateErrors, ErrorCodes); // Pass error vector to the serial thread
O_Thom 10:08c366434f2b 63
O_Thom 6:b7f6e0c0f646 64 }
O_Thom 6:b7f6e0c0f646 65 }
O_Thom 6:b7f6e0c0f646 66
O_Thom 6:b7f6e0c0f646 67 void SERIAL_Thread()
O_Thom 0:f9a18207d99c 68 {
O_Thom 12:88d33b87ecb2 69 vector<int> ErrorCodes;
O_Thom 10:08c366434f2b 70 // SerialWatch.kick(WatchDogTimeout);
O_Thom 9:654e14de9d74 71 while(1)
O_Thom 6:b7f6e0c0f646 72 {
O_Thom 10:08c366434f2b 73 //m_oSerial.SERIAL_Queue.call_every(1500, SerialWatch.kick);
O_Thom 10:08c366434f2b 74 //m_oSerial.SERIAL_Queue.call_every(1000, &m_oSerial, &Serialcomms::updateTerminal); // Publish sample
O_Thom 9:654e14de9d74 75 m_oSerial.SERIAL_Queue.dispatch(); // Enters WAITING state when blocking
O_Thom 9:654e14de9d74 76 ErrorCodes.push_back(ERROR_SERIAL_EXIT); // Update Error Vector
O_Thom 10:08c366434f2b 77
O_Thom 6:b7f6e0c0f646 78 }
O_Thom 0:f9a18207d99c 79 }
O_Thom 6:b7f6e0c0f646 80