1 |
27 |
unneback |
#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 Red Hat, 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 version.
|
18 |
|
|
//
|
19 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
|
20 |
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
21 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
22 |
|
|
// for more details.
|
23 |
|
|
//
|
24 |
|
|
// You should have received a copy of the GNU General Public License along
|
25 |
|
|
// with eCos; if not, write to the Free Software Foundation, Inc.,
|
26 |
|
|
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
|
27 |
|
|
//
|
28 |
|
|
// As a special exception, if other files instantiate templates or use macros
|
29 |
|
|
// or inline functions from this file, or you compile this file and link it
|
30 |
|
|
// with other works to produce a work based on this file, this file does not
|
31 |
|
|
// by itself cause the resulting work to be covered by the GNU General Public
|
32 |
|
|
// License. However the source code for this file must still be made available
|
33 |
|
|
// in accordance with section (3) of the GNU General Public License.
|
34 |
|
|
//
|
35 |
|
|
// This exception does not invalidate any other reasons why a work based on
|
36 |
|
|
// this file might be covered by the GNU General Public License.
|
37 |
|
|
//
|
38 |
|
|
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
|
39 |
|
|
// at http://sources.redhat.com/ecos/ecos-license/
|
40 |
|
|
// -------------------------------------------
|
41 |
|
|
//####ECOSGPLCOPYRIGHTEND####
|
42 |
|
|
//==========================================================================
|
43 |
|
|
//#####DESCRIPTIONBEGIN####
|
44 |
|
|
//
|
45 |
|
|
// Author(s): hmt
|
46 |
|
|
// Contributors: hmt, jskov, Jose Pascual <josepascual@almudi.com>
|
47 |
|
|
// Date: 2001-02-22
|
48 |
|
|
// Purpose: Define common flash device driver definitions
|
49 |
|
|
// Description: The flash_data_t type is used for accessing
|
50 |
|
|
// devices at the correct width.
|
51 |
|
|
// The FLASHWORD macro must be used to create constants
|
52 |
|
|
// of suitable width.
|
53 |
|
|
// The FLASH_P2V macro can be used to fix up non-linear
|
54 |
|
|
// mappings of flash blocks (defaults to a linear
|
55 |
|
|
// implementation).
|
56 |
|
|
//
|
57 |
|
|
//####DESCRIPTIONEND####
|
58 |
|
|
//
|
59 |
|
|
//==========================================================================
|
60 |
|
|
|
61 |
|
|
#ifdef _FLASH_PRIVATE_
|
62 |
|
|
|
63 |
|
|
// ------------------------------------------------------------------------
|
64 |
|
|
//
|
65 |
|
|
// No mapping on this target - but these casts would be needed if some
|
66 |
|
|
// manipulation did occur. An example of this might be:
|
67 |
|
|
// // First 4K page of flash at physical address zero is
|
68 |
|
|
// // virtually mapped at address 0xa0000000.
|
69 |
|
|
// #define FLASH_P2V(x) ((volatile flash_t *)(((unsigned)(x) < 0x1000) ?
|
70 |
|
|
// ((unsigned)(x) | 0xa0000000) :
|
71 |
|
|
// (unsigned)(x)))
|
72 |
|
|
|
73 |
|
|
#ifndef FLASH_P2V
|
74 |
|
|
#define FLASH_P2V( _a_ ) ((volatile flash_t *)((CYG_ADDRWORD)(_a_)))
|
75 |
|
|
#endif
|
76 |
|
|
|
77 |
|
|
// ------------------------------------------------------------------------
|
78 |
|
|
//
|
79 |
|
|
// This generic code is intended to deal with all shapes and orientations
|
80 |
|
|
// of Intel StrataFlash. Trademarks &c belong to their respective owners.
|
81 |
|
|
//
|
82 |
|
|
// It therefore needs some trickery to define the constants and accessor
|
83 |
|
|
// types that we use to interact with the device or devices.
|
84 |
|
|
//
|
85 |
|
|
// The assumptions are that
|
86 |
|
|
// o Parallel devices, we write to, with the "opcode" replicated per
|
87 |
|
|
// device
|
88 |
|
|
// o The "opcode" and status returns exist only in the low byte of the
|
89 |
|
|
// device's interface regardless of its width.
|
90 |
|
|
// o Hence opcodes and status are only one byte.
|
91 |
|
|
// An exception is the test for succesfully erased data.
|
92 |
|
|
//
|
93 |
|
|
// ------------------------------------------------------------------------
|
94 |
|
|
|
95 |
|
|
#if 8 == CYGNUM_FLASH_WIDTH
|
96 |
|
|
|
97 |
|
|
# if 1 == CYGNUM_FLASH_INTERLEAVE
|
98 |
|
|
# define FLASHWORD( k ) ((flash_data_t)(k)) // To narrow a 16-bit constant
|
99 |
|
|
typedef cyg_uint8 flash_data_t;
|
100 |
|
|
# elif 2 == CYGNUM_FLASH_INTERLEAVE
|
101 |
|
|
// 2 devices to make 16-bit
|
102 |
|
|
# define FLASHWORD( k ) ((k)+((k)<<8))
|
103 |
|
|
typedef cyg_uint16 flash_data_t;
|
104 |
|
|
# elif 4 == CYGNUM_FLASH_INTERLEAVE
|
105 |
|
|
// 4 devices to make 32-bit
|
106 |
|
|
# define FLASHWORD( k ) ((k)+((k)<<8)+((k)<<16)+((k)<<24))
|
107 |
|
|
typedef cyg_uint32 flash_data_t;
|
108 |
|
|
# elif 8 == CYGNUM_FLASH_INTERLEAVE
|
109 |
|
|
// 8 devices to make 64-bit - intermediate requires explicit widening
|
110 |
|
|
# define FLASHWORD32( k ) ((flash_data_t)((k)+((k)<<8)+((k)<<16)+((k)<<24)))
|
111 |
|
|
# define FLASHWORD( k ) (FLASHWORD32( k ) + (FLASHWORD32( k ) << 32));
|
112 |
|
|
typedef cyg_uint64 flash_data_t;
|
113 |
|
|
# else
|
114 |
|
|
# error How many 8-bit flash devices?
|
115 |
|
|
# endif
|
116 |
|
|
|
117 |
|
|
#elif 16 == CYGNUM_FLASH_WIDTH
|
118 |
|
|
|
119 |
|
|
# if 1 == CYGNUM_FLASH_INTERLEAVE
|
120 |
|
|
# define FLASHWORD( k ) (k)
|
121 |
|
|
typedef cyg_uint16 flash_data_t;
|
122 |
|
|
# elif 2 == CYGNUM_FLASH_INTERLEAVE
|
123 |
|
|
// 2 devices to make 32-bit
|
124 |
|
|
# define FLASHWORD( k ) ((k)+((k)<<16))
|
125 |
|
|
typedef cyg_uint32 flash_data_t;
|
126 |
|
|
# elif 4 == CYGNUM_FLASH_INTERLEAVE
|
127 |
|
|
// 4 devices to make 64-bit - intermediate requires explicit widening
|
128 |
|
|
# define FLASHWORD32( k ) ((flash_data_t)((k)+((k)<<16)))
|
129 |
|
|
# define FLASHWORD( k ) (FLASHWORD32( k ) + (FLASHWORD32( k ) << 32));
|
130 |
|
|
typedef cyg_uint64 flash_data_t;
|
131 |
|
|
# else
|
132 |
|
|
# error How many 16-bit flash devices?
|
133 |
|
|
# endif
|
134 |
|
|
|
135 |
|
|
#elif 32 == CYGNUM_FLASH_WIDTH
|
136 |
|
|
|
137 |
|
|
# if 1 == CYGNUM_FLASH_INTERLEAVE
|
138 |
|
|
# define FLASHWORD( k ) (k)
|
139 |
|
|
typedef cyg_uint32 flash_data_t;
|
140 |
|
|
# elif 2 == CYGNUM_FLASH_INTERLEAVE
|
141 |
|
|
// 2 devices to make 64-bit - intermediate requires explicit widening
|
142 |
|
|
# define FLASHWORD32( k ) ((flash_data_t)(k))
|
143 |
|
|
# define FLASHWORD( k ) (FLASHWORD32( k ) + (FLASHWORD32( k ) << 32));
|
144 |
|
|
typedef cyg_uint64 flash_data_t;
|
145 |
|
|
# else
|
146 |
|
|
# error How many 32-bit flash devices?
|
147 |
|
|
# endif
|
148 |
|
|
|
149 |
|
|
#else
|
150 |
|
|
# error What flash width?
|
151 |
|
|
#endif
|
152 |
|
|
|
153 |
|
|
// Data (not) that we read back:
|
154 |
|
|
#if 0 == CYGNUM_FLASH_BLANK
|
155 |
|
|
# define FLASH_BlankValue ((flash_data_t)0)
|
156 |
|
|
#elif 1 == CYGNUM_FLASH_BLANK
|
157 |
|
|
# define FLASH_BlankValue ((flash_data_t)(-1ll))
|
158 |
|
|
#else
|
159 |
|
|
# error What blank value?
|
160 |
|
|
#endif
|
161 |
|
|
|
162 |
|
|
#endif // _FLASH_PRIVATE_
|
163 |
|
|
|
164 |
|
|
#endif // CYGONCE_IO_FLASH_FLASH_DEV_H
|
165 |
|
|
//----------------------------------------------------------------------------
|
166 |
|
|
// end of flash_dev.h
|