Maintain legacy RTOS behavior before mbed-5
Fork of mbed-rtos by
Diff: rtos/RtosTimer.h
- Revision:
- 119:19af2d39a542
- Parent:
- 112:53ace74b190c
- Child:
- 120:4dc938e301cc
diff -r 6635230e06ba -r 19af2d39a542 rtos/RtosTimer.h --- a/rtos/RtosTimer.h Mon Jul 25 14:12:24 2016 +0100 +++ b/rtos/RtosTimer.h Wed Aug 10 16:09:20 2016 +0100 @@ -24,6 +24,8 @@ #include <stdint.h> #include "cmsis_os.h" +#include "Callback.h" +#include "toolchain.h" namespace rtos { @@ -36,21 +38,41 @@ */ class RtosTimer { public: - /** Create and Start timer. - @param task name of the timer call back function. + /** Create timer. + @param func function to be executed by this timer. @param type osTimerOnce for one-shot or osTimerPeriodic for periodic behaviour. (default: osTimerPeriodic) @param argument argument to the timer call back function. (default: NULL) + @deprecated Replaced with RtosTimer(Callback<void()>, os_timer_type) + */ + MBED_DEPRECATED("Replaced with RtosTimer(Callback<void()>, os_timer_type)") + RtosTimer(void (*func)(void const *argument), os_timer_type type=osTimerPeriodic, void *argument=NULL) { + constructor(mbed::Callback<void()>(argument, (void (*)(void *))func), type); + } + + /** Create timer. + @param func function to be executed by this timer. + @param type osTimerOnce for one-shot or osTimerPeriodic for periodic behaviour. (default: osTimerPeriodic) */ - RtosTimer(void (*task)(void const *argument), - os_timer_type type=osTimerPeriodic, - void *argument=NULL); + RtosTimer(mbed::Callback<void()> func, os_timer_type type=osTimerPeriodic) { + constructor(func, type); + } + + /** Create timer. + @param obj pointer to the object to call the member function on. + @param method member function to be executed by this timer. + @param type osTimerOnce for one-shot or osTimerPeriodic for periodic behaviour. (default: osTimerPeriodic) + */ + template <typename T, typename M> + RtosTimer(T *obj, M method, os_timer_type type=osTimerPeriodic) { + constructor(mbed::Callback<void()>(obj, method), type); + } /** Stop the timer. @return status code that indicates the execution status of the function. */ osStatus stop(void); - /** start a timer. + /** Start the timer. @param millisec time delay value of the timer. @return status code that indicates the execution status of the function. */ @@ -59,6 +81,11 @@ ~RtosTimer(); private: + // Required to share definitions without + // delegated constructors + void constructor(mbed::Callback<void()> func, os_timer_type type); + + mbed::Callback<void()> _function; osTimerId _timer_id; osTimerDef_t _timer; #if defined(CMSIS_OS_RTX) && !defined(__MBED_CMSIS_RTOS_CM)