Ejemplo n.º 1
0
Archivo: soc.c Proyecto: agatti/zephyr
/**
 * @brief Initialize the system clock
 *
 * @return N/A
 *
 */
static ALWAYS_INLINE void clkInit(void)
{
#ifdef CONFIG_CMU_HFCLK_HFXO
	CMU_HFXOInit(&hfxoInit);
	CMU_OscillatorEnable(cmuOsc_HFXO, true, true);
	CMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFXO);
	CMU_OscillatorEnable(cmuOsc_HFRCO, false, false);
	SystemHFXOClockSet(CONFIG_CMU_HFXO_FREQ);
#elif (defined CONFIG_CMU_HFCLK_LFXO)
	CMU_LFXOInit(&lfxoInit);
	CMU_OscillatorEnable(cmuOsc_LFXO, true, true);
	CMU_ClockSelectSet(cmuClock_HF, cmuSelect_LFXO);
	CMU_OscillatorEnable(cmuOsc_HFRCO, false, false);
	SystemLFXOClockSet(CONFIG_CMU_LFXO_FREQ);
#elif (defined CONFIG_CMU_HFCLK_HFRCO)
	/*
	 * This is the default clock, the controller starts with, so nothing to
	 * do here.
	 */
#else
#error "Unsupported clock source for HFCLK selected"
#endif

	/* Enable the High Frequency Peripheral Clock */
	CMU_ClockEnable(cmuClock_HFPER, true);

#ifdef CONFIG_GPIO_GECKO
	CMU_ClockEnable(cmuClock_GPIO, true);
#endif
}
Ejemplo n.º 2
0
/**************************************************************************//**
 * @brief vPortSetupTimerInterrupt
 * Override the default definition of vPortSetupTimerInterrupt() that is weakly
 * defined in the FreeRTOS Cortex-M3, which set source of system tick interrupt
 *****************************************************************************/
void vPortSetupTimerInterrupt(void)
{
  /* Set our data about timer used as system ticks*/
  ulTimerReloadValueForOneTick = SYSTICK_LOAD_VALUE ;
  #if (configUSE_TICKLESS_IDLE == 1)
  xMaximumPossibleSuppressedTicks = TIMER_CAPACITY / (SYSTICK_LOAD_VALUE);
  ulStoppedTimerCompensation      = TIMER_COMPENSATION / (configCPU_CLOCK_HZ / configSYSTICK_CLOCK_HZ);
#endif /* (configUSE_TICKLESS_IDLE == 1) */
  /* Configure RTC as system tick source */
  /* Structure of RTC init */
  RTC_Init_TypeDef init;
#if (configCRYSTAL_IN_EM2 == 1)
  /* LFXO setup */
  /* Starting LFXO and waiting until it is stable */
  CMU_OscillatorEnable(cmuOsc_LFXO, true, true);
#else
  /* RC oscillator */
  CMU_OscillatorEnable(cmuOsc_LFRCO, true, true);
#endif
  /* Ensure LE modules are accessible */
  CMU_ClockEnable(cmuClock_CORELE, true);
#if (configCRYSTAL_IN_EM2 == 1)
  /* Enable osc as LFACLK in CMU (will also enable oscillator if not enabled) */
  CMU_ClockSelectSet(cmuClock_LFA, cmuSelect_LFXO);
#else
  /* Enable osc as LFACLK in CMU (will also enable oscillator if not enabled) */
  CMU_ClockSelectSet(cmuClock_LFA, cmuSelect_LFRCO);
#endif
  /* Set 2 times divider to reduce energy*/
  CMU_ClockDivSet(cmuClock_RTC, cmuClkDiv_2);

  /* Enable clock to RTC module */
  CMU_ClockEnable(cmuClock_RTC, true);
  init.enable   = false;
  init.debugRun = false;
  init.comp0Top = false;         /* Count to max value before wrapping */
  /* Initialization of RTC */
  RTC_Init(&init);

  /* Disable interrupt generation from RTC0 */
  RTC_IntDisable(RTC_IFC_COMP0);

  /* Tick interrupt MUST execute at the lowest interrupt priority. */
  NVIC_SetPriority(RTC_IRQn, 255);

  /* Enable interrupts */
  NVIC_ClearPendingIRQ(RTC_IRQn);
  NVIC_EnableIRQ(RTC_IRQn);
  RTC_CompareSet(0, SYSTICK_LOAD_VALUE);
  RTC_IntClear(RTC_IFC_COMP0);
  RTC_IntEnable(RTC_IF_COMP0);
  RTC_Enable(true);
  //RTC_CounterReset();
}
Ejemplo n.º 3
0
/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void)
{
  /* Initialize chip */
  CHIP_Init();
  
  /* Enable Low energy clocking module clock. */
  CMU_ClockEnable(cmuClock_CORELE, true);

  /* Disable LFA and LFB clock domains to save power */
  CMU->LFCLKSEL = 0;
  
  /* Starting LFRCO and waiting until it is stable */
  CMU_OscillatorEnable(cmuOsc_LFRCO, true, true);

  /* Enable access to BURTC registers */
  RMU_ResetControl(rmuResetBU, false);

  /* Setting up burtc */
  setupBurtc();
  
  while (1)
  {
    /* Enter EM2. */
    EMU_EnterEM2(false);
  }
}
Ejemplo n.º 4
0
/***************************************************************************//**
 * @brief
 *   Enable Serial Wire Output (SWO) pin.
 *
 * @details
 *   The SWO pin (sometimes denoted SWV, serial wire viewer) allows for
 *   miscellaneous output to be passed from the Cortex-M3 debug trace module to
 *   an external debug probe. By default, the debug trace module and pin output
 *   may be disabled.
 *
 *   Since the SWO pin is only useful when using a debugger, a suggested use
 *   of this function during startup may be:
 * @verbatim
 * if (DBG_Connected())
 * {
 * DBG_SWOEnable(1);
 * }
 * @endverbatim
 *   By checking if debugger is attached, some setup leading to higher energy
 *   consumption when debugger is attached, can be avoided when not using
 *   a debugger.
 *
 *   Another alternative may be to set the debugger tool chain to configure
 *   the required setup (similar to the content of this function) by some
 *   sort of toolchain scripting during its attach/reset procedure. In that
 *   case, the above suggested code for enabling the SWO pin is not required
 *   in the application.
 *
 * @param[in] location
 *   Pin location used for SWO pin on the application in use.
 ******************************************************************************/
