Mercurial > flash_v2
annotate packages/io/flash/current/src/legacy_dev.c @ 1775:79275fdb4f20
* src/legacy_dev.c (legacy_flash_program): Added missing definition
of block_size.
* legacy_api.c: Added missing wrappers for flash_lock and
flash_unlock
| author | asl |
|---|---|
| date | Fri, 02 Feb 2007 20:06:03 +0000 |
| parents | 8667859d61ab |
| children |
| 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 | |
|
1769
8667859d61ab
* src/flash_legacy.h: Undef HAL_FLASH_CACHES_* macros if the HAL
jlarmour
parents:
1765
diff
changeset
|
12 // Copyright (C) 2004 eCosCentric Limited |
| 1706 | 13 // |
| 14 // eCos is free software; you can redistribute it and/or modify it under | |
| 15 // the terms of the GNU General Public License as published by the Free | |
| 16 // Software Foundation; either version 2 or (at your option) any later version. | |
| 17 // | |
| 18 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY | |
| 19 // WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 20 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 21 // for more details. | |
| 22 // | |
| 23 // You should have received a copy of the GNU General Public License along | |
| 24 // with eCos; if not, write to the Free Software Foundation, Inc., | |
| 25 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. | |
| 26 // | |
| 27 // As a special exception, if other files instantiate templates or use macros | |
| 28 // or inline functions from this file, or you compile this file and link it | |
| 29 // with other works to produce a work based on this file, this file does not | |
| 30 // by itself cause the resulting work to be covered by the GNU General Public | |
| 31 // License. However the source code for this file must still be made available | |
| 32 // in accordance with section (3) of the GNU General Public License. | |
| 33 // | |
| 34 // This exception does not invalidate any other reasons why a work based on | |
| 35 // this file might be covered by the GNU General Public License. | |
| 36 // | |
| 37 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc. | |
| 38 // at http://sources.redhat.com/ecos/ecos-license/ | |
| 39 // ------------------------------------------- | |
| 40 //####ECOSGPLCOPYRIGHTEND#### | |
| 41 //========================================================================== | |
| 42 //#####DESCRIPTIONBEGIN#### | |
| 43 // | |
| 44 // Author(s): Andrew Lunn | |
| 45 // Contributors: Andrew Lunn | |
| 46 // Date: 2004-07-02 | |
| 47 // Purpose: | |
| 48 // Description: Implement an interface to the legacy device drivers | |
| 49 // | |
| 50 //####DESCRIPTIONEND#### | |
| 51 // | |
| 52 //========================================================================== | |
| 53 | |
| 54 #include <pkgconf/system.h> | |
| 55 #include <pkgconf/io_flash.h> | |
| 56 | |
| 57 #include <cyg/hal/hal_arch.h> | |
| 58 #include <cyg/hal/hal_intr.h> | |
| 59 #include <cyg/hal/hal_cache.h> | |
| 60 #include <string.h> | |
| 61 | |
| 62 #include <cyg/io/flash.h> | |
|
1764
96ec7e534d98
V2 flash header files clean-up. Eliminate flash_priv.h, moving the
bartv
parents:
1763
diff
changeset
|
63 #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
|
64 #include "flash_legacy.h" |
| 1706 | 65 |
| 66 // When this flag is set, do not actually jump to the relocated code. | |
| 67 // This can be used for running the function in place (RAM startup only), | |
| 68 // allowing calls to diag_printf() and similar. | |
| 69 #undef RAM_FLASH_DEV_DEBUG | |
| 70 #if !defined(CYG_HAL_STARTUP_RAM) && defined(RAM_FLASH_DEV_DEBUG) | |
| 71 # warning "Can only enable the flash debugging when configured for RAM startup" | |
| 72 #endif | |
| 73 | |
| 74 struct flash_info flash_info; | |
| 75 | |
| 76 // These are the functions in the HW specific driver we need to call. | |
| 77 typedef void code_fun(void*); | |
| 78 | |
| 79 externC code_fun flash_query; | |
| 80 externC code_fun flash_erase_block; | |
| 81 externC code_fun flash_program_buf; | |
| 82 externC code_fun flash_read_buf; | |
| 83 externC code_fun flash_lock_block; | |
| 84 externC code_fun flash_unlock_block; | |
| 85 | |
| 86 // Initialize the device | |
| 87 static int | |
| 88 legacy_flash_init (struct cyg_flash_dev *dev) | |
| 89 { | |
| 90 int err; | |
| 1749 | 91 static cyg_flash_block_info_t block_info[1]; |
| 1706 | 92 |
|
1765
bfd6d67dba43
V2 flash. Miscellaneous fixes to the legacy API and legacy device
bartv
parents:
1764
diff
changeset
|
93 flash_info.pf = dev->pf; |
|
bfd6d67dba43
V2 flash. Miscellaneous fixes to the legacy API and legacy device
bartv
parents:
1764
diff
changeset
|
94 |
| 1706 | 95 err=flash_hwr_init(); |
| 96 | |
| 97 if (!err) { | |
| 98 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
|
99 dev->end = dev->start + flash_info.block_size * flash_info.blocks - 1; |
| 1706 | 100 dev->num_block_infos = 1; |
| 101 dev->block_info = block_info; | |
| 102 block_info[0].block_size = flash_info.block_size; | |
| 103 block_info[0].blocks = flash_info.blocks; | |
| 104 } | |
| 105 return err; | |
| 106 } | |
| 107 | |
| 108 static size_t | |
| 109 legacy_flash_query (struct cyg_flash_dev *dev, | |
| 110 void * data, | |
|
1758
400806bc9c4f
Remove unnecessary .2ram section attributes. These functions do not
bartv
parents:
1752
diff
changeset
|
111 size_t len) |
| 1706 | 112 { |
| 113 typedef void code_fun(void*); | |
| 114 code_fun *_flash_query; | |
| 115 | |
|
1762
9c1d9e5039c2
Move dummy init/query/lock/unlock functions to the generic flash code,
bartv
parents:
1758
diff
changeset
|
116 _flash_query = (code_fun*) cyg_flash_anonymizer(&flash_query); |
| 1706 | 117 |
| 118 (*_flash_query)(data); | |
| 119 | |
| 120 return len; | |
| 121 } | |
| 122 | |
| 123 static int | |
| 124 legacy_flash_erase_block (struct cyg_flash_dev *dev, | |
| 1752 | 125 cyg_flashaddr_t block_base) |
| 1706 | 126 { |
| 127 typedef int code_fun(cyg_flashaddr_t, unsigned int); | |
| 128 code_fun *_flash_erase_block; | |
| 129 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
|
130 int stat; |
| 1706 | 131 |
|
1762
9c1d9e5039c2
Move dummy init/query/lock/unlock functions to the generic flash code,
bartv
parents:
1758
diff
changeset
|
132 _flash_erase_block = (code_fun*) cyg_flash_anonymizer(&flash_erase_block); |
| 1706 | 133 |
|
1763
42c8ea63b78d
Eliminate hwr_map_error() from the V2 driver interface, it no longer
bartv
parents:
1762
diff
changeset
|
134 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
|
135 return flash_hwr_map_error(stat); |
| 1706 | 136 } |
| 137 | |
| 138 static int | |
| 139 legacy_flash_program(struct cyg_flash_dev *dev, | |
| 140 cyg_flashaddr_t base, | |
| 1752 | 141 const void* data, size_t len) |
| 1706 | 142 { |
| 143 typedef int code_fun(cyg_flashaddr_t, const void *, int, unsigned long, int); | |
| 144 code_fun *_flash_program_buf; | |
|
1775
79275fdb4f20
* src/legacy_dev.c (legacy_flash_program): Added missing definition
asl
parents:
1769
diff
changeset
|
145 size_t block_size = dev->block_info[0].block_size; |
|
1769
8667859d61ab
* src/flash_legacy.h: Undef HAL_FLASH_CACHES_* macros if the HAL
jlarmour
parents:
1765
diff
changeset
|
146 size_t block_mask = ~(block_size -1); |
|
1763
42c8ea63b78d
Eliminate hwr_map_error() from the V2 driver interface, it no longer
bartv
parents:
1762
diff
changeset
|
147 int stat; |
|
42c8ea63b78d
Eliminate hwr_map_error() from the V2 driver interface, it no longer
bartv
parents:
1762
diff
changeset
|
148 |
|
1762
9c1d9e5039c2
Move dummy init/query/lock/unlock functions to the generic flash code,
bartv
parents:
1758
diff
changeset
|
149 _flash_program_buf = (code_fun*) cyg_flash_anonymizer(&flash_program_buf); |
| 1706 | 150 |
|
1765
bfd6d67dba43
V2 flash. Miscellaneous fixes to the legacy API and legacy device
bartv
parents:
1764
diff
changeset
|
151 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
|
152 return flash_hwr_map_error(stat); |
| 1706 | 153 } |
| 154 | |
| 1744 | 155 #ifdef CYGSEM_IO_FLASH_READ_INDIRECT |
| 1706 | 156 static int |
| 157 legacy_flash_read (struct cyg_flash_dev *dev, | |
| 158 const cyg_flashaddr_t base, | |
| 1752 | 159 void* data, size_t len) |
| 1706 | 160 { |
|
1730
3f6b1c304c7a
* src/flash.c: Offset into the block is not calculated correctly
asl
parents:
1729
diff
changeset
|
161 typedef int code_fun(const cyg_flashaddr_t, void *, int, unsigned long, int); |
| 1706 | 162 code_fun *_flash_read_buf; |
| 163 size_t block_size = dev->block_info[0].block_size; | |
|
1769
8667859d61ab
* src/flash_legacy.h: Undef HAL_FLASH_CACHES_* macros if the HAL
jlarmour
parents:
1765
diff
changeset
|
164 size_t block_mask = ~(block_size -1); |
|
1763
42c8ea63b78d
Eliminate hwr_map_error() from the V2 driver interface, it no longer
bartv
parents:
1762
diff
changeset
|
165 int stat; |
|
1762
9c1d9e5039c2
Move dummy init/query/lock/unlock functions to the generic flash code,
bartv
parents:
1758
diff
changeset
|
166 _flash_read_buf = (code_fun*) cyg_flash_anonymizer(&flash_read_buf); |
| 1706 | 167 |
|
1763
42c8ea63b78d
Eliminate hwr_map_error() from the V2 driver interface, it no longer
bartv
parents:
1762
diff
changeset
|
168 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
|
169 return flash_hwr_map_error(stat); |
| 1744 | 170 } |
| 171 | |
| 172 # define LEGACY_FLASH_READ legacy_flash_read | |
| 1706 | 173 #else |
| 1744 | 174 # define LEGACY_FLASH_READ ((int (*)(struct cyg_flash_dev*, const cyg_flashaddr_t, void*, const size_t))0) |
| 1706 | 175 #endif |
| 176 | |
| 177 | |
| 1752 | 178 #ifdef CYGHWR_IO_FLASH_BLOCK_LOCKING |
| 1706 | 179 static int |
| 180 legacy_flash_block_lock (struct cyg_flash_dev *dev, | |
| 181 const cyg_flashaddr_t block_base) | |
| 182 { | |
| 183 typedef int code_fun(cyg_flashaddr_t); | |
| 184 code_fun *_flash_lock_block; | |
|
1763
42c8ea63b78d
Eliminate hwr_map_error() from the V2 driver interface, it no longer
bartv
parents:
1762
diff
changeset
|
185 int stat; |
|
1762
9c1d9e5039c2
Move dummy init/query/lock/unlock functions to the generic flash code,
bartv
parents:
1758
diff
changeset
|
186 _flash_lock_block = (code_fun*) cyg_flash_anonymizer(&flash_lock_block); |
| 1706 | 187 |
|
1763
42c8ea63b78d
Eliminate hwr_map_error() from the V2 driver interface, it no longer
bartv
parents:
1762
diff
changeset
|
188 stat = (*_flash_lock_block)(block_base); |
|
42c8ea63b78d
Eliminate hwr_map_error() from the V2 driver interface, it no longer
bartv
parents:
1762
diff
changeset
|
189 return flash_hwr_map_error(stat); |
| 1706 | 190 } |
| 191 | |
| 192 static int | |
| 193 legacy_flash_block_unlock (struct cyg_flash_dev *dev, | |
| 194 const cyg_flashaddr_t block_base) | |
| 195 { | |
| 196 typedef int code_fun(cyg_flashaddr_t, int, int); | |
| 197 code_fun *_flash_unlock_block; | |
| 198 size_t block_size = dev->block_info[0].block_size; | |
| 199 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
|
200 int stat; |
|
1762
9c1d9e5039c2
Move dummy init/query/lock/unlock functions to the generic flash code,
bartv
parents:
1758
diff
changeset
|
201 _flash_unlock_block = (code_fun*) cyg_flash_anonymizer(&flash_unlock_block); |
| 1706 | 202 |
|
1763
42c8ea63b78d
Eliminate hwr_map_error() from the V2 driver interface, it no longer
bartv
parents:
1762
diff
changeset
|
203 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
|
204 return flash_hwr_map_error(stat); |
| 1752 | 205 } |
| 1706 | 206 #endif |
| 207 | |
| 208 void | |
| 209 flash_dev_query(void* data) | |
| 210 { | |
| 211 typedef void code_fun(void*); | |
| 212 code_fun *_flash_query; | |
|
1769
8667859d61ab
* src/flash_legacy.h: Undef HAL_FLASH_CACHES_* macros if the HAL
jlarmour
parents:
1765
diff
changeset
|
213 HAL_FLASH_CACHES_STATE(d_cache, i_cache); |
| 1706 | 214 |
|
1762
9c1d9e5039c2
Move dummy init/query/lock/unlock functions to the generic flash code,
bartv
parents:
1758
diff
changeset
|
215 _flash_query = (code_fun*) cyg_flash_anonymizer(&flash_query); |
| 1706 | 216 |
| 217 HAL_FLASH_CACHES_OFF(d_cache, i_cache); | |
| 218 (*_flash_query)(data); | |
| 219 HAL_FLASH_CACHES_ON(d_cache, i_cache); | |
| 220 } | |
| 221 | |
| 1752 | 222 static const CYG_FLASH_FUNS(cyg_legacy_funs, |
| 223 legacy_flash_init, | |
| 224 legacy_flash_query, | |
| 225 legacy_flash_erase_block, | |
| 226 legacy_flash_program, | |
| 227 LEGACY_FLASH_READ, | |
| 228 legacy_flash_block_lock, | |
| 229 legacy_flash_block_unlock | |
| 230 ); | |
| 1706 | 231 |
| 1752 | 232 CYG_FLASH_DRIVER(cyg_zzlegacy_flashdev, |
| 1706 | 233 &cyg_legacy_funs, |
| 1752 | 234 0, // Flags |
| 235 0, // Start address, filled in by init | |
| 236 0, // End address, filled in by init | |
| 237 0, // Number of block infos, filled in by init | |
| 238 NULL, // Block infos, again filled in by init | |
| 239 NULL // Driver private data, none needed | |
| 240 ); |
