openweave / openweave-core

openWeave is a home area network application protocol stack designed to enable asynchronous, symmetric, device-to-device, device-to-mobile and device-to-cloud communications for control path and data path messaging.
Apache License 2.0
233 stars 106 forks source link

nRF5 Device Layer: Incorrect logic in NRF5Config::HandleFDSEvent() #480

Open jaylogue opened 4 years ago

jaylogue commented 4 years ago

NRF5Config::HandleFDSEvent() handles asynchronous events from the nRF5 SDK's Flash Data Storage layer. Depending on the SDK options chosen, this method can be called in ether Soft Device interrupt context or FreeRTOS task context. Conditional compilation logic in the code determines which context is used, and alters the code to use the appropriate FreeRTOS APIs when signaling other tasks (i.e. ...FromISR() or not).

However, the logic NRF5Config::HandleFDSEvent() is slightly wrong. In particular, the method will only be called in interrupt context if the Soft Device is enabled AND the NRF_SDH_DISPATCH_MODEL is NRF_SDH_DISPATCH_MODEL_INTERRUPT. Thus the conditional logic in NRF5Config::HandleFDSEvent() should look something like this:

    // Signal the Weave thread that the operation has completed.
#if defined(SOFTDEVICE_PRESENT) && SOFTDEVICE_PRESENT && NRF_SDH_DISPATCH_MODEL == NRF_SDH_DISPATCH_MODEL_INTERRUPT
    ...
    xSemaphoreGiveFromISR(sAsyncOpCompletionSem, &yieldRequired);
    ...
#else
    xSemaphoreGive(sAsyncOpCompletionSem);
#endif
zhoujc999 commented 4 years ago

Hi @jaylogue, Can I work on this?