Exemple #1
0
/**
 * Inicializa los dispositivos del sistema.
 * Esta función se debe llamar después de  bsp_int_init().
 */
static void bsp_sys_init( void )
{
	/* Inicialización de las UARTs */
	uart_init(UART1_ID, UART1_BAUDRATE, UART1_NAME);
	uart_init(UART2_ID, UART2_BAUDRATE, UART2_NAME);
}
void board_init() {
	uint16_t i,j;
	//enable all port clocks.
	SIM_SCGC5 |= (SIM_SCGC5_PORTA_MASK
			| SIM_SCGC5_PORTB_MASK
			| SIM_SCGC5_PORTC_MASK
			| SIM_SCGC5_PORTD_MASK
			| SIM_SCGC5_PORTE_MASK );


	//init all pins for the radio
	//SLPTR
#ifdef TOWER_K20
	PORTB_PCR3 = PORT_PCR_MUX(1);// -- PTB3 used as gpio for slptr
	GPIOB_PDDR |= RADIO_SLPTR_MASK; //set as output

	//RADIO RST -- TODO in the TWR change it to another pin! this is one of the leds.
	PORTC_PCR9 = PORT_PCR_MUX(1);// -- PTC9 used as gpio for radio rst
	GPIOC_PDDR |= RADIO_RST_MASK; //set as output


#elif OPENMOTE_K20
	PORTD_PCR4 = PORT_PCR_MUX(1);// -- PTD4 used as gpio for slptr
	GPIOD_PDDR |= RADIO_SLPTR_MASK; //set as output

	//RADIO RST 
	PORTD_PCR5 = PORT_PCR_MUX(1);// -- PTD5 used as gpio for radio rst
	GPIOD_PDDR |= RADIO_RST_MASK; //set as output

#endif	

	PORT_PIN_RADIO_RESET_LOW();//activate the radio.

	
	PORT_PIN_RADIO_SLP_TR_CNTL_LOW();
	
	//ptc5 .. ptc5 is pin 62, irq A
	enable_irq(RADIO_EXTERNAL_PORT_IRQ_NUM);//enable the irq. The function is mapped to the vector at position 105 (see manual page 69). The vector is in isr.h

	//external port radio_isr.
	PORTC_PCR5 = PORT_PCR_MUX(1);// -- PTC5 used as gpio for radio isr through llwu
	GPIOC_PDDR &= ~1<<RADIO_ISR_PIN; //set as input ==0
	PORTC_PCR5 |= PORT_PCR_IRQC(0x09); //9 interrupt on raising edge. page 249 of the manual.	
	PORTC_PCR5 |= PORT_PCR_ISF_MASK; //clear any pending interrupt.

	llwu_init();//low leakage unit init - to recover from deep sleep

	debugpins_init();
	leds_init();
	bsp_timer_init();
	uart_init();
	radiotimer_init();
	spi_init();	
	radio_init();
	leds_all_off();
	leds_sync_on();
	leds_radio_on();
	leds_debug_on();
	leds_error_on();
	leds_all_off();
	debugpins_fsm_clr();
}
void nrf_log_backend_uart_init(void)
{
    bool async_mode = NRF_LOG_DEFERRED ? true : false;
    uart_init(async_mode);
}
Exemple #4
0
int
main(void)
{
  wdt_disable();
  clock_prescale_set(clock_div_1);

  led_init();
  LED_ON();

  spi_init();

//  eeprom_factory_reset("xx");
  eeprom_init();

// Setup OneWire and make a full search at the beginning (takes some time)
#ifdef HAS_ONEWIRE
  i2c_init();
	onewire_Init();
	onewire_FullSearch();
#endif

  // Setup the timers. Are needed for watchdog-reset
#if defined (HAS_IRRX) || defined (HAS_IRTX)
  ir_init();
  // IR uses highspeed TIMER0 for sampling 
  OCR0A  = 1;                              // Timer0: 0.008s = 8MHz/256/2   == 15625Hz
#else
  OCR0A  = 249;                            // Timer0: 0.008s = 8MHz/256/250 == 125Hz
#endif
  TCCR0B = _BV(CS02);
  TCCR0A = _BV(WGM01);
  TIMSK0 = _BV(OCIE0A);

  TCCR1A = 0;
  TCCR1B = _BV(CS11) | _BV(WGM12);         // Timer1: 1us = 8MHz/8

  MCUSR &= ~(1 << WDRF);                   // Enable the watchdog
  wdt_enable(WDTO_2S);

  uart_init( UART_BAUD_SELECT_DOUBLE_SPEED(UART_BAUD_RATE,F_CPU) );

  fht_init();
  tx_init();
  input_handle_func = analyze_ttydata;

  display_channel = DISPLAY_USB;

#ifdef HAS_RF_ROUTER
  rf_router_init();
  display_channel |= DISPLAY_RFROUTER;
#endif

  LED_OFF();

  sei();

  for(;;) {
    uart_task();
    RfAnalyze_Task();
    Minute_Task();
#ifdef HAS_FASTRF
    FastRF_Task();
#endif
#ifdef HAS_RF_ROUTER
    rf_router_task();
#endif
#ifdef HAS_ASKSIN
    rf_asksin_task();
#endif
#ifdef HAS_MORITZ
    rf_moritz_task();
#endif
#ifdef HAS_RWE
    rf_rwe_task();
#endif
#ifdef HAS_RFNATIVE
    native_task();
#endif
#ifdef HAS_KOPP_FC
    kopp_fc_task();
#endif
#if defined(HAS_IRRX) || defined(HAS_IRTX)
    ir_task();
#endif
#ifdef HAS_MBUS
    rf_mbus_task();
#endif
#ifdef HAS_ZWAVE
    rf_zwave_task();
#endif
  }

}
Exemple #5
0
//===========================================================================
//	Initialize Micro to Desired State...
//===========================================================================
static void Initialization(void){

	//Initialize Peripherals	
		//BLKCON2 Control Bits...Manually Set 4/12/2013
			DSIO0 = 1; // 0=> Enables Synchronous Serial Port 0 
			DUA0  = 0; // 0=> Enables the operation of UART0 
			DUA1  = 1; // 0=> Enables Uart1 
			DI2C1 = 1; // 0=> Enables I2C bus Interface (Slave) 
			DI2C0 = 0; // 0=> Enables I2C bus Interface (Master)	
	
		BLKCON4 = 0x00; // SA-ADC: 0=> Enables ; 0xFF=> Disables
		BLKCON6 = 0x00; // Timers 8, 9, A, E, F : 0=> Enables ; 0xFF=> Disables
		BLKCON7 = 0x00; // PWM (PWMC, PWMD, PWME, PWMF : 0=> Enables ; 0xFF=> Disables

	// Port Initialize...
		PortA_Low();	//Initialize all 3 Ports of Q111 Port A to GPIO-Low
		PortB_Low();	//Initialize all 8 Ports of Q111 Port B to GPIO-Low
		PortC_Low();	//Initialize all 4 Ports of Q111 Port C to GPIO-Low

	// UART INIT...	
		//uart_0_Init();
				
				
	// ===== Set Oscillator Rate =====
     	SetOSC(); 	//8MHz

	// ===== PWM ================================================================
	//
	//	NOTE: Possible conflict of B.0 with RX pin from UART0
	//	
	//	PinB0_PWM();		// Set up PWM peripheral (Pin on B.0)
	//===========================================================================	
		
	// ===== Comparator =====	
		//analog_comparator();	//Set up anaolg comparator peripheral


/* 	// ===== SET SPECIFIC DESIRED PINS AS INPUTS =====
		//Setup PIR Sensor Input on B.4
			//Step 1: Set Pin Direction...
				PB4DIR = 1;			// PortB Bit4 set Direction to INPUT...
			//Step 2: Set Pin I/O Type...
				PB4C1  = 0;			// PortB Bit4 set Type to HIGH-IMPEDANCE INPUT...
				PB4C0  = 0;	
			//Step 3: Set Pin Purpose...
				PB4MD1  = 0;		// PortB Bit4 set Purpose to GENERAL PURPOSE Input/Output...
				PB4MD0  = 0;

		//Setup HALL Sensor Input on B.3
			//Step 1: Set Pin Direction...
				PB3DIR = 1;			// PortB Bit3 set Direction to INPUT...
			//Step 2: Set Pin I/O Type...
				PB3C1  = 0;			// PortB Bit3 set Type to HIGH-IMPEDANCE INPUT...
				PB3C0  = 0;	
			//Step 3: Set Pin Purpose...
				PB3MD1  = 0;		// PortB Bit3 set Purpose to GENERAL PURPOSE Input/Output...
				PB3MD0  = 0;

		//Setup ACCELEROMETER X-SIGNAL Sensor Input on A.2
			//Step 1: Set Pin Direction...
				PA2DIR = 1;			// PortA Bit2 set Direction to INPUT...
			//Step 2: Set Pin I/O Type...
				PA2C1  = 0;			// PortA Bit2 set Type to HIGH-IMPEDANCE INPUT...
				PA2C0  = 0;	
			//Step 3: Set Pin Purpose...
				PA2MD1  = 0;		// PortA Bit2 set Purpose to GENERAL PURPOSE Input/Output...
				PA2MD0  = 0;
		
		//Setup ACCELEROMETER Y-SIGNAL Sensor Input on A.1
			//Step 1: Set Pin Direction...
				PA1DIR = 1;			// PortA Bit1 set Direction to INPUT...
			//Step 2: Set Pin I/O Type...
				PA1C1  = 0;			// PortA Bit1 set Type to HIGH-IMPEDANCE INPUT...
				PA1C0  = 0;	
			//Step 3: Set Pin Purpose...
				PA1MD1  = 0;		// PortA Bit1 set Purpose to GENERAL PURPOSE Input/Output...
				PA1MD0  = 0;

		//Setup ACCELEROMETER Temperature-SIGNAL Sensor Input on A.0
			//Step 1: Set Pin Direction...
				PA0DIR = 1;			// PortA Bit0 set Direction to INPUT...
			//Step 2: Set Pin I/O Type...
				PA0C1  = 0;			// PortA Bit0 set Type to HIGH-IMPEDANCE INPUT...
				PA0C0  = 0;	
			//Step 3: Set Pin Purpose...
				PA0MD1  = 0;		// PortA Bit0 set Purpose to GENERAL PURPOSE Input/Output...
				PA0MD0  = 0; */

	//================== STANDBY CONTROL REGISTER===================================
	//
	// SBYCON is a 2-bit special function register to control operating mode of MCU
	//		STP   :   HLT
	// 		BIT 1 :  BIT 0
	//  	 0         0     => Program RUN mode (initial value)
	//  	 0         1     => HALT mode
	//  	 1         0     => STOP mode
	//  	 1         1     => (Prohibited)
	// See ML610Q111/ML610Q112 User Manual - Section 4: MCU Control Function
	//	SBYCON = 0;		// Program RUN mode
	//==============================================================================

	//================== VOLTAGE LEVEL SUPERVISOR REGISTER =========================
	// 
	// The Q11x mcu's have two channels of VOLTAGE LEVEL SUPERVISORs
	// Accuracy is ±3%
	//
	// The threshold voltages of VLS0 (VDD fall) : 2.85V (Typ. )
	//								  (VDD rise) : 2.92V (Typ. )
	//
	// The threshold voltages of VLS1 (VDD fall) : 4 types selectable 3.3V/ 3.6V/ 3.9V/ 4.2V (Typ.)
	// The VLS0 can be used as the low voltage level detector reset.
	// 
	// See ML610Q111/ML610Q112 User Manual - Section 22: Voltage Level Supervisor
	//
	//==============================================================================

   	// IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
	// INTERRUPT SETUP...
		//	The ML610Q1xx mcu's have 31 hardware interrupt sources 
		//		 7 External Interrupt Sources
		//		24 Internal Interrupt Sources 
		// EXAMPLE: WDT; VLS; EXTERNAL INT Pins (6); SPI; ADC; I2C (Slave); I2C (Master);
		//			TIMERS (6); UART; Comparators (2); PWM's ((4); TBC (4)		
	
		irq_di();	// Disable Interrupts
		//irq_init();	// Initialize Interrupts (All Off and NO Requests)
			//====================================================================
			//FOR NOTES ONLY...This is all taken care of in "irq_init()"
				// INTERRUPT ENABLE REGISTERS...
				//  IE0 = VOLTAGE LEVEL SUPERVISOR Int.
				//  IE1 = EXTERNAL Ints on B3, B2, B1, B0, A2, A1, & A0
				//  IE2 = SPI, A/D, I2C Slave & I2C Master Int.
				//  IE3 = TIMERS 8 & 9 Ints.
				//  IE4 = UART & COMPARATOR Ints.
				//  IE5 = TIMERS A, B, E & F Ints.
				//  IE6 = PWMC, PWMD, PWME, PWMF & 128Hz & 32Hz TBC Ints.
				//  IE7 = 16Hz & 2Hz TBC Ints.
				//IE0 = IE1 = IE2 = IE3 = IE4 = IE5 = IE6 = IE7 = 0;
				//--------------------------------------------------------------
				// INTERRUPT REQUEST FLAG REGISTERS...
				//  IRQ0 = WDT & VLS Int Requests
				//  IRQ1 = EXTERNAL Int Requests
				//  IRQ2 = SPI, A/D, I2C Slave & I2C Master Int Requests
				//  IRQ3 = TIMERS 8 & 9 Int Requests 
				//  IRQ4 = UART & COMPARATOR Int Requests 
				//  IRQ5 = TIMERS A, B, E & F Int Requests 
				//  IRQ6 = PWMC &  128Hz & 32Hz TBC Int Requests 
				//  IRQ7 = 16Hz & 2Hz TBC Int Requests 
				//IRQ0 = IRQ1 = IRQ2 = IRQ3 = IRQ4 = IRQ5 = IRQ6 = IRQ7 = 0;
			//====================================================================

			// INTERRUPT ENABLE REGISTERS...
				IE0 = IE1 = IE2 = IE3 = IE4 = IE5 = IE6 = IE7 = 0;


			// INTERRUPT REQUEST REGISTERS...
				IRQ0 = IRQ1 = IRQ2 = IRQ3 = IRQ4 = IRQ5 = IRQ6 = IRQ7 = 0;

 			//------------- SET UP UART Interrupts Handler -------------------------------------------
				(void)irq_setHdr( (unsigned char)IRQ_NO_UA0INT, _intUart );
					EUA0 = 1; 	// EUA0 is the enable flag for the UART0 interrupt (1=ENABLED)
					QUA0 = 0;	// Request Flag for the UART_0 	INTERRUPT (1=REQUEST, 0-NO-REQUEST)
			//----------------------------------------------------------------------------------------
			
 			//------------- SET UP I2C MASTER Interrupts Handler -------------------------------------
				(void)irq_setHdr( (unsigned char)IRQ_NO_I2CMINT, _intI2c );
					EI2CM = 1; // EI2CM is the enable flag for the I2C MASTER interrupt (1=ENABLED)
					QI2CM = 0;
			//----------------------------------------------------------------------------------------
			
			//------------- SET UP ADC Interrupts Handler --------------------------------------------
				(void)irq_setHdr( (unsigned char)IRQ_NO_SADINT, _intADC );
					ESAD = 1; // ESAD is the enable flag for the ADC interrupt (1=ENABLED)
					QSAD = 0; // Request Flag for the ADC INTERRUPT (1=REQUEST, 0-NO-REQUEST)
			//----------------------------------------------------------------------------------------
			
			//------------- SET UP  xHz TBC Interrupt (Options: 128Hz, 32Hz, 16Hz, 2Hz) --------------
				(void)irq_setHdr( (unsigned char)IRQ_NO_T2HINT, TBC_ISR );  //Clear interrupt request flag
					E2H = 1;	  // Enable x Hz TBC Interrupt (1=ENABLED)
					Q2H = 0;	  // Request flag for the TIME BASE COUNTER 2Hz Interrupt
			// -----			
			//------------- TBC...Set Ratio: : 1:1 => 1_1 --------------------------------------------
				(void)tb_setHtbdiv( (unsigned char)TB_HTD_1_1 ); //Set the ratio of dividing frequency of the time base counter
			//---------------------------------------------------------------------------------------- 
			
 			//------------- SET UP TIMER 8/9 Interrupt to increment timers every ~X ms ---------------
				(void)irq_setHdr( (unsigned char)IRQ_NO_TM9INT, TMR89_ISR );  //Clear interrupt request flag
					ETM8 = 1;	  	// Enable timer 8 Interrupt (1=ENABLED
					ETM9 = 1;	  	// Enable timer 9 Interrupt (1=ENABLED)
					QTM8 = 0;		// Timer 8 IRQ request flag; 1=REQUEST
					QTM9 = 0;		// Timer 9 IRQ request flag; 1=REQUEST
					T8CS0 = 1;		// 111 => Select PLLCLK
					T8CS1 = 1;
					T8CS2 = 1;
					T9CS0 = 1;		// 111 => Select PLLCLK
					T9CS1 = 1;
					T9CS2 = 1; 
					tm_init(TM_CH_NO_89);
					tm_set89Data(8192);				//A value of 1023 should yield 125us interrupts at 8.192 MHz
					tm_set89Source(TM_CS_HTBCLK);
					tm_start89();
					T89M16 = 1;		//1 => sets 16-bit timer mode
				
					HTD3 = 1;	//High-Speed Time Base Counter Divide Register: 1111 = 9182kHz
					HTD2 = 1;
					HTD1 = 1;
					HTD0 = 1; 
			//----------------------------------------------------------------------------------------

			
 			//------------- SET UP TIMER A/B Interrupt to increment timers every ~X ms ---------------
				(void)irq_setHdr( (unsigned char)IRQ_NO_TMBINT, TMRAB_ISR );  //Clear interrupt request flag
					ETMA = 1;	  	// Enable timer 8 Interrupt (1=ENABLED
					ETMB = 1;	  	// Enable timer 9 Interrupt (1=ENABLED)
					QTMA = 0;		// timer 8 IRQ request flag; 1=REQUEST
					QTMB = 0;		// timer 9 IRQ request flag; 1=REQUEST
					TACS0 = 1;		// 111 => Select PLLCLK
					TACS1 = 1;
					TACS2 = 1;
					TBCS0 = 1;		// 111 => Select PLLCLK
					TBCS1 = 1;
					TBCS2 = 1; 
					tm_init(TM_CH_NO_AB);
					tm_setABData(8192);				//A value of 1023 should yield 125us interrupts at 8.192 MHz
					tm_setABSource(TM_CS_HTBCLK);
					tm_startAB();
					TABM16 = 1;		//1 => sets 16-bit timer mode
				
					HTD3 = 1;	//High-Speed Time Base Counter Divide Register: 1111 = 9182kHz
					HTD2 = 1;
					HTD1 = 1;
					HTD0 = 1; 
			//----------------------------------------------------------------------------------------

			
			//------------- SET UP TIMER E/F Interrupt to increment timers every ~X ms ---------------
				(void)irq_setHdr( (unsigned char)IRQ_NO_TMFINT, TMREF_ISR );  //Clear interrupt request flag
					ETME = 1;	  	// Enable timer E Interrupt (1=ENABLED
					ETMF = 1;	  	// Enable timer F Interrupt (1=ENABLED)
					QTME = 0;		// Timer E IRQ request flag; 1=REQUEST
					QTMF = 0;		// Timer F IRQ request flag; 1=REQUEST
					TECS0 = 1;		// 111 => Select PLLCLK
					TECS1 = 1;
					TECS2 = 1;
					TFCS0 = 1;		// 111 => Select PLLCLK
					TFCS1 = 1;
					TFCS2 = 1;
					tm_init(TM_CH_NO_EF);
					tm_setEFData(8192);				//A value of 1023 should yield 125us interrupts at 8.192 MHz
					tm_setEFSource(TM_CS_HTBCLK);
					tm_startEF();
					TEFM16 = 1;		//1 => sets 16-bit timer mode
				
					HTD3 = 1;	//High-Speed Time Base Counter Divide Register: 1111 = 9182kHz
					HTD2 = 1;
					HTD1 = 1;
					HTD0 = 1; 
			//----------------------------------------------------------------------------------------
			
			//------------- SET UP B.3 as an input, and prepare to use as an external interrupt ------
					PB3DIR = 1;
					PB3C1 = 0;
					PB3C0 = 0;
					PB3MD1 = 0;
					PB3MD0 = 0;
					PB3E1 = 1;
					PB3E0 = 0;		//PBnE0-1 are used to choose the Rising-Edge Mode for this interrupt
					PB3SM = 0;
			// -----
			//------------- SET UP EXTERNAL INTERRUPT on B.3 -----------------------------------------
			//Options include following pins: A.0; A.1; A.2. B.0; B.1; B.2 & B.3
			(void)irq_setHdr( (unsigned char)IRQ_NO_PB3INT, ExtInt_ISR );  //Clear interrupt request flag
					EPB3 = 0;	// 1=> Enables Interrupt
					QPB3 = 0;	// EXT IRQ request flag; 1=REQUEST	
			//----------------------------------------------------------------------------------------   
	
			
	irq_ei(); // Enable Interrupts
	// IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII  

	// ===== SET UP WATCH DOG TIMER =============================================
		WDTMOD = 0x03; 	// 0x03=overflow 8sec...
		main_clrWDT(); 	// Clear WDT   
	//===========================================================================
	
	
	// ===== UART Initialization ================================================
	//
	//	Pin PB0 of mcu => RX  
	// 	Pin PB1 of mcu => TX 
	// 
		(void)uart_init( (unsigned char)UART_CS_HSCLK,	// Generator       				
				 (unsigned short)HSCLK_KHZ,				// HSCLK frequency 				
				 &_uartSetParam );						// Parameters from Structure    
		uart_PortSet();									// Set UART Port Pins
		_flgUartFin = 0;
		uart_stop();

	//	
	//===========================================================================

	// ===== I2C Initialization =================================================
	//	(void)i2c_init(I2C_MOD_FST, (unsigned short)HSCLK_KHZ, I2C_SYN_ON);
	//	I20SYN = 1;		//Enable Clock Stretching	
	//===========================================================================



		
		
}//End Initialization
Exemple #6
0
int main(void)
{
	/* Simulate a compal loader saying "ACK" */
	int i = 0;
	for (i = 0; i < sizeof(phone_ack); i++) {
		putchar_asm(phone_ack[i]);
	}

	/* Always disable wdt (some platforms enable it on boot) */
	wdog_enable(0);

	/* Disable the bootrom mapping */
	calypso_bootrom(0);

	/* Initialize TWL3025 for power control */
	twl3025_init();

	/* Backlight */
	bl_mode_pwl(1);
	bl_level(50);

	/* Initialize UART without interrupts */
	uart_init(SERCOMM_UART_NR, 0);
	uart_baudrate(SERCOMM_UART_NR, UART_115200);

	/* Initialize HDLC subsystem */
	sercomm_init();

	/* Say hi */
	puts("\n\nOSMOCOM Loader (revision " GIT_REVISION ")\n");
	puts(hr);

	/* Identify environment */
	printf("Running on %s in environment %s\n", manifest_board,
	       manifest_environment);

	/* Initialize flash driver */
	if (flash_init(&the_flash, 0)) {
		puts("Failed to initialize flash!\n");
	} else {
		printf("Found flash of %d bytes at 0x%x with %d regions\n",
		       the_flash.f_size, the_flash.f_base,
		       the_flash.f_nregions);

		int i;
		for (i = 0; i < the_flash.f_nregions; i++) {
			printf("  Region %d of %d pages with %d bytes each.\n",
			       i,
			       the_flash.f_regions[i].fr_bnum,
			       the_flash.f_regions[i].fr_bsize);
		}

	}

	/* Set up a key handler for powering off */
	keypad_set_handler(&key_handler);

	/* Set up loader communications */
	sercomm_register_rx_cb(SC_DLCI_LOADER, &cmd_handler);

	/* Notify any running osmoload about our startup */
	loader_send_init(SC_DLCI_LOADER);

	/* Wait for events */
	while (1) {
		keypad_poll();
		uart_poll(SERCOMM_UART_NR);
	}

	/* NOT REACHED */

	twl3025_power_off();
}
Exemple #7
0
/**
 ****************************************************************************************
 * @brief  Setup the microcontroller system.
 *
 *  Initialize the system clock and pins.
 *****************************************************************************************
 */
