feat: move configs into libs, add filesystem support
All checks were successful
Deploy Docs / build-and-deploy (push) Successful in 12s
All checks were successful
Deploy Docs / build-and-deploy (push) Successful in 12s
This commit is contained in:
@@ -4,4 +4,5 @@ add_subdirectory(ble_mgmt)
|
||||
add_subdirectory(thread_mgmt)
|
||||
add_subdirectory(lasertag_utils)
|
||||
add_subdirectory(ir)
|
||||
add_subdirectory(game_mgmt)
|
||||
add_subdirectory(game_mgmt)
|
||||
add_subdirectory(fs_mgmt)
|
||||
@@ -3,4 +3,5 @@ rsource "lasertag_utils/Kconfig"
|
||||
rsource "thread_mgmt/Kconfig"
|
||||
rsource "ble_mgmt/Kconfig"
|
||||
rsource "ir/Kconfig"
|
||||
rsource "game_mgmt/Kconfig"
|
||||
rsource "game_mgmt/Kconfig"
|
||||
rsource "fs_mgmt/Kconfig"
|
||||
@@ -1,6 +1,8 @@
|
||||
menuconfig BLE_MGMT
|
||||
bool "BLE Management"
|
||||
depends on BT
|
||||
select BT
|
||||
select BT_PERIPHERAL
|
||||
select BT_DEVICE_NAME_DYNAMIC
|
||||
help
|
||||
Library for BLE provisioning of the lasertag device.
|
||||
|
||||
@@ -9,9 +11,20 @@ if BLE_MGMT
|
||||
module-str = ble_mgmt
|
||||
source "subsys/logging/Kconfig.template.log_config"
|
||||
|
||||
config BLE_MGMT_CAN_BE_GAME_LEADER
|
||||
config BLE_MGMT_CAN_BE_GAME_LEADER
|
||||
bool "Can be game leader"
|
||||
default n
|
||||
help
|
||||
Allow this device to take the game leader role in the lasertag game.
|
||||
|
||||
config BT_DEVICE_NAME
|
||||
default "Lasertag Device"
|
||||
config BT_L2CAP_TX_MTU
|
||||
default 252
|
||||
config BT_BUF_ACL_RX_SIZE
|
||||
default 251
|
||||
config BT_BUF_ACL_TX_SIZE
|
||||
default 251
|
||||
config BT_ATT_PREPARE_COUNT
|
||||
default 5
|
||||
endif
|
||||
@@ -2,4 +2,16 @@ if(CONFIG_FS_MGMT)
|
||||
zephyr_library()
|
||||
zephyr_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()
|
||||
@@ -1,6 +1,7 @@
|
||||
menuconfig FS_MGMT
|
||||
bool "File System Management"
|
||||
select FLASH
|
||||
select FLASH_MAP
|
||||
select FILE_SYSTEM
|
||||
select FILE_SYSTEM_LITTLEFS
|
||||
select FILE_SYSTEM_MKFS
|
||||
|
||||
7
firmware/libs/fs_mgmt/include/fs_mgmt.h
Normal file
7
firmware/libs/fs_mgmt/include/fs_mgmt.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#ifndef FS_MGMT_H
|
||||
#define FS_MGMT_H
|
||||
|
||||
int fs_mgmt_init(void);
|
||||
|
||||
#endif
|
||||
|
||||
78
firmware/libs/fs_mgmt/src/fs_mgmt.c
Normal file
78
firmware/libs/fs_mgmt/src/fs_mgmt.c
Normal file
@@ -0,0 +1,78 @@
|
||||
#include <zephyr/fs/fs.h>
|
||||
#include <zephyr/fs/littlefs.h>
|
||||
#include <zephyr/storage/flash_map.h>
|
||||
#include <zephyr/logging/log.h>
|
||||
#include <fs_mgmt.h>
|
||||
|
||||
LOG_MODULE_REGISTER(fs_mgmt, CONFIG_FS_MGMT_LOG_LEVEL);
|
||||
#define STORAGE_PARTITION_ID FIXED_PARTITION_ID(littlefs_storage)
|
||||
FS_LITTLEFS_DECLARE_DEFAULT_CONFIG(fs_storage_data);
|
||||
|
||||
static struct fs_mount_t fs_storage_mnt = {
|
||||
.type = FS_LITTLEFS,
|
||||
.fs_data = &fs_storage_data,
|
||||
.storage_dev = (void *)STORAGE_PARTITION_ID,
|
||||
.mnt_point = "/lfs",
|
||||
};
|
||||
|
||||
int fs_mgmt_init(void)
|
||||
{
|
||||
int rc;
|
||||
LOG_DBG("Initializing filesystem management module");
|
||||
rc = fs_mount(&fs_storage_mnt);
|
||||
if (rc)
|
||||
{
|
||||
LOG_ERR("Filesystem mount failed (err %d)", rc);
|
||||
return rc;
|
||||
}
|
||||
else
|
||||
{
|
||||
struct fs_statvfs stat;
|
||||
uint64_t total;
|
||||
uint64_t free;
|
||||
|
||||
LOG_DBG("Filesystem mounted successfully at %s", fs_storage_mnt.mnt_point);
|
||||
|
||||
rc = fs_statvfs(fs_storage_mnt.mnt_point, &stat);
|
||||
if (rc == 0)
|
||||
{
|
||||
total = (uint64_t)stat.f_blocks * (uint64_t)stat.f_frsize;
|
||||
free = (uint64_t)stat.f_bfree * (uint64_t)stat.f_frsize;
|
||||
uint64_t total_kb = total / 1024;
|
||||
uint64_t free_kb = free / 1024;
|
||||
uint64_t used_kb = total_kb - free_kb;
|
||||
uint64_t used_pct_x10 = 0;
|
||||
LOG_DBG("Filesystem total size/used/free size: %4llu/%4llu/%4llu KB",
|
||||
(unsigned long long)total_kb,
|
||||
(unsigned long long)used_kb,
|
||||
(unsigned long long)free_kb);
|
||||
if (total_kb > 0)
|
||||
{
|
||||
used_pct_x10 = (used_kb * 1000) / total_kb;
|
||||
}
|
||||
if (used_pct_x10 >= 900)
|
||||
{
|
||||
LOG_ERR("Filesystem used: %llu.%llu%%",
|
||||
(unsigned long long)(used_pct_x10 / 10),
|
||||
(unsigned long long)(used_pct_x10 % 10));
|
||||
}
|
||||
else if (used_pct_x10 >= 750)
|
||||
{
|
||||
LOG_WRN("Filesystem used: %llu.%llu%%",
|
||||
(unsigned long long)(used_pct_x10 / 10),
|
||||
(unsigned long long)(used_pct_x10 % 10));
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_DBG("Filesystem used: %llu.%llu%%",
|
||||
(unsigned long long)(used_pct_x10 / 10),
|
||||
(unsigned long long)(used_pct_x10 % 10));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_WRN("Filesystem statvfs failed (err %d)", rc);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user