1 |
786 |
skrzyp |
#ifndef CYGONCE_IO_FLASH_FLASH_DEV_H
|
2 |
|
|
#define CYGONCE_IO_FLASH_FLASH_DEV_H
|
3 |
|
|
//==========================================================================
|
4 |
|
|
//
|
5 |
|
|
// flash_dev.h
|
6 |
|
|
//
|
7 |
|
|
// Common flash device driver definitions
|
8 |
|
|
//
|
9 |
|
|
//==========================================================================
|
10 |
|
|
// ####ECOSGPLCOPYRIGHTBEGIN####
|
11 |
|
|
// -------------------------------------------
|
12 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
13 |
|
|
// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
|
14 |
|
|
//
|
15 |
|
|
// eCos is free software; you can redistribute it and/or modify it under
|
16 |
|
|
// the terms of the GNU General Public License as published by the Free
|
17 |
|
|
// Software Foundation; either version 2 or (at your option) any later
|
18 |
|
|
// version.
|
19 |
|
|
//
|
20 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT
|
21 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
22 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
23 |
|
|
// for more details.
|
24 |
|
|
//
|
25 |
|
|
// You should have received a copy of the GNU General Public License
|
26 |
|
|
// along with eCos; if not, write to the Free Software Foundation, Inc.,
|
27 |
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
28 |
|
|
//
|
29 |
|
|
// As a special exception, if other files instantiate templates or use
|
30 |
|
|
// macros or inline functions from this file, or you compile this file
|
31 |
|
|
// and link it with other works to produce a work based on this file,
|
32 |
|
|
// this file does not by itself cause the resulting work to be covered by
|
33 |
|
|
// the GNU General Public License. However the source code for this file
|
34 |
|
|
// must still be made available in accordance with section (3) of the GNU
|
35 |
|
|
// General Public License v2.
|
36 |
|
|
//
|
37 |
|
|
// This exception does not invalidate any other reasons why a work based
|
38 |
|
|
// on this file might be covered by the GNU General Public License.
|
39 |
|
|
// -------------------------------------------
|
40 |
|
|
// ####ECOSGPLCOPYRIGHTEND####
|
41 |
|
|
//==========================================================================
|
42 |
|
|
//#####DESCRIPTIONBEGIN####
|
43 |
|
|
//
|
44 |
|
|
// Author(s): gthomas
|
45 |
|
|
// Contributors: gthomas, Andrew Lunn, bartv
|
46 |
|
|
// Date: 2000-07-14
|
47 |
|
|
// Purpose:
|
48 |
|
|
// Description:
|
49 |
|
|
//
|
50 |
|
|
//####DESCRIPTIONEND####
|
51 |
|
|
//
|
52 |
|
|
//==========================================================================
|
53 |
|
|
|
54 |
|
|
#include <pkgconf/system.h>
|
55 |
|
|
#include <pkgconf/io_flash.h>
|
56 |
|
|
#include <cyg/infra/cyg_type.h>
|
57 |
|
|
#include <cyg/io/flash.h>
|
58 |
|
|
#include <cyg/hal/hal_cache.h>
|
59 |
|
|
#include <cyg/hal/hal_tables.h>
|
60 |
|
|
|
61 |
|
|
// Forward reference of the device structure
|
62 |
|
|
struct cyg_flash_dev;
|
63 |
|
|
|
64 |
|
|
// Structure of pointers to functions in the device driver
|
65 |
|
|
struct cyg_flash_dev_funs {
|
66 |
|
|
int (*flash_init) (struct cyg_flash_dev *dev);
|
67 |
|
|
size_t (*flash_query) (struct cyg_flash_dev *dev,
|
68 |
|
|
void * data, size_t len);
|
69 |
|
|
int (*flash_erase_block) (struct cyg_flash_dev *dev,
|
70 |
|
|
cyg_flashaddr_t block_base);
|
71 |
|
|
int (*flash_program) (struct cyg_flash_dev *dev,
|
72 |
|
|
cyg_flashaddr_t base,
|
73 |
|
|
const void* data, size_t len);
|
74 |
|
|
int (*flash_read) (struct cyg_flash_dev *dev,
|
75 |
|
|
const cyg_flashaddr_t base,
|
76 |
|
|
void* data, size_t len);
|
77 |
|
|
#ifdef CYGHWR_IO_FLASH_BLOCK_LOCKING
|
78 |
|
|
int (*flash_block_lock) (struct cyg_flash_dev *dev,
|
79 |
|
|
const cyg_flashaddr_t block_base);
|
80 |
|
|
int (*flash_block_unlock) (struct cyg_flash_dev *dev,
|
81 |
|
|
const cyg_flashaddr_t block_base);
|
82 |
|
|
#endif
|
83 |
|
|
};
|
84 |
|
|
|
85 |
|
|
// Dummy functions for some of the above operations, if a device does
|
86 |
|
|
// not support e.g. locking.
|
87 |
|
|
externC int cyg_flash_devfn_init_nop(struct cyg_flash_dev*);
|
88 |
|
|
externC size_t cyg_flash_devfn_query_nop(struct cyg_flash_dev*, void*, const size_t);
|
89 |
|
|
externC int cyg_flash_devfn_lock_nop(struct cyg_flash_dev*, const cyg_flashaddr_t);
|
90 |
|
|
externC int cyg_flash_devfn_unlock_nop(struct cyg_flash_dev*, const cyg_flashaddr_t);
|
91 |
|
|
|
92 |
|
|
// Facilitate function calls between flash-resident code and .2ram
|
93 |
|
|
// functions.
|
94 |
|
|
externC void* cyg_flash_anonymizer(void*);
|
95 |
|
|
|
96 |
|
|
// Structure each device places in the HAL table
|
97 |
|
|
struct cyg_flash_dev {
|
98 |
|
|
const struct cyg_flash_dev_funs *funs; // Function pointers
|
99 |
|
|
cyg_uint32 flags; // Device characteristics
|
100 |
|
|
cyg_flashaddr_t start; // First address
|
101 |
|
|
cyg_flashaddr_t end; // Last address
|
102 |
|
|
cyg_uint32 num_block_infos; // Number of entries
|
103 |
|
|
const cyg_flash_block_info_t *block_info; // Info about one block size
|
104 |
|
|
|
105 |
|
|
const void *priv; // Devices private data
|
106 |
|
|
|
107 |
|
|
// The following are only written to by the FLASH IO layer.
|
108 |
|
|
cyg_flash_printf *pf; // Pointer to diagnostic printf
|
109 |
|
|
bool init; // Device has been initialised
|
110 |
|
|
#ifdef CYGPKG_KERNEL
|
111 |
|
|
cyg_mutex_t mutex; // Mutex for thread safeness
|
112 |
|
|
#endif
|
113 |
|
|
#if (CYGHWR_IO_FLASH_DEVICE > 1)
|
114 |
|
|
struct cyg_flash_dev *next; // Pointer to next device
|
115 |
|
|
#endif
|
116 |
|
|
} CYG_HAL_TABLE_TYPE;
|
117 |
|
|
|
118 |
|
|
// Macros for instantiating the above structures.
|
119 |
|
|
#ifdef CYGHWR_IO_FLASH_BLOCK_LOCKING
|
120 |
|
|
# define CYG_FLASH_FUNS(_funs_, _init_, _query_ , _erase_, _prog_ , _read_, _lock_, _unlock_) \
|
121 |
|
|
struct cyg_flash_dev_funs _funs_ = \
|
122 |
|
|
{ \
|
123 |
|
|
.flash_init = _init_, \
|
124 |
|
|
.flash_query = _query_, \
|
125 |
|
|
.flash_erase_block = _erase_, \
|
126 |
|
|
.flash_program = _prog_, \
|
127 |
|
|
.flash_read = _read_, \
|
128 |
|
|
.flash_block_lock = _lock_, \
|
129 |
|
|
.flash_block_unlock = _unlock_ \
|
130 |
|
|
}
|
131 |
|
|
#else
|
132 |
|
|
# define CYG_FLASH_FUNS(_funs_, _init_, _query_ , _erase_, _prog_ , _read_, _lock_, _unlock_) \
|
133 |
|
|
struct cyg_flash_dev_funs _funs_ = \
|
134 |
|
|
{ \
|
135 |
|
|
.flash_init = _init_, \
|
136 |
|
|
.flash_query = _query_, \
|
137 |
|
|
.flash_erase_block = _erase_, \
|
138 |
|
|
.flash_program = _prog_, \
|
139 |
|
|
.flash_read = _read_ \
|
140 |
|
|
}
|
141 |
|
|
#endif
|
142 |
|
|
|
143 |
|
|
// We assume HAL tables are placed into RAM.
|
144 |
|
|
#define CYG_FLASH_DRIVER(_name_, _funs_, _flags_, _start_, _end_, _num_block_infos_, _block_info_, _priv_) \
|
145 |
|
|
struct cyg_flash_dev _name_ CYG_HAL_TABLE_ENTRY(cyg_flashdev) = \
|
146 |
|
|
{ \
|
147 |
|
|
.funs = _funs_, \
|
148 |
|
|
.flags = _flags_, \
|
149 |
|
|
.start = _start_, \
|
150 |
|
|
.end = _end_, \
|
151 |
|
|
.num_block_infos = _num_block_infos_, \
|
152 |
|
|
.block_info = _block_info_, \
|
153 |
|
|
.priv = _priv_ \
|
154 |
|
|
}
|
155 |
|
|
|
156 |
|
|
// Additional support for legacy device drivers.
|
157 |
|
|
#ifdef CYGHWR_IO_FLASH_DEVICE_LEGACY
|
158 |
|
|
struct flash_info {
|
159 |
|
|
int block_size; // Assuming fixed size "blocks"
|
160 |
|
|
int blocks; // Number of blocks
|
161 |
|
|
int buffer_size; // Size of write buffer (only defined for some devices)
|
162 |
|
|
unsigned long block_mask;
|
163 |
|
|
void *start, *end; // Address range
|
164 |
|
|
int init;
|
165 |
|
|
cyg_flash_printf *pf;
|
166 |
|
|
};
|
167 |
|
|
|
168 |
|
|
externC struct flash_info flash_info;
|
169 |
|
|
externC int flash_hwr_init(void);
|
170 |
|
|
externC int flash_hwr_map_error(int err);
|
171 |
|
|
externC void flash_dev_query(void *data);
|
172 |
|
|
#endif // CYGHWR_IO_FLASH_DEVICE_LEGACY
|
173 |
|
|
|
174 |
|
|
// ----------------------------------------------------------------------------
|
175 |
|
|
// This section provides utility macros used by some flash drivers, especially
|
176 |
|
|
// the legacy ones. Such flash drivers need to #define _FLASH_PRIVATE before
|
177 |
|
|
// including this file.
|
178 |
|
|
|
179 |
|
|
#ifdef _FLASH_PRIVATE_
|
180 |
|
|
|
181 |
|
|
//==========================================================================
|
182 |
|
|
// Author(s): hmt
|
183 |
|
|
// Contributors: hmt, jskov, Jose Pascual <josepascual@almudi.com>
|
184 |
|
|
// Date: 2001-02-22
|
185 |
|
|
// Purpose: Define common flash device driver definitions
|
186 |
|
|
// Description: The flash_data_t type is used for accessing
|
187 |
|
|
// devices at the correct width.
|
188 |
|
|
// The FLASHWORD macro must be used to create constants
|
189 |
|
|
// of suitable width.
|
190 |
|
|
// The FLASH_P2V macro can be used to fix up non-linear
|
191 |
|
|
// mappings of flash blocks (defaults to a linear
|
192 |
|
|
// implementation).
|
193 |
|
|
//==========================================================================
|
194 |
|
|
|
195 |
|
|
// No mapping on this target - but these casts would be needed if some
|
196 |
|
|
// manipulation did occur. An example of this might be:
|
197 |
|
|
// // First 4K page of flash at physical address zero is
|
198 |
|
|
// // virtually mapped at address 0xa0000000.
|
199 |
|
|
// #define FLASH_P2V(x) ((volatile flash_t *)(((unsigned)(x) < 0x1000) ?
|
200 |
|
|
// ((unsigned)(x) | 0xa0000000) :
|
201 |
|
|
// (unsigned)(x)))
|
202 |
|
|
|
203 |
|
|
#ifndef FLASH_P2V
|
204 |
|
|
#define FLASH_P2V( _a_ ) ((volatile flash_t *)((CYG_ADDRWORD)(_a_)))
|
205 |
|
|
#endif
|
206 |
|
|
|
207 |
|
|
// ------------------------------------------------------------------------
|
208 |
|
|
//
|
209 |
|
|
// This generic code is intended to deal with all shapes and orientations
|
210 |
|
|
// of Intel StrataFlash. Trademarks &c belong to their respective owners.
|
211 |
|
|
//
|
212 |
|
|
// It therefore needs some trickery to define the constants and accessor
|
213 |
|
|
// types that we use to interact with the device or devices.
|
214 |
|
|
//
|
215 |
|
|
// The assumptions are that
|
216 |
|
|
// o Parallel devices, we write to, with the "opcode" replicated per
|
217 |
|
|
// device
|
218 |
|
|
// o The "opcode" and status returns exist only in the low byte of the
|
219 |
|
|
// device's interface regardless of its width.
|
220 |
|
|
// o Hence opcodes and status are only one byte.
|
221 |
|
|
// An exception is the test for succesfully erased data.
|
222 |
|
|
//
|
223 |
|
|
// ------------------------------------------------------------------------
|
224 |
|
|
|
225 |
|
|
#if 8 == CYGNUM_FLASH_WIDTH
|
226 |
|
|
|
227 |
|
|
# if 1 == CYGNUM_FLASH_INTERLEAVE
|
228 |
|
|
# define FLASHWORD( k ) ((flash_data_t)(k)) // To narrow a 16-bit constant
|
229 |
|
|
typedef cyg_uint8 flash_data_t;
|
230 |
|
|
# elif 2 == CYGNUM_FLASH_INTERLEAVE
|
231 |
|
|
// 2 devices to make 16-bit
|
232 |
|
|
# define FLASHWORD( k ) ((k)+((k)<<8))
|
233 |
|
|
typedef cyg_uint16 flash_data_t;
|
234 |
|
|
# elif 4 == CYGNUM_FLASH_INTERLEAVE
|
235 |
|
|
// 4 devices to make 32-bit
|
236 |
|
|
# define FLASHWORD( k ) ((k)+((k)<<8)+((k)<<16)+((k)<<24))
|
237 |
|
|
typedef cyg_uint32 flash_data_t;
|
238 |
|
|
# elif 8 == CYGNUM_FLASH_INTERLEAVE
|
239 |
|
|
// 8 devices to make 64-bit - intermediate requires explicit widening
|
240 |
|
|
# define FLASHWORD32( k ) ((flash_data_t)((k)+((k)<<8)+((k)<<16)+((k)<<24)))
|
241 |
|
|
# define FLASHWORD( k ) (FLASHWORD32( k ) + (FLASHWORD32( k ) << 32));
|
242 |
|
|
typedef cyg_uint64 flash_data_t;
|
243 |
|
|
# else
|
244 |
|
|
# error How many 8-bit flash devices?
|
245 |
|
|
# endif
|
246 |
|
|
|
247 |
|
|
#elif 16 == CYGNUM_FLASH_WIDTH
|
248 |
|
|
|
249 |
|
|
# if 1 == CYGNUM_FLASH_INTERLEAVE
|
250 |
|
|
# define FLASHWORD( k ) (k)
|
251 |
|
|
typedef cyg_uint16 flash_data_t;
|
252 |
|
|
# elif 2 == CYGNUM_FLASH_INTERLEAVE
|
253 |
|
|
// 2 devices to make 32-bit
|
254 |
|
|
# define FLASHWORD( k ) ((k)+((k)<<16))
|
255 |
|
|
typedef cyg_uint32 flash_data_t;
|
256 |
|
|
# elif 4 == CYGNUM_FLASH_INTERLEAVE
|
257 |
|
|
// 4 devices to make 64-bit - intermediate requires explicit widening
|
258 |
|
|
# define FLASHWORD32( k ) ((flash_data_t)((k)+((k)<<16)))
|
259 |
|
|
# define FLASHWORD( k ) (FLASHWORD32( k ) + (FLASHWORD32( k ) << 32));
|
260 |
|
|
typedef cyg_uint64 flash_data_t;
|
261 |
|
|
# else
|
262 |
|
|
# error How many 16-bit flash devices?
|
263 |
|
|
# endif
|
264 |
|
|
|
265 |
|
|
#elif 32 == CYGNUM_FLASH_WIDTH
|
266 |
|
|
|
267 |
|
|
# if 1 == CYGNUM_FLASH_INTERLEAVE
|
268 |
|
|
# define FLASHWORD( k ) (k)
|
269 |
|
|
typedef cyg_uint32 flash_data_t;
|
270 |
|
|
# elif 2 == CYGNUM_FLASH_INTERLEAVE
|
271 |
|
|
// 2 devices to make 64-bit - intermediate requires explicit widening
|
272 |
|
|
# define FLASHWORD32( k ) ((flash_data_t)(k))
|
273 |
|
|
# define FLASHWORD( k ) (FLASHWORD32( k ) + (FLASHWORD32( k ) << 32));
|
274 |
|
|
typedef cyg_uint64 flash_data_t;
|
275 |
|
|
# else
|
276 |
|
|
# error How many 32-bit flash devices?
|
277 |
|
|
# endif
|
278 |
|
|
|
279 |
|
|
#else
|
280 |
|
|
# error What flash width?
|
281 |
|
|
#endif
|
282 |
|
|
|
283 |
|
|
// Data (not) that we read back:
|
284 |
|
|
#if 0 == CYGNUM_FLASH_BLANK
|
285 |
|
|
# define FLASH_BlankValue ((flash_data_t)0)
|
286 |
|
|
#elif 1 == CYGNUM_FLASH_BLANK
|
287 |
|
|
# define FLASH_BlankValue ((flash_data_t)(-1ll))
|
288 |
|
|
#else
|
289 |
|
|
# error What blank value?
|
290 |
|
|
#endif
|
291 |
|
|
|
292 |
|
|
#endif // _FLASH_PRIVATE_
|
293 |
|
|
|
294 |
|
|
#endif // CYGONCE_IO_FLASH_FLASH_DEV_H
|
295 |
|
|
//----------------------------------------------------------------------------
|
296 |
|
|
// end of flash_dev.h
|
297 |
|
|
|