The Embedded Flash service provides functions for internal flash operations.
Macros | |
#define | EFC EFC0 |
#define | EFC EFC0 |
#define | FLASH_USER_SIG_SIZE (512) |
#define | GPNVM_NUM_MAX 3 |
#define | IFLASH0_ADDR IFLASH0_CNC_ADDR |
#define | IFLASH1_ADDR IFLASH1_CNC_ADDR |
#define | IFLASH_ADDR IFLASH0_ADDR |
#define | IFLASH_ADDR IFLASH0_ADDR |
#define | IFLASH_LOCK_REGION_SIZE IFLASH0_LOCK_REGION_SIZE |
#define | IFLASH_LOCK_REGION_SIZE IFLASH0_LOCK_REGION_SIZE |
#define | IFLASH_PAGE_SIZE IFLASH0_PAGE_SIZE |
#define | IFLASH_PAGE_SIZE IFLASH0_PAGE_SIZE |
Functions | |
static void | compute_address (Efc *p_efc, uint16_t us_page, uint16_t us_offset, uint32_t *pul_addr) |
Compute the address of a flash by the given page and offset. More... | |
static void | compute_lock_range (uint32_t ul_start, uint32_t ul_end, uint32_t *pul_actual_start, uint32_t *pul_actual_end) |
Compute the lock range associated with the given address range. More... | |
uint32_t | flash_clear_gpnvm (uint32_t ul_gpnvm) |
Clear the given GPNVM bit. More... | |
uint32_t | flash_enable_security_bit (void) |
Set security bit. More... | |
uint32_t | flash_erase_all (uint32_t ul_address) |
Erase the entire flash. More... | |
uint32_t | flash_get_descriptor (uint32_t ul_address, uint32_t *pul_flash_descriptor, uint32_t ul_size) |
Get flash descriptor. More... | |
uint32_t | flash_get_page_count (const uint32_t *pul_flash_descriptor) |
Get flash total page count for the specified bank. More... | |
uint32_t | flash_get_page_count_per_region (const uint32_t *pul_flash_descriptor) |
Get flash page count per region (plane) for the specified bank. More... | |
uint32_t | flash_get_region_count (const uint32_t *pul_flash_descriptor) |
Get flash region (plane) count for the specified bank. More... | |
uint32_t | flash_get_wait_state (uint32_t ul_address) |
Get flash wait state. More... | |
uint32_t | flash_init (uint32_t ul_mode, uint32_t ul_fws) |
Initialize the flash service. More... | |
uint32_t | flash_is_gpnvm_set (uint32_t ul_gpnvm) |
Check if the given GPNVM bit is set or not. More... | |
uint32_t | flash_is_locked (uint32_t ul_start, uint32_t ul_end) |
Get the number of locked regions inside the given address range. More... | |
uint32_t | flash_is_security_bit_enabled (void) |
Check if the security bit is set or not. More... | |
uint32_t | flash_lock (uint32_t ul_start, uint32_t ul_end, uint32_t *pul_actual_start, uint32_t *pul_actual_end) |
Lock all the regions in the given address range. More... | |
uint32_t | flash_read_unique_id (uint32_t *pul_data, uint32_t ul_size) |
Read the flash unique ID. More... | |
uint32_t | flash_set_gpnvm (uint32_t ul_gpnvm) |
Set the given GPNVM bit. More... | |
uint32_t | flash_set_wait_state (uint32_t ul_address, uint32_t ul_fws) |
Set flash wait state. More... | |
uint32_t | flash_set_wait_state_adaptively (uint32_t ul_address) |
Set flash wait state. More... | |
uint32_t | flash_unlock (uint32_t ul_start, uint32_t ul_end, uint32_t *pul_actual_start, uint32_t *pul_actual_end) |
Unlock all the regions in the given address range. More... | |
uint32_t | flash_write (uint32_t ul_address, const void *p_buffer, uint32_t ul_size, uint32_t ul_erase_flag) |
Write a data buffer on flash. More... | |
static void | translate_address (Efc **pp_efc, uint32_t ul_addr, uint16_t *pus_page, uint16_t *pus_offset) |
Translate the given flash address to page and offset values. More... | |
Variables | |
static uint32_t | gs_ul_page_buffer [IFLASH_PAGE_SIZE/sizeof(uint32_t)] |
#define EFC EFC0 |
Referenced by board_init(), flash_clear_gpnvm(), flash_init(), flash_is_gpnvm_set(), flash_read_unique_id(), flash_set_gpnvm(), and translate_address().
#define EFC EFC0 |
#define FLASH_USER_SIG_SIZE (512) |
#define GPNVM_NUM_MAX 3 |
Referenced by flash_clear_gpnvm(), flash_is_gpnvm_set(), and flash_set_gpnvm().
#define IFLASH0_ADDR IFLASH0_CNC_ADDR |
Referenced by compute_address(), flash_is_locked(), and translate_address().
#define IFLASH1_ADDR IFLASH1_CNC_ADDR |
Referenced by compute_address(), flash_is_locked(), run_flash_erase_test(), and translate_address().
#define IFLASH_ADDR IFLASH0_ADDR |
#define IFLASH_ADDR IFLASH0_ADDR |
#define IFLASH_LOCK_REGION_SIZE IFLASH0_LOCK_REGION_SIZE |
Referenced by compute_lock_range(), flash_is_locked(), flash_lock(), and flash_unlock().
#define IFLASH_LOCK_REGION_SIZE IFLASH0_LOCK_REGION_SIZE |
#define IFLASH_PAGE_SIZE IFLASH0_PAGE_SIZE |
#define IFLASH_PAGE_SIZE IFLASH0_PAGE_SIZE |
|
static |
Compute the address of a flash by the given page and offset.
p_efc | Pointer to an EFC instance. |
us_page | Page number. |
us_offset | Byte offset inside page. |
pul_addr | Computed address (optional). |
References flash_is_gpnvm_set(), FLASH_RC_YES, IFLASH0_ADDR, IFLASH1_ADDR, IFLASH_ADDR, IFLASH_PAGE_SIZE, and UNUSED.
Referenced by flash_write().
|
static |
Compute the lock range associated with the given address range.
ul_start | Start address of lock range. |
ul_end | End address of lock range. |
pul_actual_start | Actual start address of lock range. |
pul_actual_end | Actual end address of lock range. |
References IFLASH_LOCK_REGION_SIZE.
Referenced by flash_lock(), and flash_unlock().
uint32_t flash_clear_gpnvm | ( | uint32_t | ul_gpnvm | ) |
Clear the given GPNVM bit.
ul_gpnvm | GPNVM bit index. |
References EFC, EFC_FCMD_CGPB, efc_perform_command(), EFC_RC_OK, flash_is_gpnvm_set(), FLASH_RC_ERROR, FLASH_RC_INVALID, FLASH_RC_NO, FLASH_RC_OK, and GPNVM_NUM_MAX.
Referenced by run_flash_gpnvm_test().
uint32_t flash_enable_security_bit | ( | void | ) |
Set security bit.
References flash_set_gpnvm().
uint32_t flash_erase_all | ( | uint32_t | ul_address | ) |
Erase the entire flash.
ul_address | Flash bank start address. |
References EFC_FCMD_EA, efc_perform_command(), EFC_RC_OK, FLASH_RC_ERROR, FLASH_RC_OK, and translate_address().
uint32_t flash_get_descriptor | ( | uint32_t | ul_address, |
uint32_t * | pul_flash_descriptor, | ||
uint32_t | ul_size | ||
) |
Get flash descriptor.
ul_address | Flash bank start address. |
pul_flash_descriptor | Pointer to a data buffer to store flash descriptor. |
ul_size | Data buffer size in DWORD. |
References EFC_FCMD_GETD, efc_get_result(), efc_perform_command(), FLASH_RC_OK, and translate_address().
Referenced by run_flash_information_test().
uint32_t flash_get_page_count | ( | const uint32_t * | pul_flash_descriptor | ) |
Get flash total page count for the specified bank.
pul_flash_descriptor | Pointer to a flash descriptor. |
Referenced by run_flash_information_test().
uint32_t flash_get_page_count_per_region | ( | const uint32_t * | pul_flash_descriptor | ) |
Get flash page count per region (plane) for the specified bank.
pul_flash_descriptor | Pointer to a flash descriptor. |
Referenced by run_flash_information_test().
uint32_t flash_get_region_count | ( | const uint32_t * | pul_flash_descriptor | ) |
Get flash region (plane) count for the specified bank.
pul_flash_descriptor | Pointer to a flash descriptor. |
Referenced by run_flash_information_test().
uint32_t flash_get_wait_state | ( | uint32_t | ul_address | ) |
Get flash wait state.
ul_address | Flash bank start address. |
References efc_get_wait_state(), and translate_address().
Referenced by run_flash_configure_test().
uint32_t flash_init | ( | uint32_t | ul_mode, |
uint32_t | ul_fws | ||
) |
Initialize the flash service.
ul_mode | FLASH_ACCESS_MODE_128 or FLASH_ACCESS_MODE_64. |
ul_fws | The number of wait states in cycle (no shift). |
References EFC, efc_init(), and FLASH_RC_OK.
Referenced by run_flash_configure_test().
uint32_t flash_is_gpnvm_set | ( | uint32_t | ul_gpnvm | ) |
Check if the given GPNVM bit is set or not.
ul_gpnvm | GPNVM bit index. |
1 | If the given GPNVM bit is currently set. |
0 | If the given GPNVM bit is currently cleared. otherwise returns an error code. |
References EFC, EFC_FCMD_GGPB, efc_get_result(), efc_perform_command(), EFC_RC_OK, FLASH_RC_ERROR, FLASH_RC_INVALID, FLASH_RC_NO, FLASH_RC_YES, and GPNVM_NUM_MAX.
Referenced by compute_address(), flash_clear_gpnvm(), flash_is_security_bit_enabled(), flash_set_gpnvm(), run_flash_gpnvm_test(), and translate_address().
uint32_t flash_is_locked | ( | uint32_t | ul_start, |
uint32_t | ul_end | ||
) |
Get the number of locked regions inside the given address range.
ul_start | Start address of range |
ul_end | End address of range. |
References Assert, EFC_FCMD_GLB, efc_get_result(), efc_perform_command(), IFLASH0_ADDR, IFLASH1_ADDR, IFLASH_ADDR, IFLASH_LOCK_REGION_SIZE, IFLASH_PAGE_SIZE, translate_address(), and UNUSED.
Referenced by run_flash_lock_test().
uint32_t flash_is_security_bit_enabled | ( | void | ) |
Check if the security bit is set or not.
1 | If the security bit is currently set. |
0 | If the security bit is currently cleared. otherwise returns an error code. |
References flash_is_gpnvm_set().
uint32_t flash_lock | ( | uint32_t | ul_start, |
uint32_t | ul_end, | ||
uint32_t * | pul_actual_start, | ||
uint32_t * | pul_actual_end | ||
) |
Lock all the regions in the given address range.
The actual lock range is reported through two output parameters.
ul_start | Start address of lock range. |
ul_end | End address of lock range. |
pul_actual_start | Start address of the actual lock range (optional). |
pul_actual_end | End address of the actual lock range (optional). |
References compute_lock_range(), EFC_FCMD_SLB, efc_perform_command(), FLASH_RC_OK, IFLASH_LOCK_REGION_SIZE, IFLASH_PAGE_SIZE, and translate_address().
Referenced by run_flash_lock_test().
uint32_t flash_read_unique_id | ( | uint32_t * | pul_data, |
uint32_t | ul_size | ||
) |
Read the flash unique ID.
pul_data | Pointer to a data buffer to store 128-bit unique ID. |
ul_size | Data buffer size in DWORD. |
References EFC, EFC_FCMD_SPUI, EFC_FCMD_STUI, efc_perform_read_sequence(), FLASH_RC_ERROR, and FLASH_RC_OK.
Referenced by run_flash_device_id_test().
uint32_t flash_set_gpnvm | ( | uint32_t | ul_gpnvm | ) |
Set the given GPNVM bit.
ul_gpnvm | GPNVM bit index. |
References EFC, EFC_FCMD_SGPB, efc_perform_command(), EFC_RC_OK, flash_is_gpnvm_set(), FLASH_RC_ERROR, FLASH_RC_INVALID, FLASH_RC_OK, FLASH_RC_YES, and GPNVM_NUM_MAX.
Referenced by flash_enable_security_bit(), and run_flash_gpnvm_test().
uint32_t flash_set_wait_state | ( | uint32_t | ul_address, |
uint32_t | ul_fws | ||
) |
Set flash wait state.
ul_address | Flash bank start address. |
ul_fws | The number of wait states in cycle (no shift). |
References efc_set_wait_state(), FLASH_RC_OK, and translate_address().
Referenced by run_flash_configure_test().
uint32_t flash_set_wait_state_adaptively | ( | uint32_t | ul_address | ) |
Set flash wait state.
ul_address | Flash bank start address. |
ul_fws | The number of wait states in cycle (no shift). |
References efc_set_wait_state(), sysclk_get_cpu_hz(), and translate_address().
Referenced by run_flash_configure_test().
uint32_t flash_unlock | ( | uint32_t | ul_start, |
uint32_t | ul_end, | ||
uint32_t * | pul_actual_start, | ||
uint32_t * | pul_actual_end | ||
) |
Unlock all the regions in the given address range.
The actual unlock range is reported through two output parameters.
ul_start | Start address of unlock range. |
ul_end | End address of unlock range. |
pul_actual_start | Start address of the actual unlock range (optional). |
pul_actual_end | End address of the actual unlock range (optional). |
References compute_lock_range(), EFC_FCMD_CLB, efc_perform_command(), FLASH_RC_OK, IFLASH_LOCK_REGION_SIZE, IFLASH_PAGE_SIZE, and translate_address().
Referenced by run_flash_erase_test(), run_flash_lock_test(), and run_flash_write_test().
uint32_t flash_write | ( | uint32_t | ul_address, |
const void * | p_buffer, | ||
uint32_t | ul_size, | ||
uint32_t | ul_erase_flag | ||
) |
Write a data buffer on flash.
ul_address | Write address. |
p_buffer | Data buffer. |
ul_size | Size of data buffer in bytes. |
ul_erase_flag | Flag to set if erase first. |
References compute_address(), EFC_FCMD_EWP, EFC_FCMD_WP, efc_get_wait_state(), efc_perform_command(), efc_set_wait_state(), FLASH_RC_OK, gs_ul_page_buffer, IFLASH_PAGE_SIZE, Min, translate_address(), and UNUSED.
Referenced by run_flash_lock_test(), and run_flash_write_test().
|
static |
Translate the given flash address to page and offset values.
pp_efc | Pointer to an EFC pointer. |
ul_addr | Address to translate. |
pus_page | The first page accessed. |
pus_offset | Byte offset in the first page. |
References Assert, EFC, flash_is_gpnvm_set(), FLASH_RC_YES, IFLASH0_ADDR, IFLASH1_ADDR, IFLASH_ADDR, and IFLASH_PAGE_SIZE.
Referenced by flash_erase_all(), flash_get_descriptor(), flash_get_wait_state(), flash_is_locked(), flash_lock(), flash_set_wait_state(), flash_set_wait_state_adaptively(), flash_unlock(), and flash_write().
|
static |
Referenced by flash_write().