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.
297 lines
13 KiB
C
297 lines
13 KiB
C
/*****************************************************************************
|
|
* file include/pd_dau.h
|
|
* author YuLiang
|
|
* version 1.0.0
|
|
* date 03-Feb-2023
|
|
* brief This file provides all the headers of the dau functions.
|
|
******************************************************************************
|
|
* Attention
|
|
*
|
|
* <h2><center>© COPYRIGHT(c) 2021 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 LandPower 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 __PD_DAU_H__
|
|
#define __PD_DAU_H__
|
|
|
|
#ifdef CFG_DEV_TYPE_LAND_PD
|
|
/* Includes ------------------------------------------------------------------*/
|
|
#include "pd_main.h"
|
|
|
|
/* Define --------------------------------------------------------------------*/
|
|
#define DAU_MEM_PRPS_BANK 2
|
|
#define DAU_MEM_PRPS_ADDR 0x1A000000
|
|
#define DAU_MEM_PRPS_LEN 0xA00000
|
|
|
|
#define DAU_MEM_ORIGINAL_ADDR 0x1AA00000
|
|
#define DAU_MEM_ORIGINAL_LEN 0x2000000
|
|
|
|
//#define DAU_MEM_REG_ADDR 0x40000000
|
|
#define DAU_MEM_REG_ADDR 0x1CA00000
|
|
#define DAU_MEM_REG_LEN 0x1000
|
|
|
|
#define DAU_ADJ_POINT_SUM 10
|
|
#define DAU_EVENT_SUM 10
|
|
#define DAU_TREND_PRPS_SUM 10
|
|
#define DAU_TREND_POINT_BEFORE_CNT 64
|
|
#define DAU_TREND_POINT_AFTER_CNT 192
|
|
|
|
#define DAU_PKT_LEN 1536 // DAU 发包最大数据长度.
|
|
#define DAU_PKT_PRPS_LEN 640
|
|
#define DAU_PKT_PRPS_DATA_LEN 1280
|
|
#define DAU_PRPS_POINT_MAX 4000 // 自适应降噪点位调节点.
|
|
|
|
/* 全局寄存器 */
|
|
#define DAU_REG_ADDR_GSCR 0x0000 // 全局寄存器 - 软件特征寄存器.
|
|
#define DAU_GSCR_PRIMARY_Pos (24)
|
|
#define DAU_GSCR_PRIMARY_Msk (0xFF << DAU_GSCR_PRIMARY_Pos) /*!< 0xFF000000 */
|
|
#define DAU_GSCR_SECONDARY_Pos (16)
|
|
#define DAU_GSCR_SECONDARY_Msk (0xFF << DAU_GSCR_SECONDARY_Pos) /*!< 0x00FF0000 */
|
|
#define DAU_GSCR_CODE_Pos (0)
|
|
#define DAU_GSCR_CODE_Msk (0xFFFF << DAU_GSCR_CODE_Pos) /*!< 0x0000FFFF */
|
|
|
|
#define DAU_REG_ADDR_GCR 0x0004 // 全局寄存器 - 控制寄存器.
|
|
#define DAU_GCR_OFRE_Pos (16)
|
|
#define DAU_GCR_OFRE_Msk (0xFF << DAU_GCR_OFRE_Pos) /*!< 0xFFFF0000 */
|
|
#define DAU_GCR_TREND_Pos (8)
|
|
#define DAU_GCR_TREND_Msk (0xFF << DAU_GCR_TREND_Pos) /*!< 0x0000FF00 */
|
|
#define DAU_GCR_SYNC_Pos (2)
|
|
#define DAU_GCR_SYNC_Msk (0x3 << DAU_GCR_SYNC_Pos) /*!< 0x0000000C */
|
|
#define DAU_GCR_PPS_Pos (0)
|
|
#define DAU_GCR_PPS_Msk (0x3 << DAU_GCR_PPS_Pos) /*!< 0x00000003 */
|
|
|
|
#define DAU_REG_ADDR_RV0 0x0008 // 全局寄存器 - 保留寄存器.
|
|
|
|
#define DAU_REG_ADDR_GSR 0x000C // 全局寄存器 - 状态寄存器.
|
|
#define DAU_GSR_MODE_Pos (1)
|
|
#define DAU_GSR_MODE_Msk (0x1 << DAU_GSR_MODE_Pos) /*!< 0x0002 */
|
|
#define DAU_GSR_SYNC_Pos (0)
|
|
#define DAU_GSR_SYNC_Msk (0x1 << DAU_GSR_SYNC_Pos) /*!< 0x0001 */
|
|
|
|
#define DAU_REG_ADDR_GPFPCCR 0x0004 // 全局寄存器 - 工频周期时钟计数寄存器.
|
|
#define DAU_REG_ADDR_GPFPCR 0x0006 // 全局寄存器 - 工频周期计数寄存器.
|
|
#define DAU_REG_ADDR_GNSCR 0x0008 // 全局寄存器 - 纳秒级时钟计数寄存器.
|
|
|
|
/* 端口寄存器 */
|
|
#define DAU_REG_PORT_BASE 0x0100 // 端口寄存器基地址.
|
|
#define DAU_REG_PORT_OFFSET 0x0100 // 每个端口寄存器偏移地址.
|
|
|
|
#define DAU_CR_FT_Pos (4)
|
|
#define DAU_CR_FT_Msk (0xF << DAU_CR_FT_Pos) /*!< 0x000000F0 */
|
|
#define DAU_CR_PT_Pos (0)
|
|
#define DAU_CR_PT_Msk (0xF << DAU_CR_PT_Pos) /*!< 0x0000000F */
|
|
|
|
#define DAU_AVRP_AVRA_Pos (16)
|
|
#define DAU_AVRP_AVRA_Msk (0xFFFF << DAU_AVRP_AVRA_Pos) /*!< 0xFFFF0000 */
|
|
#define DAU_AVRP_AVR_Pos (0)
|
|
#define DAU_AVRP_AVR_Msk (0xFFFF << DAU_AVRP_AVR_Pos) /*!< 0x0000FFFF */
|
|
|
|
|
|
/* Exported types ------------------------------------------------------------*/
|
|
typedef void dau_prps_default_f(int16_t*);
|
|
typedef void dau_prps_process_f(uint8_t, uint8_t);
|
|
typedef void dau_trend_process_f(uint8_t, uint8_t, uint16_t);
|
|
|
|
/* 和 DAU 通讯使用的报文结构体. */
|
|
typedef struct
|
|
{
|
|
uint8_t slave_id;
|
|
uint8_t func;
|
|
uint16_t addr;
|
|
uint16_t len;
|
|
uint16_t data[DAU_PKT_LEN];
|
|
} dau_pkt_t;
|
|
|
|
/* 和 DAU 通讯使用的报文结构体. */
|
|
typedef struct
|
|
{
|
|
uint32_t power_fre_cnt;
|
|
int16_t data[DAU_PKT_PRPS_LEN];
|
|
} dau_pkt_prps_t;
|
|
|
|
/* DAU 全局寄存器. */
|
|
typedef struct
|
|
{
|
|
uint32_t GSCR; // 全局软件特征寄存器 (Global Softwave Characteristic Register).
|
|
uint32_t GCR; // 全局控制寄存器 (Global Control Register).
|
|
uint32_t reserved0; // 保留寄存器.
|
|
uint32_t GSR; // 全局状态寄存器 (Global Status Register).
|
|
uint32_t reserved1; // 保留寄存器.
|
|
uint32_t GPFPCCR; // 全局工频周期时钟计数寄存器 (Global Power Frequency Period Clock Count Register).
|
|
uint32_t GSDPCR; // 全局秒数据周期计数寄存器 (Global Second Data Period Count Register).
|
|
uint32_t GPFPCR; // 全局工频周期计数寄存器 (Global Power Frequency Period Count Register).
|
|
uint32_t GNSCR; // 全局纳秒级时钟计数寄存器 (Global ns Count Register).
|
|
uint32_t GPFCR; // 全局 PRPS 数据周期计数寄存器(Global PRPS Frequency Period Count Register).
|
|
uint32_t GODCR; // 全局原始数据点数寄存器(Global Original Data Count Register).
|
|
uint32_t reserved2[53]; // 保留寄存器.
|
|
} dau_reg_global_t;
|
|
|
|
/* DAU 通道寄存器. */
|
|
typedef struct
|
|
{
|
|
uint32_t CR; // 控制寄存器 (Control Register).
|
|
uint32_t reserved0[3]; // 保留寄存器.
|
|
uint32_t ASPR[DAU_ADJ_POINT_SUM]; // 校准分段点寄存器 (Adjust Segmentation Register).
|
|
uint32_t AFR[DAU_ADJ_POINT_SUM]; // 校准系数寄存器 (Adjust Factor Register).
|
|
uint32_t reserved1[10]; // 保留寄存器.
|
|
uint32_t AVRO; // 通道 1s 所有点的平均值.
|
|
uint32_t AVRP; // 通道 1s 12800 个点的平均值.
|
|
uint32_t reserved2[28]; // 保留寄存器.
|
|
} dau_reg_port_t;
|
|
|
|
/* DAU 全局寄存器. */
|
|
typedef struct
|
|
{
|
|
dau_reg_global_t reg_global; // 全局寄存器.
|
|
dau_reg_port_t reg_port[PD_DAU_PORT_SUM]; // 端口寄存器.
|
|
} dau_reg_t;
|
|
|
|
/* DAU 全局寄存器. */
|
|
typedef struct
|
|
{
|
|
uint32_t time; // 工频周期内点位时间, 单位: 10ns
|
|
int16_t data; // 数据
|
|
uint8_t reserved0[2]; // 保留位
|
|
} dau_prps_date_t;
|
|
|
|
/* DAU 全局寄存器. */
|
|
typedef struct
|
|
{
|
|
uint32_t time[PD_PRPS_NUM_MAX][PD_DAU_PORT_SUM];
|
|
int16_t data[PD_PRPS_NUM_MAX][PD_DAU_PORT_SUM];
|
|
} dau_prps_bank_t;
|
|
|
|
/* . */
|
|
typedef struct
|
|
{
|
|
dau_prps_bank_t bank[DAU_MEM_PRPS_BANK];
|
|
} dau_prps_t;
|
|
|
|
/* DAU 通道寄存器. */
|
|
typedef struct
|
|
{
|
|
uint32_t prps_fre_cnt; // 1s prps 工频周期计数.
|
|
dau_prps_date_t prps[PD_PRPS_NUM_MAX]; // 1s prps 原始数据.
|
|
int16_t denoise_level[PD_POWER_FRE_MAX]; // prps 计算使用的每个工频周期的噪声等级.
|
|
uint16_t denoise_auto; // 灵活降噪等级.
|
|
uint16_t denoise_variance; // 方差降噪系数, 单位: 1%
|
|
} dau_port_state_t;
|
|
|
|
/* DAU 通道数据处理函数. */
|
|
typedef struct
|
|
{
|
|
dau_prps_default_f *data_default; // PRPS buffer 还原默认值.
|
|
dau_prps_process_f *data_unit_conversion; // PRPS 数据单位转换.
|
|
dau_prps_process_f *denoise; // PRPS 自动 / 手动降噪.
|
|
dau_prps_process_f *denoise_r; // PRPS 关联降噪.
|
|
dau_prps_process_f *denoise_state; // PRPS 降噪数据统计.
|
|
dau_prps_process_f *denoise_real; // 实时数据自动 / 手动降噪.
|
|
dau_prps_process_f *denoise_real_r; // 实时数据关联降噪.
|
|
dau_prps_process_f *denoise_real_state; // PRPS 降噪数据统计.
|
|
dau_prps_process_f *event_init; // 事件结构体初始化.
|
|
dau_trend_process_f *event; // 事件处理.
|
|
dau_prps_process_f *trend_init; // 趋势结构体初始化.
|
|
dau_trend_process_f *trend; // 趋势数据.
|
|
} dau_port_func_t;
|
|
|
|
typedef struct
|
|
{
|
|
int16_t data[PD_TREND_PHASE_POINT_CNT];
|
|
} dau_original_point_t;
|
|
|
|
typedef struct
|
|
{
|
|
dau_original_point_t point[PD_PHASE_NUM][PD_DAU_PORT_SUM];
|
|
} dau_original_t;
|
|
|
|
/* DAU 板卡全局结构 */
|
|
typedef struct{
|
|
uint8_t unit; // FPGA 板卡号.
|
|
uint8_t port_num; // FPGA 板卡端口数量.
|
|
uint8_t is_del; // 用于判断是否被删除.
|
|
uint8_t is_valid;
|
|
uint8_t is_connect;
|
|
|
|
dau_port_state_t port_state[PD_DAU_PORT_SUM]; // 端口状态.
|
|
dau_port_func_t *port_func[PD_DAU_PORT_SUM]; // 端口数据处理函数.
|
|
dau_reg_t *reg; // DAU 寄存器映射地址.
|
|
dau_prps_t *PRPS; // DAU PRPS 映射地址.
|
|
dau_original_t *original; // DAU 原始数据映射地址.
|
|
} dau_t;
|
|
|
|
/* DAU 全局结构 */
|
|
typedef struct{
|
|
int fd_mmu; // MMU 映射文件描述符
|
|
pthread_mutex_t mutex; // 趋势处理线程同步信号量
|
|
|
|
uint32_t real_idx;
|
|
uint32_t trend_idx;
|
|
uint32_t event_index[PD_DAU_SUM][PD_DAU_PORT_SUM]; // 每个端口的事件索引.
|
|
uint32_t trend_event_index[PD_DAU_SUM][PD_DAU_PORT_SUM]; // 每个端口的趋势事件索引.
|
|
|
|
uint32_t dau_sum;
|
|
uint32_t recv_cnt;
|
|
uint32_t recv_cnt_old;
|
|
} dau_ctrl_t;
|
|
|
|
/* Exported macro ------------------------------------------------------------*/
|
|
#define SET_BIT(REG, BIT) ((REG) |= (BIT))
|
|
#define CLEAR_BIT(REG, BIT) ((REG) &= ~(BIT))
|
|
#define READ_BIT(REG, BIT) ((REG) & (BIT))
|
|
#define WRITE_REG(REG, VAL) ((REG) = (VAL))
|
|
#define MODIFY_REG(REG, CLEARMASK, SETMASK) WRITE_REG((REG), (((REG) & (~(CLEARMASK))) | (SETMASK)))
|
|
|
|
#define DAU_REG_PORT_ADDR_GET(port) ((port + 1) << 8)
|
|
|
|
/* Extern global variables ---------------------------------------------------*/
|
|
extern dau_t *dau[PD_DAU_SUM];
|
|
extern dau_ctrl_t dau_ctrl;
|
|
|
|
/* Extern functions ----------------------------------------------------------*/
|
|
extern int32_t dau_port_to_vport(uint8_t unit, uint8_t port);
|
|
extern int32_t dau_vport_to_port(uint8_t vport, uint8_t *unit, uint8_t *port);
|
|
extern int32_t dau_port_filter_set(uint8_t unit, uint8_t port);
|
|
extern int32_t dau_port_type_set(uint8_t unit, uint8_t port);
|
|
extern int32_t dau_pps_mode_set(void);
|
|
extern int32_t dau_sync_mode_set(void);
|
|
extern int32_t dau_sync_fre_set(void);
|
|
extern int32_t dau_trend_inv_set(void);
|
|
extern int32_t dau_handle_init(void);
|
|
extern int32_t dau_handle_init_after(void);
|
|
extern int32_t dau_power_frequency_state_get(void);
|
|
extern float dau_power_frequency_get(void);
|
|
extern uint8_t dau_connect_get(void);
|
|
extern int32_t dau_param_adj_save(void);
|
|
extern int32_t dau_is_valid(dau_t *dau_node);
|
|
extern void dau_show(uint8_t unit);
|
|
extern void dau_show_value(uint8_t unit);
|
|
extern void dau_show_adj(uint8_t unit);
|
|
extern void dau_show_reg(uint8_t unit);
|
|
extern void dau_show_reg_port(uint8_t unit, uint8_t port);
|
|
extern char* dau_version_get(uint8_t unit, char *ver);
|
|
#endif
|
|
#endif
|
|
/************************ (C) COPYRIGHT LandPower ***** END OF FILE ****/
|