Initial commit: CCU621_M firmware project with BLE debug link support.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-07-08 17:28:36 +08:00
commit 9ceb218f80
1597 changed files with 724159 additions and 0 deletions
+156
View File
@@ -0,0 +1,156 @@
/**
* @file app_fatfs.h
* @brief FATFS 文件系统兼容头文件(整合自 CCU601E_D)
*
* CCU621_M 平台:FATFS 功能由 flash_file_mgr + externalflash + sdmmc 共同实现。
* 本头文件为从 CCU601E_D 移植的应用层代码提供兼容的类型和 API 声明。
*/
#ifndef APP_FATFS_H
#define APP_FATFS_H
#include <stdint.h>
#include <stdbool.h>
#include "publicdata/type.h"
#include "publicdata/public_define.h"
#define FS_PATH_LEN 64
#define FS_FILE_NAME_LEN 32
#define FS_READ_BUF_SIZE 512
#define LOG_DIR_PATH "0:/log"
#define LOG_FILE_MAX_SIZE (2*1024*1024)
#define LOG_FILE_MAX_COUNT 3
#define LOG_MAX_FILES 20
#if FATFS_ENABLE_FAULT
#define FAULT_DIR_PATH "0:/fault"
#define FAULT_FILE_MAX_SIZE (1024*500)
#define FAULT_FILE_MAX_COUNT 2
#define FAULT_MAX_FILES 20
#endif
#if FATFS_ENABLE_ORDER
#define ORDER_DIR_PATH "0:/order"
#define ORDER_FILE_MAX_SIZE (1024*500)
#define ORDER_FILE_MAX_COUNT 2
#define ORDER_MAX_FILES 20
#endif
#define LOG_SYNC_INTERVAL 10
typedef enum {
FS_STATUS_OK = 0,
FS_STATUS_INIT_FAILED,
FS_STATUS_FS_ERROR,
FS_STATUS_FILE_FULL,
FS_STATUS_WRITE_FAILED,
FS_STATUS_READ_FAILED,
FS_STATUS_FILE_NOT_FOUND,
FS_STATUS_PARAM_ERROR,
FS_STATUS_NO_SPACE
} FS_Status;
typedef struct {
char name[FS_FILE_NAME_LEN];
uint32_t size;
uint16_t year;
uint8_t month;
uint8_t day;
uint8_t hour;
uint8_t minute;
uint8_t second;
} FS_FileInfo;
typedef struct {
uint32_t start_pos;
uint32_t end_pos;
uint32_t actual_read;
} FS_ReadRange;
typedef enum {
FILE_TYPE_LOG = 0,
FILE_TYPE_FAULT,
FILE_TYPE_ORDER,
FILE_TYPE_MAX
} FileType;
typedef struct {
FileType type;
const char *dir_path;
const char *file_prefix;
const char *file_extension;
uint32_t max_file_size;
uint32_t max_file_count;
} FileManagerConfig;
/* 文件系统基础操作 */
FS_Status fs_init(void);
FS_Status fs_deinit(void);
FS_Status fs_mount(const char *path);
FS_Status fs_unmount(const char *path);
FS_Status fs_check_space(void);
bool fs_get_is_mounted(void);
/* 文件系统格式化 */
FS_Status fs_format_drive(const char *drive_path);
FS_Status fs_format_drive_fat16(const char *drive_path);
/* 目录操作 */
FS_Status fs_mkdir(const char *path);
FS_Status fs_dir_exists(const char *path, bool *exists);
FS_Status fs_list_dir(const char *path, FS_FileInfo *file_list, uint32_t *count, uint32_t max_count);
/* 文件操作 */
FS_Status fs_create_file(const char *path);
FS_Status fs_delete_file(const char *path);
FS_Status fs_file_exists(const char *path, bool *exists);
FS_Status fs_get_file_size(const char *path, uint32_t *size);
FS_Status fs_get_file_info(const char *path, FS_FileInfo *info);
FS_Status fs_rename_file(const char *old_path, const char *new_path);
FS_Status fs_copy_file(const char *src_path, const char *dst_path);
/* 文件读写(FatFs FIL 类型用 void* 代理,避免引入 ff.h */
FS_Status fs_open(void *file, const char *path, uint8_t mode);
FS_Status fs_close(void *file);
FS_Status fs_read(void *file, void *buffer, uint32_t size, uint32_t *bytes_read);
FS_Status fs_write(void *file, const void *buffer, uint32_t size, uint32_t *bytes_written);
FS_Status fs_seek(void *file, uint32_t offset);
FS_Status fs_truncate(void *file);
FS_Status fs_sync(void *file);
/* 文件内容操作 */
FS_Status fs_read_file_content(const char *path, char *buffer, uint32_t buffer_size, FS_ReadRange *range);
FS_Status fs_write_file_content(const char *path, const void *data, uint32_t size, bool append);
FS_Status fs_write_string(const char *path, const char *str, bool append);
/* 文件系统信息 */
FS_Status fs_get_volume_info(const char *path, uint32_t *total_kb, uint32_t *free_kb, float *usage_percent);
/* 通用文件管理 */
FS_Status fs_file_manager_check_and_roll_ex(const FileManagerConfig *config, const char *current_file,
uint32_t pending_write_size, char *new_filename, uint32_t new_filename_len);
FS_Status fs_file_manager_create_new(const FileManagerConfig *config, char *new_filename, uint32_t max_len);
FS_Status fs_file_manager_ensure_dir_exists(const FileManagerConfig *config);
FS_Status fs_file_manager_get_count(const FileManagerConfig *config, uint32_t *count);
FS_Status fs_file_manager_delete_oldest(const FileManagerConfig *config);
FS_Status fs_file_manager_find_latest(const FileManagerConfig *config, char *filename, uint32_t max_len);
FS_Status fs_file_manager_find_oldest(const FileManagerConfig *config, char *filename, uint32_t max_len);
FS_Status fs_file_manager_resolve_log_append_path(const FileManagerConfig *config, char *filename, uint32_t max_len);
void fs_log_set_filename_start_seq(uint8_t start_seq);
FS_Status fs_generate_timestamp_filename(const FileManagerConfig *config, char *filename, uint32_t max_len);
bool fs_is_filename_valid(const char *filename, const FileManagerConfig *config);
FS_Status fs_cleanup_invalid_files(const FileManagerConfig *config);
uint32_t fs_get_current_fat_time(void);
FS_Status fs_get_current_time_string(char *buffer, uint32_t size);
FS_Status fs_get_formatted_time_string(char *buffer, uint32_t size);
extern const FileManagerConfig g_log_file_config;
#if FATFS_ENABLE_FAULT
extern const FileManagerConfig g_fault_file_config;
#endif
#if FATFS_ENABLE_ORDER
extern const FileManagerConfig g_order_file_config;
#endif
#endif /* APP_FATFS_H */