Mercurial > flash_v2
annotate packages/io/flash/current/src/legacy_dev.c @ 1758:400806bc9c4f flash_v2_20041123
Remove unnecessary .2ram section attributes. These functions do not
manipulate the hardware directly so do not need special treatment
| author | bartv |
|---|---|
| date | Mon, 22 Nov 2004 21:27:43 +0000 |
| parents | 61fbcc1cb232 |
| children | 9c1d9e5039c2 |
| 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, | |
|
1758
400806bc9c4f
Remove unnecessary .2ram section attributes. These functions do not
bartv
parents:
1752
diff
changeset
|
116 size_t len) |
| 1706 | 117 { |
| 118 typedef void code_fun(void*); | |
| 119 code_fun *_flash_query; | |
| 120 | |
| 121 _flash_query = (code_fun*) __anonymizer(&flash_query); | |
| 122 | |
| 123 (*_flash_query)(data); | |
| 124 | |
| 125 return len; | |
| 126 } | |
| 127 | |
| 128 static int | |
| 129 legacy_flash_erase_block (struct cyg_flash_dev *dev, | |
| 1752 | 130 cyg_flashaddr_t block_base) |
| 1706 | 131 { |
| 132 typedef int code_fun(cyg_flashaddr_t, unsigned int); | |
| 133 code_fun *_flash_erase_block; | |
| 134 size_t block_size = dev->block_info[0].block_size; | |
| 135 | |
| 136 _flash_erase_block = (code_fun*) __anonymizer(&flash_erase_block); | |
| 137 | |
| 138 return (*_flash_erase_block)(block_base, block_size); | |
| 139 } | |
| 140 | |
| 141 static int | |
| 142 legacy_flash_program(struct cyg_flash_dev *dev, | |
| 143 cyg_flashaddr_t base, | |
| 1752 | 144 const void* data, size_t len) |
| 1706 | 145 { |
| 146 typedef int code_fun(cyg_flashaddr_t, const void *, int, unsigned long, int); | |
| 147 code_fun *_flash_program_buf; | |
| 148 size_t block_size = dev->block_info[0].block_size; | |
| 149 size_t block_mask = ~(block_mask -1); | |
| 150 | |
| 151 _flash_program_buf = (code_fun*) __anonymizer(&flash_program_buf); | |
| 152 | |
| 153 return (*_flash_program_buf)(base, data, len, block_mask ,block_size); | |
| 154 } | |
| 155 | |
| 1744 | 156 #ifdef CYGSEM_IO_FLASH_READ_INDIRECT |
| 1706 | 157 static int |
| 158 legacy_flash_read (struct cyg_flash_dev *dev, | |
| 159 const cyg_flashaddr_t base, | |
| 1752 | 160 void* data, size_t len) |
| 1706 | 161 { |
|
1730
3f6b1c304c7a
* src/flash.c: Offset into the block is not calculated correctly
asl
parents:
1729
diff
changeset
|
162 typedef int code_fun(const cyg_flashaddr_t, void *, int, unsigned long, int); |
| 1706 | 163 code_fun *_flash_read_buf; |
| 164 size_t block_size = dev->block_info[0].block_size; | |
| 165 size_t block_mask = ~(block_mask -1); | |
| 166 | |
| 167 _flash_read_buf = (code_fun*) __anonymizer(&flash_read_buf); | |
| 168 | |
|
1730
3f6b1c304c7a
* src/flash.c: Offset into the block is not calculated correctly
asl
parents:
1729
diff
changeset
|
169 return (*_flash_read_buf)(base, data, len, block_mask, block_size); |
| 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; | |
| 185 | |
| 186 _flash_lock_block = (code_fun*) __anonymizer(&flash_lock_block); | |
| 187 | |
| 188 return (*_flash_lock_block)(block_base); | |
| 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; | |
| 199 | |
| 200 _flash_unlock_block = (code_fun*) __anonymizer(&flash_unlock_block); | |
| 201 | |
| 202 return (*_flash_unlock_block)(block_base, block_size, blocks); | |
| 1752 | 203 } |
| 1706 | 204 #endif |
| 205 | |
| 206 // Map a hardware status to a package error | |
| 207 static int | |
| 208 legacy_flash_hwr_map_error (struct cyg_flash_dev *dev, int err) | |
| 209 { | |
| 210 return flash_hwr_map_error(err); | |
| 211 } | |
| 212 | |
| 213 void | |
| 214 flash_dev_query(void* data) | |
| 215 { | |
| 216 typedef void code_fun(void*); | |
| 217 code_fun *_flash_query; | |
| 218 int d_cache, i_cache; | |
| 219 | |
| 220 _flash_query = (code_fun*) __anonymizer(&flash_query); | |
| 221 | |
| 222 HAL_FLASH_CACHES_OFF(d_cache, i_cache); | |
| 223 (*_flash_query)(data); | |
| 224 HAL_FLASH_CACHES_ON(d_cache, i_cache); | |
| 225 } | |
| 226 | |
| 1752 | 227 static const CYG_FLASH_FUNS(cyg_legacy_funs, |
| 228 legacy_flash_init, | |
| 229 legacy_flash_query, | |
| 230 legacy_flash_erase_block, | |
| 231 legacy_flash_program, | |
| 232 LEGACY_FLASH_READ, | |
| 233 legacy_flash_hwr_map_error, | |
| 234 legacy_flash_block_lock, | |
| 235 legacy_flash_block_unlock | |
| 236 ); | |
| 1706 | 237 |
| 1752 | 238 CYG_FLASH_DRIVER(cyg_zzlegacy_flashdev, |
| 1706 | 239 &cyg_legacy_funs, |
| 1752 | 240 0, // Flags |
| 241 0, // Start address, filled in by init | |
| 242 0, // End address, filled in by init | |
| 243 0, // Number of block infos, filled in by init | |
| 244 NULL, // Block infos, again filled in by init | |
| 245 NULL // Driver private data, none needed | |
| 246 ); |
