uint32_t ut_start(uint32_t rf_channel, uint8_t rf_address[5])
{
    uint32_t        err_code;
    
    if (m_timeslot_session_open)
    {
        return NRF_ERROR_INVALID_STATE;
    }
    
    m_uesb_config.rf_channel = rf_channel;
    memcpy(m_uesb_config.rx_address_p0, rf_address, 5);
    
    m_blocked_cancelled_count  = 0;

    err_code = sd_radio_session_open(radio_callback);
    if (err_code != NRF_SUCCESS)
    {
        return err_code;
    }

    err_code = sd_radio_request(&m_timeslot_req_earliest);
    if (err_code != NRF_SUCCESS)
    {
        return err_code;
    }
    
    m_timeslot_session_open = true;
    
    return NRF_SUCCESS;
}
Exemplo n.º 2
0
void timeslot_order_normal(uint32_t length_us, uint32_t distance_us, bool immediately)
{
    if (immediately)
    {
        radio_request_normal.params.normal.length_us = length_us;
        radio_request_normal.params.normal.distance_us = distance_us;
        g_ret_param.callback_action = NRF_RADIO_SIGNAL_CALLBACK_ACTION_REQUEST_AND_END;
        g_ret_param.params.request.p_next = &radio_request_normal;

        g_next_timeslot_length = length_us;

        if (!g_is_in_callback)
        {
            sd_radio_request(&radio_request_normal);
        }
    }
    else
    {
        radio_request_normal.params.normal.length_us = length_us;
        radio_request_normal.params.normal.distance_us = distance_us;
        //g_final_ret_param.callback_action = NRF_RADIO_SIGNAL_CALLBACK_ACTION_REQUEST_AND_END;
        //g_final_ret_param.params.request.p_next = &radio_request_normal;

        g_next_timeslot_length = length_us;
    }
}
/**
* Send initial time slot request to API. 
*/
static __INLINE void timeslot_req_initial(void)
{	
	DEBUG_PIN_POKE(7);
	/* send to sd: */
	uint8_t error_code = sd_radio_request(&g_timeslot_req_earliest);
	APP_ERROR_CHECK(error_code);
}
Exemplo n.º 4
0
btle_status_codes_t btle_scan_enable_set (btle_cmd_param_le_write_scan_enable_t param)
{
  uint32_t err_code = NRF_SUCCESS;
  btle_status_codes_t status = BTLE_STATUS_CODE_SUCCESS;

  switch (param.scan_enable)
  {
    case BTLE_SCAN_MODE_ENABLE:
      err_code = sd_radio_request (&m_timeslot_req_earliest);
      if (err_code != NRF_SUCCESS)
      {
        status = BTLE_STATUS_CODE_COMMAND_DISALLOWED;
      }
      break;

    case BTLE_SCAN_MODE_DISABLE:
      err_code = sd_radio_session_close ();
      if (err_code != NRF_SUCCESS)
      {
        status = BTLE_STATUS_CODE_COMMAND_DISALLOWED;
      }
      break;
  }

  return status;
}
Exemplo n.º 5
0
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;
    }
}
Exemplo n.º 6
0
uint32_t m_request_earliest(enum NRF_RADIO_PRIORITY priority)
{
    m_beacon.timeslot_request.request_type                = NRF_RADIO_REQ_TYPE_EARLIEST;
    m_beacon.timeslot_request.params.earliest.hfclk       = NRF_RADIO_HFCLK_CFG_DEFAULT;
    m_beacon.timeslot_request.params.earliest.priority    = priority;
    m_beacon.timeslot_request.params.earliest.length_us   = m_beacon.slot_length;
    m_beacon.timeslot_request.params.earliest.timeout_us  = 1000000;
    return sd_radio_request(&m_beacon.timeslot_request);
}
Exemplo n.º 7
0
void timeslot_sd_evt_signal(uint32_t sys_evt)
{
  switch (sys_evt) {
    case NRF_EVT_RADIO_BLOCKED:
    case NRF_EVT_RADIO_CANCELED:
      sd_radio_request(&timeslot_request);
      break;
    default:
      break;
  }
}
void app_beacon_scanner_start(void)
{
    NRF_GPIO->DIRSET = (1UL << 18) | (1UL << 19);

    m_beacon_scanner.keep_running = true;
    m_beacon_scanner.is_running   = true;

    sd_radio_session_open(m_timeslot_callback);
    
    sd_radio_request(m_reqeust_earliest(NRF_RADIO_PRIORITY_NORMAL));
}
/**@brief Function for handling the Application's system events.
 *
 * @param[in]   sys_evt   system event.
 */
