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
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");
43 //*----------------------------------------------------------------------------
44 //* \fn AT91F_DataAbort
45 //* \brief This function reports an Abort
46 //*----------------------------------------------------------------------------
55 check_mem_t init_done
= CHECK_128M
;
56 void AT91F_DataAbort()
64 pRegister
= (int *)0xFFFFFF98;
65 *pRegister
= 0x2188c159;
66 init_done
= CHECK_64M
;
71 pRegister
= (int *)0xFFFFFF98;
72 *pRegister
= 0x2188c15a;
73 init_done
= CHECK_32M
;
80 AT91F_DBGU_Printk("-F- Data Abort detected\n\r");
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");
94 //*----------------------------------------------------------------------------
96 //* \brief This function reports an Abort
97 //*----------------------------------------------------------------------------
100 AT91F_DBGU_Printk("-F- Undef detected\n\r");
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");
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
;
126 /* Configure PIOC as peripheral (D16/D31) */
129 AT91C_BASE_PIOC
, // PIO controller base address
135 pRegister
= (volatile int *)0xFFFFFF98;
136 *pRegister
= 0x2188c15a;
137 pRegister
= (volatile int *)0xFFFFFF90;
139 pRegister
= (volatile int *)0x20000000;
141 pRegister
= (volatile int *)0xFFFFFF90;
143 pRegister
= (volatile int *)0x20000000;
152 pRegister
= (volatile int *)0xFFFFFF90;
154 pRegister
= (volatile int *)0x20000080;
157 pRegister
= (volatile int *)0xFFFFFF94;
159 pRegister
= (volatile int *)0x20000000;
162 pRegister
= (volatile int *)0xFFFFFF90;
164 pRegister
= (volatile int *)0x20000000;
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;
195 pEbi
= (int *)0xFFFFFF70;
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
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
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();
242 (AT91PS_USART
) AT91C_BASE_DBGU
, // DBGU base address
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
);
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");