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, 2008 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): Sergei Gavrikov
|
46 |
|
|
// Contributors: Sergei Gavrikov
|
47 |
|
|
// Date: 2008-08-31
|
48 |
|
|
// Purpose: LPC-H2294 platform specific support routines
|
49 |
|
|
// Description:
|
50 |
|
|
// Usage: #include <cyg/hal/hal_platform_setup.h>
|
51 |
|
|
//
|
52 |
|
|
//####DESCRIPTIONEND####
|
53 |
|
|
//
|
54 |
|
|
//===========================================================================*/
|
55 |
|
|
|
56 |
|
|
#include <pkgconf/system.h>
|
57 |
|
|
#include CYGHWR_MEMORY_LAYOUT_H
|
58 |
|
|
#include <cyg/hal/var_io.h>
|
59 |
|
|
|
60 |
|
|
// There is one LED on the board.
|
61 |
|
|
// |P0.30 470 Om LED
|
62 |
|
|
// |------\/\/\/-----|<|-----> 3.3 V
|
63 |
|
|
// |
|
64 |
|
|
.macro _led_init
|
65 |
|
|
ldr r0,=CYGARC_HAL_LPC2XXX_REG_IO_BASE
|
66 |
|
|
ldr r1,[r0,#CYGARC_HAL_LPC2XXX_REG_IO0DIR]
|
67 |
|
|
orr r1,r1,#(1<<30)
|
68 |
|
|
str r1,[r0,#CYGARC_HAL_LPC2XXX_REG_IO0DIR]
|
69 |
|
|
|
70 |
|
|
.endm // _led_init
|
71 |
|
|
|
72 |
|
|
.macro _led x
|
73 |
|
|
ldr r0,=CYGARC_HAL_LPC2XXX_REG_IO_BASE
|
74 |
|
|
ldr r1,=(1<<30)
|
75 |
|
|
str r1,[r0,#CYGARC_HAL_LPC2XXX_REG_IO0SET]
|
76 |
|
|
ldr r1,=((\x & 1)<<30)
|
77 |
|
|
str r1,[r0,#CYGARC_HAL_LPC2XXX_REG_IO0CLR]
|
78 |
|
|
|
79 |
|
|
.endm // _led
|
80 |
|
|
|
81 |
|
|
.macro _pll_init
|
82 |
|
|
ldr r0,=CYGARC_HAL_LPC2XXX_REG_SCB_BASE
|
83 |
|
|
|
84 |
|
|
mov r2,#0xAA
|
85 |
|
|
mov r3,#0x55
|
86 |
|
|
|
87 |
|
|
// enable PLL
|
88 |
|
|
mov r1,#1
|
89 |
|
|
str r1,[r0,#CYGARC_HAL_LPC2XXX_REG_PLLCON]
|
90 |
|
|
|
91 |
|
|
mov r1,#(0x20 | (CYGNUM_HAL_ARM_LPC2XXX_PLL_MUL - 1))
|
92 |
|
|
str r1,[r0,#CYGARC_HAL_LPC2XXX_REG_PLLCFG]
|
93 |
|
|
|
94 |
|
|
// update PLL registers
|
95 |
|
|
str r2,[r0,#CYGARC_HAL_LPC2XXX_REG_PLLFEED]
|
96 |
|
|
str r3,[r0,#CYGARC_HAL_LPC2XXX_REG_PLLFEED]
|
97 |
|
|
|
98 |
|
|
// wait for it to lock
|
99 |
|
|
1:
|
100 |
|
|
ldr r1,[r0,#CYGARC_HAL_LPC2XXX_REG_PLLSTAT]
|
101 |
|
|
ands r1,r1,#(1<<10)
|
102 |
|
|
beq 1b
|
103 |
|
|
|
104 |
|
|
// connect PLL
|
105 |
|
|
mov r1,#3
|
106 |
|
|
str r1,[r0,#CYGARC_HAL_LPC2XXX_REG_PLLCON]
|
107 |
|
|
// update PLL registers
|
108 |
|
|
str r2,[r0,#CYGARC_HAL_LPC2XXX_REG_PLLFEED]
|
109 |
|
|
str r3,[r0,#CYGARC_HAL_LPC2XXX_REG_PLLFEED]
|
110 |
|
|
|
111 |
|
|
.endm // _pll_init
|
112 |
|
|
|
113 |
|
|
.macro _mem_init
|
114 |
|
|
// copy first 64 bytes from ROM to on-chip RAM
|
115 |
|
|
mov r0,#0
|
116 |
|
|
mov r1,#0x40000000
|
117 |
|
|
mov r2,#0x40
|
118 |
|
|
1:
|
119 |
|
|
ldr r3,[r0,#4]!
|
120 |
|
|
str r3,[r1,#4]!
|
121 |
|
|
cmp r0,r2
|
122 |
|
|
bne 1b
|
123 |
|
|
|
124 |
|
|
ldr r0,=CYGARC_HAL_LPC2XXX_REG_SCB_BASE
|
125 |
|
|
mov r1,#2 // interrupt vector table is mapped to RAM
|
126 |
|
|
str r1, [r0,#CYGARC_HAL_LPC2XXX_REG_MEMMAP]
|
127 |
|
|
|
128 |
|
|
// flash timings
|
129 |
|
|
mov r1,#4
|
130 |
|
|
str r1,[r0,#CYGARC_HAL_LPC2XXX_REG_MAMTIM]
|
131 |
|
|
mov r1,#2 // 2, full MAM
|
132 |
|
|
str r1,[r0,#CYGARC_HAL_LPC2XXX_REG_MAMCR]
|
133 |
|
|
|
134 |
|
|
// External memory interface depends on the bank width (32, 16 or 8 bit
|
135 |
|
|
// selected via MW bits in corresponding BCFG register). Furthermore,
|
136 |
|
|
// choice of the memory chip(s) will require an adequate setup of RBLE
|
137 |
|
|
// bit in BCFG register, too. RBLE = 0 in case of 8-bit based external
|
138 |
|
|
// memories, while memory chips capable of accepting 16 or 32 bit wide
|
139 |
|
|
// data will work with RBLE = 1.
|
140 |
|
|
//
|
141 |
|
|
// BANK0: 4M FLASH
|
142 |
|
|
// TE28F320C3BD70 (1024Kx32 x 1, 70nS)
|
143 |
|
|
ldr r0,=CYGARC_HAL_LPC2XXX_REG_BCFG0
|
144 |
|
|
ldr r1,= (0x3 << 0) /* IDCY=3, idle timing */\
|
145 |
|
|
| (0x4 << 5) /* WST1=4, read timing */\
|
146 |
|
|
| (0x1 << 10) /* RBLE=1 */\
|
147 |
|
|
| (0x6 << 11) /* WST2=6, write timing */\
|
148 |
|
|
| (0x1 << 28) /* MW=1, 16-bits */
|
149 |
|
|
str r1,[r0]
|
150 |
|
|
|
151 |
|
|
// BANK1: 1M RAM
|
152 |
|
|
// IDT71V416L (512Kx16 x 2, 12nS)
|
153 |
|
|
ldr r0,=CYGARC_HAL_LPC2XXX_REG_BCFG1
|
154 |
|
|
// Warning: changed these timings, you can fall dramatically the eCos
|
155 |
|
|
// kernel performance. Check it then using the eCos 'tm_basic' test.
|
156 |
|
|
ldr r1,= (0x0 << 0) /* IDCY=0, idle cycles */\
|
157 |
|
|
| (0x0 << 5) /* WST1=0, read timing */\
|
158 |
|
|
| (0x1 << 10) /* RBLE=1 */\
|
159 |
|
|
| (0x0 << 11) /* WST2=0, write timing */\
|
160 |
|
|
| (0x2 << 28) /* MW=2, 32-bits */
|
161 |
|
|
str r1,[r0]
|
162 |
|
|
|
163 |
|
|
.endm // _mem_init
|
164 |
|
|
|
165 |
|
|
.macro _gpio_init
|
166 |
|
|
ldr r0,=CYGARC_HAL_LPC2XXX_REG_PIN_BASE
|
167 |
|
|
|
168 |
|
|
// Configure P0.15:0 as PIO, but UART0
|
169 |
|
|
ldr r1,= (0x1 << 0) /* P0.0 as TxD0 */\
|
170 |
|
|
| (0x1 << 2) /* P0.1 as RxD0 */
|
171 |
|
|
str r1,[r0,#CYGARC_HAL_LPC2XXX_REG_PINSEL0]
|
172 |
|
|
|
173 |
|
|
// Configure P0.30:16 as PIO
|
174 |
|
|
ldr r1,=0
|
175 |
|
|
str r1,[r0,#CYGARC_HAL_LPC2XXX_REG_PINSEL1]
|
176 |
|
|
|
177 |
|
|
// GPIO P1.25:16, P3.0, P3.25:24 are used as PIO
|
178 |
|
|
ldr r1,= (0x1 << 2) /* P1.31:26 Debug port */\
|
179 |
|
|
| (0x2 << 4) /* D31:0,CS0,OE,BLS0-3 */\
|
180 |
|
|
| (0x1 << 8) /* WE enabled */\
|
181 |
|
|
| (0x1 << 11) /* CS1 enabled */\
|
182 |
|
|
| (0x1 << 24) /* A1 enabled */\
|
183 |
|
|
| (0x7 << 25) /* A23:2 enabled */
|
184 |
|
|
str r1,[r0,#CYGARC_HAL_LPC2XXX_REG_PINSEL2]
|
185 |
|
|
|
186 |
|
|
.endm // _gpio_init
|
187 |
|
|
|
188 |
|
|
.macro _relocate
|
189 |
|
|
// Relocate ROM/FLASH to RAM
|
190 |
|
|
ldr r0,= -8192
|
191 |
|
|
and r0,r0,pc
|
192 |
|
|
ldr r1,=(CYGMEM_REGION_ram)
|
193 |
|
|
ldr r2,=(CYGMEM_REGION_ram+0x3E000)
|
194 |
|
|
10: ldr r3,[r0],#4
|
195 |
|
|
str r3,[r1],#4
|
196 |
|
|
cmp r1,r2
|
197 |
|
|
bne 10b
|
198 |
|
|
ldr r0,=20f
|
199 |
|
|
mov pc,r0
|
200 |
|
|
20:
|
201 |
|
|
.endm // relocate
|
202 |
|
|
|
203 |
|
|
#define CYGHWR_LED_MACRO _led \x
|
204 |
|
|
|
205 |
|
|
#if defined(CYG_HAL_STARTUP_ROM) || defined(CYG_HAL_STARTUP_ROMRAM)
|
206 |
|
|
|
207 |
|
|
.macro _setup
|
208 |
|
|
|
209 |
|
|
_pll_init
|
210 |
|
|
|
211 |
|
|
_mem_init
|
212 |
|
|
|
213 |
|
|
_gpio_init
|
214 |
|
|
|
215 |
|
|
#if defined(CYG_HAL_STARTUP_ROMRAM)
|
216 |
|
|
_relocate
|
217 |
|
|
#endif
|
218 |
|
|
_led_init
|
219 |
|
|
|
220 |
|
|
.endm
|
221 |
|
|
|
222 |
|
|
|
223 |
|
|
#define CYGSEM_HAL_ROM_RESET_USES_JUMP
|
224 |
|
|
|
225 |
|
|
#else
|
226 |
|
|
|
227 |
|
|
.macro _setup
|
228 |
|
|
|
229 |
|
|
.endm
|
230 |
|
|
|
231 |
|
|
#endif // CYG_HAL_STARTUP_ROM
|
232 |
|
|
|
233 |
|
|
#define PLATFORM_SETUP1 _setup
|
234 |
|
|
|
235 |
|
|
//-----------------------------------------------------------------------------
|
236 |
|
|
// end of hal_platform_setup.h
|
237 |
|
|
#endif // CYGONCE_HAL_PLATFORM_SETUP_H
|