Exemplo n.º 1
0
/******************************************************************************
 * @brief  Main function
 *
 *****************************************************************************/
int main(void)
{
  /* Initialize chip - handle erratas */
  CHIP_Init( );

  /* Initialize clocks and oscillators */
  cmuSetup( );

  /* Initialize UART peripheral */
  uartSetup( );

  /* Initialize Development Kit in EBI mode */
  BSP_Init(BSP_INIT_DEFAULT);

  /* Enable RS-232 transceiver on Development Kit */
  BSP_PeripheralAccess(BSP_RS232_UART, true);

  /* When DVK is configured, and no more DVK access is needed, the interface can safely be disabled to save current */
  BSP_Disable();


  /* Write welcome message to UART */
  uartPutData((uint8_t*) welcomeString, welLen);

  /*  Eternal while loop
   *  CPU will sleep during Rx and Tx. When a byte is transmitted, an interrupt
   *  wakes the CPU which copies the next byte in the txBuf queue to the
   *  UART TXDATA register.
   *
   *  When the predefined termiation character is received, the all pending
   *  data in rxBuf is copied to txBuf and echoed back on the UART */
  while (1)
  {
    /* Wait in EM1 while UART transmits */
    EMU_EnterEM1();

    /* Check if RX buffer has overflowed */
    if (rxBuf.overflow)
    {
      rxBuf.overflow = false;
      uartPutData((uint8_t*) overflowString, ofsLen);
    }

    /* Check if termination character is received */
    if (rxBuf.data[(rxBuf.wrI - 1) % BUFFERSIZE] == TERMINATION_CHAR)
    {
      /* Copy received data to UART transmit queue */
      uint8_t tmpBuf[BUFFERSIZE];
      int     len = uartGetData(tmpBuf, 0);
      uartPutData(tmpBuf, len);
    }
  }
}
Exemplo n.º 2
0
void hardware_setup(void)
{
/**
*
* Hardware init
*
*/
#ifdef HAVE_WDT
	// watchdog timer init
 	wdt_init_and_start();
#else
	//stop wdg
 	wdt_hold();
#endif



	// clocks, wdt, power, uart, spi
	set_clocks_speed(MCLK_4MHZ_SMCLK_4MHZ);

	driver_power_init();
	//#if ! defined HAVE_CODE_COMPRESSION & ! defined HAVE_DEBUG
	uartSetup(UART0_CONFIG_32KHZ_9600);
	//#endif
	spi_init();
	timer_init();

	// LEDs
	LEDS_INIT();
	LEDS_OFF_CHECK_MODE(led_mode);

	// Temperature
#ifndef	HAVE_CODE_COMPRESSION
	update_temperature(); // for some unclear reason the very first temp measure is incorrect
	update_temperature(); // hence taking an extra-measure for security
#endif

// powersave
#ifdef HAVE_POWERSAVE
	power_init();
#endif /* HAVE_POWERSAVE */


}