Example software for a Cyclic Executive
Dependencies: MCP23017 SDFileSystem WattBob_TextLCD mbed
Tasks.h@7:2973bf297f3d, 2016-03-02 (annotated)
- Committer:
- sk398
- Date:
- Wed Mar 02 00:51:17 2016 +0000
- Revision:
- 7:2973bf297f3d
- Parent:
- 6:ceda53939eb8
- Child:
- 10:c0531edf4850
All tasks bar 2 and 3 Operational with relatively good timing
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 | 7:2973bf297f3d | 43 | #define WATCHDOG_PULSE_WIDTH 15 // ms |
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 | 7:2973bf297f3d | 53 | #define BACK_LIGHT_ON(INTERFACE) INTERFACE->write_bit(1,BL_BIT) |
sk398 | 7:2973bf297f3d | 54 | #define BACK_LIGHT_OFF(INTERFACE) INTERFACE->write_bit(0,BL_BIT) |
sk398 | 2:22ebabd78084 | 55 | |
sk398 | 2:22ebabd78084 | 56 | // Task 6 definitions |
sk398 | 6:ceda53939eb8 | 57 | #define ERROR_CODE_CDTN_MET 3 |
sk398 | 6:ceda53939eb8 | 58 | #define ERROR_CODE_CDTN_FAIL 0 |
sk398 | 2:22ebabd78084 | 59 | |
sk398 | 7:2973bf297f3d | 60 | |
sk398 | 2:22ebabd78084 | 61 | /* ####################### Class definitions and prototypes ####################### */ |
sk398 | 1:221d677fe0d3 | 62 | |
sk398 | 1:221d677fe0d3 | 63 | /* ==================================== Task 1 ==================================== */ |
sk398 | 2:22ebabd78084 | 64 | // Measure freuqnecy |
sk398 | 1:221d677fe0d3 | 65 | class Task1 |
sk398 | 1:221d677fe0d3 | 66 | { |
sk398 | 1:221d677fe0d3 | 67 | public: |
sk398 | 1:221d677fe0d3 | 68 | Task1(PinName squareWaveInPin); |
sk398 | 4:b85bc0d810e1 | 69 | int ReadFrequency(); |
sk398 | 1:221d677fe0d3 | 70 | |
sk398 | 1:221d677fe0d3 | 71 | private: |
sk398 | 4:b85bc0d810e1 | 72 | Timer _Task1Timer; |
sk398 | 4:b85bc0d810e1 | 73 | |
sk398 | 4:b85bc0d810e1 | 74 | void MeasureFrequency(); |
sk398 | 4:b85bc0d810e1 | 75 | void StopCounter(); |
sk398 | 4:b85bc0d810e1 | 76 | |
sk398 | 4:b85bc0d810e1 | 77 | volatile int measuredFrequency; |
sk398 | 4:b85bc0d810e1 | 78 | |
sk398 | 4:b85bc0d810e1 | 79 | InterruptIn *_squareWaveIn; |
sk398 | 6:ceda53939eb8 | 80 | |
sk398 | 6:ceda53939eb8 | 81 | protected: |
sk398 | 1:221d677fe0d3 | 82 | |
sk398 | 1:221d677fe0d3 | 83 | }; |
sk398 | 1:221d677fe0d3 | 84 | |
sk398 | 1:221d677fe0d3 | 85 | |
sk398 | 1:221d677fe0d3 | 86 | /* ==================================== Task 2 ==================================== */ |
sk398 | 2:22ebabd78084 | 87 | // Digital Input |
sk398 | 1:221d677fe0d3 | 88 | class Task2 |
sk398 | 1:221d677fe0d3 | 89 | { |
sk398 | 1:221d677fe0d3 | 90 | public: |
sk398 | 1:221d677fe0d3 | 91 | Task2(PinName digitalInCheckPin); |
sk398 | 3:c611b9bb5770 | 92 | bool digitalInState(); |
sk398 | 3:c611b9bb5770 | 93 | |
sk398 | 1:221d677fe0d3 | 94 | private: |
sk398 | 6:ceda53939eb8 | 95 | |
sk398 | 6:ceda53939eb8 | 96 | |
sk398 | 6:ceda53939eb8 | 97 | protected: |
sk398 | 1:221d677fe0d3 | 98 | DigitalIn *_digitalInCheck; |
sk398 | 6:ceda53939eb8 | 99 | |
sk398 | 1:221d677fe0d3 | 100 | }; |
sk398 | 1:221d677fe0d3 | 101 | |
sk398 | 1:221d677fe0d3 | 102 | |
sk398 | 1:221d677fe0d3 | 103 | /* ==================================== Task 3 ==================================== */ |
sk398 | 2:22ebabd78084 | 104 | // Output watchdog pulse |
sk398 | 1:221d677fe0d3 | 105 | class Task3 |
sk398 | 1:221d677fe0d3 | 106 | { |
sk398 | 1:221d677fe0d3 | 107 | public: |
sk398 | 1:221d677fe0d3 | 108 | Task3(PinName WatchdogPin); |
sk398 | 1:221d677fe0d3 | 109 | void OutputWatchdogPulse(); |
sk398 | 1:221d677fe0d3 | 110 | |
sk398 | 1:221d677fe0d3 | 111 | private: |
sk398 | 6:ceda53939eb8 | 112 | |
sk398 | 6:ceda53939eb8 | 113 | |
sk398 | 6:ceda53939eb8 | 114 | protected: |
sk398 | 6:ceda53939eb8 | 115 | DigitalOut *_Watchdog; |
sk398 | 6:ceda53939eb8 | 116 | |
sk398 | 1:221d677fe0d3 | 117 | }; |
sk398 | 1:221d677fe0d3 | 118 | |
sk398 | 1:221d677fe0d3 | 119 | |
sk398 | 2:22ebabd78084 | 120 | /* ==================================== Task 4 ==================================== */ |
sk398 | 2:22ebabd78084 | 121 | // Read 2 analog inputs |
sk398 | 2:22ebabd78084 | 122 | class Task4 |
sk398 | 2:22ebabd78084 | 123 | { |
sk398 | 2:22ebabd78084 | 124 | public: |
sk398 | 3:c611b9bb5770 | 125 | Task4(PinName Analog1Pin,PinName Analog2Pin); |
sk398 | 3:c611b9bb5770 | 126 | float *returnAnalogReadings(); |
sk398 | 2:22ebabd78084 | 127 | |
sk398 | 2:22ebabd78084 | 128 | private: |
sk398 | 6:ceda53939eb8 | 129 | |
sk398 | 6:ceda53939eb8 | 130 | |
sk398 | 6:ceda53939eb8 | 131 | protected: |
sk398 | 3:c611b9bb5770 | 132 | AnalogIn *_AnalogIn1; |
sk398 | 6:ceda53939eb8 | 133 | AnalogIn *_AnalogIn2; |
sk398 | 6:ceda53939eb8 | 134 | |
sk398 | 2:22ebabd78084 | 135 | }; |
sk398 | 2:22ebabd78084 | 136 | |
sk398 | 5:250f51c80ac1 | 137 | //* ==================================== Task 5 ==================================== */ |
sk398 | 5:250f51c80ac1 | 138 | // Display outputs to LCD |
sk398 | 5:250f51c80ac1 | 139 | class Task5 |
sk398 | 5:250f51c80ac1 | 140 | { |
sk398 | 5:250f51c80ac1 | 141 | public: |
sk398 | 5:250f51c80ac1 | 142 | Task5(PinName sda, PinName scl, int address); |
sk398 | 6:ceda53939eb8 | 143 | void updateDisplay( int task1Param, |
sk398 | 6:ceda53939eb8 | 144 | int task2Param, |
sk398 | 6:ceda53939eb8 | 145 | int errorState, |
sk398 | 6:ceda53939eb8 | 146 | float task4Channel1, |
sk398 | 6:ceda53939eb8 | 147 | float task4Channel2 ); |
sk398 | 6:ceda53939eb8 | 148 | |
sk398 | 5:250f51c80ac1 | 149 | private: |
sk398 | 5:250f51c80ac1 | 150 | |
sk398 | 5:250f51c80ac1 | 151 | |
sk398 | 5:250f51c80ac1 | 152 | protected: |
sk398 | 5:250f51c80ac1 | 153 | MCP23017 *_par_port; |
sk398 | 6:ceda53939eb8 | 154 | WattBob_TextLCD *_lcd; |
sk398 | 6:ceda53939eb8 | 155 | |
sk398 | 5:250f51c80ac1 | 156 | }; |
sk398 | 6:ceda53939eb8 | 157 | |
sk398 | 3:c611b9bb5770 | 158 | ///* ==================================== Task 6 ==================================== */ |
sk398 | 6:ceda53939eb8 | 159 | // Logical checks |
sk398 | 6:ceda53939eb8 | 160 | class Task6 |
sk398 | 6:ceda53939eb8 | 161 | { |
sk398 | 6:ceda53939eb8 | 162 | public: |
sk398 | 6:ceda53939eb8 | 163 | int updateErrorCode(int switch_1, float analog1, float analog2); |
sk398 | 6:ceda53939eb8 | 164 | |
sk398 | 6:ceda53939eb8 | 165 | private: |
sk398 | 6:ceda53939eb8 | 166 | |
sk398 | 6:ceda53939eb8 | 167 | |
sk398 | 6:ceda53939eb8 | 168 | protected: |
sk398 | 6:ceda53939eb8 | 169 | |
sk398 | 6:ceda53939eb8 | 170 | |
sk398 | 6:ceda53939eb8 | 171 | }; |
sk398 | 6:ceda53939eb8 | 172 | |
sk398 | 6:ceda53939eb8 | 173 | /* ==================================== Task 7 ==================================== */ |
sk398 | 6:ceda53939eb8 | 174 | // Save data to SD Card |
sk398 | 6:ceda53939eb8 | 175 | class Task7 |
sk398 | 6:ceda53939eb8 | 176 | { |
sk398 | 6:ceda53939eb8 | 177 | public: |
sk398 | 6:ceda53939eb8 | 178 | Task7( PinName mosi, |
sk398 | 6:ceda53939eb8 | 179 | PinName miso, |
sk398 | 6:ceda53939eb8 | 180 | PinName sck, |
sk398 | 6:ceda53939eb8 | 181 | PinName cs, |
sk398 | 6:ceda53939eb8 | 182 | const char* SDName, |
sk398 | 6:ceda53939eb8 | 183 | const char *dir ); |
sk398 | 6:ceda53939eb8 | 184 | |
sk398 | 6:ceda53939eb8 | 185 | void writeData(const char *dataStream); |
sk398 | 6:ceda53939eb8 | 186 | int openFile(const char *dirFile, const char *accessType); |
sk398 | 6:ceda53939eb8 | 187 | void closeFile(); |
sk398 | 6:ceda53939eb8 | 188 | |
sk398 | 6:ceda53939eb8 | 189 | private: |
sk398 | 6:ceda53939eb8 | 190 | void makeDirectory(const char *dir); |
sk398 | 6:ceda53939eb8 | 191 | |
sk398 | 6:ceda53939eb8 | 192 | protected: |
sk398 | 6:ceda53939eb8 | 193 | SDFileSystem *_sd; |
sk398 | 6:ceda53939eb8 | 194 | FILE *fp; |
sk398 | 6:ceda53939eb8 | 195 | }; |
sk398 | 1:221d677fe0d3 | 196 | |
sk398 | 1:221d677fe0d3 | 197 | #endif |