130 lines
		
	
	
		
			4.6 KiB
		
	
	
	
		
			C
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			130 lines
		
	
	
		
			4.6 KiB
		
	
	
	
		
			C
		
	
	
		
			Executable File
		
	
	
	
	
/****************************************************************************
 | 
						|
 | 
						|
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 _MAC_ZC_API_H_
 | 
						|
#define _MAC_ZC_API_H_
 | 
						|
 | 
						|
#include "os_types.h"
 | 
						|
#include "iot_pkt.h"
 | 
						|
#include "plc_protocol.h"
 | 
						|
 | 
						|
#ifdef __cplusplus
 | 
						|
extern "C" {
 | 
						|
#endif
 | 
						|
 | 
						|
/* mac zc PLC rise edge */
 | 
						|
#define MAC_ZC_PLC_EDGE_RISE        0
 | 
						|
/* mac zc PLC fall edge */
 | 
						|
#define MAC_ZC_PLC_EDGE_FALL        1
 | 
						|
/* mac zc hw default capture PLC rise edge */
 | 
						|
#define MAC_ZC_PLC_EDGE_DFT         MAC_ZC_PLC_EDGE_RISE
 | 
						|
/* mac zc default id */
 | 
						|
#define MAC_ZC_DEFAULT_ID           0
 | 
						|
 | 
						|
/* mac zc phase event id */
 | 
						|
typedef enum _mac_zc_collect_event {
 | 
						|
    /* indicate the phase status not changed */
 | 
						|
    MAC_ZC_EVENT_NONE = 0,
 | 
						|
    /* indicate the phase status from power active to power stop */
 | 
						|
    MAC_ZC_EVENT_PHASE_LOSS,
 | 
						|
    /* indicate the phase status from power stop to power active */
 | 
						|
    MAC_ZC_EVENT_PHASE_RESTORE,
 | 
						|
    /* mac zc collect max event id */
 | 
						|
    MAC_ZC_EVENT_MAX,
 | 
						|
} mac_zc_collect_event_t;
 | 
						|
 | 
						|
/* zero-cross ntb report format. as we are not using packed struct, so we need
 | 
						|
 * to make sure all members in this struct are 4 bytes aligned.
 | 
						|
 */
 | 
						|
typedef struct _mac_zc_ntb_rpt {
 | 
						|
    /* number of phases zero cross NTB collected */
 | 
						|
    uint32_t    phase_cnt       :2,
 | 
						|
    /* ntb array total count */
 | 
						|
                ntb_cnt         :16,
 | 
						|
    /* indicate phase a/b/c is valid */
 | 
						|
                phase_a_valid   :1,
 | 
						|
                phase_b_valid   :1,
 | 
						|
                phase_c_valid   :1,
 | 
						|
    /* indicate ntb array full period or half period
 | 
						|
     * 1: full period; 0: half period
 | 
						|
     * TODO: may be expand into data alignment mode
 | 
						|
     */
 | 
						|
                is_full_period  :1,
 | 
						|
    /* indicate repeat phase connect */
 | 
						|
                is_repeat_phase :1,
 | 
						|
    /* phase A repeat with which phase, refer to PLC_PHASE_XXX */
 | 
						|
                phase_a_repeat  :2,
 | 
						|
    /* phase B repeat with which phase, refer to PLC_PHASE_XXX */
 | 
						|
                phase_b_repeat  :2,
 | 
						|
    /* phase C repeat with which phase, refer to PLC_PHASE_XXX */
 | 
						|
                phase_c_repeat  :2,
 | 
						|
    /* reserved */
 | 
						|
                rsvd0           :3;
 | 
						|
    /* current system ac average period, unit: ntb */
 | 
						|
    uint32_t    avg_period[PLC_PHASE_CNT];
 | 
						|
    /* ntb array */
 | 
						|
    uint32_t    ntb[0];
 | 
						|
} mac_zc_ntb_rpt_t;
 | 
						|
 | 
						|
#if MAC_ZC_ENABLE
 | 
						|
/*
 | 
						|
 * @brief mac_zc_is_power_collapsed() - get zc power collapsed
 | 
						|
 * @param pdev_id : whick pdev to get power status
 | 
						|
 * @return       0: power not collapsed, 1: power collapsed.
 | 
						|
 */
 | 
						|
uint8_t mac_zc_is_power_collapsed(uint8_t pdev_id);
 | 
						|
 | 
						|
/*
 | 
						|
 * @brief           start mac layer zero-cross ntb collection. the result will
 | 
						|
 *                  be delivered back to cvg layer
 | 
						|
 * @param pdev_id:  which pdev to be collected
 | 
						|
 * @param vdev_id:  which vdev to be collected
 | 
						|
 * @param pkt:      pointer to an iot_pkt_t pointer that holds zc ntb raw data
 | 
						|
 * @param cnt:      number of consecutive zero-cross ntb to be collected.
 | 
						|
 * @param is_full_period: flag to mark if it is collecting full period.
 | 
						|
 * @param nid:      target network id, 0: means local network id
 | 
						|
 * @param ntb_ptr:  pointer to target historical zc ntb that needs to be
 | 
						|
 *                  collected, NULL: means collecting real-time zc ntb.
 | 
						|
 *
 | 
						|
 * @retval: 0        - for success case
 | 
						|
 *          othersie - error code
 | 
						|
 */
 | 
						|
uint32_t mac_start_zc_ntb_collect(uint8_t pdev_id, uint8_t vdev_id,
 | 
						|
    iot_pkt_t **pkt, uint16_t cnt, uint8_t is_full_period, uint32_t nid,
 | 
						|
    uint32_t *ntb_ptr);
 | 
						|
#else
 | 
						|
#define mac_zc_is_power_collapsed(pdev_id)     (0); \
 | 
						|
    do {\
 | 
						|
        (void)pdev_id; \
 | 
						|
    } while(0)
 | 
						|
 | 
						|
#define mac_start_zc_ntb_collect(pdev_id, vdev_id, pkt, cnt, is_full_period, \
 | 
						|
    nid, ntb_ptr)                       (ERR_NOSUPP); \
 | 
						|
    do {\
 | 
						|
        (void)pdev_id; \
 | 
						|
        (void)vdev_id; \
 | 
						|
        (void)pkt; \
 | 
						|
        (void)cnt; \
 | 
						|
        (void)is_full_period; \
 | 
						|
        (void)nid; \
 | 
						|
        (void)ntb_ptr;\
 | 
						|
    } while(0)
 | 
						|
#endif
 | 
						|
 | 
						|
#ifdef __cplusplus
 | 
						|
}
 | 
						|
#endif
 | 
						|
 | 
						|
#endif //_MAC_ZC_API_H_
 |