fast-feedback virtual target task code on STM Nucleo

Dependencies:   mbed

Committer:
gwappa
Date:
Thu Dec 13 07:18:43 2018 +0000
Revision:
32:1416e015016c
Parent:
29:1fb060aab1f8
change to use the Staged state

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gwappa 12:06ea96546af1 1 #ifndef PULSE_H_
gwappa 12:06ea96546af1 2 #define PULSE_H_
gwappa 12:06ea96546af1 3
gwappa 12:06ea96546af1 4 #include "mbed.h"
gwappa 12:06ea96546af1 5
gwappa 12:06ea96546af1 6
gwappa 12:06ea96546af1 7 /**
gwappa 12:06ea96546af1 8 * implementation for turning on the port
gwappa 12:06ea96546af1 9 * for a specified duration (using a timer).
gwappa 12:06ea96546af1 10 *
gwappa 12:06ea96546af1 11 * the state of a Pulse instance follows the
gwappa 12:06ea96546af1 12 * sequence below, after calling the run() method:
gwappa 12:06ea96546af1 13 *
gwappa 12:06ea96546af1 14 * Rest -(user calling: run)-> Armed (output=L)
gwappa 12:06ea96546af1 15 * Armed -(after onset: start)-> Active (output=H)
gwappa 12:06ea96546af1 16 * Active -(after dur: stop)-> Rest (output=L)
gwappa 12:06ea96546af1 17 *
gwappa 12:06ea96546af1 18 * Although you can generate a force-transition to the specified state
gwappa 12:06ea96546af1 19 * by calling e.g. start() or stop(), it is not a recommended usage.
gwappa 12:06ea96546af1 20 */
gwappa 12:06ea96546af1 21 class Pulse
gwappa 12:06ea96546af1 22 {
gwappa 12:06ea96546af1 23 public:
gwappa 12:06ea96546af1 24 enum Status {
gwappa 12:06ea96546af1 25 Armed,
gwappa 12:06ea96546af1 26 Active,
gwappa 12:06ea96546af1 27 Interrupted,
gwappa 12:06ea96546af1 28 Rest
gwappa 12:06ea96546af1 29 };
gwappa 12:06ea96546af1 30
gwappa 20:4c06d3041337 31 Pulse(PinName pin, const uint64_t& onset_us=0, const uint64_t& duration_us=1000, const uint64_t& blink_us=0);
gwappa 20:4c06d3041337 32
gwappa 15:20f7f737c256 33 void setEnabled(const bool& value);
gwappa 15:20f7f737c256 34 bool isEnabled();
gwappa 12:06ea96546af1 35 void setOnset(const uint64_t& value_us);
gwappa 12:06ea96546af1 36 void setDuration(const uint64_t& value_us);
gwappa 20:4c06d3041337 37 void setBlinkDuration(const uint64_t& vaue_us);
gwappa 20:4c06d3041337 38
gwappa 12:06ea96546af1 39 void attachTurnOnCallback(Callback<void ()> cb=0);
gwappa 12:06ea96546af1 40 void attachTurnOffCallback(Callback<void ()> cb=0);
gwappa 12:06ea96546af1 41 void detachTurnOnCallback();
gwappa 12:06ea96546af1 42 void detachTurnOffCallback();
gwappa 12:06ea96546af1 43
gwappa 12:06ea96546af1 44 /**
gwappa 12:06ea96546af1 45 * runs the pulse output.
gwappa 12:06ea96546af1 46 *
gwappa 12:06ea96546af1 47 * the state of this Pulse can be retrieved via getStatus().
gwappa 12:06ea96546af1 48 */
gwappa 12:06ea96546af1 49 void run();
gwappa 12:06ea96546af1 50
gwappa 12:06ea96546af1 51 /**
gwappa 12:06ea96546af1 52 * force-start the output.
gwappa 12:06ea96546af1 53 */
gwappa 12:06ea96546af1 54 void start();
gwappa 12:06ea96546af1 55
gwappa 12:06ea96546af1 56 /**
gwappa 12:06ea96546af1 57 * aborts the output.
gwappa 12:06ea96546af1 58 */
gwappa 12:06ea96546af1 59 void stop();
gwappa 12:06ea96546af1 60
gwappa 12:06ea96546af1 61 /**
gwappa 12:06ea96546af1 62 * use this output as a normal DigitalOut
gwappa 12:06ea96546af1 63 */
gwappa 12:06ea96546af1 64 void direct(const bool& value);
gwappa 12:06ea96546af1 65
gwappa 12:06ea96546af1 66 Status getStatus();
gwappa 12:06ea96546af1 67
gwappa 12:06ea96546af1 68 /**
gwappa 12:06ea96546af1 69 * busy-wait until its status becomes from Active to Rest.
gwappa 12:06ea96546af1 70 * if the status is already at Rest, then it returns immediately.
gwappa 12:06ea96546af1 71 */
gwappa 12:06ea96546af1 72 void wait();
gwappa 29:1fb060aab1f8 73
gwappa 29:1fb060aab1f8 74 void loginfo();
gwappa 12:06ea96546af1 75
gwappa 12:06ea96546af1 76 private:
gwappa 20:4c06d3041337 77 void blink();
gwappa 12:06ea96546af1 78
gwappa 12:06ea96546af1 79 DigitalOut out_;
gwappa 12:06ea96546af1 80 Timeout timer_;
gwappa 20:4c06d3041337 81 Ticker blinker_;
gwappa 15:20f7f737c256 82 bool enabled_;
gwappa 12:06ea96546af1 83 uint64_t onset_;
gwappa 12:06ea96546af1 84 uint64_t dur_;
gwappa 20:4c06d3041337 85 uint64_t blinkdur_;
gwappa 12:06ea96546af1 86 Callback<void ()> turnon_;
gwappa 12:06ea96546af1 87 Callback<void ()> turnoff_;
gwappa 12:06ea96546af1 88
gwappa 12:06ea96546af1 89 volatile Status stat_;
gwappa 12:06ea96546af1 90 };
gwappa 12:06ea96546af1 91
gwappa 12:06ea96546af1 92 #endif