static void read_mouse_and_send(void)
{
//lint -save -e514 Unusual use of a boolean expression (use of &= assignment).
    bool mouse_send_ok;

    // If the "mouse sensor" has data ready for read-out.
    if(mouse_sensor_data_is_ready())
    {
        uint8_t mouse_packet[NRFR_MOUSE_MOV_PACKET_LENGTH];

        // Get packet from "mouse sensor".
        if(mouse_sensor_read(mouse_packet))
        {
            // Wait in case the FIFOs are full.
            while(!nrf_gzll_ok_to_add_packet_to_tx_fifo(NRFR_MOUSE_EP))
            {}

            // Add mouse packet to the mouse pipe's TX FIFO.
            mouse_send_ok = nrf_gzll_add_packet_to_tx_fifo(NRFR_MOUSE_EP, mouse_packet, NRFR_MOUSE_MOV_PACKET_LENGTH);
            if(!mouse_send_ok)
            {
              /* Adding packet to the TX FIFO failed. Use nrf_gzll_get_error_code() 
                to investigate the cause. */
            }
        }
    }

   

//lint -restore
}
Пример #2
0
/**@brief Callback on Gazell Transmit failed. Resends the current packet.
 */
void nrf_gzll_device_tx_failed(uint32_t pipe, nrf_gzll_device_tx_info_t tx_info)
{
    bool push_ok;
    uint8_t dummy[NRF_GZLL_CONST_MAX_PAYLOAD_LENGTH];
    uint32_t dummy_length = NRF_GZLL_CONST_MAX_PAYLOAD_LENGTH;

    // If the transmission failed, send a new packet.
    nrf_gpio_pin_set(GZLL_TX_FAIL_LED_PIN_NO);
    nrf_gpio_pin_clear(GZLL_TX_SUCCESS_LED_PIN_NO);

    if (tx_info.payload_received_in_ack)
    {
        // if data received attached to the ack, pop them.
        push_ok = nrf_gzll_fetch_packet_from_rx_fifo(pipe, dummy, &dummy_length);
        if (!push_ok)
        {
            GET_GAZELL_ERROR();
        }
    }

    push_ok = nrf_gzll_add_packet_to_tx_fifo(0, gzll_packet, PAYLOAD_SIZE);
    if (!push_ok)
    {
        GET_GAZELL_ERROR();
    }
}
Пример #3
0
/**@brief Callback function for Gazell Transmit fail. Resends the current packet.
 */
void nrf_gzll_device_tx_failed(uint32_t pipe, nrf_gzll_device_tx_info_t tx_info)
{
    bool     push_ok;
    uint8_t  dummy[NRF_GZLL_CONST_MAX_PAYLOAD_LENGTH];
    uint32_t dummy_length = NRF_GZLL_CONST_MAX_PAYLOAD_LENGTH;
    uint32_t err_code;

    // If the transmission failed, send a new packet.
    err_code = bsp_indication_set(BSP_INDICATE_SEND_ERROR);
    APP_ERROR_CHECK(err_code);

    if (tx_info.payload_received_in_ack)
    {
        // if data received attached to the ack, pop them.
        push_ok = nrf_gzll_fetch_packet_from_rx_fifo(pipe, dummy, &dummy_length);
        if (!push_ok)
        {
            GET_GAZELL_ERROR();
        }
    }

    push_ok = nrf_gzll_add_packet_to_tx_fifo(0, m_gzll_packet, PAYLOAD_SIZE);
    if (!push_ok)
    {
        GET_GAZELL_ERROR();
    }
}
Пример #4
0
bool RFduinoGZLL_send_to_device(device_t device, const char *data, int len)
{
  if (_device != HOST)
    return false;

  return nrf_gzll_add_packet_to_tx_fifo(device, data, len);
}
Пример #5
0
/**@brief Start Gazell functionality.
 */
