Mercurial > flash_v2
annotate packages/io/flash/current/include/flash_priv.h @ 1762:9c1d9e5039c2
Move dummy init/query/lock/unlock functions to the generic flash code,
and use these in the V2 drivers where appropriate
| author | bartv |
|---|---|
| date | Mon, 29 Nov 2004 00:43:48 +0000 |
| parents | 61fbcc1cb232 |
| children | 42c8ea63b78d |
| rev | line source |
|---|---|
| 1706 | 1 //========================================================================== |
| 2 // | |
|
1750
fac0499dabd6
Move legacy macros from a public to an internal header file, to
bartv
parents:
1749
diff
changeset
|
3 // flash_priv.h |
| 1706 | 4 // |
|
1750
fac0499dabd6
Move legacy macros from a public to an internal header file, to
bartv
parents:
1749
diff
changeset
|
5 // Flash programming - driver internals |
| 1706 | 6 // |
| 7 //========================================================================== | |
| 8 //####ECOSGPLCOPYRIGHTBEGIN#### | |
| 9 // ------------------------------------------- | |
| 10 // This file is part of eCos, the Embedded Configurable Operating System. | |
| 11 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. | |
| 12 // Copyright (C) 2003 Gary Thomas | |
| 13 // copyright (C) 2004 Andrew Lunn | |
| 14 // | |
| 15 // eCos is free software; you can redistribute it and/or modify it under | |
| 16 // the terms of the GNU General Public License as published by the Free | |
| 17 // Software Foundation; either version 2 or (at your option) any later version. | |
| 18 // | |
| 19 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY | |
| 20 // WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 21 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 22 // for more details. | |
| 23 // | |
| 24 // You should have received a copy of the GNU General Public License along | |
| 25 // with eCos; if not, write to the Free Software Foundation, Inc., | |
| 26 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. | |
| 27 // | |
| 28 // As a special exception, if other files instantiate templates or use macros | |
| 29 // or inline functions from this file, or you compile this file and link it | |
| 30 // with other works to produce a work based on this file, this file does not | |
| 31 // by itself cause the resulting work to be covered by the GNU General Public | |
| 32 // License. However the source code for this file must still be made available | |
| 33 // in accordance with section (3) of the GNU General Public License. | |
| 34 // | |
| 35 // This exception does not invalidate any other reasons why a work based on | |
| 36 // this file might be covered by the GNU General Public License. | |
| 37 // | |
| 38 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc. | |
| 39 // at http://sources.redhat.com/ecos/ecos-license/ | |
| 40 // ------------------------------------------- | |
| 41 //####ECOSGPLCOPYRIGHTEND#### | |
| 42 //========================================================================== | |
| 43 //#####DESCRIPTIONBEGIN#### | |
| 44 // | |
| 45 // Author(s): gthomas | |
| 46 // Contributors: gthomas, Andrew Lunn | |
| 47 // Date: 2000-07-14 | |
| 48 // Purpose: | |
| 49 // Description: | |
| 50 // | |
| 51 //####DESCRIPTIONEND#### | |
| 52 // | |
| 53 //========================================================================== | |
| 54 #ifndef _IO_FLASH_PRIV_H_ | |
| 55 #define _IO_FLASH_PRIV_H_ | |
| 56 | |
|
1747
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1745
diff
changeset
|
57 #include <pkgconf/system.h> |
|
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1745
diff
changeset
|
58 #include <pkgconf/io_flash.h> |
| 1749 | 59 #include <cyg/hal/hal_cache.h> |
| 60 #include <cyg/hal/hal_tables.h> | |
|
1747
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1745
diff
changeset
|
61 |
| 1706 | 62 // Forward reference of the device structure |
| 63 struct cyg_flash_dev; | |
| 64 | |
| 65 // Structure of pointers to functions in the device driver | |
| 66 struct cyg_flash_dev_funs { | |
| 1752 | 67 int (*flash_init) (struct cyg_flash_dev *dev); |
| 68 size_t (*flash_query) (struct cyg_flash_dev *dev, | |
| 69 void * data, size_t len); | |
| 70 int (*flash_erase_block) (struct cyg_flash_dev *dev, | |
| 71 cyg_flashaddr_t block_base); | |
| 72 int (*flash_program) (struct cyg_flash_dev *dev, | |
| 73 cyg_flashaddr_t base, | |
| 74 const void* data, size_t len); | |
| 75 int (*flash_read) (struct cyg_flash_dev *dev, | |
| 76 const cyg_flashaddr_t base, | |
| 77 void* data, size_t len); | |
| 78 int (*flash_hwr_map_error) (struct cyg_flash_dev *dev, int err); | |
| 79 #ifdef CYGHWR_IO_FLASH_BLOCK_LOCKING | |
| 80 int (*flash_block_lock) (struct cyg_flash_dev *dev, | |
| 81 const cyg_flashaddr_t block_base); | |
| 82 int (*flash_block_unlock) (struct cyg_flash_dev *dev, | |
| 83 const cyg_flashaddr_t block_base); | |
| 84 #endif | |
| 1706 | 85 }; |
| 86 | |
|
1762
9c1d9e5039c2
Move dummy init/query/lock/unlock functions to the generic flash code,
bartv
parents:
1752
diff
changeset
|
87 // Dummy functions for some of the above operations, if a device does |
|
9c1d9e5039c2
Move dummy init/query/lock/unlock functions to the generic flash code,
bartv
parents:
1752
diff
changeset
|
88 // not support e.g. locking. |
|
9c1d9e5039c2
Move dummy init/query/lock/unlock functions to the generic flash code,
bartv
parents:
1752
diff
changeset
|
89 externC int cyg_flash_devfn_init_nop(struct cyg_flash_dev*); |
|
9c1d9e5039c2
Move dummy init/query/lock/unlock functions to the generic flash code,
bartv
parents:
1752
diff
changeset
|
90 externC size_t cyg_flash_devfn_query_nop(struct cyg_flash_dev*, void*, const size_t); |
|
9c1d9e5039c2
Move dummy init/query/lock/unlock functions to the generic flash code,
bartv
parents:
1752
diff
changeset
|
91 externC int cyg_flash_devfn_lock_nop(struct cyg_flash_dev*, const cyg_flashaddr_t); |
|
9c1d9e5039c2
Move dummy init/query/lock/unlock functions to the generic flash code,
bartv
parents:
1752
diff
changeset
|
92 externC int cyg_flash_devfn_unlock_nop(struct cyg_flash_dev*, const cyg_flashaddr_t); |
|
9c1d9e5039c2
Move dummy init/query/lock/unlock functions to the generic flash code,
bartv
parents:
1752
diff
changeset
|
93 |
|
9c1d9e5039c2
Move dummy init/query/lock/unlock functions to the generic flash code,
bartv
parents:
1752
diff
changeset
|
94 // Facilitate function calls between flash-resident code and .2ram |
|
9c1d9e5039c2
Move dummy init/query/lock/unlock functions to the generic flash code,
bartv
parents:
1752
diff
changeset
|
95 // functions. |
|
9c1d9e5039c2
Move dummy init/query/lock/unlock functions to the generic flash code,
bartv
parents:
1752
diff
changeset
|
96 externC void* cyg_flash_anonymizer(void*); |
|
9c1d9e5039c2
Move dummy init/query/lock/unlock functions to the generic flash code,
bartv
parents:
1752
diff
changeset
|
97 |
| 1706 | 98 // Structure each device places in the HAL table |
| 99 struct cyg_flash_dev { | |
| 1752 | 100 const struct cyg_flash_dev_funs *funs; // Function pointers |
| 101 cyg_uint32 flags; // Device characteristics | |
| 102 cyg_flashaddr_t start; // First address | |
| 103 cyg_flashaddr_t end; // Last address | |
| 104 cyg_uint32 num_block_infos; // Number of entries | |
| 105 const cyg_flash_block_info_t *block_info; // Info about one block size | |
| 1706 | 106 |
| 1752 | 107 const void *priv; // Devices private data |
| 1706 | 108 |
| 1752 | 109 // The following are only written to by the FLASH IO layer. |
| 110 cyg_flash_printf *pf; // Pointer to diagnostic printf | |
| 111 bool init; // Device has been initialised | |
| 1706 | 112 #ifdef CYGPKG_KERNEL |
| 1752 | 113 cyg_mutex_t mutex; // Mutex for thread safeness |
| 1706 | 114 #endif |
|
1747
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1745
diff
changeset
|
115 #if (CYGHWR_IO_FLASH_DEVICE > 1) |
| 1752 | 116 struct cyg_flash_dev *next; // Pointer to next device |
|
1747
a221170fac3d
Add an optimization for the common case of a single flash device
bartv
parents:
1745
diff
changeset
|
117 #endif |
| 1706 | 118 } CYG_HAL_TABLE_TYPE; |
| 119 | |
| 1752 | 120 #ifdef CYGHWR_IO_FLASH_BLOCK_LOCKING |
| 121 # define CYG_FLASH_FUNS(_funs_, _init_, _query_ , _erase_, _prog_ , _read_, _map_, _lock_, _unlock_) \ | |
| 122 struct cyg_flash_dev_funs _funs_ = \ | |
| 123 { \ | |
| 124 .flash_init = _init_, \ | |
| 125 .flash_query = _query_, \ | |
| 126 .flash_erase_block = _erase_, \ | |
| 127 .flash_program = _prog_, \ | |
| 128 .flash_read = _read_, \ | |
| 129 .flash_hwr_map_error = _map_, \ | |
| 130 .flash_block_lock = _lock_, \ | |
| 131 .flash_block_unlock = _unlock_ \ | |
| 132 } | |
| 133 #else | |
| 134 # define CYG_FLASH_FUNS(_funs_, _init_, _query_ , _erase_, _prog_ , _read_, _map_, _lock_, _unlock_) \ | |
| 135 struct cyg_flash_dev_funs _funs_ = \ | |
| 136 { \ | |
| 137 .flash_init = _init_, \ | |
| 138 .flash_query = _query_, \ | |
| 139 .flash_erase_block = _erase_, \ | |
| 140 .flash_program = _prog_, \ | |
| 141 .flash_read = _read_, \ | |
| 142 .flash_hwr_map_error = _map_ \ | |
| 143 } | |
| 144 #endif | |
| 1706 | 145 |
| 146 // We assume HAL tables are placed into RAM. | |
| 1752 | 147 #define CYG_FLASH_DRIVER(_name_, _funs_, _flags_, _start_, _end_, _num_block_infos_, _block_info_, _priv_) \ |
| 148 struct cyg_flash_dev _name_ CYG_HAL_TABLE_ENTRY(cyg_flashdev) = \ | |
| 149 { \ | |
| 150 .funs = _funs_, \ | |
| 151 .flags = _flags_, \ | |
| 152 .start = _start_, \ | |
| 153 .end = _end_, \ | |
| 154 .num_block_infos = _num_block_infos_, \ | |
| 155 .block_info = _block_info_, \ | |
| 156 .priv = _priv_ \ | |
| 157 } | |
| 1706 | 158 |
| 1745 | 159 #ifdef CYGHWR_IO_FLASH_DEVICE_LEGACY |
| 1706 | 160 struct flash_info { |
| 1752 | 161 int block_size; // Assuming fixed size "blocks" |
| 162 int blocks; // Number of blocks | |
| 163 int buffer_size; // Size of write buffer (only defined for some devices) | |
| 1706 | 164 unsigned long block_mask; |
| 165 void *start, *end; // Address range | |
| 1752 | 166 int init; |
| 1706 | 167 cyg_flash_printf *pf; |
| 168 }; | |
| 169 | |
| 170 externC struct flash_info flash_info; | |
| 1752 | 171 externC int flash_hwr_init(void); |
| 172 externC int flash_hwr_map_error(int err); | |
| 1706 | 173 externC void flash_dev_query(void *data); |
| 1745 | 174 #endif // CYGHWR_IO_FLASH_DEVICE_LEGACY |
| 1706 | 175 |
| 176 #endif // _IO_FLASH_PRIV_H_ |
