1 //==========================================================================
5 // HAL misc board support code for the board
7 //==========================================================================
8 //####ECOSGPLCOPYRIGHTBEGIN####
9 // -------------------------------------------
10 // This file is part of eCos, the Embedded Configurable Operating System.
11 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
13 // eCos is free software; you can redistribute it and/or modify it under
14 // the terms of the GNU General Public License as published by the Free
15 // Software Foundation; either version 2 or (at your option) any later version.
17 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 // You should have received a copy of the GNU General Public License along
23 // with eCos; if not, write to the Free Software Foundation, Inc.,
24 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
26 // As a special exception, if other files instantiate templates or use macros
27 // or inline functions from this file, or you compile this file and link it
28 // with other works to produce a work based on this file, this file does not
29 // by itself cause the resulting work to be covered by the GNU General Public
30 // License. However the source code for this file must still be made available
31 // in accordance with section (3) of the GNU General Public License.
33 // This exception does not invalidate any other reasons why a work based on
34 // this file might be covered by the GNU General Public License.
36 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
37 // at http://sources.redhat.com/ecos/ecos-license/
38 // -------------------------------------------
39 //####ECOSGPLCOPYRIGHTEND####
40 //========================================================================*/
42 #include <pkgconf/hal.h>
43 #include <pkgconf/system.h>
44 #include CYGBLD_HAL_PLATFORM_H
46 #include <cyg/infra/cyg_type.h> // base types
47 #include <cyg/infra/cyg_trac.h> // tracing macros
48 #include <cyg/infra/cyg_ass.h> // assertion macros
50 #include <cyg/hal/hal_io.h> // IO macros
51 #include <cyg/hal/hal_arch.h> // Register state info
52 #include <cyg/hal/hal_diag.h>
53 #include <cyg/hal/hal_intr.h> // Interrupt names
54 #include <cyg/hal/hal_cache.h>
55 #include <cyg/hal/hal_soc.h> // Hardware definitions
56 #include <cyg/hal/fsl_board.h> // Platform specifics
58 #include <cyg/infra/diag.h> // diag_printf
60 // All the MM table layout is here:
61 #include <cyg/hal/hal_mm.h>
63 externC void* memset(void *, int, size_t);
65 void hal_mmu_init(void)
67 unsigned long ttb_base = RAM_BANK0_BASE + 0x4000;
71 * Set the TTB register
73 asm volatile ("mcr p15,0,%0,c2,c0,0" : : "r"(ttb_base) /*:*/);
76 * Set the Domain Access Control Register
78 i = ARM_ACCESS_DACR_DEFAULT;
79 asm volatile ("mcr p15,0,%0,c3,c0,0" : : "r"(i) /*:*/);
82 * First clear all TT entries - ie Set them to Faulting
84 memset((void *)ttb_base, 0, ARM_FIRST_LEVEL_PAGE_TABLE_SIZE);
86 /* Actual Virtual Size Attributes Function */
87 /* Base Base MB cached? buffered? access permissions */
88 /* xxx00000 xxx00000 */
89 X_ARM_MMU_SECTION(0x000, 0x500, 1, ARM_CACHEABLE, ARM_BUFFERABLE, ARM_ACCESS_PERM_RW_RW); /* Boot Rom */
90 X_ARM_MMU_SECTION(0x100, 0x100, 1, ARM_UNCACHEABLE, ARM_UNBUFFERABLE, ARM_ACCESS_PERM_RW_RW); /* Internal Regsisters */
91 X_ARM_MMU_SECTION(0xC00, 0x000, 64, ARM_CACHEABLE, ARM_BUFFERABLE, ARM_ACCESS_PERM_RW_RW); /* SDRAM */
92 X_ARM_MMU_SECTION(0xC00, 0xC00, 64, ARM_CACHEABLE, ARM_BUFFERABLE, ARM_ACCESS_PERM_RW_RW); /* SDRAM */
93 X_ARM_MMU_SECTION(0xC80, 0xC80, 32, ARM_CACHEABLE, ARM_BUFFERABLE, ARM_ACCESS_PERM_RW_RW); /* Flash */
94 X_ARM_MMU_SECTION(0xCC0, 0xCC0, 832, ARM_UNCACHEABLE, ARM_UNBUFFERABLE, ARM_ACCESS_PERM_RW_RW); /* External I/O */
98 // Platform specific initialization
101 void plf_hardware_init(void)
104 *REG32_PTR(MX21_GPIO_PMASK) = 0x0000003F;
106 /* Init pull-up enable */
107 *REG32_PTR(MX21_GPIOA_BASE+KHwGpioPUEN) = 0xFFFFFFFF;
108 *REG32_PTR(MX21_GPIOB_BASE+KHwGpioPUEN) = 0xFFFFFFFF;
109 *REG32_PTR(MX21_GPIOC_BASE+KHwGpioPUEN) = 0xFFFFFFFF;
110 *REG32_PTR(MX21_GPIOD_BASE+KHwGpioPUEN) = 0xFFFFFFFF;
111 *REG32_PTR(MX21_GPIOE_BASE+KHwGpioPUEN) = 0xFFFFFFFF;
112 *REG32_PTR(MX21_GPIOF_BASE+KHwGpioPUEN) = 0xFFFFFFFF;
114 /* Init data direction */
115 *REG32_PTR(MX21_GPIOA_BASE+KHwGpioDDIR) = 0x00000000;
116 *REG32_PTR(MX21_GPIOB_BASE+KHwGpioDDIR) = 0x40000000;
117 *REG32_PTR(MX21_GPIOC_BASE+KHwGpioDDIR) = 0x00000000;
118 *REG32_PTR(MX21_GPIOD_BASE+KHwGpioDDIR) = 0x00000000;
119 *REG32_PTR(MX21_GPIOE_BASE+KHwGpioDDIR) = 0x00000000;
120 *REG32_PTR(MX21_GPIOF_BASE+KHwGpioDDIR) = 0x00000000;
122 /* Init output configuration */
123 *REG32_PTR(MX21_GPIOA_BASE+KHwGpioOCR1) = 0x00000000;
124 *REG32_PTR(MX21_GPIOB_BASE+KHwGpioOCR1) = 0xFFFFFFFF;
125 *REG32_PTR(MX21_GPIOC_BASE+KHwGpioOCR1) = 0x00000000;
126 *REG32_PTR(MX21_GPIOD_BASE+KHwGpioOCR1) = 0x00000000;
127 *REG32_PTR(MX21_GPIOE_BASE+KHwGpioOCR1) = 0x00000000;
128 *REG32_PTR(MX21_GPIOF_BASE+KHwGpioOCR1) = 0x00000000;
129 *REG32_PTR(MX21_GPIOA_BASE+KHwGpioOCR2) = 0x00000000;
130 /* Set PortB pin30 to C_IN to get UART4 to work. */
131 *REG32_PTR(MX21_GPIOB_BASE+KHwGpioOCR2) = 0xEFFFFFFF;
132 *REG32_PTR(MX21_GPIOC_BASE+KHwGpioOCR2) = 0x00000000;
133 *REG32_PTR(MX21_GPIOD_BASE+KHwGpioOCR2) = 0x00000000;
134 *REG32_PTR(MX21_GPIOE_BASE+KHwGpioOCR2) = 0x00000000;
135 *REG32_PTR(MX21_GPIOF_BASE+KHwGpioOCR2) = 0x00000000;
137 /* Init input configuration */
138 *REG32_PTR(MX21_GPIOA_BASE+KHwGpioICONFA1) = 0xFFFFFFFF;
139 *REG32_PTR(MX21_GPIOB_BASE+KHwGpioICONFA1) = 0xFFFFFFFF;
140 *REG32_PTR(MX21_GPIOC_BASE+KHwGpioICONFA1) = 0xFFFFFFFF;
141 *REG32_PTR(MX21_GPIOD_BASE+KHwGpioICONFA1) = 0xFFFFFFFF;
142 *REG32_PTR(MX21_GPIOE_BASE+KHwGpioICONFA1) = 0xFFFFFFFF;
143 *REG32_PTR(MX21_GPIOF_BASE+KHwGpioICONFA1) = 0xFFFFFFFF;
144 *REG32_PTR(MX21_GPIOA_BASE+KHwGpioICONFA2) = 0xFFFFFFFF;
145 /* Set PortB pin 29, pin 31 to A_OUT to get UART4 to work. */
146 *REG32_PTR(MX21_GPIOB_BASE+KHwGpioICONFA2) = 0x33FFFFFF;
147 *REG32_PTR(MX21_GPIOC_BASE+KHwGpioICONFA2) = 0xFFFFFFFF;
148 *REG32_PTR(MX21_GPIOD_BASE+KHwGpioICONFA2) = 0xFFFFFFFF;
149 *REG32_PTR(MX21_GPIOE_BASE+KHwGpioICONFA2) = 0xFFFFFFFF;
150 *REG32_PTR(MX21_GPIOF_BASE+KHwGpioICONFA2) = 0xFFFFFFFF;
151 *REG32_PTR(MX21_GPIOA_BASE+KHwGpioICONFB1) = 0xFFFFFFFF;
152 *REG32_PTR(MX21_GPIOB_BASE+KHwGpioICONFB1) = 0xFFFFFFFF;
153 *REG32_PTR(MX21_GPIOC_BASE+KHwGpioICONFB1) = 0xFFFFFFFF;
154 *REG32_PTR(MX21_GPIOD_BASE+KHwGpioICONFB1) = 0xFFFFFFFF;
155 *REG32_PTR(MX21_GPIOE_BASE+KHwGpioICONFB1) = 0xFFFFFFFF;
156 *REG32_PTR(MX21_GPIOF_BASE+KHwGpioICONFB1) = 0xFFFFFFFF;
157 *REG32_PTR(MX21_GPIOA_BASE+KHwGpioICONFB2) = 0xFFFFFFFF;
158 *REG32_PTR(MX21_GPIOB_BASE+KHwGpioICONFB2) = 0xFFFFFFFF;
159 *REG32_PTR(MX21_GPIOC_BASE+KHwGpioICONFB2) = 0xFFFFFFFF;
160 *REG32_PTR(MX21_GPIOD_BASE+KHwGpioICONFB2) = 0xFFFFFFFF;
161 *REG32_PTR(MX21_GPIOE_BASE+KHwGpioICONFB2) = 0xFFFFFFFF;
162 *REG32_PTR(MX21_GPIOF_BASE+KHwGpioICONFB2) = 0xFFFFFFFF;
165 *REG32_PTR(MX21_GPIOA_BASE+KHwGpioDR) = 0x00000000;
166 *REG32_PTR(MX21_GPIOB_BASE+KHwGpioDR) = 0x00000000;
167 *REG32_PTR(MX21_GPIOC_BASE+KHwGpioDR) = 0x00000000;
168 *REG32_PTR(MX21_GPIOD_BASE+KHwGpioDR) = 0x00000000;
169 *REG32_PTR(MX21_GPIOE_BASE+KHwGpioDR) = 0x00000000;
170 *REG32_PTR(MX21_GPIOF_BASE+KHwGpioDR) = 0x00000000;
172 /* Init interrupt configuration */
173 *REG32_PTR(MX21_GPIOA_BASE+KHwGpioICR1) = 0x00000000;
174 *REG32_PTR(MX21_GPIOB_BASE+KHwGpioICR1) = 0x00000000;
175 *REG32_PTR(MX21_GPIOC_BASE+KHwGpioICR1) = 0x00000000;
176 *REG32_PTR(MX21_GPIOD_BASE+KHwGpioICR1) = 0x00000000;
177 *REG32_PTR(MX21_GPIOE_BASE+KHwGpioICR1) = 0x00000000;
178 *REG32_PTR(MX21_GPIOF_BASE+KHwGpioICR1) = 0x00000000;
179 *REG32_PTR(MX21_GPIOA_BASE+KHwGpioICR2) = 0x00000000;
180 *REG32_PTR(MX21_GPIOB_BASE+KHwGpioICR2) = 0x00000000;
181 *REG32_PTR(MX21_GPIOC_BASE+KHwGpioICR2) = 0x00000000;
182 *REG32_PTR(MX21_GPIOD_BASE+KHwGpioICR2) = 0x00000000;
183 *REG32_PTR(MX21_GPIOE_BASE+KHwGpioICR2) = 0x00000000;
184 *REG32_PTR(MX21_GPIOF_BASE+KHwGpioICR2) = 0x00000000;
186 /* Init interrupt mask */
187 *REG32_PTR(MX21_GPIOA_BASE+KHwGpioIMR) = 0x00000000;
188 *REG32_PTR(MX21_GPIOB_BASE+KHwGpioIMR) = 0x00000000;
189 *REG32_PTR(MX21_GPIOC_BASE+KHwGpioIMR) = 0x00000000;
190 *REG32_PTR(MX21_GPIOD_BASE+KHwGpioIMR) = 0x00000000;
191 *REG32_PTR(MX21_GPIOE_BASE+KHwGpioIMR) = 0x00000000;
192 *REG32_PTR(MX21_GPIOF_BASE+KHwGpioIMR) = 0x00000000;
194 /* Init general purpose. */
195 /* For using UART4: Set PortB bit 28 for selecting alternate function*/
196 *REG32_PTR(MX21_GPIOA_BASE+KHwGpioGPR) = 0x00000000;
197 *REG32_PTR(MX21_GPIOB_BASE+KHwGpioGPR) = 0x10000000;
198 *REG32_PTR(MX21_GPIOC_BASE+KHwGpioGPR) = 0x00000000;
199 *REG32_PTR(MX21_GPIOD_BASE+KHwGpioGPR) = 0x00000000;
200 *REG32_PTR(MX21_GPIOE_BASE+KHwGpioGPR) = 0x00000000;
201 *REG32_PTR(MX21_GPIOF_BASE+KHwGpioGPR) = 0x00000000;
203 /* Init GPIO in use. */
204 /* For using UART4: */
205 /* Set PortB pin 28 as alternate, pin 29, 30 and 31 as GPIO */
206 *REG32_PTR(MX21_GPIOA_BASE+KHwGpioGIUS) = 0xFFFFFFE0;
207 *REG32_PTR(MX21_GPIOB_BASE+KHwGpioGIUS) = 0xEF3FFFF0;
208 *REG32_PTR(MX21_GPIOC_BASE+KHwGpioGIUS) = 0xFFFFFFE0;
209 *REG32_PTR(MX21_GPIOD_BASE+KHwGpioGIUS) = 0xFFFE0000;
210 *REG32_PTR(MX21_GPIOE_BASE+KHwGpioGIUS) = 0x00FC0F20;
211 *REG32_PTR(MX21_GPIOF_BASE+KHwGpioGIUS) = 0x00000000;
213 /* Set the FMCR register, to enable UART4 RXD functionality. */
214 *REG32_PTR(MX21_FMCR) = 0xFCFFFFCB;
218 #include CYGHWR_MEMORY_LAYOUT_H
220 typedef void code_fun(void);
222 void board_program_new_stack(void *func)
224 register CYG_ADDRESS stack_ptr asm("sp");
225 register CYG_ADDRESS old_stack asm("r4");
226 register code_fun *new_func asm("r0");
227 old_stack = stack_ptr;
228 stack_ptr = CYGMEM_REGION_ram + CYGMEM_REGION_ram_SIZE - sizeof(CYG_ADDRESS);
229 new_func = (code_fun*)func;
231 stack_ptr = old_stack;
234 // ------------------------------------------------------------------------