void DBG_SWOEnable(unsigned int location)
{
  int port;
  int pin;

  EFM_ASSERT(location < AFCHANLOC_MAX);

  port = AF_DBG_SWO_PORT(location);
  pin  = AF_DBG_SWO_PIN(location);

  /* Port/pin location not defined for device? */
  if ((pin < 0) || (port < 0))
  {
    EFM_ASSERT(0);
    return;
  }

  /* Ensure auxiliary clock going to the Cortex debug trace module is enabled */
  CMU_OscillatorEnable(cmuOsc_AUXHFRCO, true, false);

  /* Set selected pin location for SWO pin and enable it */
  GPIO_DbgLocationSet(location);
  GPIO_DbgSWOEnable(true);

  /* Configure SWO pin for output */
  GPIO_PinModeSet((GPIO_Port_TypeDef) port, pin, gpioModePushPull, 0);
}
Ejemplo n.º 5
0
/***************************************************************************//**
 * @brief
 *   Initialize the hardware drivers.
 *
 * @details
 *
 * @note
 *
 ******************************************************************************/
void rt_hw_driver_init(void)
{
    CMU_ClockEnable(cmuClock_HFPER, true);

    /* Enable GPIO */
    CMU_ClockEnable(cmuClock_GPIO, true);

    /* Enabling clock to the interface of the low energy modules */
    CMU_ClockEnable(cmuClock_CORELE, true);

    /* Starting LFXO and waiting until it is stable */
    CMU_OscillatorEnable(cmuOsc_LFXO, true, true);

	/* Select LFXO for Peripherals A */
    CMU_ClockSelectSet(cmuClock_LFA,cmuSelect_LFXO);

    /* Select LFXO for specified module (and wait for it to stabilize) */
#if (defined(EFM32GG_USING_LEUART0) || defined(EFM32GG_USING_LEUART1))
    CMU_ClockSelectSet(cmuClock_LFB, cmuSelect_LFXO);
#endif

    /* Enable SWO */
#if defined(EFM32GG_USING_SWO)
    efm_swo_setup();
#endif

    /* Initialize external interrupt */
#ifdef EFM32GG_USING_EINT
    eint_init();
#endif
}
/**************************************************************************//**
 * @brief   Setup clocks necessary to drive RTC/RTCC for EXTCOM GPIO pin.
 *
 * @return  N/A
 *****************************************************************************/
static void palClockSetup(CMU_Clock_TypeDef clock)
{
  /* Enable LE domain registers */
  CMU_ClockEnable(cmuClock_CORELE, true);

#if ( defined(PAL_CLOCK_RTC) && defined(PAL_RTC_CLOCK_LFXO) ) \
    || ( defined(PAL_CLOCK_RTCC) && defined(PAL_RTCC_CLOCK_LFXO) )
  /* LFA with LFXO setup is relatively time consuming. Therefore, check if it
     already enabled before calling. */
  if ( !(CMU->STATUS & CMU_STATUS_LFXOENS) )
  {
    CMU_OscillatorEnable(cmuOsc_LFXO, true, true);
  }
  if ( cmuSelect_LFXO != CMU_ClockSelectGet(clock) )
  {
    CMU_ClockSelectSet(clock, cmuSelect_LFXO);
  }
#elif ( defined(PAL_CLOCK_RTC) && defined(PAL_RTC_CLOCK_LFRCO) ) \
    || ( defined(PAL_CLOCK_RTCC) && defined(PAL_RTCC_CLOCK_LFRCO) )
  /* Enable LF(A|E)CLK in CMU (will also enable LFRCO oscillator if not enabled) */
  CMU_ClockSelectSet(clock, cmuSelect_LFRCO);
#elif ( defined(PAL_CLOCK_RTC) && defined(PAL_RTC_CLOCK_ULFRCO) ) \
    || ( defined(PAL_CLOCK_RTCC) && defined(PAL_RTCC_CLOCK_ULFRCO) )
  /* Enable LF(A|E)CLK in CMU (will also enable ULFRCO oscillator if not enabled) */
  CMU_ClockSelectSet(clock, cmuSelect_ULFRCO);
#else
#error No clock source for RTC defined.
#endif
}
Ejemplo n.º 7
0
/**************************************************************************//**
 * @brief main - the entrypoint after reset.
 *****************************************************************************/
