1 |
786 |
skrzyp |
//==========================================================================
|
2 |
|
|
//
|
3 |
|
|
// am29xxxxx.c
|
4 |
|
|
//
|
5 |
|
|
// Flash driver for the AMD family
|
6 |
|
|
//
|
7 |
|
|
//==========================================================================
|
8 |
|
|
// ####ECOSGPLCOPYRIGHTBEGIN####
|
9 |
|
|
// -------------------------------------------
|
10 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
11 |
|
|
// Copyright (C) 2004, 2005, 2006, 2007 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): bartv
|
43 |
|
|
// Contributors:
|
44 |
|
|
// Date: 2004-11-05
|
45 |
|
|
//
|
46 |
|
|
//####DESCRIPTIONEND####
|
47 |
|
|
//
|
48 |
|
|
//==========================================================================
|
49 |
|
|
|
50 |
|
|
#include <pkgconf/devs_flash_amd_am29xxxxx_v2.h>
|
51 |
|
|
#include <cyg/infra/cyg_type.h>
|
52 |
|
|
#include <cyg/infra/cyg_ass.h>
|
53 |
|
|
#include <cyg/infra/diag.h>
|
54 |
|
|
#include <cyg/io/flash.h>
|
55 |
|
|
#include <cyg/io/flash_dev.h>
|
56 |
|
|
#include <cyg/io/am29xxxxx_dev.h>
|
57 |
|
|
#include <cyg/hal/hal_arch.h>
|
58 |
|
|
#include <cyg/hal/hal_intr.h>
|
59 |
|
|
#include <cyg/hal/hal_cache.h>
|
60 |
|
|
#include <cyg/hal/hal_io.h>
|
61 |
|
|
|
62 |
|
|
// This driver supports multiple banks of AMD am29xxxxx flash devices
|
63 |
|
|
// or compatibles. These are NOR-flash devices, requiring explicit
|
64 |
|
|
// erase operations with an erase value of 0xff.
|
65 |
|
|
//
|
66 |
|
|
// The devices may be 8-bit, 16-bit, or 32-bit (64-bit devices are not
|
67 |
|
|
// yet supported). Most but not all 16-bit devices can also be
|
68 |
|
|
// accessed as 8-bit, in which case the chip may be hooked up to an
|
69 |
|
|
// 8-bit bus. A bank of flash may involve just a single chip, or there
|
70 |
|
|
// may be several chips in parallel. Typical combinations are 88 to
|
71 |
|
|
// get 16-bit, 8888 for 32-bit, and 1616 for 32-bit. It is assumed
|
72 |
|
|
// that all chips within a bank are the same device. There may also be
|
73 |
|
|
// several banks of flash, and different banks may use different
|
74 |
|
|
// devices.
|
75 |
|
|
//
|
76 |
|
|
// This driver instantiates support for the various bus
|
77 |
|
|
// configurations: 8, 16, 16AS8, 32, 88, 8888, and 1616. On any given
|
78 |
|
|
// platform only one or two of these combinations will be of interest,
|
79 |
|
|
// but the remainder will be eliminated via linker garbage collection.
|
80 |
|
|
// To avoid excessive duplication an auxiliary file contains the
|
81 |
|
|
// actual implementations. Compiler optimization should eliminate any
|
82 |
|
|
// unnecessary code.
|
83 |
|
|
|
84 |
|
|
// A flash driver is supposed to provide the following functions:
|
85 |
|
|
// int (*init)(...)
|
86 |
|
|
// size_t (*query)(...)
|
87 |
|
|
// int (*erase)(...)
|
88 |
|
|
// int (*program)(...)
|
89 |
|
|
// int (*block_lock)(...)
|
90 |
|
|
// int (*block_unlock)(...)
|
91 |
|
|
//
|
92 |
|
|
// The devices do not need any special initialization. However a given
|
93 |
|
|
// board may be manufactured with any one of several devices, which
|
94 |
|
|
// complicates things. The main complication is that there may be
|
95 |
|
|
// different bootsector layouts. The primary job of the init function
|
96 |
|
|
// is to check the device id, possibly fill in the bootsector info,
|
97 |
|
|
// or even to use the CFI support to get the bootsector info from the
|
98 |
|
|
// device itself. There may be other complications, e.g. minor variations
|
99 |
|
|
// of a given board design. These can be handled by h/w specific init
|
100 |
|
|
// functions in the platform HAL.
|
101 |
|
|
//
|
102 |
|
|
// The query function need not do anything useful, it is
|
103 |
|
|
// driver-defined.
|
104 |
|
|
//
|
105 |
|
|
// No read function need be supplied because the flash memory is
|
106 |
|
|
// always directly accessible to the cpu.
|
107 |
|
|
//
|
108 |
|
|
// Erase, program, and the locking functions need real
|
109 |
|
|
// implementations, although locking is not always available.
|
110 |
|
|
|
111 |
|
|
// ----------------------------------------------------------------------------
|
112 |
|
|
// The protocol understood by AMD flash chips and compatibles.
|
113 |
|
|
// The AM29_PARALLEL() macro is used in bus configurations with multiple
|
114 |
|
|
// devices in parallel, to issue commands to all the devices in a single
|
115 |
|
|
// write. In theory some of the operations, e.g. READ_DEVID, only need
|
116 |
|
|
// to access a single chip but then you get into complications for the
|
117 |
|
|
// SETUP commands. The AM29_SWAP() macro deals with endianness issues
|
118 |
|
|
// on some targets and can also help with h/w where things are just not
|
119 |
|
|
// wired right.
|
120 |
|
|
#define AM29_COMMAND_SETUP1 AM29_SWAP(AM29_PARALLEL(0x00AA))
|
121 |
|
|
#define AM29_COMMAND_SETUP2 AM29_SWAP(AM29_PARALLEL(0x0055))
|
122 |
|
|
#define AM29_COMMAND_RESET AM29_SWAP(AM29_PARALLEL(0x00F0))
|
123 |
|
|
#define AM29_COMMAND_AUTOSELECT AM29_SWAP(AM29_PARALLEL(0x0090))
|
124 |
|
|
#define AM29_COMMAND_ERASE AM29_SWAP(AM29_PARALLEL(0x0080))
|
125 |
|
|
#define AM29_COMMAND_ERASE_SECTOR AM29_SWAP(AM29_PARALLEL(0x0030))
|
126 |
|
|
#define AM29_COMMAND_ERASE_RESUME AM29_SWAP(AM29_PARALLEL(0x0030))
|
127 |
|
|
#define AM29_COMMAND_CFI AM29_SWAP(AM29_PARALLEL(0x0098))
|
128 |
|
|
#define AM29_COMMAND_PROGRAM AM29_SWAP(AM29_PARALLEL(0x00A0))
|
129 |
|
|
// Following are specific to AT49 derivatives
|
130 |
|
|
#define AM29_COMMAND_AT49_SOFTLOCK_BLOCK_0 AM29_SWAP(AM29_PARALLEL(0x0080))
|
131 |
|
|
#define AM29_COMMAND_AT49_SOFTLOCK_BLOCK_1 AM29_SWAP(AM29_PARALLEL(0x0040))
|
132 |
|
|
#define AM29_COMMAND_AT49_HARDLOCK_BLOCK_0 AM29_SWAP(AM29_PARALLEL(0x0080))
|
133 |
|
|
#define AM29_COMMAND_AT49_HARDLOCK_BLOCK_1 AM29_SWAP(AM29_PARALLEL(0x0060))
|
134 |
|
|
#define AM29_COMMAND_AT49_UNLOCK_BLOCK AM29_SWAP(AM29_PARALLEL(0x0070))
|
135 |
|
|
|
136 |
|
|
// CFI offsets of interest. This assumes that the standard query table
|
137 |
|
|
// has not been replaced by the extended query table, although the
|
138 |
|
|
// CFI standard allows that behaviour.
|
139 |
|
|
#define AM29_OFFSET_CFI_Q AM29_OFFSET_CFI_DATA(0x0010)
|
140 |
|
|
#define AM29_OFFSET_CFI_SIZE AM29_OFFSET_CFI_DATA(0x0027)
|
141 |
|
|
#define AM29_OFFSET_CFI_BLOCK_REGIONS AM29_OFFSET_CFI_DATA(0x002C)
|
142 |
|
|
#define AM29_OFFSET_CFI_BLOCK_COUNT_LSB(_i_) AM29_OFFSET_CFI_DATA(0x002D + (4 * (_i_)))
|
143 |
|
|
#define AM29_OFFSET_CFI_BLOCK_COUNT_MSB(_i_) AM29_OFFSET_CFI_DATA(0x002E + (4 * (_i_)))
|
144 |
|
|
#define AM29_OFFSET_CFI_BLOCK_SIZE_LSB(_i_) AM29_OFFSET_CFI_DATA(0x002F + (4 * (_i_)))
|
145 |
|
|
#define AM29_OFFSET_CFI_BLOCK_SIZE_MSB(_i_) AM29_OFFSET_CFI_DATA(0x0030 + (4 * (_i_)))
|
146 |
|
|
|
147 |
|
|
#define AM29_STATUS_DQ7 AM29_SWAP(AM29_PARALLEL(0x0080))
|
148 |
|
|
#define AM29_STATUS_DQ6 AM29_SWAP(AM29_PARALLEL(0x0040))
|
149 |
|
|
#define AM29_STATUS_DQ5 AM29_SWAP(AM29_PARALLEL(0x0020))
|
150 |
|
|
#define AM29_STATUS_DQ4 AM29_SWAP(AM29_PARALLEL(0x0010))
|
151 |
|
|
#define AM29_STATUS_DQ3 AM29_SWAP(AM29_PARALLEL(0x0008))
|
152 |
|
|
#define AM29_STATUS_DQ2 AM29_SWAP(AM29_PARALLEL(0x0004))
|
153 |
|
|
#define AM29_STATUS_DQ1 AM29_SWAP(AM29_PARALLEL(0x0002))
|
154 |
|
|
#define AM29_STATUS_DQ0 AM29_SWAP(AM29_PARALLEL(0x0001))
|
155 |
|
|
#define AM29_ID_LOCKED AM29_SWAP(AM29_PARALLEL(0x03))
|
156 |
|
|
|
157 |
|
|
// When programming the flash the source data may not be aligned
|
158 |
|
|
// correctly (although usually it will be). Hence it is necessary to
|
159 |
|
|
// construct the 16-bit or 32-bit numbers to be written to the flash
|
160 |
|
|
// from individual bytes, allowing for endianness.
|
161 |
|
|
#define AM29_NEXT_DATUM_8(_ptr_) (*_ptr_++)
|
162 |
|
|
#if CYG_BYTEORDER == CYG_LSBFIRST
|
163 |
|
|
# define AM29_NEXT_DATUM_16(_ptr_) \
|
164 |
|
|
({ \
|
165 |
|
|
cyg_uint16 _result_; \
|
166 |
|
|
_result_ = (_ptr_[1] << 8) | _ptr_[0]; \
|
167 |
|
|
_ptr_ += 2; \
|
168 |
|
|
_result_; })
|
169 |
|
|
|
170 |
|
|
# define AM29_NEXT_DATUM_32(_ptr_) \
|
171 |
|
|
({ \
|
172 |
|
|
cyg_uint32 _result_; \
|
173 |
|
|
_result_ = (_ptr_[3] << 24) | (_ptr_[2] << 16) | (_ptr_[1] << 8) | _ptr_[0]; \
|
174 |
|
|
_ptr_ += 4; \
|
175 |
|
|
_result_; })
|
176 |
|
|
#else
|
177 |
|
|
# define AM29_NEXT_DATUM_16(_ptr_) \
|
178 |
|
|
({ \
|
179 |
|
|
cyg_uint16 _result_; \
|
180 |
|
|
_result_ = (_ptr_[0] << 8) | _ptr_[1]; \
|
181 |
|
|
_ptr_ += 2; \
|
182 |
|
|
_result_; })
|
183 |
|
|
|
184 |
|
|
# define AM29_NEXT_DATUM_32(_ptr_) \
|
185 |
|
|
({ \
|
186 |
|
|
cyg_uint32 _result_; \
|
187 |
|
|
_result_ = (_ptr_[0] << 24) | (_ptr_[1] << 16) | (_ptr_[2] << 8) | _ptr_[3]; \
|
188 |
|
|
_ptr_ += 4; \
|
189 |
|
|
_result_; })
|
190 |
|
|
|
191 |
|
|
#endif
|
192 |
|
|
|
193 |
|
|
// The addresses used for programming the flash may be different from
|
194 |
|
|
// the ones used to read the flash. The macro
|
195 |
|
|
// HAL_AM29XXXXX_UNCACHED_ADDRESS() can be supplied by one of the HAL
|
196 |
|
|
// packages. Otherwise if CYGHWR_DEVS_FLASH_AMD_AM29XXXXX_V2_CACHED_ONLY
|
197 |
|
|
// is not implemented then the macro CYGARC_UNCACHED_ADDRESS()
|
198 |
|
|
// will be used. If there is no way of bypassing the cache then
|
199 |
|
|
// the addresses will remain unchanged and instead the INTSCACHE
|
200 |
|
|
// macros will disable the cache.
|
201 |
|
|
|
202 |
|
|
#if defined(HAL_AM29XXXXX_UNCACHED_ADDRESS)
|
203 |
|
|
# define AM29_UNCACHED_ADDRESS(_addr_) ((volatile AM29_TYPE*)HAL_AM29XXXXX_UNCACHED_ADDRESS(_addr_))
|
204 |
|
|
#elif !defined(CYGHWR_DEVS_FLASH_AMD_AM29XXXXX_V2_CACHED_ONLY)
|
205 |
|
|
# ifndef CYGARC_UNCACHED_ADDRESS
|
206 |
|
|
# error Cache should be bypassed but CYGARC_UNCACHED_ADDRESS is not defined.
|
207 |
|
|
# endif
|
208 |
|
|
# define AM29_UNCACHED_ADDRESS(_addr_) ((volatile AM29_TYPE*)CYGARC_UNCACHED_ADDRESS(_addr_))
|
209 |
|
|
#elif defined(HAL_AM29XXXXX_P2V)
|
210 |
|
|
// HAL_AM29XXXXX_P2V is a deprecated macro that is only retained for
|
211 |
|
|
// backward compatibility.
|
212 |
|
|
# define AM29_UNCACHED_ADDRESS(_addr_) ((volatile AM29_TYPE*)HAL_AM29XXXXX_P2V(_addr_))
|
213 |
|
|
#else
|
214 |
|
|
# define AM29_UNCACHED_ADDRESS(_addr_) ((volatile AM29_TYPE*)(_addr_))
|
215 |
|
|
#endif
|
216 |
|
|
|
217 |
|
|
// The bits on the data bus may need swapping, either because of
|
218 |
|
|
// endianness issues or because some lines are just wired wrong.
|
219 |
|
|
// SWAP is for commands going to the flash chip. UNSWAP is for
|
220 |
|
|
// data coming back from the flash chip. The swapping takes
|
221 |
|
|
// effect after allowing for AM29_PARALLEL(). Data is never
|
222 |
|
|
// swapped, it does not matter if bit 5 of a datum is actually
|
223 |
|
|
// stored in bit 3 of the flash as long as the data reads back
|
224 |
|
|
// right.
|
225 |
|
|
#if defined(HAL_AM29XXXXX_SWAP)
|
226 |
|
|
# define AM29_SWAP(_data_) HAL_AM29XXXXX_SWAP(_data_)
|
227 |
|
|
#else
|
228 |
|
|
# define AM29_SWAP(_data_) (_data_)
|
229 |
|
|
#endif
|
230 |
|
|
#if defined(HAL_AM29XXXXX_UNSWAP)
|
231 |
|
|
# define AM29_UNSWAP(_data_) HAL_AM29XXXXX_UNSWAP(_data_)
|
232 |
|
|
#else
|
233 |
|
|
# define AM29_UNSWAP(_data_) (_data_)
|
234 |
|
|
#endif
|
235 |
|
|
|
236 |
|
|
// On some platforms there may be almost inexplicable failures, caused
|
237 |
|
|
// by very subtle effects such as instruction cache lines still being
|
238 |
|
|
// filled from flash memory which the _hw routines in .2ram sections are
|
239 |
|
|
// already running and have taken the flash out of read-array mode.
|
240 |
|
|
// These are very rare effects and not amenable to a generic solution,
|
241 |
|
|
// so instead the platform HAL (usually) can define additional hook
|
242 |
|
|
// macros that get invoked by the .2ram functions. These can e.g.
|
243 |
|
|
// add a short delay or invalidate a couple of instruction cache lines,
|
244 |
|
|
// but only if the code is executing from flash. Any such hooks will
|
245 |
|
|
// affect interrupt latency so should only be used when absolutely
|
246 |
|
|
// necessary. They must also be simple code, e.g. no calls to other
|
247 |
|
|
// functions that may be in flash.
|
248 |
|
|
|
249 |
|
|
#ifdef HAL_AM29XXXXX_2RAM_ENTRY_HOOK
|
250 |
|
|
# define AM29_2RAM_ENTRY_HOOK() HAL_AM29XXXXX_2RAM_ENTRY_HOOK()
|
251 |
|
|
#else
|
252 |
|
|
# define AM29_2RAM_ENTRY_HOOK() CYG_EMPTY_STATEMENT
|
253 |
|
|
#endif
|
254 |
|
|
#ifdef HAL_AM29XXXXX_2RAM_EXIT_HOOK
|
255 |
|
|
# define AM29_2RAM_EXIT_HOOK() HAL_AM29XXXXX_2RAM_EXIT_HOOK()
|
256 |
|
|
#else
|
257 |
|
|
# define AM29_2RAM_EXIT_HOOK() CYG_EMPTY_STATEMENT
|
258 |
|
|
#endif
|
259 |
|
|
|
260 |
|
|
// Cache and interrupt manipulation. This driver supports fine-grained
|
261 |
|
|
// control over interrupts and the cache, using three macros. These may
|
262 |
|
|
// be provided by the platform HAL, or by defaults here. There are
|
263 |
|
|
// three variants:
|
264 |
|
|
//
|
265 |
|
|
// 1) control both interrupts and cache. This is necessary if
|
266 |
|
|
// CYGHWR_DEVS_FLASH_AMD_AM29XXXXX_V2_CACHED_ONLY is implemented,
|
267 |
|
|
// i.e. if the cache cannot be bypassed. The cache must be temporarily
|
268 |
|
|
// disabled for flash operations, and interrupts have to be disabled
|
269 |
|
|
// while the cache is disabled to prevent interrupts and context switches.
|
270 |
|
|
// 2) control interrupts only, the default if the cache can be bypassed
|
271 |
|
|
// when accessing the flash. The flash is still in an unusable
|
272 |
|
|
// state during flash operations so interrupts and context switches
|
273 |
|
|
// should be avoided.
|
274 |
|
|
// 3) only invalidate at the end, if the cache can be bypassed and the
|
275 |
|
|
// application guarantees that the flash will not be accessed by any interrupt
|
276 |
|
|
// handlers or other threads.
|
277 |
|
|
|
278 |
|
|
#if defined(CYGHWR_DEVS_FLASH_AMD_AM29XXXXX_V2_CACHED_ONLY)
|
279 |
|
|
|
280 |
|
|
// First, the amount of state that should be preserved. By default
|
281 |
|
|
// this means the interrupt state and the data cache state.
|
282 |
|
|
# define AM29_INTSCACHE_DEFAULT_STATE int _saved_ints_, _saved_dcache_
|
283 |
|
|
|
284 |
|
|
// Start an operation on the flash. Make sure that interrupts are
|
285 |
|
|
// disabled and then save the current state of the data cache. The
|
286 |
|
|
// actual flash manipulation should happen with the cache disabled.
|
287 |
|
|
// There may still be data in the cache that has not yet been flushed
|
288 |
|
|
// to memory, so take care of that first. The invalidate the cache
|
289 |
|
|
// lines so that when the cache is re-enabled later on the processor
|
290 |
|
|
// gets everything from memory, rather than reusing old data in the
|
291 |
|
|
// cache.
|
292 |
|
|
# define AM29_INTSCACHE_DEFAULT_BEGIN() \
|
293 |
|
|
CYG_MACRO_START \
|
294 |
|
|
HAL_DISABLE_INTERRUPTS(_saved_ints_); \
|
295 |
|
|
HAL_DCACHE_IS_ENABLED(_saved_dcache_); \
|
296 |
|
|
HAL_DCACHE_SYNC(); \
|
297 |
|
|
if (_saved_dcache_) { \
|
298 |
|
|
HAL_DCACHE_DISABLE(); \
|
299 |
|
|
} \
|
300 |
|
|
HAL_DCACHE_INVALIDATE_ALL(); \
|
301 |
|
|
CYG_MACRO_END
|
302 |
|
|
|
303 |
|
|
// A flash operation has completed. Restore the situation to what it
|
304 |
|
|
// was before. Because of suspend/resume support interrupt handlers
|
305 |
|
|
// and other threads may have run, filling various cache lines with
|
306 |
|
|
// useful data. However it is assumed that none of those cache
|
307 |
|
|
// lines contain any of the data that has been manipulated by this
|
308 |
|
|
// flash operation (the stack and the flash block), so there is
|
309 |
|
|
// no need for another sync or invalidate. It is also assumed that
|
310 |
|
|
// we have not been executing any code out of the block of flash
|
311 |
|
|
// that has just been erased or programmed, so no need to worry
|
312 |
|
|
// about the icache.
|
313 |
|
|
#define AM29_INTSCACHE_DEFAULT_END() \
|
314 |
|
|
CYG_MACRO_START \
|
315 |
|
|
if (_saved_dcache_) { \
|
316 |
|
|
HAL_DCACHE_ENABLE(); \
|
317 |
|
|
} \
|
318 |
|
|
HAL_RESTORE_INTERRUPTS(_saved_ints_); \
|
319 |
|
|
CYG_MACRO_END
|
320 |
|
|
|
321 |
|
|
#elif !defined(CYGIMP_DEVS_FLASH_AMD_AM29XXXXX_V2_LEAVE_INTERRUPTS_ENABLED)
|
322 |
|
|
|
323 |
|
|
# define AM29_INTSCACHE_DEFAULT_STATE int _saved_ints_
|
324 |
|
|
# define AM29_INTSCACHE_DEFAULT_BEGIN() HAL_DISABLE_INTERRUPTS(_saved_ints_)
|
325 |
|
|
|
326 |
|
|
# if defined(HAL_DCACHE_SYNC) && defined(HAL_DCACHE_INVALIDATE_ALL)
|
327 |
|
|
// The following blips the interrupt enable to allow pending interrupts
|
328 |
|
|
// to run, which will reduce interrupt latency given the dcache sync/invalidate
|
329 |
|
|
// may be relatively lengthy.
|
330 |
|
|
# define AM29_INTSCACHE_DEFAULT_END() \
|
331 |
|
|
CYG_MACRO_START \
|
332 |
|
|
HAL_RESTORE_INTERRUPTS(_saved_ints_); \
|
333 |
|
|
HAL_DISABLE_INTERRUPTS(_saved_ints_); \
|
334 |
|
|
HAL_DCACHE_SYNC(); \
|
335 |
|
|
HAL_DCACHE_INVALIDATE_ALL(); \
|
336 |
|
|
HAL_RESTORE_INTERRUPTS(_saved_ints_); \
|
337 |
|
|
CYG_MACRO_END
|
338 |
|
|
# else
|
339 |
|
|
# define AM29_INTSCACHE_DEFAULT_END() HAL_RESTORE_INTERRUPTS(_saved_ints_)
|
340 |
|
|
# endif
|
341 |
|
|
#else
|
342 |
|
|
|
343 |
|
|
# define AM29_INTSCACHE_DEFAULT_STATE CYG_EMPTY_STATEMENT
|
344 |
|
|
# define AM29_INTSCACHE_DEFAULT_BEGIN() CYG_EMPTY_STATEMENT
|
345 |
|
|
# if defined(HAL_DCACHE_SYNC) && defined(HAL_DCACHE_INVALIDATE_ALL)
|
346 |
|
|
# define AM29_INTSCACHE_DEFAULT_END() \
|
347 |
|
|
CYG_MACRO_START \
|
348 |
|
|
int _saved_ints_; \
|
349 |
|
|
HAL_DISABLE_INTERRUPTS(_saved_ints_); \
|
350 |
|
|
HAL_DCACHE_SYNC(); \
|
351 |
|
|
HAL_DCACHE_INVALIDATE_ALL(); \
|
352 |
|
|
HAL_RESTORE_INTERRUPTS(_saved_ints_); \
|
353 |
|
|
CYG_MACRO_END
|
354 |
|
|
# else
|
355 |
|
|
# define AM29_INTSCACHE_DEFAULT_END() CYG_EMPTY_STATEMENT
|
356 |
|
|
# endif
|
357 |
|
|
#endif
|
358 |
|
|
|
359 |
|
|
#ifdef HAL_AM29XXXXX_INTSCACHE_STATE
|
360 |
|
|
# define AM29_INTSCACHE_STATE HAL_AM29XXXXX_INTSCACHE_STATE
|
361 |
|
|
#else
|
362 |
|
|
# define AM29_INTSCACHE_STATE AM29_INTSCACHE_DEFAULT_STATE
|
363 |
|
|
#endif
|
364 |
|
|
#ifdef HAL_AM29XXXXX_INTSCACHE_BEGIN
|
365 |
|
|
# define AM29_INTSCACHE_BEGIN HAL_AM29XXXXX_INTSCACHE_BEGIN
|
366 |
|
|
#else
|
367 |
|
|
# define AM29_INTSCACHE_BEGIN AM29_INTSCACHE_DEFAULT_BEGIN
|
368 |
|
|
#endif
|
369 |
|
|
#ifdef HAL_AM29XXXXX_INTSCACHE_END
|
370 |
|
|
# define AM29_INTSCACHE_END HAL_AM29XXXXX_INTSCACHE_END
|
371 |
|
|
#else
|
372 |
|
|
# define AM29_INTSCACHE_END AM29_INTSCACHE_DEFAULT_END
|
373 |
|
|
#endif
|
374 |
|
|
|
375 |
|
|
// Some HALs require a special instruction to flush write buffers.
|
376 |
|
|
// Not all HALs do though, so we define it empty if it isn't already present.
|
377 |
|
|
#ifndef HAL_MEMORY_BARRIER
|
378 |
|
|
# define HAL_MEMORY_BARRIER() CYG_EMPTY_STATEMENT
|
379 |
|
|
#endif
|
380 |
|
|
|
381 |
|
|
// ----------------------------------------------------------------------------
|
382 |
|
|
// Generic code.
|
383 |
|
|
|
384 |
|
|
// Get info about the current block, i.e. base and size.
|
385 |
|
|
static void
|
386 |
|
|
am29_get_block_info(struct cyg_flash_dev* dev, const cyg_flashaddr_t addr, cyg_flashaddr_t* block_start, size_t* block_size)
|
387 |
|
|
{
|
388 |
|
|
cyg_uint32 i;
|
389 |
|
|
size_t offset = addr - dev->start;
|
390 |
|
|
cyg_flashaddr_t result;
|
391 |
|
|
|
392 |
|
|
result = dev->start;
|
393 |
|
|
|
394 |
|
|
for (i = 0; i < dev->num_block_infos; i++) {
|
395 |
|
|
if (offset < (dev->block_info[i].blocks * dev->block_info[i].block_size)) {
|
396 |
|
|
offset -= (offset % dev->block_info[i].block_size);
|
397 |
|
|
*block_start = result + offset;
|
398 |
|
|
*block_size = dev->block_info[i].block_size;
|
399 |
|
|
return;
|
400 |
|
|
}
|
401 |
|
|
result += (dev->block_info[i].blocks * dev->block_info[i].block_size);
|
402 |
|
|
offset -= (dev->block_info[i].blocks * dev->block_info[i].block_size);
|
403 |
|
|
}
|
404 |
|
|
CYG_FAIL("Address out of range of selected flash device");
|
405 |
|
|
}
|
406 |
|
|
|
407 |
|
|
// ----------------------------------------------------------------------------
|
408 |
|
|
// Instantiate all of the h/w functions appropriate for the various
|
409 |
|
|
// configurations.
|
410 |
|
|
// The suffix is used to construct the function names.
|
411 |
|
|
// Types for the width of the bus, controlling the granularity of access.
|
412 |
|
|
// devcount specifies the number of devices in parallel, and is used for looping
|
413 |
|
|
// The NEXT_DATUM() macro allows for misaligned source data.
|
414 |
|
|
// The PARALLEL macro, if defined, is used for sending commands and reading
|
415 |
|
|
// status bits from all devices in the bank in one operation.
|
416 |
|
|
|
417 |
|
|
// A single 8-bit device on an 8-bit bus.
|
418 |
|
|
#define AM29_SUFFIX 8
|
419 |
|
|
#define AM29_TYPE cyg_uint8
|
420 |
|
|
#define AM29_DEVCOUNT 1
|
421 |
|
|
#define AM29_NEXT_DATUM(_ptr_) AM29_NEXT_DATUM_8(_ptr_)
|
422 |
|
|
|
423 |
|
|
#include "am29xxxxx_aux.c"
|
424 |
|
|
|
425 |
|
|
#undef AM29_SUFFIX
|
426 |
|
|
#undef AM29_TYPE
|
427 |
|
|
#undef AM29_DEVCOUNT
|
428 |
|
|
#undef AM29_NEXT_DATUM
|
429 |
|
|
|
430 |
|
|
// A single 16-bit device.
|
431 |
|
|
#define AM29_SUFFIX 16
|
432 |
|
|
#define AM29_TYPE cyg_uint16
|
433 |
|
|
#define AM29_DEVCOUNT 1
|
434 |
|
|
#define AM29_NEXT_DATUM(_ptr_) AM29_NEXT_DATUM_16(_ptr_)
|
435 |
|
|
|
436 |
|
|
#include "am29xxxxx_aux.c"
|
437 |
|
|
|
438 |
|
|
#undef AM29_SUFFIX
|
439 |
|
|
#undef AM29_TYPE
|
440 |
|
|
#undef AM29_DEVCOUNT
|
441 |
|
|
#undef AM29_NEXT_DATUM
|
442 |
|
|
|
443 |
|
|
// A single 32-bit device.
|
444 |
|
|
#define AM29_SUFFIX 32
|
445 |
|
|
#define AM29_TYPE cyg_uint32
|
446 |
|
|
#define AM29_DEVCOUNT 1
|
447 |
|
|
#define AM29_NEXT_DATUM(_ptr_) AM29_NEXT_DATUM_32(_ptr_)
|
448 |
|
|
|
449 |
|
|
#include "am29xxxxx_aux.c"
|
450 |
|
|
|
451 |
|
|
#undef AM29_SUFFIX
|
452 |
|
|
#undef AM29_TYPE
|
453 |
|
|
#undef AM29_DEVCOUNT
|
454 |
|
|
#undef AM29_NEXT_DATUM
|
455 |
|
|
|
456 |
|
|
// Two 8-bit devices, giving a 16-bit bus.
|
457 |
|
|
#define AM29_SUFFIX 88
|
458 |
|
|
#define AM29_TYPE cyg_uint16
|
459 |
|
|
#define AM29_DEVCOUNT 2
|
460 |
|
|
#define AM29_NEXT_DATUM(_ptr_) AM29_NEXT_DATUM_16(_ptr_)
|
461 |
|
|
#define AM29_PARALLEL(_cmd_) ((_cmd_ << 8) | _cmd_)
|
462 |
|
|
|
463 |
|
|
#include "am29xxxxx_aux.c"
|
464 |
|
|
|
465 |
|
|
#undef AM29_SUFFIX
|
466 |
|
|
#undef AM29_TYPE
|
467 |
|
|
#undef AM29_DEVCOUNT
|
468 |
|
|
#undef AM29_NEXT_DATUM
|
469 |
|
|
|
470 |
|
|
// Four 8-bit devices, giving a 32-bit bus.
|
471 |
|
|
#define AM29_SUFFIX 8888
|
472 |
|
|
#define AM29_TYPE cyg_uint32
|
473 |
|
|
#define AM29_DEVCOUNT 4
|
474 |
|
|
#define AM29_NEXT_DATUM(_ptr_) AM29_NEXT_DATUM_32(_ptr_)
|
475 |
|
|
#define AM29_PARALLEL(_cmd_) ((_cmd_ << 24) | (_cmd_ << 16) | (_cmd_ << 8) | _cmd_)
|
476 |
|
|
|
477 |
|
|
#include "am29xxxxx_aux.c"
|
478 |
|
|
|
479 |
|
|
#undef AM29_SUFFIX
|
480 |
|
|
#undef AM29_TYPE
|
481 |
|
|
#undef AM29_DEVCOUNT
|
482 |
|
|
#undef AM29_NEXT_DATUM
|
483 |
|
|
|
484 |
|
|
// Two 16-bit devices, giving a 32-bit bus.
|
485 |
|
|
#define AM29_SUFFIX 1616
|
486 |
|
|
#define AM29_TYPE cyg_uint32
|
487 |
|
|
#define AM29_DEVCOUNT 2
|
488 |
|
|
#define AM29_NEXT_DATUM(_ptr_) AM29_NEXT_DATUM_32(_ptr_)
|
489 |
|
|
#define AM29_PARALLEL(_cmd_) ((_cmd_ << 16) | _cmd_)
|
490 |
|
|
|
491 |
|
|
#include "am29xxxxx_aux.c"
|
492 |
|
|
|
493 |
|
|
#undef AM29_SUFFIX
|
494 |
|
|
#undef AM29_TYPE
|
495 |
|
|
#undef AM29_DEVCOUNT
|
496 |
|
|
#undef AM29_NEXT_DATUM
|
497 |
|
|
|
498 |
|
|
// 16AS8. A 16-bit device hooked up so that only byte accesses are
|
499 |
|
|
// allowed. This requires unusual offsets
|
500 |
|
|
#define AM29_SUFFIX 16as8
|
501 |
|
|
#define AM29_TYPE cyg_uint8
|
502 |
|
|
#define AM29_DEVCOUNT 1
|
503 |
|
|
#define AM29_NEXT_DATUM(_ptr_) AM29_NEXT_DATUM_8(_ptr_)
|
504 |
|
|
#define AM29_OFFSET_COMMAND 0x0AAA
|
505 |
|
|
#define AM29_OFFSET_COMMAND2 0x0555
|
506 |
|
|
#define AM29_OFFSET_MANUFACTURER_ID 0x0000
|
507 |
|
|
#define AM29_OFFSET_DEVID 0x0002
|
508 |
|
|
#define AM29_OFFSET_DEVID2 0x001C
|
509 |
|
|
#define AM29_OFFSET_DEVID3 0x001E
|
510 |
|
|
#define AM29_OFFSET_AT49_LOCK_STATUS 04
|
511 |
|
|
#define AM29_OFFSET_CFI 0x00AA
|
512 |
|
|
#define AM29_OFFSET_CFI_DATA(_idx_) (2 * (_idx_))
|
513 |
|
|
|
514 |
|
|
#include "am29xxxxx_aux.c"
|