Ejemplo n.º 1
0
Archivo: vmac.c Proyecto: 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();
}
Ejemplo n.º 2
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;
}