Example software for a Cyclic Executive
Dependencies: MCP23017 SDFileSystem WattBob_TextLCD mbed
main.cpp@0:5989ac10c4d3, 2016-02-15 (annotated)
- Committer:
- sk398
- Date:
- Mon Feb 15 21:56:19 2016 +0000
- Revision:
- 0:5989ac10c4d3
- Child:
- 1:221d677fe0d3
All tasks implemented as classes and in a single file.; ; Task3 is fnished; All others are not
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sk398 | 0:5989ac10c4d3 | 1 | #include "mbed.h" |
sk398 | 0:5989ac10c4d3 | 2 | |
sk398 | 0:5989ac10c4d3 | 3 | #define WATCHDOG_PULSE_WIDTH 15 |
sk398 | 0:5989ac10c4d3 | 4 | |
sk398 | 0:5989ac10c4d3 | 5 | class Task1 // Square Wave Reader - read every second |
sk398 | 0:5989ac10c4d3 | 6 | { |
sk398 | 0:5989ac10c4d3 | 7 | |
sk398 | 0:5989ac10c4d3 | 8 | public: |
sk398 | 0:5989ac10c4d3 | 9 | Task1::Task1(PinName squareWaveInPin) |
sk398 | 0:5989ac10c4d3 | 10 | { |
sk398 | 0:5989ac10c4d3 | 11 | Timer Task1Timer; |
sk398 | 0:5989ac10c4d3 | 12 | _squareWaveIn = new DigitalIn(squareWaveInPin); |
sk398 | 0:5989ac10c4d3 | 13 | } |
sk398 | 0:5989ac10c4d3 | 14 | |
sk398 | 0:5989ac10c4d3 | 15 | int Task1::MeasureFreq() |
sk398 | 0:5989ac10c4d3 | 16 | { |
sk398 | 0:5989ac10c4d3 | 17 | |
sk398 | 0:5989ac10c4d3 | 18 | |
sk398 | 0:5989ac10c4d3 | 19 | } |
sk398 | 0:5989ac10c4d3 | 20 | |
sk398 | 0:5989ac10c4d3 | 21 | |
sk398 | 0:5989ac10c4d3 | 22 | private: |
sk398 | 0:5989ac10c4d3 | 23 | |
sk398 | 0:5989ac10c4d3 | 24 | DigitalIn *_squareWaveIn; |
sk398 | 0:5989ac10c4d3 | 25 | }; |
sk398 | 0:5989ac10c4d3 | 26 | |
sk398 | 0:5989ac10c4d3 | 27 | class Task2 // Digital Input Reader - Read every 300ms |
sk398 | 0:5989ac10c4d3 | 28 | { |
sk398 | 0:5989ac10c4d3 | 29 | public: |
sk398 | 0:5989ac10c4d3 | 30 | Task2::Task2() |
sk398 | 0:5989ac10c4d3 | 31 | { |
sk398 | 0:5989ac10c4d3 | 32 | |
sk398 | 0:5989ac10c4d3 | 33 | } |
sk398 | 0:5989ac10c4d3 | 34 | |
sk398 | 0:5989ac10c4d3 | 35 | private: |
sk398 | 0:5989ac10c4d3 | 36 | |
sk398 | 0:5989ac10c4d3 | 37 | }; |
sk398 | 0:5989ac10c4d3 | 38 | |
sk398 | 0:5989ac10c4d3 | 39 | class Task3 // Watchdog Pulse - output every 300ms |
sk398 | 0:5989ac10c4d3 | 40 | { |
sk398 | 0:5989ac10c4d3 | 41 | public: |
sk398 | 0:5989ac10c4d3 | 42 | Task3::Task3(WatchdogPin) |
sk398 | 0:5989ac10c4d3 | 43 | { |
sk398 | 0:5989ac10c4d3 | 44 | _Watchdog = new DigitalOut(WatchdogPin) |
sk398 | 0:5989ac10c4d3 | 45 | } |
sk398 | 0:5989ac10c4d3 | 46 | |
sk398 | 0:5989ac10c4d3 | 47 | Task3::OutputWatchdogPulse() |
sk398 | 0:5989ac10c4d3 | 48 | { |
sk398 | 0:5989ac10c4d3 | 49 | _Watchdog -> write(HIGH); |
sk398 | 0:5989ac10c4d3 | 50 | wait_ms(WATCHDOG_PULSE_WIDTH); |
sk398 | 0:5989ac10c4d3 | 51 | _Watchdog -> wirte(LOW); |
sk398 | 0:5989ac10c4d3 | 52 | } |
sk398 | 0:5989ac10c4d3 | 53 | |
sk398 | 0:5989ac10c4d3 | 54 | private: |
sk398 | 0:5989ac10c4d3 | 55 | DigitalOut *_Watchdog; |
sk398 | 0:5989ac10c4d3 | 56 | |
sk398 | 0:5989ac10c4d3 | 57 | }; |
sk398 | 0:5989ac10c4d3 | 58 | |
sk398 | 0:5989ac10c4d3 | 59 | class Task4 // Read Analogue inputs - read every 400ms |
sk398 | 0:5989ac10c4d3 | 60 | { |
sk398 | 0:5989ac10c4d3 | 61 | public: |
sk398 | 0:5989ac10c4d3 | 62 | Task4::Task4() |
sk398 | 0:5989ac10c4d3 | 63 | { |
sk398 | 0:5989ac10c4d3 | 64 | |
sk398 | 0:5989ac10c4d3 | 65 | } |
sk398 | 0:5989ac10c4d3 | 66 | |
sk398 | 0:5989ac10c4d3 | 67 | private: |
sk398 | 0:5989ac10c4d3 | 68 | |
sk398 | 0:5989ac10c4d3 | 69 | }; |
sk398 | 0:5989ac10c4d3 | 70 | |
sk398 | 0:5989ac10c4d3 | 71 | DigitalOut myled(LED1); |
sk398 | 0:5989ac10c4d3 | 72 | |
sk398 | 0:5989ac10c4d3 | 73 | Task1 task1(p5); // Square wave Measurement |
sk398 | 0:5989ac10c4d3 | 74 | |
sk398 | 0:5989ac10c4d3 | 75 | Task2 task3(p6); // Watchdog Pulse |
sk398 | 0:5989ac10c4d3 | 76 | |
sk398 | 0:5989ac10c4d3 | 77 | |
sk398 | 0:5989ac10c4d3 | 78 | int main() { |
sk398 | 0:5989ac10c4d3 | 79 | while(1) { |
sk398 | 0:5989ac10c4d3 | 80 | myled = 1; |
sk398 | 0:5989ac10c4d3 | 81 | wait(0.2); |
sk398 | 0:5989ac10c4d3 | 82 | myled = 0; |
sk398 | 0:5989ac10c4d3 | 83 | wait(0.2); |
sk398 | 0:5989ac10c4d3 | 84 | } |
sk398 | 0:5989ac10c4d3 | 85 | } |