void gzll_app_start(void)
{
    bool gzll_call_ok;

    gzll_call_ok  = nrf_gzll_init(NRF_GZLL_MODE_DEVICE);
    if (!gzll_call_ok)
    {
        GET_GAZELL_ERROR();
    }
    
    gzll_call_ok = nrf_gzll_set_max_tx_attempts(MAX_TX_ATTEMPTS);
    if (!gzll_call_ok)
    {
        GET_GAZELL_ERROR();
    }
    
    gzll_call_ok = nrf_gzll_enable();
    if (!gzll_call_ok)
    {
        GET_GAZELL_ERROR();
    }

    // Add a packet to the TX FIFO to start the data transfer. 
    // From here on more data will be added through the Gazell callbacks
    gzll_packet[0] = DUMMY_PACKET;
    gzll_call_ok = nrf_gzll_add_packet_to_tx_fifo(0, gzll_packet, PAYLOAD_SIZE);
    if (!gzll_call_ok)
    {
        GET_GAZELL_ERROR();
    }
}
static void read_mouse_and_send(void)
{
//lint -save -e514 Unusual use of a boolean expression (use of &= assignment).
    bool mouse_send_ok;

    // If the "mouse sensor" has data ready for read-out.
    if(mouse_sensor_data_is_ready())
    {
        uint8_t mouse_packet[NRFR_MOUSE_MOV_PACKET_LENGTH];

        // Get packet from "mouse sensor".
        if(mouse_sensor_read(mouse_packet))
        {
            // Wait in case the FIFOs are full.
            while(!nrf_gzll_ok_to_add_packet_to_tx_fifo(NRFR_MOUSE_EP))
            {}

            // Add mouse packet to the mouse pipe's TX FIFO.
            mouse_send_ok = nrf_gzll_add_packet_to_tx_fifo(NRFR_MOUSE_EP, mouse_packet, NRFR_MOUSE_MOV_PACKET_LENGTH);
            if (mouse_send_ok)
            {
                printf("Mouse sent OK\n");
            }
            else
            {
                printf("Mouse sent FAILED\n");
            }
        }
    }
       

   

//lint -restore
}
/* If the transmission failed, send a new packet.
 * This callback does not occur by default since NRF_GZLL_DEFAULT_MAX_TX_ATTEMPTS 
 * is 0 (inifinite retransmits)
 */
void nrf_gzll_device_tx_failed(uint32_t pipe, nrf_gzll_device_tx_info_t tx_info)
{
    tx_success = false;

    // Load data into TX queue
    data_payload[0] = input_get();
    push_ok = nrf_gzll_add_packet_to_tx_fifo(pipe, data_payload, TX_PAYLOAD_LENGTH);
}
Пример #8
0
static void gzp_preload_ack(uint8_t* src, uint8_t length, uint8_t pipe)
{
  gzll_goto_idle();
    
  gzll_tx_fifo_flush();
    
  (void)nrf_gzll_add_packet_to_tx_fifo(pipe, src, length);
    
  gzll_rx_start();
}
Пример #9
0
bool RFduinoGZLL_send_to_host(const char *data, int len)
{
  if (_device == HOST)
    return false;

  // a zero byte load is valid, but data must be non-null
  if (!data && !len)
    data = &_device;

  return nrf_gzll_add_packet_to_tx_fifo(_device, data, len);
}
Пример #10
0
/**@brief Callback function for Gazell Transmit Success. Transmits next packet.
 */
