Mercurial > flash_v2
annotate packages/io/flash/current/src/legacy_dev.c @ 1765:bfd6d67dba43
V2 flash. Miscellaneous fixes to the legacy API and legacy device
driver support
| author | bartv |
|---|---|
| date | Tue, 22 Feb 2005 23:21:12 +0000 |
| parents | 96ec7e534d98 |
| children | 8667859d61ab |
| 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 #include <cyg/io/flash.h> | |
|
1764
96ec7e534d98
V2 flash header files clean-up. Eliminate flash_priv.h, moving the
bartv
parents:
1763
diff
changeset
|
62 #include <cyg/io/flash_dev.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 |
|
1765
bfd6d67dba43
V2 flash. Miscellaneous fixes to the legacy API and legacy device
bartv
parents:
1764
diff
changeset
|
92 flash_info.pf = dev->pf; |
|
bfd6d67dba43
V2 flash. Miscellaneous fixes to the legacy API and legacy device
bartv
parents:
1764
diff
changeset
|
93 |
| 1706 | 94 err=flash_hwr_init(); |
| 95 | |
| 96 if (!err) { | |
| 97 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
|
98 dev->end = dev->start + flash_info.block_size * flash_info.blocks - 1; |
| 1706 | 99 dev->num_block_infos = 1; |
| 100 dev->block_info = block_info; | |
| 101 block_info[0].block_size = flash_info.block_size; | |
| 102 block_info[0].blocks = flash_info.blocks; | |
| 103 } | |
| 104 return err; | |
| 105 } | |
| 106 | |
| 107 static size_t | |
| 108 legacy_flash_query (struct cyg_flash_dev *dev, | |
| 109 void * data, | |
|
1758
400806bc9c4f
Remove unnecessary .2ram section attributes. These functions do not
bartv
parents:
1752
diff
changeset
|
110 size_t len) |
| 1706 | 111 { |
| 112 typedef void code_fun(void*); | |
| 113 code_fun *_flash_query; | |
| 114 | |
|
1762
9c1d9e5039c2
Move dummy init/query/lock/unlock functions to the generic flash code,
bartv
parents:
1758
diff
changeset
|
115 _flash_query = (code_fun*) cyg_flash_anonymizer(&flash_query); |
| 1706 | 116 |
| 117 (*_flash_query)(data); | |
| 118 | |
| 119 return len; | |
| 120 } | |
| 121 | |
| 122 static int | |
| 123 legacy_flash_erase_block (struct cyg_flash_dev *dev, | |
| 1752 | 124 cyg_flashaddr_t block_base) |
| 1706 | 125 { |
| 126 typedef int code_fun(cyg_flashaddr_t, unsigned int); | |
| 127 code_fun *_flash_erase_block; | |
| 128 size_t block_size = dev->block_info[0].block_size; | |
|
1763
42c8ea63b78d
Eliminate hwr_map_error() from the V2 driver interface, it no longer
bartv
parents:
1762
diff
changeset
|
129 int stat; |
| 1706 | 130 |
|
1762
9c1d9e5039c2
Move dummy init/query/lock/unlock functions to the generic flash code,
bartv
parents:
1758
diff
changeset
|
131 _flash_erase_block = (code_fun*) cyg_flash_anonymizer(&flash_erase_block); |
| 1706 | 132 |
|
1763
42c8ea63b78d
Eliminate hwr_map_error() from the V2 driver interface, it no longer
bartv
parents:
1762
diff
changeset
|
133 stat = (*_flash_erase_block)(block_base, block_size); |
|
42c8ea63b78d
Eliminate hwr_map_error() from the V2 driver interface, it no longer
bartv
parents:
1762
diff
changeset
|
134 return flash_hwr_map_error(stat); |
| 1706 | 135 } |
| 136 | |
| 137 static int | |
| 138 legacy_flash_program(struct cyg_flash_dev *dev, | |
| 139 cyg_flashaddr_t base, | |
| 1752 | 140 const void* data, size_t len) |
| 1706 | 141 { |
| 142 typedef int code_fun(cyg_flashaddr_t, const void *, int, unsigned long, int); | |
| 143 code_fun *_flash_program_buf; | |
| 144 size_t block_mask = ~(block_mask -1); | |
|
1763
42c8ea63b78d
Eliminate hwr_map_error() from the V2 driver interface, it no longer
bartv
parents:
1762
diff
changeset
|
145 int stat; |
|
42c8ea63b78d
Eliminate hwr_map_error() from the V2 driver interface, it no longer
bartv
parents:
1762
diff
changeset
|
146 |
|
1762
9c1d9e5039c2
Move dummy init/query/lock/unlock functions to the generic flash code,
bartv
parents:
1758
diff
changeset
|
147 _flash_program_buf = (code_fun*) cyg_flash_anonymizer(&flash_program_buf); |
| 1706 | 148 |
|
1765
bfd6d67dba43
V2 flash. Miscellaneous fixes to the legacy API and legacy device
bartv
parents:
1764
diff
changeset
|
149 stat = (*_flash_program_buf)(base, data, len, block_mask, flash_info.buffer_size); |
|
1763
42c8ea63b78d
Eliminate hwr_map_error() from the V2 driver interface, it no longer
bartv
parents:
1762
diff
changeset
|
150 return flash_hwr_map_error(stat); |
| 1706 | 151 } |
| 152 | |
| 1744 | 153 #ifdef CYGSEM_IO_FLASH_READ_INDIRECT |
| 1706 | 154 static int |
| 155 legacy_flash_read (struct cyg_flash_dev *dev, | |
| 156 const cyg_flashaddr_t base, | |
| 1752 | 157 void* data, size_t len) |
| 1706 | 158 { |
|
1730
3f6b1c304c7a
* src/flash.c: Offset into the block is not calculated correctly
asl
parents:
1729
diff
changeset
|
159 typedef int code_fun(const cyg_flashaddr_t, void *, int, unsigned long, int); |
| 1706 | 160 code_fun *_flash_read_buf; |
| 161 size_t block_size = dev->block_info[0].block_size; | |
| 162 size_t block_mask = ~(block_mask -1); | |
|
1763
42c8ea63b78d
Eliminate hwr_map_error() from the V2 driver interface, it no longer
bartv
parents:
1762
diff
changeset
|
163 int stat; |
|
1762
9c1d9e5039c2
Move dummy init/query/lock/unlock functions to the generic flash code,
bartv
parents:
1758
diff
changeset
|
164 _flash_read_buf = (code_fun*) cyg_flash_anonymizer(&flash_read_buf); |
| 1706 | 165 |
|
1763
42c8ea63b78d
Eliminate hwr_map_error() from the V2 driver interface, it no longer
bartv
parents:
1762
diff
changeset
|
166 stat = (*_flash_read_buf)(base, data, len, block_mask, block_size); |
|
42c8ea63b78d
Eliminate hwr_map_error() from the V2 driver interface, it no longer
bartv
parents:
1762
diff
changeset
|
167 return flash_hwr_map_error(stat); |
| 1744 | 168 } |
| 169 | |
| 170 # define LEGACY_FLASH_READ legacy_flash_read | |
| 1706 | 171 #else |
| 1744 | 172 # define LEGACY_FLASH_READ ((int (*)(struct cyg_flash_dev*, const cyg_flashaddr_t, void*, const size_t))0) |
| 1706 | 173 #endif |
| 174 | |
| 175 | |
| 1752 | 176 #ifdef CYGHWR_IO_FLASH_BLOCK_LOCKING |
| 1706 | 177 static int |
| 178 legacy_flash_block_lock (struct cyg_flash_dev *dev, | |
| 179 const cyg_flashaddr_t block_base) | |
| 180 { | |
| 181 typedef int code_fun(cyg_flashaddr_t); | |
| 182 code_fun *_flash_lock_block; | |
|
1763
42c8ea63b78d
Eliminate hwr_map_error() from the V2 driver interface, it no longer
bartv
parents:
1762
diff
changeset
|
183 int stat; |
|
1762
9c1d9e5039c2
Move dummy init/query/lock/unlock functions to the generic flash code,
bartv
parents:
1758
diff
changeset
|
184 _flash_lock_block = (code_fun*) cyg_flash_anonymizer(&flash_lock_block); |
| 1706 | 185 |
|
1763
42c8ea63b78d
Eliminate hwr_map_error() from the V2 driver interface, it no longer
bartv
parents:
1762
diff
changeset
|
186 stat = (*_flash_lock_block)(block_base); |
|
42c8ea63b78d
Eliminate hwr_map_error() from the V2 driver interface, it no longer
bartv
parents:
1762
diff
changeset
|
187 return flash_hwr_map_error(stat); |
| 1706 | 188 } |
| 189 | |
| 190 static int | |
| 191 legacy_flash_block_unlock (struct cyg_flash_dev *dev, | |
| 192 const cyg_flashaddr_t block_base) | |
| 193 { | |
| 194 typedef int code_fun(cyg_flashaddr_t, int, int); | |
| 195 code_fun *_flash_unlock_block; | |
| 196 size_t block_size = dev->block_info[0].block_size; | |
| 197 cyg_uint32 blocks = dev->block_info[0].blocks; | |
|
1763
42c8ea63b78d
Eliminate hwr_map_error() from the V2 driver interface, it no longer
bartv
parents:
1762
diff
changeset
|
198 int stat; |
|
1762
9c1d9e5039c2
Move dummy init/query/lock/unlock functions to the generic flash code,
bartv
parents:
1758
diff
changeset
|
199 _flash_unlock_block = (code_fun*) cyg_flash_anonymizer(&flash_unlock_block); |
| 1706 | 200 |
|
1763
42c8ea63b78d
Eliminate hwr_map_error() from the V2 driver interface, it no longer
bartv
parents:
1762
diff
changeset
|
201 stat = (*_flash_unlock_block)(block_base, block_size, blocks); |
|
42c8ea63b78d
Eliminate hwr_map_error() from the V2 driver interface, it no longer
bartv
parents:
1762
diff
changeset
|
202 return flash_hwr_map_error(stat); |
| 1752 | 203 } |
| 1706 | 204 #endif |
| 205 | |
| 206 void | |
| 207 flash_dev_query(void* data) | |
| 208 { | |
| 209 typedef void code_fun(void*); | |
| 210 code_fun *_flash_query; | |
| 211 int d_cache, i_cache; | |
| 212 | |
|
1762
9c1d9e5039c2
Move dummy init/query/lock/unlock functions to the generic flash code,
bartv
parents:
1758
diff
changeset
|
213 _flash_query = (code_fun*) cyg_flash_anonymizer(&flash_query); |
| 1706 | 214 |
| 215 HAL_FLASH_CACHES_OFF(d_cache, i_cache); | |
| 216 (*_flash_query)(data); | |
| 217 HAL_FLASH_CACHES_ON(d_cache, i_cache); | |
| 218 } | |
| 219 | |
| 1752 | 220 static const CYG_FLASH_FUNS(cyg_legacy_funs, |
| 221 legacy_flash_init, | |
| 222 legacy_flash_query, | |
| 223 legacy_flash_erase_block, | |
| 224 legacy_flash_program, | |
| 225 LEGACY_FLASH_READ, | |
| 226 legacy_flash_block_lock, | |
| 227 legacy_flash_block_unlock | |
| 228 ); | |
| 1706 | 229 |
| 1752 | 230 CYG_FLASH_DRIVER(cyg_zzlegacy_flashdev, |
| 1706 | 231 &cyg_legacy_funs, |
| 1752 | 232 0, // Flags |
| 233 0, // Start address, filled in by init | |
| 234 0, // End address, filled in by init | |
| 235 0, // Number of block infos, filled in by init | |
| 236 NULL, // Block infos, again filled in by init | |
| 237 NULL // Driver private data, none needed | |
| 238 ); |
