Audio added to firmware, Website File handling

This commit is contained in:
2026-04-01 16:06:40 +02:00
parent 01448223ad
commit 947346777f
22 changed files with 951 additions and 123 deletions

View File

@@ -1,5 +1,6 @@
menuconfig FS_MGMT
bool "File System Management"
default y
select FLASH
select FLASH_MAP
select FILE_SYSTEM
@@ -11,6 +12,11 @@ menuconfig FS_MGMT
Library for initializing and managing the file system.
if FS_MGMT
config FS_MGMT_MAX_PATH_LENGTH
int "Maximum File Path Length"
default 32
help
Set the maximum length for file paths in the file system. Default is 32 characters.
config FS_MGMT_MOUNT_POINT
string "Littlefs Mount Point"
default "/lfs"

View File

@@ -4,32 +4,43 @@
#include <zephyr/fs/fs.h>
#include "buzz_proto.h"
#define FS_MGMT_MAX_PATH_LENGTH 32
#define FS_AUDIO_PATH CONFIG_FS_MGMT_MOUNT_POINT CONFIG_FS_MGMT_AUDIO_SUBDIR
#define FS_SYSTEM_PATH CONFIG_FS_MGMT_MOUNT_POINT CONFIG_FS_MGMT_SYSTEM_SUBDIR
/**
* @brief Initializes the filesystem management module.
*/
int fs_mgmt_init(void);
#define MAX_FILE_NAME_LEN(target, path) \
((int)(sizeof(target) - (sizeof(path)) - 1))
/** @brief Assemble a full path from a base path and a filename
* Ensures that the resulting path fits into the target buffer and is null-terminated. If the filename is too long, it will be truncated to fit.
* @param buffer Target buffer to hold the assembled path
* @param path Base path (e.g. "/sys" or "/audio")
* @param filename Name of the file to append to the base path
*/
#define FS_MGMT_ASSEMBLE_PATH(buffer, path, filename) \
snprintf(buffer, sizeof(buffer), \
"%s/%.*s", \
path, \
MAX_FILE_NAME_LEN(buffer, path), \
filename)
/**
* @brief OP-Codes for the FS write thread
*/
enum fs_write_op {
enum fs_write_op
{
FS_WRITE_OP_FILE_START,
FS_WRITE_OP_FILE_CHUNK,
FS_WRITE_OP_FILE_END,
FS_WRITE_OP_TAGS_START, // Schon mal vorgesehen
FS_WRITE_OP_FW_START, // Schon mal vorgesehen
FS_WRITE_OP_TAGS_START, // Schon mal vorgesehen
FS_WRITE_OP_FW_START, // Schon mal vorgesehen
FS_WRITE_OP_ABORT
};
/**
* @brief Structure representing a write message for the FS write thread
*/
struct fs_write_msg {
struct fs_write_msg
{
enum fs_write_op op;
uint8_t *slab_ptr; /* Basis-Pointer des Memory-Slabs (für k_mem_slab_free) */
uint16_t data_offset; /* Offset ab dem slab_ptr, wo die Nutzdaten beginnen */
@@ -135,7 +146,7 @@ int fs_mgmt_pm_rm_recursive(char *path, size_t max_len);
* @param fp Pointer to an open fs_file_t structure representing the file
* @return Length of the audio data on success, negative error code on failure
*/
ssize_t fs_get_audio_data_len(struct fs_file_t *fp);
ssize_t fs_mgmt_get_audio_data_len(struct fs_file_t *fp);
/**
* @brief Submits a write message to the FS write thread, which will handle writing data to the filestem asynchronously, ensuring the flash is active during the operation

View File

@@ -7,6 +7,7 @@
#include "fs_mgmt.h"
#include "buzz_proto.h"
#include "event_mgmt.h"
LOG_MODULE_REGISTER(fs_mgmt, CONFIG_FS_MGMT_LOG_LEVEL);
@@ -54,7 +55,7 @@ static struct
{
fs_thread_state_t state;
struct fs_file_t file;
char filename[FS_MGMT_MAX_PATH_LENGTH];
char filename[CONFIG_FS_MGMT_MAX_PATH_LENGTH];
uint32_t crc32;
uint16_t unacked_chunks;
off_t audio_len; // Offeset für Tags
@@ -386,7 +387,7 @@ int fs_mgmt_pm_mkdir_recursive(char *path)
return rc;
}
int fs_mgmt_init(void)
static int fs_mgmt_init(void)
{
k_mutex_init(&flash_pm_lock);
@@ -405,11 +406,19 @@ int fs_mgmt_init(void)
LOG_ERR("Error mounting filesystem: %d", rc);
return rc;
}
fs_mgmt_pm_flash_suspend();
LOG_DBG("Filesystem mounted successfully");
event_mgmt_set_event(EVENT_MGMT_FS_READY);
return 0;
}
/* * APPLICATION Level sorgt dafür, dass die Treiber (Flash/QSPI)
* bereits bereit sind.
* CONFIG_APPLICATION_INIT_PRIORITY ist ein guter Standardwert (meist 90).
*/
SYS_INIT(fs_mgmt_init, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY);
static int fs_get_tag_bounds(struct fs_file_t *fp, off_t file_size,
size_t *audio_limit, size_t *payload_len, bool *has_tag)
{
@@ -465,7 +474,7 @@ static int fs_get_tag_bounds(struct fs_file_t *fp, off_t file_size,
return 0;
}
ssize_t fs_get_audio_data_len(struct fs_file_t *fp)
ssize_t fs_mgmt_get_audio_data_len(struct fs_file_t *fp)
{
off_t file_size;
size_t audio_limit = 0U;
@@ -572,8 +581,7 @@ static void fs_thread_entry(void *p1, void *p2, void *p3)
if (rc == 0)
{
// ssize_t audio_len = fs_get_audio_data_len(&write_ctx.file);
ssize_t audio_len = 0; /* Zum Testen, da wir ja kein echtes FS-Backend haben */
ssize_t audio_len = fs_mgmt_get_audio_data_len(&write_ctx.file);
if (audio_len < 0)
{
LOG_ERR("Failed to get audio length: %d", (int)audio_len);
@@ -587,7 +595,7 @@ static void fs_thread_entry(void *p1, void *p2, void *p3)
if (rc != 0)
{
LOG_ERR("Failed to truncate file: %d", rc);
// fs_mgmt_pm_close(&write_ctx.file);
fs_mgmt_pm_close(&write_ctx.file);
buzz_proto_send_error_reusing_slab(msg.reply_cb, abs(rc), msg.slab_ptr);
break;
}