void nrf_gzll_device_tx_success(uint32_t pipe, nrf_gzll_device_tx_info_t tx_info)
{
    bool       push_ok;
    static int cpt = 0;
    uint8_t    dummy[NRF_GZLL_CONST_MAX_PAYLOAD_LENGTH];
    uint32_t   dummy_length = NRF_GZLL_CONST_MAX_PAYLOAD_LENGTH;
    uint32_t err_code;

    // If an ACK was received, we send another packet. 
    err_code = bsp_indication_set(BSP_INDICATE_SENT_OK);
    APP_ERROR_CHECK(err_code);

    if (tx_info.payload_received_in_ack)
    {
        // if data received attached to the ack, pop them.
        push_ok = nrf_gzll_fetch_packet_from_rx_fifo(pipe, dummy, &dummy_length);
        if (!push_ok)
        {
            GET_GAZELL_ERROR();
        }
    }

    cpt++;
    if (cpt > NB_TX_WITH_SAME_PAYLOAD)
    {
        cpt = 0;

        m_gzll_packet[0] = ~(m_gzll_packet[0]);
        if (m_gzll_packet[0] == DUMMY_PACKET)
        {
            m_gzll_packet[0] = 0x00;
        }

        m_gzll_packet[0] <<= 1;
        if (m_gzll_packet[0] == 0)
        {
            m_gzll_packet[0]++;
        }

        m_gzll_packet[0] = ~(m_gzll_packet[0]);
    }

    push_ok = nrf_gzll_add_packet_to_tx_fifo(0, m_gzll_packet, PAYLOAD_SIZE);
    if (!push_ok)
    {
        GET_GAZELL_ERROR();
    }
}
Пример #11
0
// If a data packet was received, we write the first byte to LEDS. 
void nrf_gzll_host_rx_data_ready(uint32_t pipe, nrf_gzll_host_rx_info_t rx_info)
{   
    uint32_t data_payload_length = NRF_GZLL_CONST_MAX_PAYLOAD_LENGTH;
    packet_received = true;

    // Pop packet and write first byte of the payload to the GPIO port.
    pop_ok = nrf_gzll_fetch_packet_from_rx_fifo(pipe, data_payload, &data_payload_length);
    if (data_payload_length > 0)
    {
        nrf_gpio_port_write(LEDS,~data_payload[0]);
    }

    // Read buttons and load ACK payload into TX queue
    ack_payload[0] = nrf_gpio_port_read(BUTTONS);  // Button logic is inverted.
    push_ok = nrf_gzll_add_packet_to_tx_fifo(pipe, ack_payload, TX_PAYLOAD_LENGTH);

}
Пример #12
0
static bool gzp_tx_packet(const uint8_t* tx_packet, uint8_t length, uint8_t pipe)
{
    tx_complete = false;
    tx_success = false;

    if(nrf_gzll_add_packet_to_tx_fifo(pipe,(uint8_t *)tx_packet, length))
    {
        while(tx_complete == false)
        {
            __WFI();
        }
        return tx_success;
    }
    else
    {
        return false;
    }
}
Пример #13
0
/**@brief Callback on Gazell Transmit Success. Transmits next packet.
 */
