24
24
#include " platform/mbed_assert.h"
25
25
#include " Timeout.h"
26
26
#include " Timer.h"
27
+ #include " Ticker.h"
27
28
#include " events/Event.h"
28
29
#include " events/mbed_shared_queues.h"
29
30
@@ -45,6 +46,61 @@ static EventQueue *equeue;
45
46
static uint32_t due;
46
47
static void (*arm_hal_callback)(void );
47
48
49
+ #if defined(NS_EVENTLOOP_USE_TICK_TIMER)
50
+
51
+ #if MBED_CONF_NANOSTACK_HAL_CRITICAL_SECTION_USABLE_FROM_INTERRUPT
52
+ static SingletonPtr<Ticker> tick_ticker;
53
+ #endif
54
+
55
+ static int tick_timer_id;
56
+ static void (*tick_timer_cb)(void );
57
+
58
+ int8_t platform_tick_timer_register (void (*tick_timer_cb_handler)(void ))
59
+ {
60
+ #if !MBED_CONF_NANOSTACK_HAL_CRITICAL_SECTION_USABLE_FROM_INTERRUPT
61
+ equeue = mbed_highprio_event_queue ();
62
+ MBED_ASSERT (equeue != NULL );
63
+ #endif
64
+
65
+ tick_timer_cb = tick_timer_cb_handler;
66
+ return 0 ;
67
+ }
68
+
69
+ int8_t platform_tick_timer_start (uint32_t period_ms)
70
+ {
71
+ int8_t retval = -1 ;
72
+ if (tick_timer_cb && tick_timer_id == 0 ) {
73
+ #if !MBED_CONF_NANOSTACK_HAL_CRITICAL_SECTION_USABLE_FROM_INTERRUPT
74
+ tick_timer_id = equeue->call_every (period_ms, tick_timer_cb);
75
+ if (tick_timer_id != 0 ) {
76
+ retval = 0 ;
77
+ }
78
+ #else
79
+ tick_ticker->attach_us (tick_timer_cb, period_ms * 1000 );
80
+ tick_timer_id = 1 ;
81
+ retval = 0 ;
82
+ #endif
83
+ }
84
+ return retval;
85
+ }
86
+
87
+ int8_t platform_tick_timer_stop (void )
88
+ {
89
+ int8_t retval = -1 ;
90
+ if (tick_timer_id != 0 ) {
91
+ #if !MBED_CONF_NANOSTACK_HAL_CRITICAL_SECTION_USABLE_FROM_INTERRUPT
92
+ equeue->cancel (tick_timer_id);
93
+ #else
94
+ tick_ticker->detach ();
95
+ #endif
96
+ tick_timer_id = 0 ;
97
+ retval = 0 ;
98
+ }
99
+ return retval;
100
+ }
101
+ #endif // NS_EVENTLOOP_USE_TICK_TIMER
102
+
103
+
48
104
// Called once at boot
49
105
void platform_timer_enable (void )
50
106
{
0 commit comments