Skip to content

Commit 95906f1

Browse files
authored
Merge pull request #9579 from JarkkoPaso/timer_fhss_singleton
FHSS timer: Use singleton pointer
2 parents 7106d0d + 17e4e28 commit 95906f1

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

features/nanostack/nanostack-hal-mbed-cmsis-rtos/arm_hal_fhss_timer.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "fhss_api.h"
1818
#include "fhss_config.h"
1919
#include "mbed_trace.h"
20+
#include "platform/SingletonPtr.h"
2021
#include "platform/arm_hal_interrupt.h"
2122
#include <Timer.h>
2223
#include "equeue.h"
@@ -32,7 +33,7 @@
3233
using namespace mbed;
3334
using namespace events;
3435

35-
static Timer timer;
36+
static SingletonPtr<Timer> timer;
3637
static bool timer_initialized = false;
3738
static const fhss_api_t *fhss_active_handle = NULL;
3839
#if !MBED_CONF_NANOSTACK_HAL_CRITICAL_SECTION_USABLE_FROM_INTERRUPT
@@ -44,14 +45,14 @@ struct fhss_timeout_s {
4445
uint32_t start_time;
4546
uint32_t stop_time;
4647
bool active;
47-
Timeout timeout;
48+
SingletonPtr<Timeout> timeout;
4849
};
4950

5051
fhss_timeout_s fhss_timeout[NUMBER_OF_SIMULTANEOUS_TIMEOUTS];
5152

5253
static uint32_t read_current_time(void)
5354
{
54-
return timer.read_us();
55+
return timer->read_us();
5556
}
5657

5758
static fhss_timeout_s *find_timeout(void (*callback)(const fhss_api_t *api, uint16_t))
@@ -103,7 +104,7 @@ static int platform_fhss_timer_start(uint32_t slots, void (*callback)(const fhss
103104
equeue = mbed_highprio_event_queue();
104105
MBED_ASSERT(equeue != NULL);
105106
#endif
106-
timer.start();
107+
timer->start();
107108
timer_initialized = true;
108109
}
109110
fhss_timeout_s *fhss_tim = find_timeout(callback);
@@ -119,7 +120,7 @@ static int platform_fhss_timer_start(uint32_t slots, void (*callback)(const fhss
119120
fhss_tim->start_time = read_current_time();
120121
fhss_tim->stop_time = fhss_tim->start_time + slots;
121122
fhss_tim->active = true;
122-
fhss_tim->timeout.attach_us(timer_callback, slots);
123+
fhss_tim->timeout->attach_us(timer_callback, slots);
123124
fhss_active_handle = callback_param;
124125
ret_val = 0;
125126
platform_exit_critical();
@@ -135,7 +136,7 @@ static int platform_fhss_timer_stop(void (*callback)(const fhss_api_t *api, uint
135136
platform_exit_critical();
136137
return -1;
137138
}
138-
fhss_tim->timeout.detach();
139+
fhss_tim->timeout->detach();
139140
fhss_tim->active = false;
140141
platform_exit_critical();
141142
return 0;

0 commit comments

Comments
 (0)