Alex Pirciu
/
BFMC
a
Diff: include/Timer/timer.inl
- Revision:
- 1:ceee5a608e7c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/Timer/timer.inl Thu Mar 28 07:44:42 2019 +0000 @@ -0,0 +1,95 @@ +/** + ****************************************************************************** + * @file Timer.inl + * @author RBRO/PJ-IU + * @version V1.0.0 + * @date day-month-2017 + * @brief This file contains the class definition for the timer functionality. + * Inline implementation. + ****************************************************************************** + */ + +/** @brief CTimer class constructor + * + * Constructor method + * + * + */ +template <unsigned int N, unsigned int D> +CTimer<N,D>::CTimer() + : m_ticker() + , m_millisValue(0) + , m_started(0) +{ +} + +/** @brief CTimer class destructor + * + * Destructor method + * + * + */ +template <unsigned int N, unsigned int D> +CTimer<N,D>::~CTimer() +{ + if (m_started) + stop (); +} + +/** @brief Start timer + * + * + * + */ +template <unsigned int N, unsigned int D> +void CTimer<N,D>::start () +{ + m_started = 1; + m_ticker.attach (mbed::callback(&CTimer::callback, this), 1.f*N/D); +} + +/** @brief Stop timer + * + * + * + */ +template <unsigned int N, unsigned int D> +void CTimer<N,D>::stop() +{ + m_started = 0; + m_ticker.detach (); +} + +/** @brief Get timer + * + * + * @return Milliseconds value + */ +template <unsigned int N, unsigned int D> +uint32_t CTimer<N,D>::get() +{ + return m_millisValue; +} + +/** @brief Timer callback + * + * @param thisPointer The object pointer. + * + */ +template <unsigned int N, unsigned int D> +void CTimer<N,D>::callback(void *thisPointer) +{ + CTimer<N,D>* self = static_cast<CTimer<N,D>*>(thisPointer); + self->millisTicker(); +} + +/** @brief Increase milliseconds value + * + * + * + */ +template <unsigned int N, unsigned int D> +void CTimer<N,D>::millisTicker() +{ + m_millisValue ++; +}