123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- #include "nrf_sdh_freertos.h"
- #include "nrf_sdh.h"
- #include "FreeRTOS.h"
- #include "task.h"
- #include "queue.h"
- #include "semphr.h"
- #define NRF_LOG_MODULE_NAME nrf_sdh_freertos
- #include "nrf_log.h"
- NRF_LOG_MODULE_REGISTER();
- #define NRF_BLE_FREERTOS_SDH_TASK_STACK 256
- static TaskHandle_t m_softdevice_task;
- static nrf_sdh_freertos_task_hook_t m_task_hook;
- void SD_EVT_IRQHandler(void)
- {
- BaseType_t yield_req = pdFALSE;
- vTaskNotifyGiveFromISR(m_softdevice_task, &yield_req);
-
- portYIELD_FROM_ISR(yield_req);
- }
- static void softdevice_task(void * pvParameter)
- {
- NRF_LOG_DEBUG("Enter softdevice_task.");
- if (m_task_hook != NULL)
- {
- m_task_hook(pvParameter);
- }
- while (true)
- {
- nrf_sdh_evts_poll();
- (void) ulTaskNotifyTake(pdTRUE,
- portMAX_DELAY);
- }
- }
- void nrf_sdh_freertos_init(nrf_sdh_freertos_task_hook_t hook_fn, void * p_context)
- {
- NRF_LOG_DEBUG("Creating a SoftDevice task.");
- m_task_hook = hook_fn;
- BaseType_t xReturned = xTaskCreate(softdevice_task,
- "BLE",
- NRF_BLE_FREERTOS_SDH_TASK_STACK,
- p_context,
- 2,
- &m_softdevice_task);
- if (xReturned != pdPASS)
- {
- NRF_LOG_ERROR("SoftDevice task not created.");
- APP_ERROR_HANDLER(NRF_ERROR_NO_MEM);
- }
- }
|