22 #include "app_error.h"    23 #include "common_util.h"    26 #include "evt_sd_handler.h"    27 #include "nrf_assert.h"    31 #include "isr_manager.h"    34 #define SWI_USED SWI_USED_EVT_SD_HANDLER    39 #define SWI_ID              CONCAT_2(NRF_SWI, SWI_USED)    40 #define SWI_IRQN             SWI_IRQN_a(SWI_USED)    41 #define SWI_IRQ_Handler      SWI_IRQ_Handler_a(SWI_USED)    43 #define SWI_IRQN_a(n)        SWI_IRQN_b(n)    44 #define SWI_IRQN_b(n)        SWI##n##_EGU##n##_IRQn    46 #define SWI_IRQ_Handler_a(n) SWI_IRQ_Handler_b(n)    47 #define SWI_IRQ_Handler_b(n) SWI##n##_EGU##n##_IRQHandler    50 uint32_t ble_evt_buffer[
    52           CEIL_DIV(BLE_EVT_LEN_MAX(BLE_GATT_ATT_MTU_DEFAULT)
    55 void (*ble_handler)(ble_evt_t * evt);
    56 void (*soc_handler)(uint32_t evt);
    59             (
void (* ble_evt_handler)(ble_evt_t * ble_evt),
    60             void (* soc_evt_handler)(uint32_t soc_evt_id))
    62     ASSERT(ble_evt_handler != NULL);
    63     ASSERT(soc_evt_handler != NULL);
    64     ble_handler = ble_evt_handler;
    65     soc_handler = soc_evt_handler;
    67     uint32_t err_code = sd_nvic_EnableIRQ(SWI_IRQN);
    72 void evt_sd_handler_swi_Handler ()
    74 void SWI_IRQ_Handler(
void)
    77     bool soc_evts_handled = 
false;
    78     while(soc_evts_handled == 
false)
    80         uint32_t err_code, evt_id;
    81         err_code = sd_evt_get(&evt_id);
    82         if (err_code == NRF_ERROR_NOT_FOUND)
    85             soc_evts_handled = 
true;
    87         else if (err_code != NRF_SUCCESS)
    98     bool ble_evts_handled = 
false;
    99     while(ble_evts_handled == 
false)
   102         uint16_t evt_len = 
sizeof(ble_evt_buffer);
   104         uint32_t err_code = sd_ble_evt_get((uint8_t*)ble_evt_buffer, &evt_len);
   105         if (err_code == NRF_ERROR_NOT_FOUND)
   107             ble_evts_handled = 
true;
   109         else if (err_code != NRF_SUCCESS)
   116             ble_handler((ble_evt_t *) ble_evt_buffer);
 void evt_sd_handler_init(void(*ble_evt_handler)(ble_evt_t *ble_evt), void(*soc_evt_handler)(uint32_t soc_evt_id))
Initializes the SWI2 interrupt routine and stores the handlers for the BLE and SoC events.
#define APP_ERROR_CHECK(ERR_CODE)
Macro calls error handler if the provided error code is not NRF_SUCCESS. The behavior of this call de...
#define ASSERT(expression)
Macro for runtime assertion of an expression. If the expression is false the assert_nrf_callback func...
#define CEIL_DIV(A, B)
When the result of a division is not an integer, the result is rounded up to the next integer.