Files
2024-09-28 14:24:04 +08:00

107 lines
3.3 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.
****************************************************************************/
#ifndef _VP_UART_H_
#define _VP_UART_H_
#include "os_types.h"
#include "vc_task.h"
#include "iot_uart_h.h"
/**
* @brief vp_uart_id_e - List of virtual uart ports.
* VP_UART_PORTID0 - VC_CHNID_1 (ACM0)
* VP_UART_PORTID1 - VC_CHNID_2 (ACM1)
*/
typedef enum _virtual_port_uart_id_e_ {
VP_UART_PORTID0 = 0,
VP_UART_PORTID1,
VP_UART_PORTID_MAX
} vp_uart_id_e;
/**
* @brief UART_VP_PORT_END - Define vp logic port to phy port.
*/
#define vp_uart_lport_to_pport(lport) iot_uart_lport_to_pport(lport)
/**
* @brief UART_VP_PORT_END - Define vp logic port to phy port.
*/
#define vp_uart_pport_to_lport(lport) \
iot_uart_pport_to_lport(UART_TYPE_VP, lport)
/**
* @brief vp_uart_port_valid - Check if phy port is valid.
*/
#define vp_uart_port_valid(pport) \
((pport) == VP_UART_PORTID0 || (pport) == VP_UART_PORTID1)
/**
* @brief vp_uart_channel_valid - Check if channel is valid.
*/
#define vp_uart_channel_valid(channel) \
((channel) == VC_CHNID_1 || (channel) == VC_CHNID_2)
/**
* @brief vp_uart_port_to_channel - Convert the port number to channel number.
*/
#define vp_uart_port_to_channel(port) \
((port) == VP_UART_PORTID0 ? VC_CHNID_1 : VC_CHNID_2)
/**
* @brief vp_uart_channel_to_port - Convert the channel number to port number.
*/
#define vp_uart_channel_to_port(channel) \
((channel) == VC_CHNID_1 ? VP_UART_PORTID0 : VP_UART_PORTID1)
/**
* @brief vp_uart_rcv_func - Function pointer to get received data.
* @param port: Virtual uart port to open.
* @param pkt: Pointer to a packet holding receved data.
* @return Bytes of data that confirmed by this function.
*/
typedef uint32_t (*vp_uart_rcv_func)(uint8_t port, iot_pkt_t *pkt);
/**
* @brief vp_uart_t - Struct of vp uart.
* pport - phy port of the vp uart
* lport - logic port of the vp uart
* recv_func - recv func of the vp uart
*/
typedef struct _vp_uart_t {
uint8_t pport;
vp_uart_rcv_func recv_func;
}vp_uart_t;
/**
* @brief vp_uart_open - Open a virtual uart port.
* @param lport: Logic virtual uart port to open.
* @param rcv_func: Function pointer to receive data.
* @return -- Index of the vp uart.
*/
int vp_uart_open(uint8_t lport, vp_uart_rcv_func rcv_func);
/**
* @brief vp_uart_send - Send data to virtual uart port.
* @param lport: Logic vritual uart port to open.
* @param p_pkt: The pkt data to send.
* @return ERR_FAIL -- Operation failed.
* @return ERR_OK -- Operation Successful.
*/
uint32_t vp_uart_send(uint8_t lport, iot_pkt_t *p_pkt);
#endif /* _VP_UART_H_ */