2424
2525#include < stdint.h>
2626#include " cmsis_os.h"
27+ #include " Callback.h"
28+ #include " toolchain.h"
2729
2830namespace rtos {
2931
@@ -36,21 +38,41 @@ namespace rtos {
3638*/
3739class RtosTimer {
3840public:
39- /* * Create and Start timer.
40- @param task name of the timer call back function .
41+ /* * Create timer.
42+ @param func function to be executed by this timer .
4143 @param type osTimerOnce for one-shot or osTimerPeriodic for periodic behaviour. (default: osTimerPeriodic)
4244 @param argument argument to the timer call back function. (default: NULL)
45+ @deprecated Replaced with RtosTimer(Callback<void()>, os_timer_type)
46+ */
47+ MBED_DEPRECATED (" Replaced with RtosTimer(Callback<void()>, os_timer_type)" )
48+ RtosTimer (void (*func)(void const *argument), os_timer_type type=osTimerPeriodic, void *argument=NULL ) {
49+ constructor (mbed::Callback<void ()>(argument, (void (*)(void *))func), type);
50+ }
51+
52+ /* * Create timer.
53+ @param func function to be executed by this timer.
54+ @param type osTimerOnce for one-shot or osTimerPeriodic for periodic behaviour. (default: osTimerPeriodic)
55+ */
56+ RtosTimer (mbed::Callback<void ()> func, os_timer_type type=osTimerPeriodic) {
57+ constructor (func, type);
58+ }
59+
60+ /* * Create timer.
61+ @param obj pointer to the object to call the member function on.
62+ @param method member function to be executed by this timer.
63+ @param type osTimerOnce for one-shot or osTimerPeriodic for periodic behaviour. (default: osTimerPeriodic)
4364 */
44- RtosTimer (void (*task)(void const *argument),
45- os_timer_type type=osTimerPeriodic,
46- void *argument=NULL );
65+ template <typename T, typename M>
66+ RtosTimer (T *obj, M method, os_timer_type type=osTimerPeriodic) {
67+ constructor (mbed::Callback<void ()>(obj, method), type);
68+ }
4769
4870 /* * Stop the timer.
4971 @return status code that indicates the execution status of the function.
5072 */
5173 osStatus stop (void );
5274
53- /* * start a timer.
75+ /* * Start the timer.
5476 @param millisec time delay value of the timer.
5577 @return status code that indicates the execution status of the function.
5678 */
@@ -59,6 +81,11 @@ class RtosTimer {
5981 ~RtosTimer ();
6082
6183private:
84+ // Required to share definitions without
85+ // delegated constructors
86+ void constructor (mbed::Callback<void ()> func, os_timer_type type);
87+
88+ mbed::Callback<void ()> _function;
6289 osTimerId _timer_id;
6390 osTimerDef_t _timer;
6491#if defined(CMSIS_OS_RTX) && !defined(__MBED_CMSIS_RTOS_CM)
0 commit comments