void ut_on_sys_evt(uint32_t sys_evt)
{
    switch(sys_evt)
    {
        case NRF_EVT_FLASH_OPERATION_SUCCESS:
        case NRF_EVT_FLASH_OPERATION_ERROR:
            break;
        case NRF_EVT_RADIO_BLOCKED:
        case NRF_EVT_RADIO_CANCELED:
        {
            // Blocked events are rescheduled with normal priority. They could also
            // be rescheduled with high priority if necessary.
            uint32_t err_code = sd_radio_request((nrf_radio_request_t*) &m_timeslot_req_earliest);
            APP_ERROR_CHECK(err_code);

            m_blocked_cancelled_count++;
            
            break;
        }
        case NRF_EVT_RADIO_SIGNAL_CALLBACK_INVALID_RETURN:
            DEBUG_PRINT("NRF_EVT_RADIO_SIGNAL_CALLBACK_INVALID_RETURN\r\n");
            app_error_handler(MAIN_DEBUG, __LINE__, (const uint8_t*)__FILE__);
            break;
        case NRF_EVT_RADIO_SESSION_CLOSED:
            {
                m_timeslot_session_open = false;
                
                DEBUG_PRINT("NRF_EVT_RADIO_SESSION_CLOSED\r\n");
            }
        
            break;
        case NRF_EVT_RADIO_SESSION_IDLE:
        {
            DEBUG_PRINT("NRF_EVT_RADIO_SESSION_IDLE\r\n");
            
            uint32_t err_code = sd_radio_session_close();
            APP_ERROR_CHECK(err_code);
            break;
        }
        default:
            // No implementation needed.
            break;
    }
}
Exemplo n.º 10
0
void app_beacon_scanner_start(void)
{
    uint32_t err_code;

    m_beacon_scanner.keep_running = true;
    m_beacon_scanner.is_running   = true;

    err_code = sd_radio_session_open(m_timeslot_callback);
    if ((err_code != NRF_SUCCESS) && (m_beacon_scanner.error_handler != NULL))
    {
        m_beacon_scanner.error_handler(err_code);
    }
    
    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);
    }
}
Exemplo n.º 11
0
void timeslot_order_earliest(uint32_t length_us, bool immediately)
{
    if (immediately)
    {
        radio_request_earliest.params.earliest.length_us = length_us;
        g_ret_param.callback_action = NRF_RADIO_SIGNAL_CALLBACK_ACTION_REQUEST_AND_END;
        g_ret_param.params.request.p_next = &radio_request_earliest;

        g_next_timeslot_length = length_us;

        if (!g_is_in_callback)
        {
            uint32_t error_code = sd_radio_request(&radio_request_earliest);
            APP_ERROR_CHECK(error_code);
        }
    }
    else
    {
        radio_request_earliest.params.earliest.length_us = length_us;

        g_next_timeslot_length = length_us;
    }
}
void app_beacon_scanner_sd_evt_signal_handler(uint32_t event)
{
    switch (event)
    {
        case NRF_EVT_RADIO_SESSION_IDLE:
            if (m_beacon_scanner.is_running)
            {
                m_beacon_scanner.is_running = false;
                sd_radio_session_close();
            }
            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)
            {
                sd_radio_request(m_reqeust_earliest(NRF_RADIO_PRIORITY_NORMAL));
            }
            break;
        default:
            break;
    }
}
Exemplo n.º 13
0
void timeslot_start(void)
{
  sd_radio_session_open(timeslot_callback);
  sd_radio_request(&timeslot_request);
}