mikroSDK Reference Manual
ar8031_driver.h
Go to the documentation of this file.
1
31#ifndef _AR8031_DRIVER_H
32#define _AR8031_DRIVER_H
33
34//Dependencies
35#include "core/nic.h"
36
37//PHY address
38#ifndef AR8031_PHY_ADDR
39 #define AR8031_PHY_ADDR 0
40#elif (AR8031_PHY_ADDR < 0 || AR8031_PHY_ADDR > 31)
41 #error AR8031_PHY_ADDR parameter is not valid
42#endif
43
44//AR8031 PHY registers
45#define AR8031_BMCR 0x00
46#define AR8031_BMSR 0x01
47#define AR8031_PHYID1 0x02
48#define AR8031_PHYID2 0x03
49#define AR8031_ANAR 0x04
50#define AR8031_ANLPAR 0x05
51#define AR8031_ANER 0x06
52#define AR8031_ANNPR 0x07
53#define AR8031_ANLPNPR 0x08
54#define AR8031_GBCR 0x09
55#define AR8031_GBSR 0x0A
56#define AR8031_MMDACR 0x0D
57#define AR8031_MMDAADR 0x0E
58#define AR8031_GBESR 0x0F
59#define AR8031_FUNC_CTRL 0x10
60#define AR8031_PHY_STATUS 0x11
61#define AR8031_INT_EN 0x12
62#define AR8031_INT_STATUS 0x13
63#define AR8031_SMART_SPEED 0x14
64#define AR8031_CDT_CTRL 0x16
65#define AR8031_LED_CTRL 0x18
66#define AR8031_MAN_LED_OVERRIDE 0x19
67#define AR8031_COPPER_FIBER_STATUS 0x1B
68#define AR8031_CDT_STATUS 0x1C
69#define AR8031_DBG_PORT_ADDR_OFFSET 0x1D
70#define AR8031_DBG_PORT_DATA 0x1E
71#define AR8031_CHIP_CONF 0x1F
72
73//AR8031 MMD registers
74#define AR8031_PCS_CTRL 0x03, 0x0000
75#define AR8031_PCS_STAT 0x03, 0x0001
76#define AR8031_EEE_CAPABILITY 0x03, 0x0014
77#define AR8031_EEE_WAKE_ERROR_COUNTER 0x03, 0x0016
78#define AR8031_P1588_CTRL 0x03, 0x8012
79#define AR8031_P1588_RX_SEQ_ID 0x03, 0x8013
80#define AR8031_P1588_RX_SRC_PORT_ID1 0x03, 0x8014
81#define AR8031_P1588_RX_SRC_PORT_ID2 0x03, 0x8015
82#define AR8031_P1588_RX_SRC_PORT_ID3 0x03, 0x8016
83#define AR8031_P1588_RX_SRC_PORT_ID4 0x03, 0x8017
84#define AR8031_P1588_RX_SRC_PORT_ID5 0x03, 0x8018
85#define AR8031_P1588_RX_TIMESTAMP1 0x03, 0x8019
86#define AR8031_P1588_RX_TIMESTAMP2 0x03, 0x801A
87#define AR8031_P1588_RX_TIMESTAMP3 0x03, 0x801B
88#define AR8031_P1588_RX_TIMESTAMP4 0x03, 0x801C
89#define AR8031_P1588_RX_TIMESTAMP5 0x03, 0x801D
90#define AR8031_P1588_RX_FRAC_NANO1 0x03, 0x801E
91#define AR8031_P1588_RX_FRAC_NANO0 0x03, 0x801F
92#define AR8031_P1588_TX_SEQ_ID 0x03, 0x8020
93#define AR8031_P1588_TX_SRC_PORT_ID1 0x03, 0x8021
94#define AR8031_P1588_TX_SRC_PORT_ID2 0x03, 0x8022
95#define AR8031_P1588_TX_SRC_PORT_ID3 0x03, 0x8023
96#define AR8031_P1588_TX_SRC_PORT_ID4 0x03, 0x8024
97#define AR8031_P1588_TX_SRC_PORT_ID5 0x03, 0x8025
98#define AR8031_P1588_TX_TIMESTAMP1 0x03, 0x8026
99#define AR8031_P1588_TX_TIMESTAMP2 0x03, 0x8027
100#define AR8031_P1588_TX_TIMESTAMP3 0x03, 0x8028
101#define AR8031_P1588_TX_TIMESTAMP4 0x03, 0x8029
102#define AR8031_P1588_TX_TIMESTAMP5 0x03, 0x802A
103#define AR8031_P1588_TX_FRAC_NANO1 0x03, 0x802B
104#define AR8031_P1588_TX_FRAC_NANO2 0x03, 0x802C
105#define AR8031_P1588_ORIGIN_CORRECTION1 0x03, 0x802D
106#define AR8031_P1588_ORIGIN_CORRECTION2 0x03, 0x802E
107#define AR8031_P1588_ORIGIN_CORRECTION3 0x03, 0x802F
108#define AR8031_P1588_ORIGIN_CORRECTION4 0x03, 0x8030
109#define AR8031_P1588_INGRESS_TRIG_TIME1 0x03, 0x8031
110#define AR8031_P1588_INGRESS_TRIG_TIME2 0x03, 0x8032
111#define AR8031_P1588_INGRESS_TRIG_TIME3 0x03, 0x8033
112#define AR8031_P1588_INGRESS_TRIG_TIME4 0x03, 0x8034
113#define AR8031_P1588_TX_LATENCY 0x03, 0x8035
114#define AR8031_P1588_INC_VALUE1 0x03, 0x8036
115#define AR8031_P1588_INC_VALUE2 0x03, 0x8037
116#define AR8031_P1588_NANO_OFFSET1 0x03, 0x8038
117#define AR8031_P1588_NANO_OFFSET2 0x03, 0x8039
118#define AR8031_P1588_SEC_OFFSET1 0x03, 0x803A
119#define AR8031_P1588_SEC_OFFSET2 0x03, 0x803B
120#define AR8031_P1588_SEC_OFFSET3 0x03, 0x803C
121#define AR8031_P1588_REAL_TIME1 0x03, 0x803D
122#define AR8031_P1588_REAL_TIME2 0x03, 0x803E
123#define AR8031_P1588_REAL_TIME3 0x03, 0x803F
124#define AR8031_P1588_REAL_TIME4 0x03, 0x8040
125#define AR8031_P1588_REAL_TIME5 0x03, 0x8041
126#define AR8031_P1588_REAL_TIME6 0x03, 0x8042
127#define AR8031_P1588_RTC_FRAC_NANO1 0x03, 0x8042
128#define AR8031_P1588_RTC_FRAC_NANO2 0x03, 0x8043
129#define AR8031_WOL_INTERNAL_ADDR1 0x03, 0x804A
130#define AR8031_WOL_INTERNAL_ADDR2 0x03, 0x804B
131#define AR8031_WOL_INTERNAL_ADDR3 0x03, 0x804C
132#define AR8031_REM_PHY_LPBK 0x03, 0x805A
133#define AR8031_SMART_EEE_CTRL1 0x03, 0x805B
134#define AR8031_SMART_EEE_CTRL2 0x03, 0x805C
135#define AR8031_SMART_EEE_CTRL3 0x03, 0x805D
136#define AR8031_AN_CTRL1 0x07, 0x0000
137#define AR8031_AN_STAT 0x07, 0x0001
138#define AR8031_AN_XNP_TRANSMIT 0x07, 0x0016
139#define AR8031_AN_XNP_TRANSMIT1 0x07, 0x0017
140#define AR8031_AN_XNP_TRANSMIT2 0x07, 0x0018
141#define AR8031_AN_LP_XNP_ABILITY 0x07, 0x0019
142#define AR8031_AN_LP_XNP_ABILITY1 0x07, 0x001A
143#define AR8031_AN_LP_XNP_ABILITY2 0x07, 0x001B
144#define AR8031_EEE_ADV 0x07, 0x003C
145#define AR8031_EEE_LP_ADV 0x07, 0x003D
146#define AR8031_EEE_ABILITY_AN_RES 0x07, 0x8000
147#define AR8031_SGMII_CTRL1 0x07, 0x8005
148#define AR8031_SGMII_CTRL2 0x07, 0x8011
149#define AR8031_SGMII_CTRL3 0x07, 0x8012
150#define AR8031_CLK_25M_CLK_SEL 0x07, 0x8016
151#define AR8031_1588_CLK_SEL 0x07, 0x8017
152
153//Control register
154#define AR8031_BMCR_RESET 0x8000
155#define AR8031_BMCR_LOOPBACK 0x4000
156#define AR8031_BMCR_SPEED_SEL_LSB 0x2000
157#define AR8031_BMCR_AN_EN 0x1000
158#define AR8031_BMCR_POWER_DOWN 0x0800
159#define AR8031_BMCR_ISOLATE 0x0400
160#define AR8031_BMCR_RESTART_AN 0x0200
161#define AR8031_BMCR_DUPLEX_MODE 0x0100
162#define AR8031_BMCR_COL_TEST 0x0080
163#define AR8031_BMCR_SPEED_SEL_MSB 0x0040
164
165//Status register
166#define AR8031_BMSR_100BT4 0x8000
167#define AR8031_BMSR_100BTX_FD 0x4000
168#define AR8031_BMSR_100BTX_HD 0x2000
169#define AR8031_BMSR_10BT_FD 0x1000
170#define AR8031_BMSR_10BT_HD 0x0800
171#define AR8031_BMSR_100BT2_FD 0x0400
172#define AR8031_BMSR_100BT2_HD 0x0200
173#define AR8031_BMSR_EXTENDED_STATUS 0x0100
174#define AR8031_BMSR_MF_PREAMBLE_SUPPR 0x0040
175#define AR8031_BMSR_AN_COMPLETE 0x0020
176#define AR8031_BMSR_REMOTE_FAULT 0x0010
177#define AR8031_BMSR_AN_CAPABLE 0x0008
178#define AR8031_BMSR_LINK_STATUS 0x0004
179#define AR8031_BMSR_JABBER_DETECT 0x0002
180#define AR8031_BMSR_EXTENDED_CAPABLE 0x0001
181
182//PHY Identifier 1 register
183#define AR8031_PHYID1_OUI_MSB 0xFFFF
184#define AR8031_PHYID1_OUI_MSB_DEFAULT 0x004D
185
186//PHY Identifier 2 register
187#define AR8031_PHYID2_OUI_LSB 0xFC00
188#define AR8031_PHYID2_OUI_LSB_DEFAULT 0xD000
189#define AR8031_PHYID2_MODEL_NUM 0x03F0
190#define AR8031_PHYID2_MODEL_NUM_DEFAULT 0x0070
191#define AR8031_PHYID2_REVISION_NUM 0x000F
192
193//Auto-Negotiation Advertisement register
194#define AR8031_ANAR_NEXT_PAGE 0x8000
195#define AR8031_ANAR_ACK 0x4000
196#define AR8031_ANAR_REMOTE_FAULT 0x2000
197#define AR8031_ANAR_XNP_ABLE 0x1000
198#define AR8031_ANAR_ASYM_PAUSE 0x0800
199#define AR8031_ANAR_PAUSE 0x0400
200#define AR8031_ANAR_100BT4 0x0200
201#define AR8031_ANAR_100BTX_FD 0x0100
202#define AR8031_ANAR_100BTX_HD 0x0080
203#define AR8031_ANAR_10BT_FD 0x0040
204#define AR8031_ANAR_10BT_HD 0x0020
205#define AR8031_ANAR_SELECTOR 0x001F
206#define AR8031_ANAR_SELECTOR_DEFAULT 0x0001
207
208//Link Partner Ability register
209#define AR8031_ANLPAR_NEXT_PAGE 0x8000
210#define AR8031_ANLPAR_ACK 0x4000
211#define AR8031_ANLPAR_REMOTE_FAULT 0x2000
212#define AR8031_ANLPAR_ASYM_PAUSE 0x0800
213#define AR8031_ANLPAR_PAUSE 0x0400
214#define AR8031_ANLPAR_100BT4 0x0200
215#define AR8031_ANLPAR_100BTX_FD 0x0100
216#define AR8031_ANLPAR_100BTX_HD 0x0080
217#define AR8031_ANLPAR_10BT_FD 0x0040
218#define AR8031_ANLPAR_10BT_HD 0x0020
219#define AR8031_ANLPAR_SELECTOR 0x001F
220#define AR8031_ANLPAR_SELECTOR_DEFAULT 0x0001
221
222//Auto-Negotiation Expansion register
223#define AR8031_ANER_PAR_DETECT_FAULT 0x0010
224#define AR8031_ANER_LP_NEXT_PAGE_ABLE 0x0008
225#define AR8031_ANER_NEXT_PAGE_ABLE 0x0004
226#define AR8031_ANER_PAGE_RECEIVED 0x0002
227#define AR8031_ANER_LP_AN_ABLE 0x0001
228
229//Auto-Negotiation Next Page Transmit register
230#define AR8031_ANNPR_NEXT_PAGE 0x8000
231#define AR8031_ANNPR_MSG_PAGE 0x2000
232#define AR8031_ANNPR_ACK2 0x1000
233#define AR8031_ANNPR_TOGGLE 0x0800
234#define AR8031_ANNPR_MESSAGE 0x07FF
235
236//Link Partner Next Page register
237#define AR8031_ANLPNPR_NEXT_PAGE 0x8000
238#define AR8031_ANLPNPR_MSG_PAGE 0x2000
239#define AR8031_ANLPNPR_ACK2 0x1000
240#define AR8031_ANLPNPR_TOGGLE 0x0800
241#define AR8031_ANLPNPR_MESSAGE 0x07FF
242
243//1000BASE-T Control register
244#define AR8031_GBCR_TEST_MODE 0xE000
245#define AR8031_GBCR_MS_MAN_CONF_EN 0x1000
246#define AR8031_GBCR_MS_MAN_CONF_VAL 0x0800
247#define AR8031_GBCR_PORT_TYPE 0x0400
248#define AR8031_GBCR_1000BT_FD 0x0200
249#define AR8031_GBCR_1000BT_HD 0x0100
250
251//1000BASE-T Status register
252#define AR8031_GBSR_MS_CONF_FAULT 0x8000
253#define AR8031_GBSR_MS_CONF_RES 0x4000
254#define AR8031_GBSR_LOCAL_RECEIVER_STATUS 0x2000
255#define AR8031_GBSR_REMOTE_RECEIVER_STATUS 0x1000
256#define AR8031_GBSR_LP_1000BT_FD 0x0800
257#define AR8031_GBSR_LP_1000BT_HD 0x0400
258#define AR8031_GBSR_IDLE_ERR_COUNT 0x00FF
259
260//MMD Access Control register
261#define AR8031_MMDACR_FUNC 0xC000
262#define AR8031_MMDACR_FUNC_ADDR 0x0000
263#define AR8031_MMDACR_FUNC_DATA_NO_POST_INC 0x4000
264#define AR8031_MMDACR_FUNC_DATA_POST_INC_RW 0x8000
265#define AR8031_MMDACR_FUNC_DATA_POST_INC_W 0xC000
266#define AR8031_MMDACR_DEVAD 0x001F
267
268//Extended Status register
269#define AR8031_GBESR_1000BX_FD 0x8000
270#define AR8031_GBESR_1000BX_HD 0x4000
271#define AR8031_GBESR_1000BT_FD 0x2000
272#define AR8031_GBESR_1000BT_HD 0x1000
273
274//Function Control register
275#define AR8031_FUNC_CTRL_ASSERT_CRS_ON_TX 0x0800
276#define AR8031_FUNC_CTRL_FORCE_LINK 0x0400
277#define AR8031_FUNC_CTRL_MDIX_MODE 0x0060
278#define AR8031_FUNC_CTRL_MDIX_MODE_MANUAL_MDI 0x0000
279#define AR8031_FUNC_CTRL_MDIX_MODE_MANUAL_MDIX 0x0020
280#define AR8031_FUNC_CTRL_MDIX_MODE_AUTO 0x0060
281#define AR8031_FUNC_CTRL_SQE_TEST 0x0004
282#define AR8031_FUNC_CTRL_POLARITY_REVERSAL 0x0002
283#define AR8031_FUNC_CTRL_JABBER_DIS 0x0001
284
285//PHY-Specific Status register
286#define AR8031_PHY_STATUS_SPEED 0xC000
287#define AR8031_PHY_STATUS_SPEED_10MBPS 0x0000
288#define AR8031_PHY_STATUS_SPEED_100MBPS 0x4000
289#define AR8031_PHY_STATUS_SPEED_1000MBPS 0x8000
290#define AR8031_PHY_STATUS_DUPLEX 0x2000
291#define AR8031_PHY_STATUS_PAGE_RECEIVED 0x1000
292#define AR8031_PHY_STATUS_SPEED_DUPLEX_RESOLVED 0x0800
293#define AR8031_PHY_STATUS_LINK 0x0400
294#define AR8031_PHY_STATUS_MDI_CROSSOVER_STATUS 0x0040
295#define AR8031_PHY_STATUS_WIRESPEED_DOWNGRADE 0x0020
296#define AR8031_PHY_STATUS_TX_PAUSE_EN 0x0008
297#define AR8031_PHY_STATUS_RX_PAUSE_EN 0x0004
298#define AR8031_PHY_STATUS_POLARITY 0x0002
299#define AR8031_PHY_STATUS_JABBER 0x0001
300
301//Interrupt Enable Register register
302#define AR8031_INT_EN_AN_ERROR 0x8000
303#define AR8031_INT_EN_SPEED_CHANGED 0x4000
304#define AR8031_INT_EN_PAGE_RECEIVED 0x1000
305#define AR8031_INT_EN_LINK_FAIL 0x0800
306#define AR8031_INT_EN_LINK_SUCCESS 0x0400
307#define AR8031_INT_EN_FAST_LINK_DOWN1 0x0200
308#define AR8031_INT_EN_LINK_FAIL_BX 0x0100
309#define AR8031_INT_EN_LINK_SUCCESS_BX 0x0080
310#define AR8031_INT_EN_FAST_LINK_DOWN0 0x0040
311#define AR8031_INT_EN_WIRESPEED_DOWNGRADE 0x0020
312#define AR8031_INT_EN_10MS_PTP 0x0010
313#define AR8031_INT_EN_RX_PTP 0x0008
314#define AR8031_INT_EN_TX_PTP 0x0004
315#define AR8031_INT_EN_POLARITY_CHANGED 0x0002
316#define AR8031_INT_EN_WOL_PTP 0x0001
317
318//Interrupt Status register
319#define AR8031_INT_STATUS_AN_ERROR 0x8000
320#define AR8031_INT_STATUS_SPEED_CHANGED 0x4000
321#define AR8031_INT_STATUS_PAGE_RECEIVED 0x1000
322#define AR8031_INT_STATUS_LINK_FAIL 0x0800
323#define AR8031_INT_STATUS_LINK_SUCCESS 0x0400
324#define AR8031_INT_STATUS_FAST_LINK_DOWN1 0x0200
325#define AR8031_INT_STATUS_LINK_FAIL_BX 0x0100
326#define AR8031_INT_STATUS_LINK_SUCCESS_BX 0x0080
327#define AR8031_INT_STATUS_FAST_LINK_DOWN0 0x0040
328#define AR8031_INT_STATUS_WIRESPEED_DOWNGRADE 0x0020
329#define AR8031_INT_STATUS_10MS_PTP 0x0010
330#define AR8031_INT_STATUS_RX_PTP 0x0008
331#define AR8031_INT_STATUS_TX_PTP 0x0004
332#define AR8031_INT_STATUS_POLARITY_CHANGED 0x0002
333#define AR8031_INT_STATUS_WOL_PTP 0x0001
334
335//Smart Speed register
336#define AR8031_SMART_SPEED_EN 0x0020
337#define AR8031_SMART_SPEED_RETRY_LIMIT 0x001C
338#define AR8031_SMART_SPEED_BYPASS_TIMER 0x0002
339
340//Cable Diagnostic Tester (CDT) Control register
341#define AR8031_CDT_CTRL_MDI_PAIR_SELECT 0x0300
342#define AR8031_CDT_CTRL_TEST_EN 0x0001
343
344//LED Control register
345#define AR8031_LED_CTRL_LED_DIS 0x8000
346#define AR8031_LED_CTRL_LED_ON_TIME 0x7000
347#define AR8031_LED_CTRL_LED_OFF_TIME 0x0700
348#define AR8031_LED_CTRL_LED_LINK_CTRL 0x0018
349#define AR8031_LED_CTRL_LED_ACT_CTRL 0x0004
350
351//Manual LED Override register
352#define AR8031_MAN_LED_OVERRIDE_LED_ACT 0x1000
353#define AR8031_MAN_LED_OVERRIDE_LED_LINK10_100_CTRL 0x00C0
354#define AR8031_MAN_LED_OVERRIDE_LED_RX_CTRL 0x000C
355#define AR8031_MAN_LED_OVERRIDE_LED_TX_CTRL 0x0003
356
357//Copper/Fiber Status register
358#define AR8031_COPPER_FIBER_STATUS_TX_PAUSE_EN_BX 0x2000
359#define AR8031_COPPER_FIBER_STATUS_RX_PAUSE_EN_BX 0x1000
360#define AR8031_COPPER_FIBER_STATUS_LINK_ESTABLISHED_BX 0x0800
361#define AR8031_COPPER_FIBER_STATUS_FD_MODE_BX 0x0400
362#define AR8031_COPPER_FIBER_STATUS_SPEED_MODE_BX 0x0300
363#define AR8031_COPPER_FIBER_STATUS_TX_PAUSE_EN_BT 0x0020
364#define AR8031_COPPER_FIBER_STATUS_RX_PAUSE_EN_BT 0x0010
365#define AR8031_COPPER_FIBER_STATUS_LINK_ESTABLISHED_BT 0x0008
366#define AR8031_COPPER_FIBER_STATUS_FD_MODE_BT 0x0004
367#define AR8031_COPPER_FIBER_STATUS_SPEED_MODE_BT 0x0003
368
369//Cable Diagnostic Tester Status register
370#define AR8031_CDT_STATUS_STATUS 0x0300
371#define AR8031_CDT_STATUS_DELTA_TIME 0x00FF
372
373//Chip Configure register
374#define AR8031_CHIP_CONF_BT_BX_REG_SEL 0x8000
375#define AR8031_CHIP_CONF_SMII_IMP_50_75_AUTO 0x4000
376#define AR8031_CHIP_CONF_SGMII_RXIMP_50_75 0x2000
377#define AR8031_CHIP_CONF_SGMII_TXIMP_50_75 0x1000
378#define AR8031_CHIP_CONF_PRIORITY_SEL 0x0400
379#define AR8031_CHIP_CONF_FIBER_MODE_AUTO 0x0100
380#define AR8031_CHIP_CONF_MODE_CFG_QUAL 0x00F0
381#define AR8031_CHIP_CONF_MODE_CFG 0x000F
382
383//C++ guard
384#ifdef __cplusplus
385extern "C" {
386#endif
387
388//AR8031 Ethernet PHY driver
389extern const PhyDriver ar8031PhyDriver;
390
391//AR8031 related functions
392error_t ar8031Init(NetInterface *interface);
393void ar8031InitHook(NetInterface *interface);
394
395void ar8031Tick(NetInterface *interface);
396
397void ar8031EnableIrq(NetInterface *interface);
398void ar8031DisableIrq(NetInterface *interface);
399
400void ar8031EventHandler(NetInterface *interface);
401
402void ar8031WritePhyReg(NetInterface *interface, uint8_t address,
403 uint16_t data);
404
405uint16_t ar8031ReadPhyReg(NetInterface *interface, uint8_t address);
406
407void ar8031DumpPhyReg(NetInterface *interface);
408
409void ar8031WriteMmdReg(NetInterface *interface, uint8_t devAddr,
410 uint16_t regAddr, uint16_t data);
411
412uint16_t ar8031ReadMmdReg(NetInterface *interface, uint8_t devAddr,
413 uint16_t regAddr);
414
415//C++ guard
416#ifdef __cplusplus
417}
418#endif
419
420#endif
error_t
Error codes.
Definition error.h:43
Network interface controller abstraction layer.
Ethernet PHY driver.
Definition nic.h:308