int main( void )
{
  BSP_Init(BSP_INIT_DEFAULT);   /* Initialize DK board register access */

  /* If first word of user data page is non-zero, enable eA Profiler trace */
  BSP_TraceProfilerSetup();

  CMU_ClockSelectSet( cmuClock_HF, cmuSelect_HFXO );
  CMU_OscillatorEnable(cmuOsc_LFXO, true, false);

  if ( !MSDDMEDIA_Init() )      /* Initialize the media layer of the MSD. */
  {
    EFM_ASSERT( false );
    for( ;; ){}
  }

  VUD_Init();                   /* Initialize the vendor unique device. */
  CDC_Init();                   /* Initialize the communication class device. */
  MSDD_Init(gpioPortE, 1);      /* Initialize the Mass Storage Device.  */

  USBD_Init(&initstruct);       /* Start USB. */

  /*
   * When using a debugger it is practical to uncomment the following three
   * lines to force host to re-enumerate the device.
   */
  /* USBD_Disconnect(); */
  /* USBTIMER_DelayMs( 1000 ); */
  /* USBD_Connect(); */

  for (;;)
  {
    MSDD_Handler();             /* Serve the MSD device. */
  }
}
Ejemplo n.º 8
0
//================================================================================
// WDOG_enter_DefaultMode_from_RESET
//================================================================================
extern void WDOG_enter_DefaultMode_from_RESET(void) {

	// $[CMU_ClockEnable]
	/* Enable LE clock for CPU access to BURTC registers */
	CMU_ClockEnable(cmuClock_CORELE, true);
	// [CMU_ClockEnable]$

	// $[CMU_OscillatorEnable]
	CMU_OscillatorEnable(cmuOsc_LFRCO, true, true);
	// [CMU_OscillatorEnable]$

	// $[WDOG_Init]
	WDOG_Init_TypeDef watchdogInit = WDOG_INIT_DEFAULT;

	watchdogInit.debugRun = 0;
	watchdogInit.clkSel = wdogClkSelULFRCO;//1K频率
	watchdogInit.perSel = wdogPeriod_2k; //2K时钟周期,大约2s
	watchdogInit.swoscBlock = 0;
	watchdogInit.em4Block = 0;
	watchdogInit.lock = 0;
	watchdogInit.em3Run = 0;
	watchdogInit.em2Run = 0;
	WDOG_Init(&watchdogInit);
	// [WDOG_Init]$

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

  /* Setup RTC for periodic wake-ups */
  startRTCTick();

  /* Start LFXO. Do not wait until it is stable */
  CMU_OscillatorEnable(cmuOsc_LFXO, true, false);

  /* Wait in EM2 until LFXO is ready */
  while (!(CMU->STATUS & CMU_STATUS_LFXORDY))
  {
    EMU_EnterEM2(false);
  }
  /* Stop the RTC */
  stopRTCTick();

  while (1)
  {
    /* Go to sleep */
    EMU_EnterEM1();
  }
}
Ejemplo n.º 10
0
/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main( void )
{
  /* Chip errata */
  CHIP_Init();

  /* Setup GPIO for pushbuttons. */
  GpioSetup();

  /* Initialize the display module. */
  displayEnabled = true;
  DISPLAY_Init();

  /* Retrieve the properties of the display. */
  if ( DISPLAY_DeviceGet( 0, &displayDevice ) != DISPLAY_EMSTATUS_OK )
  {
    /* Unable to get display handle. */
    while( 1 );
  }

  /* Retarget stdio to the display. */
  if ( TEXTDISPLAY_EMSTATUS_OK != RETARGET_TextDisplayInit() )
  {
    /* Text display initialization failed. */
    while( 1 );
  }

  /* Set PCNT to generate an interrupt every second. */
  PcntInit();

  printf( "\n\n Cycling through"
          "\n energy modes"
          "\n EM0-EM3"
          "\n\n Push PB0 to"
          "\n enter EM4\n\n\n\n" );

  /* Turn on LFXO to be able to see the difference between EM2 and EM3. */
  CMU_OscillatorEnable(cmuOsc_LFXO, true, false );

  for (;;)
  {
    printf( "\r      EM0" );
    EnterEMode( 0, SLEEP_TIME );
    CheckEM4Entry();

    printf( "\r      EM1" );
    EnterEMode( 1, SLEEP_TIME );
    CheckEM4Entry();

    printf( "\r      EM2" );
    EnterEMode( 2, SLEEP_TIME );
    CheckEM4Entry();

    printf( "\r      EM3" );
    EnterEMode( 3, SLEEP_TIME );
    CheckEM4Entry();
  }
}
Ejemplo n.º 11
0
int main(int argc, char **argv)
{
/*
 * Initalize chip.
 */
  CHIP_Init();

/* 
 * Use XT oscillator, disable internal RC osc.
 */
  CMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFXO);
  CMU_OscillatorEnable(cmuOsc_HFRCO, false, false);
  SystemCoreClockUpdate();

#if PORTCFG_CON_USART == 0
  // Allow deep sleep. Doesn't work well with uart console currently.
  SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
#endif

#if PORTCFG_CONOUT_ITM == 1
#ifdef _DBG
  if (DBG_Connected()) {

    CMU_ClockEnable(cmuClock_GPIO, true);
    DBG_SWOEnable(0);

    /* Enable trace in core debug, taken from Energy Aware Commander */
    CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
    ITM->LAR  = 0xC5ACCE55;
    ITM->TER  = 0x0;
    ITM->TCR  = 0x0;
    TPI->SPPR = 2;
    TPI->ACPR = 0xf;
    ITM->TPR  = 0x0;
    DWT->CTRL = 0x400003FE;
    ITM->TCR  = 0x0001000D;
    TPI->FFCR = 0x00000100;
    ITM->TER  = 0x1;

  }
#endif
#endif

#if PORTCFG_CON_USART == 1

  // Configure usart pins.

  CMU_ClockEnable(cmuClock_GPIO, true);

  GPIO_PinModeSet(gpioPortC, 0, gpioModePushPull, 1);
  GPIO_PinModeSet(gpioPortC, 1, gpioModeInput, 0);

