Skip to content

Commit b55af5c

Browse files
committed
Use shared event queue for timer
Don't create our own timer thread - use the shared event queue.
1 parent eb80c25 commit b55af5c

File tree

1 file changed

+5
-30
lines changed

1 file changed

+5
-30
lines changed

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

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,48 +4,23 @@
44

55
// Include before mbed.h to properly get UINT*_C()
66
#include "ns_types.h"
7+
78
#include "mbed.h"
8-
#include "cmsis_os2.h"
9-
#include "rtx_os.h"
109
#include "platform/arm_hal_timer.h"
1110
#include "platform/arm_hal_interrupt.h"
1211
#include <mbed_assert.h>
1312

14-
static osThreadId_t timer_thread_id;
15-
static uint64_t timer_thread_stk[2048/sizeof(uint64_t)];
16-
static osRtxThread_t timer_thread_tcb;
17-
1813
static Timer timer;
1914
static Timeout timeout;
15+
static EventQueue *equeue;
2016
static uint32_t due;
2117
static void (*arm_hal_callback)(void);
2218

23-
static void timer_thread(void *arg)
24-
{
25-
(void)arg;
26-
for (;;) {
27-
osThreadFlagsWait(1, osFlagsWaitAny, osWaitForever);
28-
// !!! We don't do our own enter/exit critical - we rely on callback
29-
// doing it (ns_timer_interrupt_handler does)
30-
//platform_enter_critical();
31-
arm_hal_callback();
32-
//platform_exit_critical();
33-
}
34-
}
35-
3619
// Called once at boot
3720
void platform_timer_enable(void)
3821
{
39-
static osThreadAttr_t timer_thread_attr = {0};
40-
timer_thread_attr.name = "pal_timer_thread";
41-
timer_thread_attr.stack_mem = &timer_thread_stk[0];
42-
timer_thread_attr.cb_mem = &timer_thread_tcb;
43-
timer_thread_attr.stack_size = sizeof(timer_thread_stk);
44-
timer_thread_attr.cb_size = sizeof(timer_thread_tcb);
45-
timer_thread_attr.priority = osPriorityRealtime;
46-
timer_thread_id = osThreadNew(timer_thread, NULL, &timer_thread_attr);
47-
MBED_ASSERT(timer_thread_id != NULL);
48-
timer.start();
22+
equeue = mbed_highprio_event_queue();
23+
MBED_ASSERT(equeue != NULL);
4924
}
5025

5126
// Actually cancels a timer, not the opposite of enable
@@ -63,7 +38,7 @@ void platform_timer_set_cb(void (*new_fp)(void))
6338
static void timer_callback(void)
6439
{
6540
due = 0;
66-
osThreadFlagsSet(timer_thread_id, 1);
41+
equeue->call(arm_hal_callback);
6742
}
6843

6944
// This is called from inside platform_enter_critical - IRQs can't happen

0 commit comments

Comments
 (0)