Wait 200ms before starting u-boot
[romboot.git] / init.cpp
blob374c61e3bbabd553c4e7dc27a0f9f5cd69c10284
1 //*----------------------------------------------------------------------------
2 //* ATMEL Microcontroller Software Support - ROUSSET -
3 //*----------------------------------------------------------------------------
4 //* The software is delivered "AS IS" without warranty or condition of any
5 //* kind, either express, implied or statutory. This includes without
6 //* limitation any warranty or condition with respect to merchantability or
7 //* fitness for any particular purpose, or against the infringements of
8 //* intellectual property rights of others.
9 //*----------------------------------------------------------------------------
10 //* File Name : init.c
11 //* Object : Low level initialisations written in C
12 //* Creation : HIi 10/10/2003
13 //*
14 //*----------------------------------------------------------------------------
16 #include <AT91RM9200.h>
17 #include <lib_AT91RM9200.h>
19 //*----------------------------------------------------------------------------
20 //* \fn AT91F_DBGU_Printk
21 //* \brief This function is used to send a string through the DBGU channel (Very low level debugging)
22 //*----------------------------------------------------------------------------
23 void AT91F_DBGU_Printk(
24 char *buffer) // \arg pointer to a string ending by \0
26 while(*buffer != '\0') {
27 while (!AT91F_US_TxReady((AT91PS_USART)AT91C_BASE_DBGU));
28 AT91F_US_PutChar((AT91PS_USART)AT91C_BASE_DBGU, *buffer++);
32 //*----------------------------------------------------------------------------
33 //* \fn AT91F_DataAbort
34 //* \brief This function reports an Abort
35 //*----------------------------------------------------------------------------
36 void AT91F_SpuriousHandler()
38 AT91F_DBGU_Printk("-F- Spurious Interrupt detected\n\r");
39 while (1);
43 //*----------------------------------------------------------------------------
44 //* \fn AT91F_DataAbort
45 //* \brief This function reports an Abort
46 //*----------------------------------------------------------------------------
47 typedef enum
49 CHECK_128M,
50 CHECK_64M,
51 CHECK_32M,
52 CHECK_DONE
53 } check_mem_t;
55 check_mem_t init_done = CHECK_128M;
56 void AT91F_DataAbort()
58 #if 0
59 int *pRegister;
60 switch( init_done)
62 case CHECK_128M:
64 pRegister = (int *)0xFFFFFF98;
65 *pRegister = 0x2188c159;
66 init_done = CHECK_64M;
67 return;
69 case CHECK_64M:
71 pRegister = (int *)0xFFFFFF98;
72 *pRegister = 0x2188c15a;
73 init_done = CHECK_32M;
74 return;
77 #endif
80 AT91F_DBGU_Printk("-F- Data Abort detected\n\r");
81 while (1);
84 //*----------------------------------------------------------------------------
85 //* \fn AT91F_FetchAbort
86 //* \brief This function reports an Abort
87 //*----------------------------------------------------------------------------
88 void AT91F_FetchAbort()
90 AT91F_DBGU_Printk("-F- Prefetch Abort detected\n\r");
91 while (1);
94 //*----------------------------------------------------------------------------
95 //* \fn AT91F_Undef
96 //* \brief This function reports an Abort
97 //*----------------------------------------------------------------------------
98 void AT91F_Undef()
100 AT91F_DBGU_Printk("-F- Undef detected\n\r");
101 while (1);
104 //*----------------------------------------------------------------------------
105 //* \fn AT91F_UndefHandler
106 //* \brief This function reports that no handler have been set for current IT
107 //*----------------------------------------------------------------------------
108 void AT91F_UndefHandler()
110 AT91F_DBGU_Printk("-F- Undef detected\n\r");
111 while (1);
115 //*--------------------------------------------------------------------------------------
116 //* Function Name : AT91F_InitSdram
117 //* Object : Initialize the SDRAM
118 //* Input Parameters :
119 //* Output Parameters :
120 //*--------------------------------------------------------------------------------------
121 void AT91F_InitSdram()
123 volatile int *pRegister;
124 int val;
126 /* Configure PIOC as peripheral (D16/D31) */
128 AT91F_PIO_CfgPeriph(
129 AT91C_BASE_PIOC, // PIO controller base address
130 0xFFFF0030,
134 /*Init SDRAM */
135 pRegister = (volatile int *)0xFFFFFF98;
136 *pRegister = 0x2188c15a;
137 pRegister = (volatile int *)0xFFFFFF90;
138 *pRegister = 0x2;
139 pRegister = (volatile int *)0x20000000;
140 *pRegister = 0;
141 pRegister = (volatile int *)0xFFFFFF90;
142 *pRegister = 0x4;
143 pRegister = (volatile int *)0x20000000;
144 *pRegister = 0;
145 *pRegister = 0;
146 *pRegister = 0;
147 *pRegister = 0;
148 *pRegister = 0;
149 *pRegister = 0;
150 *pRegister = 0;
151 *pRegister = 0;
152 pRegister = (volatile int *)0xFFFFFF90;
153 *pRegister = 0x3;
154 pRegister = (volatile int *)0x20000080;
155 *pRegister = 0;
157 pRegister = (volatile int *)0xFFFFFF94;
158 *pRegister = 0x2e0;
159 pRegister = (volatile int *)0x20000000;
160 *pRegister = 0;
162 pRegister = (volatile int *)0xFFFFFF90;
163 *pRegister = 0x00;
164 pRegister = (volatile int *)0x20000000;
165 *pRegister = 0;
167 pRegister = (volatile int *)0x27fffffc;
168 *pRegister = 0x12345678;
169 pRegister = (volatile int *)0x23fffffc;
170 *pRegister = 0x23456789 ;
171 pRegister = (volatile int *)0x27fffffc;
172 if ( *pRegister == 0x23456789 )
174 pRegister = (volatile int *)0xFFFFFF98;
175 *pRegister = 0x2188c159;
182 //*----------------------------------------------------------------------------
183 //* \fn AT91F_InitFlash
184 //* \brief This function performs low level HW initialization
185 //*----------------------------------------------------------------------------
186 void AT91F_InitMemories()
188 int *pEbi = (int *)0xFFFFFF60;
190 //* Setup MEMC to support all connected memories (CS0 = FLASH; CS1=SDRAM)
191 pEbi = (int *)0xFFFFFF60;
192 *pEbi = 0x00000002;
194 //* CS0 cs for flash
195 pEbi = (int *)0xFFFFFF70;
196 *pEbi = 0x00003284;
198 AT91F_InitSdram();
204 //*----------------------------------------------------------------------------
205 //* \fn AT91F_LowLevelInit
206 //* \brief This function performs very low level HW initialization
207 //*----------------------------------------------------------------------------
209 extern "C" void AT91F_LowLevelInit(void)
211 // Init Interrupt Controller
212 AT91F_AIC_Open(
213 AT91C_BASE_AIC, // pointer to the AIC registers
214 AT91C_AIC_BRANCH_OPCODE, // IRQ exception vector
215 AT91F_UndefHandler, // FIQ exception vector
216 AT91F_UndefHandler, // AIC default handler
217 AT91F_SpuriousHandler, // AIC spurious handler
218 0); // Protect mode
220 // Perform 8 End Of Interrupt Command to make sure AIC will not Lock out nIRQ
221 AT91F_AIC_AcknowledgeIt(AT91C_BASE_AIC);
222 AT91F_AIC_AcknowledgeIt(AT91C_BASE_AIC);
223 AT91F_AIC_AcknowledgeIt(AT91C_BASE_AIC);
224 AT91F_AIC_AcknowledgeIt(AT91C_BASE_AIC);
225 AT91F_AIC_AcknowledgeIt(AT91C_BASE_AIC);
226 AT91F_AIC_AcknowledgeIt(AT91C_BASE_AIC);
227 AT91F_AIC_AcknowledgeIt(AT91C_BASE_AIC);
228 AT91F_AIC_AcknowledgeIt(AT91C_BASE_AIC);
230 AT91F_AIC_SetExceptionVector((unsigned int *)0x0C, AT91F_FetchAbort);
231 AT91F_AIC_SetExceptionVector((unsigned int *)0x10, AT91F_DataAbort);
232 AT91F_AIC_SetExceptionVector((unsigned int *)0x4, AT91F_Undef);
234 //Initialize SDRAM and Flash
235 AT91F_InitMemories();
237 // Open PIO for DBGU
238 AT91F_DBGU_CfgPIO();
240 // Configure DBGU
241 AT91F_US_Configure (
242 (AT91PS_USART) AT91C_BASE_DBGU, // DBGU base address
243 48000000, // 48 MHz
244 AT91C_US_ASYNC_MODE, // mode Register to be programmed
245 115200 , // baudrate to be programmed
246 0); // timeguard to be programmed
248 // Enable Transmitter
249 AT91F_US_EnableTx((AT91PS_USART)AT91C_BASE_DBGU);
250 // Enable Receiver
251 AT91F_US_EnableRx((AT91PS_USART)AT91C_BASE_DBGU);
253 /* Enable PIO to access the LEDs */
254 AT91C_BASE_PIOB->PIO_PER = AT91C_PIO_PB2;
255 AT91C_BASE_PIOB->PIO_OER = AT91C_PIO_PB2;
256 AT91C_BASE_PIOB->PIO_CODR = AT91C_PIO_PB2;
258 // AT91F_DBGU_Printk("\n\rAT91F_LowLevelInit(): Debug channel initialized\n\r");