Merge branch 'master' of /media/usbdisk-11/IER/reference/romboot
[romboot.git] / init.cpp
blob09447a7ae8e70705a9920d84d1c60bdfacf9e72c
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 <stdio.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");
42 while (1);
46 //*----------------------------------------------------------------------------
47 //* \fn AT91F_DataAbort
48 //* \brief This function reports an Abort
49 //*----------------------------------------------------------------------------
50 typedef enum
52 CHECK_128M,
53 CHECK_64M,
54 CHECK_32M,
55 CHECK_DONE
56 } check_mem_t;
58 check_mem_t init_done = CHECK_128M;
59 void AT91F_DataAbort()
61 AT91F_DBGU_Printk("-F- Data Abrt detected\n\r");
62 while (1);
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");
72 while (1);
75 //*----------------------------------------------------------------------------
76 //* \fn AT91F_Undef
77 //* \brief This function reports an Abort
78 //*----------------------------------------------------------------------------
79 void AT91F_Undef()
81 AT91F_DBGU_Printk("-F- Undef detected\n\r");
82 while (1);
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");
92 while (1);
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;
105 int val;
107 /* Configure PIOC as peripheral (D16/D31) */
109 AT91F_PIO_CfgPeriph(
110 AT91C_BASE_PIOC, // PIO controller base address
111 0xFFFF0030,
115 /*Init SDRAM */
116 pRegister = (volatile int *)0xFFFFFF98;
117 *pRegister = (volatile int)get_size_reg();
118 pRegister = (volatile int *)0xFFFFFF90;
119 *pRegister = 0x2;
120 pRegister = (volatile int *)0x20000000;
121 *pRegister = 0;
122 pRegister = (volatile int *)0xFFFFFF90;
123 *pRegister = 0x4;
124 pRegister = (volatile int *)0x20000000;
125 *pRegister = 0;
126 *pRegister = 0;
127 *pRegister = 0;
128 *pRegister = 0;
129 *pRegister = 0;
130 *pRegister = 0;
131 *pRegister = 0;
132 *pRegister = 0;
133 pRegister = (volatile int *)0xFFFFFF90;
134 *pRegister = 0x3;
135 pRegister = (volatile int *)0x20000080;
136 *pRegister = 0;
138 pRegister = (volatile int *)0xFFFFFF94;
139 *pRegister = 0x2e0;
140 pRegister = (volatile int *)0x20000000;
141 *pRegister = 0;
143 pRegister = (volatile int *)0xFFFFFF90;
144 *pRegister = 0x00;
145 pRegister = (volatile int *)0x20000000;
146 *pRegister = 0;
151 //*----------------------------------------------------------------------------
152 //* \fn AT91F_InitUdp
153 //* \brief This function performs low level Udp initialization
154 //*----------------------------------------------------------------------------
156 void AT91F_InitUdp()
158 int flag;
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()
173 * Disable UDB device
175 int *pEbi = (int *)0xFFFFFF60;
177 //* Setup MEMC to support all connected memories (CS0 = FLASH; CS1=SDRAM)
178 pEbi = (int *)0xFFFFFF60;
179 *pEbi = 0x00000002;
181 //* CS0 cs for flash
182 pEbi = (int *)0xFFFFFF70;
183 *pEbi = 0x00003284;
185 AT91F_InitSdram();
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
200 AT91F_AIC_Open(
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
206 0); // Protect mode
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();
225 // Open PIO for DBGU
226 AT91F_DBGU_CfgPIO();
228 // Configure DBGU
229 AT91F_US_Configure (
230 (AT91PS_USART) AT91C_BASE_DBGU, // DBGU base address
231 48000000, // 48 MHz
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);
238 // Enable Receiver
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);
246 AT91F_InitUdp();
249 // AT91F_DBGU_Printk("\n\rAT91F_LowLevelInit(): Debug channel initialized\n\r");