2 * Copyright (c) 2013-2018 ARM Limited. All rights reserved.
4 * SPDX-License-Identifier: Apache-2.0
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
10 * www.apache.org/licenses/LICENSE-2.0
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.
21 * Project: Flash Driver definitions
26 * Padding bytes added to ARM_FLASH_INFO
28 * ARM_FLASH_STATUS made volatile
30 * Renamed driver NOR -> Flash (more generic)
31 * Non-blocking operation
32 * Added Events, Status and Capabilities
33 * Linked Flash information (GetInfo)
35 * Changed prefix ARM_DRV -> ARM_DRIVER
37 * Namespace prefix ARM_ added
42 #ifndef DRIVER_FLASH_H_
43 #define DRIVER_FLASH_H_
50 #include "Driver_Common.h"
52 #define ARM_FLASH_API_VERSION ARM_DRIVER_VERSION_MAJOR_MINOR(2,2) /* API version */
55 #define _ARM_Driver_Flash_(n) Driver_Flash##n
56 #define ARM_Driver_Flash_(n) _ARM_Driver_Flash_(n)
59 #define ARM_FLASH_SECTOR_INFO(addr,size) { (addr), (addr)+(size)-1 }
62 \brief Flash Sector information
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;
70 \brief Flash information
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;
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;
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
98 // Function documentation
100 \fn ARM_DRIVER_VERSION ARM_Flash_GetVersion (void)
101 \brief Get driver version.
102 \return \ref ARM_DRIVER_VERSION
105 \fn ARM_FLASH_CAPABILITIES ARM_Flash_GetCapabilities (void)
106 \brief Get driver capabilities.
107 \return \ref ARM_FLASH_CAPABILITIES
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
116 \fn int32_t ARM_Flash_Uninitialize (void)
117 \brief De-initialize the Flash Interface.
118 \return \ref execution_status
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
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
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
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
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
155 \fn ARM_FLASH_STATUS ARM_Flash_GetStatus (void)
156 \brief Get Flash status.
157 \return Flash status \ref ARM_FLASH_STATUS
160 \fn ARM_FLASH_INFO * ARM_Flash_GetInfo (void)
161 \brief Get Flash information.
162 \return Pointer to Flash information \ref ARM_FLASH_INFO
166 \fn void ARM_Flash_SignalEvent (uint32_t event)
167 \brief Signal Flash event.
168 \param[in] event Event notification mask
172 typedef void (*ARM_Flash_SignalEvent_t) (uint32_t event); ///< Pointer to \ref ARM_Flash_SignalEvent : Signal Flash Event.
176 \brief Flash Driver Capabilities.
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;
187 \brief Access structure of the Flash Driver
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;
207 #endif /* DRIVER_FLASH_H_ */