1 | /* bspstart.c for TLL6527M |
---|
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) 2010 by ECE Northeastern University. |
---|
9 | * |
---|
10 | * The license and distribution terms for this file may be |
---|
11 | * found in the file LICENSE in this distribution or at |
---|
12 | * http://www.rtems.com/license |
---|
13 | */ |
---|
14 | |
---|
15 | |
---|
16 | #include <bsp.h> |
---|
17 | #include <cplb.h> |
---|
18 | #include <bsp/interrupt.h> |
---|
19 | #include <libcpu/ebiuRegs.h> |
---|
20 | |
---|
21 | const unsigned int dcplbs_table[16][2] = { |
---|
22 | { 0xFFA00000, (PAGE_SIZE_1MB | CPLB_D_PAGE_MGMT | CPLB_WT) }, |
---|
23 | { 0xFF900000, (PAGE_SIZE_1MB | CPLB_D_PAGE_MGMT | CPLB_WT) },/* L1 Data B */ |
---|
24 | { 0xFF800000, (PAGE_SIZE_1MB | CPLB_D_PAGE_MGMT | CPLB_WT) },/* L1 Data A */ |
---|
25 | { 0xFFB00000, (PAGE_SIZE_1MB | CPLB_DNOCACHE) }, |
---|
26 | |
---|
27 | { 0x20300000, (PAGE_SIZE_1MB | CPLB_DNOCACHE) },/* Async Memory Bank 3 */ |
---|
28 | { 0x20200000, (PAGE_SIZE_1MB | CPLB_DNOCACHE) },/* Async Memory Bank 2 */ |
---|
29 | { 0x20100000, (PAGE_SIZE_1MB | CPLB_DNOCACHE) },/* Async Memory Bank 1 */ |
---|
30 | { 0x20000000, (PAGE_SIZE_1MB | CPLB_DNOCACHE) }, /* Async Memory Bank 0 */ |
---|
31 | |
---|
32 | { 0x02400000, (PAGE_SIZE_4MB | CPLB_DNOCACHE) }, |
---|
33 | { 0x02000000, (PAGE_SIZE_4MB | CPLB_DNOCACHE) }, |
---|
34 | { 0x00C00000, (PAGE_SIZE_4MB | CPLB_DNOCACHE) }, |
---|
35 | { 0x00800000, (PAGE_SIZE_4MB | CPLB_DNOCACHE) }, |
---|
36 | { 0x00400000, (PAGE_SIZE_4MB | CPLB_DNOCACHE) }, |
---|
37 | { 0x00000000, (PAGE_SIZE_4MB | CPLB_DNOCACHE) }, |
---|
38 | |
---|
39 | { 0xffffffff, 0xffffffff }/* end of section - termination */ |
---|
40 | }; |
---|
41 | |
---|
42 | |
---|
43 | const unsigned int _icplbs_table[16][2] = { |
---|
44 | { 0xFFA00000, (PAGE_SIZE_1MB | CPLB_I_PAGE_MGMT | CPLB_I_PAGE_MGMT | 0x4) }, |
---|
45 | /* L1 Code */ |
---|
46 | { 0xEF000000, (PAGE_SIZE_1MB | CPLB_INOCACHE) }, /* AREA DE BOOT */ |
---|
47 | { 0xFFB00000, (PAGE_SIZE_1MB | CPLB_INOCACHE) }, |
---|
48 | |
---|
49 | { 0x20300000, (PAGE_SIZE_1MB | CPLB_INOCACHE) },/* Async Memory Bank 3 */ |
---|
50 | { 0x20200000, (PAGE_SIZE_1MB | CPLB_INOCACHE) },/* Async Bank 2 (Secnd) */ |
---|
51 | { 0x20100000, (PAGE_SIZE_1MB | CPLB_INOCACHE) },/* Async Bank 1 (Prim B) */ |
---|
52 | { 0x20000000, (PAGE_SIZE_1MB | CPLB_INOCACHE) },/* Async Bank 0 (Prim A) */ |
---|
53 | |
---|
54 | { 0x02400000, (PAGE_SIZE_4MB | CPLB_INOCACHE) }, |
---|
55 | { 0x02000000, (PAGE_SIZE_4MB | CPLB_INOCACHE) }, |
---|
56 | { 0x00C00000, (PAGE_SIZE_4MB | CPLB_INOCACHE) }, |
---|
57 | { 0x00800000, (PAGE_SIZE_4MB | CPLB_INOCACHE) }, |
---|
58 | { 0x00400000, (PAGE_SIZE_4MB | CPLB_INOCACHE) }, |
---|
59 | { 0x00000000, (PAGE_SIZE_4MB | CPLB_INOCACHE) }, |
---|
60 | |
---|
61 | { 0xffffffff, 0xffffffff }/* end of section - termination */ |
---|
62 | }; |
---|
63 | |
---|
64 | void Init_PLL (void); |
---|
65 | void Init_EBIU (void); |
---|
66 | void Init_Flags(void); |
---|
67 | void Init_RTC (void); |
---|
68 | void initCPLB(void); |
---|
69 | |
---|
70 | |
---|
71 | void null_isr(void); |
---|
72 | |
---|
73 | /* |
---|
74 | * Function: bsp_pretasking_hook |
---|
75 | * Created: 95/03/10 |
---|
76 | * |
---|
77 | * Description: |
---|
78 | * BSP pretasking hook. Called just before drivers are initialized. |
---|
79 | * Used to setup libc and install any BSP extensions. |
---|
80 | * |
---|
81 | * NOTES: |
---|
82 | * Must not use libc (to do io) from here, since drivers are |
---|
83 | * not yet initialized. |
---|
84 | * |
---|
85 | */ |
---|
86 | |
---|
87 | void bsp_pretasking_hook(void) |
---|
88 | { |
---|
89 | bfin_interrupt_init(); |
---|
90 | } |
---|
91 | |
---|
92 | /* |
---|
93 | * bsp_start |
---|
94 | * |
---|
95 | * This routine does the bulk of the system initialization. |
---|
96 | */ |
---|
97 | |
---|
98 | void bsp_start( void ) |
---|
99 | { |
---|
100 | /* BSP Hardware Initialization*/ |
---|
101 | Init_RTC(); /* Blackfin Real Time Clock initialization */ |
---|
102 | Init_PLL(); /* PLL initialization */ |
---|
103 | Init_EBIU(); /* EBIU initialization */ |
---|
104 | Init_Flags(); /* GPIO initialization */ |
---|
105 | |
---|
106 | /* |
---|
107 | * Allocate the memory for the RTEMS Work Space. This can come from |
---|
108 | * a variety of places: hard coded address, malloc'ed from outside |
---|
109 | * RTEMS world (e.g. simulator or primitive memory manager), or (as |
---|
110 | * typically done by stock BSPs) by subtracting the required amount |
---|
111 | * of work space from the last physical address on the CPU board. |
---|
112 | */ |
---|
113 | int i=0; |
---|
114 | for (i=5;i<16;i++) { |
---|
115 | set_vector((rtems_isr_entry)null_isr, i, 1); |
---|
116 | } |
---|
117 | |
---|
118 | } |
---|
119 | |
---|
120 | /* |
---|
121 | * Init_PLL |
---|
122 | * |
---|
123 | * Routine to initialize the PLL. The TLL6527M uses a 25 Mhz XTAL. |
---|
124 | */ |
---|
125 | void Init_PLL (void) |
---|
126 | { |
---|
127 | unsigned short msel = 0; |
---|
128 | unsigned short ssel = 0; |
---|
129 | |
---|
130 | msel = (unsigned short)( (float)CCLK/(float)CLKIN ); |
---|
131 | ssel = (unsigned short)( (float)(CLKIN*msel)/(float)SCLK); |
---|
132 | |
---|
133 | asm("cli r0;"); |
---|
134 | |
---|
135 | *((uint32_t*)SIC_IWR) = 0x1; |
---|
136 | |
---|
137 | /* Configure PLL registers */ |
---|
138 | *((uint16_t*)PLL_DIV) = ssel; |
---|
139 | msel = msel<<9; |
---|
140 | *((uint16_t*)PLL_CTL) = msel; |
---|
141 | |
---|
142 | /* Commands to set PLL values */ |
---|
143 | asm("idle;"); |
---|
144 | asm("sti r0;"); |
---|
145 | } |
---|
146 | |
---|
147 | /* |
---|
148 | * Init_EBIU |
---|
149 | * |
---|
150 | * Configure extern memory |
---|
151 | */ |
---|
152 | |
---|
153 | void Init_EBIU (void) |
---|
154 | { |
---|
155 | /* Check if SDRAM is already enabled */ |
---|
156 | if ( 0 != (*(uint16_t *)EBIU_SDSTAT & EBIU_SDSTAT_SDRS) ){ |
---|
157 | asm("ssync;"); |
---|
158 | /* RDIV = (100MHz*64ms)/8192-(6+3)=0x406 cycles */ |
---|
159 | *(uint16_t *)EBIU_SDRRC = 0x3F6; /* SHould have been 0x306*/ |
---|
160 | *(uint16_t *)EBIU_SDBCTL = EBIU_SDBCTL_EBCAW_10 | EBIU_SDBCTL_EBSZ_64M | |
---|
161 | EBIU_SDBCTL_EBE; |
---|
162 | *(uint32_t *)EBIU_SDGCTL = 0x8491998d; |
---|
163 | asm("ssync;"); |
---|
164 | } else { |
---|
165 | /* SDRAm is already programmed */ |
---|
166 | } |
---|
167 | } |
---|
168 | |
---|
169 | /* |
---|
170 | * Init_Flags |
---|
171 | * |
---|
172 | * Enable LEDs port |
---|
173 | */ |
---|
174 | void Init_Flags(void) |
---|
175 | { |
---|
176 | *((uint16_t*)PORTH_FER) = 0x0; |
---|
177 | *((uint16_t*)PORTH_MUX) = 0x0; |
---|
178 | *((uint16_t*)PORTHIO_DIR) = 0x1<<15; |
---|
179 | *((uint16_t*)PORTHIO_SET) = 0x1<<15; |
---|
180 | } |
---|
181 | |
---|
182 | |
---|
183 | |
---|
184 | void initCPLB(void) { |
---|
185 | |
---|
186 | int i = 0; |
---|
187 | unsigned int *addr; |
---|
188 | unsigned int *data; |
---|
189 | |
---|
190 | addr = (unsigned int *)0xffe00100; |
---|
191 | data = (unsigned int *)0xffe00200; |
---|
192 | |
---|
193 | while ( dcplbs_table[i][0] != 0xffffffff ) { |
---|
194 | *addr = dcplbs_table[i][0]; |
---|
195 | *data = dcplbs_table[i][1]; |
---|
196 | |
---|
197 | addr++; |
---|
198 | data++; |
---|
199 | } |
---|
200 | } |
---|