void SystemInit(void)
{
    /*
     **************************
     * Sub module clock setting
     **************************
     */

    // Disable all peripheral clock, will be enabled in the driver initilization.
    timer_clock_off(QN_TIMER0);
    timer_clock_off(QN_TIMER1);
    timer_clock_off(QN_TIMER2);
    timer_clock_off(QN_TIMER3);
    uart_clock_off(QN_UART0);
    uart_clock_off(QN_UART1);
    spi_clock_off(QN_SPI0);
    usart_reset((uint32_t) QN_SPI1);
    spi_clock_off(QN_SPI1);
    flash_clock_off();
    gpio_clock_off();
    adc_clock_off();
    dma_clock_off();
    pwm_clock_off();
    
    // Configure sytem clock. 
    syscon_set_sysclk_src(CLK_XTAL, __XTAL);
    syscon_set_ahb_clk(__AHB_CLK);
    syscon_set_ble_clk(__BLE_CLK);
    syscon_set_apb_clk(__APB_CLK);
    syscon_set_timer_clk(__TIMER_CLK);
    syscon_set_usart_clk((uint32_t)QN_UART0, __USART_CLK);
    syscon_set_usart_clk((uint32_t)QN_UART1, __USART_CLK);  
    clk32k_enable(__32K_TYPE);
    
    /*
     **************************
     * IO configuration
     **************************
     */

    SystemIOCfg();

    /*
     **************************
     * Peripheral setting
     **************************
     */

    // GPIO initialization for led, button & test control pin.
    gpio_init(NULL);

    // LED
    led_init();

    // Test controll pin is input to check work mode
#if (defined(QN_TEST_CTRL_PIN))
    gpio_pull_set(QN_TEST_CTRL_PIN, GPIO_PULL_UP);
    gpio_set_direction_field(QN_TEST_CTRL_PIN, (uint32_t)GPIO_INPUT);
    
#if (defined(CFG_HCI_UART))
    // Initialize HCI UART port
    uart_init(QN_HCI_PORT, USARTx_CLK(0), UART_9600);
    uart_tx_enable(QN_HCI_PORT, MASK_ENABLE);
    uart_rx_enable(QN_HCI_PORT, MASK_ENABLE);
#elif (defined(CFG_HCI_SPI))
    // Initialize HCI SPI port
    spi_init(QN_HCI_PORT, SPI_BITRATE(1000000), SPI_8BIT, SPI_SLAVE_MOD);
    gpio_set_direction_field(CFG_HCI_SPI_WR_CTRL_PIN, (uint32_t)GPIO_OUTPUT);
    gpio_write_pin(CFG_HCI_SPI_WR_CTRL_PIN, GPIO_HIGH);
#endif
#endif

#if (QN_DBG_PRINT)
    uart_init(QN_DEBUG_UART, USARTx_CLK(0), UART_9600);
    uart_tx_enable(QN_DEBUG_UART, MASK_ENABLE);
    uart_rx_enable(QN_DEBUG_UART, MASK_ENABLE);
#endif
}
Exemple #8
0
void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx)
{
	static const uint16_t spd_addr [] = {
		(0xa<<3)|0, (0xa<<3)|2, 0, 0,
		(0xa<<3)|1, (0xa<<3)|3, 0, 0,
#if CONFIG_MAX_PHYSICAL_CPUS > 1
		(0xa<<3)|4, (0xa<<3)|6, 0, 0,
		(0xa<<3)|5, (0xa<<3)|7, 0, 0,
#endif
	};

	int needs_reset;
	unsigned bsp_apicid = 0;

	struct mem_controller ctrl[8];
	unsigned nodes;

	if (!cpu_init_detectedx && boot_cpu()) {
		/* Nothing special needs to be done to find bus 0 */
		/* Allow the HT devices to be found */

		enumerate_ht_chain();

		sio_setup();

		/* Setup the ck804 */
		ck804_enable_rom();
	}

	if (bist == 0) {
		bsp_apicid = init_cpus(cpu_init_detectedx);
	}

//	post_code(0x32);

 	w83627hf_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
	uart_init();
	console_init();

	/* Halt if there was a built in self test failure */
	report_bist_failure(bist);

	setup_s2891_resource_map();
#if 0
	dump_pci_device(PCI_DEV(0, 0x18, 0));
	dump_pci_device(PCI_DEV(0, 0x19, 0));
#endif

	needs_reset = setup_coherent_ht_domain();

	wait_all_core0_started();
#if CONFIG_LOGICAL_CPUS==1
	// It is said that we should start core1 after all core0 launched
	start_other_cores();
	wait_all_other_cores_started(bsp_apicid);
#endif

	needs_reset |= ht_setup_chains_x();

	needs_reset |= ck804_early_setup_x();

	if (needs_reset) {
		printk(BIOS_INFO, "ht reset -\n");
		soft_reset();
	}

	allow_all_aps_stop(bsp_apicid);

	nodes = get_nodes();
	//It's the time to set ctrl now;
	fill_mem_ctrl(nodes, ctrl, spd_addr);

	enable_smbus();
#if 0
	dump_spd_registers(&cpu[0]);
#endif
#if 0
	dump_smbus_registers();
#endif

	memreset_setup();
	sdram_initialize(nodes, ctrl);

#if 0
	print_pci_devices();
#endif

#if 0
	dump_pci_devices();
#endif

	post_cache_as_ram();
}
Exemple #9
0
int main( int argc, char *argv[] ) {
	char			*uart_device;
	uint8_t			buf[BUF_SIZE+1];
	int				nread;
	fd_set			fds;
	fsm_demo		fsm_state = FSM_INIT;

	srand( time(NULL) );

	if( argc==2 )
		uart_device = argv[1];
	else
		uart_device = (char*) DEFAULT_UART_DEVICE;

	// open uart device
	uart_fd = open( uart_device, O_RDWR | O_NOCTTY );
	if( uart_fd<0 ) {
		perror( uart_device );
		exit( -1 );
	}
	uart_init( uart_fd );

	// register clean up callback
	signal( SIGINT, ctrl_break );
	stdin_nonblock();
	atexit( restore );

	// main loop
	while(1) {
		int	retval;

		switch( fsm_state ) {
			case FSM_INIT: {
				tcflush( uart_fd, TCIOFLUSH );
				serial_send_command( uart_fd, &cmd_stop_data_streaming, sizeof(cmd_stop_data_streaming) );
				serial_send_command( uart_fd, &cmd_stop_data_streaming, sizeof(cmd_stop_data_streaming) );
				serial_send_command( uart_fd, &cmd_motor_stop_hori, sizeof(cmd_motor_stop_t) );
				serial_send_command( uart_fd, &cmd_motor_stop_vert, sizeof(cmd_motor_stop_t) );
				fsm_state = FSM_FLUSH;
				continue;
			}
			case FSM_FLUSH: {
				int nbytes;
				usleep(10000);
				ioctl( uart_fd, FIONREAD, &nbytes );
				if( !nbytes ) {
					fsm_state = FSM_PING;
					continue;
				} else
					break;
			}
			case FSM_PING:
				printf( "ping...\n" );
				serial_send_command( uart_fd, &cmd_ping, sizeof(cmd_ping) );
				break;
			case FSM_CHECK_PRESENTATION:
				printf( "check presentation string...\n" );
				serial_send_command( uart_fd, &cmd_read_pres_string, sizeof(cmd_read_pres_string) );
				break;
			case FSM_CHECK_MODE:
				printf( "check mode...\n" );
				serial_send_command( uart_fd, &cmd_check_mode_support, sizeof(cmd_check_mode_support) );
				break;
			case FSM_INIT_SENSORS:
				printf( "init sensors...\n" );
				if( SENSORS_ENABLED ) {
					if( SENSORS_ENABLED & (SENSOR_ACCELEROMETER|SENSOR_GYROSCOPE) )
						serial_send_command( uart_fd, &cmd_lsm6ds0_init, sizeof(cmd_short_t) );
					if( SENSORS_ENABLED & SENSOR_MAGNETIC )
						serial_send_command( uart_fd, &cmd_lis3mdl_init, sizeof(cmd_short_t) );
					usleep(1000);
					break;
				}
			case FSM_START_DATA_STREAMING:
				printf( "start data streaming...\n" );
				serial_send_command( uart_fd, &cmd_start_data_streaming, sizeof(cmd_start_data_streaming) );
				break;
			case FSM_INTERACTIVE:
				printf( "> " );
				fflush( stdout );
				break;
			case FSM_IDLE:
				break;
			case FSM_RUNIN:
				break;
			default:
				fprintf( stderr, "Unknown FSM state %d\n", fsm_state );
				exit(-2);
		}

		FD_ZERO( &fds );
		FD_SET( uart_fd, &fds );
		FD_SET( STDIN_FILENO, &fds );

		retval = select( uart_fd+1, &fds, NULL, NULL, NULL );
		if( retval<0 ) {
			perror( "select" );
		} else if( retval==0 ) {
			fprintf( stderr, "select return 0\n" );
			exit(-1);
		}

		// handle uart event
		if( FD_ISSET( uart_fd, &fds ) ) {
			nread = serial_read_message( uart_fd, buf, BUF_SIZE );
			if( nread>0 ) {
				dump( stdout, buf, nread );
				if( fsm_state==FSM_INIT || fsm_state==FSM_FLUSH ) {
					// do nothing
				} else if( buf[0]==SENDER_UART && buf[1]==DEV_ADDR ) {
					switch( buf[2] ) {
						case CMD_PING|CMD_REPLY_ADD:
							fsm_state = FSM_CHECK_PRESENTATION;
							break;
						case CMD_READ_PRES_STRING|CMD_REPLY_ADD:
							if( strncmp( (char*)buf+3, PRESENTATION_STRING, sizeof(PRESENTATION_STRING) )==0 ) {
								printf( "prenstation string not match\n" );
								exit( -1 );
							}
							fsm_state = FSM_CHECK_MODE;
							break;
						case CMD_CHECK_MODE_SUPPORT|CMD_REPLY_ADD:
							fsm_state = FSM_INIT_SENSORS;
							break;
						case CMD_LIS3MDL_INIT|CMD_REPLY_ADD:
						case CMD_LSM6DS0_INIT|CMD_REPLY_ADD:
							fsm_state = FSM_START_DATA_STREAMING;
							break;
						case CMD_START_DATA_STREAMING:
							if( SENSORS_ENABLED& SENSOR_ACCELEROMETER )
								printf( "accelerometer: x=%2d, y=%2d, z=%2d\n", deserialize(buf+15,4), deserialize(buf+19,4), deserialize(buf+23,4) );
							if( SENSORS_ENABLED & SENSOR_GYROSCOPE )
								printf( "gyroscope: x=%2d, y=%2d, z=%2d\n", deserialize(buf+27,4), deserialize(buf+31,4), deserialize(buf+35,4) );
							if( SENSORS_ENABLED & SENSOR_MAGNETIC )
								printf( "magnetic: x=%2d, y=%2d, z=%2d\n", deserialize(buf+39,4), deserialize(buf+43,4), deserialize(buf+47,4) );
							break;
						case CMD_START_DATA_STREAMING|CMD_REPLY_ADD:
						case CMD_MOTOR_TEST|CMD_REPLY_ADD:
							fsm_state = FSM_INTERACTIVE;
							break;
						case CMD_MOTOR_DRIVE|CMD_REPLY_ADD:
							printf( "motor drive %s\n", buf[3]==0 ? "failed" : "successful" );
							if( fsm_state!=FSM_RUNIN )
								fsm_state = FSM_INTERACTIVE;
							break;
						case CMD_MOTOR_GET_STATE|CMD_REPLY_ADD:
							printf( "steps left = %d\n", deserialize( buf+3, 2 ) );
							fsm_state = FSM_INTERACTIVE;
							break;
						case CMD_MOTOR_STOP|CMD_REPLY_ADD:
						case CMD_MOTOR_STOP: {
							uint16_t real_steps = deserialize( buf+4, 2 );
							if( real_steps )
								printf( "receive motor stop async event, id=%d, real_steps = %d\n", buf[3], real_steps );
							if( fsm_state==FSM_RUNIN ) {
								cmd_motor_drive_t	cmd;
								motor_t				*m = buf[3]==ID_HORI ? hori : vert;
								serial_send_command( uart_fd, motor_gen_cmd_motor_drive_rpm( m, &cmd, rand()%2 ? CW : CCW, rand()%RUNIN_MAX_DEG+1, 1, 12.5, 100 ), sizeof(cmd_motor_drive_t) );
							} else
								fsm_state = FSM_INTERACTIVE;
							break;
						}
						case CMD_MOTOR_REPORT_SENSOR|CMD_REPLY_ADD:
							printf( "receive motor sensor async event, id = %d, sensor = %d, steps = %d\n", buf[3], buf[4], deserialize( buf+5, 2 ) );
							fsm_state = FSM_INTERACTIVE;
							break;
						default:
							printf( "unknown response cmd %02x\n", buf[2] );
							break;
					}
				}
			} else if( nread==-1 ) {
				// read()<0 error
			} else if( nread==-2 ) {
				// USB disconnect
				exit(-1);
			} else if( nread==-3 ) {
				// resync or checksum error
			}
		}

		// handle keystoke event
		if( FD_ISSET( STDIN_FILENO, &fds ) ) {
			cmd_motor_drive_t	cmd;
#if 0
			int	ch = tolower( getchar() );
#else
			uint8_t ch;
			
			if( !read( STDIN_FILENO, &ch, sizeof(uint8_t) ) )
				continue;
			ch = tolower( ch );
#endif
			if( !isalnum(ch) )
				continue;

			putchar( '\n' );
			if( ch=='1' ) {
				serial_send_command( uart_fd, motor_gen_cmd_motor_drive_rpm( hori, &cmd, CW, 90, 1, 12.5, 100 ), sizeof(cmd_motor_drive_t) );
			} else if( ch=='2' ) {
				serial_send_command( uart_fd, motor_gen_cmd_motor_drive_rpm( hori, &cmd, CCW, 90, 2, 15, 100 ), sizeof(cmd_motor_drive_t) );
			} else if( ch=='3' ) {
				serial_send_command( uart_fd, motor_gen_cmd_motor_drive_rpm( hori, &cmd, CW, 90, 3, 20, 100 ), sizeof(cmd_motor_drive_t) );
			} else if( ch=='4' ) {
				serial_send_command( uart_fd, motor_gen_cmd_motor_drive_rpm( hori, &cmd, CCW, 90, 4, 25, 100 ), sizeof(cmd_motor_drive_t) );
			} else if( ch=='a' ) {
				serial_send_command( uart_fd, motor_gen_cmd_motor_drive_rpm( vert, &cmd, CW, 30, 1, 12.5/2, 100 ), sizeof(cmd_motor_drive_t) );
			} else if( ch=='b' ) {
				serial_send_command( uart_fd, motor_gen_cmd_motor_drive_rpm( vert, &cmd, CCW, 30, 2, 15/2, 100 ), sizeof(cmd_motor_drive_t) );
			} else if( ch=='c' ) {
				serial_send_command( uart_fd, motor_gen_cmd_motor_drive_rpm( vert, &cmd, CW, 30, 3, 20/2, 100 ), sizeof(cmd_motor_drive_t) );
			} else if( ch=='d' ) {
				serial_send_command( uart_fd, motor_gen_cmd_motor_drive_rpm( vert, &cmd, CCW, 30, 4, 25/2, 100 ), sizeof(cmd_motor_drive_t) );
			} else if( ch=='x' ) {
				serial_send_command( uart_fd, motor_gen_cmd_motor_drive_rpm( hori, &cmd, CW, 90, 1, 1, 0 ), sizeof(cmd_motor_drive_t) );
			} else if( ch=='z' ) {
				serial_send_command( uart_fd, motor_gen_cmd_motor_drive( hori, &cmd, CCW, motor_deg2step(hori,90), 1000, MIN_TEST_PERIOD, 4 ), sizeof(cmd_motor_drive_t) );
			} else if( ch=='s' ) {
				serial_send_command( uart_fd, &cmd_motor_stop_hori, sizeof(cmd_motor_stop_t) );
				serial_send_command( uart_fd, &cmd_motor_stop_vert, sizeof(cmd_motor_stop_t) );
			} else if( ch=='r' ) {
				serial_send_command( uart_fd, motor_gen_cmd_motor_drive_rpm( hori, &cmd, rand()%2 ? CW : CCW, rand()%RUNIN_MAX_DEG+1, 1, 12.5, 100 ), sizeof(cmd_motor_drive_t) );
				serial_send_command( uart_fd, motor_gen_cmd_motor_drive_rpm( vert, &cmd, rand()%2 ? CW : CCW, rand()%RUNIN_MAX_DEG+1, 1, 12.5, 100 ), sizeof(cmd_motor_drive_t) );
				fsm_state = FSM_RUNIN;
				continue;
			} else if( ch=='t' ) {
				cmd_motor_test_t	cmd;
				cmd = (cmd_motor_test_t) { DEV_ADDR, SENDER_UART, CMD_MOTOR_TEST, ID_HORI, 0, 0 };
				serial_send_command( uart_fd, &cmd, sizeof(cmd_motor_test_t) );
				cmd = (cmd_motor_test_t) { DEV_ADDR, SENDER_UART, CMD_MOTOR_TEST, ID_HORI, 0, 1 };
				serial_send_command( uart_fd, &cmd, sizeof(cmd_motor_test_t) );
			} else if( ch=='g' ) {
				cmd_motor_get_state_t	cmd;
				cmd = (cmd_motor_get_state_t) { DEV_ADDR, SENDER_UART, CMD_MOTOR_GET_STATE, ID_HORI };
				serial_send_command( uart_fd, &cmd, sizeof(cmd_motor_get_state_t) );
			} else if( ch=='q' ) {
				break;
			} else {
				printf( "unknown command\n" );
				fsm_state = FSM_INTERACTIVE;
				continue;
			}
			fsm_state = FSM_IDLE;
		}
	}
	
	return 0;
}
Exemple #10
0
int main() {

	// LEDs as outputs
	DDRC |= (1 << IR_LED_PIN);
	DDRC |= (1 << IR_INDICATOR_LED_PIN);
	DDRC |= (1 << TIMER_INDICATOR_LED_PIN);

	//enable internal pullup resistors
	PORTC |= (1 << MODE_SWITCH_PIN);
	PORTC |= (1 << POTENTIOMETER_PIN);
	PORTD |= (1 << TRIGGER_PIN);
	
	// Pin change interrupt control register - enables interrupt vectors
	// Bit 2 = enable PC vector 2 (PCINT23..16)
	// Bit 1 = enable PC vector 1 (PCINT14..8)
	// Bit 0 = enable PC vector 0 (PCINT7..0)
	PCICR |= (1 << PCIE2);

	// Pin change mask registers decide which pins are enabled as triggers
	PCMSK2 |= (1 << PCINT18);

	adc_init();

	//start up the serial port
	uart_init();
	FILE uart_stream = FDEV_SETUP_STREAM(uart_putchar, uart_getchar, _FDEV_SETUP_RW);
	stdin = stdout = &uart_stream;

	printf_P(PSTR("STARTING\r\n"));
	
	//Check mode switch
	if ((PINC & (1 << MODE_SWITCH_PIN)) == 0) {
		mode = REMOTE;
		blink_timer_led_times(1U);
	} else {
		mode = INTERVALOMETER;
		blink_timer_led_times(2U);
		SetupTimer2();
		timer_interval_ms = get_interval_ms();
	}
	delay_ms(500U);
	
	printf_P(PSTR("Mode %u ms\r\n"), mode);
	
	while (1) {
		if (mode == INTERVALOMETER) {
		
			set_sleep_mode(SLEEP_MODE_PWR_SAVE);		
			cli();
			sleep_enable();
			sei();
			sleep_cpu();
			sleep_disable();
			sei();

			if (the_time_ms >= timer_interval_ms) {
				the_time_ms = 0UL;
				remainder_counter = 0UL;
				click();
				count_down_ms = 5000UL;
				printf_P(PSTR("Waiting for: %lu ms\r\n"), timer_interval_ms);
			} else {		
				//while waiting for next intervalometer click, flash a green LED to show it is still on
				if (the_time_ms > 0UL && (count_down_ms <= 0L)) {		//turn on every 5 seconds
					count_down_ms = 5000UL;
					blink_timer_led_times(1U);
				}
			}
		}
		else {
			set_sleep_mode(SLEEP_MODE_PWR_DOWN);
			cli();
			sleep_enable();
			sei();
			sleep_cpu();
			sleep_disable();
			sei();
		}
	}
	
	return 0;
}
/******************************************************************************
 * FunctionName : user_init
 * Description  : entry of user application, init user function here
 * Parameters   : none
 * Returns      : none
*******************************************************************************/
void user_init(void)
{
    os_delay_us(1000*1000);
    uart_init (BIT_RATE_115200, BIT_RATE_115200, USER_TASK_PRIO_0, 0);
    os_delay_us(100*1000);

    os_printf("Interactive Cube starting..\n");

    config_init();

    platform_i2c_setup(i2c_endpoint_id, 1, 2, PLATFORM_I2C_SPEED_SLOW);
    display_init();

    NODE_DBG("SDK version: %s\n", system_get_sdk_version());
    system_print_meminfo();

    os_printf("Heap size: %d.\n", system_get_free_heap_size());

#ifndef NODE_DEBUG
    system_set_os_print(1);
#endif

    int b;
    for(b=0; b<4; b++) {
        display_set_pixel(0, 1);
        display_update_inner();

        os_delay_us(500*1000);
        display_update_inner();

        display_set_pixel(0, 0);
        display_update_inner();

        os_delay_us(500*1000);
        display_update_inner();
    }

    if (display_is_key_down(0)) {
        // enter setup mode, show as blinking...!
        configui_init();
        return;
    }

    display_set_pixel(0, 1);
    display_set_pixel(1, 1);
    display_set_pixel(2, 1);
    display_update_inner();

    // uart_init(BIT_RATE_9600,0);
    os_delay_us(100*1000);

    os_delay_us(1000*1000);

    display_anim();
    //  os_delay_us(500*1000);

    NODE_DBG("Hello Wurst.\n");
    // os_delay_us(500*1000);

    // Set up I2C
    // Wire.begin(D1, D2); // sda, scl

    display_set_pixel(0, 0);
    display_set_pixel(1, 0);
    display_set_pixel(2, 0);
    display_set_pixel(3, 0);
    display_update();

    comm_init();
    orient_init();

    // system_init_done_cb(nodemcu_init);

    system_os_task(loop, user_procTaskPrio,user_procTaskQueue, user_procTaskQueueLen);
    system_os_post(user_procTaskPrio, 0, 0);

    NODE_DBG("End of user_init.\n");
}
Exemple #12
0
void welcome(void)
{
    uart_baudrate();
    uart_init();
    UARTSTR("c51drv\n");
}
Exemple #13
0
/*
 * Do all the startup-time peripheral initializations.
 */
