Files
kunlun/plc/halmac/hw/zc/mac_zc_hw.c
2024-09-28 14:24:04 +08:00

103 lines
3.8 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 "mac_sys_reg.h"
#include "hw_reg_api.h"
#include "os_types.h"
#include "os_mem_api.h"
#include "plc_protocol.h"
#include "iot_config_api.h"
#include "iot_io_api.h"
#include "mac_zc_hw.h"
#include "gpio_mtx_reg.h"
#include "gpio_mtx.h"
#include "hw_zc_cmn.h"
void mac_zc_hw_logic_sel(uint8_t chip_hw_logic_id)
{
(void)chip_hw_logic_id;
}
/* WAR: sw trigger gen cap for reset */
void mac_zc_hw_capx_reset_trig(uint8_t signal_id, uint8_t cap_edge)
{
#if (HW_PLATFORM >= HW_PLATFORM_FPGA) //gpio drive not check simulator
uint32_t cap_depth;
/* backup reg setting */
cap_depth = mac_zc_hw_cap_get_watermark();
/* set zc int num 0 for zc save ptr reset */
mac_zc_hw_cap_set_watermark(0);
uint32_t reg = CFG_SIG0_IN_CFG_ADDR + (signal_id << 2);
if (MAC_ZC_HW_CAP_EDGE_RISE == cap_edge) {
/* set signal input: low -> high to reset cap */
gpio_mtx_sig_in_set_def(reg, MTX_HW_SIG_SEL_INPUT_LOW);
gpio_mtx_sig_in_set_def(reg, MTX_HW_SIG_SEL_INPUT_HIGH);
} else {
/* set signal input: high -> low to reset cap */
gpio_mtx_sig_in_set_def(reg, MTX_HW_SIG_SEL_INPUT_HIGH);
gpio_mtx_sig_in_set_def(reg, MTX_HW_SIG_SEL_INPUT_LOW);
}
gpio_mtx_sig_in_set_def(reg, MTX_HW_SIG_SEL_INPUT_ZC);
/* restore mac zc int num config */
mac_zc_hw_cap_set_watermark((uint8_t)cap_depth);
#else
(void)signal_id;
(void)cap_edge;
#endif
}
uint32_t mac_zc_hw_get_cap_data(uint32_t *buf, uint8_t cap_id, uint32_t buf_sz)
{
#if (HW_PLATFORM >= HW_PLATFORM_FPGA)
IOT_ASSERT(buf && cap_id < MAC_ZC_HW_CAP_CNT && buf_sz > 0);
os_mem_cpy(buf, mac_zc_hw_get_ts_base_addr(cap_id), buf_sz);
return buf_sz;
#else
(void)buf;
(void)cap_id;
(void)buf_sz;
return 0;
#endif
}
/* init zc hw */
void mac_zc_hw_init(uint8_t is_half_collect, uint8_t cap_edge)
{
/* choose use KL1's zc block */
mac_zc_hw_logic_sel(MAC_ZC_HW_LOGIC_KL1);
/* set mac zc hw capture period: half or full period capture */
mac_zc_hw_cap_set_period(is_half_collect);
/* set mac zc hw capture edge: rise or fall edge capture */
mac_zc_hw_cap_set_edge(cap_edge);
/* set mac zc hw N+1 period interval capture zc timestamp */
/* set 0 to let sample every period (0+1=1) */
mac_zc_hw_cap_set_interval(0);
/* set mac zc hw N+1 cnt capture generate interrupt */
mac_zc_hw_cap_set_watermark(MAC_ZC_HW_INT_NUM_MAX);
/* set mac zc hw gen offset. not offset */
mac_zc_hw_gen_set_offset(0, MAC_ZC_HW_GEN_OFFSET_RIGHT);
/* set mac zc hw ctrl vibrate protect duration ntb */
mac_zc_hw_set_vibrate_protect_dur(MAC_ZC_HW_VIBRATE_PROTECT_NTB);
/* set mac zc hw cap0 input select mtx: detect0 */
mac_zc_hw_gen_set_phase_sel_mtx(MAC_ZC_HW_DETECT0);
/* set mac zc hw gen period: half or full period */
mac_zc_hw_gen_set_ctrl_period(is_half_collect);
/* set mac zc hw gen duration */
mac_zc_hw_gen_set_ctrl_dur(MAC_ZC_HW_GEN_BOUND_DUR_NTB);
}