165 lines
		
	
	
		
			5.6 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
		
		
			
		
	
	
			165 lines
		
	
	
		
			5.6 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
| 
								 | 
							
								/****************************************************************************
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT
							 | 
						||
| 
								 | 
							
								be copied by any method or incorporated into another program without
							 | 
						||
| 
								 | 
							
								the express written consent of Aerospace C.Power. This Information or any portion
							 | 
						||
| 
								 | 
							
								thereof remains the property of Aerospace C.Power. The Information contained herein
							 | 
						||
| 
								 | 
							
								is believed to be accurate and Aerospace C.Power assumes no responsibility or
							 | 
						||
| 
								 | 
							
								liability for its use in any way and conveys no license or title under
							 | 
						||
| 
								 | 
							
								any patent or copyright and makes no representation or warranty that this
							 | 
						||
| 
								 | 
							
								Information is free from patent or copyright infringement.
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								****************************************************************************/
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#ifndef PLC_MME_ZERO_CROSS_H
							 | 
						||
| 
								 | 
							
								#define PLC_MME_ZERO_CROSS_H
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* os shim includes */
							 | 
						||
| 
								 | 
							
								#include "os_types_api.h"
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#include "plc_mme.h"
							 | 
						||
| 
								 | 
							
								#include "plc_utils.h"
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#ifdef __cplusplus
							 | 
						||
