Alex Pirciu
/
BFMC
a
include/Timer/timer.inl@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.inl |
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 definition for the timer functionality. |
alexpirciu | 1:ceee5a608e7c | 8 | * Inline implementation. |
alexpirciu | 1:ceee5a608e7c | 9 | ****************************************************************************** |
alexpirciu | 1:ceee5a608e7c | 10 | */ |
alexpirciu | 1:ceee5a608e7c | 11 | |
alexpirciu | 1:ceee5a608e7c | 12 | /** @brief CTimer class constructor |
alexpirciu | 1:ceee5a608e7c | 13 | * |
alexpirciu | 1:ceee5a608e7c | 14 | * Constructor method |
alexpirciu | 1:ceee5a608e7c | 15 | * |
alexpirciu | 1:ceee5a608e7c | 16 | * |
alexpirciu | 1:ceee5a608e7c | 17 | */ |
alexpirciu | 1:ceee5a608e7c | 18 | template <unsigned int N, unsigned int D> |
alexpirciu | 1:ceee5a608e7c | 19 | CTimer<N,D>::CTimer() |
alexpirciu | 1:ceee5a608e7c | 20 | : m_ticker() |
alexpirciu | 1:ceee5a608e7c | 21 | , m_millisValue(0) |
alexpirciu | 1:ceee5a608e7c | 22 | , m_started(0) |
alexpirciu | 1:ceee5a608e7c | 23 | { |
alexpirciu | 1:ceee5a608e7c | 24 | } |
alexpirciu | 1:ceee5a608e7c | 25 | |
alexpirciu | 1:ceee5a608e7c | 26 | /** @brief CTimer class destructor |
alexpirciu | 1:ceee5a608e7c | 27 | * |
alexpirciu | 1:ceee5a608e7c | 28 | * Destructor method |
alexpirciu | 1:ceee5a608e7c | 29 | * |
alexpirciu | 1:ceee5a608e7c | 30 | * |
alexpirciu | 1:ceee5a608e7c | 31 | */ |
alexpirciu | 1:ceee5a608e7c | 32 | template <unsigned int N, unsigned int D> |
alexpirciu | 1:ceee5a608e7c | 33 | CTimer<N,D>::~CTimer() |
alexpirciu | 1:ceee5a608e7c | 34 | { |
alexpirciu | 1:ceee5a608e7c | 35 | if (m_started) |
alexpirciu | 1:ceee5a608e7c | 36 | stop (); |
alexpirciu | 1:ceee5a608e7c | 37 | } |
alexpirciu | 1:ceee5a608e7c | 38 | |
alexpirciu | 1:ceee5a608e7c | 39 | /** @brief Start timer |
alexpirciu | 1:ceee5a608e7c | 40 | * |
alexpirciu | 1:ceee5a608e7c | 41 | * |
alexpirciu | 1:ceee5a608e7c | 42 | * |
alexpirciu | 1:ceee5a608e7c | 43 | */ |
alexpirciu | 1:ceee5a608e7c | 44 | template <unsigned int N, unsigned int D> |
alexpirciu | 1:ceee5a608e7c | 45 | void CTimer<N,D>::start () |
alexpirciu | 1:ceee5a608e7c | 46 | { |
alexpirciu | 1:ceee5a608e7c | 47 | m_started = 1; |
alexpirciu | 1:ceee5a608e7c | 48 | m_ticker.attach (mbed::callback(&CTimer::callback, this), 1.f*N/D); |
alexpirciu | 1:ceee5a608e7c | 49 | } |
alexpirciu | 1:ceee5a608e7c | 50 | |
alexpirciu | 1:ceee5a608e7c | 51 | /** @brief Stop timer |
alexpirciu | 1:ceee5a608e7c | 52 | * |
alexpirciu | 1:ceee5a608e7c | 53 | * |
alexpirciu | 1:ceee5a608e7c | 54 | * |
alexpirciu | 1:ceee5a608e7c | 55 | */ |
alexpirciu | 1:ceee5a608e7c | 56 | template <unsigned int N, unsigned int D> |
alexpirciu | 1:ceee5a608e7c | 57 | void CTimer<N,D>::stop() |
alexpirciu | 1:ceee5a608e7c | 58 | { |
alexpirciu | 1:ceee5a608e7c | 59 | m_started = 0; |
alexpirciu | 1:ceee5a608e7c | 60 | m_ticker.detach (); |
alexpirciu | 1:ceee5a608e7c | 61 | } |
alexpirciu | 1:ceee5a608e7c | 62 | |
alexpirciu | 1:ceee5a608e7c | 63 | /** @brief Get timer |
alexpirciu | 1:ceee5a608e7c | 64 | * |
alexpirciu | 1:ceee5a608e7c | 65 | * |
alexpirciu | 1:ceee5a608e7c | 66 | * @return Milliseconds value |
alexpirciu | 1:ceee5a608e7c | 67 | */ |
alexpirciu | 1:ceee5a608e7c | 68 | template <unsigned int N, unsigned int D> |
alexpirciu | 1:ceee5a608e7c | 69 | uint32_t CTimer<N,D>::get() |
alexpirciu | 1:ceee5a608e7c | 70 | { |
alexpirciu | 1:ceee5a608e7c | 71 | return m_millisValue; |
alexpirciu | 1:ceee5a608e7c | 72 | } |
alexpirciu | 1:ceee5a608e7c | 73 | |
alexpirciu | 1:ceee5a608e7c | 74 | /** @brief Timer callback |
alexpirciu | 1:ceee5a608e7c | 75 | * |
alexpirciu | 1:ceee5a608e7c | 76 | * @param thisPointer The object pointer. |
alexpirciu | 1:ceee5a608e7c | 77 | * |
alexpirciu | 1:ceee5a608e7c | 78 | */ |
alexpirciu | 1:ceee5a608e7c | 79 | template <unsigned int N, unsigned int D> |
alexpirciu | 1:ceee5a608e7c | 80 | void CTimer<N,D>::callback(void *thisPointer) |
alexpirciu | 1:ceee5a608e7c | 81 | { |
alexpirciu | 1:ceee5a608e7c | 82 | CTimer<N,D>* self = static_cast<CTimer<N,D>*>(thisPointer); |
alexpirciu | 1:ceee5a608e7c | 83 | self->millisTicker(); |
alexpirciu | 1:ceee5a608e7c | 84 | } |
alexpirciu | 1:ceee5a608e7c | 85 | |
alexpirciu | 1:ceee5a608e7c | 86 | /** @brief Increase milliseconds value |
alexpirciu | 1:ceee5a608e7c | 87 | * |
alexpirciu | 1:ceee5a608e7c | 88 | * |
alexpirciu | 1:ceee5a608e7c | 89 | * |
alexpirciu | 1:ceee5a608e7c | 90 | */ |
alexpirciu | 1:ceee5a608e7c | 91 | template <unsigned int N, unsigned int D> |
alexpirciu | 1:ceee5a608e7c | 92 | void CTimer<N,D>::millisTicker() |
alexpirciu | 1:ceee5a608e7c | 93 | { |
alexpirciu | 1:ceee5a608e7c | 94 | m_millisValue ++; |
alexpirciu | 1:ceee5a608e7c | 95 | } |