This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

The callbacks in esb/gazell not work?How can we run ble and gazell/esb simultaneously?

Hi,I want to use my phone connect to NRF51822 by BLE, and used NRF24LE1 connect NRF51822 by GAZELL/ESB.That is to say, i want to use the device work with gazell/esb protocol and BLE alternatively! I add the function in the example(nRF51_SDK_8.1.0_b6ed55f\examples\ble_peripheral\ble_app_hids_keyboard\pca10028\s110\arm4).That is the code what i add in the example:

static nrf_radio_request_t  					   m_timeslot_request;
static uint32_t             	    			   m_slot_length = 10000;
static nrf_radio_signal_callback_return_param_t    signal_callback_return_param;
static volatile bool        					   m_esb_initialized = false;

#define PIPE_NUMBER         0 
#define TX_PAYLOAD_LENGTH   1 

static uint8_t my_tx_payload[TX_PAYLOAD_LENGTH];               
static uint8_t my_rx_payload[NRF_ESB_CONST_MAX_PAYLOAD_LENGTH]; 

static void m_configure_earliest_timeslot(void)
{
	m_timeslot_request.request_type                = NRF_RADIO_REQ_TYPE_EARLIEST;
	m_timeslot_request.params.earliest.hfclk       = NRF_RADIO_HFCLK_CFG_DEFAULT;
	m_timeslot_request.params.earliest.priority    = NRF_RADIO_PRIORITY_NORMAL;
	m_timeslot_request.params.earliest.length_us   = m_slot_length;
	m_timeslot_request.params.earliest.timeout_us  = 1000000;
}

static void m_configure_normal_timeslot(void)
{
	m_timeslot_request.request_type                = NRF_RADIO_REQ_TYPE_NORMAL;
	m_timeslot_request.params.normal.hfclk         = NRF_RADIO_HFCLK_CFG_DEFAULT;
	m_timeslot_request.params.normal.priority      = NRF_RADIO_PRIORITY_NORMAL;
	m_timeslot_request.params.normal.length_us     = m_slot_length;
	m_timeslot_request.params.normal.distance_us   = 200000;
}

static void timeslot_on_start(void)
{
    bool res;
    signal_callback_return_param.params.request.p_next = NULL;
    signal_callback_return_param.callback_action = NRF_RADIO_SIGNAL_CALLBACK_ACTION_NONE;  
	
    if (!m_esb_initialized )
    {
        res = nrf_esb_init(NRF_ESB_MODE_PTX); 
        printf("%d\r\n", res)
			
        nrf_esb_enable();

        (void)nrf_esb_add_packet_to_tx_fifo(PIPE_NUMBER, my_tx_payload, TX_PAYLOAD_LENGTH, NRF_ESB_PACKET_USE_ACK);

        m_esb_initialized = true;
    }
		
    NRF_TIMER0->INTENSET = TIMER_INTENSET_COMPARE0_Msk;		
    NRF_TIMER0->CC[0] = m_slot_length - 1000;
    NVIC_EnableIRQ(TIMER0_IRQn); 
}

static void m_on_multitimer(void)
{		
    NRF_TIMER0->EVENTS_COMPARE[0] = 0;
    NRF_TIMER0->TASKS_STOP = 1;
    
    m_configure_normal_timeslot();
    signal_callback_return_param.params.request.p_next = &m_timeslot_request;
    signal_callback_return_param.callback_action = NRF_RADIO_SIGNAL_CALLBACK_ACTION_REQUEST_AND_END;	
}

void timeslot_sys_event_handler(uint32_t sys_evt)
{
    uint32_t err_code;
		
    printf("sys_evt = %d\r\n", sys_evt);
    switch (sys_evt)
    {
        case NRF_EVT_RADIO_SIGNAL_CALLBACK_INVALID_RETURN:
        {
            
        }break;
        
        case NRF_EVT_RADIO_SESSION_IDLE:
        {
            
        }break;

        case NRF_EVT_RADIO_SESSION_CLOSED:
        {
            
        }break;

        case NRF_EVT_RADIO_BLOCKED:
        case NRF_EVT_RADIO_CANCELED:
        {
            m_configure_earliest_timeslot();
            err_code = sd_radio_request(&m_timeslot_request);
            APP_ERROR_CHECK(err_code);
        }break;

        default:break;
	}
}

nrf_radio_signal_callback_return_param_t * m_radio_callback(uint8_t signal_type)
{   
	printf("signal_type = %d\r\n", signal_type);
    switch(signal_type)
    {
        case NRF_RADIO_CALLBACK_SIGNAL_TYPE_START:
        {
            timeslot_on_start();
        }break;

        case NRF_RADIO_CALLBACK_SIGNAL_TYPE_TIMER0:
        {
            m_on_multitimer();
        }break;

        case NRF_RADIO_CALLBACK_SIGNAL_TYPE_RADIO:
        {
            signal_callback_return_param.params.request.p_next = NULL;
            signal_callback_return_param.callback_action = NRF_RADIO_SIGNAL_CALLBACK_ACTION_NONE;
        }break;
        
        default:break;
    }
    
    return (&signal_callback_return_param);
}

uint32_t radio_timeslots_start(void)
{
    uint32_t err_code;
    
    err_code = sd_radio_session_open(m_radio_callback);
    
    if(err_code != NRF_SUCCESS)
    {
        return err_code;
    }
    
    m_configure_earliest_timeslot();
    err_code = sd_radio_request(&m_timeslot_request);
    
    if(err_code != NRF_SUCCESS)
    {
        (void)sd_radio_session_close();
        
        return err_code;
    }

    return NRF_SUCCESS;
}

void nrf_esb_tx_success(uint32_t tx_pipe, int32_t rssi)
{
    static uint32_t success_times = 0;
    
    success_times++;
    printf("%d %d\r\n", success_times, rssi);
    
    my_tx_payload[0]++;
    (void)nrf_esb_add_packet_to_tx_fifo(PIPE_NUMBER, my_tx_payload, TX_PAYLOAD_LENGTH, NRF_ESB_PACKET_USE_ACK);    
}

void nrf_esb_tx_failed(uint32_t tx_pipe)
{
    static uint32_t failed_times = 0;
    
    failed_times++;
    printf("%d\r\n", failed_times); 
    
    my_tx_payload[0]++;
    (void)nrf_esb_add_packet_to_tx_fifo(PIPE_NUMBER, my_tx_payload, TX_PAYLOAD_LENGTH, NRF_ESB_PACKET_USE_ACK);    
}

void nrf_esb_rx_data_ready(uint32_t rx_pipe, int32_t rssi)
{
    uint32_t my_rx_payload_length;
    
    (void)nrf_esb_fetch_packet_from_rx_fifo(PIPE_NUMBER, my_rx_payload, &my_rx_payload_length);
    if (my_rx_payload_length > 0)
    {
        printf("%d %d\r\n", rssi, my_rx_payload[0]);
    }    
}

void nrf_esb_disabled(void)
{
    printf("disable\r\n");
}

But do not printf anything about the four callback functions. The printf as follows:

signal_type = 0
Start
signal_type = 1
sys_evt = 2
signal_type = 0
signal_type = 1
signal_type = 0
signal_type = 1
signal_type = 0
signal_type = 1
sys_evt = 4
signal_type = 0
signal_type = 1
signal_type = 0
signal_type = 1
signal_type = 0
signal_type = 1
signal_type = 0
signal_type = 1
signal_type = 0

So the four callback functions not be executed, why? What's wrong with the project?Thank you in advance!

Related