Example software for a Cyclic Executive
Dependencies: MCP23017 SDFileSystem WattBob_TextLCD mbed
Tasks.h@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 | Tasks.h |
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 | 1:221d677fe0d3 | 25 | #ifndef _TASKS_H_ |
sk398 | 1:221d677fe0d3 | 26 | #define _TASKS_H_ |
sk398 | 1:221d677fe0d3 | 27 | |
sk398 | 6:ceda53939eb8 | 28 | // Includes to operate the LCD Display |
sk398 | 5:250f51c80ac1 | 29 | #include "MCP23017.h" |
sk398 | 5:250f51c80ac1 | 30 | #include "WattBob_TextLCD.h" |
sk398 | 5:250f51c80ac1 | 31 | |
sk398 | 6:ceda53939eb8 | 32 | // Includes to operate the SD Card system |
sk398 | 6:ceda53939eb8 | 33 | #include "SDFileSystem.h" |
sk398 | 6:ceda53939eb8 | 34 | |
sk398 | 2:22ebabd78084 | 35 | // Global definitions |
sk398 | 1:221d677fe0d3 | 36 | #define HIGH 1 |
sk398 | 1:221d677fe0d3 | 37 | #define LOW 0 |
sk398 | 1:221d677fe0d3 | 38 | |
sk398 | 3:c611b9bb5770 | 39 | #define TRUE 1 |
sk398 | 3:c611b9bb5770 | 40 | #define FALSE 0 |
sk398 | 3:c611b9bb5770 | 41 | |
sk398 | 2:22ebabd78084 | 42 | // Task 1 definitions |
sk398 | 1:221d677fe0d3 | 43 | #define WATCHDOG_PULSE_WIDTH 15 |
sk398 | 1:221d677fe0d3 | 44 | |
sk398 | 2:22ebabd78084 | 45 | // Task 2 definitions |
sk398 | 2:22ebabd78084 | 46 | |
sk398 | 2:22ebabd78084 | 47 | // Task 3 definitions |
sk398 | 2:22ebabd78084 | 48 | |
sk398 | 2:22ebabd78084 | 49 | // Task 4 definitions |
sk398 | 4:b85bc0d810e1 | 50 | #define NUM_ANALOG_SAMPLES 4.0 |
sk398 | 2:22ebabd78084 | 51 | |
sk398 | 2:22ebabd78084 | 52 | // Task 5 definitions |
sk398 | 2:22ebabd78084 | 53 | |
sk398 | 2:22ebabd78084 | 54 | // Task 6 definitions |
sk398 | 6:ceda53939eb8 | 55 | #define ERROR_CODE_CDTN_MET 3 |
sk398 | 6:ceda53939eb8 | 56 | #define ERROR_CODE_CDTN_FAIL 0 |
sk398 | 2:22ebabd78084 | 57 | |
sk398 | 2:22ebabd78084 | 58 | /* ####################### Class definitions and prototypes ####################### */ |
sk398 | 1:221d677fe0d3 | 59 | |
sk398 | 1:221d677fe0d3 | 60 | /* ==================================== Task 1 ==================================== */ |
sk398 | 2:22ebabd78084 | 61 | // Measure freuqnecy |
sk398 | 1:221d677fe0d3 | 62 | class Task1 |
sk398 | 1:221d677fe0d3 | 63 | { |
sk398 | 1:221d677fe0d3 | 64 | public: |
sk398 | 1:221d677fe0d3 | 65 | Task1(PinName squareWaveInPin); |
sk398 | 4:b85bc0d810e1 | 66 | int ReadFrequency(); |
sk398 | 1:221d677fe0d3 | 67 | |
sk398 | 1:221d677fe0d3 | 68 | private: |
sk398 | 4:b85bc0d810e1 | 69 | Timer _Task1Timer; |
sk398 | 4:b85bc0d810e1 | 70 | |
sk398 | 4:b85bc0d810e1 | 71 | void MeasureFrequency(); |
sk398 | 4:b85bc0d810e1 | 72 | void StopCounter(); |
sk398 | 4:b85bc0d810e1 | 73 | |
sk398 | 4:b85bc0d810e1 | 74 | volatile int measuredFrequency; |
sk398 | 4:b85bc0d810e1 | 75 | |
sk398 | 4:b85bc0d810e1 | 76 | InterruptIn *_squareWaveIn; |
sk398 | 6:ceda53939eb8 | 77 | |
sk398 | 6:ceda53939eb8 | 78 | protected: |
sk398 | 1:221d677fe0d3 | 79 | |
sk398 | 1:221d677fe0d3 | 80 | }; |
sk398 | 1:221d677fe0d3 | 81 | |
sk398 | 1:221d677fe0d3 | 82 | |
sk398 | 1:221d677fe0d3 | 83 | /* ==================================== Task 2 ==================================== */ |
sk398 | 2:22ebabd78084 | 84 | // Digital Input |
sk398 | 1:221d677fe0d3 | 85 | class Task2 |
sk398 | 1:221d677fe0d3 | 86 | { |
sk398 | 1:221d677fe0d3 | 87 | public: |
sk398 | 1:221d677fe0d3 | 88 | Task2(PinName digitalInCheckPin); |
sk398 | 3:c611b9bb5770 | 89 | bool digitalInState(); |
sk398 | 3:c611b9bb5770 | 90 | |
sk398 | 1:221d677fe0d3 | 91 | private: |
sk398 | 6:ceda53939eb8 | 92 | |
sk398 | 6:ceda53939eb8 | 93 | |
sk398 | 6:ceda53939eb8 | 94 | protected: |
sk398 | 1:221d677fe0d3 | 95 | DigitalIn *_digitalInCheck; |
sk398 | 6:ceda53939eb8 | 96 | |
sk398 | 1:221d677fe0d3 | 97 | }; |
sk398 | 1:221d677fe0d3 | 98 | |
sk398 | 1:221d677fe0d3 | 99 | |
sk398 | 1:221d677fe0d3 | 100 | /* ==================================== Task 3 ==================================== */ |
sk398 | 2:22ebabd78084 | 101 | // Output watchdog pulse |
sk398 | 1:221d677fe0d3 | 102 | class Task3 |
sk398 | 1:221d677fe0d3 | 103 | { |
sk398 | 1:221d677fe0d3 | 104 | public: |
sk398 | 1:221d677fe0d3 | 105 | Task3(PinName WatchdogPin); |
sk398 | 1:221d677fe0d3 | 106 | void OutputWatchdogPulse(); |
sk398 | 1:221d677fe0d3 | 107 | |
sk398 | 1:221d677fe0d3 | 108 | private: |
sk398 | 6:ceda53939eb8 | 109 | |
sk398 | 6:ceda53939eb8 | 110 | |
sk398 | 6:ceda53939eb8 | 111 | protected: |
sk398 | 6:ceda53939eb8 | 112 | DigitalOut *_Watchdog; |
sk398 | 6:ceda53939eb8 | 113 | |
sk398 | 1:221d677fe0d3 | 114 | }; |
sk398 | 1:221d677fe0d3 | 115 | |
sk398 | 1:221d677fe0d3 | 116 | |
sk398 | 2:22ebabd78084 | 117 | /* ==================================== Task 4 ==================================== */ |
sk398 | 2:22ebabd78084 | 118 | // Read 2 analog inputs |
sk398 | 2:22ebabd78084 | 119 | class Task4 |
sk398 | 2:22ebabd78084 | 120 | { |
sk398 | 2:22ebabd78084 | 121 | public: |
sk398 | 3:c611b9bb5770 | 122 | Task4(PinName Analog1Pin,PinName Analog2Pin); |
sk398 | 3:c611b9bb5770 | 123 | float *returnAnalogReadings(); |
sk398 | 2:22ebabd78084 | 124 | |
sk398 | 2:22ebabd78084 | 125 | private: |
sk398 | 6:ceda53939eb8 | 126 | |
sk398 | 6:ceda53939eb8 | 127 | |
sk398 | 6:ceda53939eb8 | 128 | protected: |
sk398 | 3:c611b9bb5770 | 129 | AnalogIn *_AnalogIn1; |
sk398 | 6:ceda53939eb8 | 130 | AnalogIn *_AnalogIn2; |
sk398 | 6:ceda53939eb8 | 131 | |
sk398 | 2:22ebabd78084 | 132 | }; |
sk398 | 2:22ebabd78084 | 133 | |
sk398 | 5:250f51c80ac1 | 134 | //* ==================================== Task 5 ==================================== */ |
sk398 | 5:250f51c80ac1 | 135 | // Display outputs to LCD |
sk398 | 5:250f51c80ac1 | 136 | class Task5 |
sk398 | 5:250f51c80ac1 | 137 | { |
sk398 | 5:250f51c80ac1 | 138 | public: |
sk398 | 5:250f51c80ac1 | 139 | Task5(PinName sda, PinName scl, int address); |
sk398 | 6:ceda53939eb8 | 140 | void updateDisplay( int task1Param, |
sk398 | 6:ceda53939eb8 | 141 | int task2Param, |
sk398 | 6:ceda53939eb8 | 142 | int errorState, |
sk398 | 6:ceda53939eb8 | 143 | float task4Channel1, |
sk398 | 6:ceda53939eb8 | 144 | float task4Channel2 ); |
sk398 | 6:ceda53939eb8 | 145 | |
sk398 | 5:250f51c80ac1 | 146 | private: |
sk398 | 5:250f51c80ac1 | 147 | |
sk398 | 5:250f51c80ac1 | 148 | |
sk398 | 5:250f51c80ac1 | 149 | protected: |
sk398 | 5:250f51c80ac1 | 150 | MCP23017 *_par_port; |
sk398 | 6:ceda53939eb8 | 151 | WattBob_TextLCD *_lcd; |
sk398 | 6:ceda53939eb8 | 152 | |
sk398 | 5:250f51c80ac1 | 153 | }; |
sk398 | 6:ceda53939eb8 | 154 | |
sk398 | 3:c611b9bb5770 | 155 | ///* ==================================== Task 6 ==================================== */ |
sk398 | 6:ceda53939eb8 | 156 | // Logical checks |
sk398 | 6:ceda53939eb8 | 157 | class Task6 |
sk398 | 6:ceda53939eb8 | 158 | { |
sk398 | 6:ceda53939eb8 | 159 | public: |
sk398 | 6:ceda53939eb8 | 160 | int updateErrorCode(int switch_1, float analog1, float analog2); |
sk398 | 6:ceda53939eb8 | 161 | |
sk398 | 6:ceda53939eb8 | 162 | private: |
sk398 | 6:ceda53939eb8 | 163 | |
sk398 | 6:ceda53939eb8 | 164 | |
sk398 | 6:ceda53939eb8 | 165 | protected: |
sk398 | 6:ceda53939eb8 | 166 | |
sk398 | 6:ceda53939eb8 | 167 | |
sk398 | 6:ceda53939eb8 | 168 | }; |
sk398 | 6:ceda53939eb8 | 169 | |
sk398 | 6:ceda53939eb8 | 170 | /* ==================================== Task 7 ==================================== */ |
sk398 | 6:ceda53939eb8 | 171 | // Save data to SD Card |
sk398 | 6:ceda53939eb8 | 172 | class Task7 |
sk398 | 6:ceda53939eb8 | 173 | { |
sk398 | 6:ceda53939eb8 | 174 | public: |
sk398 | 6:ceda53939eb8 | 175 | Task7( PinName mosi, |
sk398 | 6:ceda53939eb8 | 176 | PinName miso, |
sk398 | 6:ceda53939eb8 | 177 | PinName sck, |
sk398 | 6:ceda53939eb8 | 178 | PinName cs, |
sk398 | 6:ceda53939eb8 | 179 | const char* SDName, |
sk398 | 6:ceda53939eb8 | 180 | const char *dir ); |
sk398 | 6:ceda53939eb8 | 181 | |
sk398 | 6:ceda53939eb8 | 182 | void writeData(const char *dataStream); |
sk398 | 6:ceda53939eb8 | 183 | int openFile(const char *dirFile, const char *accessType); |
sk398 | 6:ceda53939eb8 | 184 | void closeFile(); |
sk398 | 6:ceda53939eb8 | 185 | |
sk398 | 6:ceda53939eb8 | 186 | private: |
sk398 | 6:ceda53939eb8 | 187 | void makeDirectory(const char *dir); |
sk398 | 6:ceda53939eb8 | 188 | |
sk398 | 6:ceda53939eb8 | 189 | protected: |
sk398 | 6:ceda53939eb8 | 190 | SDFileSystem *_sd; |
sk398 | 6:ceda53939eb8 | 191 | FILE *fp; |
sk398 | 6:ceda53939eb8 | 192 | }; |
sk398 | 1:221d677fe0d3 | 193 | |
sk398 | 1:221d677fe0d3 | 194 | #endif |