#endif

  testStart();
  return 0;
}
Ejemplo n.º 12
0
/******************************************************************//**
* @brief
*	Start LFXO for RTC
*
* @details
*    Starts the LFXO and routes it to the RTC. RTC clock is prescaled to save energy.
*
* @note
*********************************************************************/
static void startLfxoForRtc(void)
{
	/* Starting LFXO and waiting until it is stable */
	CMU_OscillatorEnable(cmuOsc_LFXO, true, true);

	/* Routing the LFXO clock to the RTC */
	CMU_ClockDivSet(cmuClock_RTC,cmuClkDiv_32768);
	CMU_ClockSelectSet(cmuClock_LFA,cmuSelect_LFXO);
	CMU_ClockEnable(cmuClock_RTC, true);
}
Ejemplo n.º 13
0
void os_idle_demon(void)
{
  RTC_Init_TypeDef init;
  uint32_t sleep;
  
  /* The idle demon is a system thread, running when no other thread is      */
  /* ready to run.                                                           */

  CMU_OscillatorEnable(cmuOsc_LFRCO, true, true);
  
  /* Ensure LE modules are accessible */
  CMU_ClockEnable(cmuClock_CORELE, true);

  /* Enable osc as LFACLK in CMU (will also enable oscillator if not enabled) */
  CMU_ClockSelectSet(cmuClock_LFA, cmuSelect_LFRCO);

  /* Use a 32 division prescaler to reduce power consumption. */
  CMU_ClockDivSet(cmuClock_RTC, cmuClkDiv_32);

  /* Enable clock to RTC module */
  CMU_ClockEnable(cmuClock_RTC, true);

  init.enable   = false;
  init.debugRun = false;
  init.comp0Top = false; /* Count to max value before wrapping */

  RTC_Init(&init);

  /* Disable interrupt generation from RTC0 */
  RTC_IntDisable(_RTC_IF_MASK);

  /* Enable interrupts */
  NVIC_ClearPendingIRQ(RTC_IRQn);
  NVIC_EnableIRQ(RTC_IRQn);

  for (;;)
  {
    /* os_suspend stops scheduler and returns time to next event in OS_TICK units */
    sleep = os_suspend();
    if (sleep)
    {
      RTC_CompareSet(0, sleep - 1);
      RTC_IntClear(RTC_IFC_COMP0);
      RTC_IntEnable(RTC_IF_COMP0);
      RTC_CounterReset();
      /* Enter EM2 low power mode - could be replaced with EM1 if required */
      EMU_EnterEM2(true);
      /* get information how long we were in sleep */
      sleep = RTC_CounterGet();
      RTC_Enable(false);
    };
    /* resume scheduler providing information how long MCU was sleeping */
    os_resume(sleep);
  }
}
/**************************************************************************//**
 * @brief Initialize Real Time Counter
 *****************************************************************************/
void initRTC()
{
  /* Starting LFXO and waiting until it is stable */
  CMU_OscillatorEnable(cmuOsc_LFXO, true, true);

  /* Routing the LFXO clock to the RTC */
  CMU_ClockSelectSet(cmuClock_LFA, cmuSelect_LFXO);
  CMU_ClockEnable(cmuClock_RTC, true);

  /* Enabling clock to the interface of the low energy modules */
  CMU_ClockEnable(cmuClock_CORELE, true);

  const RTC_Init_TypeDef rtcInit =
  {
    .enable   = true,
    .debugRun = false,
    .comp0Top = true,
  };

  RTC_Init(&rtcInit);

  /* Set comapre value for compare register 0 */
  RTC_CompareSet(0, RTC_COUNT_BETWEEN_WAKEUP);

  /* Enable interrupt for compare register 0 */
  RTC_IntEnable(RTC_IFC_COMP0);

  /* Enabling Interrupt from RTC */
  NVIC_EnableIRQ(RTC_IRQn);

  RTC_Enable(false);
}

/**************************************************************************//**
 * @brief Initialize General Purpuse Input/Output
 *****************************************************************************/
void initGPIO()
{
  /* Enable clock for GPIO module */
  CMU_ClockEnable(cmuClock_GPIO, true);

  /* Configure pin PB9/PD8 (Push Button 1) and PB10/PB11 (Push Button 2) as an input,
   * so that we can read their values. */
  GPIO_PinModeSet(PB0_PORT, PB0_PIN, gpioModeInput, 1);
  GPIO_PinModeSet(PB1_PORT, PB1_PIN, gpioModeInput, 1);

  /* Enable GPIO_ODD and GPIO_EVEN interrupts in NVIC */
  NVIC_EnableIRQ(GPIO_ODD_IRQn);
  NVIC_EnableIRQ(GPIO_EVEN_IRQn);

  /* Configure interrupts on falling edge for pins B9/D8 (Push Button 1),
   * B10/B11 (Push Button 2) and D3 */
  GPIO_IntConfig(PB0_PORT, PB0_PIN, true, true, true);
  GPIO_IntConfig(PB1_PORT, PB1_PIN, true, true, true);
}
Ejemplo n.º 15
0
void initClocks()
{
	
	/* Starting LFXO and waiting until it is stable */
	CMU_OscillatorEnable(cmuOsc_LFXO, true, true);

	// starting HFXO, wait till stable
	CMU_OscillatorEnable(cmuOsc_HFXO, true, true);

	// route HFXO to CPU
	CMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFXO);

	/* Routing the LFXO clock to the RTC */
	CMU_ClockSelectSet(cmuClock_LFA, cmuSelect_LFXO);
	CMU_ClockSelectSet(cmuClock_LFB, cmuSelect_LFXO);

	// disabling the RCs
	CMU_ClockEnable(cmuSelect_HFRCO, false);
	CMU_ClockEnable(cmuSelect_LFRCO, false);

	/* Enabling clock to the interface of the low energy modules */
	CMU_ClockEnable(cmuClock_CORE, true);
	CMU_ClockEnable(cmuClock_CORELE, true);

	// enable clock to hf perfs
	CMU_ClockEnable(cmuClock_HFPER, true);

	// enable clock to GPIO
	CMU_ClockEnable(cmuClock_GPIO, true);

	// enable clock to RTC
	CMU_ClockEnable(cmuClock_RTC, true);
	RTC_Enable(true);

	// enable radio usart
	CMU_ClockEnable(cmuClock_USART0, true);

	// enable timers
	CMU_ClockEnable(cmuClock_TIMER0, true);
	CMU_ClockEnable(cmuClock_TIMER1, true);

}
Ejemplo n.º 16
0
/**************************************************************************//**
 * @brief Enables LFACLK and selects LFXO as clock source for RTC
 *        Sets up the RTC to generate an interrupt every second.
 *****************************************************************************/
