Mercurial > flash_v2
annotate packages/devs/flash/atmel/dataflash/current/include/dataflash.h @ 1768:ef75ad79dfe3
* include/dataflash.h: Allow the package to be compiled without
io/flash. Return correct value from cyg_dataflash_get_page_count()
| author | asl |
|---|---|
| date | Wed, 29 Jun 2005 20:12:42 +0000 |
| parents | 96ec7e534d98 |
| children |
| rev | line source |
|---|---|
| 1732 | 1 #ifndef CYGONCE_DATAFLASH_H |
| 2 #define CYGONCE_DATAFLASH_H | |
| 3 //========================================================================== | |
| 4 // | |
| 5 // dataflash.h | |
| 6 // | |
| 7 // DataFlash series flash driver defines | |
| 8 // | |
| 9 //========================================================================== | |
| 10 //####ECOSGPLCOPYRIGHTBEGIN#### | |
| 11 // ------------------------------------------- | |
| 12 // This file is part of eCos, the Embedded Configurable Operating System. | |
| 13 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. | |
| 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 //========================================================================== | |
| 44 //#####DESCRIPTIONBEGIN#### | |
| 45 // | |
| 46 // Author(s): Savin Zlobec <savin@elatec.si> | |
| 47 // Date: 2004-08-27 | |
| 48 // | |
| 49 //####DESCRIPTIONEND#### | |
| 50 // | |
| 51 //========================================================================== | |
| 52 | |
| 53 #include <pkgconf/hal.h> | |
| 54 #include <pkgconf/devs_flash_atmel_dataflash.h> | |
| 55 | |
| 56 #include <cyg/infra/cyg_type.h> | |
| 57 #include <cyg/hal/drv_api.h> | |
| 58 #include <cyg/io/spi.h> | |
| 59 | |
| 60 //---------------------------------------------------------------------------- | |
| 61 | |
| 1738 | 62 enum { |
| 63 CYG_DATAFLASH_ERR_OK = 0, // No error | |
| 64 CYG_DATAFLASH_ERR_INVALID = 1, // Invalid address error | |
| 65 CYG_DATAFLASH_ERR_WRONG_PART = 2, // Unsupported device error | |
| 66 CYG_DATAFLASH_ERR_TIMEOUT = 3, // Operation timeout error | |
| 67 CYG_DATAFLASH_ERR_COMPARE = 4 // Buffer - main memory compare error | |
| 68 }; | |
| 69 | |
| 70 enum { | |
| 71 CYG_DATAFLASH_STATE_IDLE = 0, | |
| 72 CYG_DATAFLASH_STATE_BUSY = 1 | |
| 73 }; | |
| 74 | |
| 75 //---------------------------------------------------------------------------- | |
| 76 | |
| 1732 | 77 typedef struct cyg_dataflash_dev_info_s |
| 78 { | |
| 79 cyg_uint8 device_id; // Device ID | |
| 80 cyg_uint16 page_size; // Page size in bytes | |
| 81 cyg_uint16 page_count; // Total number of pages | |
| 82 cyg_uint8 baddr_bits; // Bits used for byte address in addressing seq | |
| 83 cyg_uint16 block_size; // Block size in pages | |
| 84 cyg_uint16 sector_sizes[64]; // Sector sizes in blocks | |
| 85 cyg_uint16 sector_count; // Total number of sectors | |
| 86 } cyg_dataflash_dev_info_t; | |
| 87 | |
| 88 typedef struct cyg_dataflash_device_s | |
| 89 { | |
| 1738 | 90 const cyg_dataflash_dev_info_t *info; // DataFlash device info |
| 91 cyg_spi_device *spi_dev; // SPI device | |
| 92 cyg_drv_mutex_t lock; // Access lock | |
| 93 cyg_bool polled; // Polled mode flag | |
| 94 cyg_bool blocking; // Blocking mode flag | |
| 95 int state; // Current state (IDLE, BUSY, ...) | |
| 96 cyg_uint8 busy_buf; // Current busy buffer number | |
| 1732 | 97 } cyg_dataflash_device_t; |
| 98 | |
| 99 //---------------------------------------------------------------------------- | |
|
1768
ef75ad79dfe3
* include/dataflash.h: Allow the package to be compiled without
asl
parents:
1764
diff
changeset
|
100 #ifdef CYGPKG_IO_FLASH |
| 1732 | 101 #include <cyg/io/flash.h> |
|
1764
96ec7e534d98
V2 flash header files clean-up. Eliminate flash_priv.h, moving the
bartv
parents:
1757
diff
changeset
|
102 #include <cyg/io/flash_dev.h> |
| 1732 | 103 |
| 104 typedef struct cyg_dataflash_flash_dev_priv_s | |
| 105 { | |
|
1757
a8729175ad24
Update dataflash driver as per changes to the generic flash code
bartv
parents:
1738
diff
changeset
|
106 cyg_int16 start_sector; // Start sector of flash driver space |
|
a8729175ad24
Update dataflash driver as per changes to the generic flash code
bartv
parents:
1738
diff
changeset
|
107 cyg_int16 end_sector; // End sector of flash driver space |
|
a8729175ad24
Update dataflash driver as per changes to the generic flash code
bartv
parents:
1738
diff
changeset
|
108 cyg_dataflash_device_t dev; // DataFlash device |
|
a8729175ad24
Update dataflash driver as per changes to the generic flash code
bartv
parents:
1738
diff
changeset
|
109 cyg_uint32 start_page; // Start page of flash driver space |
|
a8729175ad24
Update dataflash driver as per changes to the generic flash code
bartv
parents:
1738
diff
changeset
|
110 cyg_uint32 end_page; // End page of flash driver space |
|
a8729175ad24
Update dataflash driver as per changes to the generic flash code
bartv
parents:
1738
diff
changeset
|
111 cyg_flash_block_info_t block_info[1]; |
| 1732 | 112 } cyg_dataflash_flash_dev_priv_t; |
| 113 | |
| 114 externC struct cyg_flash_dev_funs cyg_dataflash_flash_dev_funs; | |
| 115 | |
|
1757
a8729175ad24
Update dataflash driver as per changes to the generic flash code
bartv
parents:
1738
diff
changeset
|
116 #define CYG_DATAFLASH_FLASH_DRIVER(name, _sdev, _addr, _start, _end) \ |
|
a8729175ad24
Update dataflash driver as per changes to the generic flash code
bartv
parents:
1738
diff
changeset
|
117 static cyg_dataflash_flash_dev_priv_t cyg_dataflash_priv_ ## name = { \ |
|
a8729175ad24
Update dataflash driver as per changes to the generic flash code
bartv
parents:
1738
diff
changeset
|
118 .start_sector = _start, \ |
|
a8729175ad24
Update dataflash driver as per changes to the generic flash code
bartv
parents:
1738
diff
changeset
|
119 .end_sector = _end, \ |
|
a8729175ad24
Update dataflash driver as per changes to the generic flash code
bartv
parents:
1738
diff
changeset
|
120 .dev.spi_dev = _sdev, \ |
|
a8729175ad24
Update dataflash driver as per changes to the generic flash code
bartv
parents:
1738
diff
changeset
|
121 }; \ |
|
a8729175ad24
Update dataflash driver as per changes to the generic flash code
bartv
parents:
1738
diff
changeset
|
122 CYG_FLASH_DRIVER(name, \ |
|
a8729175ad24
Update dataflash driver as per changes to the generic flash code
bartv
parents:
1738
diff
changeset
|
123 &cyg_dataflash_flash_dev_funs, \ |
|
a8729175ad24
Update dataflash driver as per changes to the generic flash code
bartv
parents:
1738
diff
changeset
|
124 0, \ |
|
a8729175ad24
Update dataflash driver as per changes to the generic flash code
bartv
parents:
1738
diff
changeset
|
125 _addr, \ |
|
a8729175ad24
Update dataflash driver as per changes to the generic flash code
bartv
parents:
1738
diff
changeset
|
126 0, \ |
|
a8729175ad24
Update dataflash driver as per changes to the generic flash code
bartv
parents:
1738
diff
changeset
|
127 1, \ |
|
a8729175ad24
Update dataflash driver as per changes to the generic flash code
bartv
parents:
1738
diff
changeset
|
128 cyg_dataflash_priv_ ## name.block_info, \ |
|
a8729175ad24
Update dataflash driver as per changes to the generic flash code
bartv
parents:
1738
diff
changeset
|
129 & cyg_dataflash_priv_ ## name \ |
|
a8729175ad24
Update dataflash driver as per changes to the generic flash code
bartv
parents:
1738
diff
changeset
|
130 ) |
| 1732 | 131 |
|
1768
ef75ad79dfe3
* include/dataflash.h: Allow the package to be compiled without
asl
parents:
1764
diff
changeset
|
132 #endif |
| 1732 | 133 //---------------------------------------------------------------------------- |
| 134 | |
| 135 static inline cyg_uint8 | |
| 136 cyg_dataflash_get_device_id(cyg_dataflash_device_t *dev) | |
| 137 { | |
| 138 return dev->info->device_id; | |
| 139 } | |
| 140 | |
| 141 static inline cyg_uint16 | |
| 142 cyg_dataflash_get_page_size(cyg_dataflash_device_t *dev) | |
| 143 { | |
| 144 return dev->info->page_size; | |
| 145 } | |
| 146 | |
| 147 static inline cyg_uint16 | |
| 148 cyg_dataflash_get_page_count(cyg_dataflash_device_t *dev) | |
| 149 { | |
|
1768
ef75ad79dfe3
* include/dataflash.h: Allow the package to be compiled without
asl
parents:
1764
diff
changeset
|
150 return dev->info->page_count; |
| 1732 | 151 } |
| 152 | |
| 153 static inline cyg_uint16 | |
| 154 cyg_dataflash_get_block_size(cyg_dataflash_device_t *dev) | |
| 155 { | |
| 156 return dev->info->block_size; | |
| 157 } | |
| 158 | |
| 159 static inline cyg_uint16 | |
| 160 cyg_dataflash_get_sector_size(cyg_dataflash_device_t *dev, cyg_uint8 sector_num) | |
| 161 { | |
| 162 return dev->info->sector_sizes[sector_num]; | |
| 163 } | |
| 164 | |
| 165 static inline cyg_uint16 | |
| 166 cyg_dataflash_get_sector_count(cyg_dataflash_device_t *dev) | |
| 167 { | |
| 168 return dev->info->sector_count; | |
| 169 } | |
| 170 | |
| 171 static inline void | |
| 172 cyg_dataflash_set_polled_operation(cyg_dataflash_device_t *dev, cyg_bool polled) | |
| 173 { | |
| 174 dev->polled = polled; | |
| 175 } | |
| 176 | |
| 1738 | 177 static inline void |
| 178 cyg_dataflash_set_blocking_operation(cyg_dataflash_device_t *dev, cyg_bool block) | |
| 179 { | |
| 180 dev->blocking = block; | |
| 181 } | |
| 182 | |
| 183 //---------------------------------------------------------------------------- | |
| 1732 | 184 |
|
1757
a8729175ad24
Update dataflash driver as per changes to the generic flash code
bartv
parents:
1738
diff
changeset
|
185 externC int cyg_dataflash_init(cyg_bool polled, |
| 1738 | 186 cyg_dataflash_device_t *dev); |
| 1732 | 187 |
| 1738 | 188 externC int cyg_dataflash_aquire(cyg_dataflash_device_t *dev); |
| 189 | |
| 190 externC int cyg_dataflash_release(cyg_dataflash_device_t *dev); | |
| 1732 | 191 |
| 192 externC cyg_uint16 cyg_dataflash_get_sector_start(cyg_dataflash_device_t *dev, | |
| 193 cyg_uint16 sector_num); | |
| 194 | |
| 1738 | 195 externC int cyg_dataflash_wait_ready(cyg_dataflash_device_t *dev); |
| 196 | |
| 197 externC int cyg_dataflash_read_buf(cyg_dataflash_device_t *dev, | |
| 198 cyg_uint8 buf_num, | |
| 199 cyg_uint8 *buf, | |
| 200 cyg_uint32 len, | |
| 201 cyg_uint32 pos); | |
| 1732 | 202 |
| 1738 | 203 externC int cyg_dataflash_write_buf(cyg_dataflash_device_t *dev, |
| 204 cyg_uint8 buf_num, | |
| 205 const cyg_uint8 *buf, | |
| 206 cyg_uint32 len, | |
| 207 cyg_uint32 pos); | |
| 208 | |
| 209 externC int cyg_dataflash_mem_to_buf(cyg_dataflash_device_t *dev, | |
| 1732 | 210 cyg_uint8 buf_num, |
| 1738 | 211 cyg_uint32 page_num); |
| 1732 | 212 |
| 1738 | 213 externC int cyg_dataflash_program_buf(cyg_dataflash_device_t *dev, |
| 1732 | 214 cyg_uint8 buf_num, |
| 215 cyg_uint32 page_num, | |
| 1738 | 216 cyg_bool erase); |
| 1732 | 217 |
| 1738 | 218 externC int cyg_dataflash_compare_buf(cyg_dataflash_device_t *dev, |
| 219 cyg_uint8 buf_num, | |
| 220 cyg_uint32 page_num); | |
| 1732 | 221 |
| 1738 | 222 externC int cyg_dataflash_erase(cyg_dataflash_device_t *dev, |
| 223 cyg_uint32 page_num); | |
| 1732 | 224 |
| 1738 | 225 externC int cyg_dataflash_erase_block(cyg_dataflash_device_t *dev, |
| 226 cyg_uint32 block_num); | |
| 1732 | 227 |
| 1738 | 228 externC int cyg_dataflash_auto_rewrite(cyg_dataflash_device_t *dev, |
| 229 cyg_uint8 buf_num, | |
| 230 cyg_uint32 page_num); | |
| 1732 | 231 |
| 1738 | 232 externC int cyg_dataflash_read(cyg_dataflash_device_t *dev, |
| 233 cyg_uint8 *buf, | |
| 234 cyg_uint32 len, | |
| 235 cyg_uint32 pos); | |
| 1732 | 236 |
| 1738 | 237 externC int cyg_dataflash_program(cyg_dataflash_device_t *dev, |
| 238 const cyg_uint8 *buf, | |
| 239 cyg_uint32 *len, | |
| 240 cyg_uint32 pos, | |
| 241 cyg_bool erase, | |
| 242 cyg_bool verify); | |
| 1732 | 243 |
| 244 //---------------------------------------------------------------------------- | |
| 245 | |
| 246 #endif // CYGONCE_DATAFLASH_H | |
| 247 | |
| 248 //---------------------------------------------------------------------------- | |
| 249 // End of dataflash.h |
