Skip to content

Commit

Permalink
applications: nrf5340_audio: Nitpick fixes in SD card module
Browse files Browse the repository at this point in the history
Found when looking through this module.
No changes to functionality.

Signed-off-by: Erik Robstad <erik.robstad@nordicsemi.no>
  • Loading branch information
Erik Robstad committed Aug 15, 2023
1 parent 63a1d9c commit 6452d2d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
9 changes: 7 additions & 2 deletions applications/nrf5340_audio/src/modules/sd_card.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
LOG_MODULE_REGISTER(sd_card, CONFIG_MODULE_SD_CARD_LOG_LEVEL);

#define SD_ROOT_PATH "/SD:/"
#define PATH_MAX_LEN 260 /* Maximum length for path support by Windows file system*/
/* Maximum length for path support by Windows file system */
#define PATH_MAX_LEN 260
#define K_SEM_OPER_TIMEOUT_MS 500

K_SEM_DEFINE(m_sem_sd_oper_ongoing, 1, 1);

static const char *sd_root_path = "/SD:";
static FATFS fat_fs;
static bool sd_init_success;
K_SEM_DEFINE(m_sem_sd_oper_ongoing, 1, 1);

static struct fs_mount_t mnt_pt = {
.type = FS_FATFS,
Expand All @@ -51,6 +53,7 @@ int sd_card_list_files(char const *const path, char *buf, size_t *buf_size)
k_sem_give(&m_sem_sd_oper_ongoing);
return -ENODEV;
}

fs_dir_t_init(&dirp);

if (path == NULL) {
Expand Down Expand Up @@ -87,6 +90,7 @@ int sd_card_list_files(char const *const path, char *buf, size_t *buf_size)
if (entry.name[0] == 0) {
break;
}

if (buf != NULL) {
size_t remaining_buf_size = *buf_size - used_buf_size;
ssize_t len = snprintk(
Expand All @@ -101,6 +105,7 @@ int sd_card_list_files(char const *const path, char *buf, size_t *buf_size)

used_buf_size += len;
}

LOG_INF("[%s] %s", entry.type == FS_DIR_ENTRY_DIR ? "DIR " : "FILE", entry.name);
}

Expand Down
21 changes: 14 additions & 7 deletions applications/nrf5340_audio/src/modules/sd_card.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
#include <stddef.h>
#include <zephyr/fs/fs.h>

/**@brief Print out the contents under SD card root path and write the content to buffer.
/**
* @brief Print out the contents under SD card root path and write the content to buffer.
*
* @param[in] path Path of the folder which is going to be listed.
* If assigned path is null, then listing the contents under
Expand All @@ -29,7 +30,8 @@
*/
int sd_card_list_files(char const *const path, char *buf, size_t *buf_size);

/**@brief Write data from buffer into the file.
/**
* @brief Write data from buffer into the file.
*
* @note If the file already exists, data will be appended to the end of the file.
*
Expand All @@ -47,7 +49,8 @@ int sd_card_list_files(char const *const path, char *buf, size_t *buf_size);
*/
int sd_card_open_write_close(char const *const filename, char const *const data, size_t *size);

/**@brief Read data from file into the buffer.
/**
* @brief Read data from file into the buffer.
*
* @param[in] filename Name of the target file for reading, the default location is
* the root directoy of SD card, accept absolute path under
Expand All @@ -65,7 +68,8 @@ int sd_card_open_write_close(char const *const filename, char const *const data,
*/
int sd_card_open_read_close(char const *const filename, char *const buf, size_t *size);

/**@brief Open file on SD card.
/**
* @brief Open file on SD card.
*
* @param[in] filename Name of file to open. Default
* location is the root directoy of SD card.
Expand All @@ -81,7 +85,8 @@ int sd_card_open_read_close(char const *const filename, char *const buf, size_t
*/
int sd_card_open(char const *const filename, struct fs_file_t *f_seg_read_entry);

/**@brief Read segment on the open file on the SD card.
/**
* @brief Read segment on the open file on the SD card.
*
* @param[out] buf Pointer to the buffer to write the read data into.
* @param[in, out] size Number of bytes to be read from file.
Expand All @@ -100,7 +105,8 @@ int sd_card_open(char const *const filename, struct fs_file_t *f_seg_read_entry)
*/
int sd_card_read(char *buf, size_t *size, struct fs_file_t *f_seg_read_entry);

/**@brief Close the file opened by the sd_card_segment_read_open function.
/**
* @brief Close the file opened by the sd_card_segment_read_open function.
*
* @param[in, out] f_seg_read_entry Pointer to a file object. After call to this
* function, the pointer is reset and can be used for
Expand All @@ -114,7 +120,8 @@ int sd_card_read(char *buf, size_t *size, struct fs_file_t *f_seg_read_entry);
*/
int sd_card_close(struct fs_file_t *f_seg_read_entry);

/**@brief Initialize the SD card interface and print out SD card details.
/**
* @brief Initialize the SD card interface and print out SD card details.
*
* @retval 0 on success.
* @retval -ENODEV SD init failed. SD card likely not inserted.
Expand Down

0 comments on commit 6452d2d

Please sign in to comment.