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>
18 #include "dataflash.h"
19 #include <lib_AT91RM9200.h>
22 //*----------------------------------------------------------------------------
23 //* \fn AT91F_DBGU_Printk
24 //* \brief This function is used to send a string through the DBGU channel (Very low level debugging)
25 //*----------------------------------------------------------------------------
26 void AT91F_DBGU_Printk(
27 char *buffer
) // \arg pointer to a string ending by \0
29 while(*buffer
!= '\0') {
30 while (!AT91F_US_TxReady((AT91PS_USART
)AT91C_BASE_DBGU
));
31 AT91F_US_PutChar((AT91PS_USART
)AT91C_BASE_DBGU
, *buffer
++);
35 //*----------------------------------------------------------------------------
36 //* \fn AT91F_DataAbort
37 //* \brief This function reports an Abort
38 //*----------------------------------------------------------------------------
39 void AT91F_SpuriousHandler()
41 AT91F_DBGU_Printk("-F- Spurious Int detected\n\r");
46 //*----------------------------------------------------------------------------
47 //* \fn AT91F_DataAbort
48 //* \brief This function reports an Abort
49 //*----------------------------------------------------------------------------
58 check_mem_t init_done
= CHECK_128M
;
59 void AT91F_DataAbort()
61 AT91F_DBGU_Printk("-F- Data Abrt detected\n\r");
65 //*----------------------------------------------------------------------------
66 //* \fn AT91F_FetchAbort
67 //* \brief This function reports an Abort
68 //*----------------------------------------------------------------------------
69 void AT91F_FetchAbort()
71 AT91F_DBGU_Printk("-F- Prefetch Abrt detected\n\r");
75 //*----------------------------------------------------------------------------
77 //* \brief This function reports an Abort
78 //*----------------------------------------------------------------------------
81 AT91F_DBGU_Printk("-F- Undef detected\n\r");
85 //*----------------------------------------------------------------------------
86 //* \fn AT91F_UndefHandler
87 //* \brief This function reports that no handler have been set for current IT
88 //*----------------------------------------------------------------------------
89 void AT91F_UndefHandler()
91 AT91F_DBGU_Printk("-F- Undef detected\n\r");
96 //*--------------------------------------------------------------------------------------
97 //* Function Name : AT91F_InitSdram
98 //* Object : Initialize the SDRAM
99 //* Input Parameters :
100 //* Output Parameters :
101 //*--------------------------------------------------------------------------------------
102 void AT91F_InitSdram()
104 volatile int *pRegister
;
107 /* Configure PIOC as peripheral (D16/D31) */
110 AT91C_BASE_PIOC
, // PIO controller base address
116 pRegister
= (volatile int *)0xFFFFFF98;
117 *pRegister
= (volatile int)get_size_reg();
118 pRegister
= (volatile int *)0xFFFFFF90;
120 pRegister
= (volatile int *)0x20000000;
122 pRegister
= (volatile int *)0xFFFFFF90;
124 pRegister
= (volatile int *)0x20000000;
133 pRegister
= (volatile int *)0xFFFFFF90;
135 pRegister
= (volatile int *)0x20000080;
138 pRegister
= (volatile int *)0xFFFFFF94;
140 pRegister
= (volatile int *)0x20000000;
143 pRegister
= (volatile int *)0xFFFFFF90;
145 pRegister
= (volatile int *)0x20000000;
151 //*----------------------------------------------------------------------------
152 //* \fn AT91F_InitUdp
153 //* \brief This function performs low level Udp initialization
154 //*----------------------------------------------------------------------------
159 AT91F_PIO_CfgInput(AT91C_BASE_PIOD
,AT91C_PIO_PD4
);
160 *AT91C_UDP_TXVC
= AT91C_UDP_TXVDIS
;
161 AT91F_PIO_CfgOutput(AT91C_BASE_PIOD
,AT91C_PIO_PD5
);
162 *AT91C_PMC_SCDR
= AT91C_PMC_UDP
;
163 *AT91C_PMC_PCDR
= 1 << AT91C_PMC_UDP
;
166 //*----------------------------------------------------------------------------
167 //* \fn AT91F_InitFlash
168 //* \brief This function performs low level HW initialization
169 //*----------------------------------------------------------------------------
170 void AT91F_InitMemories()
175 int *pEbi
= (int *)0xFFFFFF60;
177 //* Setup MEMC to support all connected memories (CS0 = FLASH; CS1=SDRAM)
178 pEbi
= (int *)0xFFFFFF60;
182 pEbi
= (int *)0xFFFFFF70;
191 //*----------------------------------------------------------------------------
192 //* \fn AT91F_LowLevelInit
193 //* \brief This function performs very low level HW initialization
194 //*----------------------------------------------------------------------------
196 extern "C" void AT91F_LowLevelInit(void)
199 // Init Interrupt Controller
201 AT91C_BASE_AIC
, // pointer to the AIC registers
202 AT91C_AIC_BRANCH_OPCODE
, // IRQ exception vector
203 AT91F_UndefHandler
, // FIQ exception vector
204 AT91F_UndefHandler
, // AIC default handler
205 AT91F_SpuriousHandler
, // AIC spurious handler
208 // Perform 8 End Of Interrupt Command to make sure AIC will not Lock out nIRQ
209 AT91F_AIC_AcknowledgeIt(AT91C_BASE_AIC
);
210 AT91F_AIC_AcknowledgeIt(AT91C_BASE_AIC
);
211 AT91F_AIC_AcknowledgeIt(AT91C_BASE_AIC
);
212 AT91F_AIC_AcknowledgeIt(AT91C_BASE_AIC
);
213 AT91F_AIC_AcknowledgeIt(AT91C_BASE_AIC
);
214 AT91F_AIC_AcknowledgeIt(AT91C_BASE_AIC
);
215 AT91F_AIC_AcknowledgeIt(AT91C_BASE_AIC
);
216 AT91F_AIC_AcknowledgeIt(AT91C_BASE_AIC
);
218 AT91F_AIC_SetExceptionVector((unsigned int *)0x0C, AT91F_FetchAbort
);
219 AT91F_AIC_SetExceptionVector((unsigned int *)0x10, AT91F_DataAbort
);
220 AT91F_AIC_SetExceptionVector((unsigned int *)0x4, AT91F_Undef
);
222 //Initialize SDRAM and Flash
223 AT91F_InitMemories();
230 (AT91PS_USART
) AT91C_BASE_DBGU
, // DBGU base address
232 AT91C_US_ASYNC_MODE
, // mode Register to be programmed
233 115200 , // baudrate to be programmed
234 0); // timeguard to be programmed
236 // Enable Transmitter
237 AT91F_US_EnableTx((AT91PS_USART
)AT91C_BASE_DBGU
);
239 AT91F_US_EnableRx((AT91PS_USART
)AT91C_BASE_DBGU
);
241 /* Enable PIO to access the LEDs */
242 AT91F_PIO_CfgOutput(AT91C_BASE_PIOD
,AT91C_PIO_PD6
);
243 /* Enable PIO to manage flash locking */
244 AT91F_PIO_CfgOutput(AT91C_BASE_PIOB
,AT91C_PIO_PC15
);
249 // AT91F_DBGU_Printk("\n\rAT91F_LowLevelInit(): Debug channel initialized\n\r");