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 = ADV_INIT;
      mode++;
      break;
    case NRF_RADIO_CALLBACK_SIGNAL_TYPE_RADIO:
      if (NRF_RADIO->EVENTS_DISABLED == 1)
      {
        NRF_RADIO->EVENTS_DISABLED = 0;

        m_handle_radio_disabled(mode);

        if (mode == ADV_DONE)
        {
            NRF_PPI->CHENCLR = (1 << 8);
            if (m_beacon.keep_running)
            {
                signal_callback_return_param.params.request.p_next = m_configure_next_event();
                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;
        }
        mode++;
      }
      break;
    default:
        if (m_beacon.error_handler != NULL)
        {
            m_beacon.error_handler(NRF_ERROR_INVALID_STATE);
        }
      break;
  }

  return ( &signal_callback_return_param );
}
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;

            if (has_beacon_data(&m_beacon_scanner.scn_pdu[0]))
            {
                NRF_GPIO->OUT ^= (1UL << 18);
            }
        }

        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_MULTITIMER:
        if (NRF_RADIO_MULTITIMER->EVENTS_COMPARE[1] == 1)
        {
            NRF_RADIO_MULTITIMER->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_GPIO->OUT ^= (1UL << 19);
        if (m_beacon_scanner.keep_running)
        {
            signal_callback_return_param.params.request.p_next   = m_reqeust_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_RADIO_MULTITIMER->CC[1]    += TIMESLOT_LEN_US;
        break;
    default:
      APP_ASSERT( false );
      break;
  }

  return ( &signal_callback_return_param );
}
Ejemplo n.º 3
0
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 );
}