238 lines
6.4 KiB
C
238 lines
6.4 KiB
C
/**
|
|
* @file fal_execution.h
|
|
* @author xxx
|
|
* @date 2023-12-29 11:28:33
|
|
* @brief
|
|
* @copyright Copyright (c) 2024 by xxx, All Rights Reserved.
|
|
*/
|
|
|
|
/**
|
|
* 2024-01-04 模块开发完成,测试通过
|
|
*/
|
|
#ifndef _FAL_EXECUTION_
|
|
#define _FAL_EXECUTION_
|
|
#include <string.h>
|
|
#include <fal.h>
|
|
#include "flashdb.h"
|
|
#include "flow.h"
|
|
typedef enum
|
|
{
|
|
KEY_NOINIT_DATA, // 非初始化数据
|
|
KEY_DEVICE, // 设备信息
|
|
KEY_REAL_TIME_DATA, // 实时数据
|
|
KEY_DIAGNOSIS_RESULT, // 诊断结果
|
|
KEY_MAX,
|
|
} fal_key_e;
|
|
|
|
typedef enum
|
|
{
|
|
FAL_EXECUTION_EEPROM_M95_1,
|
|
FAL_EXECUTION_EEPROM_M95_2,
|
|
FAL_EXECUTION_EEPROM_FM24,
|
|
FAL_EXECUTION_MAX,
|
|
} fal_execution_e;
|
|
|
|
typedef struct
|
|
{
|
|
BOOL enable; // 是否使能
|
|
BOOL statistics_enable; // 是否统计
|
|
fal_execution_e storage_index;
|
|
struct fdb_kvdb kvdb;
|
|
struct fdb_tsdb tsdb;
|
|
|
|
struct fdb_default_kv kv;
|
|
|
|
fal_key_e read_key; // 读取键
|
|
|
|
fal_key_e write_key; // 写入键
|
|
|
|
uint16_t init_use_time; // 初始化时间
|
|
|
|
uint16_t read_use_time; // 读取时间
|
|
|
|
uint16_t write_use_time; // 写入时间
|
|
|
|
uint16_t statistics_use_time; // 统计时间
|
|
|
|
uint16_t data_size; // 数据大小,不能超过块大小
|
|
|
|
uint16_t write_error_num; // 写入错误次数
|
|
|
|
struct
|
|
{
|
|
float32 used; // 使用率
|
|
} statistics;
|
|
|
|
struct
|
|
{
|
|
int (*read)(uint32_t read_addr, uint8_t *data, uint16_t length);
|
|
int (*write)(uint32_t read_addr, uint8_t *data, uint16_t length);
|
|
} ops;
|
|
} fal_execution_t;
|
|
|
|
typedef union
|
|
{
|
|
uint8_t data;
|
|
struct
|
|
{
|
|
uint8_t M95_1 : 1;
|
|
uint8_t M95_2 : 1;
|
|
uint8_t FM24 : 1;
|
|
uint8_t CUP_FLASH : 1;
|
|
} bits;
|
|
} fal_execution_status_u; // eeprom状态
|
|
|
|
typedef struct
|
|
{
|
|
fal_execution_status_u init;
|
|
fal_execution_status_u read;
|
|
fal_execution_status_u write;
|
|
} fal_execution_status_t;
|
|
|
|
extern fal_execution_t fal_executions[FAL_EXECUTION_MAX];
|
|
extern fal_execution_status_t fal_execution_status; // eeprom状态
|
|
extern struct flow_sem fal_write_sem; // 写信号量
|
|
|
|
static inline void fdb_lock(fdb_db_t db)
|
|
{
|
|
__disable_irq();
|
|
}
|
|
|
|
static inline void fdb_unlock(fdb_db_t db)
|
|
{
|
|
__enable_irq();
|
|
}
|
|
|
|
/**
|
|
* @brief Initializes the fal_execution module.
|
|
* @param index The index of the fal_execution to clear.
|
|
* @param data_size The size of the data to be stored in the fal_execution.
|
|
*/
|
|
void fal_execution_init(fal_execution_e index, uint16_t data_size);
|
|
|
|
/**
|
|
* @brief Enables or disables the fal_execution statistics.
|
|
*
|
|
* @param index The index of the fal_execution to enable or disable the statistics for.
|
|
* @param enable TRUE to enable the fal_execution statistics, FALSE to disable it.
|
|
*/
|
|
void fal_execution_statistics_enable(fal_execution_e index, BOOL enable);
|
|
|
|
/**
|
|
* @brief Gets the fal_execution statistics.
|
|
*
|
|
* @param index The index of the fal_execution to get the statistics from.
|
|
*/
|
|
void fal_execution_statistics(fal_execution_e index);
|
|
|
|
/**
|
|
* @brief Enables or disables the fal_execution module.
|
|
*
|
|
* @param enable TRUE to enable the fal_execution module, FALSE to disable it.
|
|
*/
|
|
void fal_execution_set_enable(fal_execution_e index, BOOL enable);
|
|
|
|
/**
|
|
* @brief Clears the status of a specific fal_execution.
|
|
*
|
|
* @param index The index of the fal_execution to clear.
|
|
*/
|
|
void fal_execution_clear(fal_execution_e index);
|
|
|
|
/**
|
|
* @brief Gets the status of a specific fal_execution.
|
|
*
|
|
* @param index The index of the fal_execution to get the status from.
|
|
* @return The status of the fal_execution.
|
|
*/
|
|
BOOL fal_execution_status_get(fal_execution_e index);
|
|
|
|
/**
|
|
* @brief Sets the status of a specific fal_execution.
|
|
*
|
|
* @param index The index of the fal_execution to set the status for.
|
|
* @param status The status to set for the fal_execution.
|
|
*/
|
|
void fal_execution_status_set(fal_execution_e index, BOOL status);
|
|
|
|
/**
|
|
* @brief Checks if the fal_execution data is valid.
|
|
*
|
|
* @param index The index of the fal_execution to check the data for.
|
|
* @param data The data to check.
|
|
* @param length The length of the data to check.
|
|
* @return TRUE if the data is valid, FALSE otherwise.
|
|
*/
|
|
BOOL fal_execution_data_storage_check(const uint8_t index, const uint8_t *const data, const uint16_t length);
|
|
|
|
/**
|
|
* @brief Sets the CRC of the fal_execution data.
|
|
*
|
|
* @param index The index of the fal_execution to set the CRC for.
|
|
* @param data The data to set the CRC for.
|
|
* @param length The length of the data to set the CRC for.
|
|
*/
|
|
void fal_execution_set_crc(const uint8_t index, const uint8_t *const data, const uint16_t length);
|
|
|
|
/**
|
|
* @brief Reads data from a specific fal_execution key-value pair.
|
|
*
|
|
* @param key The key of the fal_execution key-value pair to read from.
|
|
* @param data The buffer to store the read data.
|
|
* @param length The length of the data to read.
|
|
* @return TRUE if the read operation is successful, FALSE otherwise.
|
|
*/
|
|
BOOL fal_execution_kv_read(const fal_key_e key, const uint8_t *data, uint16_t length);
|
|
|
|
/**
|
|
* @brief Writes data to a specific fal_execution key-value pair.
|
|
*
|
|
* @param key The key of the fal_execution key-value pair to write to.
|
|
* @param data The data to write.
|
|
* @param length The length of the data to write.
|
|
* @return TRUE if the write operation is successful, FALSE otherwise.
|
|
*/
|
|
BOOL fal_execution_kv_write(const fal_key_e key, const uint8_t *const data, const uint16_t length);
|
|
|
|
/**
|
|
* @brief Deletes the data associated with a specific fal_execution key.
|
|
*
|
|
* @param key The key of the fal_execution key-value pair to delete.
|
|
*/
|
|
void fal_execution_kv_delete(const fal_key_e key);
|
|
|
|
/**
|
|
* @brief Reads and checks the data.
|
|
*
|
|
* This function reads and checks the data.
|
|
* It performs the necessary operations to read and check the data.
|
|
*/
|
|
void fal_execution_write_and_check_data(fal_key_e key, uint8_t *data, uint16_t length);
|
|
|
|
/**
|
|
* @brief Gets the current time from the flashlight module.
|
|
*
|
|
* @return The current time from the flashlight module.
|
|
*/
|
|
fdb_time_t fal_execution_get_time(void);
|
|
|
|
/**
|
|
* @brief Loads the execution state.
|
|
*
|
|
* This function is responsible for loading the execution state.
|
|
* It performs the necessary operations to load the saved state
|
|
* of the execution.
|
|
*/
|
|
void fal_execution_sem_update(void);
|
|
|
|
/**
|
|
* @brief Processes the execution.
|
|
*
|
|
* This function is responsible for processing the execution.
|
|
* It performs the necessary operations to process the execution.
|
|
*/
|
|
void fal_execution_process(void);
|
|
|
|
INTERNAL_EXTERN void fal_execution_inspection_sem(void); // 更新
|
|
#endif
|