24
24
25
25
#include < stdint.h>
26
26
#include " cmsis_os.h"
27
+ #include " Callback.h"
27
28
28
29
namespace rtos {
29
30
@@ -36,21 +37,30 @@ namespace rtos {
36
37
*/
37
38
class RtosTimer {
38
39
public:
39
- /* * Create and Start timer.
40
- @param task name of the timer call back function .
40
+ /* * Create timer.
41
+ @param func function to be executed by this timer .
41
42
@param type osTimerOnce for one-shot or osTimerPeriodic for periodic behaviour. (default: osTimerPeriodic)
42
- @param argument argument to the timer call back function. (default: NULL)
43
43
*/
44
- RtosTimer (void (*task)(void const *argument),
45
- os_timer_type type=osTimerPeriodic,
46
- void *argument=NULL );
44
+ RtosTimer (mbed::Callback<void ()> func, os_timer_type type=osTimerPeriodic) {
45
+ constructor (func, type);
46
+ }
47
+
48
+ /* * Create timer.
49
+ @param obj pointer to the object to call the member function on.
50
+ @param method member function to be executed by this timer.
51
+ @param type osTimerOnce for one-shot or osTimerPeriodic for periodic behaviour. (default: osTimerPeriodic)
52
+ */
53
+ template <typename T, typename M>
54
+ RtosTimer (T *obj, M method, os_timer_type type=osTimerPeriodic) {
55
+ constructor (mbed::Callback<void ()>(obj, method), type);
56
+ }
47
57
48
58
/* * Stop the timer.
49
59
@return status code that indicates the execution status of the function.
50
60
*/
51
61
osStatus stop (void );
52
62
53
- /* * start a timer.
63
+ /* * Start the timer.
54
64
@param millisec time delay value of the timer.
55
65
@return status code that indicates the execution status of the function.
56
66
*/
@@ -59,6 +69,11 @@ class RtosTimer {
59
69
~RtosTimer ();
60
70
61
71
private:
72
+ // Required to share definitions without
73
+ // delegated constructors
74
+ void constructor (mbed::Callback<void ()> func, os_timer_type type);
75
+
76
+ mbed::Callback<void ()> _function;
62
77
osTimerId _timer_id;
63
78
osTimerDef_t _timer;
64
79
#if defined(CMSIS_OS_RTX) && !defined(__MBED_CMSIS_RTOS_CM)
0 commit comments