初始提交

This commit is contained in:
2026-08-24 15:49:57 +08:00
commit 4569284de2
181 changed files with 246421 additions and 0 deletions
+87
View File
@@ -0,0 +1,87 @@
#include "param.h"
#include "W25QXX/w25qxx.h"
sysParamDef _gtSystemParam;
sysOtpInfoDef _gtOtpInfo;
sysParamDef *gptSysParam = &_gtSystemParam;
sysOtpInfoDef *gptOtpInfo = &_gtOtpInfo;
int loadSysParam(void)
{
debug("load param");
W25QXX_Read((uint8_t *)gptSysParam, FLASH_PART_PARAM_START, sizeof(sysParamDef));
dump((uint8_t *)(gptSysParam), sizeof(sysParamDef));
return 0;
}
void saveSysParam(void)
{
debug("save param");
dump((uint8_t *)(gptSysParam), sizeof(sysParamDef));
W25QXX_Erase_Sector(FLASH_PART_PARAM_START);
W25QXX_Page_Program((uint8_t *)(gptSysParam), FLASH_PART_PARAM_START, sizeof(sysParamDef));
}
const sysOtpInfoDef *loadOtpInfo(void)
{
debug("load otp info");
W25QXX_Read((uint8_t *)gptOtpInfo, FLASH_PART_OTP_START, sizeof(sysOtpInfoDef));
dump((uint8_t *)(gptOtpInfo), sizeof(sysOtpInfoDef));
return gptOtpInfo;
}
int saveOtpInfo(const sysOtpInfoDef *otpInfo)
{
debug("save otp info");
dump((uint8_t *)(otpInfo), sizeof(sysOtpInfoDef));
if (otpInfo == NULL)
{
return -1;
}
loadOtpInfo();
for (int i = 0; i < sizeof(sysOtpInfoDef); i++)
{
if (((uint8_t *)gptOtpInfo)[i] != 0xFF)
{
debug("write failed, otp info is not empty");
return -2;
}
}
W25QXX_Page_Program((uint8_t *)(otpInfo), FLASH_PART_OTP_START, sizeof(sysOtpInfoDef));
loadOtpInfo();
if (memcmp((uint8_t *)gptOtpInfo, (uint8_t *)otpInfo, sizeof(sysOtpInfoDef)) != 0)
{
debug("write failed, otp info is not equal");
return -3;
}
return 0;
}
void systemResetFactory(void)
{
debug("reset factory");
for (uint32_t i = FLASH_PART_PARAM_START; i < FLASH_PART_PARAM_END; i += W25QXX_SECTOR_SIZE)
{
W25QXX_Erase_Sector(i);
}
for (uint32_t i = FLASH_PART_OTP_START; i < FLASH_PART_OTP_END; i += W25QXX_SECTOR_SIZE)
{
W25QXX_Erase_Sector(i);
}
}
+34
View File
@@ -0,0 +1,34 @@
#ifndef PARAM_H
#define PARAM_H
#include "main.h"
#pragma pack(1)
typedef struct __sysParamDef
{
uint16_t usAdcPeriod; ///< 定时采样周期 微秒
uint16_t usAdcinterval; ///< 定距采样间隔 微米
uint8_t ucUseEncoder; ///< 启用编码器
uint8_t ucAverageCount; ///< 平均次数
} sysParamDef;
typedef struct __sysOtpInfoDef
{
char aucModel[32];
char aucDate[32];
char aucSn[32];
} sysOtpInfoDef;
#pragma pack()
extern sysParamDef *gptSysParam;
int loadSysParam(void);
void saveSysParam(void);
const sysOtpInfoDef *loadOtpInfo(void);
int saveOtpInfo(const sysOtpInfoDef *otpInfo);
void systemResetFactory(void);
#endif // PARAM_H