1 |
786 |
skrzyp |
#ifndef CYGONCE_HAL_PLATFORM_SETUP_H
|
2 |
|
|
#define CYGONCE_HAL_PLATFORM_SETUP_H
|
3 |
|
|
|
4 |
|
|
/*=============================================================================
|
5 |
|
|
//
|
6 |
|
|
// hal_platform_setup.h
|
7 |
|
|
//
|
8 |
|
|
// Platform specific support for HAL (assembly code)
|
9 |
|
|
//
|
10 |
|
|
//=============================================================================
|
11 |
|
|
// ####ECOSGPLCOPYRIGHTBEGIN####
|
12 |
|
|
// -------------------------------------------
|
13 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
14 |
|
|
// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2009 Free Software Foundation, Inc.
|
15 |
|
|
//
|
16 |
|
|
// eCos is free software; you can redistribute it and/or modify it under
|
17 |
|
|
// the terms of the GNU General Public License as published by the Free
|
18 |
|
|
// Software Foundation; either version 2 or (at your option) any later
|
19 |
|
|
// version.
|
20 |
|
|
//
|
21 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT
|
22 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
23 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
24 |
|
|
// for more details.
|
25 |
|
|
//
|
26 |
|
|
// You should have received a copy of the GNU General Public License
|
27 |
|
|
// along with eCos; if not, write to the Free Software Foundation, Inc.,
|
28 |
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
29 |
|
|
//
|
30 |
|
|
// As a special exception, if other files instantiate templates or use
|
31 |
|
|
// macros or inline functions from this file, or you compile this file
|
32 |
|
|
// and link it with other works to produce a work based on this file,
|
33 |
|
|
// this file does not by itself cause the resulting work to be covered by
|
34 |
|
|
// the GNU General Public License. However the source code for this file
|
35 |
|
|
// must still be made available in accordance with section (3) of the GNU
|
36 |
|
|
// General Public License v2.
|
37 |
|
|
//
|
38 |
|
|
// This exception does not invalidate any other reasons why a work based
|
39 |
|
|
// on this file might be covered by the GNU General Public License.
|
40 |
|
|
// -------------------------------------------
|
41 |
|
|
// ####ECOSGPLCOPYRIGHTEND####
|
42 |
|
|
//=============================================================================
|
43 |
|
|
//#####DESCRIPTIONBEGIN####
|
44 |
|
|
//
|
45 |
|
|
// Author(s): gthomas
|
46 |
|
|
// Contributors:gthomas, tdrury, nickg
|
47 |
|
|
// Date: 2001-07-12
|
48 |
|
|
// Purpose: AT91/EB55 platform specific support routines
|
49 |
|
|
// Description:
|
50 |
|
|
// Usage: #include <cyg/hal/hal_platform_setup.h>
|
51 |
|
|
//
|
52 |
|
|
//####DESCRIPTIONEND####
|
53 |
|
|
//
|
54 |
|
|
//===========================================================================*/
|
55 |
|
|
|
56 |
|
|
#include <cyg/hal/var_io.h>
|
57 |
|
|
|
58 |
|
|
//===========================================================================*/
|
59 |
|
|
|
60 |
|
|
.macro _led_init
|
61 |
|
|
ldr r0,=AT91_PIOB
|
62 |
|
|
ldr r1,=0x0000FF00
|
63 |
|
|
str r1,[r0,#AT91_PIO_PER]
|
64 |
|
|
str r1,[r0,#AT91_PIO_OER]
|
65 |
|
|
_led 0
|
66 |
|
|
.endm
|
67 |
|
|
|
68 |
|
|
.macro _led y
|
69 |
|
|
ldr r0,=AT91_PIOB
|
70 |
|
|
ldr r1,=0x0000FF00
|
71 |
|
|
str r1,[r0,#AT91_PIO_SODR]
|
72 |
|
|
ldr r1,=(\y<<8)
|
73 |
|
|
str r1,[r0,#AT91_PIO_CODR]
|
74 |
|
|
#if 0
|
75 |
|
|
mov r0,#0x00100000
|
76 |
|
|
9: sub r0,r0,#1
|
77 |
|
|
cmp r0,#0
|
78 |
|
|
bne 9b
|
79 |
|
|
#endif
|
80 |
|
|
.endm
|
81 |
|
|
|
82 |
|
|
.macro _pclock_init
|
83 |
|
|
ldr r0,=AT91_PMC // Power saving interface
|
84 |
|
|
ldr r1,=0xFFFFFFFF // Enable all peripheral [clocks]
|
85 |
|
|
str r1,[r0,#AT91_PMC_PCER]
|
86 |
|
|
.endm
|
87 |
|
|
|
88 |
|
|
.macro _pio_init
|
89 |
|
|
ldr r0,=AT91_PIOA // Disable PIO (so peripherals can use bits)
|
90 |
|
|
ldr r1,=(0x3f<<14) // Enable UARTS 0/1 to use pins
|
91 |
|
|
str r1,[r0,#AT91_PIO_PDR]
|
92 |
|
|
.endm
|
93 |
|
|
|
94 |
|
|
#define CYGHWR_LED_MACRO _led \x
|
95 |
|
|
|
96 |
|
|
//===========================================================================*/
|
97 |
|
|
|
98 |
|
|
#if defined(CYG_HAL_STARTUP_ROM) || defined(CYG_HAL_STARTUP_ROMRAM)
|
99 |
|
|
|
100 |
|
|
#define AT91_PMC_CGMR_INIT0 (AT91_PMC_CGMR_MOSC_XTAL | \
|
101 |
|
|
AT91_PMC_CGMR_MOSC_ENA | \
|
102 |
|
|
AT91_PMC_CGMR_OSC_CNT(47))
|
103 |
|
|
|
104 |
|
|
#define AT91_PMC_CGMR_INIT1 (AT91_PMC_CGMR_INIT0 | \
|
105 |
|
|
AT91_PMC_CGMR_CSS_MOSC)
|
106 |
|
|
|
107 |
|
|
#define AT91_PMC_CGMR_INIT2 (AT91_PMC_CGMR_INIT1 | \
|
108 |
|
|
AT91_PMC_CGMR_PLL_MUL(1) | \
|
109 |
|
|
AT91_PMC_CGMR_PLL_CNT(255))
|
110 |
|
|
|
111 |
|
|
#define AT91_PMC_CGMR_INIT3 (AT91_PMC_CGMR_INIT0 | \
|
112 |
|
|
AT91_PMC_CGMR_PLL_MUL(1) | \
|
113 |
|
|
AT91_PMC_CGMR_PLL_CNT(3) | \
|
114 |
|
|
AT91_PMC_CGMR_CSS_PLL)
|
115 |
|
|
|
116 |
|
|
.macro _setup
|
117 |
|
|
_led_init
|
118 |
|
|
|
119 |
|
|
// Change system frequency from 32kHz to 32MHz.
|
120 |
|
|
|
121 |
|
|
// First enable the master oscillator to run at 16MHz from
|
122 |
|
|
// external crystal.
|
123 |
|
|
ldr r2,=AT91_PMC
|
124 |
|
|
ldr r3,=AT91_PMC_CGMR_INIT0
|
125 |
|
|
str r3,[r2,#AT91_PMC_CGMR]
|
126 |
|
|
|
127 |
|
|
// Wait for MOSC to stabilize.
|
128 |
|
|
mov r4,#AT91_PMC_SR_MOSCS
|
129 |
|
|
1:
|
130 |
|
|
ldr r3,[r2,#AT91_PMC_SR]
|
131 |
|
|
and r3,r4,r3
|
132 |
|
|
cmp r3,r4 //#AT91_PMC_SR_MOSCS
|
133 |
|
|
bne 1b
|
134 |
|
|
|
135 |
|
|
// Now switch CPU clock to use master oscillator, after this we
|
136 |
|
|
// should be running at 16MHz.
|
137 |
|
|
ldr r3,=AT91_PMC_CGMR_INIT1
|
138 |
|
|
str r3,[r2,#AT91_PMC_CGMR]
|
139 |
|
|
|
140 |
|
|
// Now enable PLL to run at twice MOSC frequency
|
141 |
|
|
ldr r3,=AT91_PMC_CGMR_INIT2
|
142 |
|
|
str r3,[r2,#AT91_PMC_CGMR]
|
143 |
|
|
|
144 |
|
|
// Wait for PLL to stabilize
|
145 |
|
|
mov r4,#AT91_PMC_SR_LOCK
|
146 |
|
|
2:
|
147 |
|
|
ldr r3,[r2,#AT91_PMC_SR]
|
148 |
|
|
and r3,r4,r3
|
149 |
|
|
cmp r3,r4
|
150 |
|
|
bne 2b
|
151 |
|
|
|
152 |
|
|
// Finally, switch CPU clock from MOSC to PLL
|
153 |
|
|
ldr r3,=AT91_PMC_CGMR_INIT3
|
154 |
|
|
str r3,[r2,#AT91_PMC_CGMR]
|
155 |
|
|
|
156 |
|
|
// All done, we should be running at 32MHz now
|
157 |
|
|
|
158 |
|
|
ldr r10,=_InitMemory // Initialize memory controller
|
159 |
|
|
movs r0,pc,lsr #20 // If ROM startup, PC < 0x100000
|
160 |
|
|
moveq r10,r10,lsl #12 // mask address to low 20 bits
|
161 |
|
|
moveq r10,r10,lsr #12
|
162 |
|
|
ldmia r10!,{r0-r9,r11-r12} // Table of initialization constants
|
163 |
|
|
#if defined(CYG_HAL_STARTUP_ROMRAM)
|
164 |
|
|
ldr r10,=0x0000FFFF
|
165 |
|
|
and r12,r12,r10
|
166 |
|
|
ldr r10,=0x01000000
|
167 |
|
|
orr r12,r12,r10
|
168 |
|
|
#endif
|
169 |
|
|
stmia r11!,{r0-r9} // Write to controller
|
170 |
|
|
mov pc,r12 // Change address space, break pipeline
|
171 |
|
|
_InitMemory:
|
172 |
|
|
.long 0x01002529 // 0x01000000, 16MB, 2 cycles after transfer, 16-bit, 6 wait states
|
173 |
|
|
.long 0x02002121 // 0x02000000, 16MB, 0 cycles after transfer, 16-bit, 1 wait state
|
174 |
|
|
.long 0x20000000 // unused
|
175 |
|
|
.long 0x30000000 // unused
|
176 |
|
|
.long 0x40000000 // unused
|
177 |
|
|
.long 0x50000000 // unused
|
178 |
|
|
.long 0x60000000 // unused
|
179 |
|
|
.long 0x70000000 // unused
|
180 |
|
|
.long 0x00000001 // REMAP command
|
181 |
|
|
.long 0x00000000 // Standard read protocol
|
182 |
|
|
.long AT91_EBI // External Bus Interface address
|
183 |
|
|
.long 10f // address where to jump
|
184 |
|
|
10:
|
185 |
|
|
#if defined(CYG_HAL_STARTUP_ROMRAM)
|
186 |
|
|
ldr r0,=0x01000000 // Relocate FLASH/ROM to on-chip RAM
|
187 |
|
|
ldr r1,=0x02000000 // RAM base & length
|
188 |
|
|
ldr r2,=0x02010000
|
189 |
|
|
20: ldr r3,[r0],#4
|
190 |
|
|
str r3,[r1],#4
|
191 |
|
|
cmp r1,r2
|
192 |
|
|
bne 20b
|
193 |
|
|
ldr r0,=30f
|
194 |
|
|
mov pc,r0
|
195 |
|
|
30:
|
196 |
|
|
#endif
|
197 |
|
|
_pclock_init
|
198 |
|
|
_pio_init
|
199 |
|
|
.endm
|
200 |
|
|
|
201 |
|
|
#define CYGSEM_HAL_ROM_RESET_USES_JUMP
|
202 |
|
|
|
203 |
|
|
#else
|
204 |
|
|
|
205 |
|
|
.macro _setup
|
206 |
|
|
_led_init
|
207 |
|
|
_pclock_init
|
208 |
|
|
_pio_init
|
209 |
|
|
.endm
|
210 |
|
|
|
211 |
|
|
#endif
|
212 |
|
|
|
213 |
|
|
#define PLATFORM_SETUP1 _setup
|
214 |
|
|
|
215 |
|
|
|
216 |
|
|
//-----------------------------------------------------------------------------
|
217 |
|
|
// end of hal_platform_setup.h
|
218 |
|
|
#endif // CYGONCE_HAL_PLATFORM_SETUP_H
|