1 #ifndef CYGONCE_IO_FLASH_FLASH_DEV_H
2 #define CYGONCE_IO_FLASH_FLASH_DEV_H
3 //==========================================================================
7 // Common flash device driver definitions
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.
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.
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
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.
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.
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.
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####
46 // Contributors: hmt, jskov, Jose Pascual <josepascual@almudi.com>
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
53 // The FLASH_P2V macro can be used to fix up non-linear
54 // mappings of flash blocks (defaults to a linear
57 //####DESCRIPTIONEND####
59 //==========================================================================
61 #ifdef _FLASH_PRIVATE_
62 #include <cyg/infra/cyg_type.h>
64 // ------------------------------------------------------------------------
66 // No mapping on this target - but these casts would be needed if some
67 // manipulation did occur. An example of this might be:
68 // // First 4K page of flash at physical address zero is
69 // // virtually mapped at address 0xa0000000.
70 // #define FLASH_P2V(x) ((volatile flash_t *)(((unsigned)(x) < 0x1000) ?
71 // ((unsigned)(x) | 0xa0000000) :
75 #define FLASH_P2V( _a_ ) ((volatile flash_t *)((CYG_ADDRWORD)(_a_)))
78 // ------------------------------------------------------------------------
80 // This generic code is intended to deal with all shapes and orientations
81 // of Intel StrataFlash. Trademarks &c belong to their respective owners.
83 // It therefore needs some trickery to define the constants and accessor
84 // types that we use to interact with the device or devices.
86 // The assumptions are that
87 // o Parallel devices, we write to, with the "opcode" replicated per
89 // o The "opcode" and status returns exist only in the low byte of the
90 // device's interface regardless of its width.
91 // o Hence opcodes and status are only one byte.
92 // An exception is the test for succesfully erased data.
94 // ------------------------------------------------------------------------
96 #if 8 == CYGNUM_FLASH_WIDTH
98 # if 1 == CYGNUM_FLASH_INTERLEAVE
99 # define FLASHWORD( k ) ((flash_data_t)(k)) // To narrow a 16-bit constant
100 typedef cyg_uint8 flash_data_t;
101 # elif 2 == CYGNUM_FLASH_INTERLEAVE
102 // 2 devices to make 16-bit
103 # define FLASHWORD( k ) ((k)+((k)<<8))
104 typedef cyg_uint16 flash_data_t;
105 # elif 4 == CYGNUM_FLASH_INTERLEAVE
106 // 4 devices to make 32-bit
107 # define FLASHWORD( k ) ((k)+((k)<<8)+((k)<<16)+((k)<<24))
108 typedef cyg_uint32 flash_data_t;
109 # elif 8 == CYGNUM_FLASH_INTERLEAVE
110 // 8 devices to make 64-bit - intermediate requires explicit widening
111 # define FLASHWORD32( k ) ((flash_data_t)((k)+((k)<<8)+((k)<<16)+((k)<<24)))
112 # define FLASHWORD( k ) (FLASHWORD32( k ) + (FLASHWORD32( k ) << 32));
113 typedef cyg_uint64 flash_data_t;
115 # error How many 8-bit flash devices?
118 #elif 16 == CYGNUM_FLASH_WIDTH
120 # if 1 == CYGNUM_FLASH_INTERLEAVE
121 # define FLASHWORD( k ) (k)
122 typedef cyg_uint16 flash_data_t;
123 # elif 2 == CYGNUM_FLASH_INTERLEAVE
124 // 2 devices to make 32-bit
125 # define FLASHWORD( k ) ((k)+((k)<<16))
126 typedef cyg_uint32 flash_data_t;
127 # elif 4 == CYGNUM_FLASH_INTERLEAVE
128 // 4 devices to make 64-bit - intermediate requires explicit widening
129 # define FLASHWORD32( k ) ((flash_data_t)((k)+((k)<<16)))
130 # define FLASHWORD( k ) (FLASHWORD32( k ) + (FLASHWORD32( k ) << 32));
131 typedef cyg_uint64 flash_data_t;
133 # error How many 16-bit flash devices?
136 #elif 32 == CYGNUM_FLASH_WIDTH
138 # if 1 == CYGNUM_FLASH_INTERLEAVE
139 # define FLASHWORD( k ) (k)
140 typedef cyg_uint32 flash_data_t;
141 # elif 2 == CYGNUM_FLASH_INTERLEAVE
142 // 2 devices to make 64-bit - intermediate requires explicit widening
143 # define FLASHWORD32( k ) ((flash_data_t)(k))
144 # define FLASHWORD( k ) (FLASHWORD32( k ) + (FLASHWORD32( k ) << 32));
145 typedef cyg_uint64 flash_data_t;
147 # error How many 32-bit flash devices?
151 # error What flash width?
154 // Data (not) that we read back:
155 #if 0 == CYGNUM_FLASH_BLANK
156 # define FLASH_BlankValue ((flash_data_t)0)
157 #elif 1 == CYGNUM_FLASH_BLANK
158 # define FLASH_BlankValue ((flash_data_t)(-1ll))
160 # error What blank value?
163 #endif // _FLASH_PRIVATE_
165 #endif // CYGONCE_IO_FLASH_FLASH_DEV_H
166 //----------------------------------------------------------------------------
167 // end of flash_dev.h