STM_ATEM/User/data_storage.h
zhoujie 6297f3044d feat(adc): implement comprehensive ADC data acquisition and processing system
Add complete data acquisition pipeline with LTC2508 ADC drivers, correction algorithms,
data storage, and system monitoring. Includes ARM DSP optimized matrix operations for
sensor calibration, SD card data logging with USB mass storage, and robust error handling
with validation throughout the processing chain.

- Add LTC2508 multi-channel SPI driver with DMA support and error recovery
- Implement correction module with ARM DSP matrix operations for sensor calibration
- Add data storage system with SD card logging and configurable file management
- Integrate system monitor for health tracking and error reporting
- Enhance data packet structure with CRC validation and timestamps
- Add USB mass storage interface for SD card access
- Implement comprehensive error handling and statistics collection
2026-01-25 18:15:13 +08:00

54 lines
1.7 KiB
C

#ifndef DATA_STORAGE_H
#define DATA_STORAGE_H
#include "main.h"
#include "fatfs.h"
#include "ff.h"
#include "data_packet.h"
#include "correction.h"
#include <stdint.h>
// 数据存储配置
#define DATA_STORAGE_BUFFER_SIZE 1024 // 缓冲区大小(字节)
#define DATA_STORAGE_FILE_MAX_SIZE (10*1024*1024) // 单个文件最大10MB
#define DATA_STORAGE_PATH "0:/DATA/" // 数据存储路径
#define DATA_STORAGE_FILE_PREFIX "ADC_DATA_" // 文件名前缀
// 数据存储状态
typedef enum {
DATA_STORAGE_IDLE = 0,
DATA_STORAGE_RECORDING,
DATA_STORAGE_ERROR,
DATA_STORAGE_FULL
} DataStorageState_t;
// 数据存储统计信息
typedef struct {
uint32_t total_samples;
uint32_t current_file_size;
uint32_t file_count;
uint32_t error_count;
DataStorageState_t state;
char current_filename[64];
} DataStorageStats_t;
// 数据存储句柄
typedef struct {
FIL file;
uint8_t buffer[DATA_STORAGE_BUFFER_SIZE];
uint16_t buffer_index;
DataStorageStats_t stats;
uint8_t initialized;
} DataStorageHandle_t;
// 函数声明
HAL_StatusTypeDef DataStorage_Init(DataStorageHandle_t *handle);
HAL_StatusTypeDef DataStorage_StartRecording(DataStorageHandle_t *handle);
HAL_StatusTypeDef DataStorage_StopRecording(DataStorageHandle_t *handle);
HAL_StatusTypeDef DataStorage_WriteData(DataStorageHandle_t *handle, const DataPacket_t *packet);
HAL_StatusTypeDef DataStorage_WriteCorrectedData(DataStorageHandle_t *handle, const CorrectionResult_t *result);
HAL_StatusTypeDef DataStorage_Flush(DataStorageHandle_t *handle);
void DataStorage_GetStats(DataStorageHandle_t *handle, DataStorageStats_t *stats);
HAL_StatusTypeDef DataStorage_CreateNewFile(DataStorageHandle_t *handle);
#endif // DATA_STORAGE_H