1 |
786 |
skrzyp |
//==========================================================================
|
2 |
|
|
//
|
3 |
|
|
// lm3s8xx_misc.c
|
4 |
|
|
//
|
5 |
|
|
// Stellaris Cortex-M3 800 Series HAL functions
|
6 |
|
|
//
|
7 |
|
|
//==========================================================================
|
8 |
|
|
// ####ECOSGPLCOPYRIGHTBEGIN####
|
9 |
|
|
// -------------------------------------------
|
10 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
11 |
|
|
// Copyright (C) 2010 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): ccoutand
|
43 |
|
|
// Date: 2010-11-21
|
44 |
|
|
// Description:
|
45 |
|
|
//
|
46 |
|
|
//####DESCRIPTIONEND####
|
47 |
|
|
//
|
48 |
|
|
//==========================================================================
|
49 |
|
|
|
50 |
|
|
#include <pkgconf/hal.h>
|
51 |
|
|
|
52 |
|
|
#ifdef CYGPKG_KERNEL
|
53 |
|
|
#include <pkgconf/kernel.h>
|
54 |
|
|
#endif
|
55 |
|
|
|
56 |
|
|
#include <cyg/infra/diag.h>
|
57 |
|
|
#include <cyg/infra/cyg_type.h>
|
58 |
|
|
#include <cyg/infra/cyg_trac.h> // tracing macros
|
59 |
|
|
#include <cyg/infra/cyg_ass.h> // assertion macros
|
60 |
|
|
|
61 |
|
|
#include <cyg/hal/hal_arch.h> // HAL header
|
62 |
|
|
#include <cyg/hal/hal_intr.h> // HAL header
|
63 |
|
|
#include <cyg/hal/hal_if.h> // HAL header
|
64 |
|
|
#include <cyg/hal/var_io.h>
|
65 |
|
|
|
66 |
|
|
#if defined(CYGHWR_HAL_CORTEXM_LM3S8XX_PLL)
|
67 |
|
|
#if CYGHWR_HAL_CORTEXM_LM3S8XX_PLL_INPUT == 3579545
|
68 |
|
|
#define CYGHWR_HAL_CORTEXM_LM3S8XX_XTAL CYGHWR_HAL_LM3S_SC_RCC_XTAL(4)
|
69 |
|
|
#elif CYGHWR_HAL_CORTEXM_LM3S8XX_PLL_INPUT == 3686400
|
70 |
|
|
#define CYGHWR_HAL_CORTEXM_LM3S8XX_XTAL CYGHWR_HAL_LM3S_SC_RCC_XTAL(5)
|
71 |
|
|
#elif CYGHWR_HAL_CORTEXM_LM3S8XX_PLL_INPUT == 4000000
|
72 |
|
|
#define CYGHWR_HAL_CORTEXM_LM3S8XX_XTAL CYGHWR_HAL_LM3S_SC_RCC_XTAL(6)
|
73 |
|
|
#elif CYGHWR_HAL_CORTEXM_LM3S8XX_PLL_INPUT == 4096000
|
74 |
|
|
#define CYGHWR_HAL_CORTEXM_LM3S8XX_XTAL CYGHWR_HAL_LM3S_SC_RCC_XTAL(7)
|
75 |
|
|
#elif CYGHWR_HAL_CORTEXM_LM3S8XX_PLL_INPUT == 4915200
|
76 |
|
|
#define CYGHWR_HAL_CORTEXM_LM3S8XX_XTAL CYGHWR_HAL_LM3S_SC_RCC_XTAL(8)
|
77 |
|
|
#elif CYGHWR_HAL_CORTEXM_LM3S8XX_PLL_INPUT == 5000000
|
78 |
|
|
#define CYGHWR_HAL_CORTEXM_LM3S8XX_XTAL CYGHWR_HAL_LM3S_SC_RCC_XTAL(9)
|
79 |
|
|
#elif CYGHWR_HAL_CORTEXM_LM3S8XX_PLL_INPUT == 5120000
|
80 |
|
|
#define CYGHWR_HAL_CORTEXM_LM3S8XX_XTAL CYGHWR_HAL_LM3S_SC_RCC_XTAL(10)
|
81 |
|
|
#elif CYGHWR_HAL_CORTEXM_LM3S8XX_PLL_INPUT == 6000000
|
82 |
|
|
#define CYGHWR_HAL_CORTEXM_LM3S8XX_XTAL CYGHWR_HAL_LM3S_SC_RCC_XTAL(11)
|
83 |
|
|
#elif CYGHWR_HAL_CORTEXM_LM3S8XX_PLL_INPUT == 6144000
|
84 |
|
|
#define CYGHWR_HAL_CORTEXM_LM3S8XX_XTAL CYGHWR_HAL_LM3S_SC_RCC_XTAL(12)
|
85 |
|
|
#elif CYGHWR_HAL_CORTEXM_LM3S8XX_PLL_INPUT == 7372800
|
86 |
|
|
#define CYGHWR_HAL_CORTEXM_LM3S8XX_XTAL CYGHWR_HAL_LM3S_SC_RCC_XTAL(13)
|
87 |
|
|
#elif CYGHWR_HAL_CORTEXM_LM3S8XX_PLL_INPUT == 8000000
|
88 |
|
|
#define CYGHWR_HAL_CORTEXM_LM3S8XX_XTAL CYGHWR_HAL_LM3S_SC_RCC_XTAL(14)
|
89 |
|
|
#elif CYGHWR_HAL_CORTEXM_LM3S8XX_PLL_INPUT == 8192000
|
90 |
|
|
#define CYGHWR_HAL_CORTEXM_LM3S8XX_XTAL CYGHWR_HAL_LM3S_SC_RCC_XTAL(15)
|
91 |
|
|
#endif
|
92 |
|
|
#endif
|
93 |
|
|
|
94 |
|
|
#if defined(CYGHWR_HAL_CORTEXM_LM3S8XX_CLOCK_INT)
|
95 |
|
|
#if CYGNUM_HAL_CORTEXM_LM3S8XX_CLOCK_INT_FREQ == 12000000
|
96 |
|
|
#define CYGHWR_HAL_CORTEXM_LM3S8XX_OSCSRC_FIELD CYGHWR_HAL_LM3S_SC_RCC_OSCSRC_IOSC
|
97 |
|
|
#else
|
98 |
|
|
#define CYGHWR_HAL_CORTEXM_LM3S8XX_OSCSRC_FIELD CYGHWR_HAL_LM3S_SC_RCC_OSCSRC_IOSC_DIV4
|
99 |
|
|
#endif
|
100 |
|
|
#else
|
101 |
|
|
#define CYGHWR_HAL_CORTEXM_LM3S8XX_OSCSRC_FIELD CYGHWR_HAL_LM3S_SC_RCC_OSCSRC_MOSC
|
102 |
|
|
#endif
|
103 |
|
|
|
104 |
|
|
#if CYGHWR_HAL_CORTEXM_LM3S8XX_SYSCLK_DIV != 1
|
105 |
|
|
#define CYGHWR_HAL_CORTEXM_LM3S8XX_SC_RCC_SYSDIV_VAL \
|
106 |
|
|
CYGHWR_HAL_LM3S_SC_RCC_SYSDIV( (CYGHWR_HAL_CORTEXM_LM3S8XX_SYSCLK_DIV-1) );
|
107 |
|
|
#endif
|
108 |
|
|
|
109 |
|
|
//==========================================================================
|
110 |
|
|
|
111 |
|
|
void hal_lm3s8xx_periph_set( cyg_uint32 periph, cyg_uint32 on_off );
|
112 |
|
|
|
113 |
|
|
__externC cyg_uint32 hal_cortexm_systick_clock;
|
114 |
|
|
__externC cyg_uint32 hal_lm3s_sysclk;
|
115 |
|
|
|
116 |
|
|
//==========================================================================
|
117 |
|
|
// System init
|
118 |
|
|
//
|
119 |
|
|
// This code runs before the DATA is copied from ROM and the BSS cleared,
|
120 |
|
|
// hence it cannot make use of static variables or data tables.
|
121 |
|
|
|
122 |
|
|
__externC void
|
123 |
|
|
hal_system_init( void )
|
124 |
|
|
{
|
125 |
|
|
}
|
126 |
|
|
|
127 |
|
|
|
128 |
|
|
//==========================================================================
|
129 |
|
|
// Setup up system clocks
|
130 |
|
|
//
|
131 |
|
|
void
|
132 |
|
|
hal_start_clocks( void )
|
133 |
|
|
{
|
134 |
|
|
CYG_ADDRESS sc = CYGHWR_HAL_LM3S_SC;
|
135 |
|
|
cyg_uint32 rcc;
|
136 |
|
|
#if defined(CYGHWR_HAL_CORTEXM_LM3S8XX_PLL)
|
137 |
|
|
cyg_uint32 plllmis = CYGHWR_HAL_LM3S_SC_MISC_PLLLMIS;
|
138 |
|
|
cyg_uint32 plllris = CYGHWR_HAL_LM3S_SC_RIS_PLLLRIS;
|
139 |
|
|
volatile cyg_uint16 wait;
|
140 |
|
|
#endif
|
141 |
|
|
|
142 |
|
|
// At power up, the LM3S8xx is setup to use external oscillator.
|
143 |
|
|
// The PLL is powered down and bypass. Same goes for the system
|
144 |
|
|
// clock divider.
|
145 |
|
|
|
146 |
|
|
// For JTAG cold restart, first we make sure the PLL and system
|
147 |
|
|
// clock divider are bypassed, enable all clock source and shutdown
|
148 |
|
|
// the PLL.
|
149 |
|
|
|
150 |
|
|
HAL_READ_UINT32( sc + CYGHWR_HAL_LM3S_SC_RCC, rcc );
|
151 |
|
|
|
152 |
|
|
rcc &= ~( CYGHWR_HAL_LM3S_SC_RCC_USESYSDIV |
|
153 |
|
|
CYGHWR_HAL_LM3S_SC_RCC_MOSCDIS |
|
154 |
|
|
CYGHWR_HAL_LM3S_SC_RCC_IOSCDIS );
|
155 |
|
|
|
156 |
|
|
rcc |= CYGHWR_HAL_LM3S_SC_RCC_BYPASS;
|
157 |
|
|
|
158 |
|
|
HAL_WRITE_UINT32( sc + CYGHWR_HAL_LM3S_SC_RCC, rcc );
|
159 |
|
|
|
160 |
|
|
rcc |= ( CYGHWR_HAL_LM3S_SC_RCC_PWRDN | CYGHWR_HAL_LM3S_SC_RCC_OEN );
|
161 |
|
|
|
162 |
|
|
HAL_WRITE_UINT32( sc + CYGHWR_HAL_LM3S_SC_RCC, rcc );
|
163 |
|
|
|
164 |
|
|
// PLL is setup if in use
|
165 |
|
|
//
|
166 |
|
|
// The XTAL frequency is configured. The PLL is powered and
|
167 |
|
|
// its output is enable
|
168 |
|
|
|
169 |
|
|
// Setup Clock Source
|
170 |
|
|
rcc |= CYGHWR_HAL_CORTEXM_LM3S8XX_OSCSRC_FIELD;
|
171 |
|
|
|
172 |
|
|
#if defined(CYGHWR_HAL_CORTEXM_LM3S8XX_PLL)
|
173 |
|
|
|
174 |
|
|
// Clear PLL lock bit
|
175 |
|
|
HAL_WRITE_UINT32( sc + CYGHWR_HAL_LM3S_SC_MISC, plllmis );
|
176 |
|
|
|
177 |
|
|
rcc &= ~( CYGHWR_HAL_LM3S_SC_RCC_XTAL_MASK |
|
178 |
|
|
( CYGHWR_HAL_LM3S_SC_RCC_PWRDN ) |
|
179 |
|
|
( CYGHWR_HAL_LM3S_SC_RCC_OEN ) );
|
180 |
|
|
|
181 |
|
|
rcc |= CYGHWR_HAL_CORTEXM_LM3S8XX_XTAL;
|
182 |
|
|
|
183 |
|
|
#endif
|
184 |
|
|
|
185 |
|
|
HAL_WRITE_UINT32( sc + CYGHWR_HAL_LM3S_SC_RCC, rcc );
|
186 |
|
|
|
187 |
|
|
//
|
188 |
|
|
// Setup System Clock divider
|
189 |
|
|
//
|
190 |
|
|
|
191 |
|
|
#if CYGHWR_HAL_CORTEXM_LM3S8XX_SYSCLK_DIV != 1
|
192 |
|
|
|
193 |
|
|
// Use system clock divider
|
194 |
|
|
rcc |= CYGHWR_HAL_LM3S_SC_RCC_USESYSDIV;
|
195 |
|
|
|
196 |
|
|
// Clear system clock divider bits
|
197 |
|
|
rcc &= ~CYGHWR_HAL_LM3S_SC_RCC_SYSDIV_MASK;
|
198 |
|
|
|
199 |
|
|
// Configure divider
|
200 |
|
|
rcc |= CYGHWR_HAL_CORTEXM_LM3S8XX_SC_RCC_SYSDIV_VAL;
|
201 |
|
|
|
202 |
|
|
HAL_WRITE_UINT32( sc + CYGHWR_HAL_LM3S_SC_RCC, rcc );
|
203 |
|
|
|
204 |
|
|
#endif
|
205 |
|
|
|
206 |
|
|
// Wait for PLL lock before feeding the clock to the
|
207 |
|
|
// device
|
208 |
|
|
|
209 |
|
|
#if defined(CYGHWR_HAL_CORTEXM_LM3S8XX_PLL)
|
210 |
|
|
|
211 |
|
|
// Wait for PLL lock, potentially a dead lock
|
212 |
|
|
plllris = 0;
|
213 |
|
|
while ( 0 == ( plllris & CYGHWR_HAL_LM3S_SC_RIS_PLLLRIS ) ) {
|
214 |
|
|
// Wait
|
215 |
|
|
for ( wait = 0; wait < ( ( 2 ^ 16 ) - 1 ); wait++ )
|
216 |
|
|
HAL_READ_UINT32( sc + CYGHWR_HAL_LM3S_SC_RIS, plllris );
|
217 |
|
|
}
|
218 |
|
|
|
219 |
|
|
// Clear bypass bit
|
220 |
|
|
rcc &= ~CYGHWR_HAL_LM3S_SC_RCC_BYPASS;
|
221 |
|
|
|
222 |
|
|
HAL_WRITE_UINT32( sc + CYGHWR_HAL_LM3S_SC_RCC, rcc );
|
223 |
|
|
|
224 |
|
|
#endif
|
225 |
|
|
|
226 |
|
|
//
|
227 |
|
|
// Disable clock source not in use
|
228 |
|
|
//
|
229 |
|
|
#if defined(CYGHWR_HAL_CORTEXM_LM3S8XX_CLOCK_EXT)
|
230 |
|
|
|
231 |
|
|
rcc |= CYGHWR_HAL_LM3S_SC_RCC_IOSCDIS;
|
232 |
|
|
|
233 |
|
|
#elif defined(CYGHWR_HAL_CORTEXM_LM3S8XX_CLOCK_INT)
|
234 |
|
|
|
235 |
|
|
rcc |= CYGHWR_HAL_LM3S_SC_RCC_MOSCDIS;
|
236 |
|
|
|
237 |
|
|
#endif
|
238 |
|
|
|
239 |
|
|
HAL_WRITE_UINT32( sc + CYGHWR_HAL_LM3S_SC_RCC, rcc );
|
240 |
|
|
|
241 |
|
|
hal_cortexm_systick_clock = CYGHWR_HAL_CORTEXM_LM3S8XX_SYSCLK;
|
242 |
|
|
hal_lm3s_sysclk = CYGHWR_HAL_CORTEXM_LM3S8XX_SYSCLK;
|
243 |
|
|
}
|
244 |
|
|
|
245 |
|
|
//==========================================================================
|
246 |
|
|
// EOF lm3s8xx_misc.c
|