Пример #1
0
app_states_t app_init(void)
{
	if(usb_get_state() == USB_REM_WU_ENABLE)   
  	{   
    	return APP_SUSP_WE;    
  	}   
       
  	if(usb_get_state() == USB_REM_WU_DISABLE)   
  	{   
    	return APP_SUSP_WD;    
  	}
   /*
   	I3FR = 1;             // rising edge SPI ready detect
  	INTEXP = 0x01; //Slave SPI Interrupt
	SPI = 1; // Enable SPI Interrupt
	 */
	hal_nrf_enable_ack_payload(1);
	hal_nrf_enable_dynamic_payload(1);
	hal_nrf_setup_dynamic_payload(1 << 0); // Set up PIPE 0 to handle dynamic lengths
	hal_nrf_set_operation_mode(HAL_NRF_PRX);  		// Configure radio as primary receiver (PTX) 
	//hal_nrf_set_rx_payload_width(HAL_NRF_PIPE0, 30);	// Set payload width to 30 bytes
	hal_nrf_set_power_mode(HAL_NRF_PWR_UP);	 		// Power up radio
	CE_HIGH();	   // Enable receiver
	
	return APP_NORMAL; 	
}
Пример #2
0
void init_radio()
{
  // Enable the radio clock
  RFCKEN = 1;
  // Enable RF interrupt
  RF = 1;
    // Power up radio
  hal_nrf_set_power_mode(HAL_NRF_PWR_UP);
	hal_nrf_set_output_power(HAL_NRF_0DBM);
  	hal_nrf_enable_ack_payload(1);
	hal_nrf_enable_dynamic_payload(1);
	hal_nrf_setup_dynamic_payload(1); // Set up PIPE 0 to handle dynamic lengths
	hal_nrf_set_rf_channel(125); // 2525 MHz
   	hal_nrf_set_auto_retr(5, 250); // Retry 5x
    // Configure radio as primary receiver (PTX) 
  hal_nrf_set_operation_mode(HAL_NRF_PTX);
 
      // Set payload width to 32 bytes
//  hal_nrf_set_rx_payload_width(HAL_NRF_PIPE0, MAXLENGTH);
   // Enable global interrupt
  EA = 1;
}
Пример #3
0
void gzll_init(void)
{
  uint32_t flag;
  uint8_t temp_adr[GZLL_ADDRESS_WIDTH] = GZLL_DEFAULT_ADDRESS_PIPE1;

  flag = gzll_interupts_save();
  GZLL_RFCE_LOW();

  hal_nrf_enable_ack_payload(true);
  hal_nrf_enable_dynamic_payload(true);
  hal_nrf_setup_dynamic_payload(0xff);

  /*
  Initialize status variables.
  */
  gzll_channel_tab_index = 0;
  gzll_channel_tab_size = GZLL_DEFAULT_CHANNEL_TAB_SIZE;

  gzll_pending_goto_idle = false;
  gzll_timer_period_modified = false;

  gzll_current_tx_pipe = 0;
  gzll_pending_tx_start = false;
  gzll_tx_setup_modified = true;
  gzll_rx_setup_modified = true;
  gzll_radio_active_f = false;
  gzll_tx_success_f = true;

  gzll_sync_period = 0;
  gzll_sync_on = false;

  gzll_rx_dr = false;
  gzll_rx_power_high_f = false;
  gzll_ack_rx_pipe_fifo_cnt = 0;

  /*
  Set up default addresses.
  */
  hal_nrf_set_address(HAL_NRF_PIPE0, gzll_p0_adr);
  hal_nrf_set_address(HAL_NRF_PIPE1, temp_adr);

  temp_adr[0] = GZLL_DEFAULT_ADDRESS_PIPE2;
  hal_nrf_set_address(HAL_NRF_PIPE2, temp_adr);

  temp_adr[0] = GZLL_DEFAULT_ADDRESS_PIPE3;
  hal_nrf_set_address(HAL_NRF_PIPE3, temp_adr);

  temp_adr[0] = GZLL_DEFAULT_ADDRESS_PIPE4;
  hal_nrf_set_address(HAL_NRF_PIPE4, temp_adr);

  temp_adr[0] = GZLL_DEFAULT_ADDRESS_PIPE5;
  hal_nrf_set_address(HAL_NRF_PIPE5, temp_adr);

  /*
  Set up default channel.
  */
  hal_nrf_set_rf_channel(gzll_channel_tab[gzll_channel_tab_index]);

  /*
  Initialize dynamic parameters using default values.
  */
  gzll_dyn_params[GZLL_PARAM_DEVICE_MODE] = GZLL_DEFAULT_PARAM_DEVICE_MODE;
  gzll_dyn_params[GZLL_PARAM_TX_TIMEOUT] = GZLL_DEFAULT_PARAM_TX_TIMEOUT;
  gzll_dyn_params[GZLL_PARAM_TX_ATTEMPTS_PR_CHANNEL_WHEN_SYNC_ON] = GZLL_DEFAULT_PARAM_TX_ATTEMPTS_PR_CHANNEL_WHEN_SYNC_ON;
  gzll_dyn_params[GZLL_PARAM_TX_ATTEMPTS_PR_CHANNEL_WHEN_SYNC_OFF] = GZLL_DEFAULT_PARAM_TX_ATTEMPTS_PR_CHANNEL_WHEN_SYNC_OFF;
  gzll_dyn_params[GZLL_PARAM_HOST_MODE] = GZLL_DEFAULT_PARAM_HOST_MODE;
  gzll_dyn_params[GZLL_PARAM_RX_PIPES] = GZLL_DEFAULT_PARAM_RX_PIPES;
  gzll_dyn_params[GZLL_PARAM_CRYPT_PIPES] = GZLL_DEFAULT_PARAM_CRYPT_PIPES;
  gzll_dyn_params[GZLL_PARAM_RX_TIMEOUT] = GZLL_DEFAULT_PARAM_RX_TIMEOUT;
  gzll_dyn_params[GZLL_PARAM_HOST_MODE_1_CYCLE_PERIOD] = GZLL_DEFAULT_PARAM_HOST_MODE_1_CYCLE_PERIOD;
  gzll_dyn_params[GZLL_PARAM_RX_PERIOD] = GZLL_DEFAULT_PARAM_RX_PERIOD;
  gzll_dyn_params[GZLL_PARAM_RX_PERIOD_MODIFIER] = GZLL_DEFAULT_PARAM_RX_PERIOD_MODIFIER;
  gzll_dyn_params[GZLL_PARAM_RX_CHANNEL_HOLD_PERIODS] = GZLL_DEFAULT_PARAM_RX_CHANNEL_HOLD_PERIODS;
  gzll_dyn_params[GZLL_PARAM_OUTPUT_POWER] = GZLL_DEFAULT_PARAM_OUTPUT_POWER;
  gzll_dyn_params[GZLL_PARAM_POWER_DOWN_IDLE_ENABLE] = GZLL_DEFAULT_PARAM_POWER_DOWN_IDLE_ENABLE;
  gzll_dyn_params[GZLL_PARAM_MAX_SYNC_PERIOD] = GZLL_DEFAULT_PARAM_MAX_SYNC_PERIOD;
  gzll_dyn_params[GZLL_PARAM_COLLISION_CHANNEL_SWITCH_LIMIT] = GZLL_DEFAULT_PARAM_COLLISION_CHANNEL_SWITCH_LIMIT;

  /*
  Set up default output power.
  */
  hal_nrf_set_output_power((hal_nrf_output_power_t) gzll_dyn_params[GZLL_PARAM_OUTPUT_POWER]);

  /*
  Static radio setup.
  */
  hal_nrf_set_datarate(GZLL_HAL_DATARATE);
  hal_nrf_set_crc_mode(GZLL_CRC);
  hal_nrf_set_address_width(GZLL_ADDRESS_WIDTH);

  /*
  Clear radio IRQ flags.
  */
  //lint -esym(534, hal_nrf_get_clear_irq_flags) "return value ignored"
  hal_nrf_get_clear_irq_flags();

  hal_nrf_flush_rx();
  hal_nrf_flush_tx();

  gzll_set_timer_period(GZLL_DEFAULT_PARAM_RX_PERIOD);
  gzll_set_system_idle();
  gzll_interupts_restore(flag);
}