refactor(vd960Loop): 算法回退到 DLD154V4B,四通道适配

- 用 DLD154V4B vd1_task/per_channel 替换 vds_task 复杂算法
- 移除 FUNCTION_B/二次判断/快速变化/多重确认等增强特性
- 保留平坦性离开算法 (CN200910309382),每通道独立状态
- 灵敏度表改为 DLD154V4B 4级: {216,108,36,10} / {108,72,18,9}
- 清理废弃类型: FltHistoryManager, Loop_ACS_Info, StageRangeConfig 等
- 首次添加 vd960DBN 完整源码
This commit is contained in:
wangfq
2026-06-25 16:21:57 +08:00
parent 6fd4e564e3
commit 95808f9f25
966 changed files with 406958 additions and 84 deletions

View File

@@ -0,0 +1,173 @@
/*
FreeRTOS V10.4.3 - Copyright (C) 2020 Real Time Engineers Ltd.
All rights reserved
VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
This file is part of the FreeRTOS distribution.
FreeRTOS is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License (version 2) as published by the
Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.
***************************************************************************
>>! NOTE: The modification to the GPL is included to allow you to !<<
>>! distribute a combined work that includes FreeRTOS without being !<<
>>! obliged to provide the source code for proprietary components !<<
>>! outside of the FreeRTOS kernel. !<<
***************************************************************************
FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. Full license text is available on the following
link: http://www.freertos.org/a00114.html
***************************************************************************
* *
* FreeRTOS provides completely free yet professionally developed, *
* robust, strictly quality controlled, supported, and cross *
* platform software that is more than just the market leader, it *
* is the industry's de facto standard. *
* *
* Help yourself get started quickly while simultaneously helping *
* to support the FreeRTOS project by purchasing a FreeRTOS *
* tutorial book, reference manual, or both: *
* http://www.FreeRTOS.org/Documentation *
* *
***************************************************************************
http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
the FAQ page "My application does not run, what could be wrong?". Have you
defined configASSERT()?
http://www.FreeRTOS.org/support - In return for receiving this top quality
embedded software for free we request you assist our global community by
participating in the support forum.
http://www.FreeRTOS.org/training - Investing in training allows your team to
be as productive as possible as early as possible. Now you can receive
FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
Ltd, and the world's leading authority on the world's leading RTOS.
http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
including FreeRTOS+Trace - an indispensable productivity tool, a DOS
compatible FAT file system, and our tiny thread aware UDP/IP stack.
http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
licenses offer ticketed support, indemnification and commercial middleware.
http://www.SafeRTOS.com - High Integrity Systems also provide a safety
engineered and independently SIL3 certified version for use in safety and
mission critical applications that require provable dependability.
1 tab == 4 spaces!
* Copyright notice & Disclaimer
*
* The software Board Support Package (BSP) that is made available to
* download from Artery official website is the copyrighted work of Artery.
* Artery authorizes customers to use, copy, and distribute the BSP
* software and its related documentation for the purpose of design and
* development in conjunction with Artery microcontrollers. Use of the
* software is governed by this copyright notice and the following disclaimer.
*
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
* GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
* TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
* STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
* INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
*
**************************************************************************
*/
#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H
#if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__)
#include <stdint.h>
#include "system_at32f421.h"
#endif
/*-----------------------------------------------------------
* Application specific definitions.
*
* These definitions should be adjusted for your particular hardware and
* application requirements.
*
* THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE
* FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE.
*
* See http://www.freertos.org/a00110.html.
*----------------------------------------------------------*/
#define configUSE_PREEMPTION 1
#define configUSE_IDLE_HOOK 0
#define configUSE_TICK_HOOK 0
#define configCPU_CLOCK_HZ ( ( unsigned long ) system_core_clock )
#define configTICK_RATE_HZ ( ( TickType_t ) 1000 )
#define configMAX_PRIORITIES ( 5 )
#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 128 )
#define configSUPPORT_DYNAMIC_ALLOCATION 1
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 8 * 1024 ) )
#define configMAX_TASK_NAME_LEN ( 16 )
#define configUSE_16_BIT_TICKS 0
#define configIDLE_SHOULD_YIELD 1
/* Co-routine definitions. */
#define configUSE_CO_ROUTINES 0
#define configMAX_CO_ROUTINE_PRIORITIES ( 2 )
/* Set the following definitions to 1 to include the API function, or zero
to exclude the API function. */
#define INCLUDE_vTaskPrioritySet 1
#define INCLUDE_uxTaskPriorityGet 1
#define INCLUDE_vTaskDelete 1
#define INCLUDE_vTaskCleanUpResources 0
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_vTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1
#define INCLUDE_xTaskGetCurrentTaskHandle 1
/* Cortex-M specific definitions. */
#ifdef __NVIC_PRIO_BITS
/* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */
#define configPRIO_BITS __NVIC_PRIO_BITS
#else
#define configPRIO_BITS 4 /* 15 priority levels */
#endif
/* The lowest interrupt priority that can be used in a call to a "set priority"
function. */
#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY 0x0f
/* The highest interrupt priority that can be used by any interrupt service
routine that makes calls to interrupt safe FreeRTOS API functions. DO NOT CALL
INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER
PRIORITY THAN THIS! (higher priorities are lower numeric values. */
#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 0x01
/* Interrupt priorities used by the kernel port layer itself. These are generic
to all Cortex-M ports, and do not rely on any particular library functions. */
#define configKERNEL_INTERRUPT_PRIORITY ( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
/* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!!
See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */
#define configMAX_SYSCALL_INTERRUPT_PRIORITY ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
/* Normal assert() semantics without relying on the provision of an assert.h
header file. */
#define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); }
/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS
standard names. */
#define vPortSVCHandler SVC_Handler
#define xPortPendSVHandler PendSV_Handler
#define xPortSysTickHandler SysTick_Handler
#endif /* FREERTOS_CONFIG_H */

