14
14
15
15
#define TRACE_GROUP "evlp"
16
16
17
+
18
+ #if MBED_CONF_NANOSTACK_HAL_EVENT_LOOP_DISPATCH_FROM_APPLICATION
19
+
20
+ static mbed_rtos_storage_event_flags_t event_flag_cb ;
21
+ static const osEventFlagsAttr_t event_flags_attr = {
22
+ .name = "nanostack_event_flags" ,
23
+ .cb_mem = & event_flag_cb ,
24
+ .cb_size = sizeof event_flag_cb
25
+ };
26
+ static osEventFlagsId_t event_flag_id ;
27
+
28
+ #else
29
+
17
30
static void event_loop_thread (void * arg );
18
31
19
32
static uint64_t event_thread_stk [MBED_CONF_NANOSTACK_HAL_EVENT_LOOP_THREAD_STACK_SIZE /8 ];
@@ -26,6 +39,8 @@ static const osThreadAttr_t event_thread_attr = {
26
39
.cb_mem = & event_thread_tcb ,
27
40
.cb_size = sizeof event_thread_tcb ,
28
41
};
42
+ #endif
43
+
29
44
static osThreadId_t event_thread_id ;
30
45
static mbed_rtos_storage_mutex_t event_mutex ;
31
46
static const osMutexAttr_t event_mutex_attr = {
@@ -66,34 +81,62 @@ void eventOS_scheduler_signal(void)
66
81
// XXX why does signal set lock if called with irqs disabled?
67
82
//__enable_irq();
68
83
//tr_debug("signal %p", (void*)event_thread_id);
84
+ #if MBED_CONF_NANOSTACK_HAL_EVENT_LOOP_DISPATCH_FROM_APPLICATION
85
+ osEventFlagsSet (event_flag_id , 1 );
86
+ #else
69
87
osThreadFlagsSet (event_thread_id , 1 );
88
+ #endif
70
89
//tr_debug("signalled %p", (void*)event_thread_id);
71
90
}
72
91
73
92
void eventOS_scheduler_idle (void )
74
93
{
75
94
//tr_debug("idle");
76
95
eventOS_scheduler_mutex_release ();
96
+
97
+ #if MBED_CONF_NANOSTACK_HAL_EVENT_LOOP_DISPATCH_FROM_APPLICATION
98
+ osEventFlagsWait (event_flag_id , 1 , osFlagsWaitAny , osWaitForever );
99
+ #else
77
100
osThreadFlagsWait (1 , 0 , osWaitForever );
101
+ #endif
102
+
78
103
eventOS_scheduler_mutex_wait ();
79
104
}
80
105
106
+ #if !MBED_CONF_NANOSTACK_HAL_EVENT_LOOP_DISPATCH_FROM_APPLICATION
81
107
static void event_loop_thread (void * arg )
82
108
{
83
109
(void )arg ;
84
110
eventOS_scheduler_mutex_wait ();
85
111
eventOS_scheduler_run (); //Does not return
86
112
}
113
+ #endif
87
114
88
- void ns_event_loop_thread_create (void )
115
+ // This is used to initialize the lock used by event loop even
116
+ // if it is not ran in a separate thread.
117
+ void ns_event_loop_init (void )
89
118
{
90
119
event_mutex_id = osMutexNew (& event_mutex_attr );
91
120
MBED_ASSERT (event_mutex_id != NULL );
92
121
122
+ // If a separate event loop thread is not used, the signaling
123
+ // happens via event flags instead of thread flags. This allows one to
124
+ // perform the initialization from any thread and removes need to know the id
125
+ // of event loop dispatch thread.
126
+ #if MBED_CONF_NANOSTACK_HAL_EVENT_LOOP_DISPATCH_FROM_APPLICATION
127
+ event_flag_id = osEventFlagsNew (& event_flags_attr );
128
+ MBED_ASSERT (event_flag_id != NULL );
129
+ #endif
130
+ }
131
+
132
+ #if !MBED_CONF_NANOSTACK_HAL_EVENT_LOOP_DISPATCH_FROM_APPLICATION
133
+ void ns_event_loop_thread_create (void )
134
+ {
93
135
event_thread_id = osThreadNew (event_loop_thread , NULL , & event_thread_attr );
94
136
MBED_ASSERT (event_thread_id != NULL );
95
137
}
96
138
97
139
void ns_event_loop_thread_start (void )
98
140
{
99
141
}
142
+ #endif
0 commit comments