Exemplo n.º 1
0
void radioInitSetup() {
    /*
     * Initialize the SPI connection, configure the I/O pins,
     * and set the register defaults
     */
    Radio_Init();

    /*
     * Configure pipe 0 as a receiver.  Pipe 0 has to be enabled
     * for the radio's link layer protocol to work.  This line
     * shouldn't be necessary since pipe 0 is enabled by default,
     * but it's nice to be explicit.
     */
    Radio_Configure_Rx(RADIO_PIPE_0, RemoteStationAddr, ENABLE);

    /*
     * Configure the radio's data rate (must match the other radio)
     * and the broadcast power
     */
    Radio_Configure(RADIO_2MBPS, RADIO_HIGHEST_POWER);

    /*
     * set the address to send to, dangling prepositions be damned.
     */
    Radio_Set_Tx_Addr(BaseStationAddr);

}
Exemplo n.º 2
0
Arquivo: vmac.c Projeto: nesl/sos-2x
/*************************************************************************
 * Initiate the radio and mac                                            *
 *************************************************************************/
void mac_init()
{
	Radio_Init();
#ifdef RADIO_CHANNEL
	Radio_Set_Channel(RADIO_CHANNEL);
#else
	Radio_Set_Channel(13);
#endif

#ifdef SOS_USE_PREEMPTION
	ker_register_module(sos_get_header_address(mod_header));
#else
	sched_register_kernel_module(&vmac_module, sos_get_header_address(mod_header), NULL);
#endif

	// Timer needs to be done after reigsteration
	ker_permanent_timer_init(&wakeup_timer, RADIO_PID, WAKEUP_TIMER_TID, TIMER_ONE_SHOT);

	mq_init(&vmac_pq);	//! Initialize sending queue
	resetSeq();		//set seq_count 0
	resetRetries(); 	//set retries 0

	//enable interrupt for receiving data
	Radio_SetPackRecvedCallBack(_MacRecvCallBack);
	Radio_Enable_Interrupt();
}
Exemplo n.º 3
0
// *************************************************************************************************
// @fn          Init_System
// @brief       Initialize system
// @param       none
// @return      none
// *************************************************************************************************
uint8 System_Init(void) {
	uint8 exit_code = 0;

	WDTCTL = WDTPW | WDTHOLD;	// Stop watchdog timer

	// Configure CPU clock
	System_Set_Speed(SYSTEM_SPEED_MHZ);

	// Ports
	LED_PORT_DIR |=  (LED1);				//Set LED1 pin as output
	LED_PORT_OUT &= ~(LED1);				// Set LED1 pin to LOW
	RF_RESET_OUT();							// Set RF module reset pin as output

	// Communication
	UART_Init();		//
	SPI_Init();			// RF module interface

	// RF Module

	if (exit_code = Radio_Init(RF_DATA_RATE, TX_POWER, RF_CHANNEL))		// Initialize RF module with 2kbps speed
		return exit_code;

	if (exit_code = Radio_Set_Channel(RF_CHANNEL))
		return exit_code;

	__enable_interrupt();

	return EXIT_NO_ERROR;
}
Exemplo n.º 4
0
void Radio_Cmd(FunctionalState cmd) {
  if(!_initialized) Radio_Init();
  
  // TODO: shut off boost converter when disabling radio?
  
  // set the FORCEOFF pin
  GPIO_WriteBit(GPIOD, GPIO_Pin_10, (cmd == ENABLE) ? Bit_SET : Bit_RESET);
}
Exemplo n.º 5
0
/**
 * \brief Main control sequence for sensor node
 * @return Constant 0, but it has nowhere to go.
 */
int main(void)
{
	Board_Init();
	Timer_Init();
	SPI_Init(); // Start SPI
	Radio_Init(); // Prep the radio

	while(True)
	{
		// Some merge example test lines.
		// More testing.
	}
}
Exemplo n.º 6
0
int main()
{
	init();
	pinMode(14, OUTPUT);
	pinMode(15, OUTPUT);
	digitalWrite(15, LOW);

	pinMode(radioPowerPin, OUTPUT);		// power cycle radio
	digitalWrite(radioPowerPin, LOW);
	delay(100);
	digitalWrite(radioPowerPin, HIGH);
	delay(100);

	pinMode(sonarPowerPin, OUTPUT);
	pinMode(sonarGroundPin, OUTPUT);
	digitalWrite(sonarGroundPin, LOW);
	digitalWrite(sonarPowerPin, HIGH);
	Sonar_Init();

	Radio_Init();
	Radio_Configure(RADIO_2MBPS, RADIO_HIGHEST_POWER);
	Radio_Configure_Rx(RADIO_PIPE_0, sensor_address, ENABLE);



	for (;;)
	{
		if (radio_flag)
		{
			radio_flag = 0;
			Radio_Receive(&packet);				// assumption: radio FIFO contains just one packet
			if (packet.type == REQUEST_ECHO)
			{
				Sonar_PreTrigger();
				Radio_Set_Tx_Addr(packet.payload.request.return_address);
				packet.type = CONFIRM_ECHO;
				packet.payload.confirm.station_id = STATION_ID;
				Radio_Transmit(&packet, RADIO_WAIT_FOR_TX);
				// sonar is triggered as soon as the explorer acknowledges it received the confirmation
				Sonar_Trigger();
				delay(50);
				digitalWrite(14, LOW);
			}
			packet.type = EMPTY;
		}
	}

	for (;;);
	return 0;
}
Exemplo n.º 7
0
// *************************************************************************************************
// @fn          Print_Error
// @brief       Print code that is set when function exits. If error code is 0 then nothin is prnted
//				out and packet is received or sent correctly
// @param       uint8 error_code		Error code number that is set by the function
// @return      none
// *************************************************************************************************
void Print_Error(uint8 error_code) {

	// Print out error code only if it is not 0
	if (error_code) {
		UART_Send_Data("\r\nError code: ");
		UART0_Send_ByteToChar(&error_code);
		error_code = 0;
	}

	// If packet size has wrong length then reset radio module
	if (error_code == ERR_RX_WRONG_LENGTH) {
		Radio_Init(RF_DATA_RATE, TX_POWER, RF_CHANNEL);
	}

	exit_code = 0;
}
Exemplo n.º 8
0
void Net_Init(net_handlers* handlers) {
    Radio_Init();
    Radio_Configure(110, RADIO_250KBPS, RADIO_HIGH_POWER);
    Radio_Configure_Rx(1, NET_BROADCAST, 1, 0);
    _handlers = handlers;
}