示例#1
0
void radio_init()
{
	rcc_periph_clock_enable(R_RCC_SPI);
	rcc_periph_clock_enable(R_RCC_GPIO);
	gpio_mode_setup(R_SPI_PORT, GPIO_MODE_AF, GPIO_PUPD_NONE,
			R_SPI_PINS);
	gpio_set_af(R_SPI_PORT, R_SPI_AFn, R_SPI_PINS);
	gpio_mode_setup(R_CS_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE,
			R_CS_PIN);

	// Reset and enable the SPI periph
	spi_reset(R_SPI);
	spi_init_master(R_SPI, SPI_CR1_BAUDRATE_FPCLK_DIV_64,
			SPI_CR1_CPOL_CLK_TO_0_WHEN_IDLE,
			SPI_CR1_CPHA_CLK_TRANSITION_1,
			SPI_CR1_CRCL_8BIT,
			SPI_CR1_MSBFIRST);

	// Trigger an RXNE event when we have 8 bits (one byte) in the buffer
	spi_fifo_reception_threshold_8bit(R_SPI);

	// NSS must be set high for the peripheral to function
	spi_enable_software_slave_management(R_SPI);
	spi_set_nss_high(R_SPI);
	gpio_set(R_CS_PORT, R_CS_PIN);

	// Enable
	spi_enable(R_SPI);

	radio_sleep();


}
示例#2
0
OT_WEAK void radio_init( ) {
/// Transceiver implementation dependent    
    //vlFILE* fp;
    
    /// Set SPIRIT1-dependent initialization defaults
    //rfctl.flags     = RADIO_FLAG_XOON;
    rfctl.flags     = 0;
    rfctl.nextcal   = 0;
    
    /// Set universal Radio module initialization defaults
    //radio.state     = RADIO_Idle;
    //radio.evtdone   = &otutils_sig2_null;
    
    /// Initialize the bus between SPIRIT1 and MCU, and load defaults.
    /// SPIRIT1 starts-up in Idle (READY), so we set the state and flags
    /// to match that.  Then, init the bus and send RADIO to sleep.
    /// SPIRIT1 can do SPI in Sleep.
    spirit1_init_bus();
    spirit1_load_defaults();
    
    /// Do this workaround (SPIRIT1 Errata DocID023165 R5, section 1.2) to fix
    /// the shutdown current issue for input voltages <= 2.6V.  For input
    /// voltages > 2.6V, it does not hurt anything.
    spirit1_write(RFREG(PM_TEST), 0xCA);
    spirit1_write(RFREG(TEST_SELECT), 0x04);
    spirit1_write(RFREG(TEST_SELECT), 0x00);
    
    /// Done with the radio init
    //spirit1drv_smart_standby();
    radio_sleep();
    
    /// Initialize RM2 elements such as channels, link-params, etc.
    rm2_init();
}
示例#3
0
void comms(void) {
  /* Wake up the radio */
  radio_wake();

  /* If we need to try to update the time */
  if (++time_update_counter >= TIME_UPDATE_INTERVAL) {
    time_update_counter = 0;

    /* Get the time */
    radio_transmit((uint8_t*)"T\n\0", 3, BASE_STATION_ADDR, 1);
  }

  upload();

  console_printf("Going to Sleep!\n");

  /* Put the radio back to sleep */
  radio_sleep();
}
示例#4
0
OT_WEAK void dll_idle(void) {
/// Idle Routine: Disable radio and manipulate system tasks in order to go into
/// the type of idle that is configured in dll.idle_state (OFF, SLEEP, HOLD)
	static const ot_u8 scan_events[] = { 0,0, 0,5, 4,0, 1,0 };
	ot_u8* scan_evt_ptr;

    /// Make sure Radio is powered-down
	radio_gag();
    radio_sleep();

    /// Assure all DLL tasks are in IDLE
#   ifndef __KERNEL_NONE__
    sys.task_RFA.event  = 0;
    scan_evt_ptr        = (ot_u8*)&scan_events[dll.idle_state<<1];
    sys.task_HSS.event  = *scan_evt_ptr;
    sys.task_SSS.event  = *(++scan_evt_ptr);

#   if (M2_FEATURE(BEACONS) == ENABLED)
    sys.task_BTS.event  = ((dll.netconf.b_attempts != 0) \
    		            && (dll.idle_state != M2_DLLIDLE_OFF));
#   endif
#   endif
}