6
6
#include " ns_types.h"
7
7
8
8
#include " mbed.h"
9
+ #include " platform/SingletonPtr.h"
9
10
#include " platform/arm_hal_timer.h"
10
11
#include " platform/arm_hal_interrupt.h"
11
12
#include < mbed_assert.h>
12
13
13
- static Timer timer;
14
- static Timeout timeout;
14
+ static SingletonPtr< Timer> timer;
15
+ static SingletonPtr< Timeout> timeout;
15
16
16
17
// If critical sections are implemented using mutexes, timers must be called in thread context, and
17
18
// we use the high-priority event queue for this.
@@ -32,12 +33,15 @@ void platform_timer_enable(void)
32
33
equeue = mbed_highprio_event_queue ();
33
34
MBED_ASSERT (equeue != NULL );
34
35
#endif
36
+ // Prime the SingletonPtrs - can't construct from IRQ/critical section
37
+ timer.get ();
38
+ timeout.get ();
35
39
}
36
40
37
41
// Actually cancels a timer, not the opposite of enable
38
42
void platform_timer_disable (void )
39
43
{
40
- timeout. detach ();
44
+ timeout-> detach ();
41
45
}
42
46
43
47
// Not called while running, fortunately
@@ -62,15 +66,15 @@ static void timer_callback(void)
62
66
// This is called from inside platform_enter_critical - IRQs can't happen
63
67
void platform_timer_start (uint16_t slots)
64
68
{
65
- timer. reset ();
69
+ timer-> reset ();
66
70
due = slots * UINT32_C (50 );
67
- timeout. attach_us (timer_callback, due);
71
+ timeout-> attach_us (timer_callback, due);
68
72
}
69
73
70
74
// This is called from inside platform_enter_critical - IRQs can't happen
71
75
uint16_t platform_timer_get_remaining_slots (void )
72
76
{
73
- uint32_t elapsed = timer. read_us ();
77
+ uint32_t elapsed = timer-> read_us ();
74
78
if (elapsed < due) {
75
79
return (uint16_t ) ((due - elapsed) / 50 );
76
80
} else {
0 commit comments