194 lines
5.8 KiB
C
194 lines
5.8 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 "hal_rx.h"
|
|
#include "tx_entry.h"
|
|
#include "iot_config.h"
|
|
#include "iot_io_api.h"
|
|
#include "iot_config_api.h"
|
|
#include "phy_chn.h"
|
|
#include "phy_phase.h"
|
|
#include "phy_txrx_pwr.h"
|
|
#include "iot_pt_func.h"
|
|
#include "mp_mode.h"
|
|
#include "phy_tools.h"
|
|
#include "plc_protocol.h"
|
|
#include "plc_mpdu_header.h"
|
|
#include "iot_cli.h"
|
|
#include "iot_pt_rf_func.h"
|
|
#include "iot_gpio_api.h"
|
|
#include "iot_board_api.h"
|
|
#include "iot_cal_data.h"
|
|
#include "iot_crc.h"
|
|
|
|
#if IOT_CLI_IC_TOOL_EN
|
|
#include "cli_ic_tool.h"
|
|
#include "cli_rf_ic_tool.h"
|
|
#endif
|
|
|
|
uint8_t mp_pt_golden_nid_config()
|
|
{
|
|
uint8_t gold_nid = 0;
|
|
uint8_t gold_nid_gpio_0 = 0, gold_nid_gpio_0_val = 0;
|
|
uint8_t gold_nid_gpio_1 = 0, gold_nid_gpio_1_val = 0;
|
|
uint8_t gold_nid_gpio_2 = 0, gold_nid_gpio_2_val = 0;
|
|
uint8_t gold_nid_gpio_3 = 0, gold_nid_gpio_3_val = 0;
|
|
uint8_t gold_nid_gpio_4 = 0, gold_nid_gpio_4_val = 0;
|
|
|
|
gold_nid_gpio_0 = iot_board_get_gpio(GPIO_PLC_EVENT);
|
|
iot_gpio_open_as_input(gold_nid_gpio_0);
|
|
gold_nid_gpio_0_val = iot_gpio_value_get(gold_nid_gpio_0);
|
|
|
|
gold_nid_gpio_1 = iot_board_get_gpio(GPIO_GOLDEN_SET);
|
|
iot_gpio_open_as_input(gold_nid_gpio_1);
|
|
gold_nid_gpio_1_val = iot_gpio_value_get(gold_nid_gpio_1);
|
|
|
|
gold_nid_gpio_2 = iot_board_get_gpio(GPIO_GOLDEN_RXD0);
|
|
iot_gpio_open_as_input(gold_nid_gpio_2);
|
|
gold_nid_gpio_2_val = iot_gpio_value_get(gold_nid_gpio_2);
|
|
|
|
gold_nid_gpio_3 = iot_board_get_gpio(GPIO_STA_OUT);
|
|
iot_gpio_open_as_input(gold_nid_gpio_3);
|
|
gold_nid_gpio_3_val = iot_gpio_value_get(gold_nid_gpio_3);
|
|
|
|
gold_nid_gpio_4 = iot_board_get_gpio(GPIO_GOLDEN_TXD0);
|
|
iot_gpio_open_as_input(gold_nid_gpio_4);
|
|
gold_nid_gpio_4_val = iot_gpio_value_get(gold_nid_gpio_4);
|
|
|
|
iot_printf("Golden Nid GPIO Status(txd0/staout/rxd0/set/event): "
|
|
"%d/%d/%d/%d/%d.\n", gold_nid_gpio_4_val,
|
|
gold_nid_gpio_3_val, gold_nid_gpio_2_val,
|
|
gold_nid_gpio_1_val, gold_nid_gpio_0_val);
|
|
|
|
gold_nid = (gold_nid_gpio_0_val |
|
|
(gold_nid_gpio_1_val << 1) |
|
|
(gold_nid_gpio_2_val << 2) |
|
|
(gold_nid_gpio_3_val << 3) |
|
|
(gold_nid_gpio_4_val << 4));
|
|
|
|
return gold_nid;
|
|
}
|
|
|
|
void iot_init_mp_mode_entry()
|
|
{
|
|
#if IOT_MP_MODE_DIRECT_ENABLE
|
|
g_phy_cpu_share_ctxt.pt_mode_entry = 1;
|
|
rx_common_init(IOT_PLC_PHY_MP_BAND);
|
|
mp_pt_golden_unit_rx();
|
|
#endif
|
|
|
|
#if IOT_MP_TX_MODE_ENABLE
|
|
rx_common_init(IOT_PLC_PHY_MP_BAND);
|
|
tx_common_init(IOT_PLC_PHY_MP_BAND);
|
|
mac_tx_handle(PHY_PHASE_OVR_A, \
|
|
PLC_PROTO_TYPE_SG, FC_DELIM_SOF, \
|
|
PT_TX_NO_BREAK_NUM, false);
|
|
#endif
|
|
|
|
#if (IOT_FLASH_SIZE >= 2 && IOT_MP_RX_MODE_ENABLE)
|
|
rx_common_init(IOT_PLC_PHY_MP_BAND);
|
|
mac_rx_single_mode(false);
|
|
#endif
|
|
|
|
#if IOT_MP_AUTO_TONE_TX
|
|
iot_printf("\nthis is auto tone tx mode entering...\n");
|
|
phy_auto_tone_tx_start(&g_phy_ctxt.indep.tx_tone);
|
|
#endif
|
|
|
|
#if IOT_MP_RF_MODE_DIRECT_ENABLE
|
|
mp_rf_golden_unit_main(MP_RF_GOLDEN_DEF_OPTION,
|
|
MP_RF_GOLDEN_DEF_CHANNEL);
|
|
#endif
|
|
|
|
#if IOT_CLI_IC_TOOL_EN
|
|
register_ic_tool_recv_cb(iot_ic_tool_op);
|
|
register_ic_rf_tool_recv_cb(iot_ic_rf_tool_op);
|
|
#endif
|
|
}
|
|
|
|
#if (IOT_CLI_IC_TOOL_EN && HPLC_RF_DEV_SUPPORT)
|
|
/*
|
|
static mp_rf_gu_tx_tone_pwr_info_t g_rf_tone_pwr_info[] = {
|
|
{11, 0x7d, 23, 420}, {-13, 0x7b, 9, 300}, {-40, 0x3f, 8, 280}};
|
|
*/
|
|
static mp_rf_gu_cali_t *g_rf_gu_cali = NULL;
|
|
|
|
uint8_t mp_pt_rf_gu_cali_load(mp_rf_gu_cali_t **cali_data)
|
|
{
|
|
iot_cal_data_cfg_t *calcfg;
|
|
uint32_t size, ret = ERR_OK;
|
|
uint16_t crc16 = 0;
|
|
uint8_t* pbuf;
|
|
|
|
if (g_rf_gu_cali == NULL) {
|
|
ret = iot_cal_data_get_cfg(&calcfg);
|
|
pbuf = calcfg->gu_cali.data;
|
|
size = sizeof(calcfg->gu_cali.data);
|
|
BUILD_BUG_ON(sizeof(mp_rf_gu_cali_t) <= size);
|
|
|
|
if (ret == ERR_OK) {
|
|
/* validate crc16 */
|
|
crc16 = iot_getcrc16(pbuf, size, IOT_CRC16_TYPE_BT);
|
|
if (crc16 != calcfg->gu_cali.crc) {
|
|
os_mem_set(pbuf, 0, size);
|
|
}
|
|
g_rf_gu_cali = (mp_rf_gu_cali_t *)pbuf;
|
|
*cali_data = g_rf_gu_cali;
|
|
} else {
|
|
os_mem_set(pbuf, 0, size);
|
|
}
|
|
} else {
|
|
*cali_data = g_rf_gu_cali;
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
uint8_t mp_pt_rf_gu_cali_commit()
|
|
{
|
|
iot_cal_data_cfg_t *calcfg;
|
|
uint32_t size, ret;
|
|
uint16_t crc16 = 0;
|
|
uint8_t* pbuf;
|
|
|
|
if (g_rf_gu_cali == NULL) {
|
|
IOT_ASSERT(0);
|
|
}
|
|
|
|
iot_cal_data_get_cfg(&calcfg);
|
|
pbuf = (uint8_t*)&calcfg->gu_cali.data;
|
|
size = sizeof(calcfg->gu_cali.data);
|
|
/* validate crc16 */
|
|
crc16 = iot_getcrc16(pbuf, size, IOT_CRC16_TYPE_BT);
|
|
calcfg->gu_cali.crc = crc16;
|
|
ret = iot_cal_data_set_cfg(calcfg);
|
|
|
|
return ret;
|
|
}
|
|
|
|
#else
|
|
|
|
uint8_t mp_pt_rf_gu_cali_load(mp_rf_gu_cali_t **cali_data)
|
|
{
|
|
(void)cali_data;
|
|
return ERR_INVAL;
|
|
}
|
|
|
|
uint8_t mp_pt_rf_gu_cali_commit()
|
|
{
|
|
return ERR_INVAL;
|
|
}
|
|
|
|
#endif
|