View File

@@ -0,0 +1,194 @@
/**
**************************************************************************
* @file TaskLoop.h
* @version v2.0
* @date 2025-09-08 (original), 2026-06-25 (rewrite: DLD154V4B algo × 4ch)
* @brief 四路线圈检测 — 移植自 DLD154V4B 算法
*
* 算法来源: DLD154V4B vd1_task() + 平坦性离开 (CN200910309382)
* 改动: 单路全局变量 → Loop154_Unit 结构体数组,四路独立
**************************************************************************
*/
#ifndef __TASKLOOP_H__
#define __TASKLOOP_H__
#include <stdint.h>
#include <stddef.h>
/*===========================================================================
* 时序参数(每 tick = 50ms由 TMR15 5ms×10 产生)
*===========================================================================*/
#define HOLD_TIME (5 * 1200) // 有限存在保持(约 5 分钟)
#define LC_HOLD_TIME (4 * 1200) // 安全复位时间(约 4 分钟)
#define IN_DELAY 10 // 进入防抖 500ms
#define OUT_DELAY 10 // 离开防抖 500ms
#define PULSE_DELAY 10 // 脉冲宽度 500ms
/*===========================================================================
* 滤波参数
*===========================================================================*/
#define ALFA_CAP1 79 // IIR 指数平滑 α = 79/256 ≈ 0.31
#define STABLE_SAMPLES 128 // 稳定期样本数
/*===========================================================================
* 离开检测: 1 = 平坦性三条件 (CN200910309382), 0 = cnt_release 防抖
*===========================================================================*/
#define USE_FLATNESS_EXIT 1
/*===========================================================================
* 平坦性参数
*===========================================================================*/
#define K1 8
#define K2 8
#define SLOPE_FLAT_THRESH 100
#define MIN_DELTA2 5
#define MIN_DELTA3 2
#define FLAT_CONFIRM_CNT 3
#define WINDOW_ORIGIN 100 // 基线跟踪窗口
/*===========================================================================
* 频率测量
* MEASUREMENT_BASE = 2^17 ≈ 131072
* LPCNT = MEASUREMENT_BASE / Xn, 使 Value 归一化到 ~131072
*===========================================================================*/
#define MEASUREMENT_BASE 131072
/*===========================================================================
* 通道数量
*===========================================================================*/
#define LOOP_CAPTURE_MAX 4
/*===========================================================================
* 灵敏度表4级: 0=低, 3=高)
* 进入阈值 = Origin × SensTable[SENS] / 65536
* 离开阈值 = Origin × SensTable_1[SENS] / 65536
*===========================================================================*/
extern const uint16_t SensTable[4];
extern const uint16_t SensTable_1[4];
/*===========================================================================
* Forward declaration
*===========================================================================*/
struct tskTaskControlBlock;
typedef struct tskTaskControlBlock* TaskHandle_t;
/*===========================================================================
* 单通道状态结构体 — 对齐 DLD154V4B 全局变量
*===========================================================================*/
typedef struct {
uint8_t loop_num; // 通道编号 0~3
/*--- 捕获 & 测量 ---*/
uint16_t loop_Xn; // 相邻边沿周期差
uint16_t loop_CapThis, loop_CapLast;
uint16_t loop_LPCNT, loop_CapCnt;
uint32_t loop_CapSum, loop_Value;
uint32_t loop_CAPVD; // IIR 滤波后的频率值
uint32_t loop_Origin; // 基线(无车参考值)
uint32_t loop_ORG_SUM;
uint16_t loop_ORG_CNT;
uint16_t loop_dlt_ORG; // 当前灵敏度阈值
uint8_t Flt_Reg; // IIR 滤波系数
/*--- 标志位 ---*/
uint8_t loop_INI_LOOP;
uint8_t loop_CAP_OK; // 新测量数据就绪
uint8_t loop_VD_FLAG; // 有车标志
uint8_t loop_VD_HOLD; // 有限存在计时启用
uint8_t loop_RF_FLAG; // 本 tick 收到线圈振荡边沿
uint8_t loop_LOOP_OK; // 线圈连接正常
uint8_t loop_LOOP_OK0; // 上周期连接状态
uint8_t loop_FLAG_IN; // 进入延时中
uint8_t loop_FLAG_OUT; // 离开延时中
uint8_t loop_FLAG_PLUSE; // 脉冲输出中
uint8_t loop_SensLevel; // 灵敏度等级 0~3
uint8_t loop_cnt_release; // 离开防抖计数
uint8_t loop_stable; // 数值已稳定
#if USE_FLATNESS_EXIT
/*--- 平坦性离开状态 ---*/
uint8_t exit_state; // 0=追踪斜率, 1=等待平坦
uint16_t max_slope; // 第一上升坡面最大 |f'|
uint16_t max_slope_rate; // 最大 |f''|
uint16_t delta2; // Δ2: 一阶平坦阈值
uint16_t delta3; // Δ3: 二阶平坦阈值
int32_t prev_capvd; // 上一帧 CAPVD
int32_t prev_first_deriv; // 上一帧一阶导数
uint8_t slope_flat_cnt; // 斜率趋零连续计数
uint8_t flat_ok_cnt; // 平坦条件满足连续计数
#endif
/*--- 计数器 ---*/
uint16_t Hold_CNT;
uint8_t INCNT, OUTCNT;
/*--- 输出配置 ---*/
uint8_t SET_PLUS; // 0=脉冲, 1=存在输出
uint8_t SET_DLY; // 离开延时: 0=无, 1=500ms
uint8_t SET_SAFE; // 1=安全复位
/*--- 安全复位 ---*/
uint8_t LC_HOLD;
uint8_t LC_Reset;
uint32_t LC_Hold_CNT;
/*--- 断开检测 ---*/
uint8_t power_up_state; // 上电后是否曾连接
uint8_t disconnect_count; // 断开次数 (0~3)
uint8_t disconnect_active; // 当前断开中
uint8_t fault_phase;
uint16_t fault_tick;
/*--- 稳定期 ---*/
uint16_t stable_cnt;
/*--- 调试 ---*/
uint32_t xn_counter;
} Loop154_Unit;
/*===========================================================================
* 全局状态
*===========================================================================*/
typedef struct {
uint32_t report_counter;
Loop154_Unit loop_unit[LOOP_CAPTURE_MAX];
} Loop154_States;
extern Loop154_States g_loop_states;
/*===========================================================================
* 全局变量
*===========================================================================*/
extern uint32_t g_sys_freq;
extern uint8_t g_input_div;
extern uint32_t g_safe_max_cnt;
/*===========================================================================
* 函数声明
*===========================================================================*/
void loop_task_function(void *pvParameters);
void usart_task_function(void *pvParameters);
void led_indicator_task_function(void *pvParameters);
void vd1_task_per_channel(Loop154_Unit *unit);
void init_vd_single(Loop154_Unit *unit);
void INIT_VDs(Loop154_States *loops);
void poll_red_pwm(void);
void poll_green_led(Loop154_Unit *unit);
void poll_yellow_led_single(Loop154_Unit *unit);
uint32_t get_flt_value(uint32_t new_value, uint32_t last_Value);
uint8_t update_moving_average(uint32_t* p_sum, uint16_t* p_cnt,
uint32_t* p_origin, uint32_t new_value,
uint8_t window);
void set_loops_relay_on(uint8_t loop_num);
void set_loops_relay_off(uint8_t loop_num);
void wdt_feed(void);
extern TaskHandle_t usart_task_handler;
#endif /* __TASKLOOP_H__ */

