source: rtems/c/src/lib/libbsp/arm/csb336/startup/bspstart.c @ cf1d667

4.115
Last change on this file since cf1d667 was cf1d667, checked in by Ralf Corsepius <ralf.corsepius@…>, on 02/11/11 at 11:42:31

2011-02-11 Ralf Corsépius <ralf.corsepius@…>

  • startup/bspstart.c: Use "asm" instead of "asm" for improved c99-compliance.
  • Property mode set to 100644
File size: 3.4 KB
Line 
1/*
2 * Cogent CSB336 - MC9328MXL SBC startup code
3 *
4 * Copyright (c) 2004 by Cogent Computer Systems
5 * Written by Jay Monkman <jtm@lopingdog.com>
6 *
7 * The license and distribution terms for this file may be
8 * found in the file LICENSE in this distribution or at
9 * http://www.rtems.com/license/LICENSE.
10 *
11 *  $Id$
12 */
13
14#include <bsp.h>
15#include <bsp/irq-generic.h>
16#include <rtems/bspIo.h>
17#include <mc9328mxl.h>
18
19extern void rtems_exception_init_mngt(void);
20
21extern void mmu_set_cpu_async_mode(void);
22
23/*
24 * bsp_start_default - BSP initialization function
25 *
26 *   This function is called before RTEMS is initialized and used
27 *   adjust the kernel's configuration.
28 *
29 *   This function also configures the CPU's memory protection unit.
30 *
31 * RESTRICTIONS/LIMITATIONS:
32 *   Since RTEMS is not configured, no RTEMS functions can be called.
33 *
34 */
35void bsp_start_default( void )
36{
37  int i;
38
39  /* Set the MCU prescaler to divide by 1 */
40  MC9328MXL_PLL_CSCR &= ~MC9328MXL_PLL_CSCR_PRESC;
41
42  /* Enable the MCU PLL */
43  MC9328MXL_PLL_CSCR |= MC9328MXL_PLL_CSCR_MPEN;
44
45  /* Delay to allow time for PLL to get going */
46  for (i = 0; i < 100; i++) {
47    __asm__ volatile ("nop\n");
48  }
49
50  /* Set the CPU to asynchrous clock mode, so it uses its fastest clock */
51  mmu_set_cpu_async_mode();
52
53  /* disable interrupts */
54  MC9328MXL_AITC_INTENABLEL = 0;
55  MC9328MXL_AITC_INTENABLEH = 0;
56
57  /* Set interrupt priority to -1 (allow all priorities) */
58  MC9328MXL_AITC_NIMASK = 0x1f;
59
60  /*
61   * Init rtems exceptions management
62   */
63  rtems_exception_init_mngt();
64
65  /*
66   * Init rtems interrupt management
67   */
68  if (bsp_interrupt_initialize() != RTEMS_SUCCESSFUL) {
69    _CPU_Fatal_halt(0xe);
70  }
71} /* bsp_start */
72
73/* Calcuate the frequency for perclk1 */
74int get_perclk1_freq(void)
75{
76  unsigned int fin;
77  unsigned int fpll;
78  unsigned int pd;
79  unsigned int mfd;
80  unsigned int mfi;
81  unsigned int mfn;
82  uint32_t reg;
83  int perclk1;
84
85  if (MC9328MXL_PLL_CSCR & MC9328MXL_PLL_CSCR_SYSSEL) {
86    /* Use external oscillator */
87    fin = BSP_OSC_FREQ;
88  } else {
89    /* Use scaled xtal freq */
90    fin = BSP_XTAL_FREQ * 512;
91  }
92
93  /* calculate the output of the system PLL */
94  reg = MC9328MXL_PLL_SPCTL0;
95  pd = ((reg & MC9328MXL_PLL_SPCTL_PD_MASK) >>
96        MC9328MXL_PLL_SPCTL_PD_SHIFT);
97  mfd = ((reg & MC9328MXL_PLL_SPCTL_MFD_MASK) >>
98         MC9328MXL_PLL_SPCTL_MFD_SHIFT);
99  mfi = ((reg & MC9328MXL_PLL_SPCTL_MFI_MASK) >>
100         MC9328MXL_PLL_SPCTL_MFI_SHIFT);
101  mfn = ((reg & MC9328MXL_PLL_SPCTL_MFN_MASK) >>
102         MC9328MXL_PLL_SPCTL_MFN_SHIFT);
103
104#if 0
105  printk("fin = %d\n", fin);
106  printk("pd = %d\n", pd);
107  printk("mfd = %d\n", mfd);
108  printk("mfi = %d\n", mfi);
109  printk("mfn = %d\n", mfn);
110  printk("rounded (fin * mfi) / (pd + 1) = %d\n", (fin * mfi) / (pd + 1));
111  printk("rounded (fin * mfn) / ((pd + 1) * (mfd + 1)) = %d\n",
112         ((long long)fin * mfn) / ((pd + 1) * (mfd + 1)));
113#endif
114
115  fpll = 2 * ( ((fin * mfi  + (pd + 1) / 2) / (pd + 1)) +
116               (((long long)fin * mfn + ((pd + 1) * (mfd + 1)) / 2) /
117               ((pd + 1) * (mfd + 1))) );
118
119  /* calculate the output of the PERCLK1 divider */
120  reg = MC9328MXL_PLL_PCDR;
121  perclk1 = fpll / (1 + ((reg & MC9328MXL_PLL_PCDR_PCLK1_MASK) >>
122                         MC9328MXL_PLL_PCDR_PCLK1_SHIFT));
123
124  return perclk1;
125}
126
127/*
128 *  By making this a weak alias for bsp_start_default, a brave soul
129 *  can override the actual bsp_start routine used.
130 */
131void bsp_start (void) __attribute__ ((weak, alias("bsp_start_default")));
132
Note: See TracBrowser for help on using the repository browser.