static void rtcSetup(unsigned int frequency)
{
  RTC_Init_TypeDef rtcInit = RTC_INIT_DEFAULT;

  /* Enable LE domain registers */
  if ( !( CMU->HFCORECLKEN0 & CMU_HFCORECLKEN0_LE) )
  {
    CMU_ClockEnable(cmuClock_CORELE, true);
  }

#ifdef PAL_RTC_CLOCK_LFXO
  /* LFA with LFXO setup is relatively time consuming. Therefore, check if it
     already enabled before calling. */
  if ( !(CMU->STATUS & CMU_STATUS_LFXOENS) )
  {
    CMU_OscillatorEnable(cmuOsc_LFXO, true, true);
  }
  if ( cmuSelect_LFXO != CMU_ClockSelectGet(cmuClock_LFA) )
  {
    CMU_ClockSelectSet(cmuClock_LFA, cmuSelect_LFXO);
  }
#elif defined PAL_RTC_CLOCK_LFRCO
  /* Enable LFACLK in CMU (will also enable LFRCO oscillator if not enabled) */
  CMU_ClockSelectSet(cmuClock_LFA, cmuSelect_LFRCO);
#elif defined PAL_RTC_CLOCK_ULFRCO
  /* Enable LFACLK in CMU (will also enable ULFRCO oscillator if not enabled) */
  CMU_ClockSelectSet(cmuClock_LFA, cmuSelect_ULFRCO);
#else
#error No clock source for RTC defined.
#endif

  /* Set the prescaler. */
  CMU_ClockDivSet( cmuClock_RTC, cmuClkDiv_1 );

  /* Enable RTC clock */
  CMU_ClockEnable(cmuClock_RTC, true);

  /* Initialize RTC */
  rtcInit.enable   = false;  /* Do not start RTC after initialization is complete. */
  rtcInit.debugRun = false;  /* Halt RTC when debugging. */
  rtcInit.comp0Top = true;   /* Wrap around on COMP0 match. */
  RTC_Init(&rtcInit);

  /* Interrupt at given frequency. */
  RTC_CompareSet(0, (CMU_ClockFreqGet(cmuClock_RTC) / frequency) - 1 );

  /* Enable interrupt */
  NVIC_EnableIRQ(RTC_IRQn);
  RTC_IntEnable(RTC_IEN_COMP0);

  /* Start Counter */
  RTC_Enable(true);
}
Ejemplo n.º 17
0
Archivo: cpu.c Proyecto: mathirkub/RIOT
static void cpu_clock_init(void)
{
    SystemLFXOClockSet((uint32_t)EFM32_LFXO_FREQ);
	CMU_OscillatorEnable(cmuOsc_LFXO, true, true);
	CMU_OscillatorEnable(cmuOsc_HFRCO, true, true);
	CMU_HFRCOBandSet(cmuHFRCOBand_28MHz);
//	/* HF Core clock is connected to external oscillator */
//	CMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFXO);
	/* HF Core clock is connected to internal RC clock */
	CMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFRCO);
	/* RTC, LESENSE, LETIMER0, LCD is connected to external 36kHz oscillator */
	CMU_ClockSelectSet(cmuClock_LFA, cmuSelect_LFXO);
	CMU_ClockSelectSet(cmuClock_LFB, cmuSelect_LFXO);
	/* HFPER clock is divided by 2 - 14MHz */
	CMU_ClockDivSet(cmuClock_HFPER, cmuClkDiv_2);
	/* core, DMA etc. clock */
	CMU_ClockDivSet(cmuClock_CORE, cmuClkDiv_1);
	/* enabling clocks */
	CMU_ClockEnable(cmuClock_HFPER, true);
	CMU_ClockEnable(cmuClock_CORELE, true);
}
Ejemplo n.º 18
0
void BoardDeInitMcu( void )
{
	/* Switching the CPU clock source to HFRCO */
	CMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFRCO);

	/* Disabling every oscillator except hfrco and lfxo */
	CMU_OscillatorEnable(cmuOsc_AUXHFRCO, false, true);
	CMU_OscillatorEnable(cmuOsc_HFXO, false, true);
	CMU_OscillatorEnable(cmuOsc_LFRCO, false, true);

#ifdef USE_I2C
	I2cDeInit( &I2c );
