The flash algorithm API
Flash Device Description structure:
struct FlashSector
{
unsigned long size; // Sector Size in Bytes
unsigned long addr; // Address of Sector
};
// Flash Device Info
struct FlashDevice
{
unsigned long type; // Flash Device Type
unsigned long baseAddr; // Flash Device Base Address
unsigned long totalSize; // Flash Device Total Size(Bytes)
unsigned long pageSize; // Page Size(Bytes)
unsigned char initialVal; // Initial Vaule of Erased Memory
struct FlashSector sectors[FLASH_SECTORS_NUM]; // Sectors
};
struct FlashAlgorithm
{
unsigned long version;
// Algorithm Version (FLASH_FRAMEWORK_VERSION << 16 | YourVersion)
char description[FLASH_ALGO_DESC_SIZE]; // Description of the Algorithm
struct FlashDevice deviceInfo;
};
If all the sectors in the flash have the same size, you only need to specify the size and set the sector address to an invalid value of 0xFFFFFFFF, just like the template example. Otherwise, you need to list all the sectors one by one.
FlashInit
int FlashInit (unsigned long baseAddr,unsigned long clk, unsigned long operateFuc)
* @brief Initialize before Flash Programming/Erase Functions
* @param[in] baseAddr Flash device base address.
* @param[in] clk Flash program clock.
* @param[in] operateFuc Init for what operation (FLASH_OPT_ERASECHIP/FLASH_OPT_ERASESECTORS/FLASH_OPT_PROGRAMPAGE/ FLASH_OPT_VERIFY/ FLASH_OPT_BLANKCHECK).
* @param[out] None
* @retval 0 All is OK.
* @retval others Some error occurs.
* @details This function is called before flash programming/erase.
FlashUnInit
int FlashUnInit(unsigned long operateFuc)
* @brief Un-Init after Flash Programming/Erase… Functions
* @param[in] operateFuc Init for what operation (FLASH_OPT_ERASECHIP/FLASH_OPT_ERASESECTORS/FLASH_OPT_PROGRAMPAGE/ FLASH_OPT_VERIFY/ FLASH_OPT_BLANKCHECK).
* @param[out] None
* @retval 0 All is OK.
* @retval others Some error occurs.
* @details This function is called after flash programming/erase….
FlashEraseChip
int FlashEraseChip (void)
* @brief Erase the full chip
* @param[in] None
* @param[out] None
* @retval 0 All is OK.
* @retval others Some error occurs.
* @details
FlashEraseSector
int FlashEraseSector (unsigned long sectorAddr)
* @brief Erase the select Sector
* @param[in] sectorAddr Sector's start address.
* @param[out] None
* @retval 0 All is OK.
* @retval others Some error occurs.
* @details
FlashProgramPage
int FlashProgramPage (unsigned long pageAddr, unsigned long size, unsigned char *buf)
* @brief Proram a page
*@param[in] pageAddr Page's start address
*@param[in] size Page size
*@param[in] buf source buf point
*@param[out] None
* @retval 0 All is OK.
* @retval others Some error occurs.
* @details
FlashVerify
optional function. When this function is absence, Colink will read flash memory directly to do verify.
int FlashVerify(unsigned long verifyAddr,unsigned long size,unsigned char *buf)
* @brief Page Verify Function
* @param[in] verifyAddr Verify Start Address(Usually page start address)
* @param[in] size Verify size
* @param[in] buf source buf point
* @param[out] None
* @retval 0 Verify pass.
* @retval others Some error occurs or verify failed.
* @details
FlashBlankCheck
optional function. When this function is absence, Colink will read flash memory directly to do blank check.
int FlashBlankCheck (unsigned long checkAddr,unsigned long size)
* @brief Page Blank Check Function
* @param[in] checkAddr Check Start Address(Usually page start address)
* @param[in] size Check size
* @param[out] None
* @retval 0 Check pass.
* @retval others Some error occurs or Check failed.
* @ details
* @note Sector can be significant.We check the page rather than the sector, having regard to the actual size of the ram.