コード例 #1
0
ファイル: main.c プロジェクト: amurlynx/rf-nordic
void main(void)
{
  uint8_t payload[GZLL_MAX_PAYLOAD_LENGTH];

  mcu_init();
  gzll_init();

  // Set P0 as output
  P0DIR = 0;                                          

  EA = 1;
  
  // Enter host mode (start monitoring for data)
  gzll_rx_start();                                          
  
  for(;;)
  {      
    // If data received
    if(gzll_rx_fifo_read(payload, NULL, NULL))
    {
      // Write received payload[0] to port 0
      P0 = payload[0];
    }
  } 
}
コード例 #2
0
ファイル: gzp_device.c プロジェクト: busyStone/radio_rf
static gzp_tx_rx_trans_result_t gzp_tx_rx_transaction(const uint8_t *tx_packet, uint8_t tx_length, uint8_t *rx_dst, uint8_t *rx_length, uint8_t pipe)
{
  gzp_tx_rx_trans_result_t retval;
  uint8_t fetch_packet[GZPAR_CMD_FETCH_RESP_PAYLOAD_LENGTH];

  gzll_rx_fifo_flush();

  retval = GZP_TX_RX_FAILED_TO_SEND;

  if(gzp_tx_packet(tx_packet, tx_length, pipe))
  {
    retval = GZP_TX_RX_NO_RESPONSE;

    gzll_rx_fifo_flush();
    fetch_packet[0] = GZP_CMD_FETCH_RESP;

    gzp_delay_rx_periods(GZP_TX_RX_TRANS_DELAY);
    gzp_tx_packet(fetch_packet, GZPAR_CMD_FETCH_RESP_PAYLOAD_LENGTH, pipe);

    if(gzll_rx_fifo_read(rx_dst, rx_length, NULL))
    {
      retval = GZP_TX_RX_SUCCESS;
    }
  }
  return retval;
}
コード例 #3
0
ファイル: main.c プロジェクト: amurlynx/rf-nordic
void main(void)
{
  uint8_t payload[GZLL_MAX_PAYLOAD_LENGTH];
  uint8_t packet_cnt = 0;
  uint8_t rx_packet_cnt = 0;
  uint8_t rx_packet_byte0 = 0;

  mcu_init();
  gzll_init();

  // Set P0 as output
  P0DIR = 0;    

  EA = 1;

  for(;;)
  {      
    // If gazell link layer idle
    if(gzll_get_state() == GZLL_IDLE)
    {
      if(gzll_rx_fifo_read(payload, NULL, NULL))
      {
        P0 = ~payload[0];
      }

      // Put P0 contents in payload[0]
      payload[0] = P2;
       
      // Transmits payload[] to pipe 0 address
      gzll_tx_data(payload, 1, 0);   
    }
  }  
}
コード例 #4
0
ファイル: main.c プロジェクト: amurlynx/rf-nordic
void main(void)
{
  uint8_t payload[GZLL_MAX_PAYLOAD_LENGTH];

  mcu_init();
  gzll_init();
  gzp_init();
  gzp_pairing_enable(true);

  // Open pipe 2. (Pipe 0 and 1 are reserved by pairing library).
  gzll_set_param(GZLL_PARAM_RX_PIPES, gzll_get_param(GZLL_PARAM_RX_PIPES) | (1 << 2));
  
  // Set P0 as output
  P0DIR = 0;                                          

  EA = 1;

  // Enter host mode (start monitoring for data)
  gzll_rx_start();                                          
  
  for(;;)
  { 
    // If gzpair_host_execute() returns true, a pairing request has been received
    gzp_host_execute();

    // If Host ID request received
    if(gzp_id_req_received())
    {
      // Always grant request
      gzp_id_req_grant();
    }
   
    // If any data received (plaintext on pipe 2 or encrypted through Gazell pairing library)
    if((gzll_get_rx_data_ready_pipe_number() == 2) || (gzp_crypt_user_data_received()))
    {
      // Plaintext data received? 
      if(gzll_rx_fifo_read(payload, NULL, NULL))
      {
        // Write received payload[0] to port 0
        P0 = payload[0];
      }
      else
      {
        // Read data from Gazell pairing library
        gzp_crypt_user_data_read(payload, NULL);
        // Write received payload[0] to port 0
        P0 = payload[0];
      }
    }   
  }          
}
コード例 #5
0
ファイル: gzp_host.c プロジェクト: amurlynx/rf-nordic
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();
  }
}
コード例 #6
0
ファイル: gzp_host.c プロジェクト: amurlynx/rf-nordic
void gzp_host_execute()
{
  uint8_t rx_pipe;
  uint8_t payload_length;
  uint8_t rx_payload[GZLL_MAX_FW_PAYLOAD_LENGTH];

  gzp_address_exchanged_f = false;

  rx_pipe = gzll_get_rx_data_ready_pipe_number();

  if((rx_pipe == GZP_PAIRING_PIPE) || ((rx_pipe == GZP_DATA_PIPE) && (gzp_encrypted_user_data_length == 0)))
  {
    gzll_rx_fifo_read(rx_payload, &payload_length, NULL);

    switch(rx_payload[0])
    {
      case GZP_CMD_HOST_ADDRESS_REQ:
        gzp_process_address_req(rx_payload);
        break;

      #ifndef GZP_CRYPT_DISABLE

      case GZP_CMD_HOST_ID_REQ:
        gzp_process_id_req(rx_payload);
        break;
      case GZP_CMD_HOST_ID_FETCH:
        gzp_process_id_fetch(rx_payload);
        break;
      case GZP_CMD_KEY_UPDATE_PREPARE:
        gzp_process_key_update_prepare();
        break;
      case GZP_CMD_KEY_UPDATE:
        gzp_process_key_update(rx_payload);
        break;
      case GZP_CMD_ENCRYPTED_USER_DATA:
        gzp_process_encrypted_user_data(rx_payload, payload_length);
        break;

      #endif

      case GZP_CMD_FETCH_RESP:
      default:
        break;
    }
  }

  // Restart reception if "not proximity backoff" period has elapsed
  if(gzll_get_state() == GZLL_IDLE)
  {
    gzll_set_param(GZLL_PARAM_RX_TIMEOUT, 0);
    if(gzp_pairing_enabled_f)
    {
      gzll_set_param(GZLL_PARAM_RX_PIPES, gzll_get_param(GZLL_PARAM_RX_PIPES) | (1 << GZP_PAIRING_PIPE));
    }
    gzll_rx_start();
  }

  #ifndef GZP_CRYPT_DISABLE
  gzp_session_counter_inc();
  #endif
}
コード例 #7
0
ファイル: gzp_device.c プロジェクト: busyStone/radio_rf
bool gzp_address_req_send(uint8_t idx)
{
  uint8_t i;
  bool retval = false;
  uint8_t address_req[GZP_CMD_HOST_ADDRESS_REQ_PAYLOAD_LENGTH];
  uint8_t rx_payload[GZLL_MAX_PAYLOAD_LENGTH];
  uint16_t temp_power, temp_tx_timeout, temp_device_mode;

  if(gzll_get_state() == GZLL_IDLE)
  {
    // Store parameters that are temporarily changed
    temp_tx_timeout = gzll_get_param(GZLL_PARAM_TX_TIMEOUT);
    temp_power = gzll_get_param(GZLL_PARAM_OUTPUT_POWER);
    temp_device_mode = gzll_get_param(GZLL_PARAM_DEVICE_MODE);
    
    // Modify parameters
    gzll_set_param(GZLL_PARAM_TX_TIMEOUT, GZP_REQ_TX_TIMEOUT);
    gzll_set_param(GZLL_PARAM_OUTPUT_POWER, GZP_POWER);
    gzll_set_param(GZLL_PARAM_DEVICE_MODE, 0);

    // Flush RX FIFO
    gzll_rx_fifo_flush();

    // Build "request" packet
    address_req[0] = GZP_CMD_HOST_ADDRESS_REQ;

    // Send a number of packets in order to broadcast that devices not within
    // close proximity must back off.
    for(i = 0; i < GZP_MAX_BACKOFF_PACKETS; i++)
    {
      if(!gzp_tx_packet(address_req, GZP_CMD_HOST_ADDRESS_REQ_PAYLOAD_LENGTH, 0))
      {
        break;
      }
    }

    gzp_delay_rx_periods(GZP_TX_ACK_WAIT_TIMEOUT);

    // Send message for fetching pairing response from host.
    address_req[0] = GZP_CMD_HOST_ADDRESS_FETCH;

    if(gzp_tx_packet(&address_req[0], GZP_CMD_HOST_ADDRESS_REQ_PAYLOAD_LENGTH, 0))
    {
      // If pairing response received
      if(gzll_rx_fifo_read(rx_payload, NULL, NULL))
      {
        if(rx_payload[0] == GZP_CMD_HOST_ADDRESS_RESP)
        {
          memcpy(gzp_system_address, &rx_payload[GZP_CMD_HOST_ADDRESS_RESP_ADDRESS], GZP_SYSTEM_ADDRESS_WIDTH);
          gzp_update_radio_params(&rx_payload[GZP_CMD_HOST_ADDRESS_RESP_ADDRESS]);

          pairing_list_addr_write(idx, gzp_system_address);
          retval = true;
        }
      }
    }
    else
    {
      gzp_delay_rx_periods(GZP_NOT_PROXIMITY_BACKOFF_RX_TIMEOUT - GZP_TX_ACK_WAIT_TIMEOUT);
    }

    gzp_delay_rx_periods(GZP_STEP1_RX_TIMEOUT);

    // Clean-up and restore parameters temporarily  modified
    gzll_rx_fifo_flush();
    gzll_tx_fifo_flush();
    gzll_set_param(GZLL_PARAM_TX_TIMEOUT, temp_tx_timeout);
    gzll_set_param(GZLL_PARAM_OUTPUT_POWER, temp_power);
    gzll_set_param(GZLL_PARAM_DEVICE_MODE, temp_device_mode);
  }

  return retval;
}
コード例 #8
0
ファイル: main.c プロジェクト: olatief/Headstage
bool com_execute()
{
  xdata bool retval = false; 
  xdata uint8_t user_data[32];
  xdata uint16_t temp;
  xdata uint8_t t_length, t_pipe, curr_gzll_state;
  static xdata uint8_t prev_gzll_state = 0xff;

  // If Device operation
  if(device_mode)
  {    
    // Get Gazell state
    curr_gzll_state = gzll_get_state();

    if(curr_gzll_state == GZLL_IDLE) 
    {
      // If state transition from TRANSMIT to IDLE
      if(prev_gzll_state == GZLL_DEVICE_ACTIVE)
      {
        retval = true;
        
        if(gzll_tx_success())
        {
          statistics[TX_PL_CNT]++;
          statistics[TX_BYTE_CNT] += app_setup[TX_PL_LENGTH];          
          temp = gzll_get_tx_attempts();
          statistics[TX_TRY_CNT] += temp;
          statistics[AVG_TX_TRIES] = (uint16_t)(((float)statistics[TX_TRY_CNT] * 100) / statistics[TX_PL_CNT] );
          if(statistics[MAX_TX_TRIES] < temp)
          {
            statistics[MAX_TX_TRIES] = temp;
          }
          statistics[TX_CH_SWITCHES] += gzll_get_tx_channel_switches();
        } 
                                    
        if(gzll_rx_fifo_read(user_data, &t_length, &t_pipe))
        {
          statistics[RX_PL_CNT]++;
          statistics[RX_BYTE_CNT] += t_length;
        }
      }

      if(radio_run)
      {
        EA = 0;
        if(cnt_1ms >= app_setup[TX_PACKET_INTERVAL] )
        {  
          gzll_timer_tick = false;
          cnt_1ms = 0;
          EA = 1;
   
          while(!gzll_timer_tick)         // Improves synchronization to start in synch with protocol timer 
          ;
          gzll_tx_data(user_data, app_setup[TX_PL_LENGTH], app_setup[TX_PIPE]);
          curr_gzll_state = GZLL_DEVICE_ACTIVE; 
        }
        EA = 1;
      }
      prev_gzll_state = curr_gzll_state;               
    }
  }
  // Host operation
  else
  {
    if(gzll_rx_fifo_read(user_data, &t_length, &t_pipe))
    {
      retval = true;
      statistics[RX_PL_CNT]++;
      statistics[RX_BYTE_CNT] += t_length;
      
      t_length = app_setup[ACK_PL_LENGTH];
      if(t_length)
      {
        if(gzll_ack_payload_write(user_data, t_length, t_pipe))
        {          
          statistics[TX_PL_CNT]++;
          statistics[TX_BYTE_CNT] += t_length;      
        }
      }
    }
  }
  
  return retval;
}