Embedded TCP/IP stack  4.7.0
fnet_eth.h
1 /**************************************************************************
2 *
3 * Copyright 2008-2018 by Andrey Butok. FNET Community.
4 *
5 ***************************************************************************
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may
8 * not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 ***************************************************************************
20 *
21 * Ethernet platform independent API definitions.
22 *
23 ***************************************************************************/
24 
25 #ifndef _FNET_ETH_H_
26 
27 #define _FNET_ETH_H_
28 
29 /**************************************************************************
30 * Definitions
31 ***************************************************************************/
32 
37 /**************************************************************************/
45 #define FNET_MAC_ADDR_STR_SIZE (18)
46 
47 /**************************************************************************/
52 #define FNET_ETH_MTU (1500u)
53 
54 /**************************************************************************/
57 typedef fnet_uint8_t fnet_mac_addr_t[6]; /* MAC address type.*/
58 
59 /**************************************************************************/
70 #define FNET_MAC_ADDR_INIT(a, b, c, d, e, f) { (a), (b), (c), (d), (e), (f) }
71 
72 /* MAC address is multicast. */
73 #define FNET_MAC_ADDR_IS_MULTICAST(a) ((((a)[0]) == 0x01U)?FNET_TRUE:FNET_FALSE)
74 
75 /* MAC address is broadcast. */
76 #define FNET_MAC_ADDR_IS_BROADCAST(a) (((((a)[0]) == 0xFFU) && \
77  (((a)[1]) == 0xFFU)&& \
78  (((a)[1]) == 0xFFU)&& \
79  (((a)[1]) == 0xFFU)&& \
80  (((a)[1]) == 0xFFU)&& \
81  (((a)[1]) == 0xFFU))? FNET_TRUE:FNET_FALSE)
82 /* Copying address. */
83 #define FNET_MAC_ADDR_COPY(from_addr, to_addr) \
84  (fnet_memcpy(&to_addr[0], &from_addr[0], sizeof(fnet_mac_addr_t)))
85 
86 /* Useful mac addresses */
87 extern const fnet_mac_addr_t fnet_eth_null_addr;
88 extern const fnet_mac_addr_t fnet_eth_broadcast;
89 
90 /************************************************************************
91 * IEEE802.3 PHY MII management register set
92 *************************************************************************/
93 #define FNET_ETH_MII_REG_CR (0x0000U) /* Control Register */
94 #define FNET_ETH_MII_REG_SR (0x0001U) /* Status Register */
95 #define FNET_ETH_MII_REG_IDR1 (0x0002U) /* Identification Register #1 */
96 #define FNET_ETH_MII_REG_IDR2 (0x0003U) /* Identification Register #2 */
97 #define FNET_ETH_MII_REG_ANAR (0x0004U) /* Auto-Negotiation Advertisement Register */
98 #define FNET_ETH_MII_REG_ANLPAR (0x0005U) /* Auto-Negotiation Link Partner Ability Register */
99 #define FNET_ETH_MII_REG_ANER (0x0006U) /* Auto-Negotiation Expansion Register */
100 #define FNET_ETH_MII_REG_ANNPTR (0x0007U) /* Auto-Negotiation Next Page TX Register */
101 
102 /* Status Register flags*/
103 #define FNET_ETH_MII_REG_SR_LINK_STATUS (0x0004U)
104 #define FNET_ETH_MII_REG_SR_AN_ABILITY (0x0008U)
105 #define FNET_ETH_MII_REG_SR_AN_COMPLETE (0x0020U)
106 
107 /* Control Register flags*/
108 #define FNET_ETH_MII_REG_CR_RESET (0x8000U) /* Resetting a port is accomplished by setting this bit to 1.*/
109 #define FNET_ETH_MII_REG_CR_LOOPBACK (0x4000U) /* Determines Digital Loopback Mode. */
110 #define FNET_ETH_MII_REG_CR_DATARATE (0x2000U) /* Speed Selection bit.*/
111 #define FNET_ETH_MII_REG_CR_ANE (0x1000U) /* Auto-Negotiation Enable bit. */
112 #define FNET_ETH_MII_REG_CR_PDWN (0x0800U) /* Power Down bit. */
113 #define FNET_ETH_MII_REG_CR_ISOL (0x0400U) /* Isolate bit.*/
114 #define FNET_ETH_MII_REG_CR_ANE_RESTART (0x0200U) /* Restart Auto-Negotiation bit.*/
115 #define FNET_ETH_MII_REG_CR_DPLX (0x0100U) /* Duplex Mode bit.*/
116 
117 /* Auto-Negotiation Advertisement Register flags*/
118 #define FNET_ETH_MII_REG_ANAR_100_FULLDUPLEX (0x0100U) /* 100 Mbps full-duplex capable.*/
119 #define FNET_ETH_MII_REG_ANAR_100_HALFDUPLEX (0x0080U) /* 100 Mbps half-duplex capable.*/
120 #define FNET_ETH_MII_REG_ANAR_10_FULLDUPLEX (0x0040U) /* 10 Mbps full-duplex capable.*/
121 #define FNET_ETH_MII_REG_ANAR_10_HALFDUPLEX (0x0020U) /* 10 Mbps half-duplex capable.*/
122 #define FNET_ETH_MII_REG_ANAR_IEEE8023 (0x0001U) /* IEEE 802.3 */
123 
124 
125 /******************************************************************************
126 * Function Prototypes
127 *******************************************************************************/
128 
129 #if defined(__cplusplus)
130 extern "C" {
131 #endif
132 
133 /***************************************************************************/
155 fnet_char_t *fnet_mac_to_str( const fnet_mac_addr_t addr, fnet_char_t *str_mac );
156 
157 /***************************************************************************/
181 
189 /***************************************************************************/
208 fnet_return_t fnet_eth_phy_read(fnet_netif_desc_t netif_desc, fnet_uint32_t reg_addr, fnet_uint16_t *reg_data);
209 
210 /***************************************************************************/
229 fnet_return_t fnet_eth_phy_write(fnet_netif_desc_t netif_desc, fnet_uint32_t reg_addr, fnet_uint16_t reg_data);
230 
231 /***************************************************************************/
246 fnet_uint8_t fnet_eth_phy_get_addr(fnet_netif_desc_t netif_desc);
247 
248 /***************************************************************************/
269 fnet_return_t fnet_eth_phy_set_addr(fnet_netif_desc_t netif_desc, fnet_uint8_t phy_addr );
270 
273 #if defined(__cplusplus)
274 }
275 #endif
276 
277 #endif /* _FNET_ETH_H_ */
fnet_return_t
General return codes, used by most of API functions.
Definition: fnet_stdlib.h:89
fnet_char_t * fnet_mac_to_str(const fnet_mac_addr_t addr, fnet_char_t *str_mac)
Converts a 6 byte MAC address into a null terminated string.
fnet_return_t fnet_eth_phy_read(fnet_netif_desc_t netif_desc, fnet_uint32_t reg_addr, fnet_uint16_t *reg_data)
Read a value from an Ethernet PHY's MII register.
fnet_return_t fnet_str_to_mac(const fnet_char_t *str_mac, fnet_mac_addr_t addr)
Converts a null terminated string to a 6 byte MAC address.
fnet_uint8_t fnet_eth_phy_get_addr(fnet_netif_desc_t netif_desc)
Get a PHY address number of the specified Ethernet interface.
fnet_return_t fnet_eth_phy_write(fnet_netif_desc_t netif_desc, fnet_uint32_t reg_addr, fnet_uint16_t reg_data)
Write Ethernet PHY's MII register.
fnet_return_t fnet_eth_phy_set_addr(fnet_netif_desc_t netif_desc, fnet_uint8_t phy_addr)
Set the PHY address number of the specified Ethernet interface.
char fnet_char_t
Type representing the charecter.
Definition: fnet_stdlib.h:75
void * fnet_netif_desc_t
Network interface descriptor.
Definition: fnet_netif.h:68
fnet_uint8_t fnet_mac_addr_t[6]
Media Access Control (MAC) address type.
Definition: fnet_eth.h:57

© 2005-2020 by Andrej Butok. http://fnet.sourceforge.net