/**
  *****************************************************************************
  * @file    ufcs_prl.h
  * @author  Solution Team
  * @version V1.00
  * @date    28-February-2023
  * @brief   UFCS protocol layer
  *****************************************************************************
  * @attention 
  *  Copyright (c) 2017 - 2023 Unicmicro Co., Ltd. 
  *  All Rights Reserved. 
  *****************************************************************************
  */
 
#ifndef __UFCS_PRL_H_
#define __UFCS_PRL_H_


#include "types.h"
#include "ufcs.h"


/** 获取接收状态 */
#define ufcs_prl_rx_state_get(dev) \
    (((UFCS_DEV_t *)(dev))->prl.rx_state)

/** 获取前一次的接收状态 */
#define ufcs_prl_rx_state_prev_get(dev) \
    (((UFCS_DEV_t *)(dev))->prl.rx_state_prev)

/** 设置接收状态 */
#define ufcs_prl_rx_state_set(dev,vL) \
    do { \
        if ((vL) != ((UFCS_DEV_t *)(dev))->prl.rx_state) { \
            ((UFCS_DEV_t *)(dev))->prl.rx_state_prev = ((UFCS_DEV_t *)(dev))->prl.rx_state; \
            ((UFCS_DEV_t *)(dev))->prl.rx_state = vL; \
        } \
    } while(0)

/** 接收消息编号清零 */
#define ufcs_prl_rx_msg_id_reset(dev) \
    do { \
        ((UFCS_DEV_t *)(dev))->prl.rx_msg_id = 0; \
        ((UFCS_DEV_t *)(dev))->prl.rx_msg_id_stored = 0; \
    } while(0)

/** 获取接收消息编号 */
#define ufcs_prl_rx_msg_id_get(dev) \
    (((UFCS_DEV_t *)(dev))->prl.rx_msg_id)

/** 获取接收消息编号存储标志 */
#define ufcs_prl_rx_msg_id_stored_get(dev) \
    (((UFCS_DEV_t *)(dev))->prl.rx_msg_id_stored)

/** 获取接收消息的命令 */
#define ufcs_prl_rx_command_get(dev) \
    (((UFCS_DEV_t *)(dev))->prl.rx_data[UFCS_MSG_CMD_OFFSET])

/** 获取发送状态 */
#define ufcs_prl_tx_state_get(dev) \
    (((UFCS_DEV_t *)(dev))->prl.tx_state)

/** 获取前一次的发送状态 */
#define ufcs_prl_tx_state_prev_get(dev) \
    (((UFCS_DEV_t *)(dev))->prl.tx_state_prev)

/** 设置发送状态 */
#define ufcs_prl_tx_state_set(dev,vL) \
    do { \
        if (vL != ((UFCS_DEV_t *)(dev))->prl.tx_state) { \
            ((UFCS_DEV_t *)(dev))->prl.tx_state_prev = ((UFCS_DEV_t *)(dev))->prl.tx_state; \
            ((UFCS_DEV_t *)(dev))->prl.tx_state = vL; \
        } \
    } while(0)

/** 获取发送消息编号 */
#define ufcs_prl_tx_msg_id_get(dev) \
    (((UFCS_DEV_t *)(dev))->prl.tx_msg_id)

/** 发送消息编号自加1 */
#define ufcs_prl_tx_msg_id_inc(dev) \
    do { \
        ((UFCS_DEV_t *)(dev))->prl.tx_msg_id++; \
    } while(0)

/** 发送消息编号清零 */
#define ufcs_prl_tx_msg_id_reset(dev) \
    do { \
        ((UFCS_DEV_t *)(dev))->prl.tx_msg_id = 0; \
    } while(0)

/** 获取发送消息命令 */
#define ufcs_prl_tx_command_get(dev) \
    (((UFCS_DEV_t *)(dev))->prl.tx_data[UFCS_MSG_CMD_OFFSET])

/** 获取来自策略控制引擎的发送消息请求 */
#define ufcs_prl_tx_msg_req_frm_pe_get(dev) \
    (((UFCS_DEV_t *)(dev))->prl.tx_msg_req_frm_pe)

/** 设置来自策略控制引擎的发送消息请求 */
#define ufcs_prl_tx_msg_req_frm_pe_set(dev,val) \
    do { \
        ((UFCS_DEV_t *)(dev))->prl.tx_msg_req_frm_pe = val; \
    } while(0)

