eth.h
Go to the documentation of this file.
00001 00043 #ifndef DRV_ETH_H 00044 #define DRV_ETH_H 00045 00046 #include "hw/hw_eth.h" 00047 #include "cfg/cfg_eth.h" 00048 00049 #include <drv/phy.h> 00050 00051 #include <cpu/types.h> 00052 00053 00054 #define ETH_ADDR_LEN 6 00055 #define ETH_HEAD_LEN 14 00056 #define ETH_DATA_LEN 1500 00057 #define ETH_FRAME_LEN (ETH_HEAD_LEN + ETH_DATA_LEN) 00058 #define ETH_TYPE_IP 0x0800 00059 00060 typedef union Ethernet 00061 { 00062 struct 00063 { 00064 uint8_t dst[ETH_ADDR_LEN]; 00065 uint8_t src[ETH_ADDR_LEN]; 00066 uint16_t type; 00067 uint8_t data[0]; 00068 }; 00069 uint8_t raw[ETH_FRAME_LEN]; 00070 } PACKED Ethernet; 00071 00075 INLINE int eth_addrIsZero(const uint8_t *addr) 00076 { 00077 return !(addr[0] | addr[1] | addr[2] | 00078 addr[3] | addr[4] | addr[5]); 00079 } 00080 00084 INLINE int eth_addrIsMcast(const uint8_t *addr) 00085 { 00086 return (0x01 & addr[0]); 00087 } 00088 00092 INLINE int eth_addrIsLocal(const uint8_t *addr) 00093 { 00094 return (0x02 & addr[0]); 00095 } 00096 00100 INLINE bool eth_addrIsBcast(const uint8_t *addr) 00101 { 00102 return (addr[0] & addr[1] & addr[2] & 00103 addr[3] & addr[4] & addr[5]) == 0xff; 00104 } 00105 00110 INLINE bool eth_addrIsValid(const uint8_t *addr) 00111 { 00112 return !eth_addrIsMcast(addr) && !eth_addrIsZero(addr); 00113 } 00114 00118 INLINE bool eth_addrCmp(const uint8_t *addr1, const uint8_t *addr2) 00119 { 00120 return !!((addr1[0] ^ addr2[0]) | 00121 (addr1[1] ^ addr2[1]) | 00122 (addr1[2] ^ addr2[2]) | 00123 (addr1[3] ^ addr2[3]) | 00124 (addr1[4] ^ addr2[4]) | 00125 (addr1[5] ^ addr2[5])); 00126 } 00127 00128 ssize_t eth_putFrame(const uint8_t *buf, size_t len); 00129 void eth_sendFrame(void); 00130 00131 size_t eth_getFrameLen(void); 00132 ssize_t eth_getFrame(uint8_t *buf, size_t len); 00133 00134 ssize_t eth_send(const uint8_t *buf, size_t len); 00135 ssize_t eth_recv(uint8_t *buf, size_t len); 00136 00137 int eth_init(void); 00138 00139 #endif /* DRV_ETH_H */
![(please configure the [header_logo] section in trac.ini)](/chrome/site/bertos_logo.png)