1 | /* bspstart.c for eZKit533 |
---|
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 <bsp.h> |
---|
23 | #include <rtems/libio.h> |
---|
24 | #include <rtems/libcsupport.h> |
---|
25 | |
---|
26 | |
---|
27 | /* |
---|
28 | * The original table from the application and our copy of it with |
---|
29 | * some changes. |
---|
30 | */ |
---|
31 | |
---|
32 | extern rtems_configuration_table Configuration; |
---|
33 | |
---|
34 | rtems_configuration_table BSP_Configuration; |
---|
35 | |
---|
36 | rtems_cpu_table Cpu_table; |
---|
37 | |
---|
38 | char *rtems_progname; |
---|
39 | |
---|
40 | /* |
---|
41 | * Use the shared implementations of the following routines |
---|
42 | */ |
---|
43 | |
---|
44 | void bsp_postdriver_hook(void); |
---|
45 | void bsp_libc_init( void *, uint32_t, int ); |
---|
46 | void Init_PLL (void); |
---|
47 | void Init_EBIU (void); |
---|
48 | void Init_Flags(void); |
---|
49 | void Init_RTC (void); |
---|
50 | |
---|
51 | void null_isr(void); |
---|
52 | |
---|
53 | /* |
---|
54 | * Function: bsp_pretasking_hook |
---|
55 | * Created: 95/03/10 |
---|
56 | * |
---|
57 | * Description: |
---|
58 | * BSP pretasking hook. Called just before drivers are initialized. |
---|
59 | * Used to setup libc and install any BSP extensions. |
---|
60 | * |
---|
61 | * NOTES: |
---|
62 | * Must not use libc (to do io) from here, since drivers are |
---|
63 | * not yet initialized. |
---|
64 | * |
---|
65 | */ |
---|
66 | |
---|
67 | void bsp_pretasking_hook(void) |
---|
68 | { |
---|
69 | extern int HeapBase; |
---|
70 | extern int HeapSize; |
---|
71 | void *heapStart = &HeapBase; |
---|
72 | unsigned long heapSize = (unsigned long)&HeapSize; |
---|
73 | |
---|
74 | bsp_libc_init(heapStart, heapSize, 0); |
---|
75 | |
---|
76 | #ifdef RTEMS_DEBUG |
---|
77 | rtems_debug_enable( RTEMS_DEBUG_ALL_MASK ); |
---|
78 | #endif |
---|
79 | } |
---|
80 | |
---|
81 | /* |
---|
82 | * bsp_start |
---|
83 | * |
---|
84 | * This routine does the bulk of the system initialization. |
---|
85 | */ |
---|
86 | |
---|
87 | void bsp_start( void ) |
---|
88 | { |
---|
89 | |
---|
90 | extern void * _WorkspaceBase; |
---|
91 | |
---|
92 | /* BSP Hardware Initialization*/ |
---|
93 | Init_RTC(); /* Blackfin Real Time Clock initialization */ |
---|
94 | Init_PLL(); /* PLL initialization */ |
---|
95 | Init_EBIU(); /* EBIU initialization */ |
---|
96 | Init_Flags(); /* GPIO initialization */ |
---|
97 | |
---|
98 | /* |
---|
99 | * Allocate the memory for the RTEMS Work Space. This can come from |
---|
100 | * a variety of places: hard coded address, malloc'ed from outside |
---|
101 | * RTEMS world (e.g. simulator or primitive memory manager), or (as |
---|
102 | * typically done by stock BSPs) by subtracting the required amount |
---|
103 | * of work space from the last physical address on the CPU board. |
---|
104 | */ |
---|
105 | |
---|
106 | /* |
---|
107 | * Need to "allocate" the memory for the RTEMS Workspace and |
---|
108 | * tell the RTEMS configuration where it is. This memory is |
---|
109 | * not malloc'ed. It is just "pulled from the air". |
---|
110 | */ |
---|
111 | |
---|
112 | BSP_Configuration.work_space_start = (void *) &_WorkspaceBase; |
---|
113 | |
---|
114 | /* |
---|
115 | * initialize the CPU table for this BSP |
---|
116 | */ |
---|
117 | |
---|
118 | Cpu_table.pretasking_hook = bsp_pretasking_hook; /* init libc, etc. */ |
---|
119 | Cpu_table.postdriver_hook = bsp_postdriver_hook; |
---|
120 | Cpu_table.interrupt_stack_size = CONFIGURE_INTERRUPT_STACK_MEMORY; |
---|
121 | |
---|
122 | int i=0; |
---|
123 | for (i=5;i<16;i++) { |
---|
124 | set_vector((rtems_isr_entry)null_isr, i, 1); |
---|
125 | } |
---|
126 | |
---|
127 | } |
---|
128 | |
---|
129 | /* |
---|
130 | * Init_PLL |
---|
131 | * |
---|
132 | * Routine to initialize the PLL. The Ezkit uses a 27 Mhz XTAL. |
---|
133 | * See "../eZKit533/include/bsp.h" for more information. |
---|
134 | */ |
---|
135 | |
---|
136 | void Init_PLL (void) |
---|
137 | { |
---|
138 | |
---|
139 | unsigned int n; |
---|
140 | |
---|
141 | /* Configure PLL registers */ |
---|
142 | *((uint16_t*)PLL_LOCKCNT) = 0x1000; |
---|
143 | *((uint16_t*)PLL_DIV) = PLL_CSEL|PLL_SSEL; |
---|
144 | *((uint16_t*)PLL_CTL) = PLL_MSEL|PLL_DF; |
---|
145 | |
---|
146 | /* Commands to set PLL values */ |
---|
147 | asm("cli r0;"); |
---|
148 | asm("idle;"); |
---|
149 | asm("sti r0;"); |
---|
150 | |
---|
151 | /* Delay for PLL stabilization */ |
---|
152 | for (n=0; n<200; n++) {} |
---|
153 | |
---|
154 | } |
---|
155 | |
---|
156 | /* |
---|
157 | * Init_EBIU |
---|
158 | * |
---|
159 | * Configure extern memory |
---|
160 | */ |
---|
161 | |
---|
162 | void Init_EBIU (void) |
---|
163 | { |
---|
164 | /* Configure FLASH */ |
---|
165 | *((uint32_t*)EBIU_AMBCTL0) = 0x7bb07bb0L; |
---|
166 | *((uint32_t*)EBIU_AMBCTL1) = 0x7bb07bb0L; |
---|
167 | *((uint16_t*)EBIU_AMGCTL) = 0x000f; |
---|
168 | |
---|
169 | /* Configure SDRAM |
---|
170 | *((uint32_t*)EBIU_SDGCTL) = 0x0091998d; |
---|
171 | *((uint16_t*)EBIU_SDBCTL) = 0x0013; |
---|
172 | *((uint16_t*)EBIU_SDRRC) = 0x0817; |
---|
173 | */ |
---|
174 | } |
---|
175 | |
---|
176 | /* |
---|
177 | * Init_Flags |
---|
178 | * |
---|
179 | * Enable LEDs port |
---|
180 | */ |
---|
181 | void Init_Flags(void) |
---|
182 | { |
---|
183 | *((uint16_t*)FIO_INEN) = 0x0100; |
---|
184 | *((uint16_t*)FIO_DIR) = 0x0000; |
---|
185 | *((uint16_t*)FIO_EDGE) = 0x0100; |
---|
186 | *((uint16_t*)FIO_MASKA_D) = 0x0100; |
---|
187 | |
---|
188 | *((uint8_t*)FlashA_PortB_Dir) = 0x3f; |
---|
189 | *((uint8_t*)FlashA_PortB_Data) = 0x00; |
---|
190 | } |
---|
191 | |
---|
192 | /* |
---|
193 | * Helper Function to use the EzKits LEDS. |
---|
194 | * Can be used by the Application. |
---|
195 | */ |
---|
196 | void setLED (uint8_t value) |
---|
197 | { |
---|
198 | *((uint8_t*)FlashA_PortB_Data) = value; |
---|
199 | } |
---|
200 | |
---|
201 | /* |
---|
202 | * Helper Function to use the EzKits LEDS |
---|
203 | */ |
---|
204 | uint8_t getLED (void) |
---|
205 | { |
---|
206 | return *((uint8_t*)FlashA_PortB_Data); |
---|
207 | } |
---|