Skip to content

Commit 123c182

Browse files
committed
Use SingletonPtr in Nanostack HAL
Avoid static data/code overhead when Nanostack HAL isn't in use. Preparation for removal of FEATURE_COMMON_PAL.
1 parent 934101e commit 123c182

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

features/FEATURE_COMMON_PAL/nanostack-hal-mbed-cmsis-rtos/arm_hal_timer.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
#include "ns_types.h"
77

88
#include "mbed.h"
9+
#include "platform/SingletonPtr.h"
910
#include "platform/arm_hal_timer.h"
1011
#include "platform/arm_hal_interrupt.h"
1112
#include <mbed_assert.h>
1213

13-
static Timer timer;
14-
static Timeout timeout;
14+
static SingletonPtr<Timer> timer;
15+
static SingletonPtr<Timeout> timeout;
1516

1617
// If critical sections are implemented using mutexes, timers must be called in thread context, and
1718
// we use the high-priority event queue for this.
@@ -32,12 +33,15 @@ void platform_timer_enable(void)
3233
equeue = mbed_highprio_event_queue();
3334
MBED_ASSERT(equeue != NULL);
3435
#endif
36+
// Prime the SingletonPtrs - can't construct from IRQ/critical section
37+
timer.get();
38+
timeout.get();
3539
}
3640

3741
// Actually cancels a timer, not the opposite of enable
3842
void platform_timer_disable(void)
3943
{
40-
timeout.detach();
44+
timeout->detach();
4145
}
4246

4347
// Not called while running, fortunately
@@ -62,15 +66,15 @@ static void timer_callback(void)
6266
// This is called from inside platform_enter_critical - IRQs can't happen
6367
void platform_timer_start(uint16_t slots)
6468
{
65-
timer.reset();
69+
timer->reset();
6670
due = slots * UINT32_C(50);
67-
timeout.attach_us(timer_callback, due);
71+
timeout->attach_us(timer_callback, due);
6872
}
6973

7074
// This is called from inside platform_enter_critical - IRQs can't happen
7175
uint16_t platform_timer_get_remaining_slots(void)
7276
{
73-
uint32_t elapsed = timer.read_us();
77+
uint32_t elapsed = timer->read_us();
7478
if (elapsed < due) {
7579
return (uint16_t) ((due - elapsed) / 50);
7680
} else {

0 commit comments

Comments
 (0)