Mercurial > flash_v2
comparison packages/devs/flash/atmel/dataflash/current/include/dataflash.h @ 1732:1646bf44203c
* cdl/devs_flash_atmel_dataflash.cdl:
* include/dataflash.h:
* src/devs_flash_atmel_dataflash.c:
* src/devs_flash_atmel_dataflash_flash_dev_funs.c:
Atmel DataFlash driver implementation.
| author | asl |
|---|---|
| date | Tue, 05 Oct 2004 09:19:15 +0000 |
| parents | |
| children | 0801d20c7256 |
comparison
equal
deleted
inserted
replaced
| 1731:a24c2d6d8afa | 1732:1646bf44203c |
|---|---|
| 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 | |
| 62 typedef struct cyg_dataflash_dev_info_s | |
| 63 { | |
| 64 cyg_uint8 device_id; // Device ID | |
| 65 cyg_uint16 page_size; // Page size in bytes | |
| 66 cyg_uint16 page_count; // Total number of pages | |
| 67 cyg_uint8 baddr_bits; // Bits used for byte address in addressing seq | |
| 68 cyg_uint16 block_size; // Block size in pages | |
| 69 cyg_uint16 sector_sizes[64]; // Sector sizes in blocks | |
| 70 cyg_uint16 sector_count; // Total number of sectors | |
| 71 } cyg_dataflash_dev_info_t; | |
| 72 | |
| 73 typedef struct cyg_dataflash_device_s | |
| 74 { | |
| 75 const cyg_dataflash_dev_info_t *info; // DataFlash device info | |
| 76 cyg_spi_device *spi_dev; // SPI device | |
| 77 cyg_bool polled; // Polled mode flag | |
| 78 cyg_drv_mutex_t lock; // Access lock | |
| 79 } cyg_dataflash_device_t; | |
| 80 | |
| 81 //---------------------------------------------------------------------------- | |
| 82 | |
| 83 #ifdef _FLASH_PRIVATE_ | |
| 84 #include <cyg/io/flash.h> | |
| 85 | |
| 86 typedef struct cyg_dataflash_flash_dev_config_s | |
| 87 { | |
| 88 cyg_spi_device **spi_dev; // SPI device | |
| 89 cyg_uint32 address; // Memory address (flash driver) | |
| 90 cyg_int16 start_sector; // Start sector of flash driver space | |
| 91 cyg_int16 end_sector; // End sector of flash driver space | |
| 92 } cyg_dataflash_flash_dev_config_t; | |
| 93 | |
| 94 typedef struct cyg_dataflash_flash_dev_priv_s | |
| 95 { | |
| 96 cyg_dataflash_device_t dev; // DataFlash device | |
| 97 cyg_uint32 start_page; // Start page of flash driver space | |
| 98 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; | |
| 101 | |
| 102 externC struct cyg_flash_dev_funs cyg_dataflash_flash_dev_funs; | |
| 103 | |
| 104 #define CYG_DATAFLASH_FLASH_DRIVER(name, _sdev, _addr, _start, _end) \ | |
| 105 static cyg_dataflash_flash_dev_config_t config_ ## name = { \ | |
| 106 .spi_dev = &_sdev, \ | |
| 107 .address = _addr, \ | |
| 108 .start_sector = _start, \ | |
| 109 .end_sector = _end \ | |
| 110 }; \ | |
| 111 CYG_FLASH_DRIVER(name, &cyg_dataflash_flash_dev_funs, \ | |
| 112 &config_ ## name, 0, \ | |
| 113 sizeof(cyg_dataflash_flash_dev_priv_t)) | |
| 114 | |
| 115 #endif // _FLASH_PRIVATE_ | |
| 116 | |
| 117 //---------------------------------------------------------------------------- | |
| 118 | |
| 119 static inline cyg_uint8 | |
| 120 cyg_dataflash_get_device_id(cyg_dataflash_device_t *dev) | |
| 121 { | |
| 122 return dev->info->device_id; | |
| 123 } | |
| 124 | |
| 125 static inline cyg_uint16 | |
| 126 cyg_dataflash_get_page_size(cyg_dataflash_device_t *dev) | |
| 127 { | |
| 128 return dev->info->page_size; | |
| 129 } | |
| 130 | |
| 131 static inline cyg_uint16 | |
| 132 cyg_dataflash_get_page_count(cyg_dataflash_device_t *dev) | |
| 133 { | |
| 134 return dev->info->page_size; | |
| 135 } | |
| 136 | |
| 137 static inline cyg_uint16 | |
| 138 cyg_dataflash_get_block_size(cyg_dataflash_device_t *dev) | |
| 139 { | |
| 140 return dev->info->block_size; | |
| 141 } | |
| 142 | |
| 143 static inline cyg_uint16 | |
| 144 cyg_dataflash_get_sector_size(cyg_dataflash_device_t *dev, cyg_uint8 sector_num) | |
| 145 { | |
| 146 return dev->info->sector_sizes[sector_num]; | |
| 147 } | |
| 148 | |
| 149 static inline cyg_uint16 | |
| 150 cyg_dataflash_get_sector_count(cyg_dataflash_device_t *dev) | |
| 151 { | |
| 152 return dev->info->sector_count; | |
| 153 } | |
| 154 | |
| 155 static inline void | |
| 156 cyg_dataflash_set_polled_operation(cyg_dataflash_device_t *dev, cyg_bool polled) | |
| 157 { | |
| 158 dev->polled = polled; | |
| 159 } | |
| 160 | |
| 161 externC cyg_bool cyg_dataflash_init(cyg_spi_device *spi_dev, | |
| 162 cyg_bool polled, | |
| 163 cyg_dataflash_device_t *dev); | |
| 164 | |
| 165 externC void cyg_dataflash_aquire(cyg_dataflash_device_t *dev); | |
| 166 | |
| 167 externC void cyg_dataflash_release(cyg_dataflash_device_t *dev); | |
| 168 | |
| 169 externC cyg_uint16 cyg_dataflash_get_sector_start(cyg_dataflash_device_t *dev, | |
| 170 cyg_uint16 sector_num); | |
| 171 | |
| 172 externC void cyg_dataflash_read_buf(cyg_dataflash_device_t *dev, | |
| 173 cyg_uint8 buf_num, | |
| 174 cyg_uint8 *buf, | |
| 175 cyg_uint32 len, | |
| 176 cyg_uint32 pos); | |
| 177 | |
| 178 externC void cyg_dataflash_write_buf(cyg_dataflash_device_t *dev, | |
| 179 cyg_uint8 buf_num, | |
| 180 const cyg_uint8 *buf, | |
| 181 cyg_uint32 len, | |
| 182 cyg_uint32 pos); | |
| 183 | |
| 184 externC void cyg_dataflash_mem_to_buf(cyg_dataflash_device_t *dev, | |
| 185 cyg_uint8 buf_num, | |
| 186 cyg_uint32 page_num, | |
| 187 cyg_bool wait); | |
| 188 | |
| 189 externC void cyg_dataflash_program_buf(cyg_dataflash_device_t *dev, | |
| 190 cyg_uint8 buf_num, | |
| 191 cyg_uint32 page_num, | |
| 192 cyg_bool erase, | |
| 193 cyg_bool wait); | |
| 194 | |
| 195 externC cyg_bool cyg_dataflash_compare_buf(cyg_dataflash_device_t *dev, | |
| 196 cyg_uint8 buf_num, | |
| 197 cyg_uint32 page_num); | |
| 198 | |
| 199 externC void cyg_dataflash_erase(cyg_dataflash_device_t *dev, | |
| 200 cyg_uint32 page_num, | |
| 201 cyg_bool wait); | |
| 202 | |
| 203 externC void cyg_dataflash_erase_block(cyg_dataflash_device_t *dev, | |
| 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 | |
| 224 //---------------------------------------------------------------------------- | |
| 225 | |
| 226 #endif // CYGONCE_DATAFLASH_H | |
| 227 | |
| 228 //---------------------------------------------------------------------------- | |
| 229 // End of dataflash.h |
