source: arduino-1-6-7/trunk/fuentes/arduino-ide-amd64/hardware/arduino/avr/firmwares/wifishield/wifi_dnld/src/SOFTWARE_FRAMEWORK/COMPONENTS/MEMORY/DATA_FLASH/AT45DBX/at45dbx.h @ 4837

Last change on this file since 4837 was 4837, checked in by daduve, 2 years ago

Adding new version

File size: 7.6 KB
Line 
1/* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
2
3/*This file is prepared for Doxygen automatic documentation generation.*/
4/*! \file *********************************************************************
5 *
6 * \brief Management of the AT45DBX data flash controller through SPI.
7 *
8 * This file manages the accesses to the AT45DBX data flash components.
9 *
10 * - Compiler:           IAR EWAVR32 and GNU GCC for AVR32
11 * - Supported devices:  All AVR32 devices with an SPI module can be used.
12 * - AppNote:
13 *
14 * \author               Atmel Corporation: http://www.atmel.com \n
15 *                       Support and FAQ: http://support.atmel.no/
16 *
17 ******************************************************************************/
18
19/* Copyright (c) 2009 Atmel Corporation. All rights reserved.
20 *
21 * Redistribution and use in source and binary forms, with or without
22 * modification, are permitted provided that the following conditions are met:
23 *
24 * 1. Redistributions of source code must retain the above copyright notice, this
25 * list of conditions and the following disclaimer.
26 *
27 * 2. Redistributions in binary form must reproduce the above copyright notice,
28 * this list of conditions and the following disclaimer in the documentation
29 * and/or other materials provided with the distribution.
30 *
31 * 3. The name of Atmel may not be used to endorse or promote products derived
32 * from this software without specific prior written permission.
33 *
34 * 4. This software may only be redistributed and used in connection with an Atmel
35 * AVR product.
36 *
37 * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
38 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
39 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
40 * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
41 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
42 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
45 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
46 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
47 *
48 */
49
50#ifndef _AT45DBX_H_
51#define _AT45DBX_H_
52
53
54#include "conf_access.h"
55
56#if AT45DBX_MEM == DISABLE
57  #error at45dbx.h is #included although AT45DBX_MEM is disabled
58#endif
59
60
61#include "spi.h"
62
63
64//_____ D E F I N I T I O N S ______________________________________________
65
66/*! \name Available AT45DBX Sizes
67 *
68 * Number of address bits of available AT45DBX data flash memories.
69 *
70 * \note Only memories with page sizes of at least 512 bytes (sector size) are
71 *       supported.
72 */
73//! @{
74#define AT45DBX_1MB             20
75#define AT45DBX_2MB             21
76#define AT45DBX_4MB             22
77#define AT45DBX_8MB             23
78//! @}
79
80// AT45DBX_1MB
81#define AT45DBX_SECTOR_BITS                             8                 //! Number of bits for addresses within sectors.
82// AT45DBX_2MB AT45DBX_4MB AT45DBX_8MB
83//#define AT45DBX_SECTOR_BITS                           9                 //! Number of bits for addresses within sectors.
84
85//! Sector size in bytes.
86#define AT45DBX_SECTOR_SIZE     (1 << AT45DBX_SECTOR_BITS)
87
88//_____ D E C L A R A T I O N S ____________________________________________
89
90/*! \name Control Functions
91 */
92//! @{
93
94/*! \brief Initializes the data flash controller and the SPI channel by which
95 *         the DF is controlled.
96 *
97 * \param spiOptions  Initialization options of the DF SPI channel.
98 * \param pba_hz      SPI module input clock frequency (PBA clock, Hz).
99 *
100 * \retval OK Success.
101 * \retval KO Failure.
102 */
103extern Bool at45dbx_init(spi_options_t spiOptions, unsigned int pba_hz);
104
105/*! \brief Performs a memory check on all DFs.
106 *
107 * \retval OK Success.
108 * \retval KO Failure.
109 */
110extern Bool at45dbx_mem_check(void);
111
112/*! \brief Opens a DF memory in read mode at a given sector.
113 *
114 * \param sector  Start sector.
115 *
116 * \retval OK Success.
117 * \retval KO Failure.
118 *
119 * \note Sector may be page-unaligned (depending on the DF page size).
120 */
121extern Bool at45dbx_read_open(U32 sector);
122
123/*! \brief Unselects the current DF memory.
124 */
125extern void at45dbx_read_close(void);
126
127/*! \brief This function opens a DF memory in write mode at a given sector.
128 *
129 * \param sector  Start sector.
130 *
131 * \retval OK Success.
132 * \retval KO Failure.
133 *
134 * \note Sector may be page-unaligned (depending on the DF page size).
135 *
136 * \note If \ref AT45DBX_PAGE_SIZE > \ref AT45DBX_SECTOR_SIZE, page content is
137 *       first loaded in buffer to then be partially updated by write byte or
138 *       write sector functions.
139 */
140extern Bool at45dbx_write_open(U32 sector);
141
142/*! \brief Fills the end of the current logical sector and launches page programming.
143 */
144extern void at45dbx_write_close(void);
145
146//! @}
147
148
149/*! \name Single-Byte Access Functions
150 */
151//! @{
152
153/*! \brief Performs a single byte read from DF memory.
154 *
155 * \return The read byte.
156 *
157 * \note First call must be preceded by a call to the \ref at45dbx_read_open
158 *       function.
159 */
160extern U8 at45dbx_read_byte(void);
161
162/*! \brief Performs a single byte write to DF memory.
163 *
164 * \param b The byte to write.
165 *
166 * \retval OK Success.
167 * \retval KO Failure.
168 *
169 * \note First call must be preceded by a call to the \ref at45dbx_write_open
170 *       function.
171 */
172extern Bool at45dbx_write_byte(U8 b);
173
174//! @}
175
176
177/*! \name Multiple-Sector Access Functions
178 */
179//! @{
180
181/*! \brief Reads \a nb_sector sectors from DF memory.
182 *
183 * Data flow is: DF -> callback.
184 *
185 * \param nb_sector Number of contiguous sectors to read.
186 *
187 * \retval OK Success.
188 * \retval KO Failure.
189 *
190 * \note First call must be preceded by a call to the \ref at45dbx_read_open
191 *       function.
192 *
193 * \note As \ref AT45DBX_PAGE_SIZE is always a multiple of
194 *       \ref AT45DBX_SECTOR_SIZE, there is no need to check page end for each
195 *       byte.
196 */
197extern Bool at45dbx_read_multiple_sector(U16 nb_sector);
198
199/*! \brief Callback function invoked after each sector read during
200 *         \ref at45dbx_read_multiple_sector.
201 *
202 * \param psector Pointer to read sector.
203 */
204extern void at45dbx_read_multiple_sector_callback(const void *psector);
205
206/*! \brief Writes \a nb_sector sectors to DF memory.
207 *
208 * Data flow is: callback -> DF.
209 *
210 * \param nb_sector Number of contiguous sectors to write.
211 *
212 * \retval OK Success.
213 * \retval KO Failure.
214 *
215 * \note First call must be preceded by a call to the \ref at45dbx_write_open
216 *       function.
217 *
218 * \note As \ref AT45DBX_PAGE_SIZE is always a multiple of
219 *       \ref AT45DBX_SECTOR_SIZE, there is no need to check page end for each
220 *       byte.
221 */
222extern Bool at45dbx_write_multiple_sector(U16 nb_sector);
223
224/*! \brief Callback function invoked before each sector write during
225 *         \ref at45dbx_write_multiple_sector.
226 *
227 * \param psector Pointer to sector to write.
228 */
229extern void at45dbx_write_multiple_sector_callback(void *psector);
230
231//! @}
232
233
234/*! \name Single-Sector Access Functions
235 */
236//! @{
237
238/*! \brief Reads 1 DF sector to a RAM buffer.
239 *
240 * Data flow is: DF -> RAM.
241 *
242 * \param ram Pointer to RAM buffer.
243 *
244 * \retval OK Success.
245 * \retval KO Failure.
246 *
247 * \note First call must be preceded by a call to the \ref at45dbx_read_open
248 *       function.
249 */
250extern Bool at45dbx_read_sector_2_ram(void *ram);
251
252/*! \brief Writes 1 DF sector from a RAM buffer.
253 *
254 * Data flow is: RAM -> DF.
255 *
256 * \param ram Pointer to RAM buffer.
257 *
258 * \retval OK Success.
259 * \retval KO Failure.
260 *
261 * \note First call must be preceded by a call to the \ref at45dbx_write_open
262 *       function.
263 */
264extern Bool at45dbx_write_sector_from_ram(const void *ram);
265
266//! @}
267
268
269#endif  // _AT45DBX_H_
Note: See TracBrowser for help on using the repository browser.