From 123c182033cd6caf9125842bae60c5c4ce48cb2a Mon Sep 17 00:00:00 2001 From: Kevin Bracey Date: Wed, 18 Apr 2018 10:40:56 +0300 Subject: [PATCH] Use SingletonPtr in Nanostack HAL Avoid static data/code overhead when Nanostack HAL isn't in use. Preparation for removal of FEATURE_COMMON_PAL. --- .../arm_hal_timer.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/features/FEATURE_COMMON_PAL/nanostack-hal-mbed-cmsis-rtos/arm_hal_timer.cpp b/features/FEATURE_COMMON_PAL/nanostack-hal-mbed-cmsis-rtos/arm_hal_timer.cpp index d74526ed1e..a6255c9d9f 100644 --- a/features/FEATURE_COMMON_PAL/nanostack-hal-mbed-cmsis-rtos/arm_hal_timer.cpp +++ b/features/FEATURE_COMMON_PAL/nanostack-hal-mbed-cmsis-rtos/arm_hal_timer.cpp @@ -6,12 +6,13 @@ #include "ns_types.h" #include "mbed.h" +#include "platform/SingletonPtr.h" #include "platform/arm_hal_timer.h" #include "platform/arm_hal_interrupt.h" #include -static Timer timer; -static Timeout timeout; +static SingletonPtr timer; +static SingletonPtr timeout; // If critical sections are implemented using mutexes, timers must be called in thread context, and // we use the high-priority event queue for this. @@ -32,12 +33,15 @@ void platform_timer_enable(void) equeue = mbed_highprio_event_queue(); MBED_ASSERT(equeue != NULL); #endif + // Prime the SingletonPtrs - can't construct from IRQ/critical section + timer.get(); + timeout.get(); } // Actually cancels a timer, not the opposite of enable void platform_timer_disable(void) { - timeout.detach(); + timeout->detach(); } // Not called while running, fortunately @@ -62,15 +66,15 @@ static void timer_callback(void) // This is called from inside platform_enter_critical - IRQs can't happen void platform_timer_start(uint16_t slots) { - timer.reset(); + timer->reset(); due = slots * UINT32_C(50); - timeout.attach_us(timer_callback, due); + timeout->attach_us(timer_callback, due); } // This is called from inside platform_enter_critical - IRQs can't happen uint16_t platform_timer_get_remaining_slots(void) { - uint32_t elapsed = timer.read_us(); + uint32_t elapsed = timer->read_us(); if (elapsed < due) { return (uint16_t) ((due - elapsed) / 50); } else {