Mercurial > flash_v2
annotate packages/io/flash/current/include/flash_priv.h @ 1749:80232dbac7fb
Flash API clean-ups
| author | bartv |
|---|---|
| date | Mon, 22 Nov 2004 12:05:55 +0000 |
| parents | a221170fac3d |
| children | fac0499dabd6 |
| rev | line source |
|---|---|
| 1706 | 1 //========================================================================== |
| 2 // | |
| 3 // flash.h | |
| 4 // | |
| 5 // Flash programming - external interfaces | |
| 6 // | |
| 7 //========================================================================== | |
| 8 //####ECOSGPLCOPYRIGHTBEGIN#### | |
| 9 // ------------------------------------------- | |
| 10 // This file is part of eCos, the Embedded Configurable Operating System. | |
| 11 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. | |
| 12 // Copyright (C) 2003 Gary Thomas | |
| 13 // copyright (C) 2004 Andrew Lunn | |
| 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): gthomas | |
| 46 // Contributors: gthomas, Andrew Lunn | |
| 47 // Date: 2000-07-14 | |
| 48 // Purpose: | |
| 49 // Description: | |
| 50 // | |
| 51 //####DESCRIPTIONEND#### | |
| 52 // | |
| 53 //========================================================================== | |
| 54 #ifndef _IO_FLASH_PRIV_H_ | |
| 55 #define _IO_FLASH_PRIV_H_ | |
| 56 | |
|
1747
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1745
diff
changeset
|
57 #include <pkgconf/system.h> |
|
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1745
diff
changeset
|
58 #include <pkgconf/io_flash.h> |
| 1749 | 59 #include <cyg/hal/hal_cache.h> |
| 60 #include <cyg/hal/hal_tables.h> | |
|
1747
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1745
diff
changeset
|
61 |
| 1706 | 62 // Forward reference of the device structure |
| 63 struct cyg_flash_dev; | |
| 64 | |
| 65 // Structure of pointers to functions in the device driver | |
| 66 struct cyg_flash_dev_funs { | |
| 67 int (*flash_init) (struct cyg_flash_dev *dev); | |
| 68 size_t (*flash_query) (struct cyg_flash_dev *dev, void * data, | |
| 69 const size_t len); | |
| 70 int (*flash_erase_block) (struct cyg_flash_dev *dev, | |
| 71 const cyg_flashaddr_t block_base); | |
| 72 int (*flash_program) (struct cyg_flash_dev *dev, | |
| 73 cyg_flashaddr_t base, | |
| 74 const void* data, const size_t len); | |
| 75 int (*flash_read) (struct cyg_flash_dev *dev, | |
| 76 const cyg_flashaddr_t base, | |
| 77 void* data, const size_t len); | |
| 78 int (*flash_hwr_map_error) (struct cyg_flash_dev *dev, int err); | |
| 79 int (*flash_block_lock) (struct cyg_flash_dev *dev, | |
| 80 const cyg_flashaddr_t block_base); | |
| 81 int (*flash_block_unlock) (struct cyg_flash_dev *dev, | |
| 82 const cyg_flashaddr_t block_base); | |
| 83 }; | |
| 84 | |
| 85 // Structure each device places in the HAL table | |
| 86 struct cyg_flash_dev { | |
| 87 struct cyg_flash_dev_funs *funs; // Function pointers | |
| 88 cyg_flashaddr_t start; // First address | |
| 89 cyg_flashaddr_t end; // Last address | |
| 90 cyg_uint32 num_block_infos; // Number of entries | |
| 1749 | 91 cyg_flash_block_info_t *block_info; // Info about one block size |
| 1706 | 92 |
| 93 void *priv; // Devices private data | |
| 94 void *config; // Configuration info | |
| 95 | |
| 96 // The following are only written to by the FLASH IO layer. | |
| 97 cyg_flash_printf *pf; // Pointer to diagnostic printf | |
| 98 bool init; // Device has been initialised | |
| 99 #ifdef CYGPKG_KERNEL | |
| 100 cyg_mutex_t mutex; // Mutex for thread safeness | |
| 101 #endif | |
|
1747
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1745
diff
changeset
|
102 #if (CYGHWR_IO_FLASH_DEVICE > 1) |
| 1706 | 103 struct cyg_flash_dev *next; // Pointer to next device |
|
1747
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1745
diff
changeset
|
104 #endif |
| 1706 | 105 } CYG_HAL_TABLE_TYPE; |
| 106 | |
| 107 #define CYG_FLASH_FUNS(funs,init,query,erase,prog,read,map,lock,unlock)\ | |
| 108 struct cyg_flash_dev_funs funs = \ | |
| 109 { \ | |
| 110 init, \ | |
| 111 query, \ | |
| 112 erase, \ | |
| 113 prog, \ | |
| 114 read, \ | |
| 115 map, \ | |
| 116 lock, \ | |
| 117 unlock \ | |
| 118 }; | |
| 119 | |
| 120 // We assume HAL tables are placed into RAM. | |
| 121 #define CYG_FLASH_DRIVER(name, _funs, _config, _start, _priv_size) \ | |
| 122 static char priv_ ## name [_priv_size]; \ | |
| 123 struct cyg_flash_dev name CYG_HAL_TABLE_ENTRY(cyg_flashdev) = { \ | |
| 124 .funs = _funs, \ | |
| 125 .config = _config, \ | |
| 126 .priv = priv_ ## name, \ | |
| 127 .start = _start, \ | |
| 128 }; | |
| 129 | |
| 1745 | 130 #ifdef CYGHWR_IO_FLASH_DEVICE_LEGACY |
| 1706 | 131 struct flash_info { |
| 132 int block_size; // Assuming fixed size "blocks" | |
| 133 int blocks; // Number of blocks | |
| 134 int buffer_size; // Size of write buffer (only defined for some devices) | |
| 135 unsigned long block_mask; | |
| 136 void *start, *end; // Address range | |
| 137 int init; | |
| 138 cyg_flash_printf *pf; | |
| 139 }; | |
| 140 | |
| 141 externC struct flash_info flash_info; | |
| 142 externC int flash_hwr_init(void); | |
| 143 externC int flash_hwr_map_error(int err); | |
| 144 externC void flash_dev_query(void *data); | |
| 1745 | 145 #endif // CYGHWR_IO_FLASH_DEVICE_LEGACY |
| 1706 | 146 // |
| 147 // Some FLASH devices may require additional support, e.g. to turn on | |
| 148 // appropriate voltage drivers, before any operation. | |
| 149 // | |
| 150 #ifdef CYGIMP_FLASH_ENABLE | |
| 151 #define FLASH_Enable CYGIMP_FLASH_ENABLE | |
| 152 extern void CYGIMP_FLASH_ENABLE(void *, void *); | |
| 153 #else | |
| 154 #define FLASH_Enable(_start_, _end_) | |
| 155 #endif | |
| 156 #ifdef CYGIMP_FLASH_DISABLE | |
| 157 #define FLASH_Disable CYGIMP_FLASH_DISABLE | |
| 158 extern void CYGIMP_FLASH_DISABLE(void *, void *); | |
| 159 #else | |
| 160 #define FLASH_Disable(_start_, _end_) | |
| 161 #endif | |
| 162 | |
| 163 // | |
| 164 // Some platforms have a DIP switch or jumper that tells the software that | |
| 165 // the flash is write protected. | |
| 166 // | |
| 167 #ifdef CYGSEM_IO_FLASH_SOFT_WRITE_PROTECT | |
| 168 externC cyg_bool plf_flash_query_soft_wp(void *addr, int len); | |
| 169 #endif | |
| 170 | |
| 171 //--------------------------------------------------------------------------- | |
| 172 // Execution of flash code must be done inside a | |
| 173 // HAL_FLASH_CACHES_OFF/HAL_FLASH_CACHES_ON region - disabling the | |
| 174 // cache on unified cache systems is necessary to prevent burst access | |
| 175 // to the flash area being programmed. With Harvard style caches, only | |
| 176 // the data cache needs to be disabled, but the instruction cache is | |
| 177 // disabled for consistency. | |
| 178 | |
| 179 // Targets may provide alternative implementations for these macros in | |
| 180 // the hal_cache.h (or var/plf) files. | |
| 181 | |
| 182 // The first part below is a generic, optimal implementation. The | |
| 183 // second part is the old implementation that has been tested to work | |
| 184 // on some targets - but it is not be suitable for targets that would | |
| 185 // do burst access to the flash (it does not disable the data cache). | |
| 186 | |
| 187 // Both implementations must be called with interrupts disabled. | |
| 188 | |
| 189 // NOTE: Do _not_ change any of the below macros without checking that | |
| 190 // the changed code still works on _all_ platforms that rely on these | |
| 191 // macros. There is no such thing as logical and correct when dealing | |
| 192 // with different cache and IO models, so _do not_ mess with this code | |
| 193 // unless you test it properly afterwards. | |
| 194 | |
| 195 #ifndef HAL_FLASH_CACHES_OFF | |
| 196 | |
| 197 // Some drivers have only been tested with the old macros below. | |
| 198 #ifndef HAL_FLASH_CACHES_OLD_MACROS | |
| 199 | |
| 200 #ifdef HAL_CACHE_UNIFIED | |
| 201 | |
| 202 // Note: the ucache code has not been tested yet on any target. | |
| 203 #define HAL_FLASH_CACHES_OFF(_d_, _i_) \ | |
| 204 CYG_MACRO_START \ | |
| 205 _i_ = 0; /* avoids warning */ \ | |
| 206 HAL_UCACHE_IS_ENABLED(_d_); \ | |
| 207 HAL_UCACHE_SYNC(); \ | |
| 208 HAL_UCACHE_INVALIDATE_ALL(); \ | |
| 209 HAL_UCACHE_DISABLE(); \ | |
| 210 CYG_MACRO_END | |
| 211 | |
| 212 #define HAL_FLASH_CACHES_ON(_d_, _i_) \ | |
| 213 CYG_MACRO_START \ | |
| 214 if (_d_) HAL_UCACHE_ENABLE(); \ | |
| 215 CYG_MACRO_END | |
| 216 | |
| 217 #else // HAL_CACHE_UNIFIED | |
| 218 | |
| 219 #define HAL_FLASH_CACHES_OFF(_d_, _i_) \ | |
| 220 CYG_MACRO_START \ | |
| 221 _i_ = 0; /* avoids warning */ \ | |
| 222 HAL_DCACHE_IS_ENABLED(_d_); \ | |
| 223 HAL_DCACHE_SYNC(); \ | |
| 224 HAL_DCACHE_INVALIDATE_ALL(); \ | |
| 225 HAL_DCACHE_DISABLE(); \ | |
| 226 HAL_ICACHE_INVALIDATE_ALL(); \ | |
| 227 CYG_MACRO_END | |
| 228 | |
| 229 #define HAL_FLASH_CACHES_ON(_d_, _i_) \ | |
| 230 CYG_MACRO_START \ | |
| 231 if (_d_) HAL_DCACHE_ENABLE(); \ | |
| 232 CYG_MACRO_END | |
| 233 | |
| 234 #endif // HAL_CACHE_UNIFIED | |
| 235 | |
| 236 #else // HAL_FLASH_CACHES_OLD_MACROS | |
| 237 | |
| 238 // Note: This implementation is broken as it will always enable the i-cache | |
| 239 // even if it was not enabled before. It also doesn't work if the | |
| 240 // target uses burst access to flash since the d-cache is left enabled. | |
| 241 // However, this does not mean you can change this code! Leave it as | |
| 242 // is - if you want a different implementation, provide it in the | |
| 243 // arch/var/platform cache header file. | |
| 244 | |
| 245 #define HAL_FLASH_CACHES_OFF(_d_, _i_) \ | |
| 246 _d_ = 0; /* avoids warning */ \ | |
| 247 _i_ = 0; /* avoids warning */ \ | |
| 248 HAL_DCACHE_SYNC(); \ | |
| 249 HAL_ICACHE_DISABLE(); | |
| 250 | |
| 251 #define HAL_FLASH_CACHES_ON(_d_, _i_) \ | |
| 252 HAL_ICACHE_ENABLE(); | |
| 253 | |
| 254 #endif // HAL_FLASH_CACHES_OLD_MACROS | |
| 255 | |
| 256 #endif // HAL_FLASH_CACHES_OFF | |
| 257 | |
| 258 #endif // _IO_FLASH_PRIV_H_ |
