18#if VSF_HAL_USE_FLASH == ENABLED
24#define vsf_real_flash_t VSF_MCONNECT(VSF_FLASH_CFG_IMP_PREFIX, _flash_t)
25#define vsf_real_flash_capability VSF_MCONNECT(VSF_FLASH_CFG_IMP_PREFIX, _flash_capability)
26#define vsf_real_flash_erase_all VSF_MCONNECT(VSF_FLASH_CFG_IMP_PREFIX, _flash_erase_all)
27#define vsf_real_flash_erase_one_sector VSF_MCONNECT(VSF_FLASH_CFG_IMP_PREFIX, _flash_erase_one_sector)
28#define vsf_real_flash_erase_multi_sector VSF_MCONNECT(VSF_FLASH_CFG_IMP_PREFIX, _flash_erase_multi_sector)
29#define vsf_real_flash_write_one_sector VSF_MCONNECT(VSF_FLASH_CFG_IMP_PREFIX, _flash_write_one_sector)
30#define vsf_real_flash_write_multi_sector VSF_MCONNECT(VSF_FLASH_CFG_IMP_PREFIX, _flash_write_multi_sector)
31#define vsf_real_flash_read_one_sector VSF_MCONNECT(VSF_FLASH_CFG_IMP_PREFIX, _flash_read_one_sector)
32#define vsf_real_flash_read_multi_sector VSF_MCONNECT(VSF_FLASH_CFG_IMP_PREFIX, _flash_read_multi_sector)
34#ifndef VSF_FLASH_CFG_REIMPLEMENT_API_CAPABILITY
35# define VSF_FLASH_CFG_REIMPLEMENT_API_CAPABILITY DISABLED
38#ifdef VSF_FLASH_CFG_IMP_REMAP_PREFIX
39# undef VSF_FLASH_CFG_REIMPLEMENT_API_CAPABILITY
40# define VSF_FLASH_CFG_REIMPLEMENT_API_CAPABILITY ENABLED
43#if VSF_FLASH_CFG_REIMPLEMENT_API_CAPABILITY == DISABLED
44# ifndef VSF_FLASH_CFG_CAPABILITY_IRQ_MASK
45# define VSF_FLASH_CFG_CAPABILITY_IRQ_MASK VSF_FLASH_IRQ_ALL_BITS_MASK
47# ifndef VSF_FLASH_CFG_CAPABILITY_BASE_ADDRESS
48# define VSF_FLASH_CFG_CAPABILITY_BASE_ADDRESS 0
50# ifndef VSF_FLASH_CFG_CAPABILITY_MAX_SIZE
51# error "Please define flash size macro 'VSF_FLASH_CFG_CAPABILITY_MAX_SIZE' in source files"
53# ifndef VSF_FLASH_CFG_CAPABILITY_ERASE_SECTORE_SIZE
54# define VSF_FLASH_CFG_CAPABILITY_ERASE_SECTORE_SIZE 4096
56# ifndef VSF_FLASH_CFG_CAPABILITY_WRITE_SECTORE_SIZE
57# define VSF_FLASH_CFG_CAPABILITY_WRITE_SECTORE_SIZE 512
59# ifndef VSF_FLASH_CFG_CAPABILITY_NONE_SECTOR_ALIGNED_WRITE
60# define VSF_FLASH_CFG_CAPABILITY_NONE_SECTOR_ALIGNED_WRITE 0
62# ifndef VSF_FLASH_CFG_CAPABILITY_NONE_SECTOR_ALIGNED_READ
63# define VSF_FLASH_CFG_CAPABILITY_NONE_SECTOR_ALIGNED_READ 1
74#if VSF_FLASH_CFG_REIMPLEMENT_API_CAPABILITY == DISABLED
78 .irq_mask = VSF_FLASH_CFG_CAPABILITY_IRQ_MASK,
80 .max_size = VSF_FLASH_CFG_CAPABILITY_MAX_SIZE,
81 .erase_sector_size = VSF_FLASH_CFG_CAPABILITY_ERASE_SECTORE_SIZE,
82 .write_sector_size = VSF_FLASH_CFG_CAPABILITY_WRITE_SECTORE_SIZE,
83 .none_sector_aligned_write = VSF_FLASH_CFG_CAPABILITY_NONE_SECTOR_ALIGNED_WRITE,
84 .none_sector_aligned_read = VSF_FLASH_CFG_CAPABILITY_NONE_SECTOR_ALIGNED_READ,
89 return flash_capability;
93#if VSF_FLASH_CFG_ERASE_ONE_SECTOR_TEMPLATE == ENABLED
107#if VSF_FLASH_CFG_ERASE_MULTI_SECTOR_TEMPLATE == ENABLED
119 vsf_err_t err = vsf_real_flash_erase_one_sector(real_flash_ptr,
offset + i);
129#if VSF_FLASH_CFG_ERASE_ALL_TEMPLATE == ENABLED
130vsf_err_t vsf_real_flash_erase_all(vsf_real_flash_t *real_flash_ptr)
139 return vsf_real_flash_erase_multi_sector(real_flash_ptr, 0, flash_capability.
max_size);
143#if VSF_FLASH_CFG_WRITE_ONE_SECTOR_TEMPLATE == ENABLED
152 return vsf_real_flash_write_multi_sector(real_flash_ptr,
offset, buffer,
size);
156#if VSF_FLASH_CFG_WRITE_MULTI_SECTOR_TEMPLATE == ENABLED
167 vsf_err_t err = vsf_real_flash_write_one_sector(real_flash_ptr,
offset + i, buffer + i, current_size);
177#if VSF_FLASH_CFG_READ_ONE_SECTOR_TEMPLATE == ENABLED
186 return vsf_real_flash_read_multi_sector(real_flash_ptr,
offset, buffer,
size);
190#if VSF_FLASH_CFG_READ_MULTI_SECTOR_TEMPLATE == ENABLED
202 vsf_err_t err = vsf_real_flash_read_one_sector(real_flash_ptr,
offset + i, buffer + i, current_size);
214#undef VSF_FLASH_CFG_REIMPLEMENT_API_CAPABILITY
215#undef VSF_FLASH_CFG_CAPABILITY_IRQ_MASK
216#undef VSF_FLASH_CFG_CAPABILITY_BASE_ADDRESS
217#undef VSF_FLASH_CFG_CAPABILITY_MAX_SIZE
218#undef VSF_FLASH_CFG_CAPABILITY_ERASE_SECTORE_SIZE
219#undef VSF_FLASH_CFG_CAPABILITY_WRITE_SECTORE_SIZE
220#undef VSF_FLASH_CFG_CAPABILITY_NONE_SECTOR_ALIGNED_WRITE
221#undef VSF_FLASH_CFG_CAPABILITY_NONE_SECTOR_ALIGNED_READ
223#undef vsf_real_flash_t
224#undef vsf_real_flash_erase_all
225#undef vsf_real_flash_erase_one_sector
226#undef vsf_real_flash_erase_multi_sector
227#undef vsf_real_flash_write_one_sector
228#undef vsf_real_flash_write_multi_sector
229#undef vsf_real_flash_read_one_sector
230#undef vsf_real_flash_read_multi_sector
231#undef vsf_real_flash_capability
235#ifdef VSF_DAC_CFG_IMP_REMAP_PREFIX
236# define vsf_imp_flash_t VSF_MCONNECT(VSF_FLASH_CFG_IMP_PREFIX, _flash_t)
237# define vsf_imp_flash_init VSF_MCONNECT(VSF_FLASH_CFG_IMP_PREFIX, _flash_init)
238# define vsf_imp_flash_fini VSF_MCONNECT(VSF_FLASH_CFG_IMP_PREFIX, _flash_fini)
239# define vsf_imp_flash_enable VSF_MCONNECT(VSF_FLASH_CFG_IMP_PREFIX, _flash_enable)
240# define vsf_imp_flash_disable VSF_MCONNECT(VSF_FLASH_CFG_IMP_PREFIX, _flash_disable)
241# define vsf_imp_flash_capability VSF_MCONNECT(VSF_FLASH_CFG_IMP_PREFIX, _flash_capability)
242# define vsf_imp_flash_status VSF_MCONNECT(VSF_FLASH_CFG_IMP_PREFIX, _flash_status)
243# define vsf_imp_flash_irq_enable VSF_MCONNECT(VSF_FLASH_CFG_IMP_PREFIX, _flash_irq_enable)
244# define vsf_imp_flash_irq_disable VSF_MCONNECT(VSF_FLASH_CFG_IMP_PREFIX, _flash_irq_disable)
245# define vsf_imp_flash_erase_one_sector VSF_MCONNECT(VSF_FLASH_CFG_IMP_PREFIX, _flash_erase_one_sector)
246# define vsf_imp_flash_erase_multi_sector VSF_MCONNECT(VSF_FLASH_CFG_IMP_PREFIX, _flash_erase_multi_sector)
247# define vsf_imp_flash_erase VSF_MCONNECT(VSF_FLASH_CFG_IMP_PREFIX, _flash_erase_multi_sector)
248# define vsf_imp_flash_erase_all VSF_MCONNECT(VSF_FLASH_CFG_IMP_PREFIX, _flash_erase_all)
249# define vsf_imp_flash_write_one_sector VSF_MCONNECT(VSF_FLASH_CFG_IMP_PREFIX, _flash_write_one_sector)
250# define vsf_imp_flash_write_multi_sector VSF_MCONNECT(VSF_FLASH_CFG_IMP_PREFIX, _flash_write_multi_sector)
251# define vsf_imp_flash_write VSF_MCONNECT(VSF_FLASH_CFG_IMP_PREFIX, _flash_write_multi_sector)
252# define vsf_imp_flash_read_one_sector VSF_MCONNECT(VSF_FLASH_CFG_IMP_PREFIX, _flash_read_one_sector)
253# define vsf_imp_flash_read_multi_sector VSF_MCONNECT(VSF_FLASH_CFG_IMP_PREFIX, _flash_read_multi_sector)
254# define vsf_imp_flash_read VSF_MCONNECT(VSF_FLASH_CFG_IMP_PREFIX, _flash_read_multi_sector)
256# define vsf_remap_flash_t VSF_MCONNECT(VSF_FLASH_CFG_IMP_REMAP_PREFIX, _flash_t)
257# define vsf_remap_flash_init VSF_MCONNECT(VSF_FLASH_CFG_IMP_REMAP_PREFIX, _flash_init)
258# define vsf_remap_flash_fini VSF_MCONNECT(VSF_FLASH_CFG_IMP_REMAP_PREFIX, _flash_fini)
259# define vsf_remap_flash_enable VSF_MCONNECT(VSF_FLASH_CFG_IMP_REMAP_PREFIX, _flash_enable)
260# define vsf_remap_flash_disable VSF_MCONNECT(VSF_FLASH_CFG_IMP_REMAP_PREFIX, _flash_disable)
261# define vsf_remap_flash_capability VSF_MCONNECT(VSF_FLASH_CFG_IMP_REMAP_PREFIX, _flash_capability)
262# define vsf_remap_flash_status VSF_MCONNECT(VSF_FLASH_CFG_IMP_REMAP_PREFIX, _flash_status)
263# define vsf_remap_flash_irq_enable VSF_MCONNECT(VSF_FLASH_CFG_IMP_REMAP_PREFIX, _flash_irq_enable)
264# define vsf_remap_flash_irq_disable VSF_MCONNECT(VSF_FLASH_CFG_IMP_REMAP_PREFIX, _flash_irq_disable)
265# define vsf_remap_flash_erase_one_sector VSF_MCONNECT(VSF_FLASH_CFG_IMP_REMAP_PREFIX, _flash_erase_one_sector)
266# define vsf_remap_flash_erase_multi_sector VSF_MCONNECT(VSF_FLASH_CFG_IMP_REMAP_PREFIX, _flash_erase_multi_sector)
267# define vsf_remap_flash_erase VSF_MCONNECT(VSF_FLASH_CFG_IMP_REMAP_PREFIX, _flash_erase_multi_sector)
268# define vsf_remap_flash_erase_all VSF_MCONNECT(VSF_FLASH_CFG_IMP_REMAP_PREFIX, _flash_erase_all)
269# define vsf_remap_flash_write_one_sector VSF_MCONNECT(VSF_FLASH_CFG_IMP_REMAP_PREFIX, _flash_write_one_sector)
270# define vsf_remap_flash_write_multi_sector VSF_MCONNECT(VSF_FLASH_CFG_IMP_REMAP_PREFIX, _flash_write_multi_sector)
271# define vsf_remap_flash_write VSF_MCONNECT(VSF_FLASH_CFG_IMP_REMAP_PREFIX, _flash_write_multi_sector)
272# define vsf_remap_flash_read_one_sector VSF_MCONNECT(VSF_FLASH_CFG_IMP_REMAP_PREFIX, _flash_read_one_sector)
273# define vsf_remap_flash_read_multi_sector VSF_MCONNECT(VSF_FLASH_CFG_IMP_REMAP_PREFIX, _flash_read_multi_sector)
274# define vsf_remap_flash_read VSF_MCONNECT(VSF_FLASH_CFG_IMP_REMAP_PREFIX, _flash_read_multi_sector)
276# define VSF_FLASH_CFG_IMP_REMAP_FUNCTIONS \
277 vsf_err_t vsf_imp_flash_init(vsf_imp_flash_t *flash_ptr, vsf_flash_cfg_t *cfg_ptr) \
279 VSF_HAL_ASSERT(flash_ptr != NULL); \
280 return vsf_remap_flash_init((vsf_remap_flash_t *)flash_ptr, cfg_ptr); \
282 void vsf_imp_flash_fini(vsf_imp_flash_t *flash_ptr) \
284 VSF_HAL_ASSERT(flash_ptr != NULL); \
285 vsf_remap_flash_fini((vsf_remap_flash_t *)flash_ptr); \
287 fsm_rt_t vsf_imp_flash_enable(vsf_imp_flash_t *flash_ptr) \
289 VSF_HAL_ASSERT(flash_ptr != NULL); \
290 return vsf_remap_flash_enable((vsf_remap_flash_t *)flash_ptr); \
292 fsm_rt_t vsf_imp_flash_disable(vsf_imp_flash_t *flash_ptr) \
294 VSF_HAL_ASSERT(flash_ptr != NULL); \
295 return vsf_remap_flash_disable((vsf_remap_flash_t *)flash_ptr); \
297 void vsf_imp_flash_irq_enable(vsf_imp_flash_t *flash_ptr, vsf_flash_irq_mask_t irq_mask) \
299 VSF_HAL_ASSERT(flash_ptr != NULL); \
300 vsf_remap_flash_irq_enable((vsf_remap_flash_t *)flash_ptr, irq_mask); \
302 void vsf_imp_flash_irq_disable(vsf_imp_flash_t *flash_ptr, vsf_flash_irq_mask_t irq_mask) \
304 VSF_HAL_ASSERT(flash_ptr != NULL); \
305 vsf_remap_flash_irq_disable((vsf_remap_flash_t *)flash_ptr, irq_mask); \
307 vsf_flash_status_t vsf_imp_flash_status(vsf_imp_flash_t *flash_ptr) \
309 VSF_HAL_ASSERT(flash_ptr != NULL); \
310 return vsf_remap_flash_status((vsf_remap_flash_t *)flash_ptr); \
312 vsf_flash_capability_t vsf_imp_flash_capability(vsf_imp_flash_t *flash_ptr) \
314 VSF_HAL_ASSERT(flash_ptr != NULL); \
315 return vsf_remap_flash_capability((vsf_remap_flash_t *)flash_ptr); \
317 vsf_err_t vsf_imp_flash_erase_one_sector(vsf_imp_flash_t *flash_ptr, uint_fast32_t offset) \
319 VSF_HAL_ASSERT(flash_ptr != NULL); \
320 return vsf_remap_flash_erase_one_sector((vsf_remap_flash_t *)flash_ptr, offset); \
322 vsf_err_t vsf_imp_flash_erase_multi_sector(vsf_imp_flash_t *flash_ptr, uint_fast32_t offset, uint_fast32_t size) \
324 VSF_HAL_ASSERT(flash_ptr != NULL); \
325 return vsf_remap_flash_erase_multi_sector((vsf_remap_flash_t *)flash_ptr, offset, size); \
327 vsf_err_t vsf_imp_flash_erase_all(vsf_imp_flash_t *flash_ptr) \
329 VSF_HAL_ASSERT(flash_ptr != NULL); \
330 return vsf_remap_flash_erase_all((vsf_remap_flash_t *)flash_ptr); \
332 vsf_err_t vsf_imp_flash_write_one_sector(vsf_imp_flash_t *flash_ptr, uint_fast32_t offset, uint8_t* buffer, uint_fast32_t size) \
334 VSF_HAL_ASSERT(flash_ptr != NULL); \
335 return vsf_remap_flash_write_one_sector((vsf_remap_flash_t *)flash_ptr, offset, buffer, size); \
337 vsf_err_t vsf_imp_flash_write_multi_sector(vsf_imp_flash_t *flash_ptr, uint_fast32_t offset, uint8_t* buffer, uint_fast32_t size) \
339 VSF_HAL_ASSERT(flash_ptr != NULL); \
340 return vsf_remap_flash_write_multi_sector((vsf_remap_flash_t *)flash_ptr, offset, buffer, size); \
342 vsf_err_t vsf_imp_flash_read_one_sector(vsf_imp_flash_t *flash_ptr, uint_fast32_t offset, uint8_t* buffer, uint_fast32_t size) \
344 VSF_HAL_ASSERT(flash_ptr != NULL); \
345 return vsf_remap_flash_read_one_sector((vsf_remap_flash_t *)flash_ptr, offset, buffer, size); \
347 vsf_err_t vsf_imp_flash_read_multi_sector(vsf_imp_flash_t *flash_ptr, uint_fast32_t offset, uint8_t* buffer, uint_fast32_t size) \
349 VSF_HAL_ASSERT(flash_ptr != NULL); \
350 return vsf_remap_flash_read_multi_sector((vsf_remap_flash_t *)flash_ptr, offset, buffer, size); \
356#define VSF_HAL_TEMPLATE_IMP_NAME _flash
357#define VSF_HAL_TEMPLATE_IMP_UPCASE_NAME _FLASH
359#ifndef VSF_FLASH_CFG_IMP_PREFIX
360# error "Please define VSF_FLASH_CFG_IMP_PREFIX in flash driver"
363#ifndef VSF_FLASH_CFG_IMP_UPCASE_PREFIX
364# error "Please define VSF_FLASH_CFG_IMP_UPCASE_PREFIX in flash driver"
367#ifndef VSF_FLASH_CFG_IMP_COUNT_MASK_PREFIX
368# define VSF_FLASH_CFG_IMP_COUNT_MASK_PREFIX VSF_FLASH_CFG_IMP_UPCASE_PREFIX
371#ifdef VSF_FLASH_CFG_IMP_REMAP_FUNCTIONS
372# define VSF_HAL_CFG_IMP_REMAP_FUNCTIONS VSF_FLASH_CFG_IMP_REMAP_FUNCTIONS
377#undef VSF_FLASH_CFG_IMP_PREFIX
378#undef VSF_FLASH_CFG_IMP_COUNT_MASK_PREFIX
379#undef VSF_FLASH_CFG_IMP_UPCASE_PREFIX
380#undef VSF_FLASH_CFG_IMP_LV0
381#undef VSF_FLASH_CFG_IMP_REMAP_FUNCTIONS
382#undef VSF_FLASH_CFG_IMP_HAS_OP
383#undef VSF_FLASH_CFG_IMP_EXTERN_OP
385#undef vsf_imp_flash_t
386#undef vsf_imp_flash_init
387#undef vsf_imp_flash_fini
388#undef vsf_imp_flash_enable
389#undef vsf_imp_flash_disable
390#undef vsf_imp_flash_capability
391#undef vsf_imp_flash_status
392#undef vsf_imp_flash_irq_enable
393#undef vsf_imp_flash_irq_disable
394#undef vsf_imp_flash_erase_one_sector
395#undef vsf_imp_flash_erase_multi_sector
396#undef vsf_imp_flash_erase
397#undef vsf_imp_flash_erase_all
398#undef vsf_imp_flash_write_one_sector
399#undef vsf_imp_flash_write_multi_sector
400#undef vsf_imp_flash_write
401#undef vsf_imp_flash_read_one_sector
402#undef vsf_imp_flash_read_multi_sector
403#undef vsf_imp_flash_read
405#undef vsf_remap_flash_t
406#undef vsf_remap_flash_init
407#undef vsf_remap_flash_fini
408#undef vsf_remap_flash_enable
409#undef vsf_remap_flash_disable
410#undef vsf_remap_flash_capability
411#undef vsf_remap_flash_status
412#undef vsf_remap_flash_irq_enable
413#undef vsf_remap_flash_irq_disable
414#undef vsf_remap_flash_erase_one_sector
415#undef vsf_remap_flash_erase_multi_sector
416#undef vsf_remap_flash_erase
417#undef vsf_remap_flash_erase_all
418#undef vsf_remap_flash_write_one_sector
419#undef vsf_remap_flash_write_multi_sector
420#undef vsf_remap_flash_write
421#undef vsf_remap_flash_read_one_sector
422#undef vsf_remap_flash_read_multi_sector
423#undef vsf_remap_flash_read
#define vsf_min(__a, __b)
Definition __type.h:152
vsf_err_t
Definition __type.h:42
@ VSF_ERR_NONE
none error
Definition __type.h:44
#define VSF_ASSERT(__EXPR)
system macros
Definition __type.h:126
unsigned char uint8_t
Definition lvgl.h:40
Definition vsf_template_flash.h:164
vsf_flash_size_t max_size
Definition vsf_template_flash.h:171
uint8_t none_sector_aligned_read
Definition vsf_template_flash.h:177
vsf_flash_size_t write_sector_size
Definition vsf_template_flash.h:173
vsf_flash_size_t base_address
Definition vsf_template_flash.h:170
vsf_flash_size_t erase_sector_size
Definition vsf_template_flash.h:172
uint8_t none_sector_aligned_write
Definition vsf_template_flash.h:176
uint64_t offset
Definition vsf_memfs.h:49
uint32_t size
Definition vsf_memfs.h:50
uint_fast32_t vsf_flash_size_t
Definition vsf_template_flash.h:135