Example software for a Cyclic Executive
Dependencies: MCP23017 SDFileSystem WattBob_TextLCD mbed
main.cpp@6:ceda53939eb8, 2016-02-29 (annotated)
- Committer:
- sk398
- Date:
- Mon Feb 29 11:20:48 2016 +0000
- Revision:
- 6:ceda53939eb8
- Parent:
- 5:250f51c80ac1
- Child:
- 7:2973bf297f3d
Tasks all written in. Just got to implement the Cyclic Executive OS element
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sk398 | 4:b85bc0d810e1 | 1 | /* ##################################################################### |
sk398 | 4:b85bc0d810e1 | 2 | main.cpp |
sk398 | 4:b85bc0d810e1 | 3 | --------- |
sk398 | 4:b85bc0d810e1 | 4 | |
sk398 | 4:b85bc0d810e1 | 5 | Embedded Software - Assignment 2 |
sk398 | 4:b85bc0d810e1 | 6 | -------------------------------- |
sk398 | 4:b85bc0d810e1 | 7 | |
sk398 | 4:b85bc0d810e1 | 8 | Written by: Steven Kay |
sk398 | 4:b85bc0d810e1 | 9 | |
sk398 | 4:b85bc0d810e1 | 10 | Date: February 2016 |
sk398 | 4:b85bc0d810e1 | 11 | |
sk398 | 4:b85bc0d810e1 | 12 | Function: This |
sk398 | 4:b85bc0d810e1 | 13 | |
sk398 | 4:b85bc0d810e1 | 14 | Version: 1.0 |
sk398 | 4:b85bc0d810e1 | 15 | |
sk398 | 4:b85bc0d810e1 | 16 | Version History |
sk398 | 4:b85bc0d810e1 | 17 | --------------- |
sk398 | 4:b85bc0d810e1 | 18 | |
sk398 | 4:b85bc0d810e1 | 19 | 1.1 rgdfgdfgdfggdfgdg |
sk398 | 4:b85bc0d810e1 | 20 | |
sk398 | 4:b85bc0d810e1 | 21 | 1.0 gdgddfdddgd |
sk398 | 4:b85bc0d810e1 | 22 | |
sk398 | 4:b85bc0d810e1 | 23 | ##################################################################### */ |
sk398 | 2:22ebabd78084 | 24 | |
sk398 | 0:5989ac10c4d3 | 25 | #include "mbed.h" |
sk398 | 1:221d677fe0d3 | 26 | #include "Tasks.h" |
sk398 | 4:b85bc0d810e1 | 27 | #include "MCP23017.h" |
sk398 | 4:b85bc0d810e1 | 28 | #include "WattBob_TextLCD.h" |
sk398 | 0:5989ac10c4d3 | 29 | |
sk398 | 4:b85bc0d810e1 | 30 | #define BACK_LIGHT_ON(INTERFACE) INTERFACE->write_bit(1,BL_BIT) |
sk398 | 4:b85bc0d810e1 | 31 | #define BACK_LIGHT_OFF(INTERFACE) INTERFACE->write_bit(0,BL_BIT) |
sk398 | 4:b85bc0d810e1 | 32 | |
sk398 | 0:5989ac10c4d3 | 33 | DigitalOut myled(LED1); |
sk398 | 0:5989ac10c4d3 | 34 | |
sk398 | 6:ceda53939eb8 | 35 | Task1 task1(p11); // Square wave Measurement |
sk398 | 6:ceda53939eb8 | 36 | Task2 task2_switch1(p12); // Read digital Output |
sk398 | 6:ceda53939eb8 | 37 | Task3 task3(p13); // Watchdog Pulse |
sk398 | 6:ceda53939eb8 | 38 | Task4 task4(p15,p16); // Read analog Inputs |
sk398 | 6:ceda53939eb8 | 39 | Task5 task5(p9,p10,0x40); // Output to LCD Display |
sk398 | 6:ceda53939eb8 | 40 | Task6 task6; // Logical checks |
sk398 | 6:ceda53939eb8 | 41 | Task7 task7(p5,p6,p7,p8,"SD","/SD/A2"); // SD Card Write |
sk398 | 0:5989ac10c4d3 | 42 | |
sk398 | 0:5989ac10c4d3 | 43 | int main() { |
sk398 | 4:b85bc0d810e1 | 44 | |
sk398 | 6:ceda53939eb8 | 45 | volatile int task1Frequency; |
sk398 | 6:ceda53939eb8 | 46 | volatile int task2SwitchState; |
sk398 | 6:ceda53939eb8 | 47 | volatile float task4AnalogChannels[2]; |
sk398 | 6:ceda53939eb8 | 48 | volatile int errorState; |
sk398 | 6:ceda53939eb8 | 49 | char logData[50]; |
sk398 | 6:ceda53939eb8 | 50 | |
sk398 | 6:ceda53939eb8 | 51 | task1Frequency = task1.ReadFrequency(); |
sk398 | 6:ceda53939eb8 | 52 | // printf("Task 1 Frequency %d Hz\r\n",task1Frequency); |
sk398 | 6:ceda53939eb8 | 53 | |
sk398 | 6:ceda53939eb8 | 54 | task2SwitchState = task2_switch1.digitalInState(); |
sk398 | 6:ceda53939eb8 | 55 | // printf("Switch 1 State: %d\r\n",task2SwitchState); |
sk398 | 4:b85bc0d810e1 | 56 | |
sk398 | 3:c611b9bb5770 | 57 | task3.OutputWatchdogPulse(); |
sk398 | 4:b85bc0d810e1 | 58 | |
sk398 | 3:c611b9bb5770 | 59 | float *analogReading = task4.returnAnalogReadings(); |
sk398 | 6:ceda53939eb8 | 60 | task4AnalogChannels[0] = *(analogReading); |
sk398 | 6:ceda53939eb8 | 61 | task4AnalogChannels[1]= *(analogReading+1); |
sk398 | 6:ceda53939eb8 | 62 | // printf("Analog Readings:\r\nChannel 1-%f\r\nChannel 2-%f\r\n",task4AnalogChannels[0],task4AnalogChannels[1]); |
sk398 | 6:ceda53939eb8 | 63 | |
sk398 | 6:ceda53939eb8 | 64 | errorState = task6.updateErrorCode( task2SwitchState, |
sk398 | 6:ceda53939eb8 | 65 | task4AnalogChannels[0], |
sk398 | 6:ceda53939eb8 | 66 | task4AnalogChannels[1] ); |
sk398 | 3:c611b9bb5770 | 67 | |
sk398 | 6:ceda53939eb8 | 68 | task5.updateDisplay(task1Frequency, |
sk398 | 6:ceda53939eb8 | 69 | task2SwitchState, |
sk398 | 6:ceda53939eb8 | 70 | errorState, |
sk398 | 6:ceda53939eb8 | 71 | task4AnalogChannels[0], |
sk398 | 6:ceda53939eb8 | 72 | task4AnalogChannels[1] ); |
sk398 | 6:ceda53939eb8 | 73 | |
sk398 | 6:ceda53939eb8 | 74 | if(task7.openFile("/SD/A2/test.csv","a")) |
sk398 | 6:ceda53939eb8 | 75 | { |
sk398 | 6:ceda53939eb8 | 76 | printf("File not opened"); |
sk398 | 6:ceda53939eb8 | 77 | } |
sk398 | 6:ceda53939eb8 | 78 | else |
sk398 | 6:ceda53939eb8 | 79 | { |
sk398 | 6:ceda53939eb8 | 80 | int a = sprintf(logData,"Freq=%d,SW1=%d,A1=%1.3f,A2=%1.3f\n",task1Frequency, |
sk398 | 6:ceda53939eb8 | 81 | task2SwitchState,task4AnalogChannels[0],task4AnalogChannels[1]); |
sk398 | 6:ceda53939eb8 | 82 | task7.writeData(logData); |
sk398 | 6:ceda53939eb8 | 83 | task7.closeFile(); |
sk398 | 6:ceda53939eb8 | 84 | } |
sk398 | 6:ceda53939eb8 | 85 | |
sk398 | 0:5989ac10c4d3 | 86 | while(1) { |
sk398 | 0:5989ac10c4d3 | 87 | myled = 1; |
sk398 | 0:5989ac10c4d3 | 88 | wait(0.2); |
sk398 | 0:5989ac10c4d3 | 89 | myled = 0; |
sk398 | 0:5989ac10c4d3 | 90 | wait(0.2); |
sk398 | 0:5989ac10c4d3 | 91 | } |
sk398 | 4:b85bc0d810e1 | 92 | } |