120 lines
		
	
	
		
			3.9 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			120 lines
		
	
	
		
			3.9 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_ETH_H_
 | |
| #define _VP_ETH_H_
 | |
| 
 | |
| #include "os_types.h"
 | |
| #include "vc_task.h"
 | |
| 
 | |
| /**
 | |
|  * @brief vp_eth_id_e - List of virtual eth ports.
 | |
|  * VP_ETH_PORTID0 - VC_CHNID_3 (ECM0)
 | |
|  */
 | |
| typedef enum _virtual_port_eth_id_e_ {
 | |
|     VP_ETH_PORTID0  = 0,
 | |
|     VP_ETH_PORTID_MAX
 | |
| } vp_eth_id_e;
 | |
| 
 | |
| /**
 | |
|  * @brief vp_eth_port_valid - Check if port is valid.
 | |
|  */
 | |
| #define vp_eth_port_valid(port) \
 | |
|     ((port) == VP_ETH_PORTID0)
 | |
| 
 | |
| /**
 | |
|  * @brief vp_eth_channel_valid - Check if channel is valid.
 | |
|  */
 | |
| #define vp_eth_channel_valid(channel)   \
 | |
|     ((channel) == VC_CHNID_3)
 | |
| 
 | |
| /**
 | |
|  * @brief vp_eth_port_to_channel - Convert the port number to channel number.
 | |
|  */
 | |
| #define vp_eth_port_to_channel(port)   \
 | |
|     ((port) == VP_ETH_PORTID0 ? VC_CHNID_3 : VC_CHNID_3)
 | |
| 
 | |
| /**
 | |
|  * @brief vp_eth_channel_to_port - Convert the channel number to port number.
 | |
|  */
 | |
| #define vp_eth_channel_to_port(channel)    \
 | |
|     ((channel) == VC_CHNID_3 : VP_ETH_PORTID0 : VP_ETH_PORTID0)
 | |
| 
 | |
| /**
 | |
|  * @brief vp_eth_filter_e - List the filter mode of virtual eth ports.
 | |
|  */
 | |
| typedef enum _virtual_port_eth_packet_filter_e_ {
 | |
|     VP_ETH_FT_UNICAST       = 1,
 | |
|     VP_ETH_FT_BROADCAST     = 2,
 | |
|     VP_ETH_FT_MULTICAST     = 4,
 | |
|     VP_ETH_FT_PROMISCUOUS   = 8
 | |
| } vp_eth_filter_e;
 | |
| 
 | |
| /**
 | |
|  * @brief vp_eth_rcv_func - Function pointer to get received data.
 | |
|  * @param p_buf: Pointer of a buffer holding receved data.
 | |
|  * @param len: Length of buffer.
 | |
|  * @return Bytes of data that confirmed by this function.
 | |
|  */
 | |
| typedef uint32_t (*vp_eth_rcv_func)(vp_eth_id_e port, uint8_t *p_buf, uint32_t len);
 | |
| 
 | |
| /**
 | |
|  * @brief vp_eth_open - Open a virtual uart port.
 | |
|  * @param port: Virtual eth port to open.
 | |
|  * @param p_func: Function pointer to receive data.
 | |
|  * @return ERR_FAIL -- Operation failed.
 | |
|  * @return ERR_OK -- Operation Successful.
 | |
|  */
 | |
| uint32_t vp_eth_open(vp_eth_id_e port, vp_eth_rcv_func p_func);
 | |
| 
 | |
| /**
 | |
|  * @brief vp_eth_send - Send data to the virtual eth port.
 | |
|  * @param port: Virtual eth port to send data.
 | |
|  * @param p_buf: Pointer of a buffer holding data to send.
 | |
|  * @param len: Length of buffer.
 | |
|  * @return Bytes of data that sent.
 | |
|  */
 | |
| uint32_t vp_eth_send(vp_eth_id_e port, uint8_t *p_buf, uint32_t len);
 | |
| 
 | |
| /**
 | |
|  * @brief vp_eth_set_mac - Set mac address of this port.
 | |
|  * @param port: Virtual eth port to set mac address.
 | |
|  * @param p_mac: Six bytes of mac address to set.
 | |
|  * @return ERR_FAIL -- Operation failed.
 | |
|  * @return ERR_OK -- Operation Successful.
 | |
|  */
 | |
| uint32_t vp_eth_set_mac(vp_eth_id_e port, uint8_t* p_mac);
 | |
| 
 | |
| /**
 | |
|  * @brief vp_eth_set_mac - Set mac address of this port.
 | |
|  * @param port: Virtual eth port to reset filter.
 | |
|  * @param filter: Bitmap of filter. Unicast and broadcast enabled by default.
 | |
|  * @return ERR_FAIL -- Operation failed.
 | |
|  * @return ERR_OK -- Operation Successful.
 | |
|  */
 | |
| uint32_t vp_eth_set_filter(vp_eth_id_e port, uint32_t filter);
 | |
| 
 | |
| /**
 | |
|  * @brief vp_eth_set_linkup - Set linkup of this port.
 | |
|  * @param port: Virtual eth port to set linkup.
 | |
|  * @param linkup: 0 - shutdown this port, else - linkup this port.
 | |
|  * @return ERR_FAIL -- Operation failed.
 | |
|  * @return ERR_OK -- Operation Successful.
 | |
|  */
 | |
| uint32_t vp_eth_set_linkup(vp_eth_id_e port, uint32_t linkup);
 | |
| 
 | |
| #endif /* _VP_ETH_H_ */
 | |
| 
 |