static void
ioinit(void)
{
  uart_init();
  lcd_init();
}
Exemple #14
0
void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx)
{
	u32 val;

	post_code(0x30);
	agesawrapper_amdinitmmio();
	post_code(0x31);

	/* Halt if there was a built in self test failure */
	post_code(0x33);
	report_bist_failure(bist);

	sb7xx_51xx_enable_wideio(0, 0x1600); /* though UARTs are on the NUVOTON BMC */
	w83627dhg_set_clksel_48(DUMMY_DEV);
	w83627dhg_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
	sb7xx_51xx_disable_wideio(0);
	post_code(0x34);

	uart_init();
	post_code(0x35);
	console_init();

	val = cpuid_eax(1);
	printk(BIOS_DEBUG, "BSP Family_Model: %08x \n", val);
	printk(BIOS_DEBUG, "cpu_init_detectedx = %08lx \n", cpu_init_detectedx);

	post_code(0x37);
	val = agesawrapper_amdinitreset();
	if (val) {
		printk(BIOS_DEBUG, "agesawrapper_amdinitreset failed: %x \n", val);
	} else {
		printk(BIOS_DEBUG, "agesawrapper_amdinitreset passed\n");
	}

	if (!cpu_init_detectedx && boot_cpu()) {
		post_code(0x38);
		/*
		 * SR5650/5670/5690 RD890 chipset, read pci config space hang at POR,
		 * Disable all Pcie Bridges to work around It.
		 */
		sr56x0_rd890_disable_pcie_bridge();
		post_code(0x39);
		nb_Poweron_Init();
		post_code(0x3A);
		sb_Poweron_Init();
	}
	post_code(0x3B);
	val = agesawrapper_amdinitearly();
	if(val) {
		printk(BIOS_DEBUG, "agesawrapper_amdinitearly failed: %x \n", val);
	} else {
		printk(BIOS_DEBUG, "agesawrapper_amdinitearly passed\n");
	}

	post_code(0x3C);
	/* W83627DHG pin89,90 function select is RSTOUT3#, RSTOUT2# by default.
	 * In order to access W83795G/ADG HWM using I2C protocol,
	 * we select function to SDA, SCL function (or GP33, GP32 function).
	 */
	w83627dhg_enable_i2c(PNP_DEV(0x2E, W83627DHG_SPI));

	nb_Ht_Init();
	post_code(0x3D);
	/* Reset for HT, FIDVID, PLL and ucode patch(errata) changes to take affect. */
	if (!warm_reset_detect(0)) {
		print_info("...WARM RESET...\n\n\n");
		distinguish_cpu_resets(0);
		soft_reset();
		die("After soft_reset_x - shouldn't see this message!!!\n");
	}

	post_code(0x40);
	val = agesawrapper_amdinitpost();
	if (val) {
		printk(BIOS_DEBUG, "agesawrapper_amdinitpost failed: %x \n", val);
	} else {
		printk(BIOS_DEBUG, "agesawrapper_amdinitpost passed\n");
	}

	post_code(0x41);
	val = agesawrapper_amdinitenv();
	if(val) {
		printk(BIOS_DEBUG, "agesawrapper_amdinitenv failed: %x \n", val);
	}
	printk(BIOS_DEBUG, "agesawrapper_amdinitenv passed\n");

	post_code(0x42);

	post_code(0x50);
	print_debug("Disabling cache as ram ");
	disable_cache_as_ram();
	print_debug("done\n");

	post_code(0x51);
	setup_i8259 ();
	setup_i8254 ();
	copy_and_run();

	/* We will not return,  Should never see this message and post code. */
	print_debug("should not be here -\n");
	post_code(0x54);
}
Exemple #15
0
void user_init(unsigned char init)
{
   unsigned char i;
   xdata char str[64];

   SFRPAGE = ADC0_PAGE;
   AMX0CF = 0x00;               // select single ended analog inputs
   ADC0CF = 0xE0;               // 16 system clocks, gain 1
   ADC0CN = 0x80;               // enable ADC 
   REF0CN = 0x00;               // use external voltage reference

   SFRPAGE = LEGACY_PAGE;
   REF0CN = 0x02;               // select external voltage reference

   SFRPAGE = DAC0_PAGE;
   DAC0CN = 0x80;               // enable DAC0
   SFRPAGE = DAC1_PAGE;
   DAC1CN = 0x80;               // enable DAC1

   /* open drain(*) /push-pull: 
      P0.0 TX1      P1.0 TP6          P2.0 LED1         P3.0 RELAIS0
      P0.1*RX1      P1.1 BACKLIGHT    P2.1 LCD_E        P3.1 RELAIS1
      P0.2 TX2      P1.2 TP5          P2.2 LCD_RW       P3.2 RELAIS2
      P0.3*RX2      P1.3 TP7          P2.3 LCD_RS       P3.3 RELAIS3
                                                                      
      P0.4 EN1      P1.4 WATCHDOG     P2.4 LCD_DB4      P3.4 DOUT0
      P0.5 EN2      P1.5 SRSTROBE     P2.5 LCD_DB5      P3.5 DOUT1
      P0.6 LED2     P1.6*SRIN         P2.6 LCD_DB6      P3.6 DOUT2
      P0.7 BUZZER   P1.7 SRCLK        P2.7 LCD_DB7      P3.7 DOUT3
    */
   SFRPAGE = CONFIG_PAGE;
   P0MDOUT = 0xF5;
   P1MDOUT = 0xBF;
   P2MDOUT = 0xFF;
   P3MDOUT = 0xFF;

   /* initial EEPROM value */
   if (init) {

      user_data.station_on = 0;
      user_data.valve_locked = 0;
      user_data.vacuum_ok = 0;
      user_data.man_mode = 0;

      for (i=0 ; i<4 ; i++)
         user_data.relais[i] = 0;

      for (i=0 ; i<8 ; i++) {
         user_data.aofs[i] = 0;
         user_data.again[i] = 1;
      }

      user_data.evac_timeout = 60; // 1h to pump recipient
      user_data.fp_cycle = 20;     // run fore pump for min. 20 sec.
      user_data.vv_max = 4;        // start fore pump at 4 mbar     
      user_data.vv_min = 0.4;      // stop fore pump at 0.4 mbar
      user_data.hv_thresh = 1E-3;  // vacuum ok if < 10^-3 mbar
   }

   /* write digital outputs */
   for (i=0 ; i<20 ; i++)
      user_write(i);

   /* initialize UART1 for TC600 */
   uart_init(1, BD_9600);

   /* turn on turbo pump motor (not pump station) */
   tc600_write(23, 6, 111111);

   /* get parameter 315 (TMP finspd) */
   tc600_read(315, str);
   user_data.final_speed = atoi(str);

   /* display startup screen */
   lcd_goto(0, 0);
   for (i=0 ; i<7-strlen(sys_info.node_name)/2 ; i++)
      puts(" ");
   puts("** ");
   puts(sys_info.node_name);
   puts(" **");
   lcd_goto(0, 1);
   printf("  Address:   %04X", sys_info.node_addr);
   lcd_goto(0, 2);
   strcpy(str, svn_revision + 21);
   *strchr(str, ' ') = 0;
   printf("  Revision:  %s", str);

   user_data.error = 0;
}
Exemple #16
0
/**
 * \brief Main routine for the cc2538dk platform
 */
