mikroSDK Reference Manual
lan8740_driver.h
Go to the documentation of this file.
1
31#ifndef _LAN8740_DRIVER_H
32#define _LAN8740_DRIVER_H
33
34//Dependencies
35#include "core/nic.h"
36
37//PHY address
38#ifndef LAN8740_PHY_ADDR
39 #define LAN8740_PHY_ADDR 0
40#elif (LAN8740_PHY_ADDR < 0 || LAN8740_PHY_ADDR > 31)
41 #error LAN8740_PHY_ADDR parameter is not valid
42#endif
43
44//LAN8740 PHY registers
45#define LAN8740_BMCR 0x00
46#define LAN8740_BMSR 0x01
47#define LAN8740_PHYID1 0x02
48#define LAN8740_PHYID2 0x03
49#define LAN8740_ANAR 0x04
50#define LAN8740_ANLPAR 0x05
51#define LAN8740_ANER 0x06
52#define LAN8740_ANNPR 0x07
53#define LAN8740_ANLPNPR 0x08
54#define LAN8740_MMDACR 0x0D
55#define LAN8740_MMDAADR 0x0E
56#define LAN8740_ENCTECR 0x10
57#define LAN8740_MCSR 0x11
58#define LAN8740_SMR 0x12
59#define LAN8740_TDRPDCR 0x18
60#define LAN8740_TDRCSR 0x19
61#define LAN8740_SECR 0x1A
62#define LAN8740_SCSIR 0x1B
63#define LAN8740_CLR 0x1C
64#define LAN8740_ISR 0x1D
65#define LAN8740_IMR 0x1E
66#define LAN8740_PSCSR 0x1F
67
68//LAN8740 MMD registers
69#define LAN8740_PCS_CTRL1 0x03, 0x0000
70#define LAN8740_PCS_STAT1 0x03, 0x0001
71#define LAN8740_PCS_MMD_DEV_PRES1 0x03, 0x0005
72#define LAN8740_PCS_MMD_DEV_PRES2 0x03, 0x0006
73#define LAN8740_EEE_CAPABILITY 0x03, 0x0014
74#define LAN8740_EEE_WAKE_ERROR 0x03, 0x0016
75#define LAN8740_WUCSR 0x03, 0x8010
76#define LAN8740_WUF_CFGA 0x03, 0x8011
77#define LAN8740_WUF_CFGB 0x03, 0x8012
78#define LAN8740_WUF_MASK 0x03, 0x8021
79#define LAN8740_RX_ADDRA 0x03, 0x8061
80#define LAN8740_RX_ADDRB 0x03, 0x8062
81#define LAN8740_RX_ADDRC 0x03, 0x8063
82#define LAN8740_MCFGR 0x03, 0x8064
83#define LAN8740_AN_MMD_DEV_PRES1 0x07, 0x0005
84#define LAN8740_AN_MMD_DEV_PRES2 0x07, 0x0006
85#define LAN8740_EEE_ADV 0x07, 0x003C
86#define LAN8740_EEE_LP_ADV 0x07, 0x003D
87#define LAN8740_VENDOR_SPECIFIC_MMD1_DEV_ID1 0x1E, 0x0002
88#define LAN8740_VENDOR_SPECIFIC_MMD1_DEV_ID2 0x1E, 0x0003
89#define LAN8740_VENDOR_SPECIFIC_MMD1_DEV_PRES1 0x1E, 0x0005
90#define LAN8740_VENDOR_SPECIFIC_MMD1_DEV_PRES2 0x1E, 0x0006
91#define LAN8740_VENDOR_SPECIFIC_MMD1_STAT 0x1E, 0x0008
92#define LAN8740_TDR_MATCH_THRESHOLD 0x1E, 0x000B
93#define LAN8740_TDR_SHORT_OPEN_THRESHOLD 0x1E, 0x000C
94#define LAN8740_VENDOR_SPECIFIC_MMD1_PKG_ID1 0x1E, 0x000E
95#define LAN8740_VENDOR_SPECIFIC_MMD1_PKG_ID2 0x1E, 0x000F
96
97//Basic Control register
98#define LAN8740_BMCR_RESET 0x8000
99#define LAN8740_BMCR_LOOPBACK 0x4000
100#define LAN8740_BMCR_SPEED_SEL 0x2000
101#define LAN8740_BMCR_AN_EN 0x1000
102#define LAN8740_BMCR_POWER_DOWN 0x0800
103#define LAN8740_BMCR_ISOLATE 0x0400
104#define LAN8740_BMCR_RESTART_AN 0x0200
105#define LAN8740_BMCR_DUPLEX_MODE 0x0100
106#define LAN8740_BMCR_COL_TEST 0x0080
107
108//Basic Status register
109#define LAN8740_BMSR_100BT4 0x8000
110#define LAN8740_BMSR_100BTX_FD 0x4000
111#define LAN8740_BMSR_100BTX_HD 0x2000
112#define LAN8740_BMSR_10BT_FD 0x1000
113#define LAN8740_BMSR_10BT_HD 0x0800
114#define LAN8740_BMSR_100BT2_FD 0x0400
115#define LAN8740_BMSR_100BT2_HD 0x0200
116#define LAN8740_BMSR_EXTENDED_STATUS 0x0100
117#define LAN8740_BMSR_AN_COMPLETE 0x0020
118#define LAN8740_BMSR_REMOTE_FAULT 0x0010
119#define LAN8740_BMSR_AN_CAPABLE 0x0008
120#define LAN8740_BMSR_LINK_STATUS 0x0004
121#define LAN8740_BMSR_JABBER_DETECT 0x0002
122#define LAN8740_BMSR_EXTENDED_CAPABLE 0x0001
123
124//PHY Identifier 1 register
125#define LAN8740_PHYID1_PHY_ID_MSB 0xFFFF
126#define LAN8740_PHYID1_PHY_ID_MSB_DEFAULT 0x0007
127
128//PHY Identifier 2 register
129#define LAN8740_PHYID2_PHY_ID_LSB 0xFC00
130#define LAN8740_PHYID2_PHY_ID_LSB_DEFAULT 0xC000
131#define LAN8740_PHYID2_MODEL_NUM 0x03F0
132#define LAN8740_PHYID2_MODEL_NUM_DEFAULT 0x0110
133#define LAN8740_PHYID2_REVISION_NUM 0x000F
134
135//Auto-Negotiation Advertisement register
136#define LAN8740_ANAR_NEXT_PAGE 0x8000
137#define LAN8740_ANAR_REMOTE_FAULT 0x2000
138#define LAN8740_ANAR_PAUSE 0x0C00
139#define LAN8740_ANAR_100BTX_FD 0x0100
140#define LAN8740_ANAR_100BTX_HD 0x0080
141#define LAN8740_ANAR_10BT_FD 0x0040
142#define LAN8740_ANAR_10BT_HD 0x0020
143#define LAN8740_ANAR_SELECTOR 0x001F
144#define LAN8740_ANAR_SELECTOR_DEFAULT 0x0001
145
146//Auto-Negotiation Link Partner Ability register
147#define LAN8740_ANLPAR_NEXT_PAGE 0x8000
148#define LAN8740_ANLPAR_ACK 0x4000
149#define LAN8740_ANLPAR_REMOTE_FAULT 0x2000
150#define LAN8740_ANLPAR_PAUSE 0x0400
151#define LAN8740_ANLPAR_100BT4 0x0200
152#define LAN8740_ANLPAR_100BTX_FD 0x0100
153#define LAN8740_ANLPAR_100BTX_HD 0x0080
154#define LAN8740_ANLPAR_10BT_FD 0x0040
155#define LAN8740_ANLPAR_10BT_HD 0x0020
156#define LAN8740_ANLPAR_SELECTOR 0x001F
157#define LAN8740_ANLPAR_SELECTOR_DEFAULT 0x0001
158
159//Auto-Negotiation Expansion register
160#define LAN8740_ANER_RECEIVE_NP_LOC_ABLE 0x0040
161#define LAN8740_ANER_RECEIVE_NP_STOR_LOC 0x0020
162#define LAN8740_ANER_PAR_DETECT_FAULT 0x0010
163#define LAN8740_ANER_LP_NEXT_PAGE_ABLE 0x0008
164#define LAN8740_ANER_NEXT_PAGE_ABLE 0x0004
165#define LAN8740_ANER_PAGE_RECEIVED 0x0002
166#define LAN8740_ANER_LP_AN_ABLE 0x0001
167
168//Auto Negotiation Next Page TX register
169#define LAN8740_ANNPR_NEXT_PAGE 0x8000
170#define LAN8740_ANNPR_MSG_PAGE 0x2000
171#define LAN8740_ANNPR_ACK2 0x1000
172#define LAN8740_ANNPR_TOGGLE 0x0800
173#define LAN8740_ANNPR_MESSAGE 0x07FF
174
175//Auto Negotiation Next Page RX register
176#define LAN8740_ANLPNPR_NEXT_PAGE 0x8000
177#define LAN8740_ANLPNPR_ACK 0x4000
178#define LAN8740_ANLPNPR_MSG_PAGE 0x2000
179#define LAN8740_ANLPNPR_ACK2 0x1000
180#define LAN8740_ANLPNPR_TOGGLE 0x0800
181#define LAN8740_ANLPNPR_MESSAGE 0x07FF
182
183//MMD Access Control register
184#define LAN8740_MMDACR_FUNC 0xC000
185#define LAN8740_MMDACR_FUNC_ADDR 0x0000
186#define LAN8740_MMDACR_FUNC_DATA_NO_POST_INC 0x4000
187#define LAN8740_MMDACR_DEVAD 0x001F
188
189//EDPD NLP/Crossover Time/EEE Configuration register
190#define LAN8740_ENCTECR_EDPD_TX_NLP_EN 0x8000
191#define LAN8740_ENCTECR_EDPD_TX_NLP_ITS 0x6000
192#define LAN8740_ENCTECR_RX_NLP_WAKE_EN 0x1000
193#define LAN8740_ENCTECR_RX_NLP_MIDS 0x0C00
194#define LAN8740_ENCTECR_PHY_EEE_EN 0x0004
195#define LAN8740_ENCTECR_EDPD_EXT_CROSSOVER 0x0002
196#define LAN8740_ENCTECR_EXT_CROSSOVER_TIME 0x0001
197
198//Mode Control/Status register
199#define LAN8740_MCSR_EDPWRDOWN 0x2000
200#define LAN8740_MCSR_FARLOOPBACK 0x0200
201#define LAN8740_MCSR_ALTINT 0x0040
202#define LAN8740_MCSR_ENERGYON 0x0002
203
204//Special Modes register
205#define LAN8740_SMR_MIIMODE 0x4000
206#define LAN8740_SMR_MODE 0x00E0
207#define LAN8740_SMR_PHYAD 0x001F
208
209//TDR Patterns/Delay Control register
210#define LAN8740_TDRPDCR_DELAY_IN 0x8000
211#define LAN8740_TDRPDCR_LINE_BREAK_COUNT 0x7000
212#define LAN8740_TDRPDCR_PATTERN_HIGH 0x0FC0
213#define LAN8740_TDRPDCR_PATTERN_LOW 0x003F
214
215//TDR Control/Status register
216#define LAN8740_TDRCSR_TDR_EN 0x8000
217#define LAN8740_TDRCSR_AD_FILTER_EN 0x4000
218#define LAN8740_TDRCSR_CH_CABLE_TYPE 0x0600
219#define LAN8740_TDRCSR_CH_STATUS 0x0100
220#define LAN8740_TDRCSR_CH_LENGTH 0x00FF
221
222//Symbol Error Counter register
223#define LAN8740_SECR_SYM_ERR_CNT 0xFFFF
224
225//Special Control/Status Indication register
226#define LAN8740_SCSIR_AMDIXCTRL 0x8000
227#define LAN8740_SCSIR_CH_SELECT 0x2000
228#define LAN8740_SCSIR_SQEOFF 0x0800
229#define LAN8740_SCSIR_XPOL 0x0010
230
231//Cable Length register
232#define LAN8740_CLR_CBLN 0xF000
233
234//Interrupt Source Flag register
235#define LAN8740_ISR_WOL 0x0100
236#define LAN8740_ISR_ENERGYON 0x0080
237#define LAN8740_ISR_AN_COMPLETE 0x0040
238#define LAN8740_ISR_REMOTE_FAULT 0x0020
239#define LAN8740_ISR_LINK_DOWN 0x0010
240#define LAN8740_ISR_AN_LP_ACK 0x0008
241#define LAN8740_ISR_PAR_DETECT_FAULT 0x0004
242#define LAN8740_ISR_AN_PAGE_RECEIVED 0x0002
243
244//Interrupt Mask register
245#define LAN8740_IMR_WOL 0x0100
246#define LAN8740_IMR_ENERGYON 0x0080
247#define LAN8740_IMR_AN_COMPLETE 0x0040
248#define LAN8740_IMR_REMOTE_FAULT 0x0020
249#define LAN8740_IMR_LINK_DOWN 0x0010
250#define LAN8740_IMR_AN_LP_ACK 0x0008
251#define LAN8740_IMR_PAR_DETECT_FAULT 0x0004
252#define LAN8740_IMR_AN_PAGE_RECEIVED 0x0002
253
254//PHY Special Control/Status register
255#define LAN8740_PSCSR_AUTODONE 0x1000
256#define LAN8740_PSCSR_4B5B_EN 0x0040
257#define LAN8740_PSCSR_HCDSPEED 0x001C
258#define LAN8740_PSCSR_HCDSPEED_10BT_HD 0x0004
259#define LAN8740_PSCSR_HCDSPEED_100BTX_HD 0x0008
260#define LAN8740_PSCSR_HCDSPEED_10BT_FD 0x0014
261#define LAN8740_PSCSR_HCDSPEED_100BTX_FD 0x0018
262
263//C++ guard
264#ifdef __cplusplus
265extern "C" {
266#endif
267
268//LAN8740 Ethernet PHY driver
269extern const PhyDriver lan8740PhyDriver;
270
271//LAN8740 related functions
272error_t lan8740Init(NetInterface *interface);
273void lan8740InitHook(NetInterface *interface);
274
275void lan8740Tick(NetInterface *interface);
276
277void lan8740EnableIrq(NetInterface *interface);
278void lan8740DisableIrq(NetInterface *interface);
279
280void lan8740EventHandler(NetInterface *interface);
281
282void lan8740WritePhyReg(NetInterface *interface, uint8_t address,
283 uint16_t data);
284
285uint16_t lan8740ReadPhyReg(NetInterface *interface, uint8_t address);
286
287void lan8740DumpPhyReg(NetInterface *interface);
288
289void lan8740WriteMmdReg(NetInterface *interface, uint8_t devAddr,
290 uint16_t regAddr, uint16_t data);
291
292uint16_t lan8740ReadMmdReg(NetInterface *interface, uint8_t devAddr,
293 uint16_t regAddr);
294
295//C++ guard
296#ifdef __cplusplus
297}
298#endif
299
300#endif
error_t
Error codes.
Definition error.h:43
Network interface controller abstraction layer.
Ethernet PHY driver.
Definition nic.h:308