| 
								 | 
							
								extern "C" {
							 | 
						||
| 
								 | 
							
								#endif
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* pack for the structures in the whole file */
							 | 
						||
| 
								 | 
							
								#pragma pack(push)              // save the pack status
							 | 
						||
| 
								 | 
							
								#pragma pack(1)                 // 1 byte align
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define MME_ZC_CT_ONE_STA           0   // collection type: one STA
							 | 
						||
| 
								 | 
							
								#define MME_ZC_CT_ALL_STA           1   // collection type: all STAs
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define MME_ZC_CP_HALF_PEROID       0   // half a power line period collection
							 | 
						||
| 
								 | 
							
								#define MME_ZC_CP_ONE_PEROID        1   // a whole power line period collection
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define MME_ZC_CT_FALLING_EDGE      0  // zc collect on falling edge
							 | 
						||
| 
								 | 
							
								#define MME_ZC_CT_RISING_EDGE       1  // zc collect on rising edge
							 | 
						||
| 
								 | 
							
								#define MME_ZC_CT_ALL_EDGE          2  // zc collect on falling and rising edge
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * each ntb_diff_value_t contain 2 NTB diff value.
							 | 
						||
| 
								 | 
							
								 * Please use ntb_diff1 to access the 1st value and ntb_diff2 for the 2nd one.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								typedef struct _ntb_diff_value {
							 | 
						||
| 
								 | 
							
								    union {
							 | 
						||
| 
								 | 
							
								        struct {
							 | 
						||
| 
								 | 
							
								            /* lower 12 bit */
							 | 
						||
| 
								 | 
							
								            uint16_t    ntb_diff1   :12;
							 | 
						||
| 
								 | 
							
								            uint16_t    _reserved_1 : 4;
							 | 
						||
| 
								 | 
							
								            uint8_t     _reserved_2;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        };
							 | 
						||
| 
								 | 
							
								        struct {
							 | 
						||
| 
								 | 
							
								            uint8_t     _reserved_3;
							 | 
						||
| 
								 | 
							
								            uint16_t    _reserved_4 : 4;
							 | 
						||
| 
								 | 
							
								            /* higher 12 bit */
							 | 
						||
| 
								 | 
							
								            uint16_t    ntb_diff2   :12;
							 | 
						||
| 
								 | 
							
								        };
							 | 
						||
| 
								 | 
							
								        /* size of this struct is 3 bytes */
							 | 
						||
| 
								 | 
							
								        uint8_t         data[3];
							 | 
						||
| 
								 | 
							
								    };
							 | 
						||
| 
								 | 
							
								} ntb_diff_value_t;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* definition of zero cross NTB collect indication */
							 | 
						||
| 
								 | 
							
								typedef struct _mme_zc_ntb_clct_ind {
							 | 
						||
| 
								 | 
							
								    /* the STA who should collect zero cross NTB */
							 | 
						||
| 
								 | 
							
								    uint16_t    sta:          12,
							 | 
						||
| 
								 | 
							
								    /* reserved for future */
							 | 
						||
| 
								 | 
							
								                reserved:     4;
							 | 
						||
| 
								 | 
							
								    /* collecting type. see MME_ZC_CT_XXX */
							 | 
						||
| 
								 | 
							
								    uint8_t     clct_type;
							 | 
						||
| 
								 | 
							
								    /* collecting period. see MME_ZC_CP_XXX */
							 | 
						||
| 
								 | 
							
								    uint8_t     clct_period;
							 | 
						||
| 
								 | 
							
								    /* number of consecutive zero cross NTB to collect */
							 | 
						||
| 
								 | 
							
								    uint8_t     clct_cnt;
							 | 
						||
| 
								 | 
							
								    /* reserved */
							 | 
						||
| 
								 | 
							
								    uint8_t     resvd[3];
							 | 
						||
| 
								 | 
							
								} mme_zc_ntb_clct_ind_t;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* definition of zero cross NTB report */
							 | 
						||
| 
								 | 
							
								typedef struct _mme_zc_ntb_report {
							 | 
						||
| 
								 | 
							
								    /* the STA reporting zero corss NTB */
							 | 
						||
| 
								 | 
							
								    uint16_t            sta:          12,
							 | 
						||
| 
								 | 
							
								    /* reserved for future */
							 | 
						||
| 
								 | 
							
								                        resvd:        4;
							 | 
						||
| 
								 | 
							
								    /* number of zero cross NTB collected */
							 | 
						||
| 
								 | 
							
								    uint8_t             clct_cnt;
							 | 
						||
| 
								 | 
							
								    /* number of item in each phase */
							 | 
						||
| 
								 | 
							
								    uint8_t             phase_cnt[3];
							 | 
						||
| 
								 | 
							
								    /* standard NTB */
							 | 
						||
| 
								 | 
							
								    uint32_t            std_ntb;
							 | 
						||
| 
								 | 
							
								    /* each item contain 2 NTB diff values */
							 | 
						||
| 
								 | 
							
								    ntb_diff_value_t    ntb_diff_val[0];
							 | 
						||
| 
								 | 
							
								} mme_zc_ntb_report_t;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* definition of high-precision zero cross NTB area notify report data filed */
							 | 
						||
| 
								 | 
							
								typedef struct __mme_area_notify_zc_ntb_data {
							 | 
						||
| 
								 | 
							
								    /* number of item in each phase */
							 | 
						||
| 
								 | 
							
								    uint8_t             phase_cnt[3];
							 | 
						||
| 
								 | 
							
								    /* standard NTB */
							 | 
						||
| 
								 | 
							
								    uint32_t            std_ntb;
							 | 
						||
| 
								 | 
							
								    /* each item contain 2 NTB diff values */
							 | 
						||
| 
								 | 
							
								    ntb_diff_value_t    ntb_diff_val[0];
							 | 
						||
| 
								 | 
							
								} mme_area_notify_zc_ntb_data_t;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* definition of high-precision zero cross NTB area notify report */
							 | 
						||
| 
								 | 
							
								typedef struct _mme_area_notify_zc_ntb_report_header {
							 | 
						||
| 
								 | 
							
								    /* version */
							 | 
						||
| 
								 | 
							
								    uint8_t             ver        :6,
							 | 
						||
| 
								 | 
							
								    /* reserved for future */
							 | 
						||
| 
								 | 
							
								                        reserved_1 :2;
							 | 
						||
| 
								 | 
							
								    /* the STA reporting zero corss NTB */
							 | 
						||
| 
								 | 
							
								    uint16_t            tei        :12,
							 | 
						||
| 
								 | 
							
								    /* reserved for future */
							 | 
						||
| 
								 | 
							
								                        reserved_2 :4;
							 | 
						||
| 
								 | 
							
								    /* task sequence number */
							 | 
						||
| 
								 | 
							
								    uint8_t             task_sn;
							 | 
						||
| 
								 | 
							
								    /* same transformer identify result. valid range from 0 to 100 */
							 | 
						||
| 
								 | 
							
								    uint8_t             score      :7,
							 | 
						||
| 
								 | 
							
								    /* data attribute, 0 means sent from cco, 1 means sent from sta */
							 | 
						||
| 
								 | 
							
								                        attr       :1;
							 | 
						||
| 
								 | 
							
								    /* collecting type. see MME_ZC_CT_XXX_EDGE */
							 | 
						||
| 
								 | 
							
								    uint8_t             clct_type  :2,
							 | 
						||
| 
								 | 
							
								    /* reserved for future */
							 | 
						||
| 
								 | 
							
								                        reserved_3 :6;
							 | 
						||
| 
								 | 
							
								} mme_area_notify_zc_ntb_report_header_t;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* definition of zero cross NTB collect indication */
							 | 
						||
| 
								 | 
							
								typedef struct _spg_mme_zc_ntb_clct_ind {
							 | 
						||
| 
								 | 
							
								    /* the STA who should collect zero cross NTB */
							 | 
						||
| 
								 | 
							
								    tei_t      sta;
							 | 
						||
| 
								 | 
							
								    /* collecting type. see MME_ZC_CT_XXX */
							 | 
						||
| 
								 | 
							
								    uint8_t    clct_type;
							 | 
						||
| 
								 | 
							
								    /* collecting period. see MME_ZC_CP_XXX */
							 | 
						||
| 
								 | 
							
								    uint8_t    clct_period;
							 | 
						||
| 
								 | 
							
								    /* number of consecutive zero cross NTB to collect */
							 | 
						||
| 
								 | 
							
								    uint8_t    clct_cnt;
							 | 
						||
| 
								 | 
							
								} spg_mme_zc_ntb_clct_ind_t;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* definition of zero cross NTB report */
							 | 
						||
| 
								 | 
							
								typedef struct _spg_mme_zc_ntb_report {
							 | 
						||
| 
								 | 
							
								    /* the STA reporting zero corss NTB */
							 | 
						||
| 
								 | 
							
								    tei_t                   sta;
							 | 
						||
| 
								 | 
							
								    /* number of zero cross NTB collected */
							 | 
						||
| 
								 | 
							
								    uint8_t                 clct_cnt;
							 | 
						||
| 
								 | 
							
								    /* reserved */
							 | 
						||
| 
								 | 
							
								    uint8_t                 resv0;
							 | 
						||
| 
								 | 
							
								    /* standard NTB */
							 | 
						||
| 
								 | 
							
								    uint32_t                std_ntb;
							 | 
						||
| 
								 | 
							
								    /* each item contain 2 NTB diff values */
							 | 
						||
| 
								 | 
							
								    ntb_diff_value_t        ntb_diff_val[0];
							 | 
						||
| 
								 | 
							
								} spg_mme_zc_ntb_report_t;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#pragma pack(pop)               // restore the pack status
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#ifdef __cplusplus
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								#endif
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#endif // PLC_MME_ZERO_CROSS_H
							 |