1 #ifndef CYGONCE_HAL_PLATFORM_SETUP_H
2 #define CYGONCE_HAL_PLATFORM_SETUP_H
3 /*=============================================================================
5 // hal_platform_setup.h
7 // Platform specific support for HAL (assembly code)
9 //=============================================================================
10 //####ECOSGPLCOPYRIGHTBEGIN####
11 // -------------------------------------------
12 // This file is part of eCos, the Embedded Configurable Operating System.
13 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
15 // eCos is free software; you can redistribute it and/or modify it under
16 // the terms of the GNU General Public License as published by the Free
17 // Software Foundation; either version 2 or (at your option) any later version.
19 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
20 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24 // You should have received a copy of the GNU General Public License along
25 // with eCos; if not, write to the Free Software Foundation, Inc.,
26 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
28 // As a special exception, if other files instantiate templates or use macros
29 // or inline functions from this file, or you compile this file and link it
30 // with other works to produce a work based on this file, this file does not
31 // by itself cause the resulting work to be covered by the GNU General Public
32 // License. However the source code for this file must still be made available
33 // in accordance with section (3) of the GNU General Public License.
35 // This exception does not invalidate any other reasons why a work based on
36 // this file might be covered by the GNU General Public License.
38 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
39 // at http://sources.redhat.com/ecos/ecos-license/
40 // -------------------------------------------
41 //####ECOSGPLCOPYRIGHTEND####
42 //=============================================================================
43 //#####DESCRIPTIONBEGIN####
46 // Contributors: gthomas
48 // Purpose: ARM9/AAED2000 platform specific support routines
50 // Usage: #include <cyg/hal/hal_platform_setup.h>
51 // Only used by "vectors.S"
53 //####DESCRIPTIONEND####
55 //===========================================================================*/
57 #include <pkgconf/system.h> // System-wide configuration info
58 #include CYGBLD_HAL_VARIANT_H // Variant specific configuration
59 #include CYGBLD_HAL_PLATFORM_H // Platform specific configuration
60 #include <cyg/hal/hal_mmu.h> // MMU definitions
61 #include <cyg/hal/aaed2000.h> // Platform specific hardware definitions
63 #if defined(CYG_HAL_STARTUP_ROM) || defined(CYG_HAL_STARTUP_ROMRAM)
64 #define PLATFORM_SETUP1 _platform_setup1
65 #define CYGHWR_HAL_ARM_HAS_MMU
66 #define CYGSEM_HAL_ROM_RESET_USES_JUMP
68 // We need this here - can't rely on a translation table until MMU has
70 .macro RAW_LED_MACRO x
74 orr r1,r1,#((0x7 & ~(\x))<<29)
78 // This macro represents the initial startup code for the platform
79 .macro _platform_setup1
81 #ifndef CYG_HAL_STARTUP_RAM
82 // Prevent all interrupts
87 // Disable and clear caches
89 bic r0,r0,#0x1000 // disable ICache
90 bic r0,r0,#0x000f // disable DCache, write buffer,
91 // MMU and alignment faults
96 mcr p15,0,r0,c7,c6,0 // clear data cache
98 mrc p15,0,r0,c15,c1,0 // disable streaming
100 mcr p15,0,r0,c15,c1,0
103 // Initialize memory controllers
105 // Static memory controller
106 // Area0: Flash: 32bit wide
108 ldr r1,=(AAEC_SMCBCR_MW32 | AAEC_SMCBCR_WST(_CS0_WST) | AAEC_SMCBCR_IDCY(_CS0_IDCY))
110 // Area1: Ethernet: 16bit wide
112 ldr r1,=(AAEC_SMCBCR_MW16 | AAEC_SMCBCR_WST(_CS1_WST) | AAEC_SMCBCR_IDCY(_CS1_IDCY))
114 // Area3: GPIO: 32bit wide
116 ldr r1,=(AAEC_SMCBCR_MW32 | AAEC_SMCBCR_WST(_CS3_WST) | AAEC_SMCBCR_IDCY(_CS3_IDCY))
120 // Set clock frequencies
121 // First set CPU to synchronous mode
122 mrc p15, 0, r0, c1, c0, 0
123 // configure for synchronous mode: FCLK >= HCLK by integer
125 orr r0, r0, #0x40000000
126 // configure for FastBus mode - FCLK and HCLK *must* be equal
127 // bic r0, r0, #0x40000000
128 bic r0, r0, #0x80000000
129 mcr p15, 0, r0, c1, c0, 0
131 ldr r0,=AAEC_CSC_CLKSET
132 ldr r1,=AAEC_CSC_CLKSET_INIT
134 // follow clock change by 5 NOPs
138 // Synchronous memory controller (as per table 4-12)
140 ldr r0,=AAEC_SMC_DEV0
141 ldr r1,=AAEC_SMC_DEV_INIT
147 // step1: delay 100usecs
148 ldr r2,=AAEC_TMR_T1_BASE
149 ldr r3,=AAEC_TMR_TxCONTROL_508KHZ_uS(100)
150 str r3,[r2, #AAEC_TMR_TxLOAD_OFFSET]
151 ldr r3,=(AAEC_TMR_TxCONTROL_ENABLE|AAEC_TMR_TxCONTROL_MODE_FREE|AAEC_TMR_TxCONTROL_508KHZ)
152 str r3,[r2, #AAEC_TMR_TxCONTROL_OFFSET]
153 1: ldr r3,[r2, #AAEC_TMR_TxVALUE_OFFSET]
156 str r3,[r2, #AAEC_TMR_TxCONTROL_OFFSET]
158 // step2: issue NOP command
159 ldr r0,=AAEC_SMC_GLOBAL
160 ldr r1,=AAEC_SMC_GLOBAL_CMD_NOP
163 // step3: wait 200usecs
164 ldr r3,=AAEC_TMR_TxCONTROL_508KHZ_uS(200)
165 str r3,[r2, #AAEC_TMR_TxLOAD_OFFSET]
166 ldr r3,=(AAEC_TMR_TxCONTROL_ENABLE|AAEC_TMR_TxCONTROL_MODE_FREE|AAEC_TMR_TxCONTROL_508KHZ)
167 str r3,[r2, #AAEC_TMR_TxCONTROL_OFFSET]
168 1: ldr r3,[r2, #AAEC_TMR_TxVALUE_OFFSET]
171 str r3,[r2, #AAEC_TMR_TxCONTROL_OFFSET]
173 // step4: PreCharge All
174 ldr r1,=AAEC_SMC_GLOBAL_CMD_PREALL
177 // step5: set refresh time to 10
178 ldr r3,=AAEC_SMC_REFRESH_TIME
182 // step6: wait 80 clock cycles, allowing 8 refresh cycles for SDRAM
187 // step7: set normal refresh count
188 // We need to do a refresh every 15.6usecs. The counter runs
189 // at bus clock, so the delay is (15.6usecs*bus speed) or
190 // (156*(bus speed/10)/1000000).
191 ldr r3,=AAEC_SMC_REFRESH_TIME
192 ldr r4,=(156*(CYGNUM_HAL_ARM_AAED2000_BUS_CLOCK/10)/1000000)
196 ldr r1,=AAEC_SMC_GLOBAL_CMD_MODE
199 // step9: program mode
200 // from page 36: SDRAM, WBL=0, TM=0, CAS=3, Sequential, BL=4
204 // step10: enable SDRAM
206 ldr r1,=AAEC_SMC_GLOBAL_CMD_ENABLE
210 #ifdef CYG_HAL_STARTUP_ROMRAM
211 // Compute [logical] base address of this image in ROM
214 ldr r8,=~0xFF01FFFF // Bits to ignore
216 orr r9,r9,#0x60000000 // Turn into ROM address
219 // Set up a stack [for calling C code]
220 ldr r1,=__startup_stack
221 ldr r2,=AAED2000_SDRAM_PHYS_BASE
231 #ifdef CYG_HAL_STARTUP_ROMRAM
232 ldr r1,=__exception_handlers
234 add r2,r9,r1 // r9 has ROM offset
236 ldr r1,=MMU_Control_Init|MMU_Control_M
237 mcr MMU_CP,0,r1,MMU_Control,c0
238 mov pc,r2 /* Change address spaces */
245 #ifdef CYG_HAL_STARTUP_ROMRAM
246 mov r0,r9 // Relocate FLASH/ROM to RAM
247 ldr r1,=__exception_handlers // ram base & length
248 ldr r2,=__rom_data_end
264 #else // defined(CYG_HAL_STARTUP_RAM)
265 #define PLATFORM_SETUP1
268 //-----------------------------------------------------------------------------
269 // end of hal_platform_setup.h
270 #endif // CYGONCE_HAL_PLATFORM_SETUP_H