brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 1 | #ifndef AOS_CRIO_MOTOR_SERVER_CRIO_CONTROL_LOOP_RUNNER_H_ |
| 2 | #define AOS_CRIO_MOTOR_SERVER_CRIO_CONTROL_LOOP_RUNNER_H_ |
| 3 | |
| 4 | #include <vector> |
| 5 | #include <semLib.h> |
| 6 | |
| 7 | #include "aos/common/control_loop/ControlLoop.h" |
| 8 | #include "aos/common/mutex.h" |
| 9 | |
| 10 | namespace aos { |
| 11 | namespace crio { |
| 12 | |
| 13 | // Runs crio-side control loops. Completely static because there is no reason |
| 14 | // for multiple ones and it gets rid of the problem of passing an instance |
| 15 | // around. |
| 16 | class CRIOControlLoopRunner { |
| 17 | public: |
| 18 | // Spawns a new Task that loops forever. |
| 19 | // No other functions should be called before this one returns. |
| 20 | static void Start(); |
| 21 | |
| 22 | // Adds a control loop to run. |
| 23 | // This class takes control of the instance. |
| 24 | static void AddControlLoop(control_loops::SerializableControlLoop *loop); |
| 25 | |
| 26 | private: |
| 27 | static bool started_; |
| 28 | |
| 29 | static std::vector<control_loops::SerializableControlLoop *> loops_; |
| 30 | static Mutex loops_lock; |
| 31 | |
| 32 | // Gets called by a WDInterruptNotifier on 0.01 second intervals. |
| 33 | static void Notify(void *); |
| 34 | }; |
| 35 | |
| 36 | |
| 37 | } // namespace crio |
| 38 | } // namespace aos |
| 39 | |
| 40 | #endif |