|
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 //---------------------------------------------------------------------------- |
|
|
100 |
|
|
101 #ifdef _FLASH_PRIVATE_ |
|
|
102 #include <cyg/io/flash.h> |
|
|
103 |
|
|
104 typedef struct cyg_dataflash_flash_dev_config_s |
|
|
105 { |
|
|
106 cyg_spi_device **spi_dev; // SPI device |
|
|
107 cyg_uint32 address; // Memory address (flash driver) |
|
|
108 cyg_int16 start_sector; // Start sector of flash driver space |
|
|
109 cyg_int16 end_sector; // End sector of flash driver space |
|
|
110 } cyg_dataflash_flash_dev_config_t; |
|
|
111 |
|
|
112 typedef struct cyg_dataflash_flash_dev_priv_s |
|
|
113 { |
|
|
114 cyg_dataflash_device_t dev; // DataFlash device |
|
|
115 cyg_uint32 start_page; // Start page of flash driver space |
|
|
116 cyg_uint32 end_page; // End page of flash driver space |
|
|
117 } cyg_dataflash_flash_dev_priv_t; |
|
|
118 |
|
|
119 externC struct cyg_flash_dev_funs cyg_dataflash_flash_dev_funs; |
|
|
120 |
|
|
121 #define CYG_DATAFLASH_FLASH_DRIVER(name, _sdev, _addr, _start, _end) \ |
|
|
122 static cyg_dataflash_flash_dev_config_t config_ ## name = { \ |
|
|
123 .spi_dev = &_sdev, \ |
|
|
124 .address = _addr, \ |
|
|
125 .start_sector = _start, \ |
|
|
126 .end_sector = _end \ |
|
|
127 }; \ |
|
|
128 CYG_FLASH_DRIVER(name, &cyg_dataflash_flash_dev_funs, \ |
|
|
129 &config_ ## name, 0, \ |
|
|
130 sizeof(cyg_dataflash_flash_dev_priv_t)) |
|
|
131 |
|
|
132 #endif // _FLASH_PRIVATE_ |
|
|
133 |
|
|
134 //---------------------------------------------------------------------------- |
|
|
135 |
|
|
136 static inline cyg_uint8 |
|
|
137 cyg_dataflash_get_device_id(cyg_dataflash_device_t *dev) |
|
|
138 { |
|
|
139 return dev->info->device_id; |
|
|
140 } |
|
|
141 |
|
|
142 static inline cyg_uint16 |
|
|
143 cyg_dataflash_get_page_size(cyg_dataflash_device_t *dev) |
|
|
144 { |
|
|
145 return dev->info->page_size; |
|
|
146 } |
|
|
147 |
|
|
148 static inline cyg_uint16 |
|
|
149 cyg_dataflash_get_page_count(cyg_dataflash_device_t *dev) |
|
|
150 { |
|
|
151 return dev->info->page_size; |
|
|
152 } |
|
|
153 |
|
|
154 static inline cyg_uint16 |
|
|
155 cyg_dataflash_get_block_size(cyg_dataflash_device_t *dev) |
|
|
156 { |
|
|
157 return dev->info->block_size; |
|
|
158 } |
|
|
159 |
|
|
160 static inline cyg_uint16 |
|
|
161 cyg_dataflash_get_sector_size(cyg_dataflash_device_t *dev, cyg_uint8 sector_num) |
|
|
162 { |
|
|
163 return dev->info->sector_sizes[sector_num]; |
|
|
164 } |
|
|
165 |
|
|
166 static inline cyg_uint16 |
|
|
167 cyg_dataflash_get_sector_count(cyg_dataflash_device_t *dev) |
|
|
168 { |
|
|
169 return dev->info->sector_count; |
|
|
170 } |
|
|
171 |
|
|
172 static inline void |
|
|
173 cyg_dataflash_set_polled_operation(cyg_dataflash_device_t *dev, cyg_bool polled) |
|
|
174 { |
|
|
175 dev->polled = polled; |
|
|
176 } |
|
|
177 |
|
1738
|
178 static inline void |
|
|
179 cyg_dataflash_set_blocking_operation(cyg_dataflash_device_t *dev, cyg_bool block) |
|
|
180 { |
|
|
181 dev->blocking = block; |
|
|
182 } |
|
|
183 |
|
|
184 //---------------------------------------------------------------------------- |
|
1732
|
185 |
|
1738
|
186 externC int cyg_dataflash_init(cyg_spi_device *spi_dev, |
|
|
187 cyg_bool polled, |
|
|
188 cyg_dataflash_device_t *dev); |
|
1732
|
189 |
|
1738
|
190 externC int cyg_dataflash_aquire(cyg_dataflash_device_t *dev); |
|
|
191 |
|
|
192 externC int cyg_dataflash_release(cyg_dataflash_device_t *dev); |
|
1732
|
193 |
|
|
194 externC cyg_uint16 cyg_dataflash_get_sector_start(cyg_dataflash_device_t *dev, |
|
|
195 cyg_uint16 sector_num); |
|
|
196 |
|
1738
|
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); |
|
1732
|
204 |
|
1738
|
205 externC int cyg_dataflash_write_buf(cyg_dataflash_device_t *dev, |
|
|
206 cyg_uint8 buf_num, |
|
|
207 const cyg_uint8 *buf, |
|
|
208 cyg_uint32 len, |
|
|
209 cyg_uint32 pos); |
|
|
210 |
|
|
211 externC int cyg_dataflash_mem_to_buf(cyg_dataflash_device_t *dev, |
|
1732
|
212 cyg_uint8 buf_num, |
|
1738
|
213 cyg_uint32 page_num); |
|
1732
|
214 |
|
1738
|
215 externC int cyg_dataflash_program_buf(cyg_dataflash_device_t *dev, |
|
1732
|
216 cyg_uint8 buf_num, |
|
|
217 cyg_uint32 page_num, |
|
1738
|
218 cyg_bool erase); |
|
1732
|
219 |
|
1738
|
220 externC int cyg_dataflash_compare_buf(cyg_dataflash_device_t *dev, |
|
|
221 cyg_uint8 buf_num, |
|
|
222 cyg_uint32 page_num); |
|
1732
|
223 |
|
1738
|
224 externC int cyg_dataflash_erase(cyg_dataflash_device_t *dev, |
|
|
225 cyg_uint32 page_num); |
|
1732
|
226 |
|
1738
|
227 externC int cyg_dataflash_erase_block(cyg_dataflash_device_t *dev, |
|
|
228 cyg_uint32 block_num); |
|
1732
|
229 |
|
1738
|
230 externC int cyg_dataflash_auto_rewrite(cyg_dataflash_device_t *dev, |
|
|
231 cyg_uint8 buf_num, |
|
|
232 cyg_uint32 page_num); |
|
1732
|
233 |
|
1738
|
234 externC int cyg_dataflash_read(cyg_dataflash_device_t *dev, |
|
|
235 cyg_uint8 *buf, |
|
|
236 cyg_uint32 len, |
|
|
237 cyg_uint32 pos); |
|
1732
|
238 |
|
1738
|
239 externC int cyg_dataflash_program(cyg_dataflash_device_t *dev, |
|
|
240 const cyg_uint8 *buf, |
|
|
241 cyg_uint32 *len, |
|
|
242 cyg_uint32 pos, |
|
|
243 cyg_bool erase, |
|
|
244 cyg_bool verify); |
|
1732
|
245 |
|
|
246 //---------------------------------------------------------------------------- |
|
|
247 |
|
|
248 #endif // CYGONCE_DATAFLASH_H |
|
|
249 |
|
|
250 //---------------------------------------------------------------------------- |
|
|
251 // End of dataflash.h |