mikroSDK Reference Manual
lan8742_driver.h
Go to the documentation of this file.
1
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//LAN8742 MMD registers
69#define LAN8742_PCS_MMD_DEV_PRES1 0x03, 0x0005
70#define LAN8742_PCS_MMD_DEV_PRES2 0x03, 0x0006
71#define LAN8742_WUCSR 0x03, 0x8010
72#define LAN8742_WUF_CFGA 0x03, 0x8011
73#define LAN8742_WUF_CFGB 0x03, 0x8012
74#define LAN8742_WUF_MASK 0x03, 0x8021
75#define LAN8742_RX_ADDRA 0x03, 0x8061
76#define LAN8742_RX_ADDRB 0x03, 0x8062
77#define LAN8742_RX_ADDRC 0x03, 0x8063
78#define LAN8742_MCFGR 0x03, 0x8064
79#define LAN8742_VENDOR_SPECIFIC_MMD1_DEV_ID1 0x1E, 0x0002
80#define LAN8742_VENDOR_SPECIFIC_MMD1_DEV_ID2 0x1E, 0x0003
81#define LAN8742_VENDOR_SPECIFIC_MMD1_DEV_PRES1 0x1E, 0x0005
82#define LAN8742_VENDOR_SPECIFIC_MMD1_DEV_PRES2 0x1E, 0x0006
83#define LAN8742_VENDOR_SPECIFIC_MMD1_STAT 0x1E, 0x0008
84#define LAN8742_TDR_MATCH_THRESHOLD 0x1E, 0x000B
85#define LAN8742_TDR_SHORT_OPEN_THRESHOLD 0x1E, 0x000C
86#define LAN8742_VENDOR_SPECIFIC_MMD1_PKG_ID1 0x1E, 0x000E
87#define LAN8742_VENDOR_SPECIFIC_MMD1_PKG_ID2 0x1E, 0x000F
88
89//Basic Control register
90#define LAN8742_BMCR_RESET 0x8000
91#define LAN8742_BMCR_LOOPBACK 0x4000
92#define LAN8742_BMCR_SPEED_SEL 0x2000
93#define LAN8742_BMCR_AN_EN 0x1000
94#define LAN8742_BMCR_POWER_DOWN 0x0800
95#define LAN8742_BMCR_ISOLATE 0x0400
96#define LAN8742_BMCR_RESTART_AN 0x0200
97#define LAN8742_BMCR_DUPLEX_MODE 0x0100
98
99//Basic Status register
100#define LAN8742_BMSR_100BT4 0x8000
101#define LAN8742_BMSR_100BTX_FD 0x4000
102#define LAN8742_BMSR_100BTX_HD 0x2000
103#define LAN8742_BMSR_10BT_FD 0x1000
104#define LAN8742_BMSR_10BT_HD 0x0800
105#define LAN8742_BMSR_100BT2_FD 0x0400
106#define LAN8742_BMSR_100BT2_HD 0x0200
107#define LAN8742_BMSR_EXTENDED_STATUS 0x0100
108#define LAN8742_BMSR_AN_COMPLETE 0x0020
109#define LAN8742_BMSR_REMOTE_FAULT 0x0010
110#define LAN8742_BMSR_AN_CAPABLE 0x0008
111#define LAN8742_BMSR_LINK_STATUS 0x0004
112#define LAN8742_BMSR_JABBER_DETECT 0x0002
113#define LAN8742_BMSR_EXTENDED_CAPABLE 0x0001
114
115//PHY Identifier 1 register
116#define LAN8742_PHYID1_PHY_ID_MSB 0xFFFF
117#define LAN8742_PHYID1_PHY_ID_MSB_DEFAULT 0x0007
118
119//PHY Identifier 2 register
120#define LAN8742_PHYID2_PHY_ID_LSB 0xFC00
121#define LAN8742_PHYID2_PHY_ID_LSB_DEFAULT 0xC000
122#define LAN8742_PHYID2_MODEL_NUM 0x03F0
123#define LAN8742_PHYID2_MODEL_NUM_DEFAULT 0x0130
124#define LAN8742_PHYID2_REVISION_NUM 0x000F
125
126//Auto-Negotiation Advertisement register
127#define LAN8742_ANAR_NEXT_PAGE 0x8000
128#define LAN8742_ANAR_REMOTE_FAULT 0x2000
129#define LAN8742_ANAR_PAUSE 0x0C00
130#define LAN8742_ANAR_100BTX_FD 0x0100
131#define LAN8742_ANAR_100BTX_HD 0x0080
132#define LAN8742_ANAR_10BT_FD 0x0040
133#define LAN8742_ANAR_10BT_HD 0x0020
134#define LAN8742_ANAR_SELECTOR 0x001F
135#define LAN8742_ANAR_SELECTOR_DEFAULT 0x0001
136
137//Auto-Negotiation Link Partner Ability register
138#define LAN8742_ANLPAR_NEXT_PAGE 0x8000
139#define LAN8742_ANLPAR_ACK 0x4000
140#define LAN8742_ANLPAR_REMOTE_FAULT 0x2000
141#define LAN8742_ANLPAR_PAUSE 0x0400
142#define LAN8742_ANLPAR_100BT4 0x0200
143#define LAN8742_ANLPAR_100BTX_FD 0x0100
144#define LAN8742_ANLPAR_100BTX_HD 0x0080
145#define LAN8742_ANLPAR_10BT_FD 0x0040
146#define LAN8742_ANLPAR_10BT_HD 0x0020
147#define LAN8742_ANLPAR_SELECTOR 0x001F
148#define LAN8742_ANLPAR_SELECTOR_DEFAULT 0x0001
149
150//Auto-Negotiation Expansion register
151#define LAN8742_ANER_RECEIVE_NP_LOC_ABLE 0x0040
152#define LAN8742_ANER_RECEIVE_NP_STOR_LOC 0x0020
153#define LAN8742_ANER_PAR_DETECT_FAULT 0x0010
154#define LAN8742_ANER_LP_NEXT_PAGE_ABLE 0x0008
155#define LAN8742_ANER_NEXT_PAGE_ABLE 0x0004
156#define LAN8742_ANER_PAGE_RECEIVED 0x0002
157#define LAN8742_ANER_LP_AN_ABLE 0x0001
158
159//Auto Negotiation Next Page TX register
160#define LAN8742_ANNPR_NEXT_PAGE 0x8000
161#define LAN8742_ANNPR_MSG_PAGE 0x2000
162#define LAN8742_ANNPR_ACK2 0x1000
163#define LAN8742_ANNPR_TOGGLE 0x0800
164#define LAN8742_ANNPR_MESSAGE 0x07FF
165
166//Auto Negotiation Next Page RX register
167#define LAN8742_ANLPNPR_NEXT_PAGE 0x8000
168#define LAN8742_ANLPNPR_ACK 0x4000
169#define LAN8742_ANLPNPR_MSG_PAGE 0x2000
170#define LAN8742_ANLPNPR_ACK2 0x1000
171#define LAN8742_ANLPNPR_TOGGLE 0x0800
172#define LAN8742_ANLPNPR_MESSAGE 0x07FF
173
174//MMD Access Control register
175#define LAN8742_MMDACR_FUNC 0xC000
176#define LAN8742_MMDACR_FUNC_ADDR 0x0000
177#define LAN8742_MMDACR_FUNC_DATA_NO_POST_INC 0x4000
178#define LAN8742_MMDACR_DEVAD 0x001F
179
180//EDPD NLP/Crossover Time Configuration register
181#define LAN8742_ENCTR_EDPD_TX_NLP_EN 0x8000
182#define LAN8742_ENCTR_EDPD_TX_NLP_ITS 0x6000
183#define LAN8742_ENCTR_EDPD_RX_NLP_WAKE_EN 0x1000
184#define LAN8742_ENCTR_EDPD_RX_NLP_MIDS 0x0C00
185#define LAN8742_ENCTR_EDPD_EXT_CROSSOVER 0x0002
186#define LAN8742_ENCTR_EXT_CROSSOVER_TIME 0x0001
187
188//Mode Control/Status register
189#define LAN8742_MCSR_EDPWRDOWN 0x2000
190#define LAN8742_MCSR_FARLOOPBACK 0x0200
191#define LAN8742_MCSR_ALTINT 0x0040
192#define LAN8742_MCSR_ENERGYON 0x0002
193
194//Special Modes register
195#define LAN8742_SMR_MODE 0x00E0
196#define LAN8742_SMR_PHYAD 0x001F
197
198//TDR Patterns/Delay Control register
199#define LAN8742_TDRPDCR_DELAY_IN 0x8000
200#define LAN8742_TDRPDCR_LINE_BREAK_COUNT 0x7000
201#define LAN8742_TDRPDCR_PATTERN_HIGH 0x0FC0
202#define LAN8742_TDRPDCR_PATTERN_LOW 0x003F
203
204//TDR Control/Status register
205#define LAN8742_TDRCSR_TDR_EN 0x8000
206#define LAN8742_TDRCSR_AD_FILTER_EN 0x4000
207#define LAN8742_TDRCSR_CH_CABLE_TYPE 0x0600
208#define LAN8742_TDRCSR_CH_STATUS 0x0100
209#define LAN8742_TDRCSR_CH_LENGTH 0x00FF
210
211//Symbol Error Counter register
212#define LAN8742_SECR_SYM_ERR_CNT 0xFFFF
213
214//Special Control/Status Indication register
215#define LAN8742_SCSIR_AMDIXCTRL 0x8000
216#define LAN8742_SCSIR_CH_SELECT 0x2000
217#define LAN8742_SCSIR_SQEOFF 0x0800
218#define LAN8742_SCSIR_XPOL 0x0010
219
220//Cable Length register
221#define LAN8742_CLR_CBLN 0xF000
222
223//Interrupt Source Flag register
224#define LAN8742_ISR_WOL 0x0100
225#define LAN8742_ISR_ENERGYON 0x0080
226#define LAN8742_ISR_AN_COMPLETE 0x0040
227#define LAN8742_ISR_REMOTE_FAULT 0x0020
228#define LAN8742_ISR_LINK_DOWN 0x0010
229#define LAN8742_ISR_AN_LP_ACK 0x0008
230#define LAN8742_ISR_PAR_DETECT_FAULT 0x0004
231#define LAN8742_ISR_AN_PAGE_RECEIVED 0x0002
232
233//Interrupt Mask register
234#define LAN8742_IMR_WOL 0x0100
235#define LAN8742_IMR_ENERGYON 0x0080
236#define LAN8742_IMR_AN_COMPLETE 0x0040
237#define LAN8742_IMR_REMOTE_FAULT 0x0020
238#define LAN8742_IMR_LINK_DOWN 0x0010
239#define LAN8742_IMR_AN_LP_ACK 0x0008
240#define LAN8742_IMR_PAR_DETECT_FAULT 0x0004
241#define LAN8742_IMR_AN_PAGE_RECEIVED 0x0002
242
243//PHY Special Control/Status register
244#define LAN8742_PSCSR_AUTODONE 0x1000
245#define LAN8742_PSCSR_HCDSPEED 0x001C
246#define LAN8742_PSCSR_HCDSPEED_10BT_HD 0x0004
247#define LAN8742_PSCSR_HCDSPEED_100BTX_HD 0x0008
248#define LAN8742_PSCSR_HCDSPEED_10BT_FD 0x0014
249#define LAN8742_PSCSR_HCDSPEED_100BTX_FD 0x0018
250
251//C++ guard
252#ifdef __cplusplus
253extern "C" {
254#endif
255
256//LAN8742 Ethernet PHY driver
257extern const PhyDriver lan8742PhyDriver;
258
259//LAN8742 related functions
260error_t lan8742Init(NetInterface *interface);
261void lan8742InitHook(NetInterface *interface);
262
263void lan8742Tick(NetInterface *interface);
264
265void lan8742EnableIrq(NetInterface *interface);
266void lan8742DisableIrq(NetInterface *interface);
267
268void lan8742EventHandler(NetInterface *interface);
269
270void lan8742WritePhyReg(NetInterface *interface, uint8_t address,
271 uint16_t data);
272
273uint16_t lan8742ReadPhyReg(NetInterface *interface, uint8_t address);
274
275void lan8742DumpPhyReg(NetInterface *interface);
276
277void lan8742WriteMmdReg(NetInterface *interface, uint8_t devAddr,
278 uint16_t regAddr, uint16_t data);
279
280uint16_t lan8742ReadMmdReg(NetInterface *interface, uint8_t devAddr,
281 uint16_t regAddr);
282
283//C++ guard
284#ifdef __cplusplus
285}
286#endif
287
288#endif
error_t
Error codes.
Definition error.h:43
Network interface controller abstraction layer.
Ethernet PHY driver.
Definition nic.h:308