]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/hal/arm/at91/at91sam7s/v2_0/include/hal_platform_setup.h
Initial revision
[karo-tx-redboot.git] / packages / hal / arm / at91 / at91sam7s / v2_0 / include / hal_platform_setup.h
1 #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
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 Red Hat, Inc.
15 // Copyright (C) 2006 eCosCentric Ltd
16 // Copy
17
18 // eCos is free software; you can redistribute it and/or modify it under
19 // the terms of the GNU General Public License as published by the Free
20 // Software Foundation; either version 2 or (at your option) any later version.
21 //
22 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
23 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
24 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
25 // for more details.
26 //
27 // You should have received a copy of the GNU General Public License along
28 // with eCos; if not, write to the Free Software Foundation, Inc.,
29 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
30 //
31 // As a special exception, if other files instantiate templates or use macros
32 // or inline functions from this file, or you compile this file and link it
33 // with other works to produce a work based on this file, this file does not
34 // by itself cause the resulting work to be covered by the GNU General Public
35 // License. However the source code for this file must still be made available
36 // in accordance with section (3) of the GNU General Public License.
37 //
38 // This exception does not invalidate any other reasons why a work based on
39 // 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, asl
47 // Date:        2006-02-18
48 // Purpose:     AT91SAM7S 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 #include <cyg/hal/plf_io.h>
58         
59 // Macro to initialise the Memory Controller
60         .macro _flash_init
61 __flash_init__:
62         ldr     r0,=AT91_MC
63 #if CYGNUM_HAL_ARM_AT91_CLOCK_SPEED > 60000000
64         // When the clock is running faster than 60MHz we need two wait states
65         ldr     r1,=(AT91_MC_FMR_2FWS)
66 #else 
67 # if CYGNUM_HAL_ARM_AT91_CLOCK_SPEED > 30000000
68         // When the clock is running faster than 30MHz we need a wait state
69         ldr     r1,=(AT91_MC_FMR_1FWS)
70 # else
71         // We have a slow clock, no extra wait states are needed
72         ldr     r1,=AT91_MC_FMR_0FWS
73 # endif
74 #endif
75         str     r1,[r0,#AT91_MC_FMR]
76         .endm
77
78 // Macro to start the main clock.
79         .macro  _main_clock_init
80 __main_clock_init__:
81         ldr     r0,=AT91_PMC
82           // Swap to the slow clock, just to be sure.
83         ldr     r1,=(AT91_PMC_MCKR_PRES_CLK|AT91_PMC_MCKR_SLOW_CLK)
84         str     r1,[r0,#AT91_PMC_MCKR]
85         // startup time
86 #if defined(CYGNUM_HAL_ARM_AT91_CLOCK_TYPE_EXTCLOCK)
87         ldr     r1,=(AT91_PMC_MOR_OSCBYPASS)
88 #else
89         ldr     r1,=(AT91_PMC_MOR_OSCCOUNT(6)|AT91_PMC_MOR_MOSCEN)
90 #endif
91         str     r1,[r0,#AT91_PMC_MOR]
92
93         // Wait for oscilator start timeout
94 wait_pmc_sr_1:  
95         ldr     r1,[r0,#AT91_PMC_SR]
96         ands    r1,r1,#AT91_PMC_SR_MOSCS
97         beq     wait_pmc_sr_1
98
99         // Set the PLL multiplier and divider. 16 slow clocks go by
100         // before the LOCK bit is set. */
101         ldr     r1,=((AT91_PMC_PLLR_DIV(CYGNUM_HAL_ARM_AT91_PLL_DIVIDER))|(AT91_PMC_PLLR_PLLCOUNT(16))|(AT91_PMC_PLLR_MUL(CYGNUM_HAL_ARM_AT91_PLL_MULTIPLIER-1)))
102         str     r1,[r0,#AT91_PMC_PLLR]
103
104         // Wait for PLL locked indication
105 wait_pmc_sr_2:
106         ldr     r1,[r0,#AT91_PMC_SR]
107         ands    r1,r1,#AT91_PMC_SR_LOCK
108         beq     wait_pmc_sr_2
109
110         // Enable the PLL clock and set the prescale to 2 */
111         ldr     r1,=(AT91_PMC_MCKR_PRES_CLK_2|AT91_PMC_MCKR_PLL_CLK)
112         str     r1,[r0,#AT91_PMC_MCKR]
113
114         // Wait for the MCLK ready indication
115 wait_pmc_sr_3:
116         ldr     r1,[r0,#AT91_PMC_SR]
117         ands    r1,r1,#AT91_PMC_SR_MCKRDY
118         beq     wait_pmc_sr_3
119         .endm
120
121 // Remap the flash from address 0x0 and place RAM there instead.
122         .macro  _remap_flash
123 __remap_flash:
124         ldr     r0,=0x000004 // Use the underfined instruction exception
125         ldr     r1,=0x200004
126         ldr     r2,[r0]      // Save away copies so we can restore them
127         ldr     r3,[r1]
128         ldr     r4,=0xffffff
129         eor     r4,r3,r4     // XOR the contents of 0x20004 
130         str     r4,[r1]      // and write it
131         ldr     r5,[r0]      // Read from low memory
132         cmp     r5,r4
133         beq     remap_done
134         ldr     r0,=AT91_MC  // Need to do a remap
135         ldr     r5,=1
136         str     r5,[r0,#AT91_MC_RCR]
137 remap_done:
138         str     r3,[r1]      // restore the value we changed
139         .endm
140         
141 #if defined(CYG_HAL_STARTUP_ROM)
142         .macro  _setup
143         _flash_init
144         _main_clock_init
145         _remap_flash
146         .endm
147
148 #define PLATFORM_SETUP1     _setup
149 #else
150 #define PLATFORM_SETUP1
151 #endif
152
153 //-----------------------------------------------------------------------------
154 // end of hal_platform_setup.h
155 #endif // CYGONCE_HAL_PLATFORM_SETUP_H