コード例 #1
0
// 0 = success
// 1 = init failed
// 2 = set tx_power failed
// 3 = enabled failed
// 4 = set channel selection policy failed
int RFduinoGZLL_begin(device_t device)
{
  _device = device;

  if (! nrf_gzll_init(device == HOST ? NRF_GZLL_MODE_HOST : NRF_GZLL_MODE_DEVICE))
    return 1;

  nrf_gzll_tx_power_t tx_power;
  if (RFduinoGZLL_tx_power_level <= -20)
    tx_power = NRF_GZLL_TX_POWER_N20_DBM;
  else if (RFduinoGZLL_tx_power_level <= -16)
    tx_power = NRF_GZLL_TX_POWER_N16_DBM;
  else if (RFduinoGZLL_tx_power_level <= -12)
    tx_power = NRF_GZLL_TX_POWER_N12_DBM;
  else if (RFduinoGZLL_tx_power_level <= -16)
    tx_power = NRF_GZLL_TX_POWER_N16_DBM;
  else if (RFduinoGZLL_tx_power_level <= -8)
    tx_power = NRF_GZLL_TX_POWER_N8_DBM;
  else if (RFduinoGZLL_tx_power_level <= -4)
    tx_power = NRF_GZLL_TX_POWER_N4_DBM;
  else if (RFduinoGZLL_tx_power_level <= 0)
    tx_power = NRF_GZLL_TX_POWER_0_DBM;
  else
    tx_power = NRF_GZLL_TX_POWER_4_DBM;

  if (! nrf_gzll_set_tx_power(tx_power))
    return 2;

  if (! nrf_gzll_set_device_channel_selection_policy(NRF_GZLL_DEVICE_CHANNEL_SELECTION_POLICY_USE_CURRENT))
    return 4;
 
  if (RFduinoGZLL_host_base_address ) {
   uint8_t msb = RFduinoGZLL_host_base_address >> 24;
   if (msb == 0x55 || msb == 0xAA)
     return 5;  // msb of base address should not be alternating 0s and 1s
	 if ( !nrf_gzll_set_base_address_0(RFduinoGZLL_host_base_address) )
		return 5;
  } 

  if (RFduinoGZLL_device_base_address) {
   uint8_t msb = RFduinoGZLL_device_base_address >> 24;
   if (msb == 0x55 || msb == 0xAA)
     return 6;  // msb of base address should not be alternating 0s and 1s
	 if ( !nrf_gzll_set_base_address_1(RFduinoGZLL_device_base_address) )
		return 6;
  }
	
  if (! nrf_gzll_enable())
    return 3;

  RFduinoGZLL_enabled = 1;

  return 0;
}
コード例 #2
0
ファイル: nrf_gzp.c プロジェクト: Abdellbar/nrf51
bool gzp_update_radio_params(const uint8_t* system_address)
{
    uint8_t i;
    uint8_t channels[NRF_GZLL_CONST_MAX_CHANNEL_TABLE_SIZE];
    uint32_t channel_table_size;
    uint32_t pairing_base_address_32, system_address_32;
    bool update_ok = true;
    bool gzll_enabled_state;

    gzll_enabled_state = nrf_gzll_is_enabled();

    // Configure "global" pairing address
    pairing_base_address_32 = (pairing_base_address[0])       + 
    ((uint32_t)pairing_base_address[1] <<  8) +
    ((uint32_t)pairing_base_address[2] << 16) +
    ((uint32_t)pairing_base_address[3] << 24) ;
    if(system_address != NULL)
    {
        system_address_32 = (system_address[0])       + 
        ((uint32_t)system_address[1] <<  8) +
        ((uint32_t)system_address[2] << 16) +
        ((uint32_t)system_address[3] << 24) ;
    }
    else
    { 
        return false;
    }

    nrf_gzp_disable_gzll();
    update_ok = update_ok && nrf_gzll_set_base_address_0(pairing_base_address_32);
    update_ok = update_ok && nrf_gzll_set_address_prefix_byte(GZP_PAIRING_PIPE, pairing_address_prefix_byte);
    update_ok = update_ok && nrf_gzll_set_base_address_1(system_address_32);

    // Configure address for pipe 1 - 5. Address byte set to equal pipe number.
    for(i = 1; i < NRF_GZLL_CONST_PIPE_COUNT; i++)
    {
        update_ok = update_ok && nrf_gzll_set_address_prefix_byte(i,i);
    }

    channel_table_size = nrf_gzll_get_channel_table_size();
    gzp_generate_channels(&channels[0], system_address, channel_table_size);

    // Write generated channel subset to Gazell Link Layer   
    update_ok = update_ok && nrf_gzll_set_channel_table(&channels[0], channel_table_size);
    if(gzll_enabled_state)
    {
        update_ok = update_ok && nrf_gzll_enable();
    }
    return update_ok;
}