190 lines
6.8 KiB
C
190 lines
6.8 KiB
C
// /***
|
||
// * @Author: mbw
|
||
// * @Date: 2024-08-22 16:18:15
|
||
// * @LastEditors: mbw && 1600520629@qq.com
|
||
// * @LastEditTime: 2024-08-23 09:48:20
|
||
// * @FilePath: \USART1_Interrupt - RT-Thread\bsp\inc\bsp_flash.h
|
||
// * @Description:
|
||
// * @
|
||
// * @Copyright (c) 2024 by ${git_name_email}, All Rights Reserved.
|
||
// */
|
||
// #ifndef __BSP_FLASH__H__
|
||
// #define __BSP_FLASH__H__
|
||
|
||
|
||
// #include "rtthread.h"
|
||
|
||
// #ifdef __cplusplus
|
||
// extern "C" {
|
||
// #endif
|
||
|
||
// #define FLASH_PAGE_HR_RECORD_NUM (51U)//一页存储多少组数据 512/ 10 = 51组
|
||
// #define FLASH_HR_ONE_RECORD_SIZE (10U)
|
||
|
||
// #define HR_ALARM_PAGES (5U) // 4 + 1 page
|
||
// #define HR_ALARM_RCY_PAGES (5U) // 4 + 1 page
|
||
// #define HR_FAULT_PAGES (3U) // 2 + 1 page
|
||
// #define HR_FAULT_RCY_PAGES (3U) // 2 + 1 page
|
||
// #define HR_POWER_FAILURE_PAGES (2U) // 1 + 1 page
|
||
// #define HR_POWER_ON_PAGES (2U) // 1 + 1 page
|
||
// #define HR_SENSOR_FAILURE_PAGES (1U) // 1 page
|
||
|
||
// #define FLASH_CONFIG_INFO_PAGES (1U)
|
||
|
||
// #define HR_RECORD_FRAME_HEADER (0xAA55U) // 帧头,用来检索
|
||
// /*帧头2Byte + 记录条数 2byte + 2(年) + 1(月) + 1(日) + 1(时) + 1(分) = 10Byte*/
|
||
// #define HR_RECORD_FRAME_LEN (10U)
|
||
|
||
// #define FLASH_START_ADDR (0x08000000U)
|
||
// // #define FLASH_START_ADDR (0U)
|
||
// #define FLASH_PAGE_SIZE (512U)
|
||
|
||
// // code flash = 64 KB
|
||
// #define FALSH_SIZE_KB (64U)
|
||
// /*最后一页起始地址127page*/
|
||
// #define FLASH_LAST_PAGE_START_ADDR (FLASH_START_ADDR + (FALSH_SIZE_KB * 1024) - FLASH_PAGE_SIZE)
|
||
// /*传感器失效地址:126page*/
|
||
// #define FLASH_HR_SENSOR_FAILURE_START_ADDR (FLASH_LAST_PAGE_START_ADDR - FLASH_PAGE_SIZE)
|
||
// /*报警起始地址:121~125page*/
|
||
// #define FLASH_HR_ALARM_START_ADDR (FLASH_HR_SENSOR_FAILURE_START_ADDR - FLASH_PAGE_SIZE * HR_ALARM_PAGES)
|
||
// /*报警恢复起始地址:116~120page*/
|
||
// #define FLASH_HR_ALARM_RCY_START_ADDR (FLASH_HR_ALARM_START_ADDR - FLASH_PAGE_SIZE * HR_ALARM_RCY_PAGES)
|
||
// /*故障起始地址:113~115page*/
|
||
// #define FLASH_HR_FAULT_START_ADDR (FLASH_HR_ALARM_RCY_START_ADDR - FLASH_PAGE_SIZE * HR_FAULT_PAGES)
|
||
// /*故障恢复起始地址:110~112page*/
|
||
// #define FLASH_HR_FAULT_RCY_START_ADDR (FLASH_HR_FAULT_START_ADDR - FLASH_PAGE_SIZE * HR_FAULT_RCY_PAGES)
|
||
// /*掉电起始地址:108~109page*/
|
||
// #define FLASH_HR_POWER_FAILURE_START_ADDR (FLASH_HR_FAULT_RCY_START_ADDR - FLASH_PAGE_SIZE * HR_POWER_FAILURE_PAGES)
|
||
// /*上电起始地址:106~107page*/
|
||
// #define FLASH_HR_POWER_ON_START_ADDR (FLASH_HR_POWER_FAILURE_START_ADDR - FLASH_PAGE_SIZE * HR_POWER_ON_PAGES)
|
||
// /*最后一页512个字节,用来存储一些初始化信息:
|
||
// 出厂日期
|
||
// 到期日期
|
||
// 传感器标定值
|
||
// 写Flash初始化的的标志位值
|
||
// */
|
||
// #define FLASH_CONFIG_INFO_START_ADDR FLASH_LAST_PAGE_START_ADDR
|
||
// /*出厂日期:127 page */
|
||
// #define FLASH_FACTORY_TIME_START_ADDR FLASH_CONFIG_INFO_START_ADDR
|
||
// /*到期日期:127page + 8byte*/
|
||
// #define FLASH_EXPIRATION_TIME_START_ADDR (FLASH_FACTORY_TIME_START_ADDR + sizeof(TuFlashProductTimeLimitFrame))
|
||
// /*传感器标定值:127page + 8byte + 8byte */
|
||
// #define FLASH_MQ_ALARM_VALUE_ADDR (FLASH_EXPIRATION_TIME_START_ADDR + sizeof(TuFlashProductTimeLimitFrame))
|
||
// /*初始化标志位地址:127page + 8byte + 8byte + 8byte*/
|
||
// #define FLASH_INIT_FLAG_ADDR (FLASH_MQ_ALARM_VALUE_ADDR + sizeof(TuFlashProductTimeLimitFrame))
|
||
|
||
// #define FLASH_FIRST_INIT_VALUE (0xA2A3U) // 第一次写值标志位
|
||
// #define FLASH_SYS_PRODUCT_VALUE (0xA3A3U)
|
||
// #define FLASH_SYS_USER_VALUE (0xA4A4U)
|
||
|
||
// #define FLASH_CONFIG_INFO_FRAME_HEADER (0xA5A5U)
|
||
|
||
// #define FLASH_PRODUCT_TIME_FRAME_HEADER (0xA5U)
|
||
|
||
// #define HR_ALARM_MAX_NUM (204)
|
||
// #define HR_ALARM_RCY_MAX_NUM (204)
|
||
// #define HR_FAULT_MAX_NUM (102)
|
||
// #define HR_FAULT_RCY_MAX_NUM (102)
|
||
// #define HR_POWER_FAILURE_MAX_NUM (51)
|
||
// #define HR_POWER_ON_MAX_NUM (51)
|
||
// #define HR_SENSOR_FAILURE_MAX_NUM (1)
|
||
|
||
// typedef enum
|
||
// {
|
||
// kFactoryTimeId = 0,
|
||
// kExpirationTimeId
|
||
// } TeFlashProductTimeLimitId;
|
||
|
||
// #pragma pack(push, 1)
|
||
// typedef struct
|
||
// {
|
||
// uint8_t header;
|
||
// uint16_t year;
|
||
// uint8_t month;
|
||
// uint8_t day;
|
||
// uint8_t hour;
|
||
// uint8_t minute;
|
||
// uint8_t second;
|
||
// } TsFlashProductTimeLimitFrame;
|
||
// #pragma pack(pop)
|
||
// typedef union
|
||
// {
|
||
// uint8_t buf[sizeof(TsFlashProductTimeLimitFrame)];
|
||
// TsFlashProductTimeLimitFrame Struct;
|
||
// } TuFlashProductTimeLimitFrame;
|
||
|
||
|
||
// #pragma pack(push, 1)
|
||
// typedef struct {
|
||
// uint16_t header;
|
||
// uint16_t value;
|
||
// } TsFlashMqAlarmFrame;
|
||
// #pragma pack(pop)
|
||
// typedef union
|
||
// {
|
||
// uint8_t buf[sizeof(TsFlashMqAlarmFrame)];
|
||
// TsFlashMqAlarmFrame Struct;
|
||
// } TuFlashMqAlarmFrame;
|
||
|
||
// #pragma pack(push, 1)
|
||
// typedef struct
|
||
// {
|
||
|
||
// uint16_t index;
|
||
// uint16_t year;
|
||
// uint8_t month;
|
||
// uint8_t day;
|
||
// uint8_t hour;
|
||
// uint8_t minute;
|
||
// uint16_t crc16;
|
||
// } TsFlashHrRecordFrame;
|
||
// #pragma pack(pop)
|
||
// typedef union
|
||
// {
|
||
// uint8_t buf[HR_RECORD_FRAME_LEN];
|
||
// TsFlashHrRecordFrame Struct;
|
||
// } TuFlashHrRecordFrame;
|
||
|
||
// #pragma pack(push, 1)
|
||
// typedef struct
|
||
// {
|
||
// uint8_t alarm;
|
||
// uint8_t alarm_rcy;
|
||
// uint8_t fault;
|
||
// uint8_t fault_rcy;
|
||
// uint8_t power_failure;
|
||
// uint8_t power_on;
|
||
// uint8_t sensor_failure;
|
||
// } TsTotalRecords;
|
||
// #pragma pack(pop)
|
||
// typedef enum
|
||
// {
|
||
// kRecordAlarm = 0, // at least 200 actually 204
|
||
// kRecordAlarmRcy, // at least 200 actually 204
|
||
// kRecordFault, // at least 100 actually 102
|
||
// kRecordFaultRcy, // at least 100 actually 102
|
||
// kRecordPowerFailure, // at least 50 actually 51
|
||
// kRecordPowerOn, // at least 50 actually 51
|
||
// kRecordSensorFailure // at least 1 actually 1
|
||
// } TeRecord;
|
||
|
||
|
||
// void BSP_Flash_Init(void);
|
||
// void Flash_Write_Record(TeRecord record);
|
||
// void BSP_Flash_Test(void);
|
||
|
||
// void Flash_SetProductTimeLimit(uint16_t year, uint8_t mon, uint8_t day, uint8_t hour, uint8_t min, uint8_t second, TeFlashProductTimeLimitId id);
|
||
// ErrorStatus Flash_GetProductTimeLimit(TuFlashProductTimeLimitFrame *pLimitTime,TeFlashProductTimeLimitId id);
|
||
// ErrorStatus Flash_GetTotalRecord(TsTotalRecords *pTotalRecords);
|
||
// ErrorStatus Flash_GetRecord(TeFrameC2 record_type, uint8_t index, TsRecordsTime *pRecordsTime);
|
||
// void Flash_SetMQ_AlarmValue(uint16_t value);
|
||
// uint16_t Flash_GetMQ_AlarmValue(void);
|
||
|
||
|
||
// #ifdef __cplusplus
|
||
// }
|
||
// #endif
|
||
|
||
|
||
// #endif // !__BSP_FLASH__H__
|