SmartSnippets DA1459x SDK
ad_flash.h
Go to the documentation of this file.
1 
46 #ifndef AD_FLASH_H_
47 #define AD_FLASH_H_
48 
49 #if dg_configFLASH_ADAPTER
50 
51 #include <stdlib.h>
52 #include <stdint.h>
53 #include <stdbool.h>
54 
55 #include "qspi_automode.h"
56 #include "eflash_automode.h"
57 
58 /*
59  * DEFINES
60  ****************************************************************************************
61  */
62 # if dg_configQSPI_AUTOMODE_ENABLE
63 # define AD_FLASH_GET_SECTOR_SIZE(addr) ((addr >= EFLASH_MEM1_VIRTUAL_BASE_ADDR && \
64  addr < (EFLASH_MEM1_VIRTUAL_BASE_ADDR + MEMORY_EFLASH_SIZE)) ? \
65  EFLASH_SECTOR_SIZE : FLASH_SECTOR_SIZE)
66 # define AD_FLASH_MAX_SECTOR_SIZE (MAX(EFLASH_SECTOR_SIZE, FLASH_SECTOR_SIZE))
67 # else
68 # define AD_FLASH_GET_SECTOR_SIZE(addr) (EFLASH_SECTOR_SIZE)
69 # define AD_FLASH_MAX_SECTOR_SIZE (EFLASH_SECTOR_SIZE)
70 # endif /* dg_configQSPI_AUTOMODE_ENABLE */
71 
80 void ad_flash_init(void);
81 
95 size_t ad_flash_read(uint32_t addr, uint8_t *buf, size_t len);
96 
114 size_t ad_flash_write(uint32_t addr, const uint8_t *buf, size_t size);
115 
132 bool ad_flash_erase_region(uint32_t addr, size_t size);
133 
144 __STATIC_INLINE const void *ad_flash_get_ptr(uint32_t addr)
145 {
148 # if (dg_configQSPI_AUTOMODE_ENABLE == 1)
149  } else if (qspi_automode_is_valid_virtual_addr(addr)) {
150  return qspi_automode_get_physical_addr(addr);
151 # endif
152  }
153 
154  return NULL;
155 }
156 
172 int ad_flash_update_possible(uint32_t addr, const uint8_t *data_to_write, size_t size);
173 
184 size_t ad_flash_erase_size(uint32_t addr);
185 
186 
196 bool ad_flash_chip_erase_by_addr(uint32_t addr);
197 
205 void ad_flash_lock(void);
206 
213 void ad_flash_unlock(void);
214 
223 #define AD_FLASH_ALWAYS_FLUSH_CACHE ((uint32_t) - 1)
224 
245 void ad_flash_skip_cache_flushing(uint32_t base, uint32_t size);
246 
247 #endif /* dg_configFLASH_ADAPTER */
248 
249 #endif /* AD_FLASH_H_ */
250 
ad_flash_write
size_t ad_flash_write(uint32_t addr, const uint8_t *buf, size_t size)
Write data to flash memory.
eflash_automode_is_valid_virtual_addr
__RETAINED_CODE bool eflash_automode_is_valid_virtual_addr(uint32_t addr)
Verify if given virtual address points to EFLASH memory.
ad_flash_lock
void ad_flash_lock(void)
Lock the flash adapter to prevent multiple tasks from accessing the same flash memory simultaneously.
ad_flash_erase_size
size_t ad_flash_erase_size(uint32_t addr)
Get minimum flash erasable size (sector size)
eflash_automode_get_physical_addr
const __RETAINED_CODE void * eflash_automode_get_physical_addr(uint32_t virtual_addr)
Get the physical address of eFlash memory for the given virtual address.
ad_flash_chip_erase_by_addr
bool ad_flash_chip_erase_by_addr(uint32_t addr)
Perform full erase of a specified flash memory.
qspi_automode.h
Access QSPI device when running in auto mode.
ad_flash_init
void ad_flash_init(void)
Initialize the flash adapter.
ad_flash_update_possible
int ad_flash_update_possible(uint32_t addr, const uint8_t *data_to_write, size_t size)
Check if a flash update can be performed without erasing memory.
ad_flash_skip_cache_flushing
void ad_flash_skip_cache_flushing(uint32_t base, uint32_t size)
Control cache flushing on modifications to a specified flash region.
ad_flash_unlock
void ad_flash_unlock(void)
Release lock on flash adapter.
ad_flash_read
size_t ad_flash_read(uint32_t addr, uint8_t *buf, size_t len)
Read data from flash memory.
eflash_automode.h
Access EFLASH device when running in auto mode.
ad_flash_erase_region
bool ad_flash_erase_region(uint32_t addr, size_t size)
Erase a flash memory region.
ad_flash_get_ptr
const __STATIC_INLINE void * ad_flash_get_ptr(uint32_t addr)
Translate a virtual address to a pointer that directly accesses the corresponding physical flash memo...
Definition: ad_flash.h:144