update g_log_switch
This commit is contained in:
@@ -19,7 +19,12 @@
|
||||
void device_reboot(void);
|
||||
extern void SetRoleSwitchFlag(unsigned mode);
|
||||
extern unsigned g_3d_fps;
|
||||
#if DEBUG_MEMORY_LOG_ENABLED
|
||||
unsigned g_log_switch = 1;
|
||||
#else
|
||||
unsigned g_log_switch = 0;
|
||||
#endif
|
||||
|
||||
|
||||
// 常量定义
|
||||
#define EQ_DISABLED_MODE 10 // 禁用EQ的模式编号
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,233 +0,0 @@
|
||||
#include <stdlib.h>
|
||||
#include <xs1.h>
|
||||
#include <platform.h>
|
||||
#include "lfs.h"
|
||||
#include "rtos_qspi_flash.h"
|
||||
#include "swlock.h"
|
||||
#include "debug_print.h"
|
||||
// variables used by the filesystem
|
||||
lfs_t lfs;
|
||||
lfs_file_t file;
|
||||
swlock_t lfs_lock = SWLOCK_INITIAL_VALUE;
|
||||
|
||||
static rtos_qspi_flash_t qspi_flash_ctx_s;
|
||||
#define FLASH_CLKBLK XS1_CLKBLK_3
|
||||
#ifndef FS_BASE_ADDR
|
||||
#define FS_BASE_ADDR 0x1da000
|
||||
#endif
|
||||
#define SECTOR_SIZE 4096
|
||||
rtos_qspi_flash_t *qspi_flash_ctx = &qspi_flash_ctx_s;
|
||||
|
||||
__attribute__((fptrgroup(" local_block_device_read_fptr_grp")))
|
||||
int local_block_device_read(const struct lfs_config *c, lfs_block_t block,
|
||||
lfs_off_t off, void *buffer, lfs_size_t size)
|
||||
{
|
||||
unsigned address = (FS_BASE_ADDR + block * SECTOR_SIZE + off);
|
||||
qspi_flash_ctx->read(qspi_flash_ctx, buffer, address, size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
__attribute__((fptrgroup(" local_block_device_prog_fptr_grp")))
|
||||
int local_block_device_prog(const struct lfs_config *c, lfs_block_t block,
|
||||
lfs_off_t off, const void *buffer, lfs_size_t size)
|
||||
{
|
||||
unsigned address = (FS_BASE_ADDR + block * SECTOR_SIZE + off);
|
||||
qspi_flash_ctx->write(qspi_flash_ctx, buffer, address, size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
__attribute__((fptrgroup(" local_block_device_erase_fptr_grp")))
|
||||
int local_block_device_erase(const struct lfs_config *c, lfs_block_t block)
|
||||
{
|
||||
unsigned address = (FS_BASE_ADDR + block * SECTOR_SIZE);
|
||||
qspi_flash_ctx->erase(qspi_flash_ctx, address, SECTOR_SIZE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
__attribute__((fptrgroup(" local_block_device_sync_fptr_grp")))
|
||||
int local_block_device_sync(const struct lfs_config *c)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// configuration of the filesystem is provided by this struct
|
||||
const struct lfs_config cfg = {
|
||||
// block device operations
|
||||
.read = local_block_device_read,
|
||||
.prog = local_block_device_prog,
|
||||
.erase = local_block_device_erase,
|
||||
.sync = local_block_device_sync,
|
||||
|
||||
// block device configuration
|
||||
.read_size = 16,
|
||||
.prog_size = 16,
|
||||
.block_size = 4096,
|
||||
.block_count = 128,
|
||||
.cache_size = 16,
|
||||
.lookahead_size = 16,
|
||||
.block_cycles = 500,
|
||||
};
|
||||
|
||||
int lfs_init(void) {
|
||||
swlock_acquire(&lfs_lock);
|
||||
rtos_qspi_flash_init(
|
||||
qspi_flash_ctx,
|
||||
FLASH_CLKBLK,
|
||||
XS1_PORT_1B,
|
||||
XS1_PORT_1C,
|
||||
XS1_PORT_4B,
|
||||
NULL);
|
||||
|
||||
|
||||
// mount the filesystem
|
||||
int err = lfs_mount(&lfs, &cfg);
|
||||
|
||||
// reformat if we can't mount the filesystem
|
||||
// this should only happen on the first boot
|
||||
if (err) {
|
||||
debug_printf("no lfs partiton is found, formating ...\n");
|
||||
lfs_format(&lfs, &cfg);
|
||||
lfs_mount(&lfs, &cfg);
|
||||
swlock_release(&lfs_lock);
|
||||
return -1;
|
||||
}
|
||||
swlock_release(&lfs_lock);
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
void lfs_deinit(void) {
|
||||
swlock_acquire(&lfs_lock);
|
||||
lfs_unmount(&lfs);
|
||||
swlock_release(&lfs_lock);
|
||||
}
|
||||
|
||||
#pragma stackfunction 1300
|
||||
void lfs_read_config(unsigned char * config, unsigned char * buffer, unsigned size)
|
||||
{
|
||||
swlock_acquire(&lfs_lock);
|
||||
debug_printf("lfs_read_config: %s, size: %d\n", config, size);
|
||||
int result = lfs_file_open(&lfs, &file, config, LFS_O_RDWR | LFS_O_CREAT);
|
||||
debug_printf("lfs_read_config: %s, result: %d\n", config, result);
|
||||
if (result != 0) {
|
||||
debug_printf("lfs_read_config: %s, open file failed\n", config);
|
||||
swlock_release(&lfs_lock);
|
||||
return;
|
||||
}
|
||||
debug_printf("lfs_read_config: %s, file opened\n", config);
|
||||
result = lfs_file_read(&lfs, &file, buffer, size);
|
||||
debug_printf("lfs_read_config: %s, result: %d\n", config, result);
|
||||
if (result < 0) {
|
||||
debug_printf("lfs_read_config: %s, read file failed, error: %d\n", config, result);
|
||||
// Update: Added lfs_file_close to ensure file is closed even on error.
|
||||
// Missing this caused subsequent open calls to assert/crash.
|
||||
lfs_file_close(&lfs, &file);
|
||||
swlock_release(&lfs_lock);
|
||||
return;
|
||||
}
|
||||
lfs_file_close(&lfs, &file);
|
||||
swlock_release(&lfs_lock);
|
||||
}
|
||||
|
||||
|
||||
#pragma stackfunction 1300
|
||||
void lfs_write_config(unsigned char * config, unsigned char * buffer, unsigned size)
|
||||
{
|
||||
swlock_acquire(&lfs_lock);
|
||||
debug_printf("lfs_write_config: %s, size: %d\n", config, size);
|
||||
int result = lfs_file_open(&lfs, &file, config, LFS_O_RDWR | LFS_O_CREAT);
|
||||
if (result != 0) {
|
||||
debug_printf("lfs_write_config: open file failed\n");
|
||||
swlock_release(&lfs_lock);
|
||||
return;
|
||||
}
|
||||
result = lfs_file_rewind(&lfs, &file);
|
||||
if (result != 0) {
|
||||
debug_printf("lfs_write_config: rewind file failed\n");
|
||||
// Update: Added lfs_file_close to prevent file remaining open if rewind fails.
|
||||
lfs_file_close(&lfs, &file);
|
||||
swlock_release(&lfs_lock);
|
||||
return;
|
||||
}
|
||||
lfs_file_write(&lfs, &file, buffer, size);
|
||||
lfs_file_close(&lfs, &file);
|
||||
swlock_release(&lfs_lock);
|
||||
}
|
||||
|
||||
|
||||
// 检查文件是否存在
|
||||
int lfs_file_exists(const char * file_path)
|
||||
{
|
||||
swlock_acquire(&lfs_lock);
|
||||
lfs_file_t file;
|
||||
int result = lfs_file_open(&lfs, &file, file_path, LFS_O_RDONLY);
|
||||
if (result == 0) {
|
||||
lfs_file_close(&lfs, &file);
|
||||
swlock_release(&lfs_lock);
|
||||
return 1; // 文件存在
|
||||
}
|
||||
swlock_release(&lfs_lock);
|
||||
return 0; // 文件不存在
|
||||
}
|
||||
|
||||
// EQ参数专用读写函数
|
||||
void lfs_read_eq_config(const char * file_path, unsigned char * buffer, unsigned size)
|
||||
{
|
||||
lfs_file_open(&lfs, &file, file_path, LFS_O_RDONLY);
|
||||
lfs_file_read(&lfs, &file, buffer, size);
|
||||
lfs_file_close(&lfs, &file);
|
||||
}
|
||||
|
||||
void lfs_write_eq_config(const char * file_path, unsigned char * buffer, unsigned size)
|
||||
{
|
||||
lfs_file_open(&lfs, &file, file_path, LFS_O_RDWR | LFS_O_CREAT);
|
||||
lfs_file_rewind(&lfs, &file);
|
||||
lfs_file_write(&lfs, &file, buffer, size);
|
||||
lfs_file_close(&lfs, &file);
|
||||
}
|
||||
|
||||
|
||||
// 删除文件
|
||||
int lfs_remove_file(const char * file_path)
|
||||
{
|
||||
return lfs_remove(&lfs, file_path);
|
||||
}
|
||||
|
||||
// 创建目录(通过创建临时文件然后删除)
|
||||
int lfs_create_directory(const char * dir_path)
|
||||
{
|
||||
char temp_file[256];
|
||||
snprintf(temp_file, sizeof(temp_file), "%s/.dir", dir_path);
|
||||
|
||||
lfs_file_t file;
|
||||
int result = lfs_file_open(&lfs, &file, temp_file, LFS_O_RDWR | LFS_O_CREAT);
|
||||
if (result == 0) {
|
||||
lfs_file_close(&lfs, &file);
|
||||
lfs_remove(&lfs, temp_file);
|
||||
return 0; // 成功
|
||||
}
|
||||
return -1; // 失败
|
||||
}
|
||||
|
||||
#if 0
|
||||
// read current count
|
||||
uint32_t boot_count = 0;
|
||||
lfs_file_open(&lfs, &file, "boot_count", LFS_O_RDWR | LFS_O_CREAT);
|
||||
lfs_file_read(&lfs, &file, &boot_count, sizeof(boot_count));
|
||||
|
||||
// update boot count
|
||||
boot_count += 1;
|
||||
lfs_file_rewind(&lfs, &file);
|
||||
for (int i = 0; i < 100; i++)
|
||||
lfs_file_write(&lfs, &file, &boot_count, sizeof(boot_count));
|
||||
|
||||
// remember the storage is not updated until the file is closed successfully
|
||||
lfs_file_close(&lfs, &file);
|
||||
|
||||
// release any resources we were using
|
||||
lfs_unmount(&lfs);
|
||||
|
||||
// print the boot count
|
||||
printf("boot_count: %d\n", boot_count);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user