]> begriffs open source - cmsis/blob - CMSIS/Driver/Include/Driver_Flash.h
Added documentation stubs for CMSIS-Driver WiFi.
[cmsis] / CMSIS / Driver / Include / Driver_Flash.h
1 /*
2  * Copyright (c) 2013-2018 ARM Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Licensed under the Apache License, Version 2.0 (the License); you may
7  * not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an AS IS BASIS, WITHOUT
14  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * $Date:        19. Apr 2018
19  * $Revision:    V2.2
20  *
21  * Project:      Flash Driver definitions
22  */
23
24 /* History:
25  *  Version 2.2
26  *    Padding bytes added to ARM_FLASH_INFO
27  *  Version 2.1
28  *    ARM_FLASH_STATUS made volatile
29  *  Version 2.0
30  *    Renamed driver NOR -> Flash (more generic)
31  *    Non-blocking operation
32  *    Added Events, Status and Capabilities
33  *    Linked Flash information (GetInfo)
34  *  Version 1.11
35  *    Changed prefix ARM_DRV -> ARM_DRIVER
36  *  Version 1.10
37  *    Namespace prefix ARM_ added
38  *  Version 1.00
39  *    Initial release
40  */
41
42 #ifndef DRIVER_FLASH_H_
43 #define DRIVER_FLASH_H_
44
45 #ifdef  __cplusplus
46 extern "C"
47 {
48 #endif
49
50 #include "Driver_Common.h"
51
52 #define ARM_FLASH_API_VERSION ARM_DRIVER_VERSION_MAJOR_MINOR(2,2)  /* API version */
53
54
55 #define _ARM_Driver_Flash_(n)      Driver_Flash##n
56 #define  ARM_Driver_Flash_(n) _ARM_Driver_Flash_(n)
57
58
59 #define ARM_FLASH_SECTOR_INFO(addr,size) { (addr), (addr)+(size)-1 }
60
61 /**
62 \brief Flash Sector information
63 */
64 typedef struct _ARM_FLASH_SECTOR {
65   uint32_t start;                       ///< Sector Start address
66   uint32_t end;                         ///< Sector End address (start+size-1)
67 } const ARM_FLASH_SECTOR;
68
69 /**
70 \brief Flash information
71 */
72 typedef struct _ARM_FLASH_INFO {
73   ARM_FLASH_SECTOR *sector_info;        ///< Sector layout information (NULL=Uniform sectors)
74   uint32_t          sector_count;       ///< Number of sectors
75   uint32_t          sector_size;        ///< Uniform sector size in bytes (0=sector_info used) 
76   uint32_t          page_size;          ///< Optimal programming page size in bytes
77   uint32_t          program_unit;       ///< Smallest programmable unit in bytes
78   uint8_t           erased_value;       ///< Contents of erased memory (usually 0xFF)
79   uint8_t           reserved[3];        ///< Reserved (must be zero)
80 } const ARM_FLASH_INFO;
81
82
83 /**
84 \brief Flash Status
85 */
86 typedef volatile struct _ARM_FLASH_STATUS {
87   uint32_t busy     : 1;                ///< Flash busy flag
88   uint32_t error    : 1;                ///< Read/Program/Erase error flag (cleared on start of next operation)
89   uint32_t reserved : 30;
90 } ARM_FLASH_STATUS;
91
92
93 /****** Flash Event *****/
94 #define ARM_FLASH_EVENT_READY           (1UL << 0)  ///< Flash Ready
95 #define ARM_FLASH_EVENT_ERROR           (1UL << 1)  ///< Read/Program/Erase Error
96
97
98 // Function documentation
99 /**
100   \fn          ARM_DRIVER_VERSION ARM_Flash_GetVersion (void)
101   \brief       Get driver version.
102   \return      \ref ARM_DRIVER_VERSION
103 */
104 /**
105   \fn          ARM_FLASH_CAPABILITIES ARM_Flash_GetCapabilities (void)
106   \brief       Get driver capabilities.
107   \return      \ref ARM_FLASH_CAPABILITIES
108 */
109 /**
110   \fn          int32_t ARM_Flash_Initialize (ARM_Flash_SignalEvent_t cb_event)
111   \brief       Initialize the Flash Interface.
112   \param[in]   cb_event  Pointer to \ref ARM_Flash_SignalEvent
113   \return      \ref execution_status
114 */
115 /**
116   \fn          int32_t ARM_Flash_Uninitialize (void)
117   \brief       De-initialize the Flash Interface.
118   \return      \ref execution_status
119 */
120 /**
121   \fn          int32_t ARM_Flash_PowerControl (ARM_POWER_STATE state)
122   \brief       Control the Flash interface power.
123   \param[in]   state  Power state
124   \return      \ref execution_status
125 */
126 /**
127   \fn          int32_t ARM_Flash_ReadData (uint32_t addr, void *data, uint32_t cnt)
128   \brief       Read data from Flash.
129   \param[in]   addr  Data address.
130   \param[out]  data  Pointer to a buffer storing the data read from Flash.
131   \param[in]   cnt   Number of data items to read.
132   \return      number of data items read or \ref execution_status
133 */
134 /**
135   \fn          int32_t ARM_Flash_ProgramData (uint32_t addr, const void *data, uint32_t cnt)
136   \brief       Program data to Flash.
137   \param[in]   addr  Data address.
138   \param[in]   data  Pointer to a buffer containing the data to be programmed to Flash.
139   \param[in]   cnt   Number of data items to program.
140   \return      number of data items programmed or \ref execution_status
141 */
142 /**
143   \fn          int32_t ARM_Flash_EraseSector (uint32_t addr)
144   \brief       Erase Flash Sector.
145   \param[in]   addr  Sector address
146   \return      \ref execution_status
147 */
148 /**
149   \fn          int32_t ARM_Flash_EraseChip (void)
150   \brief       Erase complete Flash.
151                Optional function for faster full chip erase.
152   \return      \ref execution_status
153 */
154 /**
155   \fn          ARM_FLASH_STATUS ARM_Flash_GetStatus (void)
156   \brief       Get Flash status.
157   \return      Flash status \ref ARM_FLASH_STATUS
158 */
159 /**
160   \fn          ARM_FLASH_INFO * ARM_Flash_GetInfo (void)
161   \brief       Get Flash information.
162   \return      Pointer to Flash information \ref ARM_FLASH_INFO
163 */
164
165 /**
166   \fn          void ARM_Flash_SignalEvent (uint32_t event)
167   \brief       Signal Flash event.
168   \param[in]   event  Event notification mask
169   \return      none
170 */
171
172 typedef void (*ARM_Flash_SignalEvent_t) (uint32_t event);    ///< Pointer to \ref ARM_Flash_SignalEvent : Signal Flash Event.
173
174
175 /**
176 \brief Flash Driver Capabilities.
177 */
178 typedef struct _ARM_FLASH_CAPABILITIES {
179   uint32_t event_ready  : 1;            ///< Signal Flash Ready event
180   uint32_t data_width   : 2;            ///< Data width: 0=8-bit, 1=16-bit, 2=32-bit
181   uint32_t erase_chip   : 1;            ///< Supports EraseChip operation
182   uint32_t reserved     : 28;           ///< Reserved (must be zero)
183 } ARM_FLASH_CAPABILITIES;
184
185
186 /**
187 \brief Access structure of the Flash Driver
188 */
189 typedef struct _ARM_DRIVER_FLASH {
190   ARM_DRIVER_VERSION     (*GetVersion)     (void);                                          ///< Pointer to \ref ARM_Flash_GetVersion : Get driver version.
191   ARM_FLASH_CAPABILITIES (*GetCapabilities)(void);                                          ///< Pointer to \ref ARM_Flash_GetCapabilities : Get driver capabilities.
192   int32_t                (*Initialize)     (ARM_Flash_SignalEvent_t cb_event);              ///< Pointer to \ref ARM_Flash_Initialize : Initialize Flash Interface.
193   int32_t                (*Uninitialize)   (void);                                          ///< Pointer to \ref ARM_Flash_Uninitialize : De-initialize Flash Interface.
194   int32_t                (*PowerControl)   (ARM_POWER_STATE state);                         ///< Pointer to \ref ARM_Flash_PowerControl : Control Flash Interface Power.
195   int32_t                (*ReadData)       (uint32_t addr,       void *data, uint32_t cnt); ///< Pointer to \ref ARM_Flash_ReadData : Read data from Flash.
196   int32_t                (*ProgramData)    (uint32_t addr, const void *data, uint32_t cnt); ///< Pointer to \ref ARM_Flash_ProgramData : Program data to Flash.
197   int32_t                (*EraseSector)    (uint32_t addr);                                 ///< Pointer to \ref ARM_Flash_EraseSector : Erase Flash Sector.
198   int32_t                (*EraseChip)      (void);                                          ///< Pointer to \ref ARM_Flash_EraseChip : Erase complete Flash.
199   ARM_FLASH_STATUS       (*GetStatus)      (void);                                          ///< Pointer to \ref ARM_Flash_GetStatus : Get Flash status.
200   ARM_FLASH_INFO *       (*GetInfo)        (void);                                          ///< Pointer to \ref ARM_Flash_GetInfo : Get Flash information.
201 } const ARM_DRIVER_FLASH;
202
203 #ifdef  __cplusplus
204 }
205 #endif
206
207 #endif /* DRIVER_FLASH_H_ */