295 lines
		
	
	
		
			7.6 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
		
		
			
		
	
	
			295 lines
		
	
	
		
			7.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.
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								****************************************************************************/
							 | 
						||
| 
								 | 
							
								#include "iot_config.h"
							 | 
						||
| 
								 | 
							
								#include "os_types.h"
							 | 
						||
| 
								 | 
							
								#include "hw_reg_api.h"
							 | 
						||
| 
								 | 
							
								#include "hw_phy_api.h"
							 | 
						||
| 
								 | 
							
								#include "phy_chn.h"
							 | 
						||
| 
								 | 
							
								#include "phy_bb.h"
							 | 
						||
| 
								 | 
							
								#include "iot_io.h"
							 | 
						||
| 
								 | 
							
								#include "hw_tonemask.h"
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								void phy_proto_type_set(uint32_t phy_proto)
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								    /* phy dtest mode, cpu1 is not enable*/
							 | 
						||
| 
								 | 
							
								#if IOT_DTEST_ONLY_SUPPORT == 0
							 | 
						||
| 
								 | 
							
								    g_phy_cpu_share_ctxt.phy_proto = phy_proto;
							 | 
						||
| 
								 | 
							
								#else
							 | 
						||
| 
								 | 
							
								    g_phy_ctxt.indep.chn.phy_proto = phy_proto;
							 | 
						||
| 
								 | 
							
								#endif
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								uint32_t IRAM_ATTR phy_proto_type_get()
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								    /* phy dtest mode, cpu1 is not enable*/
							 | 
						||
| 
								 | 
							
								#if IOT_DTEST_ONLY_SUPPORT == 0
							 | 
						||
| 
								 | 
							
								    return g_phy_cpu_share_ctxt.phy_proto;
							 | 
						||
| 
								 | 
							
								#else
							 | 
						||
| 
								 | 
							
								    return g_phy_ctxt.indep.chn.phy_proto;
							 | 
						||
| 
								 | 
							
								#endif
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								void phy_proto_type_to_set(uint32_t phy_proto)
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								    g_phy_ctxt.indep.chn.phy_proto_tobe = phy_proto;
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								uint32_t phy_proto_type_to_get()
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								    return g_phy_ctxt.indep.chn.phy_proto_tobe;
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								uint8_t phy_proto_type_is_i1901(void)
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								    return (SUPPORT_SMART_GRID && SUPPORT_IEEE_1901);
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								void phy_band_id_set(uint32_t band_id)
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								    /* phy dtest mode, cpu1 is not enable*/
							 | 
						||
| 
								 | 
							
								#if IOT_DTEST_ONLY_SUPPORT == 0
							 | 
						||
| 
								 | 
							
								    g_phy_cpu_share_ctxt.band_id = band_id;
							 | 
						||
| 
								 | 
							
								#else
							 | 
						||
| 
								 | 
							
								    g_phy_ctxt.indep.chn.band_id = band_id;
							 | 
						||
| 
								 | 
							
								#endif
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								uint32_t phy_band_id_get()
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								    /* phy dtest mode, cpu1 is not enable*/
							 | 
						||
| 
								 | 
							
								#if IOT_DTEST_ONLY_SUPPORT == 0
							 | 
						||
| 
								 | 
							
								    return g_phy_cpu_share_ctxt.band_id;
							 | 
						||
| 
								 | 
							
								#else
							 | 
						||
| 
								 | 
							
								    return g_phy_ctxt.indep.chn.band_id;
							 | 
						||
| 
								 | 
							
								#endif
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								void phy_band_id_to_set(uint32_t band_id)
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								    g_phy_ctxt.indep.chn.band_id_tobe = (uint16_t)band_id;
							 | 
						||