int
main(void)
{
  nvic_init();
  ioc_init();
  sys_ctrl_init();
  clock_init();
  lpm_init();
  rtimer_init();
  gpio_init();

  leds_init();
  fade(LEDS_YELLOW);

  process_init();

  watchdog_init();
  button_sensor_init();

  /*
   * Character I/O Initialisation.
   * When the UART receives a character it will call serial_line_input_byte to
   * notify the core. The same applies for the USB driver.
   *
   * If slip-arch is also linked in afterwards (e.g. if we are a border router)
   * it will overwrite one of the two peripheral input callbacks. Characters
   * received over the relevant peripheral will be handled by
   * slip_input_byte instead
   */
#if UART_CONF_ENABLE
  uart_init(0);
  uart_init(1);
  uart_set_input(SERIAL_LINE_CONF_UART, serial_line_input_byte);
#endif

#if USB_SERIAL_CONF_ENABLE
  usb_serial_init();
  usb_serial_set_input(serial_line_input_byte);
#endif

  serial_line_init();

  INTERRUPTS_ENABLE();
  fade(LEDS_GREEN);

  PUTS(CONTIKI_VERSION_STRING);
  PUTS(BOARD_STRING);

  PRINTF(" Net: ");
  PRINTF("%s\n", NETSTACK_NETWORK.name);
  PRINTF(" MAC: ");
  PRINTF("%s\n", NETSTACK_MAC.name);
  PRINTF(" RDC: ");
  PRINTF("%s\n", NETSTACK_RDC.name);

  /* Initialise the H/W RNG engine. */
  random_init(0);

  udma_init();

  process_start(&etimer_process, NULL);
  ctimer_init();

  set_rf_params();
  netstack_init();

#if NETSTACK_CONF_WITH_IPV6
  memcpy(&uip_lladdr.addr, &linkaddr_node_addr, sizeof(uip_lladdr.addr));
  queuebuf_init();
  process_start(&tcpip_process, NULL);
#endif /* NETSTACK_CONF_WITH_IPV6 */

  process_start(&sensors_process, NULL);

  energest_init();
  ENERGEST_ON(ENERGEST_TYPE_CPU);

  autostart_start(autostart_processes);

  watchdog_start();
  fade(LEDS_ORANGE);

  while(1) {
    uint8_t r;
    do {
      /* Reset watchdog and handle polls and events */
      watchdog_periodic();

      r = process_run();
    } while(r > 0);

    /* We have serviced all pending events. Enter a Low-Power mode. */
    lpm_enter();
  }
}
Exemple #17
0
// initialize the custom stuff that goes beyond esp-link
void user_init()
{
	// Initialize the GPIO subsystem.
	gpio_init();

	/* ====================================== */
	/* UART                                   */
	/* ====================================== */

	// Initialize UART0 and UART1
	/* NOTE: UART1 and I2S share same GPIO. Cannot use simultaneously. */
	uart_init( BIT_RATE_115200, BIT_RATE_115200 );

//	uart0_sendStr( "\nUART0 - USED TO PROGRAM THE MODULE\n" );

	os_printf("\n===================\nUART1 - DEBUG OUPUT\n===================\n");

	/* NOTE: PWM CANNOT BE USED SIMULTANEOUSLY WITH HW TIMER */
#if 0
	/* ====================================== */
	/* PWM                                    */
	/* ====================================== */

    uint32  pwm_period = 1000;
	uint32 pwm_duty[PWM_CHANNEL] = {0};


    uint32 io_info[][3] = {   {PWM_0_OUT_IO_MUX,PWM_0_OUT_IO_FUNC,PWM_0_OUT_IO_NUM},
    		                  {PWM_1_OUT_IO_MUX,PWM_1_OUT_IO_FUNC,PWM_1_OUT_IO_NUM},
    		              };

	/* PIN FUNCTION INIT FOR PWM OUTPUT */
	pwm_init(pwm_period, pwm_duty, PWM_CHANNEL, io_info);

	/* set pwm_duty cycle */
	pwm_set_duty (14185, 0);
	pwm_set_duty (22222, 1); // todo: explain why 22222 is the highest possible value

	/* start PWM */
	pwm_start(); // NOTE: PWM causes spikes in other GPIOs
#endif


	/* ====================================== */
	/* GPIO INTERRPUT                         */
	/* ====================================== */

	/* Set GPIO12 in GPIO mode */
	PIN_FUNC_SELECT( PERIPHS_IO_MUX_MTDI_U, FUNC_GPIO12 );

	/* Set GPIO12 as input */
	GPIO_DIS_OUTPUT( GPIO_ID_PIN(12) );

	/* Disable all GPIO interrupts */
	ETS_GPIO_INTR_DISABLE();

	/* Set a GPIO callback function */
	ETS_GPIO_INTR_ATTACH( gpioCallback, NULL );

	/* Configure the type of edge */
	gpio_pin_intr_state_set( GPIO_ID_PIN(12), GPIO_PIN_INTR_ANYEDGE );

	ETS_GPIO_INTR_ENABLE();


	/* ====================================== */
	/* SOFTWARE TIMER                         */
	/* ====================================== */

	// Set GPIO0 to output mode
	PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0);

	//Set GPIO0 low
	gpio_output_set(0, RELAY_PIN, RELAY_PIN, 0);

	/* disarm timer */
	os_timer_disarm((ETSTimer*)&some_timer);

	/* set callback */
	os_timer_setfn((ETSTimer*)&some_timer, (os_timer_func_t *) softwareTimerCallback, NULL);

	/* arm the timer -> os_timer_arm(<pointer>, <period in ms>, <fire periodically>) */
	os_timer_arm((ETSTimer*)&some_timer, 10, 1);

	/* ====================================== */
	/* OS TASK                                */
	/* ====================================== */

	/* setup OS task */
