@@ -103,6 +103,8 @@ extern "C" void wsf_mbed_ble_signal_event(void)
103
103
}
104
104
#endif // CORDIO_ZERO_COPY_HCI
105
105
106
+ #define CORDIO_TRANSPORT_WSF_MS_PER_TICK 10
107
+
106
108
static void bleLoop ()
107
109
{
108
110
#if CORDIO_ZERO_COPY_HCI
@@ -114,7 +116,7 @@ static void bleLoop()
114
116
timer.reset ();
115
117
116
118
uint64_t last_update_ms = (last_update_us / 1000 );
117
- wsfTimerTicks_t wsf_ticks = (last_update_ms / WSF_MS_PER_TICK );
119
+ wsfTimerTicks_t wsf_ticks = (last_update_ms / CORDIO_TRANSPORT_WSF_MS_PER_TICK );
118
120
119
121
if (wsf_ticks > 0 ) {
120
122
WsfTimerUpdate (wsf_ticks);
@@ -135,9 +137,20 @@ static void bleLoop()
135
137
uint64_t time_spent = (uint64_t ) timer.read_high_resolution_us ();
136
138
137
139
/* don't bother sleeping if we're already past tick */
138
- if (sleep && (WSF_MS_PER_TICK * 1000 > time_spent)) {
140
+ if (sleep && (CORDIO_TRANSPORT_WSF_MS_PER_TICK * 1000 > time_spent)) {
139
141
/* sleep to maintain constant tick rate */
140
- wait_us (WSF_MS_PER_TICK * 1000 - time_spent);
142
+ uint64_t wait_time_us = CORDIO_TRANSPORT_WSF_MS_PER_TICK * 1000 - time_spent;
143
+ uint64_t wait_time_ms = wait_time_us / 1000 ;
144
+
145
+ wait_time_us = wait_time_us % 1000 ;
146
+
147
+ if (wait_time_ms) {
148
+ rtos::ThisThread::sleep_for (wait_time_ms);
149
+ }
150
+
151
+ if (wait_time_us) {
152
+ wait_us (wait_time_us);
153
+ }
141
154
}
142
155
}
143
156
#else
@@ -147,7 +160,8 @@ static void bleLoop()
147
160
#endif // CORDIO_ZERO_COPY_HCI
148
161
}
149
162
150
- rtos::Thread bleLoopThread;
163
+ static rtos::EventFlags bleEventFlags;
164
+ static rtos::Thread bleLoopThread;
151
165
152
166
153
167
HCICordioTransportClass::HCICordioTransportClass () :
@@ -189,11 +203,12 @@ void HCICordioTransportClass::end()
189
203
190
204
void HCICordioTransportClass::wait (unsigned long timeout)
191
205
{
192
- for (unsigned long start = millis (); (millis () - start) < timeout;) {
193
- if (available ()) {
194
- break ;
195
- }
206
+ if (available ()) {
207
+ return ;
196
208
}
209
+
210
+ // wait for handleRxData to signal
211
+ bleEventFlags.wait_all (0x01 , timeout, true );
197
212
}
198
213
199
214
int HCICordioTransportClass::available ()
@@ -241,6 +256,8 @@ void HCICordioTransportClass::handleRxData(uint8_t* data, uint8_t len)
241
256
for (int i = 0 ; i < len; i++) {
242
257
_rxBuf.store_char (data[i]);
243
258
}
259
+
260
+ bleEventFlags.set (0x01 );
244
261
}
245
262
246
263
HCICordioTransportClass HCICordioTransport;
0 commit comments