See graph

Dependencies:   MCP23017 SDFileSystem WattBob_TextLCD mbed

Fork of Embedded_Software_Assignment_2 by Steven Kay

Committer:
xouf2114
Date:
Tue Mar 14 14:02:28 2017 +0000
Revision:
14:f11c30a93736
Parent:
11:1069d300847b
define task_ticks

Who changed what in which revision?

UserRevisionLine numberNew 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
xouf2114 11:1069d300847b 8 Written by: Xavier Gouesnard
sk398 4:b85bc0d810e1 9
xouf2114 11:1069d300847b 10 Date: March 2017
sk398 4:b85bc0d810e1 11
sk398 10:c0531edf4850 12 Function: This file contains the function prototypes for the
sk398 10:c0531edf4850 13 included classes and methods. It also details some
sk398 10:c0531edf4850 14 constants used within the program and includes AUX
sk398 10:c0531edf4850 15 files, for instance the LCD system and the SD card.
sk398 10:c0531edf4850 16
sk398 4:b85bc0d810e1 17 ##################################################################### */
sk398 2:22ebabd78084 18
sk398 1:221d677fe0d3 19 #ifndef _TASKS_H_
sk398 1:221d677fe0d3 20 #define _TASKS_H_
sk398 1:221d677fe0d3 21
sk398 6:ceda53939eb8 22 // Includes to operate the LCD Display
sk398 5:250f51c80ac1 23 #include "MCP23017.h"
sk398 5:250f51c80ac1 24 #include "WattBob_TextLCD.h"
sk398 5:250f51c80ac1 25
sk398 6:ceda53939eb8 26 // Includes to operate the SD Card system
sk398 6:ceda53939eb8 27 #include "SDFileSystem.h"
sk398 6:ceda53939eb8 28
sk398 2:22ebabd78084 29 // Global definitions
sk398 1:221d677fe0d3 30 #define HIGH 1
sk398 1:221d677fe0d3 31 #define LOW 0
sk398 3:c611b9bb5770 32 #define TRUE 1
sk398 3:c611b9bb5770 33 #define FALSE 0
sk398 3:c611b9bb5770 34
sk398 2:22ebabd78084 35 // Task 1 definitions
sk398 10:c0531edf4850 36 #define SAMPLE_FREQ 1
sk398 10:c0531edf4850 37
sk398 2:22ebabd78084 38 // Task 2 definitions
sk398 2:22ebabd78084 39
sk398 2:22ebabd78084 40 // Task 3 definitions
sk398 10:c0531edf4850 41 #define WATCHDOG_PULSE_WIDTH 15 // ms
sk398 2:22ebabd78084 42
sk398 2:22ebabd78084 43 // Task 4 definitions
sk398 4:b85bc0d810e1 44 #define NUM_ANALOG_SAMPLES 4.0
sk398 10:c0531edf4850 45 #define V_SUPPLY 3.3
sk398 2:22ebabd78084 46
sk398 2:22ebabd78084 47 // Task 5 definitions
sk398 7:2973bf297f3d 48 #define BACK_LIGHT_ON(INTERFACE) INTERFACE->write_bit(1,BL_BIT)
sk398 7:2973bf297f3d 49 #define BACK_LIGHT_OFF(INTERFACE) INTERFACE->write_bit(0,BL_BIT)
sk398 2:22ebabd78084 50
sk398 2:22ebabd78084 51 // Task 6 definitions
sk398 6:ceda53939eb8 52 #define ERROR_CODE_CDTN_MET 3
sk398 6:ceda53939eb8 53 #define ERROR_CODE_CDTN_FAIL 0
sk398 2:22ebabd78084 54
sk398 7:2973bf297f3d 55
sk398 2:22ebabd78084 56 /* ####################### Class definitions and prototypes ####################### */
sk398 1:221d677fe0d3 57
sk398 1:221d677fe0d3 58 /* ==================================== Task 1 ==================================== */
sk398 2:22ebabd78084 59 // Measure freuqnecy
sk398 1:221d677fe0d3 60 class Task1
sk398 1:221d677fe0d3 61 {
sk398 1:221d677fe0d3 62 public:
sk398 10:c0531edf4850 63 // Public constructer method
sk398 1:221d677fe0d3 64 Task1(PinName squareWaveInPin);
sk398 10:c0531edf4850 65
sk398 10:c0531edf4850 66 // Public method which initiates and returns a frequency measurement
sk398 4:b85bc0d810e1 67 int ReadFrequency();
sk398 1:221d677fe0d3 68
sk398 1:221d677fe0d3 69 private:
sk398 10:c0531edf4850 70 // Private Timer object used to count the high or low time of input signal
sk398 4:b85bc0d810e1 71 Timer _Task1Timer;
sk398 4:b85bc0d810e1 72
sk398 10:c0531edf4850 73 // Private method which contains the logic to measure frequency
sk398 4:b85bc0d810e1 74 void MeasureFrequency();
sk398 4:b85bc0d810e1 75
sk398 10:c0531edf4850 76 // Private and volatile field contains most recent frequency
sk398 10:c0531edf4850 77 // Volatile to avoid the compiler modifying it for any reason
sk398 10:c0531edf4850 78 volatile int measuredFrequency;
sk398 10:c0531edf4850 79
sk398 6:ceda53939eb8 80 protected:
sk398 10:c0531edf4850 81 // Pointer to DigitalIn object
sk398 10:c0531edf4850 82 DigitalIn *_squareWaveIn;
sk398 1:221d677fe0d3 83 };
sk398 1:221d677fe0d3 84
xouf2114 14:f11c30a93736 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 10:c0531edf4850 91 // Public constructer method
sk398 1:221d677fe0d3 92 Task2(PinName digitalInCheckPin);
sk398 10:c0531edf4850 93
sk398 10:c0531edf4850 94 // Public method to return the state of the DigitalIn pin
sk398 3:c611b9bb5770 95 bool digitalInState();
sk398 3:c611b9bb5770 96
sk398 1:221d677fe0d3 97 private:
sk398 6:ceda53939eb8 98
sk398 6:ceda53939eb8 99
sk398 6:ceda53939eb8 100 protected:
sk398 10:c0531edf4850 101 // Pointer to DigitalIn Object
sk398 1:221d677fe0d3 102 DigitalIn *_digitalInCheck;
sk398 1:221d677fe0d3 103 };
sk398 1:221d677fe0d3 104
sk398 1:221d677fe0d3 105
sk398 1:221d677fe0d3 106 /* ==================================== Task 3 ==================================== */
sk398 2:22ebabd78084 107 // Output watchdog pulse
sk398 1:221d677fe0d3 108 class Task3
sk398 1:221d677fe0d3 109 {
sk398 1:221d677fe0d3 110 public:
sk398 10:c0531edf4850 111 // Public constructer method
sk398 1:221d677fe0d3 112 Task3(PinName WatchdogPin);
sk398 10:c0531edf4850 113
sk398 10:c0531edf4850 114 // Public method to output watchdog pulse opon calling method
sk398 1:221d677fe0d3 115 void OutputWatchdogPulse();
sk398 1:221d677fe0d3 116
sk398 1:221d677fe0d3 117 private:
sk398 6:ceda53939eb8 118
sk398 6:ceda53939eb8 119
sk398 6:ceda53939eb8 120 protected:
sk398 10:c0531edf4850 121 // Pointer to DigitalOut Object
sk398 6:ceda53939eb8 122 DigitalOut *_Watchdog;
sk398 1:221d677fe0d3 123 };
sk398 1:221d677fe0d3 124
sk398 1:221d677fe0d3 125
sk398 2:22ebabd78084 126 /* ==================================== Task 4 ==================================== */
sk398 2:22ebabd78084 127 // Read 2 analog inputs
sk398 2:22ebabd78084 128 class Task4
sk398 2:22ebabd78084 129 {
sk398 2:22ebabd78084 130 public:
sk398 10:c0531edf4850 131 // Public constructer method
sk398 3:c611b9bb5770 132 Task4(PinName Analog1Pin,PinName Analog2Pin);
sk398 10:c0531edf4850 133
sk398 10:c0531edf4850 134 // Public method to return pointer to array containing
sk398 10:c0531edf4850 135 // the filtered analog results, increment pointer once for both results
sk398 3:c611b9bb5770 136 float *returnAnalogReadings();
sk398 2:22ebabd78084 137
sk398 2:22ebabd78084 138 private:
sk398 6:ceda53939eb8 139
sk398 6:ceda53939eb8 140
sk398 6:ceda53939eb8 141 protected:
sk398 10:c0531edf4850 142 // Pointers to AnalogIn channels
sk398 3:c611b9bb5770 143 AnalogIn *_AnalogIn1;
sk398 6:ceda53939eb8 144 AnalogIn *_AnalogIn2;
sk398 2:22ebabd78084 145 };
sk398 2:22ebabd78084 146
sk398 5:250f51c80ac1 147 //* ==================================== Task 5 ==================================== */
sk398 5:250f51c80ac1 148 // Display outputs to LCD
sk398 5:250f51c80ac1 149 class Task5
sk398 5:250f51c80ac1 150 {
sk398 5:250f51c80ac1 151 public:
sk398 10:c0531edf4850 152 // Public constructer method
sk398 5:250f51c80ac1 153 Task5(PinName sda, PinName scl, int address);
sk398 10:c0531edf4850 154
sk398 10:c0531edf4850 155 // Public method to update display using input values from other tasks
sk398 6:ceda53939eb8 156 void updateDisplay( int task1Param,
sk398 6:ceda53939eb8 157 int task2Param,
sk398 6:ceda53939eb8 158 int errorState,
sk398 6:ceda53939eb8 159 float task4Channel1,
sk398 6:ceda53939eb8 160 float task4Channel2 );
sk398 6:ceda53939eb8 161
sk398 5:250f51c80ac1 162 private:
sk398 5:250f51c80ac1 163
sk398 5:250f51c80ac1 164
sk398 5:250f51c80ac1 165 protected:
sk398 10:c0531edf4850 166 // Pointers to required LCD objects
sk398 5:250f51c80ac1 167 MCP23017 *_par_port;
sk398 6:ceda53939eb8 168 WattBob_TextLCD *_lcd;
sk398 5:250f51c80ac1 169 };
sk398 6:ceda53939eb8 170
sk398 3:c611b9bb5770 171 ///* ==================================== Task 6 ==================================== */
sk398 6:ceda53939eb8 172 // Logical checks
sk398 6:ceda53939eb8 173 class Task6
sk398 6:ceda53939eb8 174 {
sk398 6:ceda53939eb8 175 public:
sk398 10:c0531edf4850 176 // Public method to calculate condition of error state
sk398 6:ceda53939eb8 177 int updateErrorCode(int switch_1, float analog1, float analog2);
sk398 6:ceda53939eb8 178
sk398 6:ceda53939eb8 179 private:
sk398 6:ceda53939eb8 180
sk398 6:ceda53939eb8 181
sk398 6:ceda53939eb8 182 protected:
sk398 6:ceda53939eb8 183
sk398 6:ceda53939eb8 184
sk398 6:ceda53939eb8 185 };
sk398 6:ceda53939eb8 186
sk398 6:ceda53939eb8 187 /* ==================================== Task 7 ==================================== */
sk398 6:ceda53939eb8 188 // Save data to SD Card
sk398 6:ceda53939eb8 189 class Task7
sk398 6:ceda53939eb8 190 {
sk398 6:ceda53939eb8 191 public:
sk398 10:c0531edf4850 192 // Public constructer method
sk398 6:ceda53939eb8 193 Task7( PinName mosi,
sk398 6:ceda53939eb8 194 PinName miso,
sk398 6:ceda53939eb8 195 PinName sck,
sk398 6:ceda53939eb8 196 PinName cs,
sk398 6:ceda53939eb8 197 const char* SDName,
sk398 6:ceda53939eb8 198 const char *dir );
sk398 10:c0531edf4850 199
sk398 10:c0531edf4850 200 // Public method to output Stream of data to open FILE
sk398 6:ceda53939eb8 201 void writeData(const char *dataStream);
sk398 10:c0531edf4850 202
sk398 10:c0531edf4850 203 // Public method to open FILE
sk398 6:ceda53939eb8 204 int openFile(const char *dirFile, const char *accessType);
sk398 10:c0531edf4850 205
sk398 10:c0531edf4850 206 // Public method to close FILE
sk398 6:ceda53939eb8 207 void closeFile();
sk398 6:ceda53939eb8 208
sk398 6:ceda53939eb8 209 private:
sk398 10:c0531edf4850 210 // Private method to construct a new directory on SD
sk398 6:ceda53939eb8 211 void makeDirectory(const char *dir);
sk398 6:ceda53939eb8 212
sk398 6:ceda53939eb8 213 protected:
sk398 10:c0531edf4850 214 // Pointer to SDFileSystem object
sk398 6:ceda53939eb8 215 SDFileSystem *_sd;
sk398 10:c0531edf4850 216
sk398 10:c0531edf4850 217 // Pointer to FILE object
sk398 6:ceda53939eb8 218 FILE *fp;
sk398 6:ceda53939eb8 219 };
sk398 1:221d677fe0d3 220
sk398 1:221d677fe0d3 221 #endif