/** 获取发送消息处理中标志 */
#define ufcs_prl_tx_msg_in_prog_get(dev) \
    (((UFCS_DEV_t *)(dev))->prl.tx_msg_in_prog)

/** 设置发送消息处理中标志 */
#define ufcs_prl_tx_msg_in_prog_set(dev,flg) \
    do { \
        ((UFCS_DEV_t *)(dev))->prl.tx_msg_in_prog = flg; \
    } while(0)

/** 获取硬件复位状态指示标志 */
#define ufcs_prl_hard_reset_ind_get(dev) \
    (((UFCS_DEV_t *)(dev))->prl.hard_reset_ind)

/** 设置硬件复位状态指示标志 */
#define ufcs_prl_hard_reset_ind_set(dev,flg) \
    do { \
        ((UFCS_DEV_t *)(dev))->prl.hard_reset_ind = flg; \
    } while(0)

/** 获取退出硬件复位状态标志 */
#define ufcs_prl_exit_from_hard_reset_get(dev) \
    (((UFCS_DEV_t *)(dev))->prl.exit_from_hard_reset)

/** 设置退出硬件复位状态标志 */
#define ufcs_prl_exit_from_hard_reset_set(dev,flg) \
    do { \
        ((UFCS_DEV_t *)(dev))->prl.exit_from_hard_reset = flg; \
    } while(0)

/** 获取硬件复位信号已发送标志 */
#define ufcs_prl_hard_reset_sent_get(dev) \
    (((UFCS_DEV_t *)(dev))->prl.hard_reset_sent)

/** 设置硬件复位信号已发送标志 */
#define ufcs_prl_hard_reset_sent_set(dev,flg) \
    do { \
        ((UFCS_DEV_t *)(dev))->prl.hard_reset_sent = flg; \
    } while(0)

/** 获取线缆复位信号指示标记标志 */
#define ufcs_prl_hr_cbl_rst_ind_get(dev) \
    (((UFCS_DEV_t *)(dev))->prl.hr_cbl_rst_ind)

/** 设置线缆复位信号指示标记标志 */
#define ufcs_prl_hr_cbl_rst_ind_set(dev,flg) \
    do { \
        ((UFCS_DEV_t *)(dev))->prl.hr_cbl_rst_ind = flg; \
    } while(0)

/** 获取协议层复位指示标志 */
#define ufcs_prl_reset_get(dev) \
    (((UFCS_DEV_t *)(dev))->prl.reset)

/** 设置协议层复位指示标志 */
#define ufcs_prl_reset_set(dev,flg) \
    do { \
        ((UFCS_DEV_t *)(dev))->prl.reset = flg; \
    } while(0)

/** 获取来自策略控制引擎的硬件复位请求标志 */
#define ufcs_prl_hrst_req_frm_pe_get(dev) \
    (((UFCS_DEV_t *)(dev))->prl.hrst_req_frm_pe)

/** 设置来自策略控制引擎的硬件复位请求标志 */
#define ufcs_prl_hrst_req_frm_pe_set(dev,flg) \
    do { \
        ((UFCS_DEV_t *)(dev))->prl.hrst_req_frm_pe = flg; \
    } while(0)

/** 获取来自策略控制引擎的硬件复位完成标志 */
#define ufcs_prl_hrst_cmplt_frm_pe_get(dev) \
    (((UFCS_DEV_t *)(dev))->prl.hrst_cmplt_frm_pe)

/** 设置来自策略控制引擎的硬件复位完成标志 */
#define ufcs_prl_hrst_cmplt_frm_pe_set(dev,flg) \
    do { \
        ((UFCS_DEV_t *)(dev))->prl.hrst_cmplt_frm_pe = flg; \
    } while(0)

/** 获取来自策略控制引擎的线缆复位请求标志 */
#define ufcs_prl_cbl_rst_req_frm_pe_get(dev) \
    (((UFCS_DEV_t *)(dev))->prl.cbl_rst_req_frm_pe)

/** 设置来自策略控制引擎的线缆复位请求标志 */
#define ufcs_prl_cbl_rst_req_frm_pe_set(dev,flg) \
    do { \
        ((UFCS_DEV_t *)(dev))->prl.cbl_rst_req_frm_pe = flg; \
    } while(0)

/** 获取来自策略控制引擎的线缆复位完成标志 */
#define ufcs_prl_cbl_rst_cmplt_frm_pe_get(dev) \
    (((UFCS_DEV_t *)(dev))->prl.cbl_rst_cmplt_frm_pe)

/** 设置来自策略控制引擎的线缆复位完成标志 */
#define ufcs_prl_cbl_rst_cmplt_frm_pe_set(dev,flg) \
    do { \
        ((UFCS_DEV_t *)(dev))->prl.cbl_rst_cmplt_frm_pe = flg; \
    } while(0)

/** 获取线缆复位已通知策略控制标志 */
#define ufcs_prl_pe_informed_cab_rst_get(dev) \
    (((UFCS_DEV_t *)(dev))->prl.pe_informed_cab_rst)

/** 设置线缆复位已通知策略控制标志 */
#define ufcs_prl_pe_informed_cab_rst_set(dev,flg) \
    do { \
        ((UFCS_DEV_t *)(dev))->prl.pe_informed_cab_rst = flg; \
    } while(0)

/** 获取硬件复位已通知策略控制标志 */
#define ufcs_prl_pe_informed_hrst_get(dev) \
    (((UFCS_DEV_t *)(dev))->prl.pe_informed_hrst)

/** 设置硬件复位已通知策略控制标志 */
#define ufcs_prl_pe_informed_hrst_set(dev,flg) \
    do { \
        ((UFCS_DEV_t *)(dev))->prl.pe_informed_hrst = flg; \
    } while(0)

/** 获取消息发送到线缆错误标志 */
#define ufcs_prl_tx_msg2cbl_err_get(dev) \
    (((UFCS_DEV_t *)(dev))->prl.tx_msg2cbl_err)

/** 清除消息发送到线缆错误标志 */
#define ufcs_prl_tx_msg2cbl_err_clear(dev) \
    do { \
        ((UFCS_DEV_t *)(dev))->prl.tx_msg2cbl_err = FALSE; \
    } while(0)

/** 获取消息发送错误标志 */
#define ufcs_prl_tx_msg_err_get(dev) \
    (((UFCS_DEV_t *)(dev))->prl.tx_msg_err)

/** 清除消息发送错误标志 */
#define ufcs_prl_tx_msg_err_clear(dev) \
    do { \
        ((UFCS_DEV_t *)(dev))->prl.tx_msg_err = FALSE; \
    } while(0)

/** 获取发送消息类型标志 */
#define ufcs_prl_tx_msg_type_get(dev) \
    (((UFCS_DEV_t *)(dev))->prl.tx_msg_type)

/** 设置发送消息类型标志 */
#define ufcs_prl_tx_msg_type_set(dev,flg) \
    do { \
        ((UFCS_DEV_t *)(dev))->prl.tx_msg_type = flg; \
    } while(0)

/** 获取消息发送已发送指示标志 */
#define ufcs_prl_tx_msg_sent_ind_get(dev) \
    (((UFCS_DEV_t *)(dev))->prl.tx_msg_sent_ind)

/** 设置消息发送已发送指示标志 */
#define ufcs_prl_tx_msg_sent_ind_set(dev,flg) \
    do { \
        ((UFCS_DEV_t *)(dev))->prl.tx_msg_sent_ind = flg; \
    } while(0)

/** 获取协议层复位完成标志 */
#define ufcs_prl_reset_complete_get(dev) \
    (((UFCS_DEV_t *)(dev))->prl.reset_complete)

/** 设置协议层复位完成标志 */
#define ufcs_prl_reset_complete_set(dev,flg) \
    do { \
        ((UFCS_DEV_t *)(dev))->prl.reset_complete = flg; \
    } while(0)

/** 设置接收到物理层的硬件复位信号标志 */
#define ufcs_prl_hard_reset_sig_frm_phy_set(dev,flg) \
    do { \
        ((UFCS_DEV_t *)(dev))->prl.hard_reset_sig_frm_phy = flg; \
    } while(0)

/** 获取接收到物理层的硬件复位信号标志 */
#define ufcs_prl_hard_reset_sig_frm_phy_get(dev) \
    (((UFCS_DEV_t *)(dev))->prl.hard_reset_sig_frm_phy)

/** 设置接收到物理层的线缆复位信号标志 */
#define ufcs_prl_cable_reset_sig_frm_phy_set(dev,flg) \
    do { \
        ((UFCS_DEV_t *)(dev))->prl.cable_reset_sig_frm_phy = flg; \
    } while(0)

/** 获取接收到物理层的线缆复位信号标志 */
#define ufcs_prl_cable_reset_sig_frm_phy_get(dev) \
    (((UFCS_DEV_t *)(dev))->prl.cable_reset_sig_frm_phy)\


/** 获取消息发送已发送指示标志 */
#define ufcs_prl_rx_msg_ind_get(dev) \
    (((UFCS_DEV_t *)(dev))->prl.rx_msg_ind)

/** 设置消息发送已发送指示标志 */
#define ufcs_prl_rx_msg_ind_set(dev,flg) \
    do { \
        ((UFCS_DEV_t *)(dev))->prl.rx_msg_ind = flg; \
    } while(0)

/** 获取发送消息头指针 */
#define ufcs_prl_tx_msg_head_get(dev) \
    (((UFCS_DEV_t *)(dev))->prl.tx_head)

/** 获取接收消息头指针 */
#define ufcs_prl_rx_msg_head_get(dev) \
    (((UFCS_DEV_t *)(dev))->prl.rx_head)

/** 收到 PING 消息 */
#define ufcs_ping_msg_received(dev) \
    ((((UFCS_DEV_t *)(dev))->prl.rx_msg_ind) && ((((UFCS_DEV_t *)(dev))->prl.rx_msg_type) == UFCS_PRL_MSG_PING))

/** 收到 ACK 消息 */
#define ufcs_ack_msg_received(dev) \
    ((((UFCS_DEV_t *)(dev))->prl.rx_msg_ind) && ((((UFCS_DEV_t *)(dev))->prl.rx_msg_type) == UFCS_PRL_MSG_ACK))

/** 收到 NCK 消息 */
#define ufcs_nck_msg_received(dev) \
    ((((UFCS_DEV_t *)(dev))->prl.rx_msg_ind) && ((((UFCS_DEV_t *)(dev))->prl.rx_msg_type) == UFCS_PRL_MSG_NCK))

/** 收到 Accept 消息 */
#define ufcs_accept_msg_received(dev) \
    ((((UFCS_DEV_t *)(dev))->prl.rx_msg_ind) && ((((UFCS_DEV_t *)(dev))->prl.rx_msg_type) == UFCS_PRL_MSG_ACCEPT))

/** 收到 Soft Reset 消息 */
#define ufcs_soft_reset_msg_received(dev) \
    ((((UFCS_DEV_t *)(dev))->prl.rx_msg_ind) && ((((UFCS_DEV_t *)(dev))->prl.rx_msg_type) == UFCS_PRL_MSG_SOFT_RESET))

/** 收到 Power Ready 消息 */
#define ufcs_power_ready_msg_received(dev) \
    ((((UFCS_DEV_t *)(dev))->prl.rx_msg_ind) && ((((UFCS_DEV_t *)(dev))->prl.rx_msg_type) == UFCS_PRL_MSG_POWER_READY))

/** 收到 Get output cap 消息 */
#define ufcs_get_output_cap_msg_received(dev) \
    ((((UFCS_DEV_t *)(dev))->prl.rx_msg_ind) && ((((UFCS_DEV_t *)(dev))->prl.rx_msg_type) == UFCS_PRL_MSG_GET_OUTPUT_CAP))

/** 收到 Get src info 消息 */
#define ufcs_get_src_info_msg_received(dev) \
    ((((UFCS_DEV_t *)(dev))->prl.rx_msg_ind) && ((((UFCS_DEV_t *)(dev))->prl.rx_msg_type) == UFCS_PRL_MSG_GET_SRC_INFO))

/** 收到 Get snk info 消息 */
#define ufcs_get_snk_info_msg_received(dev) \
    ((((UFCS_DEV_t *)(dev))->prl.rx_msg_ind) && ((((UFCS_DEV_t *)(dev))->prl.rx_msg_type) == UFCS_PRL_MSG_GET_SNK_INFO))

/** 收到 Get cbl info 消息 */
#define ufcs_get_cbl_info_msg_received(dev) \
    ((((UFCS_DEV_t *)(dev))->prl.rx_msg_ind) && ((((UFCS_DEV_t *)(dev))->prl.rx_msg_type) == UFCS_PRL_MSG_GET_CBL_INFO))

/** 收到 Get dev info 消息 */
#define ufcs_get_dev_info_msg_received(dev) \
    ((((UFCS_DEV_t *)(dev))->prl.rx_msg_ind) && ((((UFCS_DEV_t *)(dev))->prl.rx_msg_type) == UFCS_PRL_MSG_GET_DEV_INFO))

/** 收到 Get err info 消息 */
#define ufcs_get_err_info_msg_received(dev) \
    ((((UFCS_DEV_t *)(dev))->prl.rx_msg_ind) && ((((UFCS_DEV_t *)(dev))->prl.rx_msg_type) == UFCS_PRL_MSG_GET_ERR_INFO))

/** 收到 Det cbl info 消息 */
#define ufcs_det_cbl_info_msg_received(dev) \
    ((((UFCS_DEV_t *)(dev))->prl.rx_msg_ind) && ((((UFCS_DEV_t *)(dev))->prl.rx_msg_type) == UFCS_PRL_MSG_DET_CBL_INFO))

/** 收到 Start cbl det 消息 */
#define ufcs_start_cbl_det_msg_received(dev) \
    ((((UFCS_DEV_t *)(dev))->prl.rx_msg_ind) && ((((UFCS_DEV_t *)(dev))->prl.rx_msg_type) == UFCS_PRL_MSG_START_CBL_DET))

/** 收到 End cbl det 消息 */
#define ufcs_end_cbl_det_msg_received(dev) \
    ((((UFCS_DEV_t *)(dev))->prl.rx_msg_ind) && ((((UFCS_DEV_t *)(dev))->prl.rx_msg_type) == UFCS_PRL_MSG_END_CBL_DET))

/** 收到 Exit UFCS mode 消息 */
#define ufcs_exit_msg_received(dev) \
    ((((UFCS_DEV_t *)(dev))->prl.rx_msg_ind) && ((((UFCS_DEV_t *)(dev))->prl.rx_msg_type) == UFCS_PRL_MSG_EXIT_UFCS_MODE))

/** 收到 output cap 消息 */
#define ufcs_output_cap_msg_received(dev) \
    ((((UFCS_DEV_t *)(dev))->prl.rx_msg_ind) && ((((UFCS_DEV_t *)(dev))->prl.rx_msg_type) == UFCS_PRL_MSG_OUTPUT_CAP))

/** 收到 request 消息 */
#define ufcs_request_msg_received(dev) \
    ((((UFCS_DEV_t *)(dev))->prl.rx_msg_ind) && ((((UFCS_DEV_t *)(dev))->prl.rx_msg_type) == UFCS_PRL_MSG_REQUEST))

/** 收到 src info 消息 */
#define ufcs_src_info_msg_received(dev) \
    ((((UFCS_DEV_t *)(dev))->prl.rx_msg_ind) && ((((UFCS_DEV_t *)(dev))->prl.rx_msg_type) == UFCS_PRL_MSG_SRC_INFO))

/** 收到 snk info 消息 */
#define ufcs_snk_info_msg_received(dev) \
    ((((UFCS_DEV_t *)(dev))->prl.rx_msg_ind) && ((((UFCS_DEV_t *)(dev))->prl.rx_msg_type) == UFCS_PRL_MSG_SNK_INFO))

/** 收到 cbl info 消息 */
#define ufcs_cbl_info_msg_received(dev) \
    ((((UFCS_DEV_t *)(dev))->prl.rx_msg_ind) && ((((UFCS_DEV_t *)(dev))->prl.rx_msg_type) == UFCS_PRL_MSG_CBL_INFO))

/** 收到 dev info 消息 */
#define ufcs_dev_info_msg_received(dev) \
    ((((UFCS_DEV_t *)(dev))->prl.rx_msg_ind) && ((((UFCS_DEV_t *)(dev))->prl.rx_msg_type) == UFCS_PRL_MSG_DEV_INFO))

/** 收到 err info 消息 */
#define ufcs_err_info_msg_received(dev) \
    ((((UFCS_DEV_t *)(dev))->prl.rx_msg_ind) && ((((UFCS_DEV_t *)(dev))->prl.rx_msg_type) == UFCS_PRL_MSG_ERR_INFO))

/** 收到 配置消息 消息 */
#define ufcs_cfg_wdt_msg_received(dev) \
    ((((UFCS_DEV_t *)(dev))->prl.rx_msg_ind) && ((((UFCS_DEV_t *)(dev))->prl.rx_msg_type) == UFCS_PRL_MSG_CFG_WDT))

/** 收到 Refuse 消息 */
#define ufcs_refuse_msg_received(dev) \
    ((((UFCS_DEV_t *)(dev))->prl.rx_msg_ind) && ((((UFCS_DEV_t *)(dev))->prl.rx_msg_type) == UFCS_PRL_MSG_REFUSE))

/** 收到 Verify req 消息 */
#define ufcs_verify_req_msg_received(dev) \
    ((((UFCS_DEV_t *)(dev))->prl.rx_msg_ind) && ((((UFCS_DEV_t *)(dev))->prl.rx_msg_type) == UFCS_PRL_MSG_VERIFY_REQ))

/** 收到 Verify resp 消息 */
#define ufcs_verify_resp_msg_received(dev) \
    ((((UFCS_DEV_t *)(dev))->prl.rx_msg_ind) && ((((UFCS_DEV_t *)(dev))->prl.rx_msg_type) == UFCS_PRL_MSG_VERIFY_RESP))

/** 收到 Power change 消息 */
#define ufcs_power_change_msg_received(dev) \
    ((((UFCS_DEV_t *)(dev))->prl.rx_msg_ind) && ((((UFCS_DEV_t *)(dev))->prl.rx_msg_type) == UFCS_PRL_MSG_POWER_CHANGE))

/** 收到 Test req 消息 */
#define ufcs_test_req_msg_received(dev) \
    ((((UFCS_DEV_t *)(dev))->prl.rx_msg_ind) && ((((UFCS_DEV_t *)(dev))->prl.rx_msg_type) == UFCS_PRL_MSG_TEST_REQ))

/** 收到 自定义消息 消息 */
#define ufcs_custom_msg_received(dev) \
    ((((UFCS_DEV_t *)(dev))->prl.rx_msg_ind) && ((((UFCS_DEV_t *)(dev))->prl.rx_msg_type) == UFCS_PRL_MSG_CUSTOM))


/** 已发送 PING 消息 */
#define ufcs_ping_msg_sent(dev) \
    ((((UFCS_DEV_t *)(dev))->prl.tx_msg_sent_ind) && ((((UFCS_DEV_t *)(dev))->prl.tx_msg_type) == UFCS_PRL_MSG_PING))

/** 已发送 ACK 消息 */
#define ufcs_ack_msg_sent(dev) \
    ((((UFCS_DEV_t *)(dev))->prl.tx_msg_sent_ind) && ((((UFCS_DEV_t *)(dev))->prl.tx_msg_type) == UFCS_PRL_MSG_ACK))

/** 已发送 NCK 消息 */
#define ufcs_nck_msg_sent(dev) \
    ((((UFCS_DEV_t *)(dev))->prl.tx_msg_sent_ind) && ((((UFCS_DEV_t *)(dev))->prl.tx_msg_type) == UFCS_PRL_MSG_NCK))

/** 已发送 Accept 消息 */
#define ufcs_accept_msg_sent(dev) \
    ((((UFCS_DEV_t *)(dev))->prl.tx_msg_sent_ind) && ((((UFCS_DEV_t *)(dev))->prl.tx_msg_type) == UFCS_PRL_MSG_ACCEPT))

/** 已发送 Soft Reset 消息 */
#define ufcs_soft_reset_msg_sent(dev) \
    ((((UFCS_DEV_t *)(dev))->prl.tx_msg_sent_ind) && ((((UFCS_DEV_t *)(dev))->prl.tx_msg_type) == UFCS_PRL_MSG_SOFT_RESET))

/** 已发送 Power Ready 消息 */
#define ufcs_power_ready_msg_sent(dev) \
    ((((UFCS_DEV_t *)(dev))->prl.tx_msg_sent_ind) && ((((UFCS_DEV_t *)(dev))->prl.tx_msg_type) == UFCS_PRL_MSG_POWER_READY))

/** 已发送 Get output cap 消息 */
#define ufcs_get_output_cap_msg_sent(dev) \
    ((((UFCS_DEV_t *)(dev))->prl.tx_msg_sent_ind) && ((((UFCS_DEV_t *)(dev))->prl.tx_msg_type) == UFCS_PRL_MSG_GET_OUTPUT_CAP))

/** 已发送 Get src info 消息 */
#define ufcs_get_src_info_msg_sent(dev) \
    ((((UFCS_DEV_t *)(dev))->prl.tx_msg_sent_ind) && ((((UFCS_DEV_t *)(dev))->prl.tx_msg_type) == UFCS_PRL_MSG_GET_SRC_INFO))

/** 已发送 Get snk info 消息 */
#define ufcs_get_snk_info_msg_sent(dev) \
    ((((UFCS_DEV_t *)(dev))->prl.tx_msg_sent_ind) && ((((UFCS_DEV_t *)(dev))->prl.tx_msg_type) == UFCS_PRL_MSG_GET_SNK_INFO))

/** 已发送 Get cbl info 消息 */
#define ufcs_get_cbl_info_msg_sent(dev) \
    ((((UFCS_DEV_t *)(dev))->prl.tx_msg_sent_ind) && ((((UFCS_DEV_t *)(dev))->prl.tx_msg_type) == UFCS_PRL_MSG_GET_CBL_INFO))

/** 已发送 Get dev info 消息 */
#define ufcs_get_dev_info_msg_sent(dev) \
    ((((UFCS_DEV_t *)(dev))->prl.tx_msg_sent_ind) && ((((UFCS_DEV_t *)(dev))->prl.tx_msg_type) == UFCS_PRL_MSG_GET_DEV_INFO))

/** 已发送 Get err info 消息 */
#define ufcs_get_err_info_msg_sent(dev) \
    ((((UFCS_DEV_t *)(dev))->prl.tx_msg_sent_ind) && ((((UFCS_DEV_t *)(dev))->prl.tx_msg_type) == UFCS_PRL_MSG_GET_ERR_INFO))

/** 已发送 Det cbl info 消息 */
#define ufcs_det_cbl_info_msg_sent(dev) \
    ((((UFCS_DEV_t *)(dev))->prl.tx_msg_sent_ind) && ((((UFCS_DEV_t *)(dev))->prl.tx_msg_type) == UFCS_PRL_MSG_DET_CBL_INFO))

/** 已发送 Start cbl det 消息 */
#define ufcs_start_cbl_det_msg_sent(dev) \
    ((((UFCS_DEV_t *)(dev))->prl.tx_msg_sent_ind) && ((((UFCS_DEV_t *)(dev))->prl.tx_msg_type) == UFCS_PRL_MSG_START_CBL_DET))

/** 已发送 End cbl det 消息 */
#define ufcs_end_cbl_det_msg_sent(dev) \
    ((((UFCS_DEV_t *)(dev))->prl.tx_msg_sent_ind) && ((((UFCS_DEV_t *)(dev))->prl.tx_msg_type) == UFCS_PRL_MSG_END_CBL_DET))

/** 已发送 Exit UFCS mode 消息 */
#define ufcs_exit_ufcs_mode_msg_sent(dev) \
    ((((UFCS_DEV_t *)(dev))->prl.tx_msg_sent_ind) && ((((UFCS_DEV_t *)(dev))->prl.tx_msg_type) == UFCS_PRL_MSG_EXIT_UFCS_MODE))

/** 已发送 output cap 消息 */
#define ufcs_output_cap_msg_sent(dev) \
    ((((UFCS_DEV_t *)(dev))->prl.tx_msg_sent_ind) && ((((UFCS_DEV_t *)(dev))->prl.tx_msg_type) == UFCS_PRL_MSG_OUTPUT_CAP))

/** 已发送 request 消息 */
#define ufcs_request_msg_sent(dev) \
    ((((UFCS_DEV_t *)(dev))->prl.tx_msg_sent_ind) && ((((UFCS_DEV_t *)(dev))->prl.tx_msg_type) == UFCS_PRL_MSG_REQUEST))

/** 已发送 src info 消息 */
#define ufcs_src_info_msg_sent(dev) \
    ((((UFCS_DEV_t *)(dev))->prl.tx_msg_sent_ind) && ((((UFCS_DEV_t *)(dev))->prl.tx_msg_type) == UFCS_PRL_MSG_SRC_INFO))

/** 已发送 snk info 消息 */
#define ufcs_snk_info_msg_sent(dev) \
    ((((UFCS_DEV_t *)(dev))->prl.tx_msg_sent_ind) && ((((UFCS_DEV_t *)(dev))->prl.tx_msg_type) == UFCS_PRL_MSG_SNK_INFO))

/** 已发送 cbl info 消息 */
#define ufcs_cbl_info_msg_sent(dev) \
    ((((UFCS_DEV_t *)(dev))->prl.tx_msg_sent_ind) && ((((UFCS_DEV_t *)(dev))->prl.tx_msg_type) == UFCS_PRL_MSG_CBL_INFO))

/** 已发送 dev info 消息 */
#define ufcs_dev_info_msg_sent(dev) \
    ((((UFCS_DEV_t *)(dev))->prl.tx_msg_sent_ind) && ((((UFCS_DEV_t *)(dev))->prl.tx_msg_type) == UFCS_PRL_MSG_DEV_INFO))

/** 已发送 err info 消息 */
#define ufcs_err_info_msg_sent(dev) \
    ((((UFCS_DEV_t *)(dev))->prl.tx_msg_sent_ind) && ((((UFCS_DEV_t *)(dev))->prl.tx_msg_type) == UFCS_PRL_MSG_ERR_INFO))

/** 已发送 配置消息 消息 */
#define ufcs_cfg_wdt_msg_sent(dev) \
    ((((UFCS_DEV_t *)(dev))->prl.tx_msg_sent_ind) && ((((UFCS_DEV_t *)(dev))->prl.tx_msg_type) == UFCS_PRL_MSG_CFG_WDT))

/** 已发送 Refuse 消息 */
#define ufcs_refuse_msg_sent(dev) \
    ((((UFCS_DEV_t *)(dev))->prl.tx_msg_sent_ind) && ((((UFCS_DEV_t *)(dev))->prl.tx_msg_type) == UFCS_PRL_MSG_REFUSE))

/** 已发送 Verify req 消息 */
#define ufcs_verify_req_msg_sent(dev) \
    ((((UFCS_DEV_t *)(dev))->prl.tx_msg_sent_ind) && ((((UFCS_DEV_t *)(dev))->prl.tx_msg_type) == UFCS_PRL_MSG_VERIFY_REQ))

/** 已发送 Verify resp 消息 */
#define ufcs_verify_resp_msg_sent(dev) \
    ((((UFCS_DEV_t *)(dev))->prl.tx_msg_sent_ind) && ((((UFCS_DEV_t *)(dev))->prl.tx_msg_type) == UFCS_PRL_MSG_VERIFY_RESP))

/** 已发送 Power change 消息 */
#define ufcs_power_change_msg_sent(dev) \
    ((((UFCS_DEV_t *)(dev))->prl.tx_msg_sent_ind) && ((((UFCS_DEV_t *)(dev))->prl.tx_msg_type) == UFCS_PRL_MSG_POWER_CHANGE))

/** 已发送 Test req 消息 */
#define ufcs_test_req_msg_sent(dev) \
    ((((UFCS_DEV_t *)(dev))->prl.tx_msg_sent_ind) && ((((UFCS_DEV_t *)(dev))->prl.tx_msg_type) == UFCS_PRL_MSG_TEST_REQ))

/** 已发送 自定义消息 消息 */
#define ufcs_custom_msg_sent(dev) \
    ((((UFCS_DEV_t *)(dev))->prl.tx_msg_sent_ind) && ((((UFCS_DEV_t *)(dev))->prl.tx_msg_type) == UFCS_PRL_MSG_CUSTOM))


void ufcs_prl_state_init(UFCS_DEV_t *dev);
void ufcs_prl_tx_msg_send(UFCS_DEV_t *dev);
void ufcs_prl_tx_state_machine(UFCS_DEV_t *dev);
void ufcs_prl_rx_state_machine(UFCS_DEV_t *dev);

void ufcs_prl_msg_rx(UFCS_DEV_t *dev);
void ufcs_prl_msg_tx(UFCS_DEV_t *dev, u32_t tx_msg_type, u32_t dev_type);

#if (UFCS_DEBUG_ENABLED)
extern const char * const dev_type_str[UFCS_DEV_TYPE_END];
#endif

#endif /* #ifndef __UFCS_PRL_H_ */