//	system_os_task(user_procTask, user_procTaskPrio, user_procTaskQueue, user_procTaskQueueLen);

	/* send a message to OS task (fire task) */
//	system_os_post(user_procTaskPrio, 0, 0 );


	/* ====================================== */
	/* HARDWARE TIMER                         */
	/* ====================================== */

	/* The hardware timer is used to indicate when a complete IR message frame should have
	 * arrived in order to process the received data and calculate the IR command.
	 *
	 * It is configured in "one-shot" mode. It is started when the beginning of an
	 * IR message frame is detected and stopped after the complete message frame has been read.
	 * This means that the duration of the HW timer should be longer than the duration of
	 * the longest message frame. In the NEC IR tranmission protocol all message frames have
	 * a duration of approximately 67.5ms.
	 */

	/* load the HW TIMER */
	uint32 ticks = usToTicks(70000); // 70ms
	RTC_REG_WRITE(FRC1_LOAD_ADDRESS, ticks);

	/* register callback function */
	ETS_FRC_TIMER1_INTR_ATTACH( hwTimerCallback, NULL );

	/* enable interrupts */
	TM1_EDGE_INT_ENABLE();
	ETS_FRC1_INTR_ENABLE();

	/* don't start timer yet */
	/* the timer is started inside the GPIO INT callback */


	/* ====================================== */
	/* UDP SERVER                         	  */
	/* ====================================== */

	/* usage:	echo <data> | nc -wl -u <ip address> <port>
	 * example: echo "foo" | nc -w1 -u 192.168.1.187 7777 */

	/* allocate space for server */
	pUdpServer = (struct espconn *) os_zalloc(sizeof(struct espconn));

	/* clear allocated memory */
	ets_memset(pUdpServer, 0, sizeof(struct espconn));

	/* create the server */
	espconn_create(pUdpServer);

	/* set the type of server */
	pUdpServer->type = ESPCONN_UDP;

	/* allocate memory for UDP settings */
	pUdpServer->proto.udp = (esp_udp *) os_zalloc(sizeof(esp_udp));

	/* set the port that the server will be listening to */
	pUdpServer->proto.udp->local_port = 7777;

	/* register the callback */
	espconn_regist_recvcb(pUdpServer, udpServerRxCb);

	/* start listening */
	if (espconn_create(pUdpServer))
	{
		while (1) { os_printf("Error creating a UDP server\n"); }
	}


	/* ====================================== */
	/* WIFI                         	  	  */
	/* ====================================== */

	wifi_set_opmode(STATION_MODE);

	wifi_station_get_config_default(&stconf);

//	os_strncpy((char*) stconf.ssid, "TP-LINK_2.4GHz_FC2E51", 32);
//	os_strncpy((char*) stconf.password, "tonytony", 64);

	os_strncpy((char*) stconf.ssid, "WLAN-PUB", 32);
	os_strncpy((char*) stconf.password, "", 64);

//	os_strncpy((char*) stconf.ssid, "MAD air", 32);
//	os_strncpy((char*) stconf.password, "glioninlog", 64);

	stconf.bssid_set = 0;
	wifi_station_set_config(&stconf);