#endif

	SpiDeInit( &SX1272.Spi );
	SX1272IoDeInit( );

	GpioInit( &Led1, LED_1, PIN_ANALOGIC, PIN_PUSH_PULL, PIN_NO_PULL, 0 );
	GpioInit( &Led2, LED_2, PIN_ANALOGIC, PIN_PUSH_PULL, PIN_NO_PULL, 0 );
	McuInitialized = false;
}
void __efm32lg_mcu_init()
{
    /* Chip errata */
    CHIP_Init();


#ifdef HW_USE_HFXO
    // init clock with HFXO (external)
    CMU_ClockDivSet(cmuClock_HF, cmuClkDiv_2);		// 24 MHZ
    CMU_OscillatorEnable(cmuOsc_HFXO, true, true);   // Enable XTAL Osc and wait to stabilize
    CMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFXO); // Select HF XTAL osc as system clock source. 48MHz XTAL, but we divided the system clock by 2, therefore our HF clock will be 24MHz
    //CMU_ClockDivSet(cmuClock_HFPER, cmuClkDiv_4); // TODO set HFPER clock divider (used for SPI) + disable gate clock when not used?
#else
    // init clock with HFRCO (internal)
    CMU_HFRCOBandSet(cmuHFRCOBand_21MHz);
    CMU_OscillatorEnable(cmuOsc_HFRCO, true, true);
    CMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFRCO);
#endif

    uint32_t hf = CMU_ClockFreqGet(cmuClock_HF);
}
Ejemplo n.º 20
0
/***************************************************************************//**
 * @brief
 *   Initialize the GPIO peripheral for the TDxxxx RF modules.
 ******************************************************************************/
void TD_GPIO_Init(void)
{

	// Enable the GPIO module clock
	CMU_ClockEnable(cmuClock_GPIO, true);

	// Start LFXO and wait until it is stable
	CMU_OscillatorEnable(cmuOsc_LFXO, true, true);

	// Initialize IRQ hooks
	memset(TD_GPIO_Hooks, 0, sizeof(TD_GPIO_hook_t)*TD_GPIO_MAX_HOOKS);
}
/**************************************************************************//**
 * @brief  Start oscillator for RTC
 * Starts the low frequency oscillator and routes it to the RTC
 *****************************************************************************/
void startOscForRtc(uint8_t freq)
{
    /* Start the oscillator, wait until stable, then route it to the RTC */
#ifdef HW_USE_LFXO
    CMU_OscillatorEnable(cmuOsc_LFXO, true, true);
    CMU_ClockSelectSet(cmuClock_LFA,cmuSelect_LFXO);
#else
    CMU_OscillatorEnable(cmuOsc_LFRCO, true, true);
    CMU_ClockSelectSet(cmuClock_LFA,cmuSelect_LFRCO);
#endif
    CMU_ClockEnable(cmuClock_RTC, true);

    /* Set Clock prescaler */
    if(freq == HWTIMER_FREQ_1MS)
    	CMU_ClockDivSet(cmuClock_RTC, cmuClkDiv_32);
    else
    	CMU_ClockDivSet(cmuClock_RTC, cmuClkDiv_1);

    /* Enabling clock to the interface of the low energy modules */
    CMU_ClockEnable(cmuClock_CORELE, true);
}
Ejemplo n.º 22
0
void portInitClock(void)
{

#define LFO_FREQUENCY              32768

#if PORTCFG_RTC_LFXO != 0
  /* Starting LFRCO and waiting until it is stable */
  CMU_OscillatorEnable(cmuOsc_LFXO, true, true);
  /* Routing the LFRCO clock to the RTC */
  CMU_ClockSelectSet(cmuClock_LFA,cmuSelect_LFXO);
#else
  /* Starting LFRCO and waiting until it is stable */
  CMU_OscillatorEnable(cmuOsc_LFRCO, true, true);
  /* Routing the LFRCO clock to the RTC */
  CMU_ClockSelectSet(cmuClock_LFA,cmuSelect_LFRCO);
#endif

  CMU_ClockEnable(cmuClock_RTC, true);

  /* Enabling clock to the interface of the low energy modules */
  CMU_ClockEnable(cmuClock_CORELE, true);

  RTC_Init_TypeDef rtcInit = RTC_INIT_DEFAULT;

  rtcInit.enable   = true;      /* Enable RTC after init has run */
  rtcInit.comp0Top = true;      /* Clear counter on compare match */
  rtcInit.debugRun = false;     /* Counter shall keep running during debug halt. */

  /* Setting the compare value of the RTC */
  RTC_CompareSet(0, (LFO_FREQUENCY / HZ) - 1);

  /* Enabling Interrupt from RTC */
  RTC_IntEnable(RTC_IFC_COMP0);
  NVIC_EnableIRQ(RTC_IRQn);
  NVIC_SetPriority(RTC_IRQn, PORT_SYSTICK_PRI);

  /* Initialize the RTC */
  RTC_Init(&rtcInit);

}
Ejemplo n.º 23
0
// halInit is called on first initial boot, not on wakeup from sleep.
void halInit(void)
{

#ifdef _EZR32_LEOPARD_FAMILY
    CHIP_Init();
    halInternalInitButton();
    halInternalInitLed();
    halInternalInitRadioHoldOff();
    halInternalInitVCPPins();
    CMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFXO);
    CMU_OscillatorEnable(cmuOsc_LFRCO, true, true);
    CMU_ClockSelectSet(cmuClock_LFA, cmuSelect_LFRCO);
    CMU_ClockSelectSet(cmuClock_LFB, cmuSelect_LFRCO);
    RTCDRV_Init();
    halInternalStartSymbolTimer();    // TODO: move to macInit or emRadioInit
#endif
    /* Configure board. Select either EBI or SPI mode. */
#ifdef _EFR_DEVICE
    TRACE_Config_t traceConfig;
    traceConfig.setEventFuncPtr = NULL;
    CHIP_Init();
    halInternalInitButton();
    halInternalInitBoard();
    CMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFXO);
    CMU_OscillatorEnable(cmuOsc_LFRCO, true, true);
    CMU_ClockSelectSet(cmuClock_LFA, cmuSelect_LFRCO);
    CMU_ClockSelectSet(cmuClock_LFB, cmuSelect_LFRCO);
    CMU_ClockEnable(cmuClock_CORELE, true);
    TRACE_Init(&traceConfig);

    RTCDRV_Init();
    // GRAPHICS_Init();
    // GRAPHICS_ShowStatus();
