|
|
|
/*****************************************************************************
|
|
|
|
* file Inc/dau.h
|
|
|
|
* author YuLiang
|
|
|
|
* version 1.0.0
|
|
|
|
* date 15-Aug-2024
|
|
|
|
* brief This file provides all the headers of DAU function.
|
|
|
|
******************************************************************************
|
|
|
|
* Attention
|
|
|
|
*
|
|
|
|
* <h2><center>© COPYRIGHT(c) 2022 LandPower</center></h2>
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without modification,
|
|
|
|
* are permitted provided that the following conditions are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
* 3. Neither the name of WTOE nor the names of its contributors may be used to
|
|
|
|
* endorse or promote products derived from this software without specific
|
|
|
|
* prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __DAU_H__
|
|
|
|
#define __DAU_H__
|
|
|
|
|
|
|
|
/* Includes ------------------------------------------------------------------*/
|
|
|
|
#include "main.h"
|
|
|
|
#include "FreeRTOS.h"
|
|
|
|
#include "task.h"
|
|
|
|
#include "cmsis_os.h"
|
|
|
|
|
|
|
|
/* Define --------------------------------------------------------------------*/
|
|
|
|
#define DAU_PORT_FAULT_CNT 3 // DAU 故障波形通道数
|
|
|
|
#define DAU_PORT_DEFECT_CNT 3 // DAU 缺陷波形通道数
|
|
|
|
#define DAU_PORT_GROUND_CNT 4 // DAU 工频接地波形通道数
|
|
|
|
#define DAU_BUF_LEN 1280
|
|
|
|
#define DAU_GPS_BUF_LEN 2560
|
|
|
|
|
|
|
|
#define DAU_PKT_FAULT_CNT 40 // DAU 故障波形总包数
|
|
|
|
#define DAU_PKT_FAULT_BYTE_CNT 1024 // DAU 故障波形每包数据大小
|
|
|
|
#define DAU_FAULT_BYTE_CNT 122880 // DAU 缺陷波形数据大小
|
|
|
|
|
|
|
|
#define DAU_PKT_DEFECT_CNT 40 // DAU 缺陷波形总包数
|
|
|
|
#define DAU_PKT_DEFECT_BYTE_CNT 1024 // DAU 缺陷波形每包数据大小
|
|
|
|
#define DAU_DEFECT_BYTE_CNT 122880 // DAU 缺陷波形数据大小
|
|
|
|
|
|
|
|
#define DAU_PKT_POWER_CNT 4 // DAU 工频波形总包数
|
|
|
|
#define DAU_PKT_POWER_BYTE_CNT 1024 // DAU 工频波形每包数据大小
|
|
|
|
#define DAU_POWER_DATE_LEN 2048 // DAU 工频数据长度, 每个数据大小 2byte
|
|
|
|
|
|
|
|
/* Exported types ------------------------------------------------------------*/
|
|
|
|
/* 采集标志位 */
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
DAU_COL_FLAG_FAULT_CMP = 0, // 故障触发波形上传完成
|
|
|
|
DAU_COL_FLAG_REG_DEFECT, // 寄存器触发缺陷波形有效
|
|
|
|
DAU_COL_FLAG_REG_POWER, // 寄存器触发工频波形有效
|
|
|
|
DAU_COL_FLAG_REG_CMP, // 寄存器触发波形上传完成
|
|
|
|
DAU_COL_FLAG_WAVE_FORCE, // 强制录波
|
|
|
|
} DAU_COL_FLAG_E;
|
|
|
|
|
|
|
|
/* 共有命令字. */
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
DAU_UPD_NONE = 0,
|
|
|
|
DAU_UPD_OK = 1,
|
|
|
|
DAU_UPD_ERROR = 2,
|
|
|
|
} DAU_UPD_ERR_E;
|
|
|
|
|
|
|
|
/* 采集标志位 */
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
DAU_REG_PORT_WRITE = 0, // 写端口寄存器
|
|
|
|
} DAU_REG_FLAG_E;
|
|
|
|
|
|
|
|
/* DAU 全局寄存器. */
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
uint16_t GSCR; // 全局软件特征寄存器 (Global Softwave Characteristic Register)
|
|
|
|
uint16_t GSVR; // 全局软件版本寄存器 (Global Softwave Version Register)
|
|
|
|
uint16_t GSR; // 全局状态寄存器 (Global Status Register)
|
|
|
|
uint16_t GFTR; // 全局故障触发录波状态寄存器 (Global Fault Triggering Register)
|
|
|
|
uint32_t GFTUR; // 全局故障触发 UTC 时间点寄存器 (Global Fault Triggering UTC Register)
|
|
|
|
uint32_t GFTNR; // 全局故障触发 ns 时间点寄存器 (Global Fault Triggering ns Register)
|
|
|
|
uint16_t GRTR; // 全局寄存器触发录波状态寄存器 (Global Register Triggering Register)
|
|
|
|
uint16_t reserve;
|
|
|
|
uint32_t GUR; // 全局 UTC 寄存器 (Global UTC Register)
|
|
|
|
uint32_t GNR; // 全局 ns 寄存器 (Global ns Register)
|
|
|
|
} dau_reg_global_t;
|
|
|
|
|
|
|
|
/* DAU 通道状态寄存器. */
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
int16_t DMAX[4]; // 缺陷电流通道周波最大值寄存器 (Defect Max Value Register).
|
|
|
|
uint16_t DAVR[4]; // 缺陷电流通道周波平均值寄存器 (Defect Average Value Register).
|
|
|
|
uint16_t FAVR[4]; // 故障电流通道周波平均值寄存器 (Fault Average Value Register).
|
|
|
|
int16_t FMAX[4]; // 故障电流通道原始采样值最大值寄存器 (Fault Max Value Register).
|
|
|
|
} dau_port_state_reg_t;
|
|
|
|
|
|
|
|
/* DAU 通道状态寄存器. */
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
uint16_t PDZR; // 缺陷电流通道零点原始值寄存器.
|
|
|
|
uint16_t PFZR; // 故障电流通道零点原始值寄存器.
|
|
|
|
uint16_t reserve0[10];
|
|
|
|
uint16_t PDAR; // 缺陷电流通道校准系数寄存器.
|
|
|
|
uint16_t reserve1[9];
|
|
|
|
uint16_t reserve2[10];
|
|
|
|
uint16_t PFAR; // 故障电流通道校准系数寄存器.
|
|
|
|
} dau_port_reg_t;
|
|
|
|
|
|
|
|
/* DAU 全局结构体 */
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
osThreadId_t dau_handle; // DAU 任务句柄
|
|
|
|
SPI_HandleTypeDef *spi; // DAU 通讯使用的 SPI 句柄
|
|
|
|
uint8_t buf_dau_tx[DAU_BUF_LEN]; // DAU 发包缓存
|
|
|
|
uint8_t buf_dau_rx[DAU_BUF_LEN]; // DAU 收包缓存
|
|
|
|
uint32_t addr_fault; // DAU 故障触发录波 flash 地址
|
|
|
|
uint32_t addr_reg; // DAU 寄存器触发录波 flash 地址
|
|
|
|
uint32_t col_time; // DAU 采集时间
|
|
|
|
uint8_t col_flag; // DAU 采集标志位
|
|
|
|
uint8_t update_flag; // DAU 升级标志位
|
|
|
|
uint8_t update_rt; // DAU 升级结果, 0 - 无效, 1 - 成功, 2 - 失败
|
|
|
|
uint8_t update_rt_dbg; // DAU 升级结果- debug 工具使用, 0 - 无效, 1 - 成功, 2 - 失败
|
|
|
|
uint32_t update_len; // DAU 升级文件大小
|
|
|
|
uint32_t fault_utc; // 故障触发时间
|
|
|
|
uint32_t fault_ns; // 故障触发时间纳秒
|
|
|
|
int16_t fault_power[DAU_PORT_POWER_CNT][DAU_POWER_DATE_LEN]; // 故障触发工频波形采样电流值, 接地电流 0.1A, 运行电流 0.25A
|
|
|
|
uint32_t fault_elec[DAU_PORT_POWER_CNT];// 故障触发工频电流有效值 mA
|
|
|
|
int16_t fault_trig[DAU_PORT_FAULT_MAX]; // 故障触发电流值 A
|
|
|
|
int16_t reg_power[DAU_PORT_POWER_CNT][DAU_POWER_DATE_LEN]; // 寄存器触发工频波形采样电流值, 接地电流 0.1A, 运行电流 0.25A
|
|
|
|
uint32_t reg_elec[DAU_PORT_POWER_CNT]; // 寄存器触发工频电流有效值 mA
|
|
|
|
uint16_t reg_defect_max[DAU_PORT_DEFECT_MAX]; // 寄存器触发缺陷电流最大值 mA
|
|
|
|
dau_reg_global_t reg_global; // DAU 全局寄存器
|
|
|
|
dau_port_state_reg_t reg_port_state; // DAU 端口状态寄存器
|
|
|
|
uint8_t reg_flag; // DAU 寄存器操作标志
|
|
|
|
uint8_t reg_data; // DAU 寄存器操作参数
|
|
|
|
|
|
|
|
osThreadId_t gps_handle; // GPS 任务句柄
|
|
|
|
UART_HandleTypeDef *uart; // GPS 通讯使用的串口句柄
|
|
|
|
uint8_t buf_gps[DAU_GPS_BUF_LEN]; // GPS 收包缓存
|
|
|
|
uint16_t len_buf_gps; // 接收到的报文长度
|
|
|
|
uint8_t is_half_buf_gps; // DMA 收包一半的时候会产生中断, 这个标志用于过滤这给中断
|
|
|
|
uint8_t is_utc_ok; // GPS 对时 UTC 时间成功, 当多次 is_utc_valid 无效后才会设置为失败
|
|
|
|
uint8_t is_utc_valid; // GPS 对时 UTC 时间有效
|
|
|
|
uint32_t utc; // GPS 对时 UTC 时间
|
|
|
|
} dau_ctrl_t;
|
|
|
|
|
|
|
|
/* Exported macro ------------------------------------------------------------*/
|
|
|
|
#define DAU_CS_ENABLE() HAL_GPIO_WritePin(DAU_CS_GPIO_Port, DAU_CS_Pin, GPIO_PIN_RESET)
|
|
|
|
#define DAU_CS_DISABLE() HAL_GPIO_WritePin(DAU_CS_GPIO_Port, DAU_CS_Pin, GPIO_PIN_SET)
|
|
|
|
|
|
|
|
/* Extern global variables ---------------------------------------------------*/
|
|
|
|
extern dau_ctrl_t dau_ctrl;
|
|
|
|
|
|
|
|
/* Extern functions ----------------------------------------------------------*/
|
|
|
|
extern void dau_init(void);
|
|
|
|
extern void dau_adj_init(void);
|
|
|
|
extern void dau_spi_rw(int8_t rw, uint16_t addr, uint16_t len);
|
|
|
|
extern void dau_show(void);
|
|
|
|
extern HAL_StatusTypeDef _dau_base_auto(uint8_t ch_bitmap, uint8_t index);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
/******************* (C) COPYRIGHT LandPower ***** END OF FILE ****************/
|