porting: Fix FreeRTOS NPL
Make ble_npl_eventq_remove properly handle calling from ISR.
@@ -82,6 +82,7 @@ npl_freertos_eventq_remove(struct ble_npl_eventq *evq,
BaseType_t ret;
int i;
int count;
+ BaseType_t woken, woken2;
if (!ev->queued) {
return;
@@ -94,6 +95,26 @@ npl_freertos_eventq_remove(struct ble_npl_eventq *evq,
* better use counting semaphore with os_queue to handle this in future.
*/
+ if (in_isr()) {
+ woken = pdFALSE;
+
+ count = uxQueueMessagesWaitingFromISR(evq->q);
+ for (i = 0; i < count; i++) {
+ ret = xQueueReceiveFromISR(evq->q, &tmp_ev, &woken2);
+ assert(ret == pdPASS);
+ woken |= woken2;
+
+ if (tmp_ev == ev) {
+ continue;
+ }
+
+ ret = xQueueSendToBackFromISR(evq->q, &tmp_ev, &woken2);
+ assert(ret == pdPASS);
+ woken |= woken2;
+ }
+
+ portYIELD_FROM_ISR(woken);
+ } else {
vPortEnterCritical();
count = uxQueueMessagesWaiting(evq->q);
@@ -110,6 +131,7 @@ npl_freertos_eventq_remove(struct ble_npl_eventq *evq,
}
vPortExitCritical();
+ }
ev->queued = 0;
}