//	/* ====================================== */
//	/* WS2812 LED STRIP                	  	  */
//	/* ====================================== */
//
//	/* NOTE: UART1 and I2S share same GPIO. Cannot use simultaneously. */
//	ws2812_init();
//
//	/*						G		R		B			*/
//	uint8_t ledout[] = 	{
//							0xff,	0x00,	0x00, 		//4th
////							0xff,	0x00,	0x00,		//3rd
////							0x00,	0xff,	0x00,		//2nd
////							0x00,	0x00,	0xff, 		//1st
//						};
//
//#if 0
//		os_printf("\r\nB R G: %x %x %x\r\n", ledout[0], ledout[1],ledout[2]);
//#endif
//
//	ws2812_push( ledout, sizeof( ledout ) );

	/* ====================================== */
	/* TCP CONNECTION                    	  */
	/* ====================================== */

	/* allocate space for server */
	pTcpConn = (struct espconn *) os_zalloc(sizeof(struct espconn));

	/* clear allocated memory */
	ets_memset(pTcpConn, 0, sizeof(struct espconn));

	/* set the type of connection */
	pTcpConn->type = ESPCONN_TCP;

	/* set state to NONE */
	pTcpConn->state = ESPCONN_NONE;

	/* allocate memory for TCP settings */
	pTcpConn->proto.tcp = (esp_tcp *) os_zalloc(sizeof(esp_tcp));

	/* set the port that the connection will be listening to */
	pTcpConn->proto.tcp->local_port = espconn_port();

	/* set the remote port and IP address */
	pTcpConn->proto.tcp->remote_port = 80;
	os_memcpy(pTcpConn->proto.tcp->remote_ip, server_ip_address, sizeof(server_ip_address));

	/* register callbacks */
	espconn_regist_connectcb(pTcpConn, tcpConnCb);
	espconn_regist_reconcb(pTcpConn, tcpReconnCb);

	/* disarm timer */
	os_timer_disarm((ETSTimer*)&wifi_setup_timer);

	/* set callback */
	os_timer_setfn((ETSTimer*)&wifi_setup_timer, (os_timer_func_t *) wifiConnectTimerCb, NULL);

	/* arm the timer -> os_timer_arm(<pointer>, <period in ms>, <fire periodically>) */
	os_timer_arm((ETSTimer*)&wifi_setup_timer, 5000, 1);

	return;

}
void main()
{
  uint8_t sw1,sw2;
  uint16_t  memaddr = 0;   // Start memory Address
  uint8_t  dat,c,i;
  
 /*
 *  Initialize UART library, pass baudrate and AVR cpu clock
 *  with the macro 
 *  UART_BAUD_SELECT() (normal speed mode )
 *  or 
 *  UART_BAUD_SELECT_DOUBLE_SPEED() ( double speed mode)
*/
  DDRC = 0xFC;
  uart_init(); 
 
  
  d7segment_init();
  i2ceeprom_init();
//  i2c_set_localdeviceaddr(I2C_EEPROM_MASTER_ADDR,FALSE);
//  i2c_set_localdeviceaddr(I2C_EEPROM_SLAVE_ADDR,FALSE);

  sei();
// To Wrie and read the same device. Need to delay. Maybe the wait state is not correct.... 
//  dat = 0x44;
//  memaddr = 0;
//  i2ceeprom_write_byte(I2C_EEPROM_SLAVE_ADDR, memaddr,dat);
//  debug_value (dat,16); 
//  	_delay_ms(20);
//  dat = i2ceeprom_read_byte(I2C_EEPROM_SLAVE_ADDR,memaddr);
//  debug_value (dat,16); 
 			

		
 
  while (1)
  {
 		
		
   sw1 = _7SEGMENT_SW1_IN_PORT & _7SEGMENT_SW1; 
   sw2 = _7SEGMENT_SW2_IN_PORT & _7SEGMENT_SW2; 
     
  
 // Delay
   
   if (!sw1) // Start copy eeprom 
    {   	
        i = 0;
		for (memaddr = 0  ; memaddr < E_24LC32_MEM_ADDR ;memaddr++)
		{
   
			dat = i2ceeprom_read_byte(I2C_EEPROM_MASTER_ADDR,memaddr);

			debug_value (dat,16); 
 			i2ceeprom_write_byte(I2C_EEPROM_SLAVE_ADDR, memaddr,dat);
//			_delay_ms( EEPROM_DELAY);
	          
			if (i < 100)
			{
				c =0;
			}
			if (i > 100) 
			{
				c ='-';			
            }			
			if (i > 200)
				i = 0;
			
			d7segment_display(c,1);
			_delay_ms(2);
			d7segment_display(c,2);
			_delay_ms(2);
			
		    i++;
   
		}  

//	

	}
// Finish copy   	
   	d7segment_display(0,2);
	_delay_ms( 10);
	d7segment_display(0,1);
	_delay_ms( 10);
    
  }
     
}
Exemple #19
0
int main(void) {
    uart_init();
    servos_init();
    steppers_init();
    pumps_init();

    *idle_ddr &= ~idle_mask;
    *idle_port |= idle_mask;

    *setup_ddr &= ~setup_mask;
    *setup_port |= setup_mask;

    *ready_ddr |= ready_mask;
    *ready_port &= ~(ready_mask);


    sei();

    uart_puts("PumpControl 0.1 ready\n\r");


    uint8_t active_pump = 0;

    while(1) {
        pumps_run();

        // Setup is active low
        if(!(*setup_pin & setup_mask)) {
            for(uint8_t i = 0; i < PumpCount; i++) {
                if(pump_states[i] != PUMP_SETUP) {
                     pump_enter_setup(i);
                }
            }
        }

        // We only activate extruders if we are idle
        if(*idle_pin & idle_mask) {
            /*
             * Check if we need a new active pump
             * if full -> nice we've got a fresh one
             * if dispense -> still some stuff left in this one
             */
            if(pump_states[active_pump] != PUMP_FULL &&
                pump_states[active_pump] != PUMP_DISPENSE) {
                for(uint8_t i = 0; i < PumpCount; i++) {
                    if(pump_states[i] == PUMP_FULL) {
                        active_pump = i;
                        break;
                    }
                }
            }

            // We've selected a new active pump, now we need to start it
            if(pump_states[active_pump] == PUMP_FULL) {
                uart_debug_pump(active_pump, "is new acitve pump");
                pump_enter_dispense(active_pump);
            }
        }

        /*
         * We are ready if we picked a new active pump and set it to dispense,
         * or if the old one still has stuff left in it and is in dispense.
         */
        if(pump_states[active_pump] == PUMP_DISPENSE) {
            *ready_port |= ready_mask;
        }
        else {
            *ready_port &= ~(ready_mask);
        }


        /*
         * If we are idle, try to fill all pumps
         * If the active pump is also refilled, a other full one will be chosen
         * in the next iteration.
         */
        if(!(*idle_pin & idle_mask)) {
            for(uint8_t i = 0; i < PumpCount; i++) {
                if(pump_states[i] == PUMP_DISPENSE) {
                    uart_debug("Idle state detected, refilling");
                    pump_enter_fill(i);
                }
            }
        }
    }

}
Exemple #20
0
int main(void)
{
    unsigned int c;
    char buffer[7];
    int  num=134;

    
    /*
     *  Initialize UART library, pass baudrate and AVR cpu clock
     *  with the macro 
     *  UART_BAUD_SELECT() (normal speed mode )
     *  or 
     *  UART_BAUD_SELECT_DOUBLE_SPEED() ( double speed mode)
     */
    uart_init( UART_BAUD_SELECT(UART_BAUD_RATE,F_CPU) ); 
    
    /*
     * now enable interrupt, since UART library is interrupt controlled
     */
    sei();
    
    /*
     *  Transmit string to UART
     *  The string is buffered by the uart library in a circular buffer
     *  and one character at a time is transmitted to the UART using interrupts.
     *  uart_puts() blocks if it can not write the whole string to the circular 
     *  buffer
     */
    uart_puts("String stored in SRAM\n");
    
    /*
     * Transmit string from program memory to UART
     */
    uart_puts_P("String stored in FLASH\n");
    
        
    /* 
     * Use standard avr-libc functions to convert numbers into string
     * before transmitting via UART
     */     
    itoa( num, buffer, 10);   // convert interger into string (decimal format)         
    uart_puts(buffer);        // and transmit string to UART

    
    /*
     * Transmit single character to UART
     */
    uart_putc('\r');
    
    for(;;)
    {
        /*
         * Get received character from ringbuffer
         * uart_getc() returns in the lower byte the received character and 
         * in the higher byte (bitmask) the last receive error
         * UART_NO_DATA is returned when no data is available.
         *
         */
        c = uart_getc();
        if ( c & UART_NO_DATA )
        {
            /* 
             * no data available from UART 
             */
        }
        else
        {
            /*
             * new data available from UART
             * check for Frame or Overrun error
             */
            if ( c & UART_FRAME_ERROR )
            {
                /* Framing Error detected, i.e no stop bit detected */
                uart_puts_P("UART Frame Error: ");
            }
            if ( c & UART_OVERRUN_ERROR )
            {
                /* 
                 * Overrun, a character already present in the UART UDR register was 
                 * not read by the interrupt handler before the next character arrived,
                 * one or more received characters have been dropped
                 */
                uart_puts_P("UART Overrun Error: ");
            }
            if ( c & UART_BUFFER_OVERFLOW )
            {
                /* 
                 * We are not reading the receive buffer fast enough,
                 * one or more received character have been dropped 
                 */
                uart_puts_P("Buffer overflow error: ");
            }
            /* 
             * send received character back
             */
            uart_putc( (unsigned char)c );
        }
    }
    
}
void main_loop()
{
    uart_default_config(&current_config);
    if (uart_init(&uart,
                  handle_write_completed,
                  handle_read_completed,
                  handle_notify_read) < 0)
        errx(EXIT_FAILURE, "uart_init failed");

    struct erlcmd *handler = malloc(sizeof(struct erlcmd));
    erlcmd_init(handler, handle_elixir_request, NULL);

    bool running = true;
    while (running) {
        HANDLE handles[3];
        handles[0] = erlcmd_wfmo_event(handler);

        DWORD timeout = INFINITE;
        DWORD count = 1 + uart_add_wfmo_handles(uart, &handles[1], &timeout);

        debug("Calling WFMO count=%d", (int) count);
        DWORD result = WaitForMultipleObjects(count,
                                              handles,
                                              FALSE,
                                              timeout);


        debug("WFMO returned %d", (int) result);

        switch(result) {
        case WAIT_OBJECT_0 + 0:
            if (erlcmd_process(handler))
                running = false;
            break;

        case WAIT_OBJECT_0 + 1:
            uart_process_handle(uart, handles[1]);
            break;

        case WAIT_OBJECT_0 + 2:
            uart_process_handle(uart, handles[2]);
            break;

        case WAIT_TIMEOUT:
            uart_process_timeout(uart);
            break;

        case WAIT_FAILED:
            debug("WFMO wait failed! %d", (int) GetLastError());
            // TODO: Is this ever a transient occurrence that we
            //       should ignore and retry?
            running = false;
            break;

        default:
            break;
        }

    }

    // Exit due to Erlang trying to end the process.
    if (uart_is_open(uart))
        uart_flush_all(uart);
}
Exemple #22
0
void setup(void)
{
   unsigned char adr, flags, d;
   unsigned short i;
   unsigned char *p;

   _flkey = 0;
   
   /* first disable watchdog */
   watchdog_disable();

   /* avoid any blocking of RS485 bus */
   RS485_ENABLE = RS485_ENABLE_OFF;

   /* Port and oscillator configuration */

#if defined(CPU_C8051F120)

   SFRPAGE   = CONFIG_PAGE;
  
   XBR0 = 0x04;                 // Enable XBar, UART0 & UART1
   XBR1 = 0x00;
   XBR2 = 0x44;

  #ifdef CLK_25MHZ
   /* Select internal quartz oscillator */
   SFRPAGE   = LEGACY_PAGE;
   FLSCL     = 0x00;            // set flash read time for <25 MHz

   SFRPAGE   = CONFIG_PAGE;
   OSCICN    = 0x83;            // divide by 1
   CLKSEL    = 0x00;            // select internal oscillator
  #else          // 98 MHz
   /* Select internal quartz oscillator */
   SFRPAGE   = LEGACY_PAGE;
   FLSCL     = 0xB0;            // set flash read time for 100 MHz

   SFRPAGE   = CONFIG_PAGE;
   OSCICN    = 0x83;            // divide by 1
   CLKSEL    = 0x00;            // select internal oscillator

   PLL0CN    |= 0x01;
   PLL0DIV   = 0x01;
   PLL0FLT   = 0x01;
   PLL0MUL   = 0x04;
   for (i = 0 ; i < 15; i++);   // Wait 5us for initialization
   PLL0CN    |= 0x02;
   for (i = 0 ; i<50000 && ((PLL0CN & 0x10) == 0) ; i++);

   CLKSEL    = 0x02;            // select PLL as sysclk src
  #endif

#elif defined(CPU_C8051F020)

   XBR0 = 0x04;                 // Enable UART0 & UART1
   XBR1 = 0x00;
   XBR2 = 0x44;

   /* Select external quartz oscillator */
   OSCXCN = 0x67;               // Crystal mode, Power Factor 22E6
   OSCICN = 0x08;               // CLKSL=1 (external)

#elif defined(CPU_C8051F310) || defined(CPU_C8051F320)

   XBR0 = 0x01;                 // Enable RX/TX
   XBR1 = 0x40;                 // Enable crossbar

   /* Select internal quartz oscillator */
   OSCICN = 0x83;               // IOSCEN=1, SYSCLK=24.5 MHz
   CLKSEL = 0x00;               // derive SYSCLK from internal source

#else

   XBR0 = 0x04;                 // Enable RX/TX
   XBR1 = 0x00;
   XBR2 = 0x40;                 // Enable crossbar

   PRT0CF = 0x01;               // P0.0: TX = Push Pull
   PRT1CF = 0x00;               // P1
   PRT2CF = 0x00;               // P2  Open drain for 5V LCD
   PRT3CF = 0x20;               // P3.5: RS485 enable = Push Pull

   /* Select external quartz oscillator */
   OSCXCN = 0x67;               // Crystal mode, Power Factor 22E6
   OSCICN = 0x08;               // CLKSL=1 (external)

#endif
        
#ifdef CFG_HAVE_LCD
   lcd_setup();
#endif

#ifdef CFG_HAVE_EMIF
   /* initialize external memory interface */
   d = emif_init();

   /* do memory test on cold start */
   SFRPAGE = LEGACY_PAGE;
   if (d > 0 && (RSTSRC & 0x02) > 0)
      emif_test(d);
#endif

   /* start system clock */
   sysclock_init();

   /* enable watchdog with default timeout */
   watchdog_enable(0);

   /* enable missing clock detector */
   RSTSRC |= 0x04;

   /* default LED mode */
   for (i=0 ; i<N_LED ; i++)
      led_mode(i, 1);
   
   /* initialize all memory */
   CSR = 0;
   addressed = 0;
   flash_param = 0;
   flash_program = 0;
   flash_allowed = 0;
   wrong_cpu = 0;
   _flkey = 0;

#ifdef CFG_HAVE_RTC
   rtc_set = 0;
#endif

   i_in = i_out = n_out = 0;
   _cur_sub_addr = 0;
   for (i=0 ; i<sizeof(in_buf) ; i++)
      in_buf[i] = 0;
   for (i=0 ; i<sizeof(out_buf) ; i++)
      out_buf[i] = 0;

   /* check if we got reset by watchdog */
#if defined(CPU_C8051F120)
   SFRPAGE   = LEGACY_PAGE;
#endif
   WD_RESET = ((RSTSRC & 0x02) == 0 && (RSTSRC & 0x08) > 0);

   /* initialize UART(s) */
   uart_init(0, BD_115200);

#ifdef CFG_UART1_MSCB
   uart_init(1, BD_115200);
#endif

#ifdef CFG_DYN_VARIABLES
   setup_variables();
#endif

   /* count variables */
   for (n_variables = _var_size = 0;; n_variables++) {
      _var_size += variables[n_variables].width;
      if (variables[n_variables].width == 0)
         break;
   }

   /* check if variables are in xdata and xdata is present */
   if (n_variables > 0) {
      p = variables[0].ud;
      d = *p;
      *p = 0x55;
      if (*p != 0x55)
         wrong_cpu = 1;
      *p = 0xAA;
      if (*p != 0xAA)
         wrong_cpu = 1;
      *p = d;
   }

   /* retrieve EEPROM data */
#ifdef CPU_C8051F120
   SFRPAGE = LEGACY_PAGE;
#endif
   if ((RSTSRC & 0x02) > 0)
      flags = eeprom_retrieve(1); // vars on cold start
   else
      flags = eeprom_retrieve(0);

   if ((flags & (1 << 0)) == 0) {
      configured_addr = 0;
   
      /* set initial values */
      sys_info.node_addr = 0xFFFF;
      sys_info.group_addr = 0xFFFF;
      memset(sys_info.node_name, 0, sizeof(sys_info.node_name));
      strncpy(sys_info.node_name, node_name, sizeof(sys_info.node_name));
   } else
      configured_addr = 1;

   /* store SVN revision */
   sys_info.svn_revision = (svn_rev_main[6]-'0')*1000+
                           (svn_rev_main[7]-'0')*100+
                           (svn_rev_main[8]-'0')*10+
                           (svn_rev_main[9]-'0');

   if ((flags & (1 << 1)) == 0) {

      /* init variables */
      for (i = 0; variables[i].width; i++)
         if (!(variables[i].flags & MSCBF_DATALESS)) {
            /* do it for each sub-address */
            for (adr = 0 ; adr < _n_sub_addr ; adr++) {
               memset((char*)variables[i].ud + _var_size*adr, 0, variables[i].width);
            }
         }

      /* call user initialization routine with initialization */
      user_init(1);

      /* write current variables to flash later in main routine */
      configured_vars = 0;
   } else {
      /* call user initialization routine without initialization */
      user_init(0);
      configured_vars = 1;
   }

   /* Blink LEDs */
   for (i=0 ; i<N_LED ; i++)
      led_blink(i, 3, 150);

}
Exemple #23
0
void hardware_init() {
//    setup_heap();
    for(unsigned int i=bss_start;i<bss_end;i+=4) PUT32(i,0);
    uart_init();
}
static void nrf_log_backend_uart_panic_set(nrf_log_backend_t const * p_backend)
{
    nrf_drv_uart_uninit(&m_uart);

    uart_init(false);
}
Exemple #25
0
/* later in the init process */
void stm32_debug_init(void)
{
    uart_init();
}
Exemple #26
0
//
// syscall entry point
//
long int syscall(unsigned long int command,...){
	int ret;
	va_list  ap;
	ret = 0;
	va_start(ap,command);
	switch (command) {
	// SYS
		case SYS_INIT: {
			tick_init();			// raw-handler
			int_init();			// raw-handler
			syscall(SYS_TIMER_INIT);
			syscall(SYS_DMA_INIT);
			syscall(SYS_VRAM_INIT);
			syscall(SYS_SCREEN_INIT);
			syscall(SYS_UART_INIT);
			ret = 0;
		} break;
	// TIMER
		case SYS_TIMER_INIT: {
			timer_init(&timer);
			ret = 0;
		} break;
		case SYS_TIMER_GET_COUNT: {
			ret = timer_get_count(&timer);
		} break;
	// DMA
		case SYS_DMA_INIT: {
			unsigned long int base;
			unsigned long int irq;
			base	= va_arg(ap,unsigned long int);
			irq	= va_arg(ap,unsigned long int);
			dma.ch			= dma_channel;
			dma.ch_size		= DMA_CH_SIZE;
			dma.ch[0].buf		= dma_buffer_ch0;
			dma.ch[0].buf_size	= DMA_BUF_SIZE;
			dma_init(&dma,DMA_BASE,DMA_IRQ);
			ret = 0;
		} break;
		case SYS_DMA_ADD: {
			unsigned long int ch;
			void *src;
			void *dst;
			unsigned long int size;
			ch	= va_arg(ap,unsigned long int);
			src	= va_arg(ap,void *);
			dst	= va_arg(ap,void *);
			size	= va_arg(ap,unsigned long int);
			dma_add(&dma,ch,src,dst,size);
			ret = 0;
		} break;
		case SYS_DMA_ADD_FULL: {
			unsigned long int ch;
			ch	= va_arg(ap,unsigned long int);
			ret = (long int)dma_add_full(&dma,ch);
		} break;
		case SYS_DMA_GET_HANDLE: {
			ret = (long int)&dma;
		} break;
		case SYS_DMA_GET_CH: {
			ret = 0;
		} break;
	// VRAM
		case SYS_VRAM_INIT: {
			vram_init(&vram,&dma,0);
			ret = 0;
		} break;
		case SYS_VRAM_CLEAR: {
			vram_clear(&vram);
			ret = 0;
		} break;
		case SYS_VRAM_IMAGE_PASTE: {
			IMAGE *img;
			unsigned long int x;
			unsigned long int y;
			img	= va_arg(ap,IMAGE *);
			x	= va_arg(ap,unsigned long int);
			y	= va_arg(ap,unsigned long int);
			vram_image_paste(&vram,img,x,y);
			ret = 0;
		} break;
		case SYS_VRAM_IMAGE_PASTE_FILTER: {
			IMAGE *img;
			unsigned long int x;
			unsigned long int y;
			img	= va_arg(ap,IMAGE *);
			x	= va_arg(ap,unsigned long int);
			y	= va_arg(ap,unsigned long int);
			vram_image_paste_filter(&vram,img,x,y);
			ret = 0;
		} break;
		case SYS_VRAM_IMAGE_CLEAR: {
			IMAGE *img;
			unsigned long int x;
			unsigned long int y;
			img	= va_arg(ap,IMAGE *);
			x	= va_arg(ap,unsigned long int);
			y	= va_arg(ap,unsigned long int);
			vram_image_clear(&vram,img,x,y);
			ret = 0;
		} break;
	// SCREEN
		case SYS_SCREEN_INIT: {
			screen_init(&scr,&vram);
			ret = 0;
		} break;
		case SYS_SCREEN_CLEAR: {
			screen_clear(&scr);
			ret = 0;
		} break;
		case SYS_SCREEN_LOCATE: {
			unsigned long int x;
			unsigned long int y;
			x	= va_arg(ap,unsigned long int);
			y	= va_arg(ap,unsigned long int);
			screen_locate(&scr,x,y);
			ret = 0;
		} break;
		case SYS_SCREEN_SCROLL: {
			unsigned long int height;
			height	= va_arg(ap,unsigned long int);
			screen_scroll(&scr,height);
			ret = 0;
		} break;
		case SYS_SCREEN_PUT_STRING: {
			unsigned char *s;
			s	= va_arg(ap,unsigned char *);
			screen_put_string(&scr,s);
			ret = 0;
		} break;
		case SYS_SCREEN_PUT_CHAR: {
			unsigned char c;
			c	= va_arg(ap,unsigned int); // usigned char
			screen_put_char(&scr,c);
			ret = 0;
		} break;
		case SYS_SCREEN_PRINT: {
			unsigned char c;
			c	= va_arg(ap,unsigned int); // unsigned char
			screen_print(&scr,c);
			ret = 0;
		} break;
		//case SYS_SCREEN_IMAGE: {
		//	IMAGE *image;
		//	image	= va_arg(ap,IMAGE *);
		//	screen_image(&scr,image);
		//	ret = 0;
		//} break;
		case SYS_SCREEN_SET_LOCATE_X: {
			unsigned long int x;
			x	= va_arg(ap,unsigned long int);
			screen_set_locate_x(&scr,x);
			ret = 0;
		} break;
		case SYS_SCREEN_SET_LOCATE_Y: {
			unsigned long int y;
			y	= va_arg(ap,unsigned long int);
			screen_set_locate_y(&scr,y);
			ret = 0;
		} break;
		case SYS_SCREEN_GET_LOCATE_X: {
			ret = screen_get_locate_x(&scr);
		} break;
		case SYS_SCREEN_GET_LOCATE_Y: {
			ret = screen_get_locate_y(&scr);
		} break;
		case SYS_SCREEN_SET_COLOR_FG: {
			unsigned long int r,g,b;
			r	= va_arg(ap,unsigned long int);
			g	= va_arg(ap,unsigned long int);
			b	= va_arg(ap,unsigned long int);
			screen_set_color_fg(&scr,r,g,b);
			ret = 0;
		} break;
		case SYS_SCREEN_SET_COLOR_BG: {
			unsigned long int r,g,b;
			r	= va_arg(ap,unsigned long int);
			g	= va_arg(ap,unsigned long int);
			b	= va_arg(ap,unsigned long int);
			screen_set_color_bg(&scr,r,g,b);
			ret = 0;
		} break;
	// UART
		case SYS_UART_INIT: {
			unsigned long int base;
			unsigned long int irq;
			base	= va_arg(ap,unsigned long int);
			irq	= va_arg(ap,unsigned long int);
			uart.tx.buf		= uart_buffer_tx;
			uart.tx.buf_size	= UART_TX_BUF_SIZE;
			uart.rx.buf		= uart_buffer_rx;
			uart.rx.buf_size	= UART_RX_BUF_SIZE;
			uart_init(&uart,UART_BASE,UART_IRQ);
			ret = 0;
		} break;
		case SYS_UART_GET: {
			ret = (long int)uart_get(&uart);
		} break;
		case SYS_UART_GET_EXIST: {
			ret = (long int)uart_get_exist(&uart);
		} break;
		case SYS_UART_GET_CLEAR: {
			uart_get_clear(&uart);
			ret = 0;
		} break;
		case SYS_UART_PUT: {
			unsigned int data;
			data	= va_arg(ap,unsigned int);
			uart_put(&uart,(unsigned char)data);
			ret = 0;
		} break;
		case SYS_UART_PUT_FULL: {
			ret = uart_put_full(&uart);
		} break;
		case SYS_UART_PUT_CLEAR: {
			uart_put_clear(&uart);
			ret = 0;
		} break;
		case SYS_UART_PUT_STRING: {
			unsigned char *string;
			string	= va_arg(ap,unsigned char *);
			uart_put_string(&uart,string);
			ret = 0;
		} break;
		case SYS_UART_IS_CTS: {
			ret = uart_is_cts(&uart);
		} break;
		case SYS_UART_IS_DSR: {
			ret = uart_is_dsr(&uart);
		} break;
		case SYS_UART_IS_RI: {
			ret = uart_is_ri(&uart);
		} break;
		case SYS_UART_IS_DCD: {
			ret = uart_is_dcd(&uart);
		} break;
		case SYS_UART_DTR: {
			unsigned long int data;
			data = va_arg(ap,unsigned long int);
			uart_dtr(&uart,data);
			ret = 0;
		} break;
		case SYS_UART_RTS: {
			unsigned long int data;
			data = va_arg(ap,unsigned long int);
			uart_rts(&uart,data);
			ret = 0;
		} break;
	}
	va_end(ap);
	return ret;
}
Exemple #27
0
void main(void) {
	nvmType_t type=0;
	nvmErr_t err;
	volatile uint8_t c;
	volatile uint32_t i;
	volatile uint32_t buf[4];
	volatile uint32_t len=0;
	volatile uint32_t state = SCAN_X;
	volatile uint32_t addr,data;


	uart_init(INC, MOD, SAMP);
	disable_irq(UART1);

	vreg_init();

	dbg_putstr("Detecting internal nvm\n\r");

	err = nvm_detect(gNvmInternalInterface_c, &type);
		
	dbg_putstr("nvm_detect returned: 0x");
	dbg_put_hex(err);
	dbg_putstr(" type is: 0x");
	dbg_put_hex32(type);
	dbg_putstr("\n\r");
	
	/* erase the flash */
	err = nvm_erase(gNvmInternalInterface_c, type, 0x7fffffff); 

	dbg_putstr("nvm_erase returned: 0x");
	dbg_put_hex(err);
	dbg_putstr("\n\r");

	dbg_putstr(" type is: 0x");
	dbg_put_hex32(type);
	dbg_putstr("\n\r");

	/* say we are ready */
	len = 0;
	putstr("ready");
	flushrx();

	/* read the length */
	for(i=0; i<4; i++) {
		c = uart1_getc();
		/* bail if the first byte of the length is zero */
		len += (c<<(i*8));
	}

	dbg_putstr("len: ");
	dbg_put_hex32(len);
	dbg_putstr("\n\r");
	
	/* write the OKOK magic */

#if BOOT_OK
	((uint8_t *)buf)[0] = 'O'; ((uint8_t *)buf)[1] = 'K'; ((uint8_t *)buf)[2] = 'O'; ((uint8_t *)buf)[3] = 'K';	
#elif BOOT_SECURE
	((uint8_t *)buf)[0] = 'S'; ((uint8_t *)buf)[1] = 'E'; ((uint8_t *)buf)[2] = 'C'; ((uint8_t *)buf)[3] = 'U';	
#else
	((uint8_t *)buf)[0] = 'N'; ((uint8_t *)buf)[1] = 'O'; ((uint8_t *)buf)[2] = 'N'; ((uint8_t *)buf)[3] = 'O';
#endif

	dbg_putstr(" type is: 0x");
	dbg_put_hex32(type);
	dbg_putstr("\n\r");

	/* don't make a valid boot image if the received length is zero */
	if(len == 0) {
		((uint8_t *)buf)[0] = 'N'; 
		((uint8_t *)buf)[1] = 'O'; 
		((uint8_t *)buf)[2] = 'N'; 
		((uint8_t *)buf)[3] = 'O';
	}
	
	err = nvm_write(gNvmInternalInterface_c, type, (uint8_t *)buf, 0, 4);

	dbg_putstr("nvm_write returned: 0x");
	dbg_put_hex(err);
	dbg_putstr("\n\r");

	/* write the length */
	err = nvm_write(gNvmInternalInterface_c, type, (uint8_t *)&len, 4, 4);

	/* read a byte, write a byte */
	for(i=0; i<len; i++) {
		c = getc();	       
		err = nvm_write(gNvmInternalInterface_c, type, (uint8_t *)&c, 8+i, 1); 
	}

	putstr("flasher done\n\r");

	state = SCAN_X; addr=0;
	while((c=getc())) {
		if(state == SCAN_X) {
			/* read until we see an 'x' */
			if(c==0) { break; }
			if(c!='x'){ continue; } 	
			/* go to read_chars once we have an 'x' */
			state = READ_CHARS;
			i = 0; 
		}
		if(state == READ_CHARS) {
			/* read all the chars up to a ',' */
			((uint8_t *)buf)[i++] = c;
			/* after reading a ',' */
			/* goto PROCESS state */
			if((c == ',') || (c == 0)) { state = PROCESS; }				
		}
		if(state == PROCESS) {
			if(addr==0) {
				/*interpret the string as the starting address */
				addr = to_u32(buf);				
			} else {
				/* string is data to write */
				data = to_u32(buf);
				putstr("writing addr ");
				put_hex32(addr);
				putstr(" data ");
				put_hex32(data);
				putstr("\n\r");
				err = nvm_write(gNvmInternalInterface_c, 1, (uint8_t *)&data, addr, 4);
				addr += 4;
			}
			/* look for the next 'x' */
			state=SCAN_X;
		}
	}

	while(1) {continue;};
}
Exemple #28
0
int main(void) {
	/* init serial interface */
	uart_init(UART_BAUD_SELECT(BAUDRATE, F_CPU)); 

	/* init spi interface */
	spi_init();

	/* initialize LEDs */
	strip_init();

	timer_init();

	/* enable interrupts */
	sei();

	/* motd */
	uart_puts_P("\r\n\r\nfnordstripe 0.1\r\n");

	struct hsv_color hsvd, hsv = {
		.hue = 70,
		.saturation = 0xff,
		.value = 0xff
	};

	enum mode { HUE, SAT, VAL } m = HUE;
	char buf[32];

	while (1) {
		uint16_t r = uart_getc();
		char c = r & 0xff;

		if (r & UART_NO_DATA) {
			hsv.hue++;
			hsv.hue %= 360;
			
			for (uint8_t i = 0; i < DOTS; i++) {
				hsvd = hsv;
				hsvd.hue += 7*i;
				hsvd.hue %= 360;

				cli();
				strip_setdot(hsv2rgb(hsvd), i);
				sei();
			}
			_delay_ms(500);
		}
		else if (r & 0xff00) {
			uart_puts_P("error\r\n");
		}
		else if ( c == 'h' ) m = HUE;
		else if ( c == 'v' ) m = VAL;
		else if ( c == 's' ) m = SAT;
		else if ( c >= '0' && c <= '9') {
			switch (m) {
				case HUE:
					hsv.hue = (c - '0') * 36;
					sprintf(buf, "ok, hue: %d\r\n", hsv.hue);
					break;
				case SAT:
					hsv.saturation = (c- '0') * 25;
					sprintf(buf, "ok, saturation: %d\r\n", hsv.saturation);
					break;
				case VAL:
					hsv.value = (c- '0') * 25;
					sprintf(buf, "ok, value: %d\r\n", hsv.value);
					break;
			}

			uart_puts(buf);
		}
		else {
			uart_putc(c);
		}
	}

	return 0;
}
Exemple #29
0
void user_init(void)
{
	uint8_t i;



	UartDev.data_bits = EIGHT_BITS;
	UartDev.parity = NONE_BITS;
	UartDev.stop_bits = ONE_STOP_BIT;
	uart_init(BIT_RATE_9600, BIT_RATE_9600);


	i2c_init();
	SSD1306Init();
	clearScreen();
	stringDraw(5, 1, "SDK ver:");
	stringDraw(5, 48, (char*)system_get_sdk_version());


	ets_uart_printf("reset reason: %d\n", reset_info->reason);
	ets_uart_printf("Booting...\n");
	ets_uart_printf("SDK version:%s\n", system_get_sdk_version());

	setup_wifi_st_mode();
	if(wifi_get_phy_mode() != PHY_MODE_11N)
		wifi_set_phy_mode(PHY_MODE_11N);
	if(wifi_station_get_auto_connect() == 0)
		wifi_station_set_auto_connect(1);



#ifdef CONFIG_DYNAMIC
	flash_param_t *flash_param;
	flash_param_init();
	flash_param = flash_param_get();
	UartDev.data_bits = GETUART_DATABITS(flash_param->uartconf0);
	UartDev.parity = GETUART_PARITYMODE(flash_param->uartconf0);
	UartDev.stop_bits = GETUART_STOPBITS(flash_param->uartconf0);
	uart_init(flash_param->baud, BIT_RATE_115200);
#else

#endif



	serverInit_telnet();
	serverInit_http();

#ifdef CONFIG_GPIO
	config_gpio();
#endif



	//		os_timer_disarm(&timer_1);
	//		os_timer_setfn(&timer_1, (os_timer_func_t *)timer_1_int, NULL);
	//		os_timer_arm(&timer_1, 1000, 1);

	// Wait for Wi-Fi connection
	os_timer_disarm(&WiFiLinker);
	os_timer_setfn(&WiFiLinker, (os_timer_func_t *)wifi_check_ip, NULL);
	os_timer_arm(&WiFiLinker, 1000, 0);




	system_os_task(recvTask, recvTaskPrio, recvTaskQueue, recvTaskQueueLen);
}
Exemple #30
-1
/**
 * \brief Main routine for the OpenMote-CC2538 platforms
 */