| 
								 | 
							
								    return;
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								uint32_t sg_tonemask_to_hw_tonemask(uint32_t sw_tonemask)
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								    if (sw_tonemask > MAX_HW_BAND) {
							 | 
						||
| 
								 | 
							
								        //TODO:handle other tonemask;
							 | 
						||
| 
								 | 
							
								        IOT_ASSERT(0);
							 | 
						||
| 
								 | 
							
								        return 0;
							 | 
						||
| 
								 | 
							
								    } else {
							 | 
						||
| 
								 | 
							
								        return sw_tonemask + 1;
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								uint32_t phy_support_band_table_get(uint32_t proto, void **band_tbl)
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								    uint32_t band_cnt;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    switch (proto) {
							 | 
						||
| 
								 | 
							
								#if SUPPORT_SMART_GRID
							 | 
						||
| 
								 | 
							
								    case PLC_PROTO_TYPE_SG:
							 | 
						||
| 
								 | 
							
								        if (IOT_PLC_PHY_BAND_RANGE_DFT == IOT_SUPPORT_PROTO_SG_NSG_BAND) {
							 | 
						||
| 
								 | 
							
								            band_cnt = phy_get_plc_nsg_band_tab_info(
							 | 
						||
| 
								 | 
							
								                (const plc_phy_band_table_t **)band_tbl);
							 | 
						||
| 
								 | 
							
								        } else {
							 | 
						||
| 
								 | 
							
								            band_cnt = 0;
							 | 
						||
| 
								 | 
							
								            *band_tbl = NULL;
							 | 
						||
| 
								 | 
							
								            iot_printf("support_band_get range %d error\n",
							 | 
						||
| 
								 | 
							
								                IOT_PLC_PHY_BAND_RANGE_DFT);
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								        break;
							 | 
						||
| 
								 | 
							
								#endif
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#if SUPPORT_SOUTHERN_POWER_GRID
							 | 
						||
| 
								 | 
							
								    case PLC_PROTO_TYPE_SPG:
							 | 
						||
| 
								 | 
							
								        band_cnt = phy_get_plc_nsg_band_tab_info(
							 | 
						||
| 
								 | 
							
								            (const plc_phy_band_table_t **)band_tbl);
							 | 
						||
| 
								 | 
							
								        break;
							 | 
						||
| 
								 | 
							
								#endif
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#if SUPPORT_GREEN_PHY
							 | 
						||
| 
								 | 
							
								    case PLC_PROTO_TYPE_GP:
							 | 
						||
| 
								 | 
							
								        band_cnt = phy_get_plc_gp_band_tab_info(
							 | 
						||
| 
								 | 
							
								            (const plc_phy_band_table_t **)band_tbl);
							 | 
						||
| 
								 | 
							
								        break;
							 | 
						||
| 
								 | 
							
								#endif
							 | 
						||
| 
								 | 
							
								    default:
							 | 
						||
| 
								 | 
							
								        band_cnt = 0;
							 | 
						||
| 
								 | 
							
								        *band_tbl = NULL;
							 | 
						||
| 
								 | 
							
								        break;
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    return band_cnt;
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								uint8_t phy_band_to_tonemask_id_get(uint8_t band_id)
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								    uint8_t mask_id;
							 | 
						||
| 
								 | 
							
								    switch (band_id) {
							 | 
						||
| 
								 | 
							
								    case IOT_SUPPORT_TONE_TIDE:
							 | 
						||
| 
								 | 
							
								        mask_id = TONE_MASK_ID_TIDE;
							 | 
						||
| 
								 | 
							
								        break;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    case IOT_SUPPORT_TONE_80_490_CE :
							 | 
						||
| 
								 | 
							
								    case IOT_SUPPORT_TONE_231_490_CE:
							 | 
						||
| 
								 | 
							
								    case IOT_SUPPORT_TONE_100_230_CE:
							 | 
						||
| 
								 | 
							
								        mask_id =  TONE_MASK_ID_CE;
							 | 
						||
| 
								 | 
							
								        break;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    default:
							 | 
						||
| 
								 | 
							
								        mask_id =  TONE_MASK_ID_NULL;
							 | 
						||
| 
								 | 
							
								        break;
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    return mask_id;
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								void phy_mask_id_set(plc_tone_mask_id mask_id)
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								    g_phy_ctxt.indep.chn.mask_id = mask_id;
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								void phy_mask_id_to_set(plc_tone_mask_id mask_id)
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								    g_phy_ctxt.indep.chn.mask_id_tobe = mask_id;
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								plc_tone_mask_id phy_mask_id_get()
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								    return g_phy_ctxt.indep.chn.mask_id;
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								uint32_t phy_ra_tbl_band_range_init()
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								    return 0;
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								uint32_t phy_ra_tbl_band_range_get(uint32_t proto_band_id,
							 | 
						||
| 
								 | 
							
								    uint32_t* start_idx, uint32_t* ed_idx)
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								    /* fix band = 0 for unified band handle in rate table */
							 | 
						||
| 
								 | 
							
								    (void)proto_band_id;
							 | 
						||
| 
								 | 
							
								    *start_idx = 0;
							 | 
						||
| 
								 | 
							
								    *ed_idx = phy_get_rt_sz();
							 | 
						||
| 
								 | 
							
								    return 0;
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								void phy_multi_band_opt_ena(uint32_t proto_band_id)
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								    if (IOT_SUPPORT_TONE_MULTI_BAND021 == proto_band_id) {
							 | 
						||
| 
								 | 
							
								        /* enable spur mask 100-120 for pkt detect*/
							 | 
						||
| 
								 | 
							
								        phy_spur_mask_set(110, 20);
							 | 
						||
| 
								 | 
							
								        /* increase pkt detect threshold for decrease warnning */
							 | 
						||
| 
								 | 
							
								        phy_rxfd_pkt_det_thd_set(32,32);
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								void phy_multi_band_opt_dis(uint32_t proto_band_id)
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								    if (IOT_SUPPORT_TONE_MULTI_BAND021 == proto_band_id) {
							 | 
						||
| 
								 | 
							
								        /* clear spur mask 100-120 for pkt detect*/
							 | 
						||
| 
								 | 
							
								        phy_spur_mask_clr(110, 20);
							 | 
						||
| 
								 | 
							
								        /* recover pkt detect threshold for decrease warnning */
							 | 
						||
| 
								 | 
							
								        phy_rxfd_pkt_det_thd_set(16, 32);
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								uint32_t phy_hw_band_to_proto_band(uint32_t hw_band)
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								    uint32_t proto_band_id = phy_band_id_get();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    if (IOT_SUPPORT_TONE_MULTI_BAND021 == proto_band_id) {
							 | 
						||
| 
								 | 
							
								        uint32_t proto = PHY_PROTO_TYPE_GET();
							 | 
						||
| 
								 | 
							
								        if (PLC_PROTO_TYPE_SPG == proto) {
							 | 
						||
| 
								 | 
							
								            /* spg not have proto band0, full band -> proto band2 */
							 | 
						||
| 
								 | 
							
								            switch (hw_band) {
							 | 
						||
| 
								 | 
							
								            case HW_FULL_BAND:
							 | 
						||
| 
								 | 
							
								            case HW_LOW_BAND:
							 | 
						||
| 
								 | 
							
								                return IOT_SUPPORT_TONE_32_120;
							 | 
						||
| 
								 | 
							
								            case HW_HIGH_BAND:
							 | 
						||
| 
								 | 
							
								                return IOT_SUPPORT_TONE_100_230;
							 | 
						||
| 
								 | 
							
								            default:
							 | 
						||
| 
								 | 
							
								                IOT_ASSERT(0);
							 | 
						||
| 
								 | 
							
								            }
							 | 
						||
| 
								 | 
							
								        } else {
							 | 
						||
| 
								 | 
							
								            switch (hw_band) {
							 | 
						||
| 
								 | 
							
								            case HW_FULL_BAND:
							 | 
						||
| 
								 | 
							
								                return IOT_SUPPORT_TONE_80_490;
							 | 
						||
| 
								 | 
							
								            case HW_LOW_BAND:
							 | 
						||
| 
								 | 
							
								                return IOT_SUPPORT_TONE_32_120;
							 | 
						||
| 
								 | 
							
								            case HW_HIGH_BAND:
							 | 
						||
| 
								 | 
							
								                return IOT_SUPPORT_TONE_100_230;
							 | 
						||
| 
								 | 
							
								            default:
							 | 
						||
| 
								 | 
							
								                IOT_ASSERT(0);
							 | 
						||
| 
								 | 
							
								            }
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    return proto_band_id;
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								uint32_t phy_proto_band_to_hw_band(uint32_t proto_single_band)
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								    uint32_t proto_band_id = phy_band_id_get();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    /* check valid */
							 | 
						||
| 
								 | 
							
								    IOT_ASSERT(proto_single_band < IOT_SUPPORT_TONE_MULTI_BAND021);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    if (IOT_SUPPORT_TONE_MULTI_BAND021 == proto_band_id) {
							 | 
						||
| 
								 | 
							
								        switch (proto_single_band)
							 | 
						||
| 
								 | 
							
								        {
							 | 
						||
| 
								 | 
							
								            case IOT_SUPPORT_TONE_80_490:
							 | 
						||
| 
								 | 
							
								                return HW_FULL_BAND;
							 | 
						||
| 
								 | 
							
								            case IOT_SUPPORT_TONE_100_230:
							 | 
						||
| 
								 | 
							
								                return HW_HIGH_BAND;
							 | 
						||
| 
								 | 
							
								            case IOT_SUPPORT_TONE_32_120:
							 | 
						||
| 
								 | 
							
								                return HW_LOW_BAND;
							 | 
						||
| 
								 | 
							
								            default:
							 | 
						||
| 
								 | 
							
								                /* TODO: default share last band id.
							 | 
						||
| 
								 | 
							
								                 * when fix phy_get_sym_per_pb() and phy_get_fl_per_pb()
							 | 
						||
| 
								 | 
							
								                 * source source, then need to IOT_ASSERT here.
							 | 
						||
| 
								 | 
							
								                 */
							 | 
						||
| 
								 | 
							
								                //IOT_ASSERT(0);
							 | 
						||
| 
								 | 
							
								                return HW_LOW_BAND;
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    return HW_FULL_BAND;
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								uint32_t phy_def_hw_band_id_get(void)
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								    uint32_t proto_band_id = phy_band_id_get();
							 | 
						||
| 
								 | 
							
								    if (proto_band_id < IOT_SUPPORT_TONE_MULTI_BAND021) {
							 | 
						||
| 
								 | 
							
								        return HW_FULL_BAND;
							 | 
						||
| 
								 | 
							
								    } else {
							 | 
						||
| 
								 | 
							
								        switch (proto_band_id) {
							 | 
						||
| 
								 | 
							
								        case IOT_SUPPORT_TONE_MULTI_BAND021:
							 | 
						||
| 
								 | 
							
								            //TODO: need check multi band default hw band.
							 | 
						||
| 
								 | 
							
								            /* default proto band 2 */
							 | 
						||
| 
								 | 
							
								            return HW_LOW_BAND;
							 | 
						||
| 
								 | 
							
								        default:
							 | 
						||
| 
								 | 
							
								            IOT_ASSERT(0);
							 | 
						||
| 
								 | 
							
								            return HW_LOW_BAND;
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								uint32_t phy_proto_single_band_id_get(void)
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								    return phy_hw_band_to_proto_band(phy_def_hw_band_id_get());
							 | 
						||
| 
								 | 
							
								}
							 |