Пример #1
0
void gzp_init()
{
  uint8_t system_address[GZP_SYSTEM_ADDRESS_WIDTH];

  // Read "chip id", of which 4 bytes (GZP_SYSTEM_ADDRESS_WIDTH)
  // are used as system address
  gzp_host_chip_id_read(system_address, GZP_SYSTEM_ADDRESS_WIDTH);

  // Set up radio parameters (addresses and channel subset) from system_address
  gzp_update_radio_params(system_address);

  // Only "data pipe" enabled by default
  gzll_set_param(GZLL_PARAM_RX_PIPES, gzll_get_param(GZLL_PARAM_RX_PIPES) | (1 << GZP_DATA_PIPE));

  gzp_pairing_enabled_f = false;
  gzp_address_exchanged_f = false;
  gzp_id_req_stat = GZP_ID_REQ_IDLE;
  gzp_encrypted_user_data_length = 0;

  // Infinite RX timeout
  gzll_set_param(GZLL_PARAM_RX_TIMEOUT, 0);
}
Пример #2
0
static void gzp_process_address_req(uint8_t* gzp_req)
{
  uint8_t temp_rx_pipes, temp_host_mode;
  uint8_t pairing_resp[GZP_CMD_HOST_ADDRESS_RESP_PAYLOAD_LENGTH];

  gzp_address_exchanged_f = false;

  gzll_goto_idle();
  temp_rx_pipes = gzll_get_param(GZLL_PARAM_RX_PIPES);
  temp_host_mode =  gzll_get_param(GZLL_PARAM_HOST_MODE);

  // If requesting Device within close proximity
  if(gzll_rx_power_high())
  {
    gzll_set_param(GZLL_PARAM_RX_PIPES, 0);
    gzll_set_param(GZLL_PARAM_HOST_MODE, 0);
    gzll_set_param(GZLL_PARAM_RX_TIMEOUT, GZP_CLOSE_PROXIMITY_BACKOFF_RX_TIMEOUT);
    gzll_rx_fifo_flush();

    // Start "proximity" back off period
    gzll_rx_start();

    while(gzll_get_state() != GZLL_IDLE)
    ;

    // Build pairing response packet
    pairing_resp[0] = GZP_CMD_HOST_ADDRESS_RESP;
    gzp_host_chip_id_read(&pairing_resp[GZP_CMD_HOST_ADDRESS_RESP_ADDRESS], GZP_SYSTEM_ADDRESS_WIDTH);
    gzll_ack_payload_write(&pairing_resp[0], GZP_CMD_HOST_ADDRESS_RESP_PAYLOAD_LENGTH, 0);
    gzll_set_param(GZLL_PARAM_RX_TIMEOUT, GZP_STEP1_RX_TIMEOUT);

    // Enable only pairing pipe when waiting for pairing request step 1
    gzll_set_param(GZLL_PARAM_RX_PIPES, (1 << GZP_PAIRING_PIPE));
    gzll_rx_start();

    while(gzll_get_state() != GZLL_IDLE)
    {
      if(gzll_rx_fifo_read(&gzp_req[0], NULL, NULL))
      {
        // Validate step 1 of pairing request
        if(gzp_req[0] == GZP_CMD_HOST_ADDRESS_FETCH)
        {
          gzp_address_exchanged_f = true;
        }
      }
    }

    gzll_tx_fifo_flush();
    gzll_rx_fifo_flush();
    gzll_set_param(GZLL_PARAM_RX_TIMEOUT, 0);
    gzll_set_param(GZLL_PARAM_RX_PIPES, temp_rx_pipes);
    gzll_set_param(GZLL_PARAM_HOST_MODE, temp_host_mode);

    // Return to normal operation
    gzll_rx_start();
  }
  else
  {
    gzll_set_param(GZLL_PARAM_RX_PIPES, temp_rx_pipes & ~(1 << GZP_PAIRING_PIPE));
    gzll_set_param(GZLL_PARAM_RX_TIMEOUT, GZP_NOT_PROXIMITY_BACKOFF_RX_TIMEOUT);
    // Start "not proximity" backoff period
    gzll_rx_start();
  }
}
Пример #3
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();
  }
}