You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
143 lines
8.0 KiB
C
143 lines
8.0 KiB
C
/*****************************************************************************
|
|
* 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;
|
|
|
|
/* 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
|
|
{
|
|
uint16_t MSRR[4]; // 缺陷电流通道周波原始采样值的平均值 (Mean Square Root Register).
|
|
int16_t AVR[4]; // 缺陷电流通道周波校准值寄存器 (Adjust Value Register).
|
|
int16_t MAX[4]; // 缺陷电流通道周波校准值最大值寄存器 (Max Value Register).
|
|
int16_t FAULT[4]; // 故障触发电流值寄存器 (Fault Value Register).
|
|
} dau_port_state_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 采集标志位
|
|
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
|
|
int16_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 端口状态寄存器
|
|
|
|
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_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_show(void);
|
|
|
|
#endif
|
|
/******************* (C) COPYRIGHT LandPower ***** END OF FILE ****************/
|