]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/hal/arm/lpc2xxx/phycore229x/v2_0/include/hal_platform_setup.h
Initial revision
[karo-tx-redboot.git] / packages / hal / arm / lpc2xxx / phycore229x / v2_0 / include / hal_platform_setup.h
1 #ifndef CYGONCE_HAL_PLATFORM_SETUP_H
2 #define CYGONCE_HAL_PLATFORM_SETUP_H
3 /*=============================================================================
4 //
5 //      hal_platform_setup.h
6 //
7 //      Platform specific support for HAL (assembly code)
8 //
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.
14 // Copyright (C) 2008 eCosCentric Limited
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 version.
19 //
20 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
21 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
22 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
23 // for more details.
24 //
25 // You should have received a copy of the GNU General Public License along
26 // with eCos; if not, write to the Free Software Foundation, Inc.,
27 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
28 //
29 // As a special exception, if other files instantiate templates or use macros
30 // or inline functions from this file, or you compile this file and link it
31 // with other works to produce a work based on this file, this file does not
32 // by itself cause the resulting work to be covered by the GNU General Public
33 // License. However the source code for this file must still be made available
34 // in accordance with section (3) of the GNU General Public License.
35 //
36 // This exception does not invalidate any other reasons why a work based on
37 // this file might be covered by the GNU General Public License.
38 // -------------------------------------------
39 //####ECOSGPLCOPYRIGHTEND####
40 //=============================================================================
41 //#####DESCRIPTIONBEGIN####
42 //
43 // Author(s):    Uwe Kindler
44 // Contributors: Uwe Kindler
45 // Date:         2007-12-02
46 // Purpose:      phyCORE-LPC229x platform specific support routines
47 // Description:
48 // Usage:        #include <cyg/hal/hal_platform_setup.h>
49 //
50 //####DESCRIPTIONEND####
51 //
52 //===========================================================================*/
53 #include <pkgconf/system.h>
54 #include <cyg/hal/var_io.h>
55
56 //===========================================================================*/
57
58 #define LINES (0xFE<<16)
59 #define LINE  (1<<16)
60 .macro  _line_init
61     // set to GPIO
62     ldr r0,=CYGARC_HAL_LPC2XXX_REG_PIN_BASE
63     ldr r1,[r0,#CYGARC_HAL_LPC2XXX_REG_PINSEL2]
64     bic r1, r1, #8
65     str r1,[r0,#CYGARC_HAL_LPC2XXX_REG_PINSEL2]
66     // set to output
67     ldr r0,=CYGARC_HAL_LPC2XXX_REG_IO_BASE
68     ldr r1,[r0,#CYGARC_HAL_LPC2XXX_REG_IO1DIR]
69     orr r1,r1,#LINE
70     str r1,[r0,#CYGARC_HAL_LPC2XXX_REG_IO1DIR]
71     // turn ON
72     ldr r1,[r0,#CYGARC_HAL_LPC2XXX_REG_IO1PIN]
73     bic r1,r1,#LINES
74     orr r1,r1,#LINE
75     str r1,[r0,#CYGARC_HAL_LPC2XXX_REG_IO1PIN]
76 .endm
77
78 //----------------------------------------------------------------------------
79 // The phyCORE Carrier Board HD200 offers a programmable LED at
80 // D3 for user implementations. This LED can be connected to port pin
81 // P0.8 (TxD1) of the phyCORE-LPC2292/94 which is available via
82 // signal GPIO0 (JP17 = closed). A low-level at port pin P0.8 causes the
83 // LED to illuminate, LED D3 remains off when writing a high-level to
84 // P0.8.
85 //
86 .macro  _led_init
87     ldr r0,=CYGARC_HAL_LPC2XXX_REG_IO_BASE
88     ldr r1,=(1<<8)                                // GPIO0 pins 8 is LED output
89     str r1,[r0,#CYGARC_HAL_LPC2XXX_REG_IO0DIR]
90 .endm
91
92 .macro _led x
93     ldr r0,=CYGARC_HAL_LPC2XXX_REG_IO_BASE
94     ldr r1,=(1<<8)
95     str r1,[r0,#CYGARC_HAL_LPC2XXX_REG_IO0CLR]
96     ldr r1,=((\x & 1)<<8)
97     str r1,[r0,#CYGARC_HAL_LPC2XXX_REG_IO0SET]
98 .endm
99 #define CYGHWR_LED_MACRO _led \x 
100
101
102 //----------------------------------------------------------------------------
103 // PLL initialisation
104 //
105 .macro _pll_init
106     ldr r0,=CYGARC_HAL_LPC2XXX_REG_SCB_BASE
107
108     mov r2,#0xAA
109     mov r3,#0x55
110
111     mov r1,#(0x20 | (CYGNUM_HAL_ARM_LPC2XXX_PLL_MUL - 1))
112     // load the PLL configuration register
113     str r1,[r0,#CYGARC_HAL_LPC2XXX_REG_PLLCFG] 
114
115     mov r1,#1
116     str r1,[r0,#CYGARC_HAL_LPC2XXX_REG_PLLCON] // enable PLL
117
118     // perform validation sequence 0XAA followed by 0x55
119     str r2,[r0,#CYGARC_HAL_LPC2XXX_REG_PLLFEED] 
120     str r3,[r0,#CYGARC_HAL_LPC2XXX_REG_PLLFEED]
121
122 1:
123     ldr r1,[r0,#CYGARC_HAL_LPC2XXX_REG_PLLSTAT] // wait for it to lock
124     ands r1,r1,#(1<<10)
125     beq 1b
126
127     mov r1,#3 // connect PLL
128     str r1,[r0,#CYGARC_HAL_LPC2XXX_REG_PLLCON]
129
130     // perform validation sequence 0XAA followed by 0x55
131     str r2,[r0,#CYGARC_HAL_LPC2XXX_REG_PLLFEED] 
132     str r3,[r0,#CYGARC_HAL_LPC2XXX_REG_PLLFEED] 
133 .endm
134
135
136 //----------------------------------------------------------------------------
137 // External memory and bus initialisation
138 //
139 .macro _mem_init
140     //
141     // first map the vector table to internal flash - normally this should be
142     // the default value after boot - but we go the safe way here and force
143     // the mapping to internal flash (the value for
144     // CYGARC_HAL_LPC2XXX_REG_MEMMAP is 1)
145     //
146     ldr r0,=CYGARC_HAL_LPC2XXX_REG_SCB_BASE
147     mov r1,#1
148     str r1, [r0,#CYGARC_HAL_LPC2XXX_REG_MEMMAP] 
149     
150     //    
151     // Now its is save to copy the first 64 bytes of flash to RAM
152     //
153     mov r0,#0                                   
154     mov r1,#0x40000000
155     mov r2,#0x40
156 1:
157     ldr r3,[r0,#4]!
158     str r3,[r1,#4]!
159     cmps r0,r2
160     bne 1b
161         
162     // 
163     // Now we can map the vector table to internal SRAM because the SRAM no
164     // contains a copy of the vector tablefrom flash (the value for 
165     // CYGARC_HAL_LPC2XXX_REG_MEMMAP is 2 = SRAM)
166     //
167     ldr r0,=CYGARC_HAL_LPC2XXX_REG_SCB_BASE
168     // User RAM Mode. Interrupt vectors are re-mapped to Static RAM.
169     mov r1,#2                                   
170     str r1, [r0,#CYGARC_HAL_LPC2XXX_REG_MEMMAP] 
171     // 4 processor clocks fetch cycle
172     mov r1,#4                                                   
173     str r1,[r0,#CYGARC_HAL_LPC2XXX_REG_MAMTIM]  // flash timings
174     mov r1,#2
175     str r1,[r0,#CYGARC_HAL_LPC2XXX_REG_MAMCR]   // enable full MAM
176     
177     //
178     // Set-up external memory - the main task here is to setup the
179     // wait states for the external memory properly
180     //
181     // Bank Configuration Registers 0-3 (BCFG0-3)
182     // [0..3]          IDCY: Min. number of idle Cycles <0-15>
183     // [4]             Reserved     
184     // [5..9]          WST1: Wait States 1 <0-31>
185     // [10]            RBLE: Read Byte Lane Enable
186     // [11..15]        WST2: Wait States 2 <0-31>
187     // [16..23]        Reserved
188     // [26]            WP: Write Protect
189     // [27]            BM: Burst ROM
190     // [28..29]        MW: Memory Width  <0=8-bit,1=16-bit,2=32-bit,3=Reserved>
191     // [30..31]        Reserved
192     //
193     
194     // enable external parallel bus signals
195     ldr r0,=CYGARC_HAL_LPC2XXX_REG_PIN_BASE
196     // A0..1 enabled, CS0..3, OE, WE, BLS0..3, D0..31, A2..23, JTAG Pins
197     ldr r1,=0x0FE149E4 
198     str r1,[r0,#CYGARC_HAL_LPC2XXX_REG_PINSEL2] 
199
200     // setup external FLASH wait states
201     ldr r0,=CYGARC_HAL_LPC2XXX_REG_BCFG0
202     ldr r1,=0x20003CE3
203     str r1, [r0]
204         
205     // setup external SRAM wait states
206     ldr r0,=CYGARC_HAL_LPC2XXX_REG_BCFG1
207     ldr r1,=0x020002483
208     str r1, [r0]
209
210     // setup Ethernet chip wait states for /CS2 and /CS3
211     ldr r0,=CYGARC_HAL_LPC2XXX_REG_BCFG2
212     ldr r1,=0x020000C23
213     str r1, [r0]
214     ldr r0,=CYGARC_HAL_LPC2XXX_REG_BCFG3
215     ldr r1,=0x020000C23
216     str r1, [r0]
217 .endm
218                 
219 .macro _gpio_init
220     // enable  RX and TX on UART0 and UART1
221     ldr r0,=CYGARC_HAL_LPC2XXX_REG_PIN_BASE     
222     ldr r1,=0x00050005
223     str r1,[r0,#CYGARC_HAL_LPC2XXX_REG_PINSEL0]
224     
225     // set pin function to EINT0
226     ldr r0,=CYGARC_HAL_LPC2XXX_REG_PIN_BASE     
227     ldr r1,=0x00000001
228     str r1,[r0,#CYGARC_HAL_LPC2XXX_REG_PINSEL1]
229 .endm
230
231 .macro  _block
232     ldr r0,=CYGARC_HAL_LPC2XXX_REG_IO_BASE
233     ldr r1,=(1<<8)
234     str r1,[r0,#CYGARC_HAL_LPC2XXX_REG_IO0CLR]
235 2:
236     nop
237     b 2
238 .endm
239 #define PLATFORM_BLOCK _block 
240 //===========================================================================*/
241                         
242 #if defined(CYG_HAL_STARTUP_ROM)
243 .macro  _setup
244         _line_init
245         _led_init
246         _led 1
247         _pll_init
248         _mem_init
249         _gpio_init
250 .endm
251 #define CYGSEM_HAL_ROM_RESET_USES_JUMP
252 #else
253         .macro  _setup
254
255         .endm    
256 #endif
257
258 #define PLATFORM_SETUP1 _setup
259
260 //-----------------------------------------------------------------------------
261 // end of hal_platform_setup.h
262 #endif // CYGONCE_HAL_PLATFORM_SETUP_H