lan8742_driver.h
Go to the documentation of this file.
1 /**
2  * @file lan8742_driver.h
3  * @brief LAN8742 Ethernet PHY transceiver
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2019 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneTCP Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 1.9.6
29  **/
30 
31 #ifndef _LAN8742_DRIVER_H
32 #define _LAN8742_DRIVER_H
33 
34 //Dependencies
35 #include "core/nic.h"
36 
37 //PHY address
38 #ifndef LAN8742_PHY_ADDR
39  #define LAN8742_PHY_ADDR 0
40 #elif (LAN8742_PHY_ADDR < 0 || LAN8742_PHY_ADDR > 31)
41  #error LAN8742_PHY_ADDR parameter is not valid
42 #endif
43 
44 //LAN8742 PHY registers
45 #define LAN8742_BMCR 0x00
46 #define LAN8742_BMSR 0x01
47 #define LAN8742_PHYID1 0x02
48 #define LAN8742_PHYID2 0x03
49 #define LAN8742_ANAR 0x04
50 #define LAN8742_ANLPAR 0x05
51 #define LAN8742_ANER 0x06
52 #define LAN8742_ANNPR 0x07
53 #define LAN8742_ANLPNPR 0x08
54 #define LAN8742_MMDACR 0x0D
55 #define LAN8742_MMDAADR 0x0E
56 #define LAN8742_ENCTR 0x10
57 #define LAN8742_MCSR 0x11
58 #define LAN8742_SMR 0x12
59 #define LAN8742_TDRPDCR 0x18
60 #define LAN8742_TDRCSR 0x19
61 #define LAN8742_SECR 0x1A
62 #define LAN8742_SCSIR 0x1B
63 #define LAN8742_CLR 0x1C
64 #define LAN8742_ISR 0x1D
65 #define LAN8742_IMR 0x1E
66 #define LAN8742_PSCSR 0x1F
67 
68 //Basic Control register
69 #define LAN8742_BMCR_RESET 0x8000
70 #define LAN8742_BMCR_LOOPBACK 0x4000
71 #define LAN8742_BMCR_SPEED_SEL 0x2000
72 #define LAN8742_BMCR_AN_EN 0x1000
73 #define LAN8742_BMCR_POWER_DOWN 0x0800
74 #define LAN8742_BMCR_ISOLATE 0x0400
75 #define LAN8742_BMCR_RESTART_AN 0x0200
76 #define LAN8742_BMCR_DUPLEX_MODE 0x0100
77 
78 //Basic Status register
79 #define LAN8742_BMSR_100BT4 0x8000
80 #define LAN8742_BMSR_100BTX_FD 0x4000
81 #define LAN8742_BMSR_100BTX_HD 0x2000
82 #define LAN8742_BMSR_10BT_FD 0x1000
83 #define LAN8742_BMSR_10BT_HD 0x0800
84 #define LAN8742_BMSR_100BT2_FD 0x0400
85 #define LAN8742_BMSR_100BT2_HD 0x0200
86 #define LAN8742_BMSR_EXTENDED_STATUS 0x0100
87 #define LAN8742_BMSR_AN_COMPLETE 0x0020
88 #define LAN8742_BMSR_REMOTE_FAULT 0x0010
89 #define LAN8742_BMSR_AN_CAPABLE 0x0008
90 #define LAN8742_BMSR_LINK_STATUS 0x0004
91 #define LAN8742_BMSR_JABBER_DETECT 0x0002
92 #define LAN8742_BMSR_EXTENDED_CAPABLE 0x0001
93 
94 //PHY Identifier 1 register
95 #define LAN8742_PHYID1_PHY_ID_MSB 0xFFFF
96 #define LAN8742_PHYID1_PHY_ID_MSB_DEFAULT 0x0007
97 
98 //PHY Identifier 2 register
99 #define LAN8742_PHYID2_PHY_ID_LSB 0xFC00
100 #define LAN8742_PHYID2_PHY_ID_LSB_DEFAULT 0xC000
101 #define LAN8742_PHYID2_MODEL_NUM 0x03F0
102 #define LAN8742_PHYID2_MODEL_NUM_DEFAULT 0x0130
103 #define LAN8742_PHYID2_REVISION_NUM 0x000F
104 
105 //Auto-Negotiation Advertisement register
106 #define LAN8742_ANAR_NEXT_PAGE 0x8000
107 #define LAN8742_ANAR_REMOTE_FAULT 0x2000
108 #define LAN8742_ANAR_PAUSE 0x0C00
109 #define LAN8742_ANAR_100BTX_FD 0x0100
110 #define LAN8742_ANAR_100BTX_HD 0x0080
111 #define LAN8742_ANAR_10BT_FD 0x0040
112 #define LAN8742_ANAR_10BT_HD 0x0020
113 #define LAN8742_ANAR_SELECTOR 0x001F
114 #define LAN8742_ANAR_SELECTOR_DEFAULT 0x0001
115 
116 //Auto-Negotiation Link Partner Ability register
117 #define LAN8742_ANLPAR_NEXT_PAGE 0x8000
118 #define LAN8742_ANLPAR_ACK 0x4000
119 #define LAN8742_ANLPAR_REMOTE_FAULT 0x2000
120 #define LAN8742_ANLPAR_PAUSE 0x0400
121 #define LAN8742_ANLPAR_100BT4 0x0200
122 #define LAN8742_ANLPAR_100BTX_FD 0x0100
123 #define LAN8742_ANLPAR_100BTX_HD 0x0080
124 #define LAN8742_ANLPAR_10BT_FD 0x0040
125 #define LAN8742_ANLPAR_10BT_HD 0x0020
126 #define LAN8742_ANLPAR_SELECTOR 0x001F
127 #define LAN8742_ANLPAR_SELECTOR_DEFAULT 0x0001
128 
129 //Auto-Negotiation Expansion register
130 #define LAN8742_ANER_RECEIVE_NP_LOC_ABLE 0x0040
131 #define LAN8742_ANER_RECEIVE_NP_STOR_LOC 0x0020
132 #define LAN8742_ANER_PAR_DETECT_FAULT 0x0010
133 #define LAN8742_ANER_LP_NEXT_PAGE_ABLE 0x0008
134 #define LAN8742_ANER_NEXT_PAGE_ABLE 0x0004
135 #define LAN8742_ANER_PAGE_RECEIVED 0x0002
136 #define LAN8742_ANER_LP_AN_ABLE 0x0001
137 
138 //Auto Negotiation Next Page TX register
139 #define LAN8742_ANNPR_NEXT_PAGE 0x8000
140 #define LAN8742_ANNPR_MSG_PAGE 0x2000
141 #define LAN8742_ANNPR_ACK2 0x1000
142 #define LAN8742_ANNPR_TOGGLE 0x0800
143 #define LAN8742_ANNPR_MESSAGE 0x07FF
144 
145 //Auto Negotiation Next Page RX register
146 #define LAN8742_ANLPNPR_NEXT_PAGE 0x8000
147 #define LAN8742_ANLPNPR_ACK 0x4000
148 #define LAN8742_ANLPNPR_MSG_PAGE 0x2000
149 #define LAN8742_ANLPNPR_ACK2 0x1000
150 #define LAN8742_ANLPNPR_TOGGLE 0x0800
151 #define LAN8742_ANLPNPR_MESSAGE 0x07FF
152 
153 //MMD Access Control register
154 #define LAN8742_MMDACR_FUNC 0xC000
155 #define LAN8742_MMDACR_FUNC_ADDR 0x0000
156 #define LAN8742_MMDACR_FUNC_DATA_NO_POST_INC 0x4000
157 #define LAN8742_MMDACR_DEVAD 0x001F
158 
159 //EDPD NLP/Crossover Time Configuration register
160 #define LAN8742_ENCTR_EDPD_TX_NLP_EN 0x8000
161 #define LAN8742_ENCTR_EDPD_TX_NLP_ITS 0x6000
162 #define LAN8742_ENCTR_EDPD_RX_NLP_WAKE_EN 0x1000
163 #define LAN8742_ENCTR_EDPD_RX_NLP_MIDS 0x0C00
164 #define LAN8742_ENCTR_EDPD_EXT_CROSSOVER 0x0002
165 #define LAN8742_ENCTR_EXT_CROSSOVER_TIME 0x0001
166 
167 //Mode Control/Status register
168 #define LAN8742_MCSR_EDPWRDOWN 0x2000
169 #define LAN8742_MCSR_FARLOOPBACK 0x0200
170 #define LAN8742_MCSR_ALTINT 0x0040
171 #define LAN8742_MCSR_ENERGYON 0x0002
172 
173 //Special Modes register
174 #define LAN8742_SMR_MODE 0x00E0
175 #define LAN8742_SMR_PHYAD 0x001F
176 
177 //TDR Patterns/Delay Control register
178 #define LAN8742_TDRPDCR_DELAY_IN 0x8000
179 #define LAN8742_TDRPDCR_LINE_BREAK_COUNT 0x7000
180 #define LAN8742_TDRPDCR_PATTERN_HIGH 0x0FC0
181 #define LAN8742_TDRPDCR_PATTERN_LOW 0x003F
182 
183 //TDR Control/Status register
184 #define LAN8742_TDRCSR_TDR_EN 0x8000
185 #define LAN8742_TDRCSR_AD_FILTER_EN 0x4000
186 #define LAN8742_TDRCSR_CH_CABLE_TYPE 0x0600
187 #define LAN8742_TDRCSR_CH_STATUS 0x0100
188 #define LAN8742_TDRCSR_CH_LENGTH 0x00FF
189 
190 //Symbol Error Counter register
191 #define LAN8742_SECR_SYM_ERR_CNT 0xFFFF
192 
193 //Special Control/Status Indication register
194 #define LAN8742_SCSIR_AMDIXCTRL 0x8000
195 #define LAN8742_SCSIR_CH_SELECT 0x2000
196 #define LAN8742_SCSIR_SQEOFF 0x0800
197 #define LAN8742_SCSIR_XPOL 0x0010
198 
199 //Cable Length register
200 #define LAN8742_CLR_CBLN 0xF000
201 
202 //Interrupt Source Flag register
203 #define LAN8742_ISR_WOL 0x0100
204 #define LAN8742_ISR_ENERGYON 0x0080
205 #define LAN8742_ISR_AN_COMPLETE 0x0040
206 #define LAN8742_ISR_REMOTE_FAULT 0x0020
207 #define LAN8742_ISR_LINK_DOWN 0x0010
208 #define LAN8742_ISR_AN_LP_ACK 0x0008
209 #define LAN8742_ISR_PAR_DETECT_FAULT 0x0004
210 #define LAN8742_ISR_AN_PAGE_RECEIVED 0x0002
211 
212 //Interrupt Mask register
213 #define LAN8742_IMR_WOL 0x0100
214 #define LAN8742_IMR_ENERGYON 0x0080
215 #define LAN8742_IMR_AN_COMPLETE 0x0040
216 #define LAN8742_IMR_REMOTE_FAULT 0x0020
217 #define LAN8742_IMR_LINK_DOWN 0x0010
218 #define LAN8742_IMR_AN_LP_ACK 0x0008
219 #define LAN8742_IMR_PAR_DETECT_FAULT 0x0004
220 #define LAN8742_IMR_AN_PAGE_RECEIVED 0x0002
221 
222 //PHY Special Control/Status register
223 #define LAN8742_PSCSR_AUTODONE 0x1000
224 #define LAN8742_PSCSR_HCDSPEED 0x001C
225 #define LAN8742_PSCSR_HCDSPEED_10BT_HD 0x0004
226 #define LAN8742_PSCSR_HCDSPEED_100BTX_HD 0x0008
227 #define LAN8742_PSCSR_HCDSPEED_10BT_FD 0x0014
228 #define LAN8742_PSCSR_HCDSPEED_100BTX_FD 0x0018
229 
230 //C++ guard
231 #ifdef __cplusplus
232 extern "C" {
233 #endif
234 
235 //LAN8742 Ethernet PHY driver
236 extern const PhyDriver lan8742PhyDriver;
237 
238 //LAN8742 related functions
239 error_t lan8742Init(NetInterface *interface);
240 
241 void lan8742Tick(NetInterface *interface);
242 
243 void lan8742EnableIrq(NetInterface *interface);
244 void lan8742DisableIrq(NetInterface *interface);
245 
246 void lan8742EventHandler(NetInterface *interface);
247 
248 void lan8742WritePhyReg(NetInterface *interface, uint8_t address,
249  uint16_t data);
250 
251 uint16_t lan8742ReadPhyReg(NetInterface *interface, uint8_t address);
252 
253 void lan8742DumpPhyReg(NetInterface *interface);
254 
255 //C++ guard
256 #ifdef __cplusplus
257 }
258 #endif
259 
260 #endif
const PhyDriver lan8742PhyDriver
LAN8742 Ethernet PHY driver.
void lan8742DisableIrq(NetInterface *interface)
Disable interrupts.
PHY driver.
Definition: nic.h:214
void lan8742EnableIrq(NetInterface *interface)
Enable interrupts.
void lan8742DumpPhyReg(NetInterface *interface)
Dump PHY registers for debugging purpose.
error_t
Error codes.
Definition: error.h:42
uint16_t lan8742ReadPhyReg(NetInterface *interface, uint8_t address)
Read PHY register.
#define NetInterface
Definition: net.h:36
void lan8742WritePhyReg(NetInterface *interface, uint8_t address, uint16_t data)
Write PHY register.
error_t lan8742Init(NetInterface *interface)
LAN8742 PHY transceiver initialization.
void lan8742EventHandler(NetInterface *interface)
LAN8742 event handler.
Network interface controller abstraction layer.
void lan8742Tick(NetInterface *interface)
LAN8742 timer handler.
Ipv6Addr address
uint8_t data[]
Definition: dtls_misc.h:176