void nrf_gzll_device_tx_success(uint32_t pipe, nrf_gzll_device_tx_info_t tx_info)
{
    bool       push_ok;
    static int cpt = 0;
    uint8_t dummy[NRF_GZLL_CONST_MAX_PAYLOAD_LENGTH];
    uint32_t dummy_length = NRF_GZLL_CONST_MAX_PAYLOAD_LENGTH;
    

    // If an ACK was received, we send another packet. 
    nrf_gpio_pin_set(GZLL_TX_SUCCESS_LED_PIN_NO);
    nrf_gpio_pin_clear(GZLL_TX_FAIL_LED_PIN_NO);

    if (tx_info.payload_received_in_ack)
    {
        // if data received attached to the ack, pop them.
        push_ok = nrf_gzll_fetch_packet_from_rx_fifo(pipe, dummy, &dummy_length);
        if (!push_ok)
        {
            GET_GAZELL_ERROR();
        }
    }

    cpt++;
    if (cpt > NB_TX_WITH_SAME_PAYLOAD)
    {
        cpt = 0;
        gzll_packet[0] = ~(gzll_packet[0]);
        if (gzll_packet[0] == DUMMY_PACKET)
        {
            gzll_packet[0] = 0x00;
        }
        gzll_packet[0] <<= 1;
        if (gzll_packet[0] == 0)
        {
            gzll_packet[0]++;
        }
        gzll_packet[0] = ~(gzll_packet[0]);
    }
    push_ok = nrf_gzll_add_packet_to_tx_fifo(0, gzll_packet, PAYLOAD_SIZE);
    if (!push_ok)
    {
        GET_GAZELL_ERROR();
    }
}
Пример #14
0
// If an ACK was received, we send another packet. 
void  nrf_gzll_device_tx_success(uint32_t pipe, nrf_gzll_device_tx_info_t tx_info)
{
    uint32_t ack_payload_length = NRF_GZLL_CONST_MAX_PAYLOAD_LENGTH;    
    tx_success = true;

    if (tx_info.payload_received_in_ack)
    {
        // Pop packet and write first byte of the payload to the GPIO port.
        pop_ok = nrf_gzll_fetch_packet_from_rx_fifo(pipe, ack_payload, &ack_payload_length);
        if (ack_payload_length > 0)
        {
            nrf_gpio_port_write(LEDS, ~ack_payload[0]);  // Button press is active low. 
        }
    }
    
    // Read buttons and load data payload into TX queue
    data_payload[0] = nrf_gpio_port_read(BUTTONS);
    push_ok = nrf_gzll_add_packet_to_tx_fifo(pipe, data_payload, TX_PAYLOAD_LENGTH);
}
// If an ACK was received, we send another packet. 
void  nrf_gzll_device_tx_success(uint32_t pipe, nrf_gzll_device_tx_info_t tx_info)
{
    uint32_t ack_payload_length = NRF_GZLL_CONST_MAX_PAYLOAD_LENGTH;    
    tx_success = true;

    if (tx_info.payload_received_in_ack)
    {
        // Pop packet and write first byte of the payload to the GPIO port.
        pop_ok = nrf_gzll_fetch_packet_from_rx_fifo(pipe, ack_payload, &ack_payload_length);
        if (ack_payload_length > 0)
        {
            output_present(ack_payload[0]);
        }
    }
    
    // Read buttons and load data payload into TX queue
    data_payload[0] = input_get();
    push_ok = nrf_gzll_add_packet_to_tx_fifo(pipe, data_payload, TX_PAYLOAD_LENGTH);
}
int main()
{
    uint8_t debug_led_output;

    // Setup user interface (buttons and LEDs)
    ui_init();

    // Initialize Gazell
    init_ok = nrf_gzll_init(NRF_GZLL_MODE_DEVICE);
    
    // Attempt sending every packet up to 100 times    
    init_ok &= nrf_gzll_set_max_tx_attempts(100);

    // Load data into TX queue
    data_payload[0] = input_get();
    push_ok = nrf_gzll_add_packet_to_tx_fifo(PIPE_NUMBER, data_payload, TX_PAYLOAD_LENGTH);
    
    // Enable Gazell to start sending over the air
    enable_ok = nrf_gzll_enable();         

    while(1)
    {
        // Error handling
        debug_led_output = ((uint8_t)tx_success << 4) | ((uint8_t)pop_ok << 3) | ((uint8_t)push_ok << 2) | ((uint8_t)enable_ok << 1) | (uint8_t)init_ok;                
        
        // If an error has occured
        if(debug_led_output != 0x1F)
        {
            output_present(0xFF);
            nrf_delay_us(1000000); // 1 second delay 
            output_present(0xFF);
            nrf_delay_us(1000000); // 1 second delay 
            output_present(0xFF);
            //nrf_gzll_get_error_code());
            nrf_delay_us(1000000); // 1 second delay 
        }

        // Optionally send the CPU to sleep while waiting for a callback.
        // __WFI();
    }
}
Пример #17
0
int main()
{
    uint8_t debug_led_output;

    // Setup port directions
    nrf_gpio_port_dir_set(BUTTONS, NRF_GPIO_PORT_DIR_INPUT);
    nrf_gpio_port_dir_set(LEDS, NRF_GPIO_PORT_DIR_OUTPUT);

    // Initialize Gazell
    init_ok = nrf_gzll_init(NRF_GZLL_MODE_DEVICE);
    
    // Attempt sending every packet up to 100 times    
    init_ok &= nrf_gzll_set_max_tx_attempts(100);

    // Load data into TX queue
    data_payload[0] = nrf_gpio_port_read(BUTTONS);  
    push_ok = nrf_gzll_add_packet_to_tx_fifo(PIPE_NUMBER, data_payload, TX_PAYLOAD_LENGTH);
    
    // Enable Gazell to start sending over the air
    enable_ok = nrf_gzll_enable();         

    while(1)
    {
        // Error handling
        debug_led_output = ((uint8_t)tx_success << 4) | ((uint8_t)pop_ok << 3) | ((uint8_t)push_ok << 2) | ((uint8_t)enable_ok << 1) | (uint8_t)init_ok;                
        
        // If an error has occured
        if(debug_led_output != 0x1F)
        {
            nrf_gpio_port_write(LEDS,0xFF);      
            nrf_delay_us(1000000); // 1 second delay 
            nrf_gpio_port_write(LEDS, debug_led_output);
            nrf_delay_us(1000000); // 1 second delay 
            nrf_gpio_port_write(LEDS,0xF0 + (uint32_t)nrf_gzll_get_error_code()); 
            nrf_delay_us(1000000); // 1 second delay 
        }

        // Optionally send the CPU to sleep while waiting for a callback.
        // __WFI();
    }
}
Пример #18
0
static void gzp_process_address_req(uint8_t* gzp_req)
{
  uint8_t temp_rx_pipes;
  uint8_t pairing_resp[GZP_CMD_HOST_ADDRESS_RESP_PAYLOAD_LENGTH];
  uint32_t rx_payload_length = NRF_GZLL_CONST_MAX_PAYLOAD_LENGTH;

  gzp_address_exchanged_f = false;

  gzll_goto_idle();
  ASSERT(nrf_gzll_get_error_code() == NRF_GZLL_ERROR_CODE_NO_ERROR);
    
  temp_rx_pipes = nrf_gzll_get_rx_pipes_enabled();
  ASSERT(nrf_gzll_get_error_code() == NRF_GZLL_ERROR_CODE_NO_ERROR);

  // If requesting Device within close proximity
  if(prev_gzp_rx_info.rssi >= GZP_HOST_RX_POWER_THRESHOLD) 
  {
    (void)nrf_gzll_set_rx_pipes_enabled(0);
    ASSERT(nrf_gzll_get_error_code() == NRF_GZLL_ERROR_CODE_NO_ERROR);
    
      gzll_set_rx_timeout(GZP_CLOSE_PROXIMITY_BACKOFF_RX_TIMEOUT);
    ASSERT(nrf_gzll_get_error_code() == NRF_GZLL_ERROR_CODE_NO_ERROR);
      
    gzll_rx_fifo_flush();
    ASSERT(nrf_gzll_get_error_code() == NRF_GZLL_ERROR_CODE_NO_ERROR);
      
    // Start "proximity" back off period
    gzll_rx_start();
    ASSERT(nrf_gzll_get_error_code() == NRF_GZLL_ERROR_CODE_NO_ERROR);

    while(nrf_gzll_is_enabled())
    {}
    
    // Build pairing response packet
    pairing_resp[0] = (uint8_t)GZP_CMD_HOST_ADDRESS_RESP;
    gzp_host_chip_id_read(&pairing_resp[GZP_CMD_HOST_ADDRESS_RESP_ADDRESS], GZP_SYSTEM_ADDRESS_WIDTH);

    (void)nrf_gzll_add_packet_to_tx_fifo(0, &pairing_resp[0], GZP_CMD_HOST_ADDRESS_RESP_PAYLOAD_LENGTH);
    ASSERT(nrf_gzll_get_error_code() == NRF_GZLL_ERROR_CODE_NO_ERROR);
    gzll_set_rx_timeout(GZP_STEP1_RX_TIMEOUT);
    
    // Enable only pairing pipe when waiting for pairing request step 1
    (void)nrf_gzll_set_rx_pipes_enabled((1 << GZP_PAIRING_PIPE));
    
    gzll_rx_start();   
        
    while(nrf_gzll_is_enabled())
    {
      if(nrf_gzll_get_rx_fifo_packet_count(GZP_PAIRING_PIPE))
      {
        (void)nrf_gzll_fetch_packet_from_rx_fifo(GZP_PAIRING_PIPE, &gzp_req[0], &rx_payload_length);
        
        // Validate step 1 of pairing request
        if(gzp_req[0] == (uint8_t)GZP_CMD_HOST_ADDRESS_FETCH)
        {
          gzp_address_exchanged_f = true;
        }
      }
    }
   
    gzll_tx_fifo_flush();
    gzll_rx_fifo_flush();
    
    gzll_set_rx_timeout(0);
    
    (void)nrf_gzll_set_rx_pipes_enabled(temp_rx_pipes);
    
    // Return to normal operation
    gzll_rx_start();
  }
  else
  {
    (void)nrf_gzll_set_rx_pipes_enabled(temp_rx_pipes & ~(1 << GZP_PAIRING_PIPE));
    
    gzll_set_rx_timeout(GZP_NOT_PROXIMITY_BACKOFF_RX_TIMEOUT);
      
    // Start "not proximity" backoff period
    gzll_rx_start();
  }
}