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 <rtems/bspIo.h> |
---|
16 | #include <mc9328mxl.h> |
---|
17 | |
---|
18 | extern void rtems_irq_mngt_init(void); |
---|
19 | extern void mmu_set_cpu_async_mode(void); |
---|
20 | |
---|
21 | /* |
---|
22 | * bsp_start_default - BSP initialization function |
---|
23 | * |
---|
24 | * This function is called before RTEMS is initialized and used |
---|
25 | * adjust the kernel's configuration. |
---|
26 | * |
---|
27 | * This function also configures the CPU's memory protection unit. |
---|
28 | * |
---|
29 | * RESTRICTIONS/LIMITATIONS: |
---|
30 | * Since RTEMS is not configured, no RTEMS functions can be called. |
---|
31 | * |
---|
32 | */ |
---|
33 | void bsp_start_default( void ) |
---|
34 | { |
---|
35 | int i; |
---|
36 | |
---|
37 | /* Set the MCU prescaler to divide by 1 */ |
---|
38 | MC9328MXL_PLL_CSCR &= ~MC9328MXL_PLL_CSCR_PRESC; |
---|
39 | |
---|
40 | /* Enable the MCU PLL */ |
---|
41 | MC9328MXL_PLL_CSCR |= MC9328MXL_PLL_CSCR_MPEN; |
---|
42 | |
---|
43 | /* Delay to allow time for PLL to get going */ |
---|
44 | for (i = 0; i < 100; i++) { |
---|
45 | asm volatile ("nop\n"); |
---|
46 | } |
---|
47 | |
---|
48 | /* Set the CPU to asynchrous clock mode, so it uses its fastest clock */ |
---|
49 | mmu_set_cpu_async_mode(); |
---|
50 | |
---|
51 | /* disable interrupts */ |
---|
52 | MC9328MXL_AITC_INTENABLEL = 0; |
---|
53 | MC9328MXL_AITC_INTENABLEH = 0; |
---|
54 | |
---|
55 | /* Set interrupt priority to -1 (allow all priorities) */ |
---|
56 | MC9328MXL_AITC_NIMASK = 0x1f; |
---|
57 | |
---|
58 | /* |
---|
59 | * Init rtems exceptions management |
---|
60 | */ |
---|
61 | rtems_exception_init_mngt(); |
---|
62 | |
---|
63 | /* |
---|
64 | * Init rtems interrupt management |
---|
65 | */ |
---|
66 | rtems_irq_mngt_init(); |
---|
67 | } /* bsp_start */ |
---|
68 | |
---|
69 | /* Calcuate the frequency for perclk1 */ |
---|
70 | int get_perclk1_freq(void) |
---|
71 | { |
---|
72 | unsigned int fin; |
---|
73 | unsigned int fpll; |
---|
74 | unsigned int pd; |
---|
75 | unsigned int mfd; |
---|
76 | unsigned int mfi; |
---|
77 | unsigned int mfn; |
---|
78 | uint32_t reg; |
---|
79 | int perclk1; |
---|
80 | |
---|
81 | if (MC9328MXL_PLL_CSCR & MC9328MXL_PLL_CSCR_SYSSEL) { |
---|
82 | /* Use external oscillator */ |
---|
83 | fin = BSP_OSC_FREQ; |
---|
84 | } else { |
---|
85 | /* Use scaled xtal freq */ |
---|
86 | fin = BSP_XTAL_FREQ * 512; |
---|
87 | } |
---|
88 | |
---|
89 | /* calculate the output of the system PLL */ |
---|
90 | reg = MC9328MXL_PLL_SPCTL0; |
---|
91 | pd = ((reg & MC9328MXL_PLL_SPCTL_PD_MASK) >> |
---|
92 | MC9328MXL_PLL_SPCTL_PD_SHIFT); |
---|
93 | mfd = ((reg & MC9328MXL_PLL_SPCTL_MFD_MASK) >> |
---|
94 | MC9328MXL_PLL_SPCTL_MFD_SHIFT); |
---|
95 | mfi = ((reg & MC9328MXL_PLL_SPCTL_MFI_MASK) >> |
---|
96 | MC9328MXL_PLL_SPCTL_MFI_SHIFT); |
---|
97 | mfn = ((reg & MC9328MXL_PLL_SPCTL_MFN_MASK) >> |
---|
98 | MC9328MXL_PLL_SPCTL_MFN_SHIFT); |
---|
99 | |
---|
100 | #if 0 |
---|
101 | printk("fin = %d\n", fin); |
---|
102 | printk("pd = %d\n", pd); |
---|
103 | printk("mfd = %d\n", mfd); |
---|
104 | printk("mfi = %d\n", mfi); |
---|
105 | printk("mfn = %d\n", mfn); |
---|
106 | printk("rounded (fin * mfi) / (pd + 1) = %d\n", (fin * mfi) / (pd + 1)); |
---|
107 | printk("rounded (fin * mfn) / ((pd + 1) * (mfd + 1)) = %d\n", |
---|
108 | ((long long)fin * mfn) / ((pd + 1) * (mfd + 1))); |
---|
109 | #endif |
---|
110 | |
---|
111 | fpll = 2 * ( ((fin * mfi + (pd + 1) / 2) / (pd + 1)) + |
---|
112 | (((long long)fin * mfn + ((pd + 1) * (mfd + 1)) / 2) / |
---|
113 | ((pd + 1) * (mfd + 1))) ); |
---|
114 | |
---|
115 | /* calculate the output of the PERCLK1 divider */ |
---|
116 | reg = MC9328MXL_PLL_PCDR; |
---|
117 | perclk1 = fpll / (1 + ((reg & MC9328MXL_PLL_PCDR_PCLK1_MASK) >> |
---|
118 | MC9328MXL_PLL_PCDR_PCLK1_SHIFT)); |
---|
119 | |
---|
120 | return perclk1; |
---|
121 | } |
---|
122 | |
---|
123 | /* |
---|
124 | * By making this a weak alias for bsp_start_default, a brave soul |
---|
125 | * can override the actual bsp_start routine used. |
---|
126 | */ |
---|
127 | void bsp_start (void) __attribute__ ((weak, alias("bsp_start_default"))); |
---|
128 | |
---|
129 | /** |
---|
130 | * Reset the system. |
---|
131 | * |
---|
132 | * This functions enables the watchdog and waits for it to |
---|
133 | * fire, thus resetting the system. |
---|
134 | */ |
---|
135 | void bsp_reset(void) |
---|
136 | { |
---|
137 | rtems_interrupt_level level; |
---|
138 | |
---|
139 | _CPU_ISR_Disable(level); |
---|
140 | |
---|
141 | printk("\n\rI should reset here.\n\r"); |
---|
142 | while(1); |
---|
143 | } |
---|