Files
kunlun/plc/halmac/channel_tools/mac_channel_tools.c
2024-09-28 14:24:04 +08:00

198 lines
5.3 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.
****************************************************************************/
#include "os_types.h"
#include "hw_phy_api.h"
#include "mac_init_api.h"
#include "hw_phy_init.h"
#include "phy_rf_init.h"
#include "mac_task.h"
#include "iot_ipc_api.h"
#include "plc_chn_est.h"
#include "iot_io.h"
#include "mac_channel_tools.h"
#include "mac_pdev.h"
#include "phy_data_ckb.h"
#if (IOT_STA_CONTROL_MODE == IOT_STA_CONTROL_TYPE_STA)
static mac_chan_tool_t chan_tool = { 0 };
void mac_channel_dump_start_internal(iot_pkt_t *pkt)
{
#if HW_PLATFORM >= HW_PLATFORM_FPGA
IOT_ASSERT(pkt != NULL);
iot_printf("[DUMP]start\n");
iot_channel_test_msg *msg = (iot_channel_test_msg*)iot_pkt_data(pkt);
iot_phy_chn_dump_rt_cfg_t *dump_cfg = \
(iot_phy_chn_dump_rt_cfg_t*)&msg->data[0];
mac_block_all_tx_ena(&g_mac_pdev[PLC_PDEV_ID]->hwq_hdl, true);
mac_pre_phy_reinit();
phy_rf_deinit();
/* turn off sw-agc */
phy_swagc_set(false);
iot_phy_chn_dump_start(dump_cfg);
iot_pkt_free(pkt);
#else
(void)pkt;
#endif
}
void mac_channel_test_end_internal()
{
#if HW_PLATFORM >= HW_PLATFORM_FPGA
iot_printf("[CH]end\n");
phy_new_cfg_apply();
phy_rf_new_cfg_apply();
mac_post_phy_reinit(0);
mac_block_all_tx_ena(&g_mac_pdev[PLC_PDEV_ID]->hwq_hdl, false);
chan_tool.chan_test_flag = 0;
#endif
}
static uint32_t mac_channel_dump_start(void *pkt)
{
uint32_t ret = 0;
mac_msg_t *msg = mac_alloc_msg();
if (msg == NULL) {
IOT_ASSERT(0);
ret = ERR_NOMEM;
goto out;
}
msg->type = MAC_MSG_TYPE_CLI;
msg->id = MAC_MSG_ID_CHANNEL_DUMP_TEST;
msg->data2 = pkt;
mac_queue_msg(msg, MAC_MSG_QUEUE_HP);
out:
return ret;
}
static uint32_t mac_channel_test_end()
{
uint32_t ret = 0;
mac_msg_t *msg = mac_alloc_msg();
if (msg == NULL) {
IOT_ASSERT(0);
ret = ERR_NOMEM;
goto out;
}
msg->type = MAC_MSG_TYPE_PHY;
msg->id = MAC_MSG_ID_CHANNEL_TEST_STOP;
mac_queue_msg(msg, MAC_MSG_QUEUE_HP);
out:
return ret;
}
static uint32_t mac_ada_dump_done( uint8_t *addr, uint32_t len,
int8_t gain, iot_phy_chn_dump_report_t *dump_info)
{
iot_pkt_t *pkt = iot_ipc_pkt_alloc(IOT_ADA_DUMP_MSG_PKT_SIZE,
PLC_MAC_COMMON_MID);
if (pkt == NULL) {
IOT_ASSERT(0);
return ERR_FAIL;
}
iot_channel_test_msg *msg = (iot_channel_test_msg*)iot_pkt_data(pkt);
iot_phy_chn_dump_result *result = (iot_phy_chn_dump_result*)&msg->data[0];
/* msg_id and cfg data */
IOT_ASSERT(iot_pkt_put(pkt, sizeof(iot_phy_chn_dump_result) + \
sizeof(msg->msg_id)) != NULL);
msg->msg_id = IOT_CHANNEL_DUMP_TEST_DONE;
result->len = len;
result->start_ptr = addr;
result->gain = gain;
if (dump_info == NULL) {
result->report.params.trig_offset = 0;
} else {
result->report.params.trig_offset = dump_info->params.trig_offset;
result->report.params.dump_rst = dump_info->params.dump_rst;
result->report.params.max_pwr = dump_info->params.max_pwr;
}
iot_ipc_send(chan_tool.ada_ipc_h, &chan_tool.ada_ipc_addr, pkt);
/* recover sw-agc for mm mode */
phy_swagc_set(true);
mac_channel_test_end();
return ERR_OK;
}
static void iot_mac_ipc_recv_for_ada(void *param, iot_ipc_addr_t *addr,
iot_pkt_t *pkt)
{
(void)addr;
(void)param;
IOT_ASSERT(pkt != NULL);
iot_channel_test_msg *msg = (iot_channel_test_msg*)iot_pkt_data(pkt);
switch (msg->msg_id) {
case IOT_CHANNEL_DUMP_TEST_START:
if (chan_tool.chan_test_flag == 0) {
chan_tool.chan_test_flag = 1;
mac_channel_dump_start(pkt);
} else {
iot_pkt_free(pkt);
}
break;
case IOT_CHANNEL_TEST_END:
iot_pkt_free(pkt);
mac_channel_test_end();
break;
default:
IOT_ASSERT(0);
break;
}
}
static void iot_mac_ipc_init_for_ada()
{
if (chan_tool.ada_ipc_h == NULL) {
iot_ipc_client_t client;
/* register ipc to communicate with cli */
client.addr.f_id = IOT_IPC_FID_ADA;
client.addr.c_id = IOT_IPC_CID_ADA_MAC;
client.recv = iot_mac_ipc_recv_for_ada;
client.param = NULL;
chan_tool.ada_ipc_h = iot_ipc_register_client(&client);
}
chan_tool.chan_test_flag = 0;
chan_tool.ada_ipc_addr.c_id = IOT_IPC_CID_ADA_CLI;
chan_tool.ada_ipc_addr.f_id = IOT_IPC_FID_ADA;
}
void mac_channel_test_init()
{
iot_mac_ipc_init_for_ada();
iot_phy_chn_dump_cb_register(mac_ada_dump_done);
}
#endif