View File

@@ -0,0 +1,44 @@
/**
**************************************************************************
* @file at32f421_clock.h
* @brief header file of clock program
**************************************************************************
* Copyright notice & Disclaimer
*
* The software Board Support Package (BSP) that is made available to
* download from Artery official website is the copyrighted work of Artery.
* Artery authorizes customers to use, copy, and distribute the BSP
* software and its related documentation for the purpose of design and
* development in conjunction with Artery microcontrollers. Use of the
* software is governed by this copyright notice and the following disclaimer.
*
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
* GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
* TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
* STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
* INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
*
**************************************************************************
*/
/* define to prevent recursive inclusion -------------------------------------*/
#ifndef __AT32F421_CLOCK_H
#define __AT32F421_CLOCK_H
#ifdef __cplusplus
extern "C" {
#endif
/* includes ------------------------------------------------------------------*/
#include "at32f421.h"
/* exported functions ------------------------------------------------------- */
void system_clock_config(void);
#ifdef __cplusplus
}
#endif
#endif /* __AT32F421_CLOCK_H */

View File

@@ -0,0 +1,137 @@
/**
**************************************************************************
* @file at32f421_conf.h
* @brief at32f421 config header file
**************************************************************************
* Copyright notice & Disclaimer
*
* The software Board Support Package (BSP) that is made available to
* download from Artery official website is the copyrighted work of Artery.
* Artery authorizes customers to use, copy, and distribute the BSP
* software and its related documentation for the purpose of design and
* development in conjunction with Artery microcontrollers. Use of the
* software is governed by this copyright notice and the following disclaimer.
*
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
* GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
* TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
* STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
* INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
*
**************************************************************************
*/
/* define to prevent recursive inclusion -------------------------------------*/
#ifndef __AT32F421_CONF_H
#define __AT32F421_CONF_H
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief in the following line adjust the value of high speed external crystal (hext)
* used in your application
*
* tip: to avoid modifying this file each time you need to use different hext, you
* can define the hext value in your toolchain compiler preprocessor.
*
*/
#if !defined HEXT_VALUE
#define HEXT_VALUE ((uint32_t)12000000) /*!< value of the high speed external crystal in hz */
#endif
/**
* @brief in the following line adjust the high speed external crystal (hext) startup
* timeout value
*/
#define HEXT_STARTUP_TIMEOUT ((uint16_t)0x3000) /*!< time out for hext start up */
#define HICK_VALUE ((uint32_t)8000000) /*!< value of the high speed internal clock in hz */
#define LEXT_VALUE ((uint32_t)32768) /*!< value of the low speed external clock in hz */
/* module define -------------------------------------------------------------*/
#define CRM_MODULE_ENABLED
#define CMP_MODULE_ENABLED
#define TMR_MODULE_ENABLED
#define ERTC_MODULE_ENABLED
#define GPIO_MODULE_ENABLED
#define I2C_MODULE_ENABLED
#define USART_MODULE_ENABLED
#define PWC_MODULE_ENABLED
#define ADC_MODULE_ENABLED
#define SPI_MODULE_ENABLED
#define DMA_MODULE_ENABLED
#define DEBUG_MODULE_ENABLED
#define FLASH_MODULE_ENABLED
#define CRC_MODULE_ENABLED
#define WWDT_MODULE_ENABLED
#define WDT_MODULE_ENABLED
#define EXINT_MODULE_ENABLED
#define MISC_MODULE_ENABLED
#define SCFG_MODULE_ENABLED
/* includes ------------------------------------------------------------------*/
#ifdef CRM_MODULE_ENABLED
#include "at32f421_crm.h"
#endif
#ifdef CMP_MODULE_ENABLED
#include "at32f421_cmp.h"
#endif
#ifdef TMR_MODULE_ENABLED
#include "at32f421_tmr.h"
#endif
#ifdef ERTC_MODULE_ENABLED
#include "at32f421_ertc.h"
#endif
#ifdef GPIO_MODULE_ENABLED
#include "at32f421_gpio.h"
#endif
#ifdef I2C_MODULE_ENABLED
#include "at32f421_i2c.h"
#endif
#ifdef USART_MODULE_ENABLED
#include "at32f421_usart.h"
#endif
#ifdef PWC_MODULE_ENABLED
#include "at32f421_pwc.h"
#endif
#ifdef ADC_MODULE_ENABLED
#include "at32f421_adc.h"
#endif
#ifdef SPI_MODULE_ENABLED
#include "at32f421_spi.h"
#endif
#ifdef DMA_MODULE_ENABLED
#include "at32f421_dma.h"
#endif
#ifdef DEBUG_MODULE_ENABLED
#include "at32f421_debug.h"
#endif
#ifdef FLASH_MODULE_ENABLED
#include "at32f421_flash.h"
#endif
#ifdef CRC_MODULE_ENABLED
#include "at32f421_crc.h"
#endif
#ifdef WWDT_MODULE_ENABLED
#include "at32f421_wwdt.h"
#endif
#ifdef WDT_MODULE_ENABLED
#include "at32f421_wdt.h"
#endif
#ifdef EXINT_MODULE_ENABLED
#include "at32f421_exint.h"
#endif
#ifdef MISC_MODULE_ENABLED
#include "at32f421_misc.h"
#endif
#ifdef SCFG_MODULE_ENABLED
#include "at32f421_scfg.h"
#endif
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,56 @@
/**
**************************************************************************
* @file at32f421_int.h
* @brief header file of main interrupt service routines.
**************************************************************************
* Copyright notice & Disclaimer
*
* The software Board Support Package (BSP) that is made available to
* download from Artery official website is the copyrighted work of Artery.
* Artery authorizes customers to use, copy, and distribute the BSP
* software and its related documentation for the purpose of design and
* development in conjunction with Artery microcontrollers. Use of the
* software is governed by this copyright notice and the following disclaimer.
*
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
* GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
* TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
* STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
* INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
*
**************************************************************************
*/
/* define to prevent recursive inclusion -------------------------------------*/
#ifndef __AT32F421_INT_H
#define __AT32F421_INT_H
#ifdef __cplusplus
extern "C" {
#endif
/* includes ------------------------------------------------------------------*/
#include "at32f421.h"
/* exported types ------------------------------------------------------------*/
/* exported constants --------------------------------------------------------*/
/* exported macro ------------------------------------------------------------*/
/* exported functions ------------------------------------------------------- */
void NMI_Handler(void);
void HardFault_Handler(void);
void MemManage_Handler(void);
void BusFault_Handler(void);
void UsageFault_Handler(void);
void SVC_Handler(void);
void DebugMon_Handler(void);
void PendSV_Handler(void);
void SysTick_Handler(void);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,99 @@
/**
**************************************************************************
* @file cmcng.h
* @version v1.0
* @date 2025-09-08
* @brief һЩ<D2BB><D0A9><EFBFBD><EFBFBD>
**************************************************************************
* Copyright notice & Disclaimer
* * Create 2025-09-08 by wangfq
* *
**************************************************************************
*/
#ifndef __CMCNG_H__
#define __CMCNG_H__
#include <stdio.h>
#include <stdint.h>
#define PRODUCT_MODEL "DLD960"
#define FIRMWARE_VER "1.00"
#define HARDWARE_VER "1.00"
#define FIRMWARE_VER_MAIN 0
#define FIRMWARE_VER_SUB 30
#define FIRMWARE_VER_SSUB 0
#define HARDWARE_VER_MAIN 1
#define HARDWARE_VER_SUB 0
#define HARDWARE_VER_SSUB 0
#define FUNCTION_A 0x01 // 二次判断
#define FUNCTION_B 0x02 // 二次判断增强条件判断
#define FUNCTION_C 0x04 //
#define FUNCTION_D 0x08 //
#ifdef DEBUG
#define PRINT(X...) printf(X)
#else
#define PRINT(X...)
#endif
#define LOOP_CAPTURE_MAX 4 // 4 loop capture
#define CMD_DEV_Ver 0x4A // Version
#define CMD_DBN_SET_MCJQ_PARAM 0x63 // 设置 车检器多路参数
#define CMD_DBN_GET_MCJQ_PARAM 0x64 // 读取 车检器多路参数
#define CMD_DBN_DEV_RESET 0x6D
#define CMD_DBN_LOOP_SAMPLE_PARAM 0x87
#define CMD_DBN_LOOP_BALANCE_PARAM 0x88
#define CMD_DBN_LOOP_RELEASE_PLANB 0x89
#define CMD_DBN_LOOP_SENS_LIST 0x8A
#define CMD_DBN_SET_CJQ_FACTORY 0x92
#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 // 设备主动上报 使能
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_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, 线圈环境评估
SENS_MULTI_LOOP_DYNAMIC, // 0x0C, 多路线圈环境动态信息
} SUB_SENS_TYPE; // 传感数据类型
#define BUFF_STACK_SIZE 64
// USART1
#define USART1_RX_BUFFER_SIZE BUFF_STACK_SIZE
extern char usart1_rx_buffer[USART1_RX_BUFFER_SIZE];
typedef struct _PKG_UART_
{
uint8_t flag;
uint8_t offset;
uint8_t len;
uint8_t pkg[BUFF_STACK_SIZE];
uint32_t tick;
}Pkg_Uart;
extern Pkg_Uart g_pkg_uart_1;
extern Pkg_Uart g_pkg_uart_report;
void uart_report_packet_loop_acs(uint8_t flag);
#endif

