Mercurial > flash_v2
comparison packages/devs/flash/atmel/dataflash/current/include/dataflash.h @ 1738:0801d20c7256
* include/dataflash.h:
* src/devs_flash_atmel_dataflash.c:
Changed the API to be more consistent, included error
reporting and added blocking/non blocking mode of operation.
* src/devs_flash_atmel_dataflash_flash_dev_funs.c:
Synced with new API and set the block size to DataFlash's
native page size.
| author | asl |
|---|---|
| date | Thu, 07 Oct 2004 19:59:27 +0000 |
| parents | 1646bf44203c |
| children | a8729175ad24 |
comparison
equal
deleted
inserted
replaced
| 1737:dcf02dfe567d | 1738:0801d20c7256 |
|---|---|
| 54 #include <pkgconf/devs_flash_atmel_dataflash.h> | 54 #include <pkgconf/devs_flash_atmel_dataflash.h> |
| 55 | 55 |
| 56 #include <cyg/infra/cyg_type.h> | 56 #include <cyg/infra/cyg_type.h> |
| 57 #include <cyg/hal/drv_api.h> | 57 #include <cyg/hal/drv_api.h> |
| 58 #include <cyg/io/spi.h> | 58 #include <cyg/io/spi.h> |
| 59 | |
| 60 //---------------------------------------------------------------------------- | |
| 61 | |
| 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 }; | |
| 59 | 74 |
| 60 //---------------------------------------------------------------------------- | 75 //---------------------------------------------------------------------------- |
| 61 | 76 |
| 62 typedef struct cyg_dataflash_dev_info_s | 77 typedef struct cyg_dataflash_dev_info_s |
| 63 { | 78 { |
| 70 cyg_uint16 sector_count; // Total number of sectors | 85 cyg_uint16 sector_count; // Total number of sectors |
| 71 } cyg_dataflash_dev_info_t; | 86 } cyg_dataflash_dev_info_t; |
| 72 | 87 |
| 73 typedef struct cyg_dataflash_device_s | 88 typedef struct cyg_dataflash_device_s |
| 74 { | 89 { |
| 75 const cyg_dataflash_dev_info_t *info; // DataFlash device info | 90 const cyg_dataflash_dev_info_t *info; // DataFlash device info |
| 76 cyg_spi_device *spi_dev; // SPI device | 91 cyg_spi_device *spi_dev; // SPI device |
| 77 cyg_bool polled; // Polled mode flag | 92 cyg_drv_mutex_t lock; // Access lock |
| 78 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 | |
| 79 } cyg_dataflash_device_t; | 97 } cyg_dataflash_device_t; |
| 80 | 98 |
| 81 //---------------------------------------------------------------------------- | 99 //---------------------------------------------------------------------------- |
| 82 | 100 |
| 83 #ifdef _FLASH_PRIVATE_ | 101 #ifdef _FLASH_PRIVATE_ |
| 94 typedef struct cyg_dataflash_flash_dev_priv_s | 112 typedef struct cyg_dataflash_flash_dev_priv_s |
| 95 { | 113 { |
| 96 cyg_dataflash_device_t dev; // DataFlash device | 114 cyg_dataflash_device_t dev; // DataFlash device |
| 97 cyg_uint32 start_page; // Start page of flash driver space | 115 cyg_uint32 start_page; // Start page of flash driver space |
| 98 cyg_uint32 end_page; // End page of flash driver space | 116 cyg_uint32 end_page; // End page of flash driver space |
| 99 cyg_uint32 page_2size_log; // Page (2^n) size log | |
| 100 } cyg_dataflash_flash_dev_priv_t; | 117 } cyg_dataflash_flash_dev_priv_t; |
| 101 | 118 |
| 102 externC struct cyg_flash_dev_funs cyg_dataflash_flash_dev_funs; | 119 externC struct cyg_flash_dev_funs cyg_dataflash_flash_dev_funs; |
| 103 | 120 |
| 104 #define CYG_DATAFLASH_FLASH_DRIVER(name, _sdev, _addr, _start, _end) \ | 121 #define CYG_DATAFLASH_FLASH_DRIVER(name, _sdev, _addr, _start, _end) \ |
| 156 cyg_dataflash_set_polled_operation(cyg_dataflash_device_t *dev, cyg_bool polled) | 173 cyg_dataflash_set_polled_operation(cyg_dataflash_device_t *dev, cyg_bool polled) |
| 157 { | 174 { |
| 158 dev->polled = polled; | 175 dev->polled = polled; |
| 159 } | 176 } |
| 160 | 177 |
| 161 externC cyg_bool cyg_dataflash_init(cyg_spi_device *spi_dev, | 178 static inline void |
| 162 cyg_bool polled, | 179 cyg_dataflash_set_blocking_operation(cyg_dataflash_device_t *dev, cyg_bool block) |
| 163 cyg_dataflash_device_t *dev); | 180 { |
| 164 | 181 dev->blocking = block; |
| 165 externC void cyg_dataflash_aquire(cyg_dataflash_device_t *dev); | 182 } |
| 166 | 183 |
| 167 externC void cyg_dataflash_release(cyg_dataflash_device_t *dev); | 184 //---------------------------------------------------------------------------- |
| 185 | |
| 186 externC int cyg_dataflash_init(cyg_spi_device *spi_dev, | |
| 187 cyg_bool polled, | |
| 188 cyg_dataflash_device_t *dev); | |
| 189 | |
| 190 externC int cyg_dataflash_aquire(cyg_dataflash_device_t *dev); | |
| 191 | |
| 192 externC int cyg_dataflash_release(cyg_dataflash_device_t *dev); | |
| 168 | 193 |
| 169 externC cyg_uint16 cyg_dataflash_get_sector_start(cyg_dataflash_device_t *dev, | 194 externC cyg_uint16 cyg_dataflash_get_sector_start(cyg_dataflash_device_t *dev, |
| 170 cyg_uint16 sector_num); | 195 cyg_uint16 sector_num); |
| 171 | 196 |
| 172 externC void cyg_dataflash_read_buf(cyg_dataflash_device_t *dev, | 197 externC int cyg_dataflash_wait_ready(cyg_dataflash_device_t *dev); |
| 198 | |
| 199 externC int cyg_dataflash_read_buf(cyg_dataflash_device_t *dev, | |
| 200 cyg_uint8 buf_num, | |
| 201 cyg_uint8 *buf, | |
| 202 cyg_uint32 len, | |
| 203 cyg_uint32 pos); | |
| 204 | |
| 205 externC int cyg_dataflash_write_buf(cyg_dataflash_device_t *dev, | |
| 173 cyg_uint8 buf_num, | 206 cyg_uint8 buf_num, |
| 174 cyg_uint8 *buf, | 207 const cyg_uint8 *buf, |
| 175 cyg_uint32 len, | 208 cyg_uint32 len, |
| 176 cyg_uint32 pos); | 209 cyg_uint32 pos); |
| 177 | 210 |
| 178 externC void cyg_dataflash_write_buf(cyg_dataflash_device_t *dev, | 211 externC int cyg_dataflash_mem_to_buf(cyg_dataflash_device_t *dev, |
| 179 cyg_uint8 buf_num, | 212 cyg_uint8 buf_num, |
| 180 const cyg_uint8 *buf, | 213 cyg_uint32 page_num); |
| 181 cyg_uint32 len, | 214 |
| 182 cyg_uint32 pos); | 215 externC int cyg_dataflash_program_buf(cyg_dataflash_device_t *dev, |
| 183 | |
| 184 externC void cyg_dataflash_mem_to_buf(cyg_dataflash_device_t *dev, | |
| 185 cyg_uint8 buf_num, | 216 cyg_uint8 buf_num, |
| 186 cyg_uint32 page_num, | 217 cyg_uint32 page_num, |
| 187 cyg_bool wait); | 218 cyg_bool erase); |
| 188 | 219 |
| 189 externC void cyg_dataflash_program_buf(cyg_dataflash_device_t *dev, | 220 externC int cyg_dataflash_compare_buf(cyg_dataflash_device_t *dev, |
| 221 cyg_uint8 buf_num, | |
| 222 cyg_uint32 page_num); | |
| 223 | |
| 224 externC int cyg_dataflash_erase(cyg_dataflash_device_t *dev, | |
| 225 cyg_uint32 page_num); | |
| 226 | |
| 227 externC int cyg_dataflash_erase_block(cyg_dataflash_device_t *dev, | |
| 228 cyg_uint32 block_num); | |
| 229 | |
| 230 externC int cyg_dataflash_auto_rewrite(cyg_dataflash_device_t *dev, | |
| 190 cyg_uint8 buf_num, | 231 cyg_uint8 buf_num, |
| 191 cyg_uint32 page_num, | 232 cyg_uint32 page_num); |
| 192 cyg_bool erase, | 233 |
| 193 cyg_bool wait); | 234 externC int cyg_dataflash_read(cyg_dataflash_device_t *dev, |
| 194 | 235 cyg_uint8 *buf, |
| 195 externC cyg_bool cyg_dataflash_compare_buf(cyg_dataflash_device_t *dev, | 236 cyg_uint32 len, |
| 196 cyg_uint8 buf_num, | 237 cyg_uint32 pos); |
| 197 cyg_uint32 page_num); | 238 |
| 198 | 239 externC int cyg_dataflash_program(cyg_dataflash_device_t *dev, |
| 199 externC void cyg_dataflash_erase(cyg_dataflash_device_t *dev, | 240 const cyg_uint8 *buf, |
| 200 cyg_uint32 page_num, | 241 cyg_uint32 *len, |
| 201 cyg_bool wait); | 242 cyg_uint32 pos, |
| 202 | 243 cyg_bool erase, |
| 203 externC void cyg_dataflash_erase_block(cyg_dataflash_device_t *dev, | 244 cyg_bool verify); |
| 204 cyg_uint32 block_num, | |
| 205 cyg_bool wait); | |
| 206 | |
| 207 externC void cyg_dataflash_auto_rewrite(cyg_dataflash_device_t *dev, | |
| 208 cyg_uint8 buf_num, | |
| 209 cyg_uint32 page_num, | |
| 210 cyg_bool wait); | |
| 211 | |
| 212 externC void cyg_dataflash_read(cyg_dataflash_device_t *dev, | |
| 213 cyg_uint8 *buf, | |
| 214 cyg_uint32 len, | |
| 215 cyg_uint32 pos); | |
| 216 | |
| 217 externC cyg_bool cyg_dataflash_program(cyg_dataflash_device_t *dev, | |
| 218 const cyg_uint8 *buf, | |
| 219 cyg_uint32 *len, | |
| 220 cyg_uint32 pos, | |
| 221 cyg_bool erase, | |
| 222 cyg_bool verify); | |
| 223 | 245 |
| 224 //---------------------------------------------------------------------------- | 246 //---------------------------------------------------------------------------- |
| 225 | 247 |
| 226 #endif // CYGONCE_DATAFLASH_H | 248 #endif // CYGONCE_DATAFLASH_H |
| 227 | 249 |
