141 lines
5.3 KiB
C
141 lines
5.3 KiB
C
#ifndef FS_H
|
|
#define FS_H
|
|
|
|
#include <zephyr/fs/fs.h>
|
|
|
|
typedef struct slot_info_t {
|
|
size_t start_addr;
|
|
size_t size;
|
|
} slot_info_t;
|
|
|
|
/**
|
|
* @brief Initializes the filesystem by mounting it
|
|
*/
|
|
int fs_init(void);
|
|
|
|
/**
|
|
* @brief Puts the QSPI flash into deep sleep mode to save power
|
|
*/
|
|
int fs_pm_flash_suspend(void);
|
|
|
|
/**
|
|
* @brief Resumes the QSPI flash from deep sleep mode
|
|
*/
|
|
int fs_pm_flash_resume(void);
|
|
|
|
/**
|
|
* @brief Wrapper around fs_open that handles power management for the flash
|
|
* Resumes the flash before opening and suspends it if opening fails
|
|
* @param file Pointer to fs_file_t structure to be initialized
|
|
* @param path Path to the file to open
|
|
* @param mode Open flags (e.g. FS_O_READ, FS_O_WRITE)
|
|
* @return 0 on success, negative error code on failure
|
|
*/
|
|
int fs_pm_open(struct fs_file_t *file, const char *path, fs_mode_t mode);
|
|
|
|
/**
|
|
* @brief Wrapper around fs_close that handles power management for the flash
|
|
* Resumes the flash after closing and suspends it if closing fails
|
|
* @param file Pointer to fs_file_t structure to be closed
|
|
* @return 0 on success, negative error code on failure
|
|
*/
|
|
int fs_pm_close(struct fs_file_t *file);
|
|
|
|
/**
|
|
* @brief Wrapper around fs_opendir that handles power management for the flash
|
|
* Resumes the flash before opening and suspends it if opening fails
|
|
* @param dirp Pointer to fs_dir_t structure to be initialized
|
|
* @param path Path to the directory to open
|
|
* @return 0 on success, negative error code on failure
|
|
*/
|
|
int fs_pm_opendir(struct fs_dir_t *dirp, const char *path);
|
|
|
|
/**
|
|
* @brief Wrapper around fs_closedir that handles power management for the flash
|
|
* Resumes the flash after closing and suspends it if closing fails
|
|
* @param dirp Pointer to fs_dir_t structure to be closed
|
|
* @return 0 on success, negative error code on failure
|
|
*/
|
|
int fs_pm_closedir(struct fs_dir_t *dirp);
|
|
|
|
/**
|
|
* @brief Unlinks (deletes) a file, ensuring the flash is active during the operation
|
|
* @param path Path to the file to unlink
|
|
* @return 0 on success, negative error code on failure
|
|
*/
|
|
int fs_pm_unlink(const char *path);
|
|
|
|
/**
|
|
* @brief Wrapper around fs_statvfs that handles power management for the flash
|
|
* Resumes the flash before getting stats and suspends it afterwards
|
|
* @param path Path to the filesystem to get stats for
|
|
* @param stat Pointer to fs_statvfs structure to be filled with stats
|
|
* @return 0 on success, negative error code on failure
|
|
*/
|
|
int fs_pm_statvfs(const char *path, struct fs_statvfs *stat);
|
|
|
|
/**
|
|
* @brief Wrapper around fs_mkdir that handles power management for the flash
|
|
* Resumes the flash before creating the directory and suspends it afterwards
|
|
* @param path Path to the directory to create
|
|
* @return 0 on success, negative error code on failure
|
|
*/
|
|
int fs_pm_mkdir(const char *path);
|
|
|
|
/**
|
|
* @brief Gets the length of the audio data in a file, accounting for any metadata tags
|
|
* @param fp Pointer to an open fs_file_t structure representing the audio file
|
|
* @return Length of the audio data in bytes, or negative error code on failure
|
|
*/
|
|
int fs_get_audio_data_len(struct fs_file_t *fp);
|
|
|
|
/**
|
|
* @brief Reads audio data from a file, ensuring that it does not read past the audio data limit
|
|
* @param fp Pointer to an open fs_file_t structure representing the audio file
|
|
* @param buffer Pointer to the buffer to read data into
|
|
* @param len Maximum number of bytes to read
|
|
* @param audio_limit Maximum byte offset for audio data (e.g. file size minus metadata)
|
|
* @return Number of bytes read, or negative error code on failure
|
|
*/
|
|
int fs_read_audio(struct fs_file_t *fp, void *buffer, size_t len, size_t audio_limit);
|
|
|
|
/**
|
|
* @brief Writes a hexadecimal string as a metadata tag at the end of an audio file
|
|
* @param fp Pointer to an open fs_file_t structure representing the audio file
|
|
* @param hex_str Null-terminated string containing hexadecimal characters (0-9, a-f, A-F)
|
|
* @return 0 on success, negative error code on failure
|
|
*/
|
|
int fs_write_hex_tag(struct fs_file_t *fp, const char *hex_str);
|
|
|
|
/**
|
|
* @brief Reads a hexadecimal string from a metadata tag at the end of an audio file
|
|
* @param fp Pointer to an open fs_file_t structure representing the audio file
|
|
* @param hex_str Buffer to be filled with the hexadecimal string (must be large enough to hold the data)
|
|
* @param hex_str_size Size of the hex_str buffer
|
|
* @return 0 on success, negative error code on failure
|
|
*/
|
|
int fs_read_hex_tag(struct fs_file_t *fp, char *hex_str, size_t hex_str_size);
|
|
|
|
/**
|
|
* @brief Retrieves information about the firmware slot, such as start address and size
|
|
* @param info Pointer to slot_info_t structure to be filled with slot information
|
|
* @return 0 on success, negative error code on failure
|
|
*/
|
|
int flash_get_slot_info(slot_info_t *info);
|
|
|
|
/**
|
|
* @brief Initializes the flash for firmware upload, preparing it for receiving new firmware data
|
|
* @return 0 on success, negative error code on failure
|
|
*/
|
|
int flash_init_firmware_upload(void);
|
|
|
|
/**
|
|
* @brief Writes a block of firmware data to the flash
|
|
* @param buffer Pointer to the data buffer
|
|
* @param length Length of the data buffer
|
|
* @param is_last_block Indicates if this is the last block of the firmware
|
|
* @return 0 on success, negative error code on failure
|
|
*/
|
|
int flash_write_firmware_block(const uint8_t *buffer, size_t length, bool is_last_block);
|
|
|
|
#endif // FS_H
|