#ifndef DISABLE_WATCHDOG
    halInternalEnableWatchDog();
#endif
#endif

    halInternalStartSystemTimer();
}
Ejemplo n.º 24
0
/*
 * Function Name: main();
 * Description: All the function calls are done in main(). The CPU goes to sleep while in main(); until Interupt is generated.
 */
int main(void)
{

    CHIP_Init();

    CMU_HFRCOBandSet(cmuHFRCOBand_14MHz);
    CMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFRCO);
    CMU_OscillatorEnable(cmuOsc_HFXO, false, false);

    blockSleepMode(EM2); //Prevents the CPU to go below EM3 mode.

#if DEBUG_ON
    BSP_TraceSwoSetup(); //For simplicity studio Energy profiler code correlation.
#endif
    LETIMER_setup(); //Initialize LETIMER.

    ADC_Setup(); //Initialize the ADC

    DMA_Init();	//Initialize DMA.

    DMA_Setup(); //Setup DMA.

    LEUART_Setup(); //Initialize LEUART.

    GPIO_Init(); //Initialize GPOIs.

    LETIMER_IntEnable(LETIMER0, LETIMER_IF_UF); //Enable underflow UF interrupt.

    LEUART_IntEnable(LEUART0, LEUART_IF_SIGF);	// Enable SF RXDATAV

    NVIC_EnableIRQ(LETIMER0_IRQn); //Enable LETIMER0 interrupt vector in NVIC (Nested Vector Interrupt Controller)

    NVIC_EnableIRQ(LEUART0_IRQn); //Enable LETIMER0 interrupt vector in NVIC (Nested Vector Interrupt Controller)

	LEUART0->SIGFRAME = '!';							// Set LEUART signal frame to '!'

	LEUART0->CTRL |= LEUART_CTRL_RXDMAWU;				// Enable DMA wake up for LEUART RX in EM2
    DMA_ActivateBasic(DMA_CHANNEL_RX, true, false, (void *)RX_Buffer, (void *)&(LEUART0->RXDATA), LEUART0_BUFFER-1);

    // Enable Sleep-on-Exit
#if SLEEPONEXIT
    SCB->SCR |= SCB_SCR_SLEEPONEXIT_Msk;	// Setting the corresponding bit for SleepOnExit
#endif

    while(1)
    {
        sleep(); //CPU goes to EM3 Mode to save energy, waits there until Interrupt is generated.
    }

}
Ejemplo n.º 25
0
/**************************************************************************//**
 * @brief main - the entrypoint after reset.
 *****************************************************************************/
int main( void )
{
    CHIP_Init();
    /* If first word of user data page is non-zero, enable eA Profiler trace */
    BSP_TraceProfilerSetup();

    CMU_ClockSelectSet( cmuClock_HF, cmuSelect_HFXO );
    CMU_OscillatorEnable(cmuOsc_LFXO, true, false);

    /* Initialize LCD driver */
    SegmentLCD_Init(false);
    SegmentLCD_Write("usbcomp");
    SegmentLCD_Symbol(LCD_SYMBOL_GECKO, true);

    /* Initialize LED driver */
    BSP_LedsInit();

    /* Initialize SLEEP driver, no calbacks are used */
    SLEEP_Init(NULL, NULL);
#if (configSLEEP_MODE < 3)
    /* do not let to sleep deeper than define */
    SLEEP_SleepBlockBegin((SLEEP_EnergyMode_t)(configSLEEP_MODE + 1));
#endif

    /* Parameters value for taks*/
    static LedTaskParams_t parametersToTask1 = { 1000 / portTICK_RATE_MS, 0 };
    static LedTaskParams_t parametersToTask2 = { 500 / portTICK_RATE_MS, 1 };

    static AdcTaskParams_t parametersToAdc =
    {
        .adcChannelsMask = 0x32,
        .uPrsChannel = 5,
        .uSampleRate = 1,
        .uTimer = 3
    };

    /*Create two task for blinking leds*/
    xTaskCreate( UsbCDCTask, "UsbCDC", STACK_SIZE_FOR_TASK, NULL, TASK_PRIORITY, NULL);
//   xTaskCreate( LedTask, (const char *) "LedBlink1", STACK_SIZE_FOR_TASK, &parametersToTask1, TASK_PRIORITY, NULL);
//   xTaskCreate( LedTask, (const char *) "LedBlink2", STACK_SIZE_FOR_TASK, &parametersToTask2, TASK_PRIORITY, NULL);
    xTaskCreate( vAdcTask, "ADC", STACK_SIZE_FOR_TASK, &parametersToAdc, TASK_PRIORITY + 1, NULL);
    xTaskCreate( vDacTask, "DAC", STACK_SIZE_FOR_TASK, NULL, TASK_PRIORITY, NULL);
    xTaskCreate( vEchoTask, "echo", STACK_SIZE_FOR_TASK, NULL, TASK_PRIORITY, NULL);

    NVIC_SetPriority(USB_IRQn, 7);
    NVIC_SetPriority(ADC0_IRQn, 7);
    vTaskStartScheduler();
}
/**************************************************************************//**
 * @brief  Start LFRCO for RTC
 * Starts the low frequency RC oscillator (LFRCO) and routes it to the RTC
 *****************************************************************************/
void startLfxoForRtc(uint8_t freq)
{
    /* Starting LFRCO and waiting until it is stable */
    CMU_OscillatorEnable(cmuOsc_LFXO, true, true);

    /* Routing the LFRCO clock to the RTC */
    CMU_ClockSelectSet(cmuClock_LFA,cmuSelect_LFXO);
    CMU_ClockEnable(cmuClock_RTC, true);

    /* Set Clock prescaler */
    if(freq == HWTIMER_FREQ_1MS)
    	CMU_ClockDivSet(cmuClock_RTC, cmuClkDiv_32);
    else
    	CMU_ClockDivSet(cmuClock_RTC, cmuClkDiv_1);

    /* Enabling clock to the interface of the low energy modules */
    CMU_ClockEnable(cmuClock_CORELE, true);
}
Ejemplo n.º 27
0
/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void)
{
  /* Initialize chip */
  CHIP_Init();
  
  setupSWO();

  /* Enable HFXO */
  CMU_OscillatorEnable(cmuOsc_HFXO, true, true);

  /* Switch HFCLK to HFXO */
  CMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFXO);

  /* Turn off HFRCO */
  CMU_OscillatorEnable(cmuOsc_HFRCO, false, false);

  BSP_LedsInit();

  while (1)
  {
    /* Blink led three times, with a factor 1 million delay */
    blink_led(1000000, 3);

    /* Turn on LFRCO */
    CMU_OscillatorEnable(cmuOsc_LFRCO, true, true);

    /* Select LFRCO */
    CMU_ClockSelectSet(cmuClock_HF, cmuSelect_LFRCO);

    /* Maximum prescaling for smalles frequency (64 Hz) */
    CMU_ClockDivSet(cmuClock_CORE, cmuClkDiv_512);

    /* Turn off HFXO */
    CMU_OscillatorEnable(cmuOsc_HFXO, false, false);

    /* Blink led three times, with a factor 1 delay */
    blink_led(1, 3);

    /* Turn on HFXO */
    CMU_OscillatorEnable(cmuOsc_HFXO, true, true);

    /* Select HFXO */
    CMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFXO);

    /* No prescaling for maximum clock frequency (32 MHz) */
    CMU_ClockDivSet(cmuClock_CORE, cmuClkDiv_1);

    /* Turn off LFRCO */
    CMU_OscillatorEnable(cmuOsc_LFRCO, false, false);
  }
}
Ejemplo n.º 28
0
/**************************************************************************//**
 * @brief main - the entrypoint after reset.
 *****************************************************************************/
int main( void )
{
#if !defined(BUSPOWERED)
  BSP_Init(BSP_INIT_DEFAULT);   /* Initialize DK board register access */

  /* If first word of user data page is non-zero, enable eA Profiler trace */
  BSP_TraceProfilerSetup();
#endif

  CMU_ClockSelectSet( cmuClock_HF, cmuSelect_HFXO );
  CMU_OscillatorEnable(cmuOsc_LFXO, true, false);

#if !defined(BUSPOWERED)
  RETARGET_SerialInit();        /* Initialize DK UART port */
  RETARGET_SerialCrLf( 1 );     /* Map LF to CRLF          */
  printf( "\nEFM32 Mass Storage Device example\n" );
#endif

  if ( !MSDDMEDIA_Init() )
  {
#if !defined(BUSPOWERED)
    printf( "\nMedia error !\n" );
#endif
    EFM_ASSERT( false );
    for( ;; ){}
  }

  MSDD_Init(gpioPortE, 1);

  for (;;)
  {
    if ( MSDD_Handler() )
    {
      /* There is no pending activity in the MSDD handler.  */
      /* Enter sleep mode to conserve energy.               */

      if ( USBD_SafeToEnterEM2() )
        EMU_EnterEM2(true);
      else
        EMU_EnterEM1();
    }
  }
}
void system_init(uint8_t* tx_buffer, uint16_t tx_buffer_size, uint8_t* rx_buffer, uint16_t rx_buffer_size)
{
    /* Chip errata */
    CHIP_Init();

    //if (SysTick_Config(CMU_ClockFreqGet(cmuClock_CORE) / 1000)) while (1) ;

    // init clock
    CMU_ClockDivSet(cmuClock_HF, cmuClkDiv_2);       // Set HF clock divider to /2 to keep core frequency < 32MHz
    CMU_OscillatorEnable(cmuOsc_HFXO, true, true);   // Enable XTAL Osc and wait to stabilize
    CMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFXO); // Select HF XTAL osc as system clock source. 48MHz XTAL, but we divided the system clock by 2, therefore our HF clock will be 24MHz

    led_init();
    //button_init();
    uart_init();

    // TODO not hardware specific
    queue_init_with_header(&tx_queue, tx_buffer, tx_buffer_size, 1, 30);
    queue_init(&rx_queue, rx_buffer, rx_buffer_size, 1);
}
Ejemplo n.º 30
0
Archivo: main.c Proyecto: Eclo/FreeRTOS
static void prvSetupHardware( void )
{
EMU_DCDCInit_TypeDef xDCDInit = EMU_DCDCINIT_STK_DEFAULT;
CMU_HFXOInit_TypeDef xHFXOInit = CMU_HFXOINIT_STK_DEFAULT;

	/* Chip errata */
	CHIP_Init();

	/* Init DCDC regulator and HFXO with kit specific parameters */
	EMU_DCDCInit( &xDCDInit );
	CMU_HFXOInit( &xHFXOInit );

	/* Switch HFCLK to HFXO and disable HFRCO */
	CMU_ClockSelectSet( cmuClock_HF, cmuSelect_HFXO );
	CMU_OscillatorEnable( cmuOsc_HFRCO, false, false );

	/* Initialize LED driver. */
	BSP_LedsInit();
	BSP_LedSet( 0 );
	BSP_LedClear( 1 );
}