void app_beacon_scanner_on_sys_evt(uint32_t event) { uint32_t err_code; switch (event) { case NRF_EVT_RADIO_SESSION_IDLE: if (m_beacon_scanner.is_running) { m_beacon_scanner.is_running = false; err_code = sd_radio_session_close(); if ((err_code != NRF_SUCCESS) && (m_beacon_scanner.error_handler != NULL)) { m_beacon_scanner.error_handler(err_code); } } break; case NRF_EVT_RADIO_SESSION_CLOSED: break; case NRF_EVT_RADIO_BLOCKED: case NRF_EVT_RADIO_CANCELED: // Fall through if (m_beacon_scanner.keep_running) { err_code = sd_radio_request(m_request_earliest(NRF_RADIO_PRIORITY_NORMAL)); if ((err_code != NRF_SUCCESS) && (m_beacon_scanner.error_handler != NULL)) { m_beacon_scanner.error_handler(err_code); } } break; default: break; } }
void app_beacon_sd_evt_signal_handler(uint32_t event) { uint32_t err_code; switch (event) { case NRF_EVT_RADIO_SESSION_IDLE: if (m_beacon.is_running) { m_beacon.is_running = false; err_code = sd_radio_session_close(); if ((err_code != NRF_SUCCESS) && (m_beacon.error_handler != NULL)) { m_beacon.error_handler(err_code); } } break; case NRF_EVT_RADIO_SESSION_CLOSED: break; case NRF_EVT_RADIO_BLOCKED: case NRF_EVT_RADIO_CANCELED: // Fall through if (m_beacon.keep_running) { // TODO: A proper solution should try again in <block_count> * m_beacon.adv_interval err_code = m_request_earliest(NRF_RADIO_PRIORITY_HIGH); if ((err_code != NRF_SUCCESS) && (m_beacon.error_handler != NULL)) { m_beacon.error_handler(err_code); } } break; default: break; } }
void app_beacon_start(void) { m_beacon.keep_running = true; m_beacon.is_running = true; uint32_t err_code = sd_radio_session_open(m_timeslot_callback); if ((err_code != NRF_SUCCESS) && (m_beacon.error_handler != NULL)) { m_beacon.error_handler(err_code); } err_code = m_request_earliest(NRF_RADIO_PRIORITY_NORMAL); if ((err_code != NRF_SUCCESS) && (m_beacon.error_handler != NULL)) { m_beacon.error_handler(err_code); } }
static nrf_radio_signal_callback_return_param_t * m_timeslot_callback(uint8_t signal_type) { static nrf_radio_signal_callback_return_param_t signal_callback_return_param; static enum mode_t mode; signal_callback_return_param.params.request.p_next = NULL; signal_callback_return_param.callback_action = NRF_RADIO_SIGNAL_CALLBACK_ACTION_NONE; switch (signal_type) { case NRF_RADIO_CALLBACK_SIGNAL_TYPE_START: m_handle_start(); mode = SCN_INIT; mode++; break; case NRF_RADIO_CALLBACK_SIGNAL_TYPE_RADIO: if (NRF_RADIO->EVENTS_ADDRESS == 1) { NRF_RADIO->EVENTS_ADDRESS = 0; ble_scan_beacon_evt_t evt; uint32_t err_code = decode_advertising(&m_beacon_scanner.scn_pdu[0], &(evt.rcv_adv_packet)); if (err_code == NRF_SUCCESS) { if (m_beacon_scanner.evt_handler != NULL) { evt.evt_type = BLE_SCAN_BEACON_ADVERTISER_FOUND; m_beacon_scanner.evt_handler(&evt); } } } if (NRF_RADIO->EVENTS_DISABLED == 1) { NRF_RADIO->EVENTS_DISABLED = 0; if (mode == SCN_DONE) { mode = SCN_INIT; mode++; } m_handle_radio_disabled(mode); mode++; } break; case NRF_RADIO_CALLBACK_SIGNAL_TYPE_TIMER0: if (NRF_TIMER0->EVENTS_COMPARE[1] == 1) { NRF_TIMER0->EVENTS_COMPARE[1] = 0; signal_callback_return_param.params.extend.length_us = TIMESLOT_LEN_US; signal_callback_return_param.callback_action = NRF_RADIO_SIGNAL_CALLBACK_ACTION_EXTEND; } break; case NRF_RADIO_CALLBACK_SIGNAL_TYPE_EXTEND_FAILED: NRF_PPI->CHENCLR = (1UL << 8); if (m_beacon_scanner.keep_running) { signal_callback_return_param.params.request.p_next = m_request_earliest(NRF_RADIO_PRIORITY_NORMAL); signal_callback_return_param.callback_action = NRF_RADIO_SIGNAL_CALLBACK_ACTION_REQUEST_AND_END; } else { signal_callback_return_param.callback_action = NRF_RADIO_SIGNAL_CALLBACK_ACTION_END; } break; case NRF_RADIO_CALLBACK_SIGNAL_TYPE_EXTEND_SUCCEEDED: NRF_TIMER0->CC[1] += TIMESLOT_LEN_US; break; default: if (m_beacon_scanner.error_handler != NULL) { m_beacon_scanner.error_handler(NRF_ERROR_INVALID_STATE); } break; } return ( &signal_callback_return_param ); }