1 | /* bspstart.c for bf537Stamp |
---|
2 | * |
---|
3 | * This routine starts the application. It includes application, |
---|
4 | * board, and monitor specific initialization and configuration. |
---|
5 | * The generic CPU dependent initialization has been performed |
---|
6 | * before this routine is invoked. |
---|
7 | * |
---|
8 | * Copyright (c) 2006 by Atos Automacao Industrial Ltda. |
---|
9 | * written by Alain Schaefer <alain.schaefer@easc.ch> |
---|
10 | * and Antonio Giovanini <antonio@atos.com.br> |
---|
11 | * |
---|
12 | * The license and distribution terms for this file may be |
---|
13 | * found in the file LICENSE in this distribution or at |
---|
14 | * http://www.rtems.com/license/LICENSE. |
---|
15 | * |
---|
16 | * $Id$ |
---|
17 | */ |
---|
18 | |
---|
19 | |
---|
20 | #include <string.h> |
---|
21 | |
---|
22 | #include <rtems/libio.h> |
---|
23 | #include <rtems/libcsupport.h> |
---|
24 | #include <libcpu/bf537.h> |
---|
25 | #include <libcpu/gpioRegs.h> |
---|
26 | #include <libcpu/mmu.h> |
---|
27 | #include <libcpu/interrupt.h> |
---|
28 | #include <bsp.h> |
---|
29 | |
---|
30 | |
---|
31 | #if 0 |
---|
32 | static bfin_mmu_region_t mmuRegions[] = { |
---|
33 | }; |
---|
34 | #endif |
---|
35 | |
---|
36 | /* |
---|
37 | * Use the shared implementations of the following routines |
---|
38 | */ |
---|
39 | |
---|
40 | void bsp_postdriver_hook(void); |
---|
41 | void bsp_libc_init(void *, uint32_t, int); |
---|
42 | |
---|
43 | void Init_RTC(void); |
---|
44 | |
---|
45 | static void initPLL(void); |
---|
46 | static void initEBIU(void); |
---|
47 | static void initGPIO(void); |
---|
48 | |
---|
49 | /* |
---|
50 | * Function: bsp_pretasking_hook |
---|
51 | * Created: 95/03/10 |
---|
52 | * |
---|
53 | * Description: |
---|
54 | * BSP pretasking hook. Called just before drivers are initialized. |
---|
55 | * Used to setup libc and install any BSP extensions. |
---|
56 | * |
---|
57 | * NOTES: |
---|
58 | * Must not use libc (to do io) from here, since drivers are |
---|
59 | * not yet initialized. |
---|
60 | * |
---|
61 | */ |
---|
62 | |
---|
63 | void bsp_pretasking_hook(void) { |
---|
64 | extern int HeapBase; |
---|
65 | extern int RamBase; |
---|
66 | extern int RamSize; |
---|
67 | unsigned long heapSize; |
---|
68 | void *heapStart; |
---|
69 | |
---|
70 | bfin_interrupt_init(); |
---|
71 | |
---|
72 | heapStart = &HeapBase; |
---|
73 | heapSize = (unsigned long) &RamBase; |
---|
74 | heapSize += (unsigned long) &RamSize; |
---|
75 | heapSize -= (unsigned long) &HeapBase; |
---|
76 | |
---|
77 | bsp_libc_init(heapStart, heapSize, 0); |
---|
78 | |
---|
79 | } |
---|
80 | |
---|
81 | /* |
---|
82 | * bsp_start |
---|
83 | * |
---|
84 | * This routine does the bulk of the system initialization. |
---|
85 | */ |
---|
86 | void bsp_start(void) { |
---|
87 | |
---|
88 | extern void *_WorkspaceBase; |
---|
89 | |
---|
90 | /* BSP Hardware Initialization*/ |
---|
91 | |
---|
92 | /*bfin_mmu_init(sizeof(mmuRegions) / sizeof(mmuRegions[0]), mmuRegions);*/ |
---|
93 | |
---|
94 | Init_RTC(); /* Blackfin Real Time Clock initialization */ |
---|
95 | |
---|
96 | initPLL(); /* PLL initialization */ |
---|
97 | initEBIU(); /* EBIU initialization */ |
---|
98 | initGPIO(); /* GPIO initialization */ |
---|
99 | |
---|
100 | /* |
---|
101 | * Allocate the memory for the RTEMS Work Space. This can come from |
---|
102 | * a variety of places: hard coded address, malloc'ed from outside |
---|
103 | * RTEMS world (e.g. simulator or primitive memory manager), or (as |
---|
104 | * typically done by stock BSPs) by subtracting the required amount |
---|
105 | * of work space from the last physical address on the CPU board. |
---|
106 | */ |
---|
107 | |
---|
108 | /* |
---|
109 | * Need to "allocate" the memory for the RTEMS Workspace and |
---|
110 | * tell the RTEMS configuration where it is. This memory is |
---|
111 | * not malloc'ed. It is just "pulled from the air". |
---|
112 | */ |
---|
113 | |
---|
114 | Configuration.work_space_start = (void *) &_WorkspaceBase; |
---|
115 | |
---|
116 | } |
---|
117 | |
---|
118 | /* |
---|
119 | * initPLL |
---|
120 | * |
---|
121 | * Routine to initialize the PLL. The BF537 Stamp uses a 27 Mhz XTAL. BISON |
---|
122 | * See "../bf537Stamp/include/bsp.h" for more information. |
---|
123 | */ |
---|
124 | |
---|
125 | static void initPLL(void) { |
---|
126 | |
---|
127 | #ifdef BISON |
---|
128 | unsigned int n; |
---|
129 | |
---|
130 | /* Configure PLL registers */ |
---|
131 | *((uint16_t*)PLL_LOCKCNT) = 0x1000; |
---|
132 | *((uint16_t*)PLL_DIV) = PLL_CSEL|PLL_SSEL; |
---|
133 | *((uint16_t*)PLL_CTL) = PLL_MSEL|PLL_DF; |
---|
134 | |
---|
135 | /* Commands to set PLL values */ |
---|
136 | asm("cli r0;"); |
---|
137 | asm("idle;"); |
---|
138 | asm("sti r0;"); |
---|
139 | |
---|
140 | /* Delay for PLL stabilization */ |
---|
141 | for (n=0; n<200; n++) {} |
---|
142 | #endif |
---|
143 | |
---|
144 | } |
---|
145 | |
---|
146 | /* |
---|
147 | * initEBIU |
---|
148 | * |
---|
149 | * Configure extern memory |
---|
150 | */ |
---|
151 | |
---|
152 | static void initEBIU(void) { |
---|
153 | #ifdef BISON |
---|
154 | /* Configure FLASH */ |
---|
155 | *((uint32_t*)EBIU_AMBCTL0) = 0x7bb07bb0L; |
---|
156 | *((uint32_t*)EBIU_AMBCTL1) = 0x7bb07bb0L; |
---|
157 | *((uint16_t*)EBIU_AMGCTL) = 0x000f; |
---|
158 | |
---|
159 | /* Configure SDRAM |
---|
160 | *((uint32_t*)EBIU_SDGCTL) = 0x0091998d; |
---|
161 | *((uint16_t*)EBIU_SDBCTL) = 0x0013; |
---|
162 | *((uint16_t*)EBIU_SDRRC) = 0x0817; |
---|
163 | */ |
---|
164 | #endif |
---|
165 | } |
---|
166 | |
---|
167 | /* |
---|
168 | * initGPIO |
---|
169 | * |
---|
170 | * Enable LEDs port |
---|
171 | */ |
---|
172 | static void initGPIO(void) { |
---|
173 | |
---|
174 | *(uint16_t volatile *) PORT_MUX = 0; |
---|
175 | |
---|
176 | /* port f bits 0, 1: uart0 tx, rx */ |
---|
177 | /* bits 2 - 5: buttons */ |
---|
178 | /* bits 6 - 11: leds */ |
---|
179 | *(uint16_t volatile *) PORTF_FER = 0x0003; |
---|
180 | *(uint16_t volatile *) (PORTFIO_BASE_ADDRESS + PORTIO_OFFSET) = 0x0000; |
---|
181 | *(uint16_t volatile *) (PORTFIO_BASE_ADDRESS + PORTIO_INEN_OFFSET) = 0x003c; |
---|
182 | *(uint16_t volatile *) (PORTFIO_BASE_ADDRESS + PORTIO_POLAR_OFFSET) = 0x0000; |
---|
183 | *(uint16_t volatile *) (PORTFIO_BASE_ADDRESS + PORTIO_EDGE_OFFSET) = 0x0000; |
---|
184 | *(uint16_t volatile *) (PORTFIO_BASE_ADDRESS + PORTIO_BOTH_OFFSET) = 0x0000; |
---|
185 | *(uint16_t volatile *) (PORTFIO_BASE_ADDRESS + PORTIO_MASKA_OFFSET) = 0x0000; |
---|
186 | *(uint16_t volatile *) (PORTFIO_BASE_ADDRESS + PORTIO_MASKB_OFFSET) = 0x0000; |
---|
187 | *(uint16_t volatile *) (PORTFIO_BASE_ADDRESS + PORTIO_DIR_OFFSET) = 0x0fc0; |
---|
188 | |
---|
189 | *(uint16_t volatile *) PORTG_FER = 0x0000; |
---|
190 | *(uint16_t volatile *) (PORTGIO_BASE_ADDRESS + PORTIO_OFFSET) = 0x0000; |
---|
191 | *(uint16_t volatile *) (PORTGIO_BASE_ADDRESS + PORTIO_INEN_OFFSET) = 0x0000; |
---|
192 | *(uint16_t volatile *) (PORTGIO_BASE_ADDRESS + PORTIO_POLAR_OFFSET) = 0x0000; |
---|
193 | *(uint16_t volatile *) (PORTGIO_BASE_ADDRESS + PORTIO_EDGE_OFFSET) = 0x0000; |
---|
194 | *(uint16_t volatile *) (PORTGIO_BASE_ADDRESS + PORTIO_BOTH_OFFSET) = 0x0000; |
---|
195 | *(uint16_t volatile *) (PORTGIO_BASE_ADDRESS + PORTIO_MASKA_OFFSET) = 0x0000; |
---|
196 | *(uint16_t volatile *) (PORTGIO_BASE_ADDRESS + PORTIO_MASKB_OFFSET) = 0x0000; |
---|
197 | *(uint16_t volatile *) (PORTGIO_BASE_ADDRESS + PORTIO_DIR_OFFSET) = 0x0000; |
---|
198 | |
---|
199 | /* port h bits 0 - 15: ethernet */ |
---|
200 | *(uint16_t volatile *) PORTH_FER = 0xffff; |
---|
201 | *(uint16_t volatile *) (PORTHIO_BASE_ADDRESS + PORTIO_OFFSET) = 0x0000; |
---|
202 | *(uint16_t volatile *) (PORTHIO_BASE_ADDRESS + PORTIO_INEN_OFFSET) = 0x0000; |
---|
203 | *(uint16_t volatile *) (PORTHIO_BASE_ADDRESS + PORTIO_POLAR_OFFSET) = 0x0000; |
---|
204 | *(uint16_t volatile *) (PORTHIO_BASE_ADDRESS + PORTIO_EDGE_OFFSET) = 0x0000; |
---|
205 | *(uint16_t volatile *) (PORTHIO_BASE_ADDRESS + PORTIO_BOTH_OFFSET) = 0x0000; |
---|
206 | *(uint16_t volatile *) (PORTHIO_BASE_ADDRESS + PORTIO_MASKA_OFFSET) = 0x0000; |
---|
207 | *(uint16_t volatile *) (PORTHIO_BASE_ADDRESS + PORTIO_MASKB_OFFSET) = 0x0000; |
---|
208 | *(uint16_t volatile *) (PORTHIO_BASE_ADDRESS + PORTIO_DIR_OFFSET) = 0x0000; |
---|
209 | } |
---|
210 | |
---|
211 | /* |
---|
212 | * Helper Function to use the EzKits LEDS. |
---|
213 | * Can be used by the Application. |
---|
214 | */ |
---|
215 | void setLEDs(uint8_t value) { |
---|
216 | |
---|
217 | *(uint16_t volatile *) (PORTFIO_BASE_ADDRESS + PORTIO_CLEAR_OFFSET) = |
---|
218 | (uint16_t) (~value & 0x3f) << 6; |
---|
219 | *(uint16_t volatile *) (PORTFIO_BASE_ADDRESS + PORTIO_SET_OFFSET) = |
---|
220 | (uint16_t) (value & 0x3f) << 6; |
---|
221 | } |
---|
222 | |
---|
223 | /* |
---|
224 | * Helper Function to use the EzKits LEDS |
---|
225 | */ |
---|
226 | uint8_t getLEDs(void) { |
---|
227 | uint16_t r; |
---|
228 | |
---|
229 | r = *(uint16_t volatile *) (PORTFIO_BASE_ADDRESS + PORTIO_OFFSET); |
---|
230 | return (uint8_t) ((r >> 6) & 0x3f); |
---|
231 | } |
---|
232 | |
---|
233 | uint8_t getButtons(void) { |
---|
234 | uint16_t r; |
---|
235 | |
---|
236 | r = *(uint16_t volatile *) (PORTFIO_BASE_ADDRESS + PORTIO_OFFSET); |
---|
237 | |
---|
238 | return (uint8_t) ((r >> 2) & 0x0f); |
---|
239 | } |
---|
240 | |
---|
241 | |
---|