]> begriffs open source - cmsis/blob - CMSIS/Driver/Include/Driver_Flash.h
5.0.1-dev1: http:// removed. PACK schema relaxed
[cmsis] / CMSIS / Driver / Include / Driver_Flash.h
1 /*
2  * Copyright (c) 2013-2016 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
19 /* History:
20  *  Version 2.00
21  *    Renamed driver NOR -> Flash (more generic)
22  *    Non-blocking operation
23  *    Added Events, Status and Capabilities
24  *    Linked Flash information (GetInfo)
25  *  Version 1.11
26  *    Changed prefix ARM_DRV -> ARM_DRIVER
27  *  Version 1.10
28  *    Namespace prefix ARM_ added
29  *  Version 1.00
30  *    Initial release
31  */
32
33 #ifndef DRIVER_FLASH_H_
34 #define DRIVER_FLASH_H_
35
36 #ifdef  __cplusplus
37 extern "C"
38 {
39 #endif
40
41 #include "Driver_Common.h"
42
43 #define ARM_FLASH_API_VERSION ARM_DRIVER_VERSION_MAJOR_MINOR(2,00)  /* API version */
44
45
46 #define _ARM_Driver_Flash_(n)      Driver_Flash##n
47 #define  ARM_Driver_Flash_(n) _ARM_Driver_Flash_(n)
48
49
50 #define ARM_FLASH_SECTOR_INFO(addr,size) { (addr), (addr)+(size)-1 }
51
52 /**
53 \brief Flash Sector information
54 */
55 typedef struct _ARM_FLASH_SECTOR {
56   uint32_t start;                       ///< Sector Start address
57   uint32_t end;                         ///< Sector End address (start+size-1)
58 } const ARM_FLASH_SECTOR;
59
60 /**
61 \brief Flash information
62 */
63 typedef struct _ARM_FLASH_INFO {
64   ARM_FLASH_SECTOR *sector_info;        ///< Sector layout information (NULL=Uniform sectors)
65   uint32_t          sector_count;       ///< Number of sectors
66   uint32_t          sector_size;        ///< Uniform sector size in bytes (0=sector_info used) 
67   uint32_t          page_size;          ///< Optimal programming page size in bytes
68   uint32_t          program_unit;       ///< Smallest programmable unit in bytes
69   uint8_t           erased_value;       ///< Contents of erased memory (usually 0xFF)
70 } const ARM_FLASH_INFO;
71
72
73 /**
74 \brief Flash Status
75 */
76 typedef struct _ARM_FLASH_STATUS {
77   uint32_t busy  : 1;                   ///< Flash busy flag
78   uint32_t error : 1;                   ///< Read/Program/Erase error flag (cleared on start of next operation)
79 } ARM_FLASH_STATUS;
80
81
82 /****** Flash Event *****/
83 #define ARM_FLASH_EVENT_READY           (1UL << 0)  ///< Flash Ready
84 #define ARM_FLASH_EVENT_ERROR           (1UL << 1)  ///< Read/Program/Erase Error
85
86
87 // Function documentation
88 /**
89   \fn          ARM_DRIVER_VERSION ARM_Flash_GetVersion (void)
90   \brief       Get driver version.
91   \return      \ref ARM_DRIVER_VERSION
92 */
93 /**
94   \fn          ARM_FLASH_CAPABILITIES ARM_Flash_GetCapabilities (void)
95   \brief       Get driver capabilities.
96   \return      \ref ARM_FLASH_CAPABILITIES
97 */
98 /**
99   \fn          int32_t ARM_Flash_Initialize (ARM_Flash_SignalEvent_t cb_event)
100   \brief       Initialize the Flash Interface.
101   \param[in]   cb_event  Pointer to \ref ARM_Flash_SignalEvent
102   \return      \ref execution_status
103 */
104 /**
105   \fn          int32_t ARM_Flash_Uninitialize (void)
106   \brief       De-initialize the Flash Interface.
107   \return      \ref execution_status
108 */
109 /**
110   \fn          int32_t ARM_Flash_PowerControl (ARM_POWER_STATE state)
111   \brief       Control the Flash interface power.
112   \param[in]   state  Power state
113   \return      \ref execution_status
114 */
115 /**
116   \fn          int32_t ARM_Flash_ReadData (uint32_t addr, void *data, uint32_t cnt)
117   \brief       Read data from Flash.
118   \param[in]   addr  Data address.
119   \param[out]  data  Pointer to a buffer storing the data read from Flash.
120   \param[in]   cnt   Number of data items to read.
121   \return      number of data items read or \ref execution_status
122 */
123 /**
124   \fn          int32_t ARM_Flash_ProgramData (uint32_t addr, const void *data, uint32_t cnt)
125   \brief       Program data to Flash.
126   \param[in]   addr  Data address.
127   \param[in]   data  Pointer to a buffer containing the data to be programmed to Flash.
128   \param[in]   cnt   Number of data items to program.
129   \return      number of data items programmed or \ref execution_status
130 */
131 /**
132   \fn          int32_t ARM_Flash_EraseSector (uint32_t addr)
133   \brief       Erase Flash Sector.
134   \param[in]   addr  Sector address
135   \return      \ref execution_status
136 */
137 /**
138   \fn          int32_t ARM_Flash_EraseChip (void)
139   \brief       Erase complete Flash.
140                Optional function for faster full chip erase.
141   \return      \ref execution_status
142 */
143 /**
144   \fn          ARM_FLASH_STATUS ARM_Flash_GetStatus (void)
145   \brief       Get Flash status.
146   \return      Flash status \ref ARM_FLASH_STATUS
147 */
148 /**
149   \fn          ARM_FLASH_INFO * ARM_Flash_GetInfo (void)
150   \brief       Get Flash information.
151   \return      Pointer to Flash information \ref ARM_FLASH_INFO
152 */
153
154 /**
155   \fn          void ARM_Flash_SignalEvent (uint32_t event)
156   \brief       Signal Flash event.
157   \param[in]   event  Event notification mask
158   \return      none
159 */
160
161 typedef void (*ARM_Flash_SignalEvent_t) (uint32_t event);    ///< Pointer to \ref ARM_Flash_SignalEvent : Signal Flash Event.
162
163
164 /**
165 \brief Flash Driver Capabilities.
166 */
167 typedef struct _ARM_FLASH_CAPABILITIES {
168   uint32_t event_ready  : 1;            ///< Signal Flash Ready event
169   uint32_t data_width   : 2;            ///< Data width: 0=8-bit, 1=16-bit, 2=32-bit
170   uint32_t erase_chip   : 1;            ///< Supports EraseChip operation
171 } ARM_FLASH_CAPABILITIES;
172
173
174 /**
175 \brief Access structure of the Flash Driver
176 */
177 typedef struct _ARM_DRIVER_FLASH {
178   ARM_DRIVER_VERSION     (*GetVersion)     (void);                                          ///< Pointer to \ref ARM_Flash_GetVersion : Get driver version.
179   ARM_FLASH_CAPABILITIES (*GetCapabilities)(void);                                          ///< Pointer to \ref ARM_Flash_GetCapabilities : Get driver capabilities.
180   int32_t                (*Initialize)     (ARM_Flash_SignalEvent_t cb_event);              ///< Pointer to \ref ARM_Flash_Initialize : Initialize Flash Interface.
181   int32_t                (*Uninitialize)   (void);                                          ///< Pointer to \ref ARM_Flash_Uninitialize : De-initialize Flash Interface.
182   int32_t                (*PowerControl)   (ARM_POWER_STATE state);                         ///< Pointer to \ref ARM_Flash_PowerControl : Control Flash Interface Power.
183   int32_t                (*ReadData)       (uint32_t addr,       void *data, uint32_t cnt); ///< Pointer to \ref ARM_Flash_ReadData : Read data from Flash.
184   int32_t                (*ProgramData)    (uint32_t addr, const void *data, uint32_t cnt); ///< Pointer to \ref ARM_Flash_ProgramData : Program data to Flash.
185   int32_t                (*EraseSector)    (uint32_t addr);                                 ///< Pointer to \ref ARM_Flash_EraseSector : Erase Flash Sector.
186   int32_t                (*EraseChip)      (void);                                          ///< Pointer to \ref ARM_Flash_EraseChip : Erase complete Flash.
187   ARM_FLASH_STATUS       (*GetStatus)      (void);                                          ///< Pointer to \ref ARM_Flash_GetStatus : Get Flash status.
188   ARM_FLASH_INFO *       (*GetInfo)        (void);                                          ///< Pointer to \ref ARM_Flash_GetInfo : Get Flash information.
189 } const ARM_DRIVER_FLASH;
190
191 #ifdef  __cplusplus
192 }
193 #endif
194
195 #endif /* DRIVER_FLASH_H_ */