View File

@@ -0,0 +1,83 @@
/**
**************************************************************************
* @file flash.h
* @brief flash header file
**************************************************************************
* Copyright notice & Disclaimer
*
* The software Board Support Package (BSP) that is made available to
* download from Artery official website is the copyrighted work of Artery.
* Artery authorizes customers to use, copy, and distribute the BSP
* software and its related documentation for the purpose of design and
* development in conjunction with Artery microcontrollers. Use of the
* software is governed by this copyright notice and the following disclaimer.
*
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
* GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
* TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
* STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
* INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
*
**************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __FLASH_H__
#define __FLASH_H__
#include "at32f421_board.h"
/** @addtogroup AT32F421_periph_examples
* @{
*/
#define DLD_BUFEER_SIZE 100 // byte number, sector
#define DLD_FLASH_ADDRESS_START (0x08000000 + 1024 * 63 + 512) // The last sector
#define DLD_FLASH_MAX_SIZE (0x08000000 + 1024 * 64)
#define MAX_Store_Size DLD_BUFEER_SIZE
/** @addtogroup 421_FLASH_write_read
* @{
*/
/** @defgroup FLASH_write_read_functions
* @{
*/
void flash_read(uint32_t read_addr, uint16_t *p_buffer, uint16_t num_read);
error_status flash_write_nocheck(uint32_t write_addr, uint16_t *p_buffer, uint16_t num_write);
error_status flash_write(uint32_t write_addr,uint16_t *p_Buffer, uint16_t num_write);
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#endif

