zwischenstand

This commit is contained in:
2026-03-19 07:39:25 +01:00
parent ff63dda086
commit b863b04505
15 changed files with 647 additions and 337 deletions

View File

@@ -514,8 +514,8 @@ static void fs_thread_entry(void *p1, void *p2, void *p3)
LOG_WRN("Write timeout! Aborting transfer.");
if (write_ctx.state == FS_STATE_RECEIVING_FILE)
{
fs_mgmt_pm_close(&write_ctx.file);
fs_mgmt_pm_unlink(write_ctx.filename);
// fs_mgmt_pm_close(&write_ctx.file);
// fs_mgmt_pm_unlink(write_ctx.filename);
}
write_ctx.state = FS_STATE_IDLE;
continue;
@@ -536,8 +536,8 @@ static void fs_thread_entry(void *p1, void *p2, void *p3)
memcpy(write_ctx.filename, msg.slab_ptr + msg.data_offset, msg.data_len);
write_ctx.filename[msg.data_len] = '\0';
fs_mgmt_pm_unlink(write_ctx.filename);
rc = fs_mgmt_pm_open(&write_ctx.file, write_ctx.filename, FS_O_CREATE | FS_O_WRITE);
// fs_mgmt_pm_unlink(write_ctx.filename);
// rc = fs_mgmt_pm_open(&write_ctx.file, write_ctx.filename, FS_O_CREATE | FS_O_WRITE);
if (rc == 0)
{
@@ -568,12 +568,12 @@ static void fs_thread_entry(void *p1, void *p2, void *p3)
write_ctx.filename[msg.data_len] = '\0';
/* Datei öffnen: Nur Lese- und Schreibrechte, Datei muss bereits existieren */
int rc = fs_mgmt_pm_open(&write_ctx.file, write_ctx.filename, FS_O_READ | FS_O_WRITE);
// int rc = fs_mgmt_pm_open(&write_ctx.file, write_ctx.filename, FS_O_READ | FS_O_WRITE);
if (rc == 0)
{
ssize_t audio_len = fs_get_audio_data_len(&write_ctx.file);
// 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 */
if (audio_len < 0)
{
LOG_ERR("Failed to get audio length: %d", (int)audio_len);
@@ -583,17 +583,17 @@ static void fs_thread_entry(void *p1, void *p2, void *p3)
}
/* Datei ab dem Ende der Audiodaten abschneiden (alte Tags entfernen) */
rc = fs_truncate(&write_ctx.file, audio_len);
// rc = fs_truncate(&write_ctx.file, audio_len);
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;
}
/* File-Pointer exakt an das neue Ende (audio_len) setzen */
fs_seek(&write_ctx.file, audio_len, FS_SEEK_SET);
// fs_seek(&write_ctx.file, audio_len, FS_SEEK_SET);
write_ctx.state = FS_STATE_RECEIVING_TAGS;
write_ctx.crc32 = 0;
@@ -622,8 +622,8 @@ static void fs_thread_entry(void *p1, void *p2, void *p3)
case FS_STATE_RECEIVING_FILE:
if (msg.op == FS_WRITE_OP_FILE_CHUNK && msg.slab_ptr)
{
ssize_t written = fs_write(&write_ctx.file, msg.slab_ptr + msg.data_offset, msg.data_len);
// ssize_t written = fs_write(&write_ctx.file, msg.slab_ptr + msg.data_offset, msg.data_len);
ssize_t written = msg.data_len; /* Zum Testen, da wir ja kein echtes FS-Backend haben */
if (written == msg.data_len)
{
write_ctx.crc32 = crc32_ieee_update(write_ctx.crc32, msg.slab_ptr + msg.data_offset, msg.data_len);
@@ -649,7 +649,7 @@ static void fs_thread_entry(void *p1, void *p2, void *p3)
}
else if (msg.op == FS_WRITE_OP_FILE_END)
{
fs_mgmt_pm_close(&write_ctx.file);
// fs_mgmt_pm_close(&write_ctx.file);
write_ctx.state = FS_STATE_IDLE;
if (write_ctx.crc32 == msg.metadata)
@@ -660,14 +660,14 @@ static void fs_thread_entry(void *p1, void *p2, void *p3)
else
{
LOG_ERR("CRC Mismatch! Expected: 0x%08X, Got: 0x%08X", msg.metadata, write_ctx.crc32);
fs_mgmt_pm_unlink(write_ctx.filename);
// fs_mgmt_pm_unlink(write_ctx.filename);
buzz_proto_send_error_reusing_slab(msg.reply_cb, EBADMSG, msg.slab_ptr);
}
}
else if (msg.op == FS_WRITE_OP_ABORT)
{
fs_mgmt_pm_close(&write_ctx.file);
fs_mgmt_pm_unlink(write_ctx.filename);
// fs_mgmt_pm_close(&write_ctx.file);
// fs_mgmt_pm_unlink(write_ctx.filename);
write_ctx.state = FS_STATE_IDLE;
if (msg.slab_ptr)
buzz_proto_buf_free(&msg.slab_ptr);
@@ -677,8 +677,8 @@ static void fs_thread_entry(void *p1, void *p2, void *p3)
case FS_STATE_RECEIVING_TAGS:
if (msg.op == FS_WRITE_OP_FILE_CHUNK && msg.slab_ptr)
{
ssize_t written = fs_write(&write_ctx.file, msg.slab_ptr + msg.data_offset, msg.data_len);
// ssize_t written = fs_write(&write_ctx.file, msg.slab_ptr + msg.data_offset, msg.data_len);
ssize_t written = msg.data_len; /* Zum Testen, da wir ja kein echtes FS-Backend haben */
if (written == msg.data_len)
{
write_ctx.crc32 = crc32_ieee_update(write_ctx.crc32, msg.slab_ptr + msg.data_offset, msg.data_len);
@@ -699,8 +699,8 @@ static void fs_thread_entry(void *p1, void *p2, void *p3)
else
{
LOG_ERR("Flash write failed during tags transfer!");
fs_truncate(&write_ctx.file, write_ctx.audio_len); /* Rollback */
fs_mgmt_pm_close(&write_ctx.file);
// fs_truncate(&write_ctx.file, write_ctx.audio_len); /* Rollback */
// fs_mgmt_pm_close(&write_ctx.file);
write_ctx.state = FS_STATE_IDLE;
buzz_proto_send_error_reusing_slab(msg.reply_cb, EIO, msg.slab_ptr);
}
@@ -716,16 +716,16 @@ static void fs_thread_entry(void *p1, void *p2, void *p3)
else
{
LOG_ERR("Tags CRC Mismatch! Expected: 0x%08X, Got: 0x%08X", msg.metadata, write_ctx.crc32);
fs_truncate(&write_ctx.file, write_ctx.audio_len); /* Rollback */
fs_mgmt_pm_close(&write_ctx.file);
// fs_truncate(&write_ctx.file, write_ctx.audio_len); /* Rollback */
// fs_mgmt_pm_close(&write_ctx.file);
buzz_proto_send_error_reusing_slab(msg.reply_cb, EBADMSG, msg.slab_ptr);
}
write_ctx.state = FS_STATE_IDLE;
}
else if (msg.op == FS_WRITE_OP_ABORT)
{
fs_truncate(&write_ctx.file, write_ctx.audio_len); /* Rollback */
fs_mgmt_pm_close(&write_ctx.file);
// fs_truncate(&write_ctx.file, write_ctx.audio_len); /* Rollback */
// fs_mgmt_pm_close(&write_ctx.file);
write_ctx.state = FS_STATE_IDLE;
if (msg.slab_ptr)
buzz_proto_buf_free(&msg.slab_ptr);

View File

@@ -0,0 +1,17 @@
if(CONFIG_FS_MGMT)
zephyr_library()
zephyr_library_sources(src/fs_mgmt.c)
zephyr_include_directories(include)
if(CONFIG_FILE_SYSTEM_LITTLEFS)
if(DEFINED ZEPHYR_LITTLEFS_MODULE_DIR)
zephyr_include_directories(${ZEPHYR_LITTLEFS_MODULE_DIR})
elseif(DEFINED WEST_TOPDIR)
zephyr_include_directories(${WEST_TOPDIR}/modules/fs/littlefs)
endif()
if(DEFINED ZEPHYR_BASE)
zephyr_include_directories(${ZEPHYR_BASE}/modules/littlefs)
endif()
endif()
endif()

View File

@@ -0,0 +1,64 @@
menuconfig FS_MGMT
bool "File System Management"
select FLASH
select FLASH_MAP
select FILE_SYSTEM
select FILE_SYSTEM_LITTLEFS
select FILE_SYSTEM_MKFS
select FLASH_PAGE_LAYOUT
select NORDIC_QSPI_NOR if SOC_SERIES_NRF52X && (SOC_NRF52840_QIAA || SOC_NRF52833_QIAA)
help
Library for initializing and managing the file system.
if FS_MGMT
config FS_MGMT_MOUNT_POINT
string "Littlefs Mount Point"
default "/lfs"
help
Set the mount point for the Littlefs file system. Default is "/lfs".
config FS_MGMT_AUDIO_SUBDIR
string "Audio File Path"
default "/a"
help
Set the path for the audio file within the file system. Default is "/a".
config FS_MGMT_SYSTEM_SUBDIR
string "System File Path"
default "/sys"
help
Set the path for the system file within the file system. Default is "/sys".
config FS_MGMT_THREAD_STACK_SIZE
int "File System Management Thread Stack Size"
default 2048
help
Set the stack size for the file system management thread. Default is 2048 bytes.
config FS_MGMT_THREAD_PRIORITY
int "File System Management Thread Priority"
default 6
help
Set the priority for the file system management thread. Default is 6.
if SOC_SERIES_NRF52X
config PM_PARTITION_REGION_LITTLEFS_EXTERNAL
default y
config PM_PARTITION_SIZE_LITTLEFS
default 0x1000000
endif # SOC_SERIES_NRF52X
config FS_LITTLEFS_READ_SIZE
default 256
config FS_LITTLEFS_PROG_SIZE
default 256
config FS_LITTLEFS_CACHE_SIZE
default 4096
config FS_LITTLEFS_LOOKAHEAD_SIZE
default 512
module = FS_MGMT
module-str = fs_mgmt
source "subsys/logging/Kconfig.template.log_config"
endif # FS_MGMT