int
main(void)
{
  nvic_init();
  ioc_init();
  sys_ctrl_init();
  clock_init();
  lpm_init();
  rtimer_init();
  gpio_init();
  leds_init();
  fade(LEDS_RED);
  process_init();
  watchdog_init();

#if UART_CONF_ENABLE
  uart_init(0);
  uart_init(1);
  uart_set_input(SERIAL_LINE_CONF_UART, serial_line_input_byte);
#endif

#if USB_SERIAL_CONF_ENABLE
  usb_serial_init();
  usb_serial_set_input(serial_line_input_byte);
#endif

  i2c_init(I2C_SDA_PORT, I2C_SDA_PIN, I2C_SCL_PORT, I2C_SCL_PIN, I2C_SCL_NORMAL_BUS_SPEED);

  serial_line_init();

  INTERRUPTS_ENABLE();
  fade(LEDS_BLUE);

  PUTS(CONTIKI_VERSION_STRING);
  PUTS(BOARD_STRING);
#if STARTUP_CONF_VERBOSE
  soc_print_info();
#endif

  random_init(0);

  udma_init();

  process_start(&etimer_process, NULL);
  ctimer_init();

  board_init();

#if CRYPTO_CONF_INIT
  crypto_init();
  crypto_disable();
#endif

  netstack_init();
  set_rf_params();

  PRINTF("Net: ");
  PRINTF("%s\n", NETSTACK_NETWORK.name);
  PRINTF("MAC: ");
  PRINTF("%s\n", NETSTACK_MAC.name);
  PRINTF("RDC: ");
  PRINTF("%s\n", NETSTACK_RDC.name);

#if NETSTACK_CONF_WITH_IPV6
  memcpy(&uip_lladdr.addr, &linkaddr_node_addr, sizeof(uip_lladdr.addr));
  queuebuf_init();
  process_start(&tcpip_process, NULL);
#endif /* NETSTACK_CONF_WITH_IPV6 */

  process_start(&sensors_process, NULL);

  SENSORS_ACTIVATE(button_sensor);

  energest_init();
  ENERGEST_ON(ENERGEST_TYPE_CPU);

  autostart_start(autostart_processes);

  watchdog_start();
  fade(LEDS_GREEN);

  while(1) {
    uint8_t r;
    do {
      watchdog_periodic();

      r = process_run();
    } while(r > 0);

    lpm_enter();
  }
}