]> begriffs open source - cmsis/blob - CMSIS/DoxyGen/Driver/src/Driver_Flash.c
Merge branch 'develop' of https://github.com/ARM-software/CMSIS_5 into develop
[cmsis] / CMSIS / DoxyGen / Driver / src / Driver_Flash.c
1 /* -----------------------------------------------------------------------------
2  * Copyright (c) 2013-2014 ARM Limited. All rights reserved.
3  *  
4  * $Date:        2. January 2014
5  * $Revision:    V2.00
6  *  
7  * Project:      Flash Driver API
8  * -------------------------------------------------------------------------- */
9
10
11 /**
12 \defgroup flash_interface_gr Flash Interface
13 \brief    Driver API for Flash Device Interface (%Driver_Flash.h)
14 \details
15 <a href="http://en.wikipedia.org/wiki/Flash_memory" target="_blank">Flash devices</a> based on NOR memory cells are the
16 preferred technology for embedded applications requiring a discrete non-volatile memory device. The low read latency
17 characteristic of these Flash devices allow a direct code execution
18 (<a href="http://en.wikipedia.org/wiki/Execute_in_place" target="_blank">XIP</a>) and data storage in a single memory
19 product.
20
21 <b>Flash API</b>
22
23 The Flash API provides a generic API suitable for Flashes with NOR memory cells independent from the actual interface
24 to the MCU (memory bus, SPI, ...). <a href="http://en.wikipedia.org/wiki/Flash_memory#Serial_flash" target="_blank">SPI</a>
25 flashes are typically not named NOR flashes but have usually same flash cell properties. 
26
27 The following header files define the Application Programming Interface (API) for the Flash interface:
28   - \b %Driver_Flash.h : Driver API for Flash Device Interface
29
30 <b>Driver Functions</b>
31
32 The driver functions are published in the access struct as explained in \ref DriverFunctions
33   - \ref ARM_DRIVER_FLASH : access struct for Flash driver functions
34 @{
35 */
36 /*
37 \todo provide more text for the driver implementation above
38
39 A typical setup sequence for the driver is shown below:
40
41 <b>Example Code:</b>
42
43 \todo example
44 *******************************************************************************************************************/
45
46
47 /**
48 \defgroup Flash_events Flash Events
49 \ingroup flash_interface_gr
50 \brief The Flash driver generates call back events that are notified via the function \ref ARM_Flash_SignalEvent.
51 \details 
52 This section provides the event values for the \ref ARM_Flash_SignalEvent callback function.
53
54 The following call back notification events are generated:
55 @{
56 \def ARM_FLASH_EVENT_READY
57 \def ARM_FLASH_EVENT_ERROR
58 @}
59 */
60
61
62 /**
63 \struct     ARM_FLASH_SECTOR 
64 \details  
65 Specifies sector start and end address.
66
67 <b>Element of</b>:
68   - \ref ARM_FLASH_INFO structure
69 *******************************************************************************************************************/
70
71 /**
72 \struct     ARM_FLASH_INFO 
73 \details 
74 Stores the characteristics of a Flash device. This includes sector layout, programming size and a default value for erased memory.
75 This information can be obtained from the Flash device datasheet and is used by the middleware in order to properly interact with the Flash device.
76
77 Sector layout is described by specifying the \em sector_info which points to an array of sector information (start and end address) and by specifying the \em sector_count which defines the number of sectors.
78 The element \em sector_size is not used in this case and needs to be \em 0.
79 Flash sectors need not to be aligned continuously. Gaps are allowed in the device memory space in order to reserve sectors for other usage (for example application code).
80
81 When the device has uniform sector size than the sector layout can be described by specifying the \em sector_size which defines the size of a single sector and by specifying the \em sector_count which defines the number of sectors.
82 The element \em sector_info is not used in this case and needs to be \em NULL.
83
84 The smallest programmable unit within a sector is specified by the \em program_unit. It defines the granularity for programming data.
85
86 Optimal programming page size is specified by the \em page_size and defines the amount of data that should be programmed in one step to achieve maximum programming speed.
87
88 Contents of erased memory is specified by the \em erased_value and is typically \em 0xFF. This value can be used before erasing a sector to check if the sector is blank and erase can be skipped.
89
90 *******************************************************************************************************************/
91
92 /**
93 \struct     ARM_DRIVER_FLASH
94 \details 
95 The functions of the Flash driver are accessed by function pointers exposed by this structure. Refer to \ref DriverFunctions for overview information.
96
97 Each instance of a Flash interface provides such an access structure. 
98 The instance is identified by a postfix number in the symbol name of the access structure, for example:
99  - \b Driver_Flash0 is the name of the access struct of the first instance (no. 0).
100  - \b Driver_Flash1 is the name of the access struct of the second instance (no. 1).
101
102 A middleware configuration setting allows connecting the middleware to a specific driver instance \b %Driver_Flash<i>n</i>.
103 The default is \token{0}, which connects a middleware to the first instance of a driver.
104 *******************************************************************************************************************/
105
106 /**
107 \struct     ARM_FLASH_CAPABILITIES 
108 \details
109 A Flash driver can be implemented with different capabilities. The data fields of this struct encode 
110 the capabilities implemented by this driver.
111
112 The element \em event_ready indicates that the driver is able to generate the \ref ARM_FLASH_EVENT_READY event. In case that this event is not available it is possible to poll the driver status by calling the \ref ARM_Flash_GetStatus and check the \em busy flag.
113
114 The element \em data_width specifies the data access size and also defines the data type (uint8_t, uint16_t or uint32_t) for the \em data parameter in \ref ARM_Flash_ReadData and \ref ARM_Flash_ProgramData functions.
115
116 The element \em erase_chip specifies that the \ref ARM_Flash_EraseChip function is supported. Typically full chip erase is much faster than erasing the whole device sector per sector.
117
118 <b>Returned by:</b>
119   - \ref ARM_Flash_GetCapabilities
120 *******************************************************************************************************************/
121
122 /**
123 \struct     ARM_FLASH_STATUS
124 \details
125 Structure with information about the status of the Flash.
126
127 The flag \em busy indicates that the driver is busy executing read/program/erase operation.
128
129 The flag \em error flag is cleared on start of read/program/erase operation and is set at the end of the current operation in case of error.
130
131 <b>Returned by:</b>
132   - \ref ARM_Flash_GetStatus
133 *****************************************************************************************************************/
134
135 /**
136 \typedef    ARM_Flash_SignalEvent_t
137 \details
138 Provides the typedef for the callback function \ref ARM_Flash_SignalEvent.
139
140 <b>Parameter for:</b>
141   - \ref ARM_Flash_Initialize
142 *******************************************************************************************************************/
143
144
145 //
146 // Functions
147 //
148
149 ARM_DRIVER_VERSION ARM_Flash_GetVersion (void)  {
150   return { 0, 0 };
151 }
152 /**
153 \fn ARM_DRIVER_VERSION ARM_Flash_GetVersion (void)
154 \details
155 The function \b ARM_Flash_GetVersion returns version information of the driver implementation in \ref ARM_DRIVER_VERSION
156  - API version is the version of the CMSIS-Driver specification used to implement this driver.
157  - Driver version is source code version of the actual driver implementation.
158
159 Example:
160 \code
161 extern ARM_DRIVER_FLASH Driver_Flash0;
162 ARM_DRIVER_FLASH *drv_info;
163  
164 void read_version (void)  {
165   ARM_DRIVER_VERSION  version;
166  
167   drv_info = &Driver_Flash0;  
168   version = drv_info->GetVersion ();
169   if (version.api < 0x10A)   {      // requires at minimum API version 1.10 or higher
170     // error handling
171     return;
172   }
173 }
174 \endcode
175 *******************************************************************************************************************/
176
177 ARM_FLASH_CAPABILITIES ARM_Flash_GetCapabilities (void)  {
178   return { 0 };
179 }
180 /**
181 \fn ARM_FLASH_CAPABILITIES ARM_Flash_GetCapabilities (void)
182 \details
183 The function \b ARM_Flash_GetCapabilities returns information about capabilities in this driver implementation.
184 The data fields of the struct \ref ARM_FLASH_CAPABILITIES encode various capabilities, for example
185 if a hardware is able to create signal events using the \ref ARM_Flash_SignalEvent callback function.
186  
187 Example:
188 \code
189 extern ARM_DRIVER_FLASH Driver_Flash0;
190 ARM_DRIVER_FLASH *drv_info;
191   
192 void read_capabilities (void)  {
193   ARM_FLASH_CAPABILITIES drv_capabilities;
194  
195   drv_info = &Driver_Flash0;  
196   drv_capabilities = drv_info->GetCapabilities ();
197   // interrogate capabilities
198  
199 }
200 \endcode
201 *******************************************************************************************************************/
202
203 int32_t ARM_Flash_Initialize (ARM_Flash_SignalEvent_t cb_event)  {
204   return 0;
205 }
206 /**
207 \fn int32_t ARM_Flash_Initialize (ARM_Flash_SignalEvent_t cb_event)
208 \details
209 The function \b ARM_Flash_Initialize initializes the Flash interface.
210 It is called when the middleware component starts operation.
211
212 The function performs the following operations:
213   - Initializes the resources needed for the Flash interface.
214   - Registers the \ref ARM_Flash_SignalEvent callback function.
215
216 The parameter \em cb_event is a pointer to the \ref ARM_Flash_SignalEvent callback function; use a NULL pointer 
217 when no callback signals are required.
218
219 \b Example:
220  - see \ref flash_interface_gr - Driver Functions
221
222 *******************************************************************************************************************/
223
224 int32_t ARM_Flash_Uninitialize (void)  {
225   return 0;
226 }
227 /**
228 \fn int32_t ARM_Flash_Uninitialize (void)
229 \details
230 The function \b ARM_Flash_Uninitialize de-initializes the resources of Flash interface.
231
232 It is called when the middleware component stops operation and releases the software resources used by the interface.
233 *******************************************************************************************************************/
234
235 int32_t ARM_Flash_PowerControl (ARM_POWER_STATE state)  {
236   return 0;
237 }
238 /**
239 \fn int32_t ARM_Flash_PowerControl (ARM_POWER_STATE state)
240 \details
241 The function \b ARM_Flash_PowerControl operates the power modes of the Flash interface.
242
243 The parameter \em state can have the following values:
244   - \ref ARM_POWER_FULL : set-up peripheral for data transfers, enable interrupts (NVIC) and optionally DMA. Can be called multiple times. 
245                           If the peripheral is already in this mode, then the function performs no operation and returns with \ref ARM_DRIVER_OK.
246   - \ref ARM_POWER_LOW : may use power saving. Returns \ref ARM_DRIVER_ERROR_UNSUPPORTED when not implemented.
247   - \ref ARM_POWER_OFF : terminates any pending data transfers, disables peripheral, disables related interrupts and DMA.
248       
249 Refer to \ref CallSequence for more information.
250 *******************************************************************************************************************/
251
252 int32_t ARM_Flash_ReadData (uint32_t addr, void *data, uint32_t cnt)  {
253   return 0;
254 }
255 /**
256 \fn int32_t ARM_Flash_ReadData (uint32_t addr, void *data, uint32_t cnt)
257 \details  
258 This function \b ARM_Flash_ReadData reads data from the Flash device.
259
260 The parameter \em addr specifies the address from where to read data (needs to be aligned to data type size). \n
261 The parameter \em data specifies the pointer to a buffer storing the data read. 
262 The data type is \em uint8_t, \em uint16_t or \em uint32_t and is specified by the \em data_width in \ref ARM_FLASH_CAPABILITIES. \n
263 The parameter \em cnt specifies the number of data items to read.
264
265 The function executes in the following ways:
266  - When the operation is non-blocking (typical for SPI Flash) then the function only starts the operation and returns with zero number of data items read. 
267    When the operation is completed the \ref ARM_FLASH_EVENT_READY event is generated (if supported and reported by \ref ARM_Flash_GetCapabilities).
268    In case of errors the \ref ARM_FLASH_EVENT_ERROR event is generated at the same time.   
269    Progress of the operation can also be monitored by calling the \ref ARM_Flash_GetStatus function and checking the \em busy flag.
270  - When the operation is blocking (typical for memory mapped Flash) then the function returns after the data is read and returns the number of data items read.
271 *******************************************************************************************************************/
272
273 int32_t ARM_Flash_ProgramData (uint32_t addr, const void *data, uint32_t cnt)  {
274   return 0;
275 }
276 /**
277 \fn int32_t ARM_Flash_ProgramData (uint32_t addr, const void *data, uint32_t cnt)
278 \details  
279 This function \b ARM_Flash_ProgramData programs data to the Flash device.
280
281 The parameter \em addr specifies the address to where to program data (needs to be aligned to \em program_unit specified in \ref ARM_FLASH_INFO). \n
282 The parameter \em data specifies the pointer to a buffer containing data to be programmed. 
283 The data type is \em uint8_t, \em uint16_t or \em uint32_t and is specified by the \em data_width in \ref ARM_FLASH_CAPABILITIES. \n
284 The parameter \em cnt specifies the number of data items to program (data size needs to be a multiple of \em program_unit).
285
286 The function executes in the following ways:
287  - When the operation is non-blocking (typically) then the function only starts the operation and returns with zero number of data items programmed. 
288    When the operation is completed the \ref ARM_FLASH_EVENT_READY event is generated (if supported and reported by \ref ARM_Flash_GetCapabilities).
289    In case of errors the \ref ARM_FLASH_EVENT_ERROR event is generated at the same time.
290    Progress of the operation can also be monitored by calling the \ref ARM_Flash_GetStatus function and checking the \em busy flag.
291  - When the operation is blocking then the function returns after the data is programmed and returns the number of data items programmed.
292 *******************************************************************************************************************/
293
294 int32_t ARM_Flash_EraseSector (uint32_t addr)  {
295   return 0;
296 }
297 /**
298 \fn int32_t ARM_Flash_EraseSector (uint32_t addr)
299 \details  
300 This function \b ARM_Flash_EraseSector erases a flash sector specified by the parameter <i>adr</i> (points to start of the sector).
301
302 The function is non-blocking and returns as soon as the driver has started the operation.
303 When the operation is completed the \ref ARM_FLASH_EVENT_READY event is generated (if supported and reported by \ref ARM_Flash_GetCapabilities).
304 In case of errors the \ref ARM_FLASH_EVENT_ERROR event is generated at the same time.
305 Progress of the operation can also be monitored by calling the \ref ARM_Flash_GetStatus function and checking the \em busy flag.
306 *******************************************************************************************************************/
307
308 int32_t ARM_Flash_EraseChip (void)  {
309   return 0;
310 }
311 /**
312 \fn int32_t ARM_Flash_EraseChip (void)
313 \details  
314 The optional function \b ARM_Flash_EraseChip erases the complete device.
315 If the device does not support global erase or only a portion of the Flash memory space is used for storing files,
316 then the functions returns the error value \ref ARM_DRIVER_ERROR_UNSUPPORTED.
317 The data field \em eras_chip = \token{1} of the structure \ref ARM_FLASH_CAPABILITIES encodes that \b ARM_Flash_EraseChip is supported.
318 The field can be verified with the function \ref ARM_Flash_GetCapabilities.
319
320 The function is non-blocking and returns as soon as the driver has started the operation.
321 When the operation is completed, the \ref ARM_FLASH_EVENT_READY event is generated (if supported and reported by \ref ARM_Flash_GetCapabilities).
322 In case of errors, the \ref ARM_FLASH_EVENT_ERROR event is generated at the same time.
323 Progress of the operation can also be monitored by calling the \ref ARM_Flash_GetStatus function and checking the \em busy flag.
324
325 <b>See also:</b>
326  - ARM_Flash_SignalEvent
327 *******************************************************************************************************************/
328
329 ARM_FLASH_STATUS ARM_Flash_GetStatus (void)  {
330   return 0;
331 }
332 /**
333 \fn ARM_FLASH_STATUS ARM_Flash_GetStatus (void)
334 \details
335 The function \b ARM_Flash_GetStatus returns the current Flash interface status stored in the structure \ref ARM_FLASH_STATUS.
336 *******************************************************************************************************************/
337
338 ARM_FLASH_INFO * ARM_Flash_GetInfo (void)  {
339   return NULL;
340 }
341 /**
342 \fn ARM_FLASH_INFO * ARM_Flash_GetInfo (void)
343 \details
344 The function \b ARM_Flash_GetInfo returns information about the Flash device.
345 *******************************************************************************************************************/
346
347 void ARM_Flash_SignalEvent (uint32_t event)  {
348   return 0;
349 }
350 /**
351 \fn void ARM_Flash_SignalEvent (uint32_t event)
352 \details
353
354 The function \b ARM_Flash_SignalEvent is a callback function registered by the function \ref ARM_Flash_Initialize. 
355 The function is called automatically after read/program/erase operation completes.
356
357 The parameter \em event indicates one or more events that occurred during driver operation. Each event is coded in a separate bit and
358 therefore it is possible to signal multiple events in the event call back function. 
359
360 Not every event is necessarily generated by the driver. This depends on the implemented capabilities stored in the 
361 data fields of the structure \ref ARM_FLASH_CAPABILITIES, which can be retrieved with the function \ref ARM_Flash_GetCapabilities.
362
363 The following events can be generated:
364
365 Parameter \em event                 | Bit | Description 
366 :-----------------------------------|:---:|:-----------
367 \ref ARM_FLASH_EVENT_READY          |  0  | Occurs after read/program/erase operation completes.
368 \ref ARM_FLASH_EVENT_ERROR          |  1  | Occurs together with \ref ARM_FLASH_EVENT_READY when operation completes with errors.
369
370 <b>See also:</b>
371  - \ref ARM_Flash_EraseChip
372 *******************************************************************************************************************/
373
374 /**
375 @}
376 */ 
377 // End Flash Interface