View File

@@ -0,0 +1,70 @@
/**
**************************************************************************
* @file iap.h
* @brief iap header file
**************************************************************************
* Copyright notice & Disclaimer
*
* The software Board Support Package (BSP) that is made available to
* download from Artery official website is the copyrighted work of Artery.
* Artery authorizes customers to use, copy, and distribute the BSP
* software and its related documentation for the purpose of design and
* development in conjunction with Artery microcontrollers. Use of the
* software is governed by this copyright notice and the following disclaimer.
*
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
* GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
* TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
* STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
* INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
*
**************************************************************************
*/
#ifndef __IAP_H__
#define __IAP_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "at32f421_board.h"
/** @addtogroup UTILITIES_examples
* @{
*/
/** @addtogroup USART_iap_bootloader
* @{
*/
/** @defgroup bootloader_definition
* @{
*/
/* app starting address */
#define APP_START_ADDR 0x08003400
/* the previous sector of app starting address is iap upgrade flag */
#define IAP_UPGRADE_FLAG_ADDR (APP_START_ADDR - 0x800)
#define UPGRADE_DAT_START_ADDR APP_START_ADDR //0x0800A000 // 0x0804B000 // 0x08080000
/* when app received cmd 0x5aa5 from pc-tool, will set up the flag,
indicates that an app upgrade will follow, see iap application note for more details */
#define IAP_UPGRADE_FLAG 0x41544B38
#define IAP_UPGRADE_FLAG_9F 0x444C4439 //0x41544B39 //use 9F Protocol
#define IAP_UPGRADE_TYPE_DEFAULT 0
#define IAP_UPGRADE_TYPE_9F 1
#define IAP_CMD_READY 0xA5
#define IAP_CMD_ADDR_START 0xA6
#define IAP_CMD_TRAN_PKG_WITH_BACK 0xA7
#define IAP_CMD_TRAN_PKG_WITHOUT_OKBACK 0xA8
#endif

