编码转换: GBK -> UTF-8,所有.c/.h源文件中文注释统一UTF-8编码
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
* Author : WCH
|
||||
* Version : V1.10
|
||||
* Date : 2018/12/14
|
||||
* Description : oad相关配置定义
|
||||
* Description : oad相关配置定义
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
@@ -19,18 +19,18 @@
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/* 整个用户code区分成四块,依次为4K,44K,16K,128K 后三块分别叫做imageA(APP),imageB(IAP),LIB */
|
||||
/* 整个用户code区分成四块,依次为4K,44K,16K,128K 后三块分别叫做imageA(APP),imageB(IAP),LIB */
|
||||
|
||||
/* FLASH定义 */
|
||||
/* FLASH定义 */
|
||||
|
||||
#define FLASH_BLOCK_SIZE EEPROM_BLOCK_SIZE
|
||||
|
||||
/* imageA定义 */
|
||||
/* imageA定义 */
|
||||
#define IMAGE_A_FLAG 0x01
|
||||
#define IMAGE_A_START_ADD 0x1000
|
||||
#define IMAGE_A_SIZE 44 * 1024
|
||||
|
||||
/* imageB定义 */
|
||||
/* imageB定义 */
|
||||
#define IMAGE_B_FLAG 0x02
|
||||
#define IMAGE_B_START_ADD (IMAGE_A_START_ADD + IMAGE_A_SIZE)
|
||||
#define IMAGE_B_SIZE 16 * 1024
|
||||
@@ -39,72 +39,72 @@
|
||||
|
||||
#define jumpApp ((void (*)(void))((uint32_t *)IMAGE_A_START_ADD))
|
||||
|
||||
/* IAP定义 */
|
||||
/* 以下为IAP下载命令定义 */
|
||||
#define CMD_IAP_PROM 0x80 // IAP编程命令
|
||||
#define CMD_IAP_ERASE 0x81 // IAP擦除命令
|
||||
#define CMD_IAP_VERIFY 0x82 // IAP校验命令
|
||||
#define CMD_IAP_END 0x83 // IAP结束标志
|
||||
#define CMD_IAP_INFO 0x84 // IAP获取设备信息
|
||||
/* IAP定义 */
|
||||
/* 以下为IAP下载命令定义 */
|
||||
#define CMD_IAP_PROM 0x80 // IAP编程命令
|
||||
#define CMD_IAP_ERASE 0x81 // IAP擦除命令
|
||||
#define CMD_IAP_VERIFY 0x82 // IAP校验命令
|
||||
#define CMD_IAP_END 0x83 // IAP结束标志
|
||||
#define CMD_IAP_INFO 0x84 // IAP获取设备信息
|
||||
|
||||
/* 数据帧长度定义 */
|
||||
/* 数据帧长度定义 */
|
||||
#define IAP_LEN 247
|
||||
|
||||
/* 存放在DataFlash地址,不能占用蓝牙的位置 */
|
||||
/* 存放在DataFlash地址,不能占用蓝牙的位置 */
|
||||
#define OTA_DATAFLASH_ADD 0x00077000 - FLASH_ROM_MAX_SIZE
|
||||
|
||||
/* 存放在DataFlash里的OTA信息 */
|
||||
/* 存放在DataFlash里的OTA信息 */
|
||||
typedef struct
|
||||
{
|
||||
unsigned char ImageFlag; //记录的当前的image标志
|
||||
unsigned char ImageFlag; //记录的当前的image标志
|
||||
unsigned char Revd[3];
|
||||
} OTADataFlashInfo_t;
|
||||
|
||||
/* OTA IAP通讯协议定义 */
|
||||
/* 地址使用4倍偏移 */
|
||||
/* OTA IAP通讯协议定义 */
|
||||
/* 地址使用4倍偏移 */
|
||||
typedef union
|
||||
{
|
||||
struct
|
||||
{
|
||||
unsigned char cmd; /* 命令码 0x81 */
|
||||
unsigned char len; /* 后续数据长度 */
|
||||
unsigned char addr[2]; /* 擦除地址 */
|
||||
unsigned char block_num[2]; /* 擦除块数 */
|
||||
unsigned char cmd; /* 命令码 0x81 */
|
||||
unsigned char len; /* 后续数据长度 */
|
||||
unsigned char addr[2]; /* 擦除地址 */
|
||||
unsigned char block_num[2]; /* 擦除块数 */
|
||||
|
||||
} erase; /* 擦除命令 */
|
||||
} erase; /* 擦除命令 */
|
||||
struct
|
||||
{
|
||||
unsigned char cmd; /* 命令码 0x83 */
|
||||
unsigned char len; /* 后续数据长度 */
|
||||
unsigned char status[2]; /* 两字节状态,保留 */
|
||||
} end; /* 结束命令 */
|
||||
unsigned char cmd; /* 命令码 0x83 */
|
||||
unsigned char len; /* 后续数据长度 */
|
||||
unsigned char status[2]; /* 两字节状态,保留 */
|
||||
} end; /* 结束命令 */
|
||||
struct
|
||||
{
|
||||
unsigned char cmd; /* 命令码 0x82 */
|
||||
unsigned char len; /* 后续数据长度 */
|
||||
unsigned char addr[2]; /* 校验地址 */
|
||||
unsigned char buf[IAP_LEN - 4]; /* 校验数据 */
|
||||
} verify; /* 校验命令 */
|
||||
unsigned char cmd; /* 命令码 0x82 */
|
||||
unsigned char len; /* 后续数据长度 */
|
||||
unsigned char addr[2]; /* 校验地址 */
|
||||
unsigned char buf[IAP_LEN - 4]; /* 校验数据 */
|
||||
} verify; /* 校验命令 */
|
||||
struct
|
||||
{
|
||||
unsigned char cmd; /* 命令码 0x80 */
|
||||
unsigned char len; /* 后续数据长度 */
|
||||
unsigned char addr[2]; /* 地址 */
|
||||
unsigned char buf[IAP_LEN - 4]; /* 后续数据 */
|
||||
} program; /* 编程命令 */
|
||||
unsigned char cmd; /* 命令码 0x80 */
|
||||
unsigned char len; /* 后续数据长度 */
|
||||
unsigned char addr[2]; /* 地址 */
|
||||
unsigned char buf[IAP_LEN - 4]; /* 后续数据 */
|
||||
} program; /* 编程命令 */
|
||||
struct
|
||||
{
|
||||
unsigned char cmd; /* 命令码 0x84 */
|
||||
unsigned char len; /* 后续数据长度 */
|
||||
unsigned char buf[IAP_LEN - 2]; /* 后续数据 */
|
||||
} info; /* 编程命令 */
|
||||
unsigned char cmd; /* 命令码 0x84 */
|
||||
unsigned char len; /* 后续数据长度 */
|
||||
unsigned char buf[IAP_LEN - 2]; /* 后续数据 */
|
||||
} info; /* 编程命令 */
|
||||
struct
|
||||
{
|
||||
unsigned char buf[IAP_LEN]; /* 接收数据包*/
|
||||
unsigned char buf[IAP_LEN]; /* 接收数据包*/
|
||||
} other;
|
||||
} OTA_IAP_CMD_t;
|
||||
|
||||
/* 记录当前的Image */
|
||||
/* 记录当前的Image */
|
||||
extern unsigned char CurrImageFlag;
|
||||
|
||||
#endif
|
||||
|
||||
@@ -28,7 +28,7 @@ extern "C" {
|
||||
// Simple BLE Peripheral Task Events
|
||||
#define SBP_START_DEVICE_EVT 0x0001
|
||||
#define SBP_PERIODIC_EVT 0x0002
|
||||
#define OTA_FLASH_ERASE_EVT 0x0004 //OTA Flash²Á³ýÈÎÎñ
|
||||
#define OTA_FLASH_ERASE_EVT 0x0004 //OTA Flash擦除任务
|
||||
|
||||
/*********************************************************************
|
||||
* MACROS
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Author : WCH
|
||||
* Version : V1.0
|
||||
* Date : 2018/12/10
|
||||
* Description : 外设从机应用程序,初始化广播连接参数,然后广播,直至连接主机后,通过自定义服务传输数据
|
||||
* Description : 外设从机应用程序,初始化广播连接参数,然后广播,直至连接主机后,通过自定义服务传输数据
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
@@ -128,26 +128,26 @@ static uint8_t advertData[] = {
|
||||
static uint8_t attDeviceName[GAP_DEVICE_NAME_LEN] = "OTAOTA_OTAOTA_OTA";
|
||||
|
||||
// OTA IAP VARIABLES
|
||||
/* OTA通讯的帧 */
|
||||
/* OTA通讯的帧 */
|
||||
OTA_IAP_CMD_t iap_rec_data;
|
||||
|
||||
/* OTA解析结果 */
|
||||
/* OTA解析结果 */
|
||||
uint32_t OpParaDataLen = 0;
|
||||
uint32_t OpAdd = 0;
|
||||
|
||||
/* flash的数据临时存储 */
|
||||
/* flash的数据临时存储 */
|
||||
__attribute__((aligned(8))) uint8_t block_buf[16];
|
||||
|
||||
/* Image跳转函数地址定义 */
|
||||
/* Image跳转函数地址定义 */
|
||||
typedef int (*pImageTaskFn)(void);
|
||||
pImageTaskFn user_image_tasks;
|
||||
|
||||
/* Flash 擦除过程 */
|
||||
uint32_t EraseAdd = 0; //擦除地址
|
||||
uint32_t EraseBlockNum = 0; //需要擦除的块数
|
||||
uint32_t EraseBlockCnt = 0; //擦除的块计数
|
||||
/* Flash 擦除过程 */
|
||||
uint32_t EraseAdd = 0; //擦除地址
|
||||
uint32_t EraseBlockNum = 0; //需要擦除的块数
|
||||
uint32_t EraseBlockCnt = 0; //擦除的块计数
|
||||
|
||||
/* FLASH 校验过程 */
|
||||
/* FLASH 校验过程 */
|
||||
uint8_t VerifyStatus = 0;
|
||||
|
||||
/*********************************************************************
|
||||
@@ -312,7 +312,7 @@ uint16_t Peripheral_ProcessEvent(uint8_t task_id, uint16_t events)
|
||||
PRINT("ERASE:%08x num:%d\r\n", (int)(EraseAdd + EraseBlockCnt * FLASH_BLOCK_SIZE), (int)EraseBlockCnt);
|
||||
status = FLASH_ROM_ERASE(EraseAdd + EraseBlockCnt * FLASH_BLOCK_SIZE, FLASH_BLOCK_SIZE);
|
||||
|
||||
/* 擦除失败 */
|
||||
/* 擦除失败 */
|
||||
if(status != SUCCESS)
|
||||
{
|
||||
OTA_IAP_SendCMDDealSta(status);
|
||||
@@ -321,7 +321,7 @@ uint16_t Peripheral_ProcessEvent(uint8_t task_id, uint16_t events)
|
||||
|
||||
EraseBlockCnt++;
|
||||
|
||||
/* 擦除结束 */
|
||||
/* 擦除结束 */
|
||||
if(EraseBlockCnt >= EraseBlockNum)
|
||||
{
|
||||
PRINT("ERASE Complete\r\n");
|
||||
@@ -438,10 +438,10 @@ static void performPeriodicTask(void)
|
||||
/*********************************************************************
|
||||
* @fn OTA_IAP_SendData
|
||||
*
|
||||
* @brief OTA IAP发送数据,使用时限制20字节以内
|
||||
* @brief OTA IAP发送数据,使用时限制20字节以内
|
||||
*
|
||||
* @param p_send_data - 发送数据的指针
|
||||
* @param send_len - 发送数据的长度
|
||||
* @param p_send_data - 发送数据的指针
|
||||
* @param send_len - 发送数据的长度
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
@@ -453,9 +453,9 @@ void OTA_IAP_SendData(uint8_t *p_send_data, uint8_t send_len)
|
||||
/*********************************************************************
|
||||
* @fn OTA_IAP_SendCMDDealSta
|
||||
*
|
||||
* @brief OTA IAP执行的状态返回
|
||||
* @brief OTA IAP执行的状态返回
|
||||
*
|
||||
* @param deal_status - 返回的状态
|
||||
* @param deal_status - 返回的状态
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
@@ -471,7 +471,7 @@ void OTA_IAP_SendCMDDealSta(uint8_t deal_status)
|
||||
/*********************************************************************
|
||||
* @fn OTA_IAP_CMDErrDeal
|
||||
*
|
||||
* @brief OTA IAP异常命令码处理
|
||||
* @brief OTA IAP异常命令码处理
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
@@ -483,9 +483,9 @@ void OTA_IAP_CMDErrDeal(void)
|
||||
/*********************************************************************
|
||||
* @fn SwitchImageFlag
|
||||
*
|
||||
* @brief 切换dataflash里的ImageFlag
|
||||
* @brief 切换dataflash里的ImageFlag
|
||||
*
|
||||
* @param new_flag - 切换的ImageFlag
|
||||
* @param new_flag - 切换的ImageFlag
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
@@ -494,23 +494,23 @@ void SwitchImageFlag(uint8_t new_flag)
|
||||
uint16_t i;
|
||||
uint32_t ver_flag;
|
||||
|
||||
/* 读取第一块 */
|
||||
/* 读取第一块 */
|
||||
EEPROM_READ(OTA_DATAFLASH_ADD, (uint32_t *)&block_buf[0], 4);
|
||||
|
||||
/* 擦除第一块 */
|
||||
/* 擦除第一块 */
|
||||
EEPROM_ERASE(OTA_DATAFLASH_ADD, EEPROM_PAGE_SIZE);
|
||||
|
||||
/* 更新Image信息 */
|
||||
/* 更新Image信息 */
|
||||
block_buf[0] = new_flag;
|
||||
|
||||
/* 编程DataFlash */
|
||||
/* 编程DataFlash */
|
||||
EEPROM_WRITE(OTA_DATAFLASH_ADD, (uint32_t *)&block_buf[0], 4);
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn DisableAllIRQ
|
||||
*
|
||||
* @brief 关闭所有的中断
|
||||
* @brief 关闭所有的中断
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
@@ -522,7 +522,7 @@ void DisableAllIRQ(void)
|
||||
/*********************************************************************
|
||||
* @fn Rec_OTA_IAP_DataDeal
|
||||
*
|
||||
* @brief 接收到OTA数据包处理
|
||||
* @brief 接收到OTA数据包处理
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
@@ -530,7 +530,7 @@ void Rec_OTA_IAP_DataDeal(void)
|
||||
{
|
||||
switch(iap_rec_data.other.buf[0])
|
||||
{
|
||||
/* 编程 */
|
||||
/* 编程 */
|
||||
case CMD_IAP_PROM:
|
||||
{
|
||||
uint32_t i;
|
||||
@@ -543,12 +543,12 @@ void Rec_OTA_IAP_DataDeal(void)
|
||||
|
||||
PRINT("IAP_PROM: %08x len:%d \r\n", (int)OpAdd, (int)OpParaDataLen);
|
||||
|
||||
/* 当前是ImageA,直接编程 */
|
||||
/* 当前是ImageA,直接编程 */
|
||||
status = FLASH_ROM_WRITE(OpAdd, iap_rec_data.program.buf, (uint16_t)OpParaDataLen);
|
||||
OTA_IAP_SendCMDDealSta(status);
|
||||
break;
|
||||
}
|
||||
/* 擦除 -- 蓝牙擦除由主机控制 */
|
||||
/* 擦除 -- 蓝牙擦除由主机控制 */
|
||||
case CMD_IAP_ERASE:
|
||||
{
|
||||
OpAdd = (uint32_t)(iap_rec_data.erase.addr[0]);
|
||||
@@ -560,7 +560,7 @@ void Rec_OTA_IAP_DataDeal(void)
|
||||
EraseAdd = OpAdd;
|
||||
EraseBlockCnt = 0;
|
||||
|
||||
/* 检验就放在擦除里清0 */
|
||||
/* 检验就放在擦除里清0 */
|
||||
VerifyStatus = 0;
|
||||
|
||||
PRINT("IAP_ERASE start:%08x num:%d\r\n", (int)OpAdd, (int)EraseBlockNum);
|
||||
@@ -571,15 +571,15 @@ void Rec_OTA_IAP_DataDeal(void)
|
||||
}
|
||||
else
|
||||
{
|
||||
/* 修改DataFlash,切换至ImageB */
|
||||
/* 修改DataFlash,切换至ImageB */
|
||||
SwitchImageFlag(IMAGE_B_FLAG);
|
||||
|
||||
/* 启动擦除 */
|
||||
/* 启动擦除 */
|
||||
tmos_set_event(Peripheral_TaskID, OTA_FLASH_ERASE_EVT);
|
||||
}
|
||||
break;
|
||||
}
|
||||
/* 校验 */
|
||||
/* 校验 */
|
||||
case CMD_IAP_VERIFY:
|
||||
{
|
||||
uint32_t i;
|
||||
@@ -598,22 +598,22 @@ void Rec_OTA_IAP_DataDeal(void)
|
||||
OTA_IAP_SendCMDDealSta(VerifyStatus);
|
||||
break;
|
||||
}
|
||||
/* 编程结束 */
|
||||
/* 编程结束 */
|
||||
case CMD_IAP_END:
|
||||
{
|
||||
PRINT("IAP_END \r\n");
|
||||
|
||||
/* 关闭当前所有使用中断,或者方便一点直接全部关闭 */
|
||||
/* 关闭当前所有使用中断,或者方便一点直接全部关闭 */
|
||||
DisableAllIRQ();
|
||||
|
||||
/* 修改DataFlash,切换至ImageA */
|
||||
/* 修改DataFlash,切换至ImageA */
|
||||
SwitchImageFlag(IMAGE_A_FLAG);
|
||||
|
||||
/* 等待打印完成 ,跳转ImageB*/
|
||||
/* 等待打印完成 ,跳转ImageB*/
|
||||
mDelaymS(10);
|
||||
jumpApp();
|
||||
|
||||
/* 不会执行到这 */
|
||||
/* 不会执行到这 */
|
||||
SYS_ResetExecute();
|
||||
|
||||
break;
|
||||
@@ -639,9 +639,9 @@ void Rec_OTA_IAP_DataDeal(void)
|
||||
|
||||
send_buf[7] = CHIP_ID&0xFF;
|
||||
send_buf[8] = (CHIP_ID>>8)&0xFF;
|
||||
/* 有需要再增加 */
|
||||
/* 有需要再增加 */
|
||||
|
||||
/* 发送信息 */
|
||||
/* 发送信息 */
|
||||
OTA_IAP_SendData(send_buf, 20);
|
||||
|
||||
break;
|
||||
@@ -658,9 +658,9 @@ void Rec_OTA_IAP_DataDeal(void)
|
||||
/*********************************************************************
|
||||
* @fn OTA_IAPReadDataComplete
|
||||
*
|
||||
* @brief OTA 数据读取完成处理
|
||||
* @brief OTA 数据读取完成处理
|
||||
*
|
||||
* @param index - OTA 通道序号
|
||||
* @param index - OTA 通道序号
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
@@ -672,11 +672,11 @@ void OTA_IAPReadDataComplete(unsigned char index)
|
||||
/*********************************************************************
|
||||
* @fn OTA_IAPWriteData
|
||||
*
|
||||
* @brief OTA 通道数据接收完成处理
|
||||
* @brief OTA 通道数据接收完成处理
|
||||
*
|
||||
* @param index - OTA 通道序号
|
||||
* @param p_data - 写入的数据
|
||||
* @param w_len - 写入的长度
|
||||
* @param index - OTA 通道序号
|
||||
* @param p_data - 写入的数据
|
||||
* @param w_len - 写入的长度
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Author : WCH
|
||||
* Version : V1.1
|
||||
* Date : 2019/11/05
|
||||
* Description : 升级从机应用主函数及任务系统初始化
|
||||
* Description : 升级从机应用主函数及任务系统初始化
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
@@ -11,14 +11,14 @@
|
||||
*******************************************************************************/
|
||||
|
||||
/******************************************************************************/
|
||||
/* 头文件包含 */
|
||||
/* 头文件包含 */
|
||||
#include "CONFIG.h"
|
||||
#include "HAL.h"
|
||||
#include "Peripheral.h"
|
||||
#include "OTA.h"
|
||||
#include "OTAprofile.h"
|
||||
|
||||
/* 记录当前的Image */
|
||||
/* 记录当前的Image */
|
||||
unsigned char CurrImageFlag = 0xff;
|
||||
|
||||
/*********************************************************************
|
||||
@@ -30,11 +30,11 @@ __attribute__((aligned(4))) uint32_t MEM_BUF[BLE_MEMHEAP_SIZE / 4];
|
||||
const uint8_t MacAddr[6] = {0x84, 0xC2, 0xE4, 0x03, 0x02, 0x02};
|
||||
#endif
|
||||
|
||||
/* 注意:关于程序升级后flash的操作必须先执行,不开启任何中断,防止操作中断和失败 */
|
||||
/* 注意:关于程序升级后flash的操作必须先执行,不开启任何中断,防止操作中断和失败 */
|
||||
/*********************************************************************
|
||||
* @fn ReadImageFlag
|
||||
*
|
||||
* @brief 读取当前的程序的Image标志,DataFlash如果为空,就默认是ImageA,如果为ImageA,则跳转ImageA
|
||||
* @brief 读取当前的程序的Image标志,DataFlash如果为空,就默认是ImageA,如果为ImageA,则跳转ImageA
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
@@ -45,7 +45,7 @@ void ReadImageFlag(void)
|
||||
EEPROM_READ(OTA_DATAFLASH_ADD, &p_image_flash, 4);
|
||||
CurrImageFlag = p_image_flash.ImageFlag;
|
||||
|
||||
/* 程序第一次执行,或者没有更新过,以后更新后在擦除DataFlash */
|
||||
/* 程序第一次执行,或者没有更新过,以后更新后在擦除DataFlash */
|
||||
if((CurrImageFlag != IMAGE_B_FLAG) && (CurrImageFlag != IMAGE_A_FLAG) && (CurrImageFlag != IMAGE_OTA_FLAG))
|
||||
{
|
||||
CurrImageFlag = IMAGE_A_FLAG;
|
||||
@@ -64,7 +64,7 @@ void ReadImageFlag(void)
|
||||
/*********************************************************************
|
||||
* @fn Main_Circulation
|
||||
*
|
||||
* @brief 主循环
|
||||
* @brief 主循环
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
@@ -81,7 +81,7 @@ void Main_Circulation()
|
||||
/*********************************************************************
|
||||
* @fn main
|
||||
*
|
||||
* @brief 主函数
|
||||
* @brief 主函数
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
@@ -100,18 +100,18 @@ int main(void)
|
||||
// GPIOA_ModeCfg(bTXD1, GPIO_ModeOut_PP_5mA);
|
||||
// UART1_DefInit();
|
||||
#endif
|
||||
/* 配置串口0:先配置IO口模式,再配置串口 */
|
||||
/* 配置串口0:先配置IO口模式,再配置串口 */
|
||||
GPIOPinRemap(ENABLE, RB_PIN_UART0);
|
||||
GPIOA_SetBits(GPIO_Pin_14);
|
||||
GPIOA_ModeCfg(GPIO_Pin_15, GPIO_ModeIN_PU); // RXD-配置上拉输入
|
||||
GPIOA_ModeCfg(GPIO_Pin_14, GPIO_ModeOut_PP_5mA); // TXD-配置推挽输出,注意先让IO口输出高电平
|
||||
GPIOA_ModeCfg(GPIO_Pin_15, GPIO_ModeIN_PU); // RXD-配置上拉输入
|
||||
GPIOA_ModeCfg(GPIO_Pin_14, GPIO_ModeOut_PP_5mA); // TXD-配置推挽输出,注意先让IO口输出高电平
|
||||
UART0_DefInit();
|
||||
|
||||
PRINT("%s\n", VER_LIB);
|
||||
ReadImageFlag();
|
||||
if((R8_RESET_STATUS & RB_RESET_FLAG) == RST_FLAG_SW)
|
||||
{
|
||||
// 软复位不跳APP
|
||||
// 软复位不跳APP
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Author : WCH
|
||||
* Version : V1.0
|
||||
* Date : 2018/12/10
|
||||
* Description : OTA升级蓝牙通讯接口
|
||||
* Description : OTA升级蓝牙通讯接口
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
@@ -137,11 +137,11 @@ gattServiceCBs_t OTAProfileCBs = {
|
||||
/*********************************************************************
|
||||
* @fn OTAProfile_AddService
|
||||
*
|
||||
* @brief OTA Profile初始化
|
||||
* @brief OTA Profile初始化
|
||||
*
|
||||
* @param services - 服务控制字
|
||||
* @param services - 服务控制字
|
||||
*
|
||||
* @return 初始化的状态
|
||||
* @return 初始化的状态
|
||||
*/
|
||||
bStatus_t OTAProfile_AddService(uint32_t services)
|
||||
{
|
||||
@@ -162,11 +162,11 @@ bStatus_t OTAProfile_AddService(uint32_t services)
|
||||
/*********************************************************************
|
||||
* @fn OTAProfile_RegisterAppCBs
|
||||
*
|
||||
* @brief OTA Profile读写回调函数注册
|
||||
* @brief OTA Profile读写回调函数注册
|
||||
*
|
||||
* @param appCallbacks - 函数结构体指针
|
||||
* @param appCallbacks - 函数结构体指针
|
||||
*
|
||||
* @return 函数执行状态
|
||||
* @return 函数执行状态
|
||||
*/
|
||||
bStatus_t OTAProfile_RegisterAppCBs(OTAProfileCBs_t *appCallbacks)
|
||||
{
|
||||
@@ -308,19 +308,19 @@ static bStatus_t OTAProfile_WriteAttrCB(uint16_t connHandle, gattAttribute_t *pA
|
||||
/*********************************************************************
|
||||
* @fn OTAProfile_SendData
|
||||
*
|
||||
* @brief OTA Profile通道发送数据
|
||||
* @brief OTA Profile通道发送数据
|
||||
*
|
||||
* @param paramID - OTA通道选择
|
||||
* @param p_data - 数据指针
|
||||
* @param send_len - 发送数据长度
|
||||
* @param paramID - OTA通道选择
|
||||
* @param p_data - 数据指针
|
||||
* @param send_len - 发送数据长度
|
||||
*
|
||||
* @return 函数执行状态
|
||||
* @return 函数执行状态
|
||||
*/
|
||||
bStatus_t OTAProfile_SendData(unsigned char paramID, unsigned char *p_data, unsigned char send_len)
|
||||
{
|
||||
bStatus_t status = SUCCESS;
|
||||
|
||||
/* 数据长度超出范围 */
|
||||
/* 数据长度超出范围 */
|
||||
if(send_len > 20)
|
||||
return 0xfe;
|
||||
|
||||
|
||||
@@ -25,13 +25,13 @@ extern "C" {
|
||||
* CONSTANTS
|
||||
*/
|
||||
|
||||
// OTA Profile通道Index定义
|
||||
// OTA Profile通道Index定义
|
||||
#define OTAPROFILE_CHAR 0
|
||||
|
||||
// OTA 服务的UUID定义
|
||||
// OTA 服务的UUID定义
|
||||
#define OTAPROFILE_SERV_UUID 0xFEE0
|
||||
|
||||
// OTA 通讯通道UUID定义
|
||||
// OTA 通讯通道UUID定义
|
||||
#define OTAPROFILE_CHAR_UUID 0xFEE1
|
||||
|
||||
// Simple Keys Profile Services bit fields
|
||||
@@ -49,7 +49,7 @@ extern "C" {
|
||||
* Profile Callbacks
|
||||
*/
|
||||
|
||||
// 读写操作函数回调
|
||||
// 读写操作函数回调
|
||||
typedef void (*OTAProfileRead_t)(unsigned char paramID);
|
||||
typedef void (*OTAProfileWrite_t)(unsigned char paramID, unsigned char *p_data, unsigned char w_len);
|
||||
|
||||
@@ -64,31 +64,31 @@ typedef struct
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief OTA Profile初始化
|
||||
* @brief OTA Profile初始化
|
||||
*
|
||||
* @param services - 服务控制字
|
||||
* @param services - 服务控制字
|
||||
*
|
||||
* @return 初始化的状态
|
||||
* @return 初始化的状态
|
||||
*/
|
||||
bStatus_t OTAProfile_AddService(uint32_t services);
|
||||
|
||||
/**
|
||||
* @brief OTA Profile读写回调函数注册
|
||||
* @brief OTA Profile读写回调函数注册
|
||||
*
|
||||
* @param appCallbacks - 函数结构体指针
|
||||
* @param appCallbacks - 函数结构体指针
|
||||
*
|
||||
* @return 函数执行状态
|
||||
* @return 函数执行状态
|
||||
*/
|
||||
bStatus_t OTAProfile_RegisterAppCBs(OTAProfileCBs_t *appCallbacks);
|
||||
|
||||
/**
|
||||
* @brief OTA Profile通道发送数据
|
||||
* @brief OTA Profile通道发送数据
|
||||
*
|
||||
* @param paramID - OTA通道选择
|
||||
* @param p_data - 数据指针
|
||||
* @param send_len - 发送数据长度
|
||||
* @param paramID - OTA通道选择
|
||||
* @param p_data - 数据指针
|
||||
* @param send_len - 发送数据长度
|
||||
*
|
||||
* @return 函数执行状态
|
||||
* @return 函数执行状态
|
||||
*/
|
||||
bStatus_t OTAProfile_SendData(unsigned char paramID, unsigned char *p_data, unsigned char send_len);
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Author : WCH
|
||||
* Version : V1.1
|
||||
* Date : 2020/08/06
|
||||
* Description : 跳转指令
|
||||
* Description : 跳转指令
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
@@ -12,12 +12,12 @@
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
// 如需修改跳转地址,直接修改启动文件 startup_CH59x.s 中跳转指令 “j” 之后的地址
|
||||
// 如需修改跳转地址,直接修改启动文件 startup_CH59x.s 中跳转指令 “j” 之后的地址
|
||||
|
||||
/*********************************************************************
|
||||
* @fn main
|
||||
*
|
||||
* @brief 主函数
|
||||
* @brief 主函数
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include "CH59x_common.h"
|
||||
|
||||
|
||||
uint8_t g_flag_notify_temp = 0; //临时通知notify flag, 0 disable, 1 enable
|
||||
uint8_t g_flag_notify_temp = 0; //临时通知notify flag, 0 disable, 1 enable
|
||||
|
||||
BLE_Notify_Buf g_notify_buftemp = {0,0, ""};
|
||||
BLE_Notify_Buf g_ble_rcv_buf = {0,0, ""};
|
||||
@@ -70,8 +70,8 @@ void clear_buf_dbn_ble_all(Buf_DBN_BLE * buf)
|
||||
}
|
||||
|
||||
|
||||
// 0: 包检测异常
|
||||
//检测包是否完整,Magic Byte, Header Byte, CK Byte, 校验字节(异或校验,以及和校验)
|
||||
// 0: 包检测异常
|
||||
//检测包是否完整,Magic Byte, Header Byte, CK Byte, 校验字节(异或校验,以及和校验)
|
||||
uint8_t check_pkg(uint8_t * pkg, uint8_t len)
|
||||
{
|
||||
if(len < 6) //min length of ble pkg is 6
|
||||
@@ -84,7 +84,7 @@ uint8_t check_pkg(uint8_t * pkg, uint8_t len)
|
||||
}
|
||||
uint8_t _dxor = 0;
|
||||
uint8_t _dsum = 0;
|
||||
uint8_t _cklen = _len + 3; //不计算 校验字节
|
||||
uint8_t _cklen = _len + 3; //不计算 校验字节
|
||||
uint8_t i = 0;
|
||||
for(i = 1; i < _cklen; i++)
|
||||
{
|
||||
@@ -200,7 +200,7 @@ uint8_t set_response_to_notify(Buf_DBN_BLE *response_ori, BLE_Notify_Buf * notif
|
||||
}
|
||||
if(response_ori->pkg_amount <= 1)
|
||||
{
|
||||
//没有分包的情况
|
||||
//没有分包的情况
|
||||
notify_dst->buf[0] = response_ori->magic;
|
||||
if(response_ori->magic == MAGIC_BYTE_DBN_TRANSPARENT)
|
||||
{
|
||||
@@ -436,7 +436,7 @@ static void unpack_pkg_set_cjq_param(uint8_t *pkg, uint8_t len)
|
||||
tmp[i++] = g_loop_cng_unit.sensitvity;
|
||||
tmp[i++] = g_loop_cng_unit.delay_time;
|
||||
tmp[i++] = g_loop_cng_unit.output_mode;
|
||||
tmp[i++] = g_loop_cng_unit.direction_mode; //默认 0
|
||||
tmp[i++] = g_loop_cng_unit.direction_mode; //默认 0
|
||||
tmp[i++] = g_loop_cng_unit.loopFreq_Level;
|
||||
tmp[i++] = g_loop_cng_unit.loopSafe_Timeout;
|
||||
tmp[i++] = g_loop_cng_unit.exist_mode;
|
||||
@@ -470,7 +470,7 @@ void usart_packet_processing_acs_loop(uint8_t flag)
|
||||
|
||||
g_freq_tmp = (float)(g_sys_freq )/((float)(_loop_capvd)/((float)(loop1_LPCNT))); // ?? ???????
|
||||
|
||||
// why + 360? balance value ,补偿,经验值,可以根据示波器比较再进行调整
|
||||
// why + 360? balance value ,补偿,经验值,可以根据示波器比较再进行调整
|
||||
_current_freq = (uint32_t)(g_freq_tmp) + 360 ;// * 32);
|
||||
// if(flag)
|
||||
{
|
||||
@@ -483,7 +483,7 @@ void usart_packet_processing_acs_loop(uint8_t flag)
|
||||
// {
|
||||
// if(_current_freq - _last_freq > 30)
|
||||
// {
|
||||
// //稳定显示,过滤低数值的变动
|
||||
// //稳定显示,过滤低数值的变动
|
||||
// g_loop_acs_info.frequent = _current_freq;
|
||||
// _last_freq = _current_freq;
|
||||
// }
|
||||
@@ -492,7 +492,7 @@ void usart_packet_processing_acs_loop(uint8_t flag)
|
||||
// {
|
||||
// if(_last_freq - _current_freq > 30)
|
||||
// {
|
||||
// // 稳定显示,过滤低数值的变动
|
||||
// // 稳定显示,过滤低数值的变动
|
||||
// g_loop_acs_info.frequent = _current_freq;
|
||||
// _last_freq = _current_freq;
|
||||
// }
|
||||
@@ -531,7 +531,7 @@ void report_sens_acs(void)
|
||||
|
||||
if(g_dbn_ble_state_acs_enable.enable)
|
||||
{
|
||||
// 上报线圈动态数据
|
||||
// 上报线圈动态数据
|
||||
|
||||
|
||||
// switch(g_dbn_ble_state_acs_enable.sens_type)
|
||||
@@ -539,7 +539,7 @@ void report_sens_acs(void)
|
||||
// //case SENS_LOOP_DYNAMIC:
|
||||
// default:
|
||||
// {
|
||||
// 线圈动态信息
|
||||
// 线圈动态信息
|
||||
if(g_loop_acs_info.flag_event)
|
||||
{
|
||||
// if(g_loop_acs_info.report_counter >= 3)
|
||||
@@ -637,7 +637,7 @@ void manage_dbn_ble_default(uint8_t *pkg, uint8_t len)
|
||||
// PRINT("\nGet_Cjq_param\n");
|
||||
} break;
|
||||
// case CMD_DBN_LOOP_SAMPLE_PARAM:{
|
||||
// // 获取/设置 地感采样参数
|
||||
// // 获取/设置 地感采样参数
|
||||
//// PRINT("SAMPLE_CNG: %02X\n", pkg[4]);
|
||||
// if(pkg[4] == 0){
|
||||
// // get param
|
||||
@@ -664,13 +664,13 @@ void manage_dbn_ble_default(uint8_t *pkg, uint8_t len)
|
||||
//
|
||||
// set_response_buf(&g_buf_ble_response, MAGIC_BYTE_DBN_DEFAULT, _cmd, tmp_ble_buf, i);
|
||||
//
|
||||
// //TODO: 不整个设备复位,复位除了蓝牙的部分,即蓝牙正常,其他部分重新初始化
|
||||
// //TODO: 不整个设备复位,复位除了蓝牙的部分,即蓝牙正常,其他部分重新初始化
|
||||
// para_store_init();
|
||||
// }
|
||||
//
|
||||
// } break;
|
||||
// case CMD_DBN_LOOP_BALANCE_PARAM: {
|
||||
// // 获取/设置 漂移补偿参数
|
||||
// // 获取/设置 漂移补偿参数
|
||||
//// PRINT("Balance_CNG: %02X\n", pkg[4]);
|
||||
// if(pkg[4] == 0){
|
||||
// // get param
|
||||
@@ -698,14 +698,14 @@ void manage_dbn_ble_default(uint8_t *pkg, uint8_t len)
|
||||
//
|
||||
// set_response_buf(&g_buf_ble_response, MAGIC_BYTE_DBN_DEFAULT, _cmd, tmp_ble_buf, i);
|
||||
//
|
||||
// //TODO: 不整个设备复位,复位除了蓝牙的部分,即蓝牙正常,其他部分重新初始化
|
||||
// //TODO: 不整个设备复位,复位除了蓝牙的部分,即蓝牙正常,其他部分重新初始化
|
||||
// para_store_init();
|
||||
//
|
||||
// }
|
||||
//
|
||||
// } break;
|
||||
// case CMD_DBN_LOOP_RELEASE_PLANB: {
|
||||
// // 获取/设置 释放去抖动算法参数
|
||||
// // 获取/设置 释放去抖动算法参数
|
||||
//// PRINT("Release2_CNG: %02X\n", pkg[4]);
|
||||
// if(pkg[4] == 0){
|
||||
// // get param
|
||||
@@ -733,7 +733,7 @@ void manage_dbn_ble_default(uint8_t *pkg, uint8_t len)
|
||||
//
|
||||
// set_response_buf(&g_buf_ble_response, MAGIC_BYTE_DBN_DEFAULT, _cmd, tmp_ble_buf, i);
|
||||
//
|
||||
// //TODO: 不整个设备复位,复位除了蓝牙的部分,即蓝牙正常,其他部分重新初始化
|
||||
// //TODO: 不整个设备复位,复位除了蓝牙的部分,即蓝牙正常,其他部分重新初始化
|
||||
// para_store_init();
|
||||
// }
|
||||
// } break;
|
||||
@@ -773,23 +773,23 @@ void manage_dbn_ble_default(uint8_t *pkg, uint8_t len)
|
||||
write_cfg_to_store(Addr_Loop_Sens_List_Offset, &tmp_ble_buf[1], (i - 1));
|
||||
DelayMs(10);
|
||||
|
||||
//TODO: 不整个设备复位,复位除了蓝牙的部分,即蓝牙正常,其他部分重新初始化
|
||||
//TODO: 不整个设备复位,复位除了蓝牙的部分,即蓝牙正常,其他部分重新初始化
|
||||
para_store_init();
|
||||
}
|
||||
} break;
|
||||
case CMD_DBN_SET_CJQ_FACTORY: {
|
||||
// 出厂初始化
|
||||
// 出厂初始化
|
||||
tmp_ble_buf[0] = 0;
|
||||
set_response_buf(&g_buf_ble_response, MAGIC_BYTE_DBN_DEFAULT, _cmd, tmp_ble_buf, 1);
|
||||
|
||||
set_factory_param();
|
||||
factory_dev();
|
||||
DelayMs(10);
|
||||
//TODO: 不整个设备复位,复位除了蓝牙的部分,即蓝牙正常,其他部分重新初始化
|
||||
//TODO: 不整个设备复位,复位除了蓝牙的部分,即蓝牙正常,其他部分重新初始化
|
||||
para_store_init();
|
||||
} break;
|
||||
case CMD_SENS_ACS_ENABLE: {
|
||||
// 线圈动态
|
||||
// 线圈动态
|
||||
g_dbn_ble_state_acs_enable.enable = pkg[5];
|
||||
|
||||
if(g_dbn_ble_state_acs_enable.enable){
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
*
|
||||
* Created on: Aug 27, 2024
|
||||
* Author: Thinkpad
|
||||
* 2026-07-18: 算法移植 DLD154V4B, 移除 FltHistoryManager / SecondOrderState /
|
||||
* StageRangeConfig 等旧算法结构
|
||||
* 2026-07-18: 算法移植 DLD154V4B, 移除 FltHistoryManager / SecondOrderState /
|
||||
* StageRangeConfig 等旧算法结构
|
||||
*/
|
||||
|
||||
#ifndef INCLUDE_CMCNG_H_
|
||||
@@ -20,9 +20,9 @@
|
||||
#define HARDWARE_VER_MAIN 4
|
||||
#define HARDWARE_VER_SUB 1
|
||||
|
||||
/* 功能模式位 (direction_mode 高4位, 协议保留; 新算法不再消费) */
|
||||
#define FUNCTION_A 0x01 // 二次判断 (已废弃)
|
||||
#define FUNCTION_B 0x02 // 二次判断增强条件判断 (已废弃)
|
||||
/* 功能模式位 (direction_mode 高4位, 协议保留; 新算法不再消费) */
|
||||
#define FUNCTION_A 0x01 // 二次判断 (已废弃)
|
||||
#define FUNCTION_B 0x02 // 二次判断增强条件判断 (已废弃)
|
||||
#define FUNCTION_C 0x04 //
|
||||
#define FUNCTION_D 0x08 //
|
||||
|
||||
@@ -38,9 +38,9 @@ extern uint8_t g_loop_power_up_state;
|
||||
|
||||
extern uint8_t g_function_mode;
|
||||
|
||||
/* 新算法状态 (DLD154V4B 移植) */
|
||||
extern uint8_t g_loop_stable; // 稳定期结束标志 (0=收敛中, 1=稳定)
|
||||
extern uint8_t g_env_activity; // 环境活跃度 (BLE condition 字段来源)
|
||||
/* 新算法状态 (DLD154V4B 移植) */
|
||||
extern uint8_t g_loop_stable; // 稳定期结束标志 (0=收敛中, 1=稳定)
|
||||
extern uint8_t g_env_activity; // 环境活跃度 (BLE condition 字段来源)
|
||||
|
||||
uint32_t mstick(void);
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
* * Len = len(CMD) + len(Data)
|
||||
*/
|
||||
#define MAGIC_BYTE_DBN_DEFAULT 0x8F
|
||||
#define MAGIC_BYTE_DBN_TRANSPARENT 0x7F // 用于 显示屏协议、地感协议、探头协议等
|
||||
#define MAGIC_BYTE_DBN_TRANSPARENT 0x7F // 用于 显示屏协议、地感协议、探头协议等
|
||||
|
||||
#define CMD_DBN_GET_DEV_INFO 0x10
|
||||
|
||||
@@ -32,9 +32,9 @@
|
||||
|
||||
#define CMD_DBN_SET_NOTIFY 0x20
|
||||
#define CMD_DBN_SET_NOTIFY_LOOP 0x21
|
||||
#define CMD_DBN_SET_SUB_CODE 0x22 //使能 子功能
|
||||
#define CMD_DBN_SET_CJQ_PARAM 0x23 // 设置 车检器参数
|
||||
#define CMD_DBN_GET_CJQ_PARAM 0x24 // 读取 车检器参数
|
||||
#define CMD_DBN_SET_SUB_CODE 0x22 //使能 子功能
|
||||
#define CMD_DBN_SET_CJQ_PARAM 0x23 // 设置 车检器参数
|
||||
#define CMD_DBN_GET_CJQ_PARAM 0x24 // 读取 车检器参数
|
||||
|
||||
#define CMD_DBN_DEV_RESET 0x6D
|
||||
|
||||
@@ -45,17 +45,17 @@
|
||||
#define CMD_DBN_SET_CJQ_FACTORY 0x92
|
||||
|
||||
|
||||
#define CMD_SUB_SENS_REPORT 0xC0 //设备主动上报传感信息
|
||||
#define CMD_SUB_SENS_REPORT 0xC0 //设备主动上报传感信息
|
||||
// #define CMD_REQUIRE_DEV_MAC_ADDR 0xC1
|
||||
// #define CMD_CHANGE_DEV_ADDR_BY_MAC 0xC2
|
||||
// #define CMD_SET_LED 0xC3
|
||||
// #define CMD_SET_RELAY 0xC4
|
||||
#define CMD_SENS_ACS_ENABLE 0xC5 // 设备主动上报 使能
|
||||
#define CMD_SENS_ACS_ENABLE 0xC5 // 设备主动上报 使能
|
||||
|
||||
|
||||
|
||||
|
||||
#define MAX_BLE_DAT_RESPONSE_LEN (BLE_BUFF_MAX_LEN - 4) // 14 //返回 的所有字节数不能超过20个字节,除去 magic、header和ckb校验字节,剩下数据的字节数为14
|
||||
#define MAX_BLE_DAT_RESPONSE_LEN (BLE_BUFF_MAX_LEN - 4) // 14 //返回 的所有字节数不能超过20个字节,除去 magic、header和ckb校验字节,剩下数据的字节数为14
|
||||
#define MAX_BLE_Notify_Buf_LEN BLE_BUFF_MAX_LEN //24
|
||||
#define MAX_BLE_BUF_LEN BLE_BUFF_MAX_LEN //128
|
||||
#define MAX_BLE_TMP_BUF_LEN BLE_BUFF_MAX_LEN
|
||||
|
||||
@@ -39,20 +39,20 @@
|
||||
typedef struct _Loop_Sample_CNG_
|
||||
{
|
||||
uint8_t flag;
|
||||
uint16_t max_amplitude; // 最大幅值
|
||||
uint16_t max_amplitude; // 最大幅值
|
||||
}Loop_Sample_Cng;
|
||||
|
||||
typedef struct _Loop_Balance_Ori_CNG_
|
||||
{
|
||||
uint8_t flag;
|
||||
uint16_t max_cnt ; // 最大补偿次数
|
||||
}Loop_Balance_Ori_Cng; // 漂移补偿
|
||||
uint16_t max_cnt ; // 最大补偿次数
|
||||
}Loop_Balance_Ori_Cng; // 漂移补偿
|
||||
|
||||
typedef struct _Loop_Release_Ori_PlanB_
|
||||
{
|
||||
uint8_t flag_weight;
|
||||
uint16_t max_amplitude; //最大幅值
|
||||
uint8_t timeout; // 单位:分钟
|
||||
uint16_t max_amplitude; //最大幅值
|
||||
uint8_t timeout; // 单位:分钟
|
||||
}Loop_Release_Ori_PlanB;
|
||||
|
||||
typedef struct _Loop_Release_Change_Rate_
|
||||
@@ -77,13 +77,13 @@ extern Loop_Balance_PlanB g_loop_balance_planB;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t sensitvity; // 高四位表示灵敏度的数量,低四位表示当前灵敏度的序号(从0开始)
|
||||
uint8_t sensitvity; // 高四位表示灵敏度的数量,低四位表示当前灵敏度的序号(从0开始)
|
||||
uint8_t delay_time;
|
||||
uint8_t output_mode;
|
||||
uint8_t direction_mode; // 方向判别模式,0 触发模式, 非0 表示方向判别模式
|
||||
uint8_t loopFreq_Level; // 高低频
|
||||
uint8_t loopSafe_Timeout; // 线圈安全模式, 0表示关闭,非0表示开启,以10秒为单位
|
||||
uint8_t exist_mode; // 0 永久存在,非0,表示有限存在的时间,单位为10秒
|
||||
uint8_t direction_mode; // 方向判别模式,0 触发模式, 非0 表示方向判别模式
|
||||
uint8_t loopFreq_Level; // 高低频
|
||||
uint8_t loopSafe_Timeout; // 线圈安全模式, 0表示关闭,非0表示开启,以10秒为单位
|
||||
uint8_t exist_mode; // 0 永久存在,非0,表示有限存在的时间,单位为10秒
|
||||
}Loop_Cng_Unit;
|
||||
extern Loop_Cng_Unit g_loop_cng_unit;
|
||||
|
||||
@@ -105,7 +105,7 @@ extern Loop_Sens_List g_loop_sens_list;
|
||||
typedef struct _DBN_BLE_STATE_
|
||||
{
|
||||
uint8_t flag; // if need to report
|
||||
uint8_t enable; // 是否使能
|
||||
uint8_t enable; // 是否使能
|
||||
uint8_t send_flag;
|
||||
uint8_t obj_amount;
|
||||
uint8_t cmd;
|
||||
@@ -126,18 +126,18 @@ extern DBN_BLE_State g_dbn_ble_state_acs_enable;
|
||||
typedef enum
|
||||
{
|
||||
SENS_NONE = 0,
|
||||
SENS_SUB_INFO = 1, // 传感器设备信息
|
||||
SENS_OBJ_DYNAMIC = 2, // 动态目标类型
|
||||
SENS_SOUTPUT_STATUS = 3, // 当前开关量输出的状态
|
||||
SENS_DETAIL_CNG = 4, // 详细配置
|
||||
SENS_LOOP_DYNAMIC = 5, // 线圈动态信息
|
||||
SENS_SUB_INFO = 1, // 传感器设备信息
|
||||
SENS_OBJ_DYNAMIC = 2, // 动态目标类型
|
||||
SENS_SOUTPUT_STATUS = 3, // 当前开关量输出的状态
|
||||
SENS_DETAIL_CNG = 4, // 详细配置
|
||||
SENS_LOOP_DYNAMIC = 5, // 线圈动态信息
|
||||
SENS_OBJ_BackGround = 6, //
|
||||
SENS_OBJ_INSIDE = 7, //
|
||||
SENS_LOOP_TREND,
|
||||
SENS_OBJ_DYNAMIC_SIMPLE,
|
||||
SENS_OBJ_STATIC_XuJing, //10, 0x0A
|
||||
SENS_DOBULE_LOOP_ESTIMATE //0x0B, 线圈环境评估
|
||||
} SUB_SENS_TYPE; // 传感数据类型
|
||||
SENS_DOBULE_LOOP_ESTIMATE //0x0B, 线圈环境评估
|
||||
} SUB_SENS_TYPE; // 传感数据类型
|
||||
|
||||
|
||||
|
||||
@@ -174,7 +174,7 @@ extern Loop_ACS_Info g_loop_acs_info;
|
||||
|
||||
|
||||
#define HOLD_TIME 5*1200
|
||||
#define LC_HOLD_TIME 4*1200 //时间4分钟
|
||||
#define LC_HOLD_TIME 4*1200 //时间4分钟
|
||||
#define IN_DELAY 10
|
||||
#define OUT_DELAY 39
|
||||
#define PLUSE_DELAY 10
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
* Author : WCH
|
||||
* Version : V1.0
|
||||
* Date : 2018/12/10
|
||||
* Description : 外设从机多连接应用程序,初始化广播连接参数,然后广播,连接主机后,
|
||||
* 请求更新连接参数,通过自定义服务传输数据
|
||||
* Description : 外设从机多连接应用程序,初始化广播连接参数,然后广播,连接主机后,
|
||||
* 请求更新连接参数,通过自定义服务传输数据
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
@@ -742,19 +742,19 @@ static void simpleProfileChangeCB(uint8_t paramID, uint8_t *pValue, uint16_t len
|
||||
}
|
||||
}
|
||||
|
||||
/* OTA 升级标志 */
|
||||
/* OTA 升级标志 */
|
||||
#define IMAGE_OTA_FLAG 0x03
|
||||
|
||||
/* 存放在DataFlash地址,不能占用蓝牙的位置 */
|
||||
/* 存放在DataFlash地址,不能占用蓝牙的位置 */
|
||||
#define OTA_DATAFLASH_ADD 0x00077000 - FLASH_ROM_MAX_SIZE
|
||||
|
||||
/* flash的数据临时存储 */
|
||||
/* flash的数据临时存储 */
|
||||
__attribute__((aligned(8))) uint8_t block_buf[16];
|
||||
|
||||
/*********************************************************************
|
||||
* @fn Jump_OTA
|
||||
*
|
||||
* @brief 跳转OTA升级
|
||||
* @brief 跳转OTA升级
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
@@ -763,19 +763,19 @@ void Jump_OTA(void)
|
||||
uint16_t i;
|
||||
uint32_t ver_flag;
|
||||
|
||||
/* 读取第一块 */
|
||||
/* 读取第一块 */
|
||||
EEPROM_READ(OTA_DATAFLASH_ADD, (uint32_t *)&block_buf[0], 4);
|
||||
|
||||
/* 擦除第一块 */
|
||||
/* 擦除第一块 */
|
||||
EEPROM_ERASE(OTA_DATAFLASH_ADD, EEPROM_PAGE_SIZE);
|
||||
|
||||
/* 更新Image信息 */
|
||||
/* 更新Image信息 */
|
||||
block_buf[0] = IMAGE_OTA_FLAG;
|
||||
|
||||
/* 编程DataFlash */
|
||||
/* 编程DataFlash */
|
||||
EEPROM_WRITE(OTA_DATAFLASH_ADD, (uint32_t *)&block_buf[0], 4);
|
||||
|
||||
/* 软复位 */
|
||||
/* 软复位 */
|
||||
SYS_ResetExecute();
|
||||
}
|
||||
|
||||
|
||||
@@ -3,15 +3,15 @@
|
||||
* Author : WCH / wangfq
|
||||
* Version : V2.0 (algorithm ported from DLD154V4B)
|
||||
* Date : 2026/07/18
|
||||
* Description : DLD110SV4 单线圈蓝牙车检器 主函数
|
||||
* Description : DLD110SV4 单线圈蓝牙车检器 主函数
|
||||
*
|
||||
* 算法说明 (移植自 DLD154V4B TaskLoop V2.0, M1H 精简系):
|
||||
* - 自适应测量窗: LPCNT = MEASUREMENT_BASE / Xn, 测量窗时长与线圈频率无关
|
||||
* - 一阶 IIR (79/256) + 斜率限幅 5% (拒绝 EMI 瞬态尖峰)
|
||||
* - 稳定期 128 窗快速收敛 (绕过滤波, 小窗口 100)
|
||||
* - 基线跟踪 窗口 500 + 冻结保护 (超时 + 稳定性双条件强制更新)
|
||||
* - 进入确认 3 次; 离开: 平坦性三条件判定 (专利 CN200910309382)
|
||||
* - 有限存在超时 / 安全复位: 全复位重建基线
|
||||
* 算法说明 (移植自 DLD154V4B TaskLoop V2.0, M1H 精简系):
|
||||
* - 自适应测量窗: LPCNT = MEASUREMENT_BASE / Xn, 测量窗时长与线圈频率无关
|
||||
* - 一阶 IIR (79/256) + 斜率限幅 5% (拒绝 EMI 瞬态尖峰)
|
||||
* - 稳定期 128 窗快速收敛 (绕过滤波, 小窗口 100)
|
||||
* - 基线跟踪 窗口 500 + 冻结保护 (超时 + 稳定性双条件强制更新)
|
||||
* - 进入确认 3 次; 离开: 平坦性三条件判定 (专利 CN200910309382)
|
||||
* - 有限存在超时 / 安全复位: 全复位重建基线
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
@@ -19,7 +19,7 @@
|
||||
*******************************************************************************/
|
||||
|
||||
/******************************************************************************/
|
||||
/* 头文件包含 */
|
||||
/* 头文件包含 */
|
||||
#include "CONFIG.h"
|
||||
#include "HAL.h"
|
||||
#include "gattprofile.h"
|
||||
@@ -30,7 +30,7 @@
|
||||
#include "dbn_ble_srv.h"
|
||||
|
||||
|
||||
uint8_t g_flag_bt_state = 0; // 0 蓝牙没有连接,1 有蓝牙连接
|
||||
uint8_t g_flag_bt_state = 0; // 0 蓝牙没有连接,1 有蓝牙连接
|
||||
uint8_t g_flag_output = 0;
|
||||
uint32_t g_xn_counter = 0;
|
||||
uint8_t g_function_mode = 0;
|
||||
@@ -51,27 +51,27 @@ uint8_t g_function_mode = 0;
|
||||
#define KEY_SA2 (GPIOA_ReadPortPin(GPIO_Pin_15))
|
||||
|
||||
const uint8_t MAX_Store_Size = 80;
|
||||
uint8_t g_loop_power_up_state = 0; // 开机启动时线圈是否连接
|
||||
uint8_t g_loop_power_up_state = 0; // 开机启动时线圈是否连接
|
||||
__IO uint32_t TimingDelayInc;
|
||||
|
||||
/*===========================================================================
|
||||
* 算法参数 -- 移植自 DLD154V4B (M4 优化版), 适配 CH591R @60MHz
|
||||
* 算法参数 -- 移植自 DLD154V4B (M4 优化版), 适配 CH591R @60MHz
|
||||
*
|
||||
* 测量窗: MEASUREMENT_BASE 个系统时钟 tick, 与线圈频率无关
|
||||
* 524288(2^19) / 60MHz ~= 8.74ms, 即 vd1_task 有效采样周期 ~8.74ms
|
||||
* (DLD154V4B 为 131072 @120MHz + 10ms 任务轮询, 时间尺度基本一致)
|
||||
* 测量窗: MEASUREMENT_BASE 个系统时钟 tick, 与线圈频率无关
|
||||
* 524288(2^19) / 60MHz ~= 8.74ms, 即 vd1_task 有效采样周期 ~8.74ms
|
||||
* (DLD154V4B 为 131072 @120MHz + 10ms 任务轮询, 时间尺度基本一致)
|
||||
*===========================================================================*/
|
||||
#define MEASUREMENT_BASE 524288L // 2^19, 自适应测量窗目标值 (Value ~= 524288)
|
||||
#define MEASUREMENT_BASE 524288L // 2^19, 自适应测量窗目标值 (Value ~= 524288)
|
||||
#define ALFA_CAP1 79 // IIR a=79/256~=0.31 (@8.74ms -> tau~=24ms)
|
||||
#define MAX_SLOPE_RATE 5 // 斜率限幅: 单次最大变化 5% (拒绝 EMI 尖峰)
|
||||
#define ENTRY_CONFIRM 3 // 进入确认: 连续 N 次低于阈值才判有车
|
||||
#define FREEZE_TIMEOUT 1000 // 基线冻结超时: ~8.7s, 持续偏高且稳定后强制更新
|
||||
#define FREEZE_STABILITY_RATE 2 // 冻结稳定性窗口: 参考值 +-2%
|
||||
#define USE_FLATNESS_EXIT 1 // 1=平坦性三条件离开, 0=简单滞回防抖
|
||||
#define WINDOW_ORIGIN 500 // 基线跟踪窗口 (500 窗 ~= 4.4s)
|
||||
#define STABLE_SAMPLES 128 // 稳定期样本数 (~1.1s)
|
||||
#define VARIATION_EVENT_TH 40 // BLE variation 事件阈值 (幅值基准 2^19, 对应旧代码的 5)
|
||||
#define ENV_ACT_TH 30 // 环境活跃度: CAPVD 相邻差绝对值阈值 (待现场验证)
|
||||
#define MAX_SLOPE_RATE 5 // 斜率限幅: 单次最大变化 5% (拒绝 EMI 尖峰)
|
||||
#define ENTRY_CONFIRM 3 // 进入确认: 连续 N 次低于阈值才判有车
|
||||
#define FREEZE_TIMEOUT 1000 // 基线冻结超时: ~8.7s, 持续偏高且稳定后强制更新
|
||||
#define FREEZE_STABILITY_RATE 2 // 冻结稳定性窗口: 参考值 +-2%
|
||||
#define USE_FLATNESS_EXIT 1 // 1=平坦性三条件离开, 0=简单滞回防抖
|
||||
#define WINDOW_ORIGIN 500 // 基线跟踪窗口 (500 窗 ~= 4.4s)
|
||||
#define STABLE_SAMPLES 128 // 稳定期样本数 (~1.1s)
|
||||
#define VARIATION_EVENT_TH 40 // BLE variation 事件阈值 (幅值基准 2^19, 对应旧代码的 5)
|
||||
#define ENV_ACT_TH 30 // 环境活跃度: CAPVD 相邻差绝对值阈值 (待现场验证)
|
||||
|
||||
uint32_t mstick(void){
|
||||
return TimingDelayInc;
|
||||
@@ -93,7 +93,7 @@ const uint8_t MacAddr[6] = {0x84, 0xC2, 0xE4, 0x03, 0x02, 0x02};
|
||||
uint8_t MACAddr[6] = {0x84, 0xC2, 0xE4, 0x03, 0x02, 0x02};
|
||||
#endif
|
||||
|
||||
uint8_t g_dev_number[6] = ""; // 设备编号 产品编号
|
||||
uint8_t g_dev_number[6] = ""; // 设备编号 产品编号
|
||||
char g_flag_debug = 1;
|
||||
|
||||
|
||||
@@ -109,27 +109,27 @@ uint8_t TM1cnt = 0;
|
||||
uint16_t g_hold_time = 0;
|
||||
|
||||
/*===========================================================================
|
||||
* 捕获 & 测量
|
||||
* 捕获 & 测量
|
||||
*===========================================================================*/
|
||||
uint16_t loop1_Xn; // 相邻下降沿周期 (TMR0 直接给出)
|
||||
uint32_t loop1_dlt_ORG; // 当前灵敏度阈值
|
||||
uint32_t loop1_Origin; // 基线 (无车参考值)
|
||||
uint16_t loop1_LPCNT; // 每个测量窗累加的 Xn 个数
|
||||
uint16_t loop1_CapCnt; // 当前窗口已累加次数
|
||||
uint32_t loop1_CapSum; // 当前窗口累加和
|
||||
uint32_t loop1_CAPVD; // IIR 滤波后的测量值
|
||||
uint32_t loop1_Value; // 一个测量窗的原始 Sigma-Xn
|
||||
uint32_t loop1_ORG_SUM; // 基线跟踪累加和
|
||||
uint16_t loop1_ORG_CNT; // 基线跟踪计数
|
||||
uint16_t loop1_Xn; // 相邻下降沿周期 (TMR0 直接给出)
|
||||
uint32_t loop1_dlt_ORG; // 当前灵敏度阈值
|
||||
uint32_t loop1_Origin; // 基线 (无车参考值)
|
||||
uint16_t loop1_LPCNT; // 每个测量窗累加的 Xn 个数
|
||||
uint16_t loop1_CapCnt; // 当前窗口已累加次数
|
||||
uint32_t loop1_CapSum; // 当前窗口累加和
|
||||
uint32_t loop1_CAPVD; // IIR 滤波后的测量值
|
||||
uint32_t loop1_Value; // 一个测量窗的原始 Sigma-Xn
|
||||
uint32_t loop1_ORG_SUM; // 基线跟踪累加和
|
||||
uint16_t loop1_ORG_CNT; // 基线跟踪计数
|
||||
|
||||
/*===========================================================================
|
||||
* 计数器
|
||||
* 计数器
|
||||
*===========================================================================*/
|
||||
uint8_t loop1_INCNT;
|
||||
uint8_t loop1_OUTCNT;
|
||||
|
||||
/*===========================================================================
|
||||
* 标志位
|
||||
* 标志位
|
||||
*===========================================================================*/
|
||||
uint8_t loop1_INI_LOOP;
|
||||
uint8_t loop1_CAP_OK;
|
||||
@@ -144,48 +144,48 @@ uint8_t loop1_FLAG_PLUSE;
|
||||
uint8_t loop1_FLAG_PLUSE_IN_F = 0;
|
||||
uint8_t loop1_FLAG_PLUSE_IN = 0;
|
||||
uint8_t loop1_FLAG_CUT;
|
||||
uint8_t loop1_FLAG_HOLD_TIMEOUT; // 有限存在超时
|
||||
uint8_t loop1_FLAG_HOLD_TIMEOUT; // 有限存在超时
|
||||
|
||||
/*===========================================================================
|
||||
* 安全复位
|
||||
* 安全复位
|
||||
*===========================================================================*/
|
||||
uint8_t loop1_LC_HOLD = 0;
|
||||
uint8_t loop1_LC_Reset = 0;
|
||||
uint32_t LC_Hold_CNT = 0;
|
||||
|
||||
/*===========================================================================
|
||||
* 新算法状态 (DLD154V4B 移植)
|
||||
* 新算法状态 (DLD154V4B 移植)
|
||||
*===========================================================================*/
|
||||
uint8_t g_loop_stable = 0; // 线圈数值已稳定 (0=稳定期中, 1=稳定)
|
||||
uint16_t loop1_stable_cnt = 0; // 稳定期样本计数
|
||||
uint8_t loop1_entry_cnt = 0; // 进入确认计数
|
||||
uint8_t loop1_cnt_release = 0; // 简单离开防抖计数 (USE_FLATNESS_EXIT=0)
|
||||
uint16_t loop1_freeze_cnt = 0; // 基线冻结持续计数
|
||||
uint32_t loop1_freeze_ref = 0; // 冻结稳定性参考值
|
||||
uint8_t g_loop_stable = 0; // 线圈数值已稳定 (0=稳定期中, 1=稳定)
|
||||
uint16_t loop1_stable_cnt = 0; // 稳定期样本计数
|
||||
uint8_t loop1_entry_cnt = 0; // 进入确认计数
|
||||
uint8_t loop1_cnt_release = 0; // 简单离开防抖计数 (USE_FLATNESS_EXIT=0)
|
||||
uint16_t loop1_freeze_cnt = 0; // 基线冻结持续计数
|
||||
uint32_t loop1_freeze_ref = 0; // 冻结稳定性参考值
|
||||
#if USE_FLATNESS_EXIT
|
||||
uint8_t g_exit_state = 0; // 0=追踪坡面, 1=等待平坦
|
||||
uint16_t g_max_slope = 0; // 第一上升坡面最大 |f'|
|
||||
uint16_t g_max_slope_rate = 0; // 第一上升坡面最大 |f''|
|
||||
uint16_t g_delta2 = 0; // 一阶平坦阈值
|
||||
uint16_t g_delta3 = 0; // 二阶平坦阈值
|
||||
int32_t g_prev_capvd = 0; // 上一帧 CAPVD (差分用)
|
||||
int32_t g_prev_first_deriv = 0; // 上一帧一阶导数
|
||||
uint8_t g_slope_flat_cnt = 0; // 斜率趋零连续计数
|
||||
uint8_t g_flat_ok_cnt = 0; // 平坦条件满足连续计数
|
||||
uint8_t g_exit_state = 0; // 0=追踪坡面, 1=等待平坦
|
||||
uint16_t g_max_slope = 0; // 第一上升坡面最大 |f'|
|
||||
uint16_t g_max_slope_rate = 0; // 第一上升坡面最大 |f''|
|
||||
uint16_t g_delta2 = 0; // 一阶平坦阈值
|
||||
uint16_t g_delta3 = 0; // 二阶平坦阈值
|
||||
int32_t g_prev_capvd = 0; // 上一帧 CAPVD (差分用)
|
||||
int32_t g_prev_first_deriv = 0; // 上一帧一阶导数
|
||||
uint8_t g_slope_flat_cnt = 0; // 斜率趋零连续计数
|
||||
uint8_t g_flat_ok_cnt = 0; // 平坦条件满足连续计数
|
||||
#endif
|
||||
|
||||
/* 环境活跃度 (供 BLE condition 字段上报, 替代旧 flt_mgr.cnt_not_idle) */
|
||||
/* 环境活跃度 (供 BLE condition 字段上报, 替代旧 flt_mgr.cnt_not_idle) */
|
||||
uint8_t g_env_activity = 0;
|
||||
uint32_t g_env_prev_capvd = 0;
|
||||
|
||||
/*===========================================================================
|
||||
* 出厂灵敏度默认表 (写入 g_loop_sens_list, 运行时以 g_loop_sens_list 为准)
|
||||
* 进入阈值 = Origin * sens_in / 65536; 离开阈值 = Origin * sens_out / 65536
|
||||
* 出厂灵敏度默认表 (写入 g_loop_sens_list, 运行时以 g_loop_sens_list 为准)
|
||||
* 进入阈值 = Origin * sens_in / 65536; 离开阈值 = Origin * sens_out / 65536
|
||||
*===========================================================================*/
|
||||
const uint16_t SensTable[MAX_LOOP_SENS_AMOUNT] = { 108, 54, 28};
|
||||
const uint16_t SensTable1[MAX_LOOP_SENS_AMOUNT] = {81, 32, 16};
|
||||
|
||||
uint16_t g_loop_out_delay = 10; // 离开延时, 50ms 为单位, 由 delay_time 配置
|
||||
uint16_t g_loop_out_delay = 10; // 离开延时, 50ms 为单位, 由 delay_time 配置
|
||||
|
||||
DBN_BLE_State g_dbn_ble_state_acs_enable = {0};
|
||||
Loop_ACS_Info g_loop_acs_info = {0,};
|
||||
@@ -193,7 +193,7 @@ Loop_ACS_Info g_loop_acs_info = {0,};
|
||||
float g_freq_tmp = 0.0;
|
||||
|
||||
|
||||
/* 用于APP判断文件有效性 */
|
||||
/* 用于APP判断文件有效性 */
|
||||
const uint32_t Address = 0xFFFFFFFF;
|
||||
|
||||
__attribute__((aligned(4))) uint32_t Image_Flag __attribute__((section(".ImageFlag"))) = (uint32_t)&Address;
|
||||
@@ -263,7 +263,7 @@ void poll_sens_key(void)
|
||||
static uint8_t _last_sens = 3;
|
||||
|
||||
#if DEBUG
|
||||
g_freq_sens = 2; // 默认最高灵敏度
|
||||
g_freq_sens = 2; // 默认最高灵敏度
|
||||
#else
|
||||
if(KEY_SA1){
|
||||
if(KEY_SA2){
|
||||
@@ -285,7 +285,7 @@ void poll_sens_key(void)
|
||||
}
|
||||
|
||||
if(_last_sens != g_freq_sens){
|
||||
/* 灵敏度阈值每周期由 g_loop_sens_list 实时计算, 无需重载 */
|
||||
/* 灵敏度阈值每周期由 g_loop_sens_list 实时计算, 无需重载 */
|
||||
_last_sens = g_freq_sens;
|
||||
}
|
||||
|
||||
@@ -309,7 +309,7 @@ void para_store_init(void)
|
||||
|
||||
poll_sens_key();
|
||||
|
||||
g_loop_out_delay = g_loop_cng_unit.delay_time * 2; // 定时器以 50ms 为单位, 延时以100ms为单位
|
||||
g_loop_out_delay = g_loop_cng_unit.delay_time * 2; // 定时器以 50ms 为单位, 延时以100ms为单位
|
||||
g_hold_time = g_loop_cng_unit.exist_mode * 30 * 20; //50ms/per, 30s
|
||||
g_safe_max_cnt = g_loop_cng_unit.loopSafe_Timeout * 10 * (1000 / 50);
|
||||
g_freq_level = g_loop_cng_unit.loopFreq_Level - 1;
|
||||
@@ -322,23 +322,23 @@ void para_store_init(void)
|
||||
switch(g_freq_level)
|
||||
{
|
||||
case 0: {
|
||||
// 高频
|
||||
// 高频
|
||||
FLEVEL_H_LOW; FLEVEL_L_LOW;
|
||||
} break;
|
||||
case 1: {
|
||||
// 中高
|
||||
// 中高
|
||||
FLEVEL_H_LOW; FLEVEL_L_HIGH;
|
||||
} break;
|
||||
case 2: {
|
||||
// 中低
|
||||
// 中低
|
||||
FLEVEL_H_HIGH; FLEVEL_L_LOW;
|
||||
} break;
|
||||
case 3: {
|
||||
// 低频
|
||||
// 低频
|
||||
FLEVEL_H_HIGH; FLEVEL_L_HIGH;
|
||||
} break;
|
||||
default:{
|
||||
// 默认低频
|
||||
// 默认低频
|
||||
g_freq_level = 3;
|
||||
FLEVEL_H_HIGH; FLEVEL_L_HIGH;
|
||||
} break;
|
||||
@@ -360,7 +360,7 @@ void para_store_init(void)
|
||||
|
||||
void tm_init(void){
|
||||
|
||||
// Cap 捕获
|
||||
// Cap 捕获
|
||||
GPIOA_ResetBits(GPIO_Pin_9);
|
||||
GPIOA_ModeCfg(GPIO_Pin_9, GPIO_ModeIN_Floating);
|
||||
|
||||
@@ -372,29 +372,29 @@ void tm_init(void){
|
||||
|
||||
|
||||
// TMR1
|
||||
TMR1_TimerInit(FREQ_SYS / 200); // 设置定时时间 5ms
|
||||
TMR1_ITCfg(ENABLE, TMR0_3_IT_CYC_END); // 开启中断
|
||||
TMR1_TimerInit(FREQ_SYS / 200); // 设置定时时间 5ms
|
||||
TMR1_ITCfg(ENABLE, TMR0_3_IT_CYC_END); // 开启中断
|
||||
PFIC_EnableIRQ(TMR1_IRQn);
|
||||
}
|
||||
|
||||
void gpio_uart_init(void)
|
||||
{
|
||||
/* 配置串口0:先配置IO口模式,再配置串口 */
|
||||
/* 配置串口0:先配置IO口模式,再配置串口 */
|
||||
#ifdef DEBUG
|
||||
GPIOPinRemap(ENABLE, RB_PIN_UART0);
|
||||
GPIOA_SetBits(GPIO_Pin_14);
|
||||
GPIOA_ModeCfg(GPIO_Pin_14, GPIO_ModeOut_PP_5mA); // TXD-配置推挽输出,注意先让IO口输出高电平
|
||||
GPIOA_ModeCfg(GPIO_Pin_14, GPIO_ModeOut_PP_5mA); // TXD-配置推挽输出,注意先让IO口输出高电平
|
||||
|
||||
UART0_BaudRateCfg(230400); //115200
|
||||
R8_UART0_FCR = (2 << 6) | RB_FCR_TX_FIFO_CLR | RB_FCR_RX_FIFO_CLR | RB_FCR_FIFO_EN; // FIFO打开,触发点4字节
|
||||
R8_UART0_FCR = (2 << 6) | RB_FCR_TX_FIFO_CLR | RB_FCR_RX_FIFO_CLR | RB_FCR_FIFO_EN; // FIFO打开,触发点4字节
|
||||
R8_UART0_LCR = RB_LCR_WORD_SZ;
|
||||
R8_UART0_IER = RB_IER_TXD_EN;
|
||||
R8_UART0_DIV = 1;
|
||||
|
||||
GPIOA_ModeCfg(GPIO_Pin_15, GPIO_ModeIN_PU); // 拨动开关,调节灵敏度
|
||||
GPIOA_ModeCfg(GPIO_Pin_15, GPIO_ModeIN_PU); // 拨动开关,调节灵敏度
|
||||
#else
|
||||
|
||||
GPIOA_ModeCfg(GPIO_Pin_15|GPIO_Pin_14, GPIO_ModeIN_PU); // 拨动开关,调节灵敏度
|
||||
GPIOA_ModeCfg(GPIO_Pin_15|GPIO_Pin_14, GPIO_ModeIN_PU); // 拨动开关,调节灵敏度
|
||||
|
||||
#endif
|
||||
|
||||
@@ -413,7 +413,7 @@ void gpio_uart_init(void)
|
||||
|
||||
|
||||
/*===========================================================================
|
||||
* 一阶 IIR 低通滤波器 (对齐 M1H 公式)
|
||||
* 一阶 IIR 低通滤波器 (对齐 M1H 公式)
|
||||
* CAPVD_new = a * new_value + (1-a) * CAPVD_old, a = Flt_Reg/256
|
||||
*===========================================================================*/
|
||||
uint32_t get_flt_value(uint32_t new_value, uint32_t last_Value) {
|
||||
@@ -432,8 +432,8 @@ uint32_t get_flt_value(uint32_t new_value, uint32_t last_Value) {
|
||||
|
||||
|
||||
/*===========================================================================
|
||||
* 滑动平均基线更新
|
||||
* 注意: window 必须是 uint16_t (WINDOW_ORIGIN=500 > 255, uint8_t 会静默截断)
|
||||
* 滑动平均基线更新
|
||||
* 注意: window 必须是 uint16_t (WINDOW_ORIGIN=500 > 255, uint8_t 会静默截断)
|
||||
*===========================================================================*/
|
||||
void update_moving_average(uint32_t* p_sum, uint16_t* p_cnt, uint32_t* p_origin, uint32_t new_value, uint16_t window) {
|
||||
if (!p_sum || !p_cnt || !p_origin || window == 0) {
|
||||
@@ -452,8 +452,8 @@ void update_moving_average(uint32_t* p_sum, uint16_t* p_cnt, uint32_t* p_origin,
|
||||
|
||||
|
||||
/*===========================================================================
|
||||
* 初始化所有检测状态 (上电 / 有限存在超时 / 线圈重连 时调用)
|
||||
* 注意: 不复位 g_loop_power_up_state / g_loop_cut_amount (BLE 上报用)
|
||||
* 初始化所有检测状态 (上电 / 有限存在超时 / 线圈重连 时调用)
|
||||
* 注意: 不复位 g_loop_power_up_state / g_loop_cut_amount (BLE 上报用)
|
||||
*===========================================================================*/
|
||||
void INIT_VD(void)
|
||||
{
|
||||
@@ -493,7 +493,7 @@ void INIT_VD(void)
|
||||
loop1_LC_Reset = 0;
|
||||
LC_Hold_CNT = 0;
|
||||
|
||||
/* 新算法状态 */
|
||||
/* 新算法状态 */
|
||||
g_loop_stable = 0;
|
||||
loop1_stable_cnt = 0;
|
||||
loop1_entry_cnt = 0;
|
||||
@@ -519,7 +519,7 @@ void INIT_VD(void)
|
||||
|
||||
|
||||
/*===========================================================================
|
||||
* 车辆离开 / 释放 公共处理
|
||||
* 车辆离开 / 释放 公共处理
|
||||
*===========================================================================*/
|
||||
static void loop_release_common(void)
|
||||
{
|
||||
@@ -539,19 +539,19 @@ static void loop_release_common(void)
|
||||
|
||||
|
||||
/*===========================================================================
|
||||
* vd1_task -- 核心检测算法 (移植 DLD154V4B, 每次 CAP_OK 调用, ~8.74ms)
|
||||
* vd1_task -- 核心检测算法 (移植 DLD154V4B, 每次 CAP_OK 调用, ~8.74ms)
|
||||
*
|
||||
* 流程:
|
||||
* 1. IIR 滤波 + 斜率限幅
|
||||
* 2. 稳定期: 小窗口快速收敛基线
|
||||
* 3. 无车: 基线跟踪 (冻结保护) + 进入确认
|
||||
* 4. 有车: 平坦性三条件离开判定 (带滞回)
|
||||
* 流程:
|
||||
* 1. IIR 滤波 + 斜率限幅
|
||||
* 2. 稳定期: 小窗口快速收敛基线
|
||||
* 3. 无车: 基线跟踪 (冻结保护) + 进入确认
|
||||
* 4. 有车: 平坦性三条件离开判定 (带滞回)
|
||||
*===========================================================================*/
|
||||
void vd1_task(void){
|
||||
|
||||
if (loop1_Origin == 0) return;
|
||||
|
||||
/*--- 1. IIR 滤波 + 斜率限幅 ---*/
|
||||
/*--- 1. IIR 滤波 + 斜率限幅 ---*/
|
||||
if (loop1_CAPVD == 0) {
|
||||
loop1_CAPVD = loop1_Value;
|
||||
} else {
|
||||
@@ -565,7 +565,7 @@ void vd1_task(void){
|
||||
loop1_CAPVD = get_flt_value(clamped_value, loop1_CAPVD);
|
||||
}
|
||||
|
||||
/*--- 2. 稳定期: 绕过 IIR/斜率限幅, 小窗口快速收敛 ---*/
|
||||
/*--- 2. 稳定期: 绕过 IIR/斜率限幅, 小窗口快速收敛 ---*/
|
||||
if (!g_loop_stable) {
|
||||
loop1_CAPVD = loop1_Value;
|
||||
update_moving_average(&loop1_ORG_SUM, &loop1_ORG_CNT, &loop1_Origin, loop1_CAPVD, 100);
|
||||
@@ -577,7 +577,7 @@ void vd1_task(void){
|
||||
return;
|
||||
}
|
||||
|
||||
/*--- 3. BLE 上报状态刷新 (flag_change 置位期间冻结, 保持事件时刻的值) ---*/
|
||||
/*--- 3. BLE 上报状态刷新 (flag_change 置位期间冻结, 保持事件时刻的值) ---*/
|
||||
if (g_loop_acs_info.flag_change == 0) {
|
||||
int32_t _var = (int32_t)loop1_Origin - (int32_t)loop1_CAPVD;
|
||||
g_loop_acs_info.loop_capvd = loop1_CAPVD;
|
||||
@@ -587,7 +587,7 @@ void vd1_task(void){
|
||||
}
|
||||
}
|
||||
|
||||
/*--- 4. 环境活跃度 (BLE condition 字段, 0~15) ---*/
|
||||
/*--- 4. 环境活跃度 (BLE condition 字段, 0~15) ---*/
|
||||
{
|
||||
int32_t d = (int32_t)loop1_CAPVD - (int32_t)g_env_prev_capvd;
|
||||
if (d < 0) d = -d;
|
||||
@@ -601,7 +601,7 @@ void vd1_task(void){
|
||||
|
||||
if (!loop1_VD_FLAG) {
|
||||
/*================================================================
|
||||
* 无车状态: 基线跟踪 (冻结保护) + 进入确认
|
||||
* 无车状态: 基线跟踪 (冻结保护) + 进入确认
|
||||
*================================================================*/
|
||||
loop1_dlt_ORG = ((uint32_t)loop1_Origin * g_loop_sens_list.sens[g_freq_sens].sens_in) >> 16;
|
||||
{
|
||||
@@ -610,7 +610,7 @@ void vd1_task(void){
|
||||
loop1_freeze_cnt = 0;
|
||||
update_moving_average(&loop1_ORG_SUM, &loop1_ORG_CNT, &loop1_Origin, loop1_CAPVD, WINDOW_ORIGIN);
|
||||
} else {
|
||||
/*--- CAPVD 异常偏高: 暂停跟踪, 冻结超时 + 稳定性双条件 ---*/
|
||||
/*--- CAPVD 异常偏高: 暂停跟踪, 冻结超时 + 稳定性双条件 ---*/
|
||||
if (loop1_freeze_cnt == 0) {
|
||||
loop1_freeze_ref = loop1_CAPVD;
|
||||
} else {
|
||||
@@ -623,7 +623,7 @@ void vd1_task(void){
|
||||
}
|
||||
loop1_freeze_cnt++;
|
||||
if (loop1_freeze_cnt >= FREEZE_TIMEOUT) {
|
||||
loop1_Origin = loop1_CAPVD; /* 确认稳定的新常态 */
|
||||
loop1_Origin = loop1_CAPVD; /* 确认稳定的新常态 */
|
||||
loop1_freeze_cnt = 0;
|
||||
loop1_freeze_ref = 0;
|
||||
}
|
||||
@@ -632,7 +632,7 @@ void vd1_task(void){
|
||||
}
|
||||
}
|
||||
|
||||
/*--- 进入确认: 连续 ENTRY_CONFIRM 次低于阈值才判有车 ---*/
|
||||
/*--- 进入确认: 连续 ENTRY_CONFIRM 次低于阈值才判有车 ---*/
|
||||
if (loop1_CAPVD < (loop1_Origin - loop1_dlt_ORG)) {
|
||||
loop1_entry_cnt++;
|
||||
if (loop1_entry_cnt >= ENTRY_CONFIRM) {
|
||||
@@ -643,11 +643,11 @@ void vd1_task(void){
|
||||
loop1_VD_FLAG = 1;
|
||||
loop1_FLAG_IN = 1;
|
||||
|
||||
if (g_loop_cng_unit.exist_mode) { /* 有限存在 */
|
||||
if (g_loop_cng_unit.exist_mode) { /* 有限存在 */
|
||||
loop1_VD_HOLD = 1;
|
||||
Hold_CNT = 0;
|
||||
}
|
||||
if (g_loop_cng_unit.loopSafe_Timeout) { /* 线圈安全模式: 启动安全复位计时 */
|
||||
if (g_loop_cng_unit.loopSafe_Timeout) { /* 线圈安全模式: 启动安全复位计时 */
|
||||
loop1_LC_HOLD = 1;
|
||||
LC_Hold_CNT = 0;
|
||||
} else {
|
||||
@@ -665,7 +665,7 @@ void vd1_task(void){
|
||||
g_loop_acs_info.car_state = 1;
|
||||
|
||||
#if USE_FLATNESS_EXIT
|
||||
/* 重置平坦性状态 (专利 CN200910309382) */
|
||||
/* 重置平坦性状态 (专利 CN200910309382) */
|
||||
g_exit_state = 0;
|
||||
g_max_slope = 0;
|
||||
g_max_slope_rate = 0;
|
||||
@@ -684,8 +684,8 @@ void vd1_task(void){
|
||||
else {
|
||||
#if USE_FLATNESS_EXIT
|
||||
/*================================================================
|
||||
* 有车状态: 平坦性三条件判定离开 (专利 CN200910309382)
|
||||
* 幅值阈值按新测量基准 2^19 缩放 (DLD154V4B: 100/5/2 @2^17)
|
||||
* 有车状态: 平坦性三条件判定离开 (专利 CN200910309382)
|
||||
* 幅值阈值按新测量基准 2^19 缩放 (DLD154V4B: 100/5/2 @2^17)
|
||||
*================================================================*/
|
||||
#define K1 8
|
||||
#define K2 8
|
||||
@@ -702,7 +702,7 @@ void vd1_task(void){
|
||||
abs_sd = (second_deriv >= 0) ? second_deriv : -second_deriv;
|
||||
|
||||
if (g_exit_state == 0) {
|
||||
/*--- 阶段0: 追踪第一上升坡面, 自适应计算平坦阈值 ---*/
|
||||
/*--- 阶段0: 追踪第一上升坡面, 自适应计算平坦阈值 ---*/
|
||||
if (abs_fd > (int32_t)g_max_slope) g_max_slope = (uint16_t)abs_fd;
|
||||
if (abs_sd > (int32_t)g_max_slope_rate) g_max_slope_rate = (uint16_t)abs_sd;
|
||||
if (abs_fd < SLOPE_FLAT_THRESH) {
|
||||
@@ -719,7 +719,7 @@ void vd1_task(void){
|
||||
g_slope_flat_cnt = 0;
|
||||
}
|
||||
} else {
|
||||
/*--- 阶段1: 幅值回归 + 一阶平坦 + 二阶平坦 三条件确认离开 ---*/
|
||||
/*--- 阶段1: 幅值回归 + 一阶平坦 + 二阶平坦 三条件确认离开 ---*/
|
||||
int32_t dev = (int32_t)loop1_CAPVD - (int32_t)loop1_Origin;
|
||||
int32_t cond1 = (dev >= 0) ? dev : -dev;
|
||||
loop1_dlt_ORG = ((uint32_t)loop1_Origin * g_loop_sens_list.sens[g_freq_sens].sens_out) >> 16;
|
||||
@@ -739,7 +739,7 @@ void vd1_task(void){
|
||||
g_prev_first_deriv = first_deriv;
|
||||
#else
|
||||
/*================================================================
|
||||
* 有车状态: 简单滞回 + 防抖离开
|
||||
* 有车状态: 简单滞回 + 防抖离开
|
||||
*================================================================*/
|
||||
loop1_dlt_ORG = ((uint32_t)loop1_Origin * g_loop_sens_list.sens[g_freq_sens].sens_out) >> 16;
|
||||
|
||||
@@ -758,33 +758,33 @@ void vd1_task(void){
|
||||
|
||||
|
||||
/*===========================================================================
|
||||
* cjq_srv -- 车检器主循环服务
|
||||
* - 有限存在超时 / 线圈断开重连: 全复位重建基线
|
||||
* (线圈仍被占用时, 新基线落在占用值上, 继电器保持释放 -- 对齐 M1H 行为)
|
||||
* - CAP_OK 到达时执行核心检测算法
|
||||
* cjq_srv -- 车检器主循环服务
|
||||
* - 有限存在超时 / 线圈断开重连: 全复位重建基线
|
||||
* (线圈仍被占用时, 新基线落在占用值上, 继电器保持释放 -- 对齐 M1H 行为)
|
||||
* - CAP_OK 到达时执行核心检测算法
|
||||
*===========================================================================*/
|
||||
void cjq_srv(void){
|
||||
|
||||
if(loop1_LOOP_OK){
|
||||
if(loop1_FLAG_HOLD_TIMEOUT){
|
||||
/* 有限存在超时: 全复位, 重新经历稳定期重建基线 */
|
||||
/* 有限存在超时: 全复位, 重新经历稳定期重建基线 */
|
||||
INIT_VD();
|
||||
return;
|
||||
}
|
||||
if(loop1_FLAG_CUT){
|
||||
/* 线圈断开后重连: 全复位, 重新自适应测量窗并重建基线 */
|
||||
/* 线圈断开后重连: 全复位, 重新自适应测量窗并重建基线 */
|
||||
g_loop_cut_last = 0;
|
||||
INIT_VD();
|
||||
return;
|
||||
}
|
||||
if(!loop1_LOOP_OK0){
|
||||
DelayMs(200); /* 线圈重新起振后等待 200ms 再消费数据 */
|
||||
DelayMs(200); /* 线圈重新起振后等待 200ms 再消费数据 */
|
||||
loop1_LOOP_OK0 = 1;
|
||||
}
|
||||
if(loop1_CAP_OK){
|
||||
loop1_CAP_OK = 0;
|
||||
if(!g_loop_power_up_state){
|
||||
g_loop_power_up_state = 1; // 表示连接了线圈
|
||||
g_loop_power_up_state = 1; // 表示连接了线圈
|
||||
}
|
||||
vd1_task();
|
||||
poll_sens_key();
|
||||
@@ -799,7 +799,7 @@ void cjq_srv(void){
|
||||
loop1_FLAG_PLUSE_IN_F = 0;
|
||||
loop1_FLAG_PLUSE_IN = 0;
|
||||
|
||||
// 线圈断开: 继电器释放, 车辆状态清零
|
||||
// 线圈断开: 继电器释放, 车辆状态清零
|
||||
RLY1_OFF; RLY2_OFF;
|
||||
g_loop_acs_info.relay1_state = 0;
|
||||
g_loop_acs_info.relay2_state = 0;
|
||||
@@ -824,7 +824,7 @@ void cjq_srv(void){
|
||||
/*********************************************************************
|
||||
* @fn Main_Circulation
|
||||
*
|
||||
* @brief 主循环
|
||||
* @brief 主循环
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
@@ -843,7 +843,7 @@ void Main_Circulation()
|
||||
cjq_srv();
|
||||
|
||||
if(g_flag_bt_state == 0){
|
||||
// 如果蓝牙断开,主动上报需要禁用
|
||||
// 如果蓝牙断开,主动上报需要禁用
|
||||
if(g_dbn_ble_state_acs_enable.enable){
|
||||
g_dbn_ble_state_acs_enable.enable = 0;
|
||||
}
|
||||
@@ -867,7 +867,7 @@ void Main_Circulation()
|
||||
/*********************************************************************
|
||||
* @fn main
|
||||
*
|
||||
* @brief 主函数
|
||||
* @brief 主函数
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
@@ -907,15 +907,15 @@ int main(void)
|
||||
|
||||
/* @fn TMR0_IRQHandler
|
||||
*
|
||||
* @brief TMR0 输入捕获中断 -- 线圈频率测量
|
||||
* FallEdge_To_FallEdge 模式, CAPGetData 直接给出相邻下降沿周期 Xn
|
||||
* 累加 LPCNT 次 -> 一个测量窗 Value (~= MEASUREMENT_BASE)
|
||||
* @brief TMR0 输入捕获中断 -- 线圈频率测量
|
||||
* FallEdge_To_FallEdge 模式, CAPGetData 直接给出相邻下降沿周期 Xn
|
||||
* 累加 LPCNT 次 -> 一个测量窗 Value (~= MEASUREMENT_BASE)
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
__INTERRUPT
|
||||
__HIGH_CODE
|
||||
void TMR0_IRQHandler(void) // TMR0 捕获中断
|
||||
void TMR0_IRQHandler(void) // TMR0 捕获中断
|
||||
{
|
||||
if(TMR0_GetITFlag(TMR0_3_IT_DATA_ACT)){
|
||||
loop1_Xn = (uint16_t)TMR0_CAPGetData();
|
||||
@@ -936,12 +936,12 @@ void TMR0_IRQHandler(void) // TMR0
|
||||
loop1_CapCnt++;
|
||||
|
||||
if(loop1_INI_LOOP){
|
||||
/*--- 初始化阶段 ---*/
|
||||
/*--- 初始化阶段 ---*/
|
||||
if(loop1_LPCNT == 0){
|
||||
if(loop1_CapCnt > 200){ /* 上电/换频后等待振荡稳定 */
|
||||
if(loop1_CapCnt > 200){ /* 上电/换频后等待振荡稳定 */
|
||||
uint32_t lpcnt = (uint32_t)MEASUREMENT_BASE / loop1_Xn;
|
||||
if(lpcnt == 0 || lpcnt > 65535){
|
||||
lpcnt = 100; /* 异常 Xn 保护 */
|
||||
lpcnt = 100; /* 异常 Xn 保护 */
|
||||
}
|
||||
loop1_LPCNT = (uint16_t)lpcnt;
|
||||
|
||||
@@ -953,7 +953,7 @@ void TMR0_IRQHandler(void) // TMR0
|
||||
}
|
||||
}
|
||||
else{
|
||||
/* 第一个测量窗: 直接作为基线 Origin */
|
||||
/* 第一个测量窗: 直接作为基线 Origin */
|
||||
loop1_CapSum += loop1_Xn;
|
||||
if(loop1_CapCnt >= loop1_LPCNT){
|
||||
loop1_CAPVD = loop1_CapSum;
|
||||
@@ -969,7 +969,7 @@ void TMR0_IRQHandler(void) // TMR0
|
||||
}
|
||||
}// end if loop1_INI_LOOP
|
||||
else {
|
||||
/*--- 正常运行: 累加到测量窗 ---*/
|
||||
/*--- 正常运行: 累加到测量窗 ---*/
|
||||
loop1_CapSum += loop1_Xn;
|
||||
|
||||
if(loop1_CapCnt >= loop1_LPCNT){
|
||||
@@ -990,7 +990,7 @@ void TMR0_IRQHandler(void) // TMR0
|
||||
/*********************************************************************
|
||||
* @fn TMR1_IRQHandler
|
||||
*
|
||||
* @brief TMR1 定时中断 5ms/per -- 时序状态机 / 继电器输出 / LED
|
||||
* @brief TMR1 定时中断 5ms/per -- 时序状态机 / 继电器输出 / LED
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
@@ -1020,7 +1020,7 @@ void TMR1_IRQHandler(void)
|
||||
TimingDelayInc++;
|
||||
u32CountWdt++;
|
||||
|
||||
/*--- LED: 稳定期 200ms 快闪; 线圈断开 150ms 快闪 ---*/
|
||||
/*--- LED: 稳定期 200ms 快闪; 线圈断开 150ms 快闪 ---*/
|
||||
if(loop1_FLAG_CUT == 0)
|
||||
{
|
||||
if(!g_loop_stable)
|
||||
@@ -1047,12 +1047,12 @@ void TMR1_IRQHandler(void)
|
||||
if(TM1cnt >= 10) //about=50ms
|
||||
{
|
||||
TM1cnt = 0;
|
||||
if(loop1_FLAG_IN) // 线圈1 从无车到有车
|
||||
if(loop1_FLAG_IN) // 线圈1 从无车到有车
|
||||
{
|
||||
loop1_FLAG_OUT = 0;
|
||||
loop1_OUTCNT = 0;
|
||||
loop1_FLAG_IN = 0;
|
||||
if(g_loop_cng_unit.output_mode == 1) // 进入脉冲
|
||||
if(g_loop_cng_unit.output_mode == 1) // 进入脉冲
|
||||
{
|
||||
loop1_FLAG_PLUSE_IN_F = 1;
|
||||
}
|
||||
@@ -1082,7 +1082,7 @@ void TMR1_IRQHandler(void)
|
||||
}
|
||||
|
||||
|
||||
if(loop1_FLAG_OUT) // 从有车到无车的标志
|
||||
if(loop1_FLAG_OUT) // 从有车到无车的标志
|
||||
{
|
||||
loop1_OUTCNT++;
|
||||
if(loop1_OUTCNT > g_loop_out_delay)
|
||||
@@ -1108,13 +1108,13 @@ void TMR1_IRQHandler(void)
|
||||
if(loop1_VD_HOLD)
|
||||
{
|
||||
Hold_CNT++;
|
||||
if(Hold_CNT > g_hold_time) // 超过有限存在时间
|
||||
if(Hold_CNT > g_hold_time) // 超过有限存在时间
|
||||
{
|
||||
loop1_VD_HOLD = 0;
|
||||
Hold_CNT = 0;
|
||||
if(loop1_VD_FLAG)
|
||||
{
|
||||
/* 有限存在超时: 释放继电器, 主循环全复位重建基线 */
|
||||
/* 有限存在超时: 释放继电器, 主循环全复位重建基线 */
|
||||
loop1_FLAG_HOLD_TIMEOUT = 1;
|
||||
RLY1_OFF; RLY2_OFF;
|
||||
g_loop_acs_info.relay1_state = 0;
|
||||
@@ -1128,7 +1128,7 @@ void TMR1_IRQHandler(void)
|
||||
LC_Hold_CNT++;
|
||||
if(LC_Hold_CNT > g_safe_max_cnt)
|
||||
{
|
||||
/* 安全复位: 重新初始化测量, 重建基线 (对齐 M1H) */
|
||||
/* 安全复位: 重新初始化测量, 重建基线 (对齐 M1H) */
|
||||
loop1_LC_Reset = 1;
|
||||
loop1_INI_LOOP = 1;
|
||||
loop1_LOOP_OK0 = 0;
|
||||
@@ -1148,7 +1148,7 @@ void TMR1_IRQHandler(void)
|
||||
}
|
||||
}
|
||||
|
||||
/*--- 线圈载波检测 & 继电器输出刷新 (每 5ms) ---*/
|
||||
/*--- 线圈载波检测 & 继电器输出刷新 (每 5ms) ---*/
|
||||
if(loop1_RF_FLAG)
|
||||
{
|
||||
loop1_LOOP_OK = 1;
|
||||
@@ -1157,10 +1157,10 @@ void TMR1_IRQHandler(void)
|
||||
if(loop1_LC_Reset == 0)
|
||||
{
|
||||
switch(g_loop_cng_unit.output_mode)
|
||||
{ // 输出方式
|
||||
case 0: // 存在输出
|
||||
{ // 输出方式
|
||||
case 0: // 存在输出
|
||||
{
|
||||
if(loop1_VD_FLAG | loop1_FLAG_OUT)// 输出存在信号
|
||||
if(loop1_VD_FLAG | loop1_FLAG_OUT)// 输出存在信号
|
||||
{
|
||||
RLY1_ON;
|
||||
g_loop_acs_info.relay1_state = 1;
|
||||
@@ -1175,9 +1175,9 @@ void TMR1_IRQHandler(void)
|
||||
g_loop_acs_info.relay2_state = 0;
|
||||
}
|
||||
} break;
|
||||
case 1: // 进入脉冲
|
||||
case 1: // 进入脉冲
|
||||
{
|
||||
if(loop1_VD_FLAG) // 继电器2存在信号
|
||||
if(loop1_VD_FLAG) // 继电器2存在信号
|
||||
{
|
||||
RLY2_ON;
|
||||
g_loop_acs_info.relay2_state = 1;
|
||||
@@ -1199,9 +1199,9 @@ void TMR1_IRQHandler(void)
|
||||
g_loop_acs_info.relay1_state = 0;
|
||||
}
|
||||
} break;
|
||||
case 2: // 离开脉冲
|
||||
case 2: // 离开脉冲
|
||||
{
|
||||
if(loop1_VD_FLAG) // 继电器2存在信号
|
||||
if(loop1_VD_FLAG) // 继电器2存在信号
|
||||
{
|
||||
RLY2_ON;
|
||||
g_loop_acs_info.relay2_state = 1;
|
||||
@@ -1212,7 +1212,7 @@ void TMR1_IRQHandler(void)
|
||||
g_loop_acs_info.relay2_state = 0;
|
||||
}
|
||||
|
||||
if(loop1_FLAG_PLUSE) // 输出离开脉冲
|
||||
if(loop1_FLAG_PLUSE) // 输出离开脉冲
|
||||
{
|
||||
RLY1_ON;
|
||||
g_loop_acs_info.relay1_state = 1;
|
||||
@@ -1224,7 +1224,7 @@ void TMR1_IRQHandler(void)
|
||||
}
|
||||
} break;
|
||||
default: {
|
||||
if(loop1_VD_FLAG) // 继电器2存在信号
|
||||
if(loop1_VD_FLAG) // 继电器2存在信号
|
||||
{
|
||||
RLY2_ON;
|
||||
g_loop_acs_info.relay2_state = 1;
|
||||
@@ -1246,7 +1246,7 @@ void TMR1_IRQHandler(void)
|
||||
|
||||
|
||||
|
||||
TMR1_ClearITFlag(TMR0_3_IT_CYC_END); // 清除中断标志
|
||||
TMR1_ClearITFlag(TMR0_3_IT_CYC_END); // 清除中断标志
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Author : WCH
|
||||
* Version : V1.0
|
||||
* Date : 2018/12/10
|
||||
* Description : É豸ÐÅÏ¢·þÎñ
|
||||
* Description : 设备信息服务
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Author : WCH
|
||||
* Version : V1.0
|
||||
* Date : 2018/12/10
|
||||
* Description : 自定义包含五种不同属性的服务,包含可读、可写、通知、可读可写、安全可读
|
||||
* Description : 自定义包含五种不同属性的服务,包含可读、可写、通知、可读可写、安全可读
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
|
||||
+6
-6
@@ -11,14 +11,14 @@
|
||||
*******************************************************************************/
|
||||
|
||||
/******************************************************************************/
|
||||
/* 头文件包含 */
|
||||
/* 头文件包含 */
|
||||
#include "HAL.h"
|
||||
|
||||
/**************************************************************************************************
|
||||
* GLOBAL VARIABLES
|
||||
**************************************************************************************************/
|
||||
|
||||
static uint8_t halKeySavedKeys; /* 保留按键最后的状态,用于查询是否有键值变化 */
|
||||
static uint8_t halKeySavedKeys; /* 保留按键最后的状态,用于查询是否有键值变化 */
|
||||
|
||||
/**************************************************************************************************
|
||||
* FUNCTIONS - Local
|
||||
@@ -76,19 +76,19 @@ uint8_t HalKeyRead(void)
|
||||
uint8_t keys = 0;
|
||||
|
||||
if(HAL_PUSH_BUTTON1())
|
||||
{ //读按键1
|
||||
{ //读按键1
|
||||
keys |= HAL_KEY_SW_1;
|
||||
}
|
||||
if(HAL_PUSH_BUTTON2())
|
||||
{ //读按键1
|
||||
{ //读按键1
|
||||
keys |= HAL_KEY_SW_2;
|
||||
}
|
||||
if(HAL_PUSH_BUTTON3())
|
||||
{ //读按键1
|
||||
{ //读按键1
|
||||
keys |= HAL_KEY_SW_3;
|
||||
}
|
||||
if(HAL_PUSH_BUTTON4())
|
||||
{ //读按键1
|
||||
{ //读按键1
|
||||
keys |= HAL_KEY_SW_4;
|
||||
}
|
||||
return keys;
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@
|
||||
*******************************************************************************/
|
||||
|
||||
/******************************************************************************/
|
||||
/* Í·Îļþ°üº¬ */
|
||||
/* 头文件包含 */
|
||||
#include "HAL.h"
|
||||
|
||||
/* LED control structure */
|
||||
|
||||
+20
-20
@@ -3,7 +3,7 @@
|
||||
* Author : WCH
|
||||
* Version : V1.2
|
||||
* Date : 2022/01/18
|
||||
* Description : 硬件任务处理函数及BLE和硬件初始化
|
||||
* Description : 硬件任务处理函数及BLE和硬件初始化
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
@@ -11,7 +11,7 @@
|
||||
*******************************************************************************/
|
||||
|
||||
/******************************************************************************/
|
||||
/* 头文件包含 */
|
||||
/* 头文件包含 */
|
||||
#include "HAL.h"
|
||||
|
||||
tmosTaskID halTaskID;
|
||||
@@ -19,7 +19,7 @@ uint32_t g_LLE_IRQLibHandlerLocation;
|
||||
/*******************************************************************************
|
||||
* @fn Lib_Calibration_LSI
|
||||
*
|
||||
* @brief 内部32k校准
|
||||
* @brief 内部32k校准
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
@@ -96,7 +96,7 @@ uint32_t Lib_Write_Flash(uint32_t addr, uint32_t num, uint32_t *pBuf)
|
||||
/*******************************************************************************
|
||||
* @fn CH59x_BLEInit
|
||||
*
|
||||
* @brief BLE 库初始化
|
||||
* @brief BLE 库初始化
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
@@ -112,7 +112,7 @@ void CH59x_BLEInit(void)
|
||||
// while(1);
|
||||
}
|
||||
|
||||
SysTick_Config(SysTick_LOAD_RELOAD_Msk);// 配置SysTick并打开中断
|
||||
SysTick_Config(SysTick_LOAD_RELOAD_Msk);// 配置SysTick并打开中断
|
||||
PFIC_DisableIRQ(SysTick_IRQn);
|
||||
|
||||
g_LLE_IRQLibHandlerLocation = (uint32_t)LLE_IRQLibHandler;
|
||||
@@ -139,13 +139,13 @@ void CH59x_BLEInit(void)
|
||||
cfg.ConnectNumber = (PERIPHERAL_MAX_CONNECTION & 3) | (CENTRAL_MAX_CONNECTION << 2);
|
||||
cfg.srandCB = SYS_GetSysTickCnt;
|
||||
#if(defined TEM_SAMPLE) && (TEM_SAMPLE == TRUE)
|
||||
cfg.tsCB = HAL_GetInterTempValue; // 根据温度变化校准RF和内部RC( 大于7摄氏度 )
|
||||
cfg.tsCB = HAL_GetInterTempValue; // 根据温度变化校准RF和内部RC( 大于7摄氏度 )
|
||||
#if(CLK_OSC32K)
|
||||
cfg.rcCB = Lib_Calibration_LSI; // 内部32K时钟校准
|
||||
cfg.rcCB = Lib_Calibration_LSI; // 内部32K时钟校准
|
||||
#endif
|
||||
#endif
|
||||
#if(defined(HAL_SLEEP)) && (HAL_SLEEP == TRUE)
|
||||
cfg.idleCB = CH59x_LowPower; // 启用睡眠
|
||||
cfg.idleCB = CH59x_LowPower; // 启用睡眠
|
||||
#endif
|
||||
#if(defined(BLE_MAC)) && (BLE_MAC == TRUE)
|
||||
for(i = 0; i < 6; i++)
|
||||
@@ -158,7 +158,7 @@ void CH59x_BLEInit(void)
|
||||
GetMACAddress(MacAddr);
|
||||
for(i = 0; i < 6; i++)
|
||||
{
|
||||
cfg.MacAddr[i] = MacAddr[i]; // 使用芯片mac地址
|
||||
cfg.MacAddr[i] = MacAddr[i]; // 使用芯片mac地址
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -177,7 +177,7 @@ void CH59x_BLEInit(void)
|
||||
/*******************************************************************************
|
||||
* @fn HAL_ProcessEvent
|
||||
*
|
||||
* @brief 硬件层事务处理
|
||||
* @brief 硬件层事务处理
|
||||
*
|
||||
* @param task_id - The TMOS assigned task ID.
|
||||
* @param events - events to process. This is a bit map and can
|
||||
@@ -190,7 +190,7 @@ tmosEvents HAL_ProcessEvent(tmosTaskID task_id, tmosEvents events)
|
||||
uint8_t *msgPtr;
|
||||
|
||||
if(events & SYS_EVENT_MSG)
|
||||
{ // 处理HAL层消息,调用tmos_msg_receive读取消息,处理完成后删除消息。
|
||||
{ // 处理HAL层消息,调用tmos_msg_receive读取消息,处理完成后删除消息。
|
||||
msgPtr = tmos_msg_receive(task_id);
|
||||
if(msgPtr)
|
||||
{
|
||||
@@ -217,14 +217,14 @@ tmosEvents HAL_ProcessEvent(tmosTaskID task_id, tmosEvents events)
|
||||
if(events & HAL_REG_INIT_EVENT)
|
||||
{
|
||||
uint8_t x32Kpw;
|
||||
#if(defined BLE_CALIBRATION_ENABLE) && (BLE_CALIBRATION_ENABLE == TRUE) // 校准任务,单次校准耗时小于10ms
|
||||
BLE_RegInit(); // 校准RF
|
||||
#if(defined BLE_CALIBRATION_ENABLE) && (BLE_CALIBRATION_ENABLE == TRUE) // 校准任务,单次校准耗时小于10ms
|
||||
BLE_RegInit(); // 校准RF
|
||||
#if(CLK_OSC32K)
|
||||
Lib_Calibration_LSI(); // 校准内部RC
|
||||
Lib_Calibration_LSI(); // 校准内部RC
|
||||
#else
|
||||
x32Kpw = (R8_XT32K_TUNE & 0xfc) | 0x01;
|
||||
sys_safe_access_enable();
|
||||
R8_XT32K_TUNE = x32Kpw; // LSE驱动电流降低到额定电流
|
||||
R8_XT32K_TUNE = x32Kpw; // LSE驱动电流降低到额定电流
|
||||
sys_safe_access_disable();
|
||||
#endif
|
||||
tmos_start_task(halTaskID, HAL_REG_INIT_EVENT, MS1_TO_SYSTEM_TIME(BLE_CALIBRATION_PERIOD));
|
||||
@@ -243,7 +243,7 @@ tmosEvents HAL_ProcessEvent(tmosTaskID task_id, tmosEvents events)
|
||||
/*******************************************************************************
|
||||
* @fn HAL_Init
|
||||
*
|
||||
* @brief 硬件初始化
|
||||
* @brief 硬件初始化
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
@@ -263,17 +263,17 @@ void HAL_Init()
|
||||
HAL_KeyInit();
|
||||
#endif
|
||||
#if(defined BLE_CALIBRATION_ENABLE) && (BLE_CALIBRATION_ENABLE == TRUE)
|
||||
tmos_start_task(halTaskID, HAL_REG_INIT_EVENT, 800); // 添加校准任务,500ms启动,单次校准耗时小于10ms
|
||||
tmos_start_task(halTaskID, HAL_REG_INIT_EVENT, 800); // 添加校准任务,500ms启动,单次校准耗时小于10ms
|
||||
#endif
|
||||
// tmos_start_task( halTaskID, HAL_TEST_EVENT, 1600 ); // 添加一个测试任务
|
||||
// tmos_start_task( halTaskID, HAL_TEST_EVENT, 1600 ); // 添加一个测试任务
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn HAL_GetInterTempValue
|
||||
*
|
||||
* @brief 获取内部温感采样值,如果使用了ADC中断采样,需在此函数中暂时屏蔽中断.
|
||||
* @brief 获取内部温感采样值,如果使用了ADC中断采样,需在此函数中暂时屏蔽中断.
|
||||
*
|
||||
* @return 内部温感采样值.
|
||||
* @return 内部温感采样值.
|
||||
*/
|
||||
uint16_t HAL_GetInterTempValue(void)
|
||||
{
|
||||
|
||||
+8
-8
@@ -3,7 +3,7 @@
|
||||
* Author : WCH
|
||||
* Version : V1.2
|
||||
* Date : 2022/01/18
|
||||
* Description : RTC配置及其初始化
|
||||
* Description : RTC配置及其初始化
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
@@ -11,7 +11,7 @@
|
||||
*******************************************************************************/
|
||||
|
||||
/******************************************************************************/
|
||||
/* 头文件包含 */
|
||||
/* 头文件包含 */
|
||||
#include "HAL.h"
|
||||
|
||||
/*********************************************************************
|
||||
@@ -29,9 +29,9 @@ volatile uint32_t RTCTigFlag;
|
||||
/*******************************************************************************
|
||||
* @fn RTC_SetTignTime
|
||||
*
|
||||
* @brief 配置RTC触发时间
|
||||
* @brief 配置RTC触发时间
|
||||
*
|
||||
* @param time - 触发时间.
|
||||
* @param time - 触发时间.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
@@ -46,7 +46,7 @@ void RTC_SetTignTime(uint32_t time)
|
||||
/*******************************************************************************
|
||||
* @fn RTC_IRQHandler
|
||||
*
|
||||
* @brief RTC中断处理
|
||||
* @brief RTC中断处理
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
@@ -63,7 +63,7 @@ void RTC_IRQHandler(void)
|
||||
/*******************************************************************************
|
||||
* @fn SYS_GetClockValue
|
||||
*
|
||||
* @brief 获取RTC当前计数值
|
||||
* @brief 获取RTC当前计数值
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
@@ -84,7 +84,7 @@ static uint32_t SYS_GetClockValue(void)
|
||||
/*******************************************************************************
|
||||
* @fn HAL_Time0Init
|
||||
*
|
||||
* @brief 系统定时器初始化
|
||||
* @brief 系统定时器初始化
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
@@ -110,7 +110,7 @@ void HAL_TimeInit(void)
|
||||
R8_CK32K_CONFIG |= RB_CLK_OSC32K_XT | RB_CLK_XT32K_PON;
|
||||
sys_safe_access_disable();
|
||||
#endif
|
||||
RTC_InitTime(2020, 1, 1, 0, 0, 0); //RTC时钟初始化当前时间
|
||||
RTC_InitTime(2020, 1, 1, 0, 0, 0); //RTC时钟初始化当前时间
|
||||
|
||||
tmos_memset( &conf, 0, sizeof(bleClockConfig_t) );
|
||||
conf.ClockAccuracy = CLK_OSC32K ? 1000 : 50;
|
||||
|
||||
+37
-37
@@ -3,7 +3,7 @@
|
||||
* Author : WCH
|
||||
* Version : V1.2
|
||||
* Date : 2022/01/18
|
||||
* Description : 配置说明及默认值,建议在工程配置里的预处理中修改当前值
|
||||
* Description : 配置说明及默认值,建议在工程配置里的预处理中修改当前值
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
@@ -27,53 +27,53 @@
|
||||
#include "CH59x_common.h"
|
||||
|
||||
/*********************************************************************
|
||||
【MAC】
|
||||
BLE_MAC - 是否自定义蓝牙Mac地址 ( 默认:FALSE - 使用芯片Mac地址 ),需要在main.c修改Mac地址定义
|
||||
【MAC】
|
||||
BLE_MAC - 是否自定义蓝牙Mac地址 ( 默认:FALSE - 使用芯片Mac地址 ),需要在main.c修改Mac地址定义
|
||||
|
||||
【DCDC】
|
||||
DCDC_ENABLE - 是否使能DCDC ( 默认:FALSE )
|
||||
【DCDC】
|
||||
DCDC_ENABLE - 是否使能DCDC ( 默认:FALSE )
|
||||
|
||||
【SLEEP】
|
||||
HAL_SLEEP - 是否开启睡眠功能 ( 默认:FALSE )
|
||||
SLEEP_RTC_MIN_TIME - 非空闲模式下睡眠的最小时间(单位:一个RTC周期)
|
||||
SLEEP_RTC_MAX_TIME - 非空闲模式下睡眠的最大时间(单位:一个RTC周期)
|
||||
WAKE_UP_RTC_MAX_TIME - 等待32M晶振稳定时间(单位:一个RTC周期)
|
||||
根据不同睡眠类型取值可分为: 睡眠模式/下电模式 - 45 (默认)
|
||||
暂停模式 - 45
|
||||
空闲模式 - 5
|
||||
【TEMPERATION】
|
||||
TEM_SAMPLE - 是否打开根据温度变化校准的功能,单次校准耗时小于10ms( 默认:TRUE )
|
||||
【SLEEP】
|
||||
HAL_SLEEP - 是否开启睡眠功能 ( 默认:FALSE )
|
||||
SLEEP_RTC_MIN_TIME - 非空闲模式下睡眠的最小时间(单位:一个RTC周期)
|
||||
SLEEP_RTC_MAX_TIME - 非空闲模式下睡眠的最大时间(单位:一个RTC周期)
|
||||
WAKE_UP_RTC_MAX_TIME - 等待32M晶振稳定时间(单位:一个RTC周期)
|
||||
根据不同睡眠类型取值可分为: 睡眠模式/下电模式 - 45 (默认)
|
||||
暂停模式 - 45
|
||||
空闲模式 - 5
|
||||
【TEMPERATION】
|
||||
TEM_SAMPLE - 是否打开根据温度变化校准的功能,单次校准耗时小于10ms( 默认:TRUE )
|
||||
|
||||
【CALIBRATION】
|
||||
BLE_CALIBRATION_ENABLE - 是否打开定时校准的功能,单次校准耗时小于10ms( 默认:TRUE )
|
||||
BLE_CALIBRATION_PERIOD - 定时校准的周期,单位ms( 默认:120000 )
|
||||
【CALIBRATION】
|
||||
BLE_CALIBRATION_ENABLE - 是否打开定时校准的功能,单次校准耗时小于10ms( 默认:TRUE )
|
||||
BLE_CALIBRATION_PERIOD - 定时校准的周期,单位ms( 默认:120000 )
|
||||
|
||||
【SNV】
|
||||
BLE_SNV - 是否开启SNV功能,用于储存绑定信息( 默认:TRUE )
|
||||
BLE_SNV_ADDR - SNV信息保存地址,使用data flash最后512字节( 默认:0x77E00 )
|
||||
BLE_SNV_BLOCK - SNV信息保存块大小( 默认:256 )
|
||||
BLE_SNV_NUM - SNV信息保存数量( 默认:1 )
|
||||
【SNV】
|
||||
BLE_SNV - 是否开启SNV功能,用于储存绑定信息( 默认:TRUE )
|
||||
BLE_SNV_ADDR - SNV信息保存地址,使用data flash最后512字节( 默认:0x77E00 )
|
||||
BLE_SNV_BLOCK - SNV信息保存块大小( 默认:256 )
|
||||
BLE_SNV_NUM - SNV信息保存数量( 默认:1 )
|
||||
|
||||
【RTC】
|
||||
CLK_OSC32K - RTC时钟选择,如包含主机角色必须使用外部32K( 0 外部(32768Hz),默认:1:内部(32000Hz),2:内部(32768Hz) )
|
||||
【RTC】
|
||||
CLK_OSC32K - RTC时钟选择,如包含主机角色必须使用外部32K( 0 外部(32768Hz),默认:1:内部(32000Hz),2:内部(32768Hz) )
|
||||
|
||||
【MEMORY】
|
||||
BLE_MEMHEAP_SIZE - 蓝牙协议栈使用的RAM大小,不小于6K ( 默认:(1024*6) )
|
||||
【MEMORY】
|
||||
BLE_MEMHEAP_SIZE - 蓝牙协议栈使用的RAM大小,不小于6K ( 默认:(1024*6) )
|
||||
|
||||
【DATA】
|
||||
BLE_BUFF_MAX_LEN - 单个连接最大包长度( 默认:27 (ATT_MTU=23),取值范围[27~516] )
|
||||
BLE_BUFF_NUM - 控制器缓存的包数量( 默认:5 )
|
||||
BLE_TX_NUM_EVENT - 单个连接事件最多可以发多少个数据包( 默认:1 )
|
||||
BLE_TX_POWER - 发射功率( 默认:LL_TX_POWEER_0_DBM (0dBm) )
|
||||
【DATA】
|
||||
BLE_BUFF_MAX_LEN - 单个连接最大包长度( 默认:27 (ATT_MTU=23),取值范围[27~516] )
|
||||
BLE_BUFF_NUM - 控制器缓存的包数量( 默认:5 )
|
||||
BLE_TX_NUM_EVENT - 单个连接事件最多可以发多少个数据包( 默认:1 )
|
||||
BLE_TX_POWER - 发射功率( 默认:LL_TX_POWEER_0_DBM (0dBm) )
|
||||
|
||||
【MULTICONN】
|
||||
PERIPHERAL_MAX_CONNECTION - 最多可同时做多少从机角色( 默认:1 )
|
||||
CENTRAL_MAX_CONNECTION - 最多可同时做多少主机角色( 默认:3 )
|
||||
【MULTICONN】
|
||||
PERIPHERAL_MAX_CONNECTION - 最多可同时做多少从机角色( 默认:1 )
|
||||
CENTRAL_MAX_CONNECTION - 最多可同时做多少主机角色( 默认:3 )
|
||||
|
||||
**********************************************************************/
|
||||
|
||||
/*********************************************************************
|
||||
* 默认配置值
|
||||
* 默认配置值
|
||||
*/
|
||||
#ifndef BLE_MAC
|
||||
#define BLE_MAC FALSE
|
||||
@@ -121,7 +121,7 @@
|
||||
#define BLE_SNV_NUM 1
|
||||
#endif
|
||||
#ifndef CLK_OSC32K
|
||||
#define CLK_OSC32K 1 // 该项请勿在此修改,必须在工程配置里的预处理中修改,如包含主机角色必须使用外部32K
|
||||
#define CLK_OSC32K 1 // 该项请勿在此修改,必须在工程配置里的预处理中修改,如包含主机角色必须使用外部32K
|
||||
#endif
|
||||
#ifndef BLE_MEMHEAP_SIZE
|
||||
#define BLE_MEMHEAP_SIZE (1024*6)
|
||||
|
||||
@@ -40,12 +40,12 @@ extern tmosTaskID halTaskID;
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief 硬件初始化
|
||||
* @brief 硬件初始化
|
||||
*/
|
||||
extern void HAL_Init(void);
|
||||
|
||||
/**
|
||||
* @brief 硬件层事务处理
|
||||
* @brief 硬件层事务处理
|
||||
*
|
||||
* @param task_id - The TMOS assigned task ID.
|
||||
* @param events - events to process. This is a bit map and can
|
||||
@@ -54,19 +54,19 @@ extern void HAL_Init(void);
|
||||
extern tmosEvents HAL_ProcessEvent(tmosTaskID task_id, tmosEvents events);
|
||||
|
||||
/**
|
||||
* @brief BLE 库初始化
|
||||
* @brief BLE 库初始化
|
||||
*/
|
||||
extern void CH59x_BLEInit(void);
|
||||
|
||||
/**
|
||||
* @brief 获取内部温感采样值,如果使用了ADC中断采样,需在此函数中暂时屏蔽中断.
|
||||
* @brief 获取内部温感采样值,如果使用了ADC中断采样,需在此函数中暂时屏蔽中断.
|
||||
*
|
||||
* @return 内部温感采样值.
|
||||
* @return 内部温感采样值.
|
||||
*/
|
||||
extern uint16_t HAL_GetInterTempValue(void);
|
||||
|
||||
/**
|
||||
* @brief 内部32k校准
|
||||
* @brief 内部32k校准
|
||||
*/
|
||||
extern void Lib_Calibration_LSI(void);
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ extern "C" {
|
||||
#define HAL_KEY_SW_3 0x04 // key3
|
||||
#define HAL_KEY_SW_4 0x08 // key4
|
||||
|
||||
/* °´¼ü¶¨Òå */
|
||||
/* 按键定义 */
|
||||
|
||||
/* 1 - KEY */
|
||||
#define KEY1_BV BV(22)
|
||||
@@ -52,7 +52,7 @@ extern "C" {
|
||||
#define KEY3_IN ()
|
||||
#define KEY4_IN ()
|
||||
|
||||
#define HAL_PUSH_BUTTON1() (KEY1_IN) //Ìí¼Ó×Ô¶¨Òå°´¼ü
|
||||
#define HAL_PUSH_BUTTON1() (KEY1_IN) //添加自定义按键
|
||||
#define HAL_PUSH_BUTTON2() (KEY2_IN)
|
||||
#define HAL_PUSH_BUTTON3() (0)
|
||||
#define HAL_PUSH_BUTTON4() (0)
|
||||
|
||||
@@ -46,7 +46,7 @@ extern "C" {
|
||||
* TYPEDEFS
|
||||
*/
|
||||
|
||||
/* 连接一个LED用于监控演示程序的进度,低电平LED亮 */
|
||||
/* 连接一个LED用于监控演示程序的进度,低电平LED亮 */
|
||||
|
||||
/* 1 - LED */
|
||||
#define LED1_BV BV(15)
|
||||
|
||||
@@ -47,9 +47,9 @@ extern volatile uint32_t RTCTigFlag;
|
||||
void HAL_TimeInit(void);
|
||||
|
||||
/**
|
||||
* @brief 配置RTC触发时间
|
||||
* @brief 配置RTC触发时间
|
||||
*
|
||||
* @param time - 触发时间.
|
||||
* @param time - 触发时间.
|
||||
*/
|
||||
extern void RTC_SetTignTime(uint32_t time);
|
||||
|
||||
|
||||
@@ -27,14 +27,14 @@ extern "C" {
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief 配置睡眠唤醒的方式 - RTC唤醒,触发模式
|
||||
* @brief 配置睡眠唤醒的方式 - RTC唤醒,触发模式
|
||||
*/
|
||||
extern void HAL_SleepInit(void);
|
||||
|
||||
/**
|
||||
* @brief 启动睡眠
|
||||
* @brief 启动睡眠
|
||||
*
|
||||
* @param time - 唤醒的时间点(RTC绝对值)
|
||||
* @param time - 唤醒的时间点(RTC绝对值)
|
||||
*
|
||||
* @return state.
|
||||
*/
|
||||
|
||||
@@ -187,7 +187,7 @@ extern const uint8_t VER_LIB[]; // LIB version
|
||||
#define ABS(n) (((n) < 0) ? -(n) : (n))
|
||||
#endif
|
||||
|
||||
/* TxPower define(Accuracy:¡À2dBm) */
|
||||
/* TxPower define(Accuracy:±2dBm) */
|
||||
#define LL_TX_POWEER_MINUS_20_DBM 0x01
|
||||
#define LL_TX_POWEER_MINUS_15_DBM 0x03
|
||||
#define LL_TX_POWEER_MINUS_10_DBM 0x05
|
||||
@@ -773,7 +773,7 @@ extern const uint8_t VER_LIB[]; // LIB version
|
||||
#define TGAP_AUTH_TASK_ID 24 //!< Task ID override for Task Authentication control (for stack internal use only)
|
||||
|
||||
// v5.x
|
||||
#define TGAP_ADV_TX_POWER 25 //!< Indicates the maximum power level Range: -127 ¡Ü N ¡Ü +126 Units: dBm.Default 127(Host has no preference).
|
||||
#define TGAP_ADV_TX_POWER 25 //!< Indicates the maximum power level Range: -127 ≤ N ≤ +126 Units: dBm.Default 127(Host has no preference).
|
||||
#define TGAP_ADV_PRIMARY_PHY 26 //!< resv.
|
||||
#define TGAP_ADV_SECONDARY_PHY 27 //!< LE 1M/LE 2M. Default GAP_PHY_VAL_LE_1M.
|
||||
#define TGAP_ADV_SECONDARY_MAX_SKIP 28 //!< Maximum advertising events the Controller can skip before sending the AUX_ADV_IND packets on the secondary advertising channel. Default 0.
|
||||
@@ -1110,7 +1110,7 @@ extern const uint8_t VER_LIB[]; // LIB version
|
||||
#define SMP_PAIRING_FAILED_UNSPECIFIED 0x08 //!< Pairing failed due to an unspecified reason
|
||||
#define SMP_PAIRING_FAILED_REPEATED_ATTEMPTS 0x09 //!< Pairing or authentication procedure is disallowed because too little time has elapsed since the last pairing request or security request.
|
||||
#define SMP_PAIRING_FAILED_INVALID_PARAMERERS 0x0A //!< The Invalid Parameters error code indicates that the command length is invalid or that a parameter is outside of the specified range.
|
||||
#define SMP_PAIRING_FAILED_DHKEY_CHECK_FAILED 0x0B //!< Indicates to the remote device that the DHKey Check value received doesn¡¯t match the one calculated by the local device.
|
||||
#define SMP_PAIRING_FAILED_DHKEY_CHECK_FAILED 0x0B //!< Indicates to the remote device that the DHKey Check value received doesn’t match the one calculated by the local device.
|
||||
#define SMP_PAIRING_FAILED_NUMERIC_COMPARISON 0x0C //!< Indicates that the confirm values in the numeric comparison protocol do not match.
|
||||
#define SMP_PAIRING_FAILED_KEY_REJECTED 0x0F //!< Indicates that the device chose not to accept a distributed key.
|
||||
|
||||
@@ -2849,7 +2849,7 @@ extern void LLE_IRQLibHandler( void );
|
||||
* @return access address
|
||||
* the Access Address meets the following requirements:
|
||||
* It shall have no more than six consecutive zeros or ones.
|
||||
* It shall not be t he advertising channel packets¡¯ Access Address.
|
||||
* It shall not be t he advertising channel packets’ Access Address.
|
||||
* It shall not be a sequence that differ s from the advertising channel packets' Access Address by only one bit.
|
||||
* It shall not have all four octets equal.
|
||||
* It shall have no more than 24 transitions.
|
||||
|
||||
@@ -199,7 +199,7 @@ extern const uint8_t VER_LIB[]; // LIB version
|
||||
#define ABS(n) (((n) < 0) ? -(n) : (n))
|
||||
#endif
|
||||
|
||||
/* TxPower define(Accuracy:¡À2dBm) */
|
||||
/* TxPower define(Accuracy:±2dBm) */
|
||||
#define LL_TX_POWEER_MINUS_20_DBM 0x01
|
||||
#define LL_TX_POWEER_MINUS_15_DBM 0x03
|
||||
#define LL_TX_POWEER_MINUS_10_DBM 0x05
|
||||
@@ -785,7 +785,7 @@ extern const uint8_t VER_LIB[]; // LIB version
|
||||
#define TGAP_AUTH_TASK_ID 24 //!< Task ID override for Task Authentication control (for stack internal use only)
|
||||
|
||||
// v5.x
|
||||
#define TGAP_ADV_TX_POWER 25 //!< Indicates the maximum power level Range: -127 ¡Ü N ¡Ü +126 Units: dBm.Default 127(Host has no preference).
|
||||
#define TGAP_ADV_TX_POWER 25 //!< Indicates the maximum power level Range: -127 ≤ N ≤ +126 Units: dBm.Default 127(Host has no preference).
|
||||
#define TGAP_ADV_PRIMARY_PHY 26 //!< resv.
|
||||
#define TGAP_ADV_SECONDARY_PHY 27 //!< LE 1M/LE 2M. Default GAP_PHY_VAL_LE_1M.
|
||||
#define TGAP_ADV_SECONDARY_MAX_SKIP 28 //!< Maximum advertising events the Controller can skip before sending the AUX_ADV_IND packets on the secondary advertising channel. Default 0.
|
||||
@@ -1122,7 +1122,7 @@ extern const uint8_t VER_LIB[]; // LIB version
|
||||
#define SMP_PAIRING_FAILED_UNSPECIFIED 0x08 //!< Pairing failed due to an unspecified reason
|
||||
#define SMP_PAIRING_FAILED_REPEATED_ATTEMPTS 0x09 //!< Pairing or authentication procedure is disallowed because too little time has elapsed since the last pairing request or security request.
|
||||
#define SMP_PAIRING_FAILED_INVALID_PARAMERERS 0x0A //!< The Invalid Parameters error code indicates that the command length is invalid or that a parameter is outside of the specified range.
|
||||
#define SMP_PAIRING_FAILED_DHKEY_CHECK_FAILED 0x0B //!< Indicates to the remote device that the DHKey Check value received doesn¡¯t match the one calculated by the local device.
|
||||
#define SMP_PAIRING_FAILED_DHKEY_CHECK_FAILED 0x0B //!< Indicates to the remote device that the DHKey Check value received doesn’t match the one calculated by the local device.
|
||||
#define SMP_PAIRING_FAILED_NUMERIC_COMPARISON 0x0C //!< Indicates that the confirm values in the numeric comparison protocol do not match.
|
||||
#define SMP_PAIRING_FAILED_KEY_REJECTED 0x0F //!< Indicates that the device chose not to accept a distributed key.
|
||||
|
||||
@@ -2877,7 +2877,7 @@ typedef struct tag_rf_config
|
||||
* @return access address
|
||||
* the Access Address meets the following requirements:
|
||||
* It shall have no more than six consecutive zeros or ones.
|
||||
* It shall not be t he advertising channel packets¡¯ Access Address.
|
||||
* It shall not be t he advertising channel packets’ Access Address.
|
||||
* It shall not be a sequence that differ s from the advertising channel packets' Access Address by only one bit.
|
||||
* It shall not have all four octets equal.
|
||||
* It shall have no more than 24 transitions.
|
||||
@@ -4037,7 +4037,7 @@ typedef struct tag_rf_config
|
||||
* @return SUCCESS - bond record found and changed
|
||||
* bleIncorrectMode - Link not found.
|
||||
*/
|
||||
#define GAPBondMgr_OobRsp (( bStatus_t (*) ( uint16_t connHandle, uint8_t status, uint8_t *oob, uint8_t * c_peer )£© BLE_LIB_JT(139) )
|
||||
#define GAPBondMgr_OobRsp (( bStatus_t (*) ( uint16_t connHandle, uint8_t status, uint8_t *oob, uint8_t * c_peer )) BLE_LIB_JT(139) )
|
||||
|
||||
/**
|
||||
* @brief Initialization function for the ecc-function callback.
|
||||
@@ -4046,7 +4046,7 @@ typedef struct tag_rf_config
|
||||
*
|
||||
* @return null.
|
||||
*/
|
||||
#define GAPBondMgr_EccInit (( void (*) ( gapEccCBs_t *pEcc )£© BLE_LIB_JT(140) )
|
||||
#define GAPBondMgr_EccInit (( void (*) ( gapEccCBs_t *pEcc )) BLE_LIB_JT(140) )
|
||||
|
||||
/**
|
||||
* @brief Send a security request
|
||||
|
||||
Reference in New Issue
Block a user