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