Mercurial > flash_v2
annotate packages/io/flash/current/src/legacy_dev.c @ 1750:fac0499dabd6
Move legacy macros from a public to an internal header file, to
facilitate future clean-ups
| author | bartv |
|---|---|
| date | Mon, 22 Nov 2004 13:25:23 +0000 |
| parents | 80232dbac7fb |
| children | 61fbcc1cb232 |
| rev | line source |
|---|---|
| 1706 | 1 //========================================================================== |
| 2 // | |
| 3 // legacy_dev.c | |
| 4 // | |
| 5 // Interface to the legacy device drivers | |
| 6 // | |
| 7 //========================================================================== | |
| 8 //####ECOSGPLCOPYRIGHTBEGIN#### | |
| 9 // ------------------------------------------- | |
| 10 // This file is part of eCos, the Embedded Configurable Operating System. | |
| 11 // Copyright (C) 2004 Andrew Lunn | |
| 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 version. | |
| 16 // | |
| 17 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY | |
| 18 // WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 19 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 20 // for more details. | |
| 21 // | |
| 22 // You should have received a copy of the GNU General Public License along | |
| 23 // with eCos; if not, write to the Free Software Foundation, Inc., | |
| 24 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. | |
| 25 // | |
| 26 // As a special exception, if other files instantiate templates or use macros | |
| 27 // or inline functions from this file, or you compile this file and link it | |
| 28 // with other works to produce a work based on this file, this file does not | |
| 29 // by itself cause the resulting work to be covered by the GNU General Public | |
| 30 // License. However the source code for this file must still be made available | |
| 31 // in accordance with section (3) of the GNU General Public License. | |
| 32 // | |
| 33 // This exception does not invalidate any other reasons why a work based on | |
| 34 // this file might be covered by the GNU General Public License. | |
| 35 // | |
| 36 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc. | |
| 37 // at http://sources.redhat.com/ecos/ecos-license/ | |
| 38 // ------------------------------------------- | |
| 39 //####ECOSGPLCOPYRIGHTEND#### | |
| 40 //========================================================================== | |
| 41 //#####DESCRIPTIONBEGIN#### | |
| 42 // | |
| 43 // Author(s): Andrew Lunn | |
| 44 // Contributors: Andrew Lunn | |
| 45 // Date: 2004-07-02 | |
| 46 // Purpose: | |
| 47 // Description: Implement an interface to the legacy device drivers | |
| 48 // | |
| 49 //####DESCRIPTIONEND#### | |
| 50 // | |
| 51 //========================================================================== | |
| 52 | |
| 53 #include <pkgconf/system.h> | |
| 54 #include <pkgconf/io_flash.h> | |
| 55 | |
| 56 #include <cyg/hal/hal_arch.h> | |
| 57 #include <cyg/hal/hal_intr.h> | |
| 58 #include <cyg/hal/hal_cache.h> | |
| 59 #include <string.h> | |
| 60 | |
| 61 #define _FLASH_PRIVATE_ | |
| 62 #include <cyg/io/flash.h> | |
|
1750
fac0499dabd6
Move legacy macros from a public to an internal header file, to
bartv
parents:
1749
diff
changeset
|
63 #include "flash_legacy.h" |
| 1706 | 64 |
| 65 // When this flag is set, do not actually jump to the relocated code. | |
| 66 // This can be used for running the function in place (RAM startup only), | |
| 67 // allowing calls to diag_printf() and similar. | |
| 68 #undef RAM_FLASH_DEV_DEBUG | |
| 69 #if !defined(CYG_HAL_STARTUP_RAM) && defined(RAM_FLASH_DEV_DEBUG) | |
| 70 # warning "Can only enable the flash debugging when configured for RAM startup" | |
| 71 #endif | |
| 72 | |
| 73 struct flash_info flash_info; | |
| 74 | |
| 75 // These are the functions in the HW specific driver we need to call. | |
| 76 typedef void code_fun(void*); | |
| 77 | |
| 78 externC code_fun flash_query; | |
| 79 externC code_fun flash_erase_block; | |
| 80 externC code_fun flash_program_buf; | |
| 81 externC code_fun flash_read_buf; | |
| 82 externC code_fun flash_lock_block; | |
| 83 externC code_fun flash_unlock_block; | |
| 84 | |
| 85 // Initialize the device | |
| 86 static int | |
| 87 legacy_flash_init (struct cyg_flash_dev *dev) | |
| 88 { | |
| 89 int err; | |
| 1749 | 90 static cyg_flash_block_info_t block_info[1]; |
| 1706 | 91 |
| 92 err=flash_hwr_init(); | |
| 93 | |
| 94 if (!err) { | |
| 95 dev->start = (cyg_flashaddr_t)flash_info.start; | |
|
1735
e308039f4579
* src/legacy_dev.c (legacy_flash_init): The end is the size plus
asl
parents:
1730
diff
changeset
|
96 dev->end = dev->start + flash_info.block_size * flash_info.blocks - 1; |
| 1706 | 97 dev->num_block_infos = 1; |
| 98 dev->block_info = block_info; | |
| 99 block_info[0].block_size = flash_info.block_size; | |
| 100 block_info[0].blocks = flash_info.blocks; | |
| 101 } | |
| 102 return err; | |
| 103 } | |
| 104 | |
| 105 // Use this function to make function pointers anonymous - forcing the | |
| 106 // compiler to use jumps instead of branches when calling driver | |
| 107 // services. | |
| 108 static void* __anonymizer(void* p) | |
| 109 { | |
| 110 return p; | |
| 111 } | |
| 112 | |
| 113 static size_t | |
| 114 legacy_flash_query (struct cyg_flash_dev *dev, | |
| 115 void * data, | |
| 116 const size_t len) | |
| 117 __attribute__ ((section (".2ram.flash_program_buf"))); | |
| 118 | |
| 119 static size_t | |
| 120 legacy_flash_query (struct cyg_flash_dev *dev, | |
| 121 void * data, | |
| 122 const size_t len) | |
| 123 { | |
| 124 typedef void code_fun(void*); | |
| 125 code_fun *_flash_query; | |
| 126 | |
| 127 _flash_query = (code_fun*) __anonymizer(&flash_query); | |
| 128 | |
| 129 (*_flash_query)(data); | |
| 130 | |
| 131 return len; | |
| 132 } | |
| 133 | |
| 134 static int | |
| 135 legacy_flash_erase_block (struct cyg_flash_dev *dev, | |
| 136 const cyg_flashaddr_t block_base) | |
| 137 __attribute__ ((section (".2ram.flash_program_buf"))); | |
| 138 | |
| 139 static int | |
| 140 legacy_flash_erase_block (struct cyg_flash_dev *dev, | |
| 141 const cyg_flashaddr_t block_base) | |
| 142 { | |
| 143 typedef int code_fun(cyg_flashaddr_t, unsigned int); | |
| 144 code_fun *_flash_erase_block; | |
| 145 size_t block_size = dev->block_info[0].block_size; | |
| 146 | |
| 147 _flash_erase_block = (code_fun*) __anonymizer(&flash_erase_block); | |
| 148 | |
| 149 return (*_flash_erase_block)(block_base, block_size); | |
| 150 } | |
| 151 | |
| 152 static int | |
| 153 legacy_flash_program(struct cyg_flash_dev *dev, | |
| 154 cyg_flashaddr_t base, | |
| 155 const void* data, const size_t len) | |
| 156 __attribute__ ((section (".2ram.flash_program_buf"))); | |
| 157 | |
| 158 static int | |
| 159 legacy_flash_program(struct cyg_flash_dev *dev, | |
| 160 cyg_flashaddr_t base, | |
| 161 const void* data, const size_t len) | |
| 162 { | |
| 163 typedef int code_fun(cyg_flashaddr_t, const void *, int, unsigned long, int); | |
| 164 code_fun *_flash_program_buf; | |
| 165 size_t block_size = dev->block_info[0].block_size; | |
| 166 size_t block_mask = ~(block_mask -1); | |
| 167 | |
| 168 _flash_program_buf = (code_fun*) __anonymizer(&flash_program_buf); | |
| 169 | |
| 170 return (*_flash_program_buf)(base, data, len, block_mask ,block_size); | |
| 171 } | |
| 172 | |
| 1744 | 173 #ifdef CYGSEM_IO_FLASH_READ_INDIRECT |
| 1706 | 174 static int |
| 175 legacy_flash_read (struct cyg_flash_dev *dev, | |
| 176 const cyg_flashaddr_t base, | |
| 177 void* data, const size_t len) | |
| 178 __attribute__ ((section (".2ram.flash_program_buf"))); | |
| 179 | |
| 180 static int | |
| 181 legacy_flash_read (struct cyg_flash_dev *dev, | |
| 182 const cyg_flashaddr_t base, | |
| 183 void* data, const size_t len) | |
| 184 { | |
|
1730
3f6b1c304c7a
* src/flash.c: Offset into the block is not calculated correctly
asl
parents:
1729
diff
changeset
|
185 typedef int code_fun(const cyg_flashaddr_t, void *, int, unsigned long, int); |
| 1706 | 186 code_fun *_flash_read_buf; |
| 187 size_t block_size = dev->block_info[0].block_size; | |
| 188 size_t block_mask = ~(block_mask -1); | |
| 189 | |
| 190 _flash_read_buf = (code_fun*) __anonymizer(&flash_read_buf); | |
| 191 | |
|
1730
3f6b1c304c7a
* src/flash.c: Offset into the block is not calculated correctly
asl
parents:
1729
diff
changeset
|
192 return (*_flash_read_buf)(base, data, len, block_mask, block_size); |
| 1744 | 193 } |
| 194 | |
| 195 # define LEGACY_FLASH_READ legacy_flash_read | |
| 1706 | 196 #else |
| 1744 | 197 # define LEGACY_FLASH_READ ((int (*)(struct cyg_flash_dev*, const cyg_flashaddr_t, void*, const size_t))0) |
| 1706 | 198 #endif |
| 199 | |
| 200 | |
| 201 static int | |
| 202 legacy_flash_block_lock (struct cyg_flash_dev *dev, | |
| 203 const cyg_flashaddr_t block_base) | |
| 204 __attribute__ ((section (".2ram.flash_program_buf"))); | |
| 205 | |
| 206 static int | |
| 207 legacy_flash_block_lock (struct cyg_flash_dev *dev, | |
| 208 const cyg_flashaddr_t block_base) | |
| 209 { | |
| 210 #ifdef CYGHWR_IO_FLASH_BLOCK_LOCKING | |
| 211 typedef int code_fun(cyg_flashaddr_t); | |
| 212 code_fun *_flash_lock_block; | |
| 213 | |
| 214 _flash_lock_block = (code_fun*) __anonymizer(&flash_lock_block); | |
| 215 | |
| 216 return (*_flash_lock_block)(block_base); | |
| 217 #else | |
| 218 return CYG_FLASH_ERR_INVALID; | |
| 219 #endif | |
| 220 } | |
| 221 | |
| 222 static int | |
| 223 legacy_flash_block_unlock (struct cyg_flash_dev *dev, | |
| 224 const cyg_flashaddr_t block_base) | |
| 225 __attribute__ ((section (".2ram.flash_program_buf"))); | |
| 226 | |
| 227 static int | |
| 228 legacy_flash_block_unlock (struct cyg_flash_dev *dev, | |
| 229 const cyg_flashaddr_t block_base) | |
| 230 { | |
| 231 #ifdef CYGHWR_IO_FLASH_BLOCK_LOCKING | |
| 232 typedef int code_fun(cyg_flashaddr_t, int, int); | |
| 233 code_fun *_flash_unlock_block; | |
| 234 size_t block_size = dev->block_info[0].block_size; | |
| 235 cyg_uint32 blocks = dev->block_info[0].blocks; | |
| 236 | |
| 237 _flash_unlock_block = (code_fun*) __anonymizer(&flash_unlock_block); | |
| 238 | |
| 239 return (*_flash_unlock_block)(block_base, block_size, blocks); | |
| 240 #else | |
| 241 return CYG_FLASH_ERR_INVALID; | |
| 242 #endif | |
| 243 } | |
| 244 | |
| 245 // Map a hardware status to a package error | |
| 246 static int | |
| 247 legacy_flash_hwr_map_error (struct cyg_flash_dev *dev, int err) | |
| 248 __attribute__ ((section (".2ram.flash_program_buf"))); | |
| 249 | |
| 250 static int | |
| 251 legacy_flash_hwr_map_error (struct cyg_flash_dev *dev, int err) | |
| 252 { | |
| 253 return flash_hwr_map_error(err); | |
| 254 } | |
| 255 | |
| 256 void | |
| 257 flash_dev_query(void* data) | |
| 258 { | |
| 259 typedef void code_fun(void*); | |
| 260 code_fun *_flash_query; | |
| 261 int d_cache, i_cache; | |
| 262 | |
| 263 _flash_query = (code_fun*) __anonymizer(&flash_query); | |
| 264 | |
| 265 HAL_FLASH_CACHES_OFF(d_cache, i_cache); | |
| 266 (*_flash_query)(data); | |
| 267 HAL_FLASH_CACHES_ON(d_cache, i_cache); | |
| 268 } | |
| 269 | |
| 270 CYG_FLASH_FUNS(cyg_legacy_funs, | |
| 271 legacy_flash_init, | |
| 272 legacy_flash_query, | |
| 273 legacy_flash_erase_block, | |
| 274 legacy_flash_program, | |
| 1744 | 275 LEGACY_FLASH_READ, |
| 1706 | 276 legacy_flash_hwr_map_error, |
| 277 legacy_flash_block_lock, | |
| 278 legacy_flash_block_unlock | |
| 279 ); | |
| 280 | |
| 281 CYG_FLASH_DRIVER(cyg_zzlegacy_flashdev, // zz so that it probably comes last. | |
| 282 &cyg_legacy_funs, | |
| 283 NULL, // Pointer to config structure | |
| 284 0, // Start address of flash | |
| 285 0); // Size of private structure | |
| 286 |
