1 |
786 |
skrzyp |
//==========================================================================
|
2 |
|
|
//
|
3 |
|
|
// lpc1766stk_misc.c
|
4 |
|
|
//
|
5 |
|
|
// Cortex-M3 LPC1766STK HAL functions
|
6 |
|
|
//
|
7 |
|
|
//==========================================================================
|
8 |
|
|
// ####ECOSGPLCOPYRIGHTBEGIN####
|
9 |
|
|
// -------------------------------------------
|
10 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
11 |
|
|
// Copyright (C) 2008 Free Software Foundation, Inc.
|
12 |
|
|
//
|
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
|
16 |
|
|
// version.
|
17 |
|
|
//
|
18 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT
|
19 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
20 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
21 |
|
|
// for more details.
|
22 |
|
|
//
|
23 |
|
|
// You should have received a copy of the GNU General Public License
|
24 |
|
|
// along with eCos; if not, write to the Free Software Foundation, Inc.,
|
25 |
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
26 |
|
|
//
|
27 |
|
|
// As a special exception, if other files instantiate templates or use
|
28 |
|
|
// macros or inline functions from this file, or you compile this file
|
29 |
|
|
// and link it with other works to produce a work based on this file,
|
30 |
|
|
// this file does not by itself cause the resulting work to be covered by
|
31 |
|
|
// the GNU General Public License. However the source code for this file
|
32 |
|
|
// must still be made available in accordance with section (3) of the GNU
|
33 |
|
|
// General Public License v2.
|
34 |
|
|
//
|
35 |
|
|
// This exception does not invalidate any other reasons why a work based
|
36 |
|
|
// on this file might be covered by the GNU General Public License.
|
37 |
|
|
// -------------------------------------------
|
38 |
|
|
// ####ECOSGPLCOPYRIGHTEND####
|
39 |
|
|
//==========================================================================
|
40 |
|
|
//#####DESCRIPTIONBEGIN####
|
41 |
|
|
//
|
42 |
|
|
// Author(s): nickg
|
43 |
|
|
// Contributor(s): ilijak
|
44 |
|
|
// Date: 2010-12-22
|
45 |
|
|
// Description:
|
46 |
|
|
//
|
47 |
|
|
//####DESCRIPTIONEND####
|
48 |
|
|
//
|
49 |
|
|
//==========================================================================
|
50 |
|
|
|
51 |
|
|
#include <pkgconf/hal.h>
|
52 |
|
|
#include <pkgconf/hal_cortexm.h>
|
53 |
|
|
#include <pkgconf/hal_cortexm_lpc17xx.h>
|
54 |
|
|
#include <pkgconf/hal_cortexm_lpc17xx_lpc1766stk.h>
|
55 |
|
|
#ifdef CYGPKG_KERNEL
|
56 |
|
|
# include <pkgconf/kernel.h>
|
57 |
|
|
#endif
|
58 |
|
|
|
59 |
|
|
#include <cyg/infra/diag.h>
|
60 |
|
|
#include <cyg/infra/cyg_type.h>
|
61 |
|
|
#include <cyg/infra/cyg_trac.h> // tracing macros
|
62 |
|
|
#include <cyg/infra/cyg_ass.h> // assertion macros
|
63 |
|
|
|
64 |
|
|
#include <cyg/hal/hal_arch.h> // HAL header
|
65 |
|
|
#include <cyg/hal/hal_intr.h> // HAL header
|
66 |
|
|
static inline void hal_gpio_init(void);
|
67 |
|
|
|
68 |
|
|
|
69 |
|
|
//==========================================================================
|
70 |
|
|
// System init
|
71 |
|
|
//
|
72 |
|
|
// This is run to set up the basic system, including GPIO setting,
|
73 |
|
|
// clock feeds, power supply, and memory initialization. This code
|
74 |
|
|
// runs before the DATA is copied from ROM and the BSS cleared, hence
|
75 |
|
|
// it cannot make use of static variables or data tables.
|
76 |
|
|
|
77 |
|
|
__externC void
|
78 |
|
|
hal_system_init(void)
|
79 |
|
|
{
|
80 |
|
|
#if defined(CYG_HAL_STARTUP_ROM) | defined(CYG_HAL_STARTUP_SRAM)
|
81 |
|
|
hal_gpio_init();
|
82 |
|
|
#endif
|
83 |
|
|
|
84 |
|
|
#if defined(CYG_HAL_STARTUP_ROM)
|
85 |
|
|
{
|
86 |
|
|
// Set flash accelerator according to CPU clock speed.
|
87 |
|
|
cyg_uint32 regval;
|
88 |
|
|
HAL_READ_UINT32(CYGHWR_HAL_LPC17XX_REG_SCB_BASE +
|
89 |
|
|
CYGHWR_HAL_LPC17XX_REG_FLASHCFG, regval);
|
90 |
|
|
regval &= ~CYGHWR_HAL_LPC17XX_REG_FLTIM_MASK;
|
91 |
|
|
regval |= CYGHWR_HAL_LPC17XX_REG_FLASHTIM;
|
92 |
|
|
HAL_WRITE_UINT32(CYGHWR_HAL_LPC17XX_REG_SCB_BASE +
|
93 |
|
|
CYGHWR_HAL_LPC17XX_REG_FLASHCFG, regval);
|
94 |
|
|
}
|
95 |
|
|
#endif
|
96 |
|
|
}
|
97 |
|
|
|
98 |
|
|
|
99 |
|
|
//===========================================================================
|
100 |
|
|
// hal_gpio_init
|
101 |
|
|
//===========================================================================
|
102 |
|
|
static inline void
|
103 |
|
|
hal_gpio_init(void)
|
104 |
|
|
{
|
105 |
|
|
// Enable UART0 and UART1 (has wired flow control and line status lines)
|
106 |
|
|
CYGHWR_HAL_LPC17XX_PIN_SET(CYGHWR_HAL_LPC17XX_REG_PINSEL0,
|
107 |
|
|
(1 /* TXD0 */ << 4) |
|
108 |
|
|
(1 /* RXD0 */ << 6) |
|
109 |
|
|
(1 /* TXD1 */ << 30)
|
110 |
|
|
);
|
111 |
|
|
CYGHWR_HAL_LPC17XX_PIN_SET(CYGHWR_HAL_LPC17XX_REG_PINSEL1,
|
112 |
|
|
(1 /* RXD1 */ << 0) |
|
113 |
|
|
(1 /* CTS1 */ << 2) |
|
114 |
|
|
(1 /* DCD1 */ << 4) |
|
115 |
|
|
(1 /* DSR1 */ << 6) |
|
116 |
|
|
(1 /* DTR1 */ << 8) |
|
117 |
|
|
(1 /* RTS1 */ << 12)
|
118 |
|
|
);
|
119 |
|
|
CYGHWR_HAL_LPC17XX_PIN_SET(CYGHWR_HAL_LPC17XX_REG_PINSEL2, 0);
|
120 |
|
|
CYGHWR_HAL_LPC17XX_PIN_SET(CYGHWR_HAL_LPC17XX_REG_PINSEL3, 0);
|
121 |
|
|
CYGHWR_HAL_LPC17XX_PIN_SET(CYGHWR_HAL_LPC17XX_REG_PINSEL4, 0);
|
122 |
|
|
#if 0 // not used
|
123 |
|
|
CYGHWR_HAL_LPC17XX_PIN_SET(CYGHWR_HAL_LPC17XX_REG_PINSEL5, 0);
|
124 |
|
|
CYGHWR_HAL_LPC17XX_PIN_SET(CYGHWR_HAL_LPC17XX_REG_PINSEL6, 0);
|
125 |
|
|
#endif
|
126 |
|
|
CYGHWR_HAL_LPC17XX_PIN_SET(CYGHWR_HAL_LPC17XX_REG_PINSEL7, 0);
|
127 |
|
|
#if 0 // not used
|
128 |
|
|
CYGHWR_HAL_LPC17XX_PIN_SET(CYGHWR_HAL_LPC17XX_REG_PINSEL8, 0);
|
129 |
|
|
#endif
|
130 |
|
|
CYGHWR_HAL_LPC17XX_PIN_SET(CYGHWR_HAL_LPC17XX_REG_PINSEL9, 0);
|
131 |
|
|
CYGHWR_HAL_LPC17XX_PIN_SET(CYGHWR_HAL_LPC17XX_REG_PINSEL10, 0);
|
132 |
|
|
}
|
133 |
|
|
|
134 |
|
|
|
135 |
|
|
//==========================================================================
|
136 |
|
|
|
137 |
|
|
__externC void
|
138 |
|
|
hal_platform_init(void)
|
139 |
|
|
{
|
140 |
|
|
}
|
141 |
|
|
|
142 |
|
|
//==========================================================================
|
143 |
|
|
|
144 |
|
|
#ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
|
145 |
|
|
|
146 |
|
|
#include CYGHWR_MEMORY_LAYOUT_H
|
147 |
|
|
|
148 |
|
|
//--------------------------------------------------------------------------
|
149 |
|
|
// Accesses to areas not backed by real devices or memory can cause
|
150 |
|
|
// the CPU to hang.
|
151 |
|
|
//
|
152 |
|
|
// The following table defines the memory areas that GDB is allowed to
|
153 |
|
|
// touch. All others are disallowed.
|
154 |
|
|
// This table needs to be kept up to date with the set of memory areas
|
155 |
|
|
// that are available on the board.
|
156 |
|
|
|
157 |
|
|
static struct {
|
158 |
|
|
CYG_ADDRESS start; // Region start address
|
159 |
|
|
CYG_ADDRESS end; // End address (last byte)
|
160 |
|
|
} hal_data_access[] = {
|
161 |
|
|
{
|
162 |
|
|
// Main RAM (On-chip SRAM in code area)
|
163 |
|
|
CYGMEM_REGION_ram, CYGMEM_REGION_ram + CYGMEM_REGION_ram_SIZE - 1},
|
164 |
|
|
#ifdef CYGMEM_REGION_ahb_sram_bank0
|
165 |
|
|
{
|
166 |
|
|
// On-chip AHB SRAM bank 0
|
167 |
|
|
CYGMEM_REGION_ahb_sram_bank0, CYGMEM_REGION_ahb_sram_bank0 + CYGMEM_REGION_ahb_sram_bank0_SIZE - 1},
|
168 |
|
|
#endif
|
169 |
|
|
#ifdef CYGMEM_REGION_ahb_sram_bank1
|
170 |
|
|
{
|
171 |
|
|
// On-chip AHB SRAM bank 1
|
172 |
|
|
CYGMEM_REGION_ahb_sram_bank1, CYGMEM_REGION_ahb_sram_bank1 + CYGMEM_REGION_ahb_sram_bank1_SIZE - 1},
|
173 |
|
|
#endif
|
174 |
|
|
#ifdef CYGMEM_REGION_flash
|
175 |
|
|
{
|
176 |
|
|
// On-chip flash
|
177 |
|
|
CYGMEM_REGION_flash, CYGMEM_REGION_flash + CYGMEM_REGION_flash_SIZE - 1},
|
178 |
|
|
#endif
|
179 |
|
|
#ifdef CYGMEM_REGION_rom
|
180 |
|
|
{
|
181 |
|
|
// External flash
|
182 |
|
|
CYGMEM_REGION_rom, CYGMEM_REGION_rom + CYGMEM_REGION_rom_SIZE - 1},
|
183 |
|
|
#endif
|
184 |
|
|
{
|
185 |
|
|
0xE0000000, 0x00000000 - 1}, // Cortex-M peripherals
|
186 |
|
|
{
|
187 |
|
|
0x40000000, 0x60000000 - 1}, // Chip specific peripherals
|
188 |
|
|
};
|
189 |
|
|
|
190 |
|
|
__externC int
|
191 |
|
|
cyg_hal_stub_permit_data_access(CYG_ADDRESS addr, cyg_uint32 count)
|
192 |
|
|
{
|
193 |
|
|
int i;
|
194 |
|
|
|
195 |
|
|
for (i = 0; i < sizeof(hal_data_access) / sizeof(hal_data_access[0]); i++) {
|
196 |
|
|
if ((addr >= hal_data_access[i].start) &&
|
197 |
|
|
(addr + count) <= hal_data_access[i].end)
|
198 |
|
|
return true;
|
199 |
|
|
}
|
200 |
|
|
|
201 |
|
|
return false;
|
202 |
|
|
}
|
203 |
|
|
|
204 |
|
|
#endif // CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
|
205 |
|
|
|
206 |
|
|
//==========================================================================
|
207 |
|
|
|
208 |
|
|
#ifdef CYGPKG_REDBOOT
|
209 |
|
|
#include <redboot.h>
|
210 |
|
|
#include CYGHWR_MEMORY_LAYOUT_H
|
211 |
|
|
|
212 |
|
|
//--------------------------------------------------------------------------
|
213 |
|
|
// Memory layout
|
214 |
|
|
//
|
215 |
|
|
// We report the main (S)RAM and peripheral (AHB) SRAM banks.
|
216 |
|
|
|
217 |
|
|
|
218 |
|
|
void
|
219 |
|
|
cyg_plf_memory_segment(int seg, unsigned char **start, unsigned char **end)
|
220 |
|
|
{
|
221 |
|
|
switch (seg) {
|
222 |
|
|
case 0:
|
223 |
|
|
*start = (unsigned char *)CYGMEM_REGION_ram;
|
224 |
|
|
*end = (unsigned char *)(CYGMEM_REGION_ram + CYGMEM_REGION_ram_SIZE);
|
225 |
|
|
break;
|
226 |
|
|
#ifdef CYGMEM_REGION_ahb_sram_bank0
|
227 |
|
|
case 1:
|
228 |
|
|
*start = (unsigned char *)CYGMEM_REGION_ahb_sram_bank0;
|
229 |
|
|
*end =
|
230 |
|
|
(unsigned char *)(CYGMEM_REGION_ahb_sram_bank0 +
|
231 |
|
|
CYGMEM_REGION_ahb_sram_bank0_SIZE);
|
232 |
|
|
break;
|
233 |
|
|
#endif
|
234 |
|
|
#ifdef CYGMEM_REGION_ahb_sram_bank1
|
235 |
|
|
# ifndef CYGMEM_REGION_ahb_sram_bank0
|
236 |
|
|
case 1:
|
237 |
|
|
# else
|
238 |
|
|
case 2:
|
239 |
|
|
# endif
|
240 |
|
|
*start = (unsigned char *)CYGMEM_REGION_ahb_sram_bank1;
|
241 |
|
|
*end =
|
242 |
|
|
(unsigned char *)(CYGMEM_REGION_ahb_sram_bank1 +
|
243 |
|
|
CYGMEM_REGION_ahb_sram_bank1_SIZE);
|
244 |
|
|
break;
|
245 |
|
|
#endif
|
246 |
|
|
default:
|
247 |
|
|
*start = *end = NO_MEMORY;
|
248 |
|
|
break;
|
249 |
|
|
}
|
250 |
|
|
}
|
251 |
|
|
|
252 |
|
|
#endif // CYGPKG_REDBOOT
|
253 |
|
|
|
254 |
|
|
|
255 |
|
|
//==========================================================================
|
256 |
|
|
// EOF lpc1766stk_misc.c
|