From 511117acdfab2d69fe18c00d3285c1150f958d0a Mon Sep 17 00:00:00 2001 From: neilt6 Date: Wed, 20 Jul 2016 10:51:45 -0600 Subject: [PATCH] [RTOS] Updated RtosTimer to use Callback Updated the RtosTimer class to use Callback in order to be consistent with the updated Thread class. --- rtos/rtos/RtosTimer.cpp | 8 +++++--- rtos/rtos/RtosTimer.h | 29 ++++++++++++++++++++++------- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/rtos/rtos/RtosTimer.cpp b/rtos/rtos/RtosTimer.cpp index f546183f49..dbb9532dbe 100644 --- a/rtos/rtos/RtosTimer.cpp +++ b/rtos/rtos/RtosTimer.cpp @@ -23,19 +23,21 @@ #include +#include "mbed.h" #include "cmsis_os.h" #include "mbed_error.h" namespace rtos { -RtosTimer::RtosTimer(void (*periodic_task)(void const *argument), os_timer_type type, void *argument) { +void RtosTimer::constructor(mbed::Callback func, os_timer_type type) { #ifdef CMSIS_OS_RTX - _timer.ptimer = periodic_task; + _timer.ptimer = (void (*)(const void *))Callback::thunk; memset(_timer_data, 0, sizeof(_timer_data)); _timer.timer = _timer_data; #endif - _timer_id = osTimerCreate(&_timer, type, argument); + _function = func; + _timer_id = osTimerCreate(&_timer, type, &_function); } osStatus RtosTimer::start(uint32_t millisec) { diff --git a/rtos/rtos/RtosTimer.h b/rtos/rtos/RtosTimer.h index 4fc2eae53b..5d0530ce7f 100644 --- a/rtos/rtos/RtosTimer.h +++ b/rtos/rtos/RtosTimer.h @@ -24,6 +24,7 @@ #include #include "cmsis_os.h" +#include "Callback.h" namespace rtos { @@ -36,21 +37,30 @@ namespace rtos { */ 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) */ - RtosTimer(void (*task)(void const *argument), - os_timer_type type=osTimerPeriodic, - void *argument=NULL); + RtosTimer(mbed::Callback 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 + RtosTimer(T *obj, M method, os_timer_type type=osTimerPeriodic) { + constructor(mbed::Callback(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 +69,11 @@ public: ~RtosTimer(); private: + // Required to share definitions without + // delegated constructors + void constructor(mbed::Callback func, os_timer_type type); + + mbed::Callback _function; osTimerId _timer_id; osTimerDef_t _timer; #if defined(CMSIS_OS_RTX) && !defined(__MBED_CMSIS_RTOS_CM)