Skip to main content

Flash Manager

The Flash Manager is used to provide an abstraction for an underlying filesystem implementation.

Due to the unique nature of the filesystem being an abstract "virtual" device, only one flash device can be registered at a time. However, generally there should be no need to have more than one filesystem. This means the Flash Manager's API functions essentially act as wrappers which calls the Operators of the underlying flash HAL device.1

info

1 Flash access is exclusive, one request at a time.

note

When working with the Flash Manager, unlike most other managers, FWK_Flash_DeviceRegister should be called before FWK_Flash_Init.

Device APIs

FWK_Flash_DeviceRegister

/**
* @brief Only one flash device is supported. Registered a flash filesystem device
* @param dev Pointer to a flash device structure
* @return int Return 0 if registration was successful
*/
int FWK_Flash_DeviceRegister(const flash_dev_t *dev);

Unlike the flow for most other managers, this function should be called before FWK_Flash_Init.

FWK_Flash_Init

/**
* @brief Init internal structures for flash.
* @return int Return 0 if the init process was successful
*/
sln_flash_status_t FWK_Flash_Init();

FWK_Flash_Deinit

/**
* @brief Deinit internal structures for flash.
* @return int Return 0 if the init process was successful
*/
sln_flash_status_t FWK_Flash_Deinit();

Operations APIs

The Flash Manager and underlying flash HAL device define only a few operations in order to keep the API simple and easy to implement. These API functions include:

  • Format
  • Save
  • Delete
  • Read
  • Make Directory
  • Append
  • Rename
  • Cleanup

While this might limit filesystem functionality, it also helps to keep the code readable, portable, and maintainable.

note

If the default list of APIs does not satisfy the requirements of a use-case, the API can always be extended or bypassed in the code directly.

FWK_Flash_Format

/**
* @brief Format the filesystem
* @return the status of formatting operation
*/
sln_flash_status_t FWK_Flash_Format();

FWK_Flash_Save

/**
* @brief Save the data into a file from the file system
* @param path Path of the file in the file system
* @param buf Buffer which contains the data that is going to be saved
* @param size Size of the buffer
* @return the status of save operation
*/
sln_flash_status_t FWK_Flash_Save(const char *path, void *buf, unsigned int size);

FWK_Flash_Append

/**
* @brief Append the data to an existing file.
* @param path Path of the file in the file system
* @param buf Buffer which contains the data that is going to be append
* @param size Size of the buffer
* @param overwrite Boolean parameter. If true the existing file will be truncated. Similar to SLN_flash_save
* @return the status of append operation
*/
sln_flash_status_t FWK_Flash_Append(const char *path, void *buf, unsigned int size, bool overwrite);

FWK_Flash_Read

note

For now read with an offset has not been implemented. This is currently planned for a future release.

/**
* @brief Read from a file
* @param path Path of the file in the file system
* @param buf Buffer in which to store the read value
* @param size Size that was read.
* @return the status of read operation
*/
sln_flash_status_t FWK_Flash_Read(const char *path, void *buf, unsigned int size);

FWK_Flash_Mkdir

/**
* @brief Make directory operation
* @param path Path of the directory in the file system
* @return the status of mkdir operation
*/
sln_flash_status_t FWK_Flash_Mkdir(const char *path);

FWK_Flash_Rm

/**
* @brief Remove file
* @param path Path of the file that shall be removed
* @return the status of rm operation
*/
sln_flash_status_t FWK_Flash_Rm(const char *path);

FWK_Flash_Rename

/**
* @brief Rename existing file
* @param OldPath Path of the file that is renamed
* @param NewPath New Path of the file
* @return status of rename operation
*/
sln_flash_status_t FWK_Flash_Rename(const char *oldPath, const char *newPath);

FWK_Flash_Cleanup

/**
* @brief Cleanup function. Might imply defragmentation, erased unused sectors etc.
*
* @param timeout Time consuming operation. Set a time constrain to be sure that is not disturbing the system.
* Timeout = 0 means no timeout
* @return status of cleanup operation
*/
sln_flash_status_t FWK_Flash_Cleanup(uint32_t timeout);