24
24
25
25
#include < stdint.h>
26
26
#include " cmsis_os.h"
27
+ #include " Callback.h"
28
+ #include " toolchain.h"
27
29
28
30
namespace rtos {
29
31
@@ -36,21 +38,41 @@ namespace rtos {
36
38
*/
37
39
class RtosTimer {
38
40
public:
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 .
41
43
@param type osTimerOnce for one-shot or osTimerPeriodic for periodic behaviour. (default: osTimerPeriodic)
42
44
@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)
43
64
*/
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
+ }
47
69
48
70
/* * Stop the timer.
49
71
@return status code that indicates the execution status of the function.
50
72
*/
51
73
osStatus stop (void );
52
74
53
- /* * start a timer.
75
+ /* * Start the timer.
54
76
@param millisec time delay value of the timer.
55
77
@return status code that indicates the execution status of the function.
56
78
*/
@@ -59,6 +81,11 @@ class RtosTimer {
59
81
~RtosTimer ();
60
82
61
83
private:
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;
62
89
osTimerId _timer_id;
63
90
osTimerDef_t _timer;
64
91
#if defined(CMSIS_OS_RTX) && !defined(__MBED_CMSIS_RTOS_CM)
0 commit comments