Drivers for the mini robot designed for Princeton's MAE 433 course.
Dependencies: mbed-dsp mbed-rtos mbed
Dependents: MAE433_Library_Tester RobotBalancerv2
FixedRefresh.hpp@6:076fcae78bac, 2016-06-29 (annotated)
- Committer:
- Electrotiger
- Date:
- Wed Jun 29 19:04:28 2016 +0000
- Revision:
- 6:076fcae78bac
Added FixedRefresh class.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Electrotiger | 6:076fcae78bac | 1 | /** |
Electrotiger | 6:076fcae78bac | 2 | * @file FixedRefresh.hpp |
Electrotiger | 6:076fcae78bac | 3 | * @author Weimen Li |
Electrotiger | 6:076fcae78bac | 4 | * @date June 26th, 2016 |
Electrotiger | 6:076fcae78bac | 5 | * @class FixedRefresh |
Electrotiger | 6:076fcae78bac | 6 | * @brief This class is used in an RTOS to ensure that iterations of a loop happen at fixed time intervals, |
Electrotiger | 6:076fcae78bac | 7 | * regardless of how long other code in the loop takes. In doing so, it waits the thread that is currently |
Electrotiger | 6:076fcae78bac | 8 | * running to allow other threads to run. |
Electrotiger | 6:076fcae78bac | 9 | */ |
Electrotiger | 6:076fcae78bac | 10 | |
Electrotiger | 6:076fcae78bac | 11 | /* |
Electrotiger | 6:076fcae78bac | 12 | * FixedRefresh.hpp |
Electrotiger | 6:076fcae78bac | 13 | * |
Electrotiger | 6:076fcae78bac | 14 | * Created on: Jun 26, 2016 |
Electrotiger | 6:076fcae78bac | 15 | * Author: Developer |
Electrotiger | 6:076fcae78bac | 16 | */ |
Electrotiger | 6:076fcae78bac | 17 | |
Electrotiger | 6:076fcae78bac | 18 | #ifndef FIXEDREFRESH_HPP_ |
Electrotiger | 6:076fcae78bac | 19 | #define FIXEDREFRESH_HPP_ |
Electrotiger | 6:076fcae78bac | 20 | #include "mbed.h" |
Electrotiger | 6:076fcae78bac | 21 | #include "rtos.h" |
Electrotiger | 6:076fcae78bac | 22 | |
Electrotiger | 6:076fcae78bac | 23 | class FixedRefresh { |
Electrotiger | 6:076fcae78bac | 24 | public: |
Electrotiger | 6:076fcae78bac | 25 | /// Constructor for the FixedRefresh class. |
Electrotiger | 6:076fcae78bac | 26 | FixedRefresh(); |
Electrotiger | 6:076fcae78bac | 27 | /// Destructor for the FixedRefresh class. |
Electrotiger | 6:076fcae78bac | 28 | virtual ~FixedRefresh(); |
Electrotiger | 6:076fcae78bac | 29 | |
Electrotiger | 6:076fcae78bac | 30 | /* |
Electrotiger | 6:076fcae78bac | 31 | * @brief Function which ensures as much as possible that micros microseconds elapses |
Electrotiger | 6:076fcae78bac | 32 | * between successive calls, no matter how long the computation beforehand took. |
Electrotiger | 6:076fcae78bac | 33 | * @args micros The number of microseconds that should elapse between successive calls. |
Electrotiger | 6:076fcae78bac | 34 | * @returns false if waiting will not occur because greater than micros microseconds has |
Electrotiger | 6:076fcae78bac | 35 | * elapsed since the previous calls. If the function does return false, then your computation |
Electrotiger | 6:076fcae78bac | 36 | * is taking too much time. |
Electrotiger | 6:076fcae78bac | 37 | */ |
Electrotiger | 6:076fcae78bac | 38 | bool refresh_us(uint32_t micros); |
Electrotiger | 6:076fcae78bac | 39 | private: |
Electrotiger | 6:076fcae78bac | 40 | /// The number of microseconds to wait. |
Electrotiger | 6:076fcae78bac | 41 | uint32_t wait_us; |
Electrotiger | 6:076fcae78bac | 42 | Timer elapsedTime; |
Electrotiger | 6:076fcae78bac | 43 | Timeout waitTimer; |
Electrotiger | 6:076fcae78bac | 44 | /** |
Electrotiger | 6:076fcae78bac | 45 | * @brief Mutex that is locked |
Electrotiger | 6:076fcae78bac | 46 | */ |
Electrotiger | 6:076fcae78bac | 47 | Semaphore waitSemaphore; |
Electrotiger | 6:076fcae78bac | 48 | void timerCallback(); |
Electrotiger | 6:076fcae78bac | 49 | }; |
Electrotiger | 6:076fcae78bac | 50 | |
Electrotiger | 6:076fcae78bac | 51 | #endif /* FIXEDREFRESH_HPP_ */ |