Alex Pirciu
/
BFMC
a
include/Timer/timer.hpp@1:ceee5a608e7c, 2019-03-28 (annotated)
- Committer:
- alexpirciu
- Date:
- Thu Mar 28 07:44:42 2019 +0000
- Revision:
- 1:ceee5a608e7c
assa
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
alexpirciu | 1:ceee5a608e7c | 1 | /** |
alexpirciu | 1:ceee5a608e7c | 2 | ****************************************************************************** |
alexpirciu | 1:ceee5a608e7c | 3 | * @file Timer.hpp |
alexpirciu | 1:ceee5a608e7c | 4 | * @author RBRO/PJ-IU |
alexpirciu | 1:ceee5a608e7c | 5 | * @version V1.0.0 |
alexpirciu | 1:ceee5a608e7c | 6 | * @date day-month-2017 |
alexpirciu | 1:ceee5a608e7c | 7 | * @brief This file contains the class declaration for the timer functionality. |
alexpirciu | 1:ceee5a608e7c | 8 | ****************************************************************************** |
alexpirciu | 1:ceee5a608e7c | 9 | */ |
alexpirciu | 1:ceee5a608e7c | 10 | |
alexpirciu | 1:ceee5a608e7c | 11 | /* Inclusion guard */ |
alexpirciu | 1:ceee5a608e7c | 12 | #ifndef TIMER_HPP |
alexpirciu | 1:ceee5a608e7c | 13 | #define TIMER_HPP |
alexpirciu | 1:ceee5a608e7c | 14 | |
alexpirciu | 1:ceee5a608e7c | 15 | #include <mbed.h> |
alexpirciu | 1:ceee5a608e7c | 16 | |
alexpirciu | 1:ceee5a608e7c | 17 | /** |
alexpirciu | 1:ceee5a608e7c | 18 | * @brief It is used for implementing timers. |
alexpirciu | 1:ceee5a608e7c | 19 | * |
alexpirciu | 1:ceee5a608e7c | 20 | * @tparam N |
alexpirciu | 1:ceee5a608e7c | 21 | * @tparam 1 |
alexpirciu | 1:ceee5a608e7c | 22 | */ |
alexpirciu | 1:ceee5a608e7c | 23 | template <unsigned int N, unsigned int D = 1> |
alexpirciu | 1:ceee5a608e7c | 24 | class CTimer |
alexpirciu | 1:ceee5a608e7c | 25 | { |
alexpirciu | 1:ceee5a608e7c | 26 | public: |
alexpirciu | 1:ceee5a608e7c | 27 | /* Constructor */ |
alexpirciu | 1:ceee5a608e7c | 28 | CTimer(); |
alexpirciu | 1:ceee5a608e7c | 29 | /* Destructor */ |
alexpirciu | 1:ceee5a608e7c | 30 | virtual ~CTimer(); |
alexpirciu | 1:ceee5a608e7c | 31 | /* Start timer */ |
alexpirciu | 1:ceee5a608e7c | 32 | inline void start(); |
alexpirciu | 1:ceee5a608e7c | 33 | /* Stop timer */ |
alexpirciu | 1:ceee5a608e7c | 34 | inline void stop() ; |
alexpirciu | 1:ceee5a608e7c | 35 | /* Get timer */ |
alexpirciu | 1:ceee5a608e7c | 36 | inline uint32_t get(); |
alexpirciu | 1:ceee5a608e7c | 37 | private: |
alexpirciu | 1:ceee5a608e7c | 38 | /* Timer callback */ |
alexpirciu | 1:ceee5a608e7c | 39 | static void callback(void *thisPointer); |
alexpirciu | 1:ceee5a608e7c | 40 | /* Increase milliseconds value */ |
alexpirciu | 1:ceee5a608e7c | 41 | void millisTicker(); |
alexpirciu | 1:ceee5a608e7c | 42 | /* Ticker member */ |
alexpirciu | 1:ceee5a608e7c | 43 | Ticker m_ticker; |
alexpirciu | 1:ceee5a608e7c | 44 | /* Milliseconds value */ |
alexpirciu | 1:ceee5a608e7c | 45 | volatile uint32_t m_millisValue; |
alexpirciu | 1:ceee5a608e7c | 46 | /* Flag indicating timer started */ |
alexpirciu | 1:ceee5a608e7c | 47 | bool m_started; |
alexpirciu | 1:ceee5a608e7c | 48 | }; |
alexpirciu | 1:ceee5a608e7c | 49 | |
alexpirciu | 1:ceee5a608e7c | 50 | typedef CTimer<1,1000> CTimer_ms; |
alexpirciu | 1:ceee5a608e7c | 51 | typedef CTimer<1,1000000> CTimer_us; |
alexpirciu | 1:ceee5a608e7c | 52 | typedef CTimer<1,10000> CTimer_100us; |
alexpirciu | 1:ceee5a608e7c | 53 | typedef CTimer<60> CTimer_min; |
alexpirciu | 1:ceee5a608e7c | 54 | |
alexpirciu | 1:ceee5a608e7c | 55 | /* Inline implementation */ |
alexpirciu | 1:ceee5a608e7c | 56 | #include "timer.inl" |
alexpirciu | 1:ceee5a608e7c | 57 | |
alexpirciu | 1:ceee5a608e7c | 58 | #endif |