Latest

Dependencies:   serial_terminal sample_hardware PLL_Config SDCard BMP280 Networkbits TextLCD SDBlockDevice

Committer:
Swabey89
Date:
Sat Nov 10 19:31:35 2018 +0000
Revision:
10:0fffc988d325
Parent:
9:fa8a35d9d6c0
Child:
11:3ad0327e8c9f
Pre- serial_thread changes

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Swabey89 7:e2bf2d703867 1 #include "mbed.h"
Swabey89 1:31c7b4ab552b 2 #include "sample_hardware.hpp"
Swabey89 1:31c7b4ab552b 3 #include "Networkbits.hpp"
Swabey89 5:956984cbe447 4 #include "serial_terminal.hpp"
Swabey89 6:a5394c9e5927 5 #include "SDCard.hpp"
Swabey89 5:956984cbe447 6 #include "rtos.h"
Swabey89 7:e2bf2d703867 7 #include "mbed_events.h"
Swabey89 8:c81b0ff8b822 8 #include "LCDdisplay.hpp"
Swabey89 5:956984cbe447 9
Swabey89 10:0fffc988d325 10
Swabey89 10:0fffc988d325 11 //Signals
Swabey89 8:c81b0ff8b822 12 #define TAKE_SAMPLE 1
Swabey89 10:0fffc988d325 13
Swabey89 10:0fffc988d325 14
Swabey89 10:0fffc988d325 15
Swabey89 10:0fffc988d325 16 float sample_rate = 15;
Swabey89 10:0fffc988d325 17 //bool sample_enable = true;
Swabey89 8:c81b0ff8b822 18
Swabey89 8:c81b0ff8b822 19 //Queues
Swabey89 8:c81b0ff8b822 20 EventQueue SDqueue;
Swabey89 8:c81b0ff8b822 21 EventQueue LCDqueue;
Swabey89 1:31c7b4ab552b 22
Swabey89 1:31c7b4ab552b 23 //Threads
Swabey89 10:0fffc988d325 24 Thread SDqueue_thread(32*EVENTS_EVENT_SIZE);
Swabey89 10:0fffc988d325 25 Thread LCDqueue_thread(32*EVENTS_EVENT_SIZE);
Swabey89 8:c81b0ff8b822 26 Thread sterm_thread;
Swabey89 8:c81b0ff8b822 27 Thread sample_thread(osPriorityHigh);
Swabey89 8:c81b0ff8b822 28 //Thread ntwkthread
Swabey89 0:4afd4940a189 29
Swabey89 8:c81b0ff8b822 30 Ticker sample;
Swabey89 10:0fffc988d325 31
Swabey89 8:c81b0ff8b822 32 void sampleISR(void);
Swabey89 8:c81b0ff8b822 33 void takesample(void);
Swabey89 8:c81b0ff8b822 34 void samples(void);
Swabey89 7:e2bf2d703867 35
Swabey89 10:0fffc988d325 36
Swabey89 9:fa8a35d9d6c0 37 FILE* fp;
Swabey89 9:fa8a35d9d6c0 38 FATFileSystem* fs;
Swabey89 7:e2bf2d703867 39
Swabey89 7:e2bf2d703867 40 int main() {
Swabey89 8:c81b0ff8b822 41 //Move threads into a thread init function?
Swabey89 8:c81b0ff8b822 42 SDqueue_thread.start(callback(&SDqueue, &EventQueue::dispatch_forever));
Swabey89 8:c81b0ff8b822 43 LCDqueue_thread.start(callback(&LCDqueue, &EventQueue::dispatch_forever));
Swabey89 8:c81b0ff8b822 44
Swabey89 8:c81b0ff8b822 45 sterm_thread.start(serialterm);
Swabey89 8:c81b0ff8b822 46 sample_thread.start(samples);
Swabey89 8:c81b0ff8b822 47
Swabey89 8:c81b0ff8b822 48 //Initialise, move into initialise function
Swabey89 8:c81b0ff8b822 49 SDcard();
Swabey89 5:956984cbe447 50
Swabey89 9:fa8a35d9d6c0 51
Swabey89 1:31c7b4ab552b 52 //Greeting
Swabey89 10:0fffc988d325 53 printf("Testing\n\n");
Swabey89 10:0fffc988d325 54
Swabey89 1:31c7b4ab552b 55
Swabey89 1:31c7b4ab552b 56 //Power on self test
Swabey89 1:31c7b4ab552b 57 post();
Swabey89 1:31c7b4ab552b 58
Swabey89 6:a5394c9e5927 59 printf("Send commands\n\r");
Swabey89 3:b1583f309b43 60
Swabey89 10:0fffc988d325 61 sample.attach(&sampleISR, sample_rate);
Swabey89 10:0fffc988d325 62
Swabey89 1:31c7b4ab552b 63
Swabey89 1:31c7b4ab552b 64 //Flash to indicate goodness
Swabey89 1:31c7b4ab552b 65 while(true) {
Swabey89 5:956984cbe447 66 greenLED = !greenLED;
Swabey89 5:956984cbe447 67 Thread::wait(500);
Swabey89 0:4afd4940a189 68 }
Swabey89 0:4afd4940a189 69 }
Swabey89 1:31c7b4ab552b 70
Swabey89 8:c81b0ff8b822 71 void sampleISR()
Swabey89 8:c81b0ff8b822 72 {
Swabey89 8:c81b0ff8b822 73 sample_thread.signal_set(TAKE_SAMPLE);
Swabey89 8:c81b0ff8b822 74 }
Swabey89 8:c81b0ff8b822 75
Swabey89 8:c81b0ff8b822 76 void samples()
Swabey89 8:c81b0ff8b822 77 {
Swabey89 8:c81b0ff8b822 78 while(true)
Swabey89 8:c81b0ff8b822 79 {
Swabey89 8:c81b0ff8b822 80 //High priority thread
Swabey89 8:c81b0ff8b822 81 Thread::signal_wait(TAKE_SAMPLE);
Swabey89 8:c81b0ff8b822 82
Swabey89 8:c81b0ff8b822 83 double temp = sensor.getTemperature();
Swabey89 8:c81b0ff8b822 84 double pressure = sensor.getPressure();
Swabey89 8:c81b0ff8b822 85
Swabey89 8:c81b0ff8b822 86 //Pass onto queues
Swabey89 8:c81b0ff8b822 87 LCDqueue.call(LCD_display,temp,pressure);
Swabey89 8:c81b0ff8b822 88 SDqueue.call(SDaddSample,temp,pressure);
Swabey89 8:c81b0ff8b822 89 }
Swabey89 8:c81b0ff8b822 90 }
Swabey89 1:31c7b4ab552b 91
Swabey89 1:31c7b4ab552b 92