View File

@@ -0,0 +1,187 @@
/*
* storage.h
*
* Created on: Aug 27, 2024
* Author: Thinkpad
*/
#ifndef INCLUDE_STORAGE_H_
#define INCLUDE_STORAGE_H_
#include <stdint.h>
#include <string.h>
#include "cmcng.h"
#define Addr_Dev_Flag_Offset 0x00
#define Addr_Sens_Amount_Offset 0x0E
#define Addr_Smart_Mode_Offset 0x0F
#define Addr_Loop_Cng_Offset 0x10
#define Addr_Loop_PlanB_Cng_Offset 0x30
#define Addr_Flag_Sample_In 0x30
#define Addr_Sample_Max_Amplitude 0x31
#define Addr_Flag_Balance_Ori_In 0x33
#define Addr_Balance_Ori_In_Max_Cnt 0x34
#define Addr_Flag_Release_Ori_PlanB 0x36
#define Addr_Release_Ori_PlanB_TimeOut 0x37
#define Addr_Release_Ori_PlanB_Weight 0x38
#define Addr_Release_Ori_Amplitude 0x39
#define Addr_Flag_Release_Rate 0x3B
#define Addr_Release_Rate_First 0x3C
#define Addr_Release_Rate_Second 0x3D
#define Addr_Release_Rate_Weight 0x3E
#define Addr_Release_Rate_Mode 0x3F
#define Addr_Loop_Sens_List_Offset 0x40
#define Addr_Sens_Array_In 0x40
#define Addr_Sens_Array_Out 0x50
#define MAX_LOOP_SENS_AMOUNT 8 // 4 // 5
extern const uint16_t SensTable[MAX_LOOP_SENS_AMOUNT];
extern const uint16_t SensTable_1[MAX_LOOP_SENS_AMOUNT];
#pragma pack(1)
typedef struct _Loop_Sample_CNG_
{
uint8_t flag;
uint16_t max_amplitude; // 最大幅值
}Loop_Sample_Cng;
typedef struct _Loop_Balance_Ori_CNG_
{
uint8_t flag;
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; // 单位:分钟
}Loop_Release_Ori_PlanB;
typedef struct _Loop_Release_Change_Rate_
{
uint8_t flag_weight;
uint8_t rate_first;
uint8_t rate_second;
uint8_t mode;
}Loop_Release_Change_Rate;
typedef struct _Loop_Balance_PlanB_
{
Loop_Sample_Cng sample_cng;
Loop_Balance_Ori_Cng balance_ori_cng;
Loop_Release_Ori_PlanB release_ori_planB;
Loop_Release_Change_Rate release_change_rate;
}Loop_Balance_PlanB;
extern Loop_Balance_PlanB g_loop_balance_planB;
#define SENS_Default_Amount 4
typedef enum
{
Freq_High = 0,
Freq_Middle_High,
Freq_Middle_Low,
Freq_Low
} Freq_Level;
typedef enum
{
Smart_Mode_Disable = 0,
Smart_Mode_Enable
} Freq_Smart_Mode;
typedef enum
{
LNum_1 = 0,
LNum_2,
LNum_3,
LNum_4
} Loop_Num;
typedef struct
{
uint8_t sensitvity; // 高四位表示灵敏度的数量低四位表示当前灵敏度的序号从0开始
uint8_t delay_time;
uint8_t output_mode;
uint8_t direction_mode; // 方向判别模式0 触发模式, 非0 表示方向判别模式
uint8_t loopFreq_Level; // 高低频 0 High, 1 Middle High; 2 Middle Low, 3 Low
uint8_t loopSafe_Timeout; // 线圈安全模式, 0表示关闭非0表示开启以10秒为单位
uint8_t exist_mode; // 0 永久存在非0表示有限存在的时间单位为10秒
uint8_t rfu;
}Loop_Cng_Unit;
// extern Loop_Cng_Unit g_loop_cng_unit[LOOP_CAPTURE_MAX];
typedef struct
{
uint8_t smart_mode; // 0 disable
Loop_Cng_Unit loop_cng[LOOP_CAPTURE_MAX];
}Loop_Cng_Info;
extern Loop_Cng_Info g_loop_cng_info;
typedef struct
{
uint16_t sens_in;
uint16_t sens_out;
}Loop_Single_Sens;
typedef struct
{
uint8_t total;
Loop_Single_Sens sens[MAX_LOOP_SENS_AMOUNT];
}Loop_Sens_List;
extern Loop_Sens_List g_loop_sens_list;
typedef struct _DBN_BLE_STATE_
{
uint8_t flag; // if need to report
uint8_t enable; // if enable
uint8_t send_flag;
uint8_t obj_amount;
uint8_t cmd;
uint8_t sens_type;
uint8_t dat_len ;
uint8_t dat_offset;
uint8_t pkg_amount;
uint8_t pkg_seq;
uint16_t interval;
uint32_t counter;
uint8_t timeout_min; // minute
uint32_t timeout_counter;
} DBN_BLE_State;
#pragma pack()
#define HOLD_TIME 5*1200
#define LC_HOLD_TIME 4*1200 // 4 minute
#define IN_DELAY 10
#define OUT_DELAY 39
#define PLUSE_DELAY 10
void set_flp_level(uint8_t loop_num, uint8_t freq_level);
void set_factory_param(void);
void storage_dev(void);
void para_store_init(void);
void test_factory(void);
#endif /* INCLUDE_STORAGE_H_ */