Example #1
0
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);   
    }
  }  
}
Example #2
0
static bool gzp_tx_packet(const uint8_t* tx_packet, uint8_t length, uint8_t pipe)
{
  if(gzll_tx_data(tx_packet, length, pipe))
  {
    while(gzll_get_state() != GZLL_IDLE)
    ;
    return gzll_tx_success();
  }
  return false;
}
Example #3
0
void main(void)
{
  bool send_crypt_data = false;
  bool tx_success = false;
  gzp_id_req_res_t id_req_status;
  uint8_t payload[GZLL_MAX_PAYLOAD_LENGTH];
 
  mcu_init();
  
  // Initialize Gazell Link Layer
  gzll_init();
  
  // Initialize Gazell Pairing Library
  gzp_init();

  EA = 1;

  while(true)
  {      
    payload[0] = ~P0;
    
    // Send every other packet as encrypted data  
    if(send_crypt_data)
    {
      // Send encrypted packet using the Gazell pairing library
      tx_success = gzp_crypt_data_send(payload, GZP_ENCRYPTED_USER_DATA_MAX_LENGTH);
    }
    else
    {
      // Send packet as plaintext on pipe 2
      gzll_tx_data(payload, GZLL_MAX_FW_PAYLOAD_LENGTH, 2);   
      while(gzll_get_state() != GZLL_IDLE)
      ;
      tx_success = gzll_tx_success();
    }
    send_crypt_data = !send_crypt_data;

    // If data transfer failed
    if(!tx_success)
    {
      // Send "system address request". Needed for sending any user data to Host.
      gzp_address_req_send();
      
      // Send "Host ID request". Needed for sending encrypted user data to host.
      id_req_status = gzp_id_req_send();
    }

    // If waiting for Host to grant or reject ID request
    if(id_req_status == GZP_ID_RESP_PENDING)
    {
      // Send new ID request for fetching response
      id_req_status = gzp_id_req_send();
    }
  }  
}
Example #4
0
void main(void)
{
  uint8_t poll_cnt = 0;
  uint8_t payload[GZLL_MAX_PAYLOAD_LENGTH];

  mcu_init();
  gzll_init();

  // Always run on 16MHz crystal oscillator
  hal_clk_set_16m_source(HAL_CLK_XOSC16M);

  // Use Gazell Link Layer synchronous device mode 2 for minimizing 
  // transmit attempts
  gzll_set_param(GZLL_PARAM_DEVICE_MODE, 2);

  EA = 1;

  while(true)
  {      
    // If gazell link layer idle
    if(gzll_get_state() == GZLL_IDLE)
    {
      // Send a packet for every 20 wakeup, equals every ~20 ms  
      if(poll_cnt > 20)
      {
        // Read P0 and put in payload[0]
        payload[0] = ~P0;
        // Transmits 1 byte ( payload[0] ) to pipe 0 address
        gzll_tx_data(&payload[0], 1, 0);   
        poll_cnt = 0;
      }
    }

    EA = 0;
    // If radio not active, enter "register retention"
    if(!gzll_radio_active())
    {
      PWRDWN = 0x04; // Enter "register retention", will wake up on pre-tick
    }
    PWRDWN = 0x07;   // Enter "standby", will wake up on tick
    EA = 1; 
    
    poll_cnt++;
  }  
}
Example #5
0
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;
}