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


#include "ufcs.h"


/** 设置物理层状态标志 */
#define ufcs_phy_state_set(dev,val) \
    do { \
        ((UFCS_DEV_t *)(dev))->phy.state_prev = ((UFCS_DEV_t *)(dev))->phy.state; \
        if ((val) != ((UFCS_DEV_t *)(dev))->phy.state) { \
            ((UFCS_DEV_t *)(dev))->phy.state = val; \
            ((UFCS_DEV_t *)(dev))->phy.configured_flag = 0; \
        } \
    } while(0)

/** 获取物理层状态标志 */
#define ufcs_phy_state_get(dev) \
    (((UFCS_DEV_t *)(dev))->phy.state)

/** 获取物理层前一次的状态标志 */
#define ufcs_phy_state_prev_get(dev) \
    (((UFCS_DEV_t *)(dev))->phy.state_prev)


/** 设置物理层发送引脚对应的GPIO */
#define ufcs_phy_tx_pin_set(dev,val) \
    do { \
        ((UFCS_DEV_t *)(dev))->phy.tx_pin = val; \
    } while(0)

/** 获取物理层发送引脚对应的GPIO */
#define ufcs_phy_tx_pin_get(dev) \
    (((UFCS_DEV_t *)(dev))->phy.tx_pin)

/** 设置物理层接收引脚对应的GPIO */
#define ufcs_phy_rx_pin_set(dev,val) \
    do { \
        ((UFCS_DEV_t *)(dev))->phy.rx_pin = val; \
    } while(0)

/** 获取物理层接收引脚对应的GPIO */
#define ufcs_phy_rx_pin_get(dev) \
    (((UFCS_DEV_t *)(dev))->phy.rx_pin)

/** 设置物理层波特率 */
#define ufcs_phy_baudrate_set(dev,val) \
    do { \
        if ((val) != ((UFCS_DEV_t *)(dev))->phy.baudrate) { \
            ((UFCS_DEV_t *)(dev))->phy.baudrate_prev = ((UFCS_DEV_t *)(dev))->phy.baudrate; \
            ((UFCS_DEV_t *)(dev))->phy.baudrate = val; \
            ((UFCS_DEV_t *)(dev))->phy.configured_flag = 0; \
        } \
    } while(0)

/** 获取物理层波特率 */
#define ufcs_phy_baudrate_get(dev) \
    (((UFCS_DEV_t *)(dev))->phy.baudrate)

/** 获取物理层前一次的波特率 */
#define ufcs_phy_baudrate_prev_get(dev) \
    (((UFCS_DEV_t *)(dev))->phy.baudrate_prev)

/**
 * @description:    UFCS 物理层初始化
 * @param *dev      设备指针
 * @return void
 */
void ufcs_phy_init(UFCS_DEV_t *dev);

/**
 * @description:    UFCS 物理层配置，每次调用ufcs_phy_state_set或ufcs_phy_baudrate_set后应该调用这个接口
 * @param dev_ptr   设备指针
 * @return void
 */
void ufcs_phy_config(u32_t dev_ptr);

/**
 * @description:    UFCS获取物理层接口电压值
 * @param dev_ptr   设备指针
 * @param type      物理接口类型，请看UFCS_PHY_INTF_t定义
 * @return u32_t    返回电压值，单位为毫伏
 */
u32_t ufcs_phy_volt_get(UFCS_DEV_t *dev, UFCS_PHY_INTF_t type);

#endif /* #ifndef __UFCS_PHY_H_ */

