Mercurial > flash_v2
annotate packages/io/flash/current/src/legacy_dev.c @ 1769:8667859d61ab
* src/flash_legacy.h: Undef HAL_FLASH_CACHES_* macros if the HAL
supplied them and they're not needed.
* cdl/io_flash.cdl, src/flash.c, src/flash_legacy.h,
src/legacy_dev.c: add support for V2 drivers which can take care
of the cache and interrupts themselves.
| author | jlarmour |
|---|---|
| date | Wed, 27 Sep 2006 14:24:46 +0000 |
| parents | bfd6d67dba43 |
| children | 79275fdb4f20 |
| 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; | |
|
1769
8667859d61ab
* src/flash_legacy.h: Undef HAL_FLASH_CACHES_* macros if the HAL
jlarmour
parents:
1765
diff
changeset
|
145 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
|
146 int stat; |
|
42c8ea63b78d
Eliminate hwr_map_error() from the V2 driver interface, it no longer
bartv
parents:
1762
diff
changeset
|
147 |
|
1762
9c1d9e5039c2
Move dummy init/query/lock/unlock functions to the generic flash code,
bartv
parents:
1758
diff
changeset
|
148 _flash_program_buf = (code_fun*) cyg_flash_anonymizer(&flash_program_buf); |
| 1706 | 149 |
|
1765
bfd6d67dba43
V2 flash. Miscellaneous fixes to the legacy API and legacy device
bartv
parents:
1764
diff
changeset
|
150 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
|
151 return flash_hwr_map_error(stat); |
| 1706 | 152 } |
| 153 | |
| 1744 | 154 #ifdef CYGSEM_IO_FLASH_READ_INDIRECT |
| 1706 | 155 static int |
| 156 legacy_flash_read (struct cyg_flash_dev *dev, | |
| 157 const cyg_flashaddr_t base, | |
| 1752 | 158 void* data, size_t len) |
| 1706 | 159 { |
|
1730
3f6b1c304c7a
* src/flash.c: Offset into the block is not calculated correctly
asl
parents:
1729
diff
changeset
|
160 typedef int code_fun(const cyg_flashaddr_t, void *, int, unsigned long, int); |
| 1706 | 161 code_fun *_flash_read_buf; |
| 162 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
|
163 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
|
164 int stat; |
|
1762
9c1d9e5039c2
Move dummy init/query/lock/unlock functions to the generic flash code,
bartv
parents:
1758
diff
changeset
|
165 _flash_read_buf = (code_fun*) cyg_flash_anonymizer(&flash_read_buf); |
| 1706 | 166 |
|
1763
42c8ea63b78d
Eliminate hwr_map_error() from the V2 driver interface, it no longer
bartv
parents:
1762
diff
changeset
|
167 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
|
168 return flash_hwr_map_error(stat); |
| 1744 | 169 } |
| 170 | |
| 171 # define LEGACY_FLASH_READ legacy_flash_read | |
| 1706 | 172 #else |
| 1744 | 173 # define LEGACY_FLASH_READ ((int (*)(struct cyg_flash_dev*, const cyg_flashaddr_t, void*, const size_t))0) |
| 1706 | 174 #endif |
| 175 | |
| 176 | |
| 1752 | 177 #ifdef CYGHWR_IO_FLASH_BLOCK_LOCKING |
| 1706 | 178 static int |
| 179 legacy_flash_block_lock (struct cyg_flash_dev *dev, | |
| 180 const cyg_flashaddr_t block_base) | |
| 181 { | |
| 182 typedef int code_fun(cyg_flashaddr_t); | |
| 183 code_fun *_flash_lock_block; | |
|
1763
42c8ea63b78d
Eliminate hwr_map_error() from the V2 driver interface, it no longer
bartv
parents:
1762
diff
changeset
|
184 int stat; |
|
1762
9c1d9e5039c2
Move dummy init/query/lock/unlock functions to the generic flash code,
bartv
parents:
1758
diff
changeset
|
185 _flash_lock_block = (code_fun*) cyg_flash_anonymizer(&flash_lock_block); |
| 1706 | 186 |
|
1763
42c8ea63b78d
Eliminate hwr_map_error() from the V2 driver interface, it no longer
bartv
parents:
1762
diff
changeset
|
187 stat = (*_flash_lock_block)(block_base); |
|
42c8ea63b78d
Eliminate hwr_map_error() from the V2 driver interface, it no longer
bartv
parents:
1762
diff
changeset
|
188 return flash_hwr_map_error(stat); |
| 1706 | 189 } |
| 190 | |
| 191 static int | |
| 192 legacy_flash_block_unlock (struct cyg_flash_dev *dev, | |
| 193 const cyg_flashaddr_t block_base) | |
| 194 { | |
| 195 typedef int code_fun(cyg_flashaddr_t, int, int); | |
| 196 code_fun *_flash_unlock_block; | |
| 197 size_t block_size = dev->block_info[0].block_size; | |
| 198 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
|
199 int stat; |
|
1762
9c1d9e5039c2
Move dummy init/query/lock/unlock functions to the generic flash code,
bartv
parents:
1758
diff
changeset
|
200 _flash_unlock_block = (code_fun*) cyg_flash_anonymizer(&flash_unlock_block); |
| 1706 | 201 |
|
1763
42c8ea63b78d
Eliminate hwr_map_error() from the V2 driver interface, it no longer
bartv
parents:
1762
diff
changeset
|
202 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
|
203 return flash_hwr_map_error(stat); |
| 1752 | 204 } |
| 1706 | 205 #endif |
| 206 | |
| 207 void | |
| 208 flash_dev_query(void* data) | |
| 209 { | |
| 210 typedef void code_fun(void*); | |
| 211 code_fun *_flash_query; | |
|
1769
8667859d61ab
* src/flash_legacy.h: Undef HAL_FLASH_CACHES_* macros if the HAL
jlarmour
parents:
1765
diff
changeset
|
212 HAL_FLASH_CACHES_STATE(d_cache, i_cache); |
| 1706 | 213 |
|
1762
9c1d9e5039c2
Move dummy init/query/lock/unlock functions to the generic flash code,
bartv
parents:
1758
diff
changeset
|
214 _flash_query = (code_fun*) cyg_flash_anonymizer(&flash_query); |
| 1706 | 215 |
| 216 HAL_FLASH_CACHES_OFF(d_cache, i_cache); | |
| 217 (*_flash_query)(data); | |
| 218 HAL_FLASH_CACHES_ON(d_cache, i_cache); | |
| 219 } | |
| 220 | |
| 1752 | 221 static const CYG_FLASH_FUNS(cyg_legacy_funs, |
| 222 legacy_flash_init, | |
| 223 legacy_flash_query, | |
| 224 legacy_flash_erase_block, | |
| 225 legacy_flash_program, | |
| 226 LEGACY_FLASH_READ, | |
| 227 legacy_flash_block_lock, | |
| 228 legacy_flash_block_unlock | |
| 229 ); | |
| 1706 | 230 |
| 1752 | 231 CYG_FLASH_DRIVER(cyg_zzlegacy_flashdev, |
| 1706 | 232 &cyg_legacy_funs, |
| 1752 | 233 0, // Flags |
| 234 0, // Start address, filled in by init | |
| 235 0, // End address, filled in by init | |
| 236 0, // Number of block infos, filled in by init | |
| 237 NULL, // Block infos, again filled in by init | |
| 238 NULL // Driver private data, none needed | |
| 239 ); |
