Blame view

RIOT/cpu/ezr32wg/cpu.c 1.82 KB
a752c7ab   elopes   add first test an...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
  /*
   * Copyright (C) 2015 Freie Universitรคt Berlin
   *
   * This file is subject to the terms and conditions of the GNU Lesser
   * General Public License v2.1. See the file LICENSE in the top level
   * directory for more details.
   */
  
  /**
   * @ingroup     cpu_ezr32wg
   * @{
   *
   * @file
   * @brief       Implementation of the CPU initialization
   *
   * @author      Hauke Petersen <hauke.petersen@fu-berlin.de>
   * @}
   */
  
  #include "cpu.h"
  #include "periph_conf.h"
  #include "periph/init.h"
  
  /**
   * @brief   Configure clock sources and the CPU frequency
   *
   * On the ezr32wg cpu, we basically have two options for selecting the main
   * clock source, using an external clock source (e.g. a crystal), or using the
   * internal RC oscillator (enabled by default).
   */
  static void clk_init(void)
  {
      /* reset the clock to it's default values */
      CMU->CTRL = _CMU_CTRL_RESETVALUE;
  
  #ifdef CLOCK_HFXO
      /* configure clock system for external oscillator */
  #if CLOCK_HFXO > 32000000
      CMU->CTRL |= CMU_CTRL_HFXOBUFCUR_BOOSTABOVE32MHZ;
  #endif
      /* enable the oscillator */
      CMU->OSCENCMD = CMU_OSCENCMD_HFXOEN;
      /* wait for external oscillator to be stable */
      while (!(CMU->STATUS & CMU_STATUS_HFXORDY));
      /* switch to the external oscillator */
      CMU->CMD = CMU_CMD_HFCLKSEL_HFXO;
      /* wait until clock source is applied */
      while (!(CMU->STATUS & CMU_STATUS_HFXOSEL));
  #endif
  
      /* set the core clock divider */
      CMU->HFCORECLKDIV = (CLOCK_HFCORECLKDIV - 1);
      /* configure the high speed peripheral clock: set divider and enable it */
      CMU->HFPERCLKDIV = (CMU_HFPERCLKDIV_HFPERCLKEN | (CLOCK_HFPERCLKDIV - 1));
  }
  
  void cpu_init(void)
  {
      /* initialize the Cortex-M core */
      cortexm_init();
      /* Initialise clock sources and generic clocks */
      clk_init();
      /* trigger static peripheral initialization */
      periph_init();
  }