source: rtems/c/src/lib/libbsp/powerpc/mpc55xxevb/startup/start-clock.c @ 32ec0f6b

4.115
Last change on this file since 32ec0f6b was 32ec0f6b, checked in by Sebastian Huber <sebastian.huber@…>, on 07/17/12 at 14:56:58

bsp/mpc55xx: Add MPC55XX_NEEDS_LOW_LEVEL_INIT

  • Property mode set to 100644
File size: 2.5 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup mpc55xx
5 *
6 * @brief Clock and FMPLL initialization code.
7 */
8
9/*
10 * Copyright (c) 2008-2011 embedded brains GmbH.  All rights reserved.
11 *
12 *  embedded brains GmbH
13 *  Obere Lagerstr. 30
14 *  82178 Puchheim
15 *  Germany
16 *  <rtems@embedded-brains.de>
17 *
18 * The license and distribution terms for this file may be
19 * found in the file LICENSE in this distribution or at
20 * http://www.rtems.com/license/LICENSE.
21 */
22
23#include <bsp.h>
24#include <bsp/start.h>
25#include <bsp/bootcard.h>
26#include <bsp/mpc55xx-config.h>
27
28#ifdef MPC55XX_NEEDS_LOW_LEVEL_INIT
29  #if defined(MPC55XX_HAS_FMPLL) || defined(MPC55XX_HAS_FMPLL_ENHANCED)
30    static BSP_START_TEXT_SECTION void fmpll_wait_for_lock(void)
31    {
32      int i = 0;
33      bool lock = false;
34
35      while (!lock && i < 6000) {
36        lock = FMPLL.SYNSR.B.LOCK != 0;
37        ++i;
38      }
39
40      if (!lock) {
41        bsp_reset();
42      }
43    }
44  #endif
45#endif
46
47BSP_START_TEXT_SECTION void mpc55xx_start_clock(void)
48{
49  #ifdef MPC55XX_NEEDS_LOW_LEVEL_INIT
50    const mpc55xx_clock_config *cfg = mpc55xx_start_config_clock;
51
52    #ifdef MPC55XX_HAS_FMPLL
53      volatile struct FMPLL_tag *fmpll = &FMPLL;
54
55      fmpll->SYNCR.R = cfg->syncr_tmp.R;
56      fmpll->SYNCR.R;
57      fmpll_wait_for_lock();
58
59      fmpll->SYNCR.R = cfg->syncr_final.R;
60      fmpll->SYNCR.R;
61      fmpll_wait_for_lock();
62    #endif
63
64    #ifdef MPC55XX_HAS_FMPLL_ENHANCED
65      volatile struct FMPLL_tag *fmpll = &FMPLL;
66
67      fmpll->ESYNCR2.R = cfg->esyncr2_tmp.R;
68      fmpll->ESYNCR2.R;
69      fmpll->ESYNCR1.R = cfg->esyncr1_final.R;
70      fmpll->ESYNCR1.R;
71      fmpll_wait_for_lock();
72
73      fmpll->ESYNCR2.R = cfg->esyncr2_final.R;
74      fmpll->ESYNCR2.R;
75      fmpll_wait_for_lock();
76
77      #if MPC55XX_CHIP_TYPE / 10 == 551
78        /* System clock supplied by PLL */
79        SIU.SYSCLK.B.SYSCLKSEL = 2;
80      #endif
81    #endif
82
83    #ifdef MPC55XX_HAS_MODE_CONTROL
84      volatile CGM_tag *cgm = &CGM;
85      size_t fmpll_count = sizeof(cfg->fmpll) / sizeof(cfg->fmpll [0]);
86      size_t auxclk_count = sizeof(cfg->auxclk) / sizeof(cfg->auxclk [0]);
87      size_t i = 0;
88
89      for (i = 0; i < auxclk_count; ++i) {
90        cgm->AUXCLK [i].AC_SC.R = cfg->auxclk [i].AC_SC.R;
91        cgm->AUXCLK [i].AC_DC0_3.R = cfg->auxclk [i].AC_DC0_3.R;
92      }
93
94      for (i = 0; i < fmpll_count; ++i) {
95        cgm->FMPLL [i].CR.R = cfg->fmpll [i].cr.R;
96        cgm->FMPLL [i].MR.R = cfg->fmpll [i].mr.R;
97      }
98
99      cgm->OC_EN.R = cfg->oc_en.R;
100      cgm->OCDS_SC.R = cfg->ocds_sc.R;
101    #endif
102  #endif
103}
Note: See TracBrowser for help on using the repository browser.