ChibiOS/HAL 9.0.0
hal_flash_interface.h
Go to the documentation of this file.
1/*
2 ChibiOS - Copyright (C) 2006..2025 Giovanni Di Sirio
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17/**
18 * @file hal_flash_interface.h
19 * @brief Generated Flash Interface header.
20 * @note This is a generated file, do not edit directly.
21 *
22 * @addtogroup HAL_FLASH_INTERFACE
23 * @brief Flash Interface.
24 * @details Base interface for flash devices.
25 * @{
26 */
27
28#ifndef HAL_FLASH_INTERFACE_H
29#define HAL_FLASH_INTERFACE_H
30
31/*===========================================================================*/
32/* Module constants. */
33/*===========================================================================*/
34
35/*===========================================================================*/
36/* Module pre-compile time settings. */
37/*===========================================================================*/
38
39/*===========================================================================*/
40/* Derived constants and error checks. */
41/*===========================================================================*/
42
43/*===========================================================================*/
44/* Module macros. */
45/*===========================================================================*/
46
47/*===========================================================================*/
48/* Module data structures and types. */
49/*===========================================================================*/
50
51/**
52 * @interface flash_interface_i
53 *
54 * @brief Generic flash interface.
55 *
56 * @name Interface @p flash_interface_i structures
57 * @{
58 */
59
60/**
61 * @brief Type of a flash interface interface.
62 */
64
65/**
66 * @brief Interface @p flash_interface_i virtual methods table.
67 */
69 /* Memory offset between this interface structure and begin of
70 the implementing class structure.*/
72 /* From flash_interface_i.*/
73 const flash_descriptor_t * (*get_descriptor)(void *ip);
74 flash_error_t (*read)(void *ip, flash_offset_t offset, size_t n, uint8_t *rp);
75 flash_error_t (*program)(void *ip, flash_offset_t offset, size_t n, const uint8_t *pp);
78 flash_error_t (*query_erase)(void *ip, unsigned *msec);
82};
83
84/**
85 * @brief Structure representing a flash interface interface.
86 */
88 /**
89 * @brief Virtual Methods Table.
90 */
91 const struct flash_interface_vmt *vmt;
92};
93/** @} */
94
95/*===========================================================================*/
96/* External declarations. */
97/*===========================================================================*/
98
99#ifdef __cplusplus
100extern "C" {
101#endif
102#ifdef __cplusplus
103}
104#endif
105
106/*===========================================================================*/
107/* Module inline functions. */
108/*===========================================================================*/
109
110/**
111 * @name Virtual methods of flash_interface_i
112 * @{
113 */
114/**
115 * @brief Gets the flash descriptor structure.
116 *
117 * @param[in,out] ip Pointer to a @p flash_interface_i instance.
118 * @return A flash device descriptor.
119 */
121static inline const flash_descriptor_t *flsGetDescriptor(void *ip) {
123
124 return self->vmt->get_descriptor(ip);
125}
126
127/**
128 * @brief Read operation.
129 *
130 * @param[in,out] ip Pointer to a @p flash_interface_i instance.
131 * @param[in] offset Flash offset.
132 * @param[in] n Number of bytes to be read.
133 * @param[out] rp Pointer to the data buffer.
134 * @return An error code.
135 * @retval FLASH_NO_ERROR If there is no erase operation in progress.
136 * @retval FLASH_BUSY_ERASING If there is an erase operation in progress.
137 * @retval FLASH_ERROR_READ If the read operation failed.
138 * @retval FLASH_ERROR_HW_FAILURE If access to the memory failed.
139 */
141static inline flash_error_t flsRead(void *ip, flash_offset_t offset, size_t n,
142 uint8_t *rp) {
144
145 return self->vmt->read(ip, offset, n, rp);
146}
147
148/**
149 * @brief Program operation.
150 *
151 * @param[in,out] ip Pointer to a @p flash_interface_i instance.
152 * @param[in] offset Flash offset.
153 * @param[in] n Number of bytes to be programmed.
154 * @param[in] pp Pointer to the data buffer.
155 * @return An error code.
156 * @retval FLASH_NO_ERROR If there is no erase operation in progress.
157 * @retval FLASH_BUSY_ERASING If there is an erase operation in progress.
158 * @retval FLASH_ERROR_PROGRAM If the program operation failed.
159 * @retval FLASH_ERROR_HW_FAILURE If access to the memory failed.
160 */
162static inline flash_error_t flsProgram(void *ip, flash_offset_t offset,
163 size_t n, const uint8_t *pp) {
165
166 return self->vmt->program(ip, offset, n, pp);
167}
168
169/**
170 * @brief Starts a whole-device erase operation.
171 *
172 * @param[in,out] ip Pointer to a @p flash_interface_i instance.
173 * @return An error code.
174 * @retval FLASH_NO_ERROR If there is no erase operation in progress.
175 * @retval FLASH_BUSY_ERASING If there is an erase operation in progress.
176 * @retval FLASH_ERROR_HW_FAILURE If access to the memory failed.
177 */
179static inline flash_error_t flsStartEraseAll(void *ip) {
181
182 return self->vmt->start_erase_all(ip);
183}
184
185/**
186 * @brief Starts an sector erase operation.
187 *
188 * @param[in,out] ip Pointer to a @p flash_interface_i instance.
189 * @param[in] sector Sector to be erased.
190 * @return An error code.
191 * @retval FLASH_NO_ERROR If there is no erase operation in progress.
192 * @retval FLASH_BUSY_ERASING If there is an erase operation in progress.
193 * @retval FLASH_ERROR_HW_FAILURE If access to the memory failed.
194 */
196static inline flash_error_t flsStartEraseSector(void *ip,
197 flash_sector_t sector) {
199
200 return self->vmt->start_erase_sector(ip, sector);
201}
202
203/**
204 * @brief Queries the driver for erase operation progress.
205 *
206 * @param[in,out] ip Pointer to a @p flash_interface_i instance.
207 * @param[out] msec Recommended time, in milliseconds, that should
208 * be spent before calling this function again,
209 * can be @p NULL
210 * @return An error code.
211 * @retval FLASH_NO_ERROR If there is no erase operation in progress.
212 * @retval FLASH_BUSY_ERASING If there is an erase operation in progress.
213 * @retval FLASH_ERROR_HW_FAILURE If access to the memory failed.
214 */
216static inline flash_error_t flsQueryErase(void *ip, unsigned *msec) {
218
219 return self->vmt->query_erase(ip, msec);
220}
221
222/**
223 * @brief Returns the erase state of a sector.
224 *
225 * @param[in,out] ip Pointer to a @p flash_interface_i instance.
226 * @param[in] sector Sector to be verified.
227 * @return An error code.
228 * @retval FLASH_NO_ERROR If there is no erase operation in progress.
229 * @retval FLASH_BUSY_ERASING If there is an erase operation in progress.
230 * @retval FLASH_ERROR_VERIFY If the verify operation failed.
231 * @retval FLASH_ERROR_HW_FAILURE If access to the memory failed.
232 */
234static inline flash_error_t flsVerifyErase(void *ip, flash_sector_t sector) {
236
237 return self->vmt->verify_erase(ip, sector);
238}
239
240/**
241 * @brief Acquires exclusive access to flash.
242 *
243 * @param[in,out] ip Pointer to a @p flash_interface_i instance.
244 * @return An error code.
245 * @retval FLASH_NO_ERROR If there is no erase operation in progress.
246 * @retval FLASH_ERROR_UNIMPLEMENTED UNIMPLEMENTED if exclusive access not
247 * enabled.
248 */
250static inline flash_error_t flsAcquireExclusive(void *ip) {
252
253 return self->vmt->acquire_exclusive(ip);
254}
255
256/**
257 * @brief Releases exclusive access to flash.
258 *
259 * @param[in,out] ip Pointer to a @p flash_interface_i instance.
260 * @return An error code.
261 * @retval FLASH_NO_ERROR If there is no erase operation in progress.
262 * @retval FLASH_ERROR_UNIMPLEMENTED UNIMPLEMENTED if exclusive access not
263 * enabled.
264 */
266static inline flash_error_t flsReleaseExclusive(void *ip) {
268
269 return self->vmt->release_exclusive(ip);
270}
271/** @} */
272
273#endif /* HAL_FLASH_INTERFACE_H */
274
275/** @} */
#define CC_FORCE_INLINE
Enforces a function inline.
Definition ccportab.h:108
static CC_FORCE_INLINE flash_error_t flsStartEraseSector(void *ip, flash_sector_t sector)
Starts an sector erase operation.
static CC_FORCE_INLINE flash_error_t flsVerifyErase(void *ip, flash_sector_t sector)
Returns the erase state of a sector.
static CC_FORCE_INLINE const flash_descriptor_t * flsGetDescriptor(void *ip)
Gets the flash descriptor structure.
static CC_FORCE_INLINE flash_error_t flsReleaseExclusive(void *ip)
Releases exclusive access to flash.
static CC_FORCE_INLINE flash_error_t flsStartEraseAll(void *ip)
Starts a whole-device erase operation.
static CC_FORCE_INLINE flash_error_t flsQueryErase(void *ip, unsigned *msec)
Queries the driver for erase operation progress.
static CC_FORCE_INLINE flash_error_t flsAcquireExclusive(void *ip)
Acquires exclusive access to flash.
static CC_FORCE_INLINE flash_error_t flsProgram(void *ip, flash_offset_t offset, size_t n, const uint8_t *pp)
Program operation.
static CC_FORCE_INLINE flash_error_t flsRead(void *ip, flash_offset_t offset, size_t n, uint8_t *rp)
Read operation.
uint32_t flash_sector_t
Type of a flash sector number.
Definition hal_flash.h:117
uint32_t flash_offset_t
Type of a flash offset.
Definition hal_flash.h:112
flash_error_t
Type of a flash error code.
Definition hal_flash.h:98
Generic flash interface.
Type of a flash device descriptor.
Definition hal_flash.h:136
Interface flash_interface_i virtual methods table.
flash_error_t(* read)(void *ip, flash_offset_t offset, size_t n, uint8_t *rp)
flash_error_t(* start_erase_sector)(void *ip, flash_sector_t sector)
flash_error_t(* acquire_exclusive)(void *ip)
flash_error_t(* program)(void *ip, flash_offset_t offset, size_t n, const uint8_t *pp)
flash_error_t(* start_erase_all)(void *ip)
flash_error_t(* release_exclusive)(void *ip)
flash_error_t(* verify_erase)(void *ip, flash_sector_t sector)
flash_error_t(* query_erase)(void *ip, unsigned *msec)
Structure representing a flash interface interface.
const struct flash_interface_vmt * vmt
Virtual Methods Table.