lan8670_driver.h
Go to the documentation of this file.
1 /**
2  * @file lan8670_driver.h
3  * @brief LAN8670 10Base-T1S Ethernet PHY driver
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2024 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 2.4.0
29  **/
30 
31 #ifndef _LAN8670_DRIVER_H
32 #define _LAN8670_DRIVER_H
33 
34 //Dependencies
35 #include "core/nic.h"
36 
37 //PHY address
38 #ifndef LAN8670_PHY_ADDR
39  #define LAN8670_PHY_ADDR 0
40 #elif (LAN8670_PHY_ADDR < 0 || LAN8670_PHY_ADDR > 31)
41  #error LAN8670_PHY_ADDR parameter is not valid
42 #endif
43 
44 //PLCA support
45 #ifndef LAN8670_PLCA_SUPPORT
46  #define LAN8670_PLCA_SUPPORT ENABLED
47 #elif (LAN8670_PLCA_SUPPORT != ENABLED && LAN8670_PLCA_SUPPORT != DISABLED)
48  #error LAN8670_PLCA_SUPPORT parameter is not valid
49 #endif
50 
51 //Node count
52 #ifndef LAN8670_NODE_COUNT
53  #define LAN8670_NODE_COUNT 8
54 #elif (LAN8670_NODE_COUNT < 0 || LAN8670_NODE_COUNT > 255)
55  #error LAN8670_NODE_COUNT parameter is not valid
56 #endif
57 
58 //Local ID
59 #ifndef LAN8670_LOCAL_ID
60  #define LAN8670_LOCAL_ID 1
61 #elif (LAN8670_LOCAL_ID < 0 || LAN8670_LOCAL_ID > 255)
62  #error LAN8670_LOCAL_ID parameter is not valid
63 #endif
64 
65 //LAN8670 PHY registers
66 #define LAN8670_BASIC_CONTROL 0x00
67 #define LAN8670_BASIC_STATUS 0x01
68 #define LAN8670_PHY_ID0 0x02
69 #define LAN8670_PHY_ID1 0x03
70 #define LAN8670_MMDCTRL 0x0D
71 #define LAN8670_MMDAD 0x0E
72 #define LAN8670_STRAP_CTRL0 0x12
73 
74 //LAN8670 MMD registers
75 #define LAN8670_PMA_PMD_EXT_ABILITY 0x01, 0x0012
76 #define LAN8670_T1PMAPMDCTL 0x01, 0x0834
77 #define LAN8670_T1SPMACTL 0x01, 0x08F9
78 #define LAN8670_T1SPMASTS 0x01, 0x08FA
79 #define LAN8670_T1STSTCTL 0x01, 0x08FB
80 #define LAN8670_T1SPCSCTL 0x02, 0x08F3
81 #define LAN8670_T1SPCSSTS 0x02, 0x08F4
82 #define LAN8670_T1SPCSDIAG1 0x02, 0x08F5
83 #define LAN8670_T1SPCSDIAG2 0x02, 0x08F6
84 #define LAN8670_CTRL1 0x1F, 0x0010
85 #define LAN8670_STS1 0x1F, 0x0018
86 #define LAN8670_STS2 0x1F, 0x0019
87 #define LAN8670_STS3 0x1F, 0x001A
88 #define LAN8670_IMSK1 0x1F, 0x001C
89 #define LAN8670_IMSK2 0x1F, 0x001D
90 #define LAN8670_CTRCTRL 0x1F, 0x0020
91 #define LAN8670_TOCNTH 0x1F, 0x0024
92 #define LAN8670_TOCNTL 0x1F, 0x0025
93 #define LAN8670_BCNCNTH 0x1F, 0x0026
94 #define LAN8670_BCNCNTL 0x1F, 0x0027
95 #define LAN8670_PADCTRL3 0x1F, 0x00CB
96 #define LAN8670_MIDVER 0x1F, 0xCA00
97 #define LAN8670_PLCA_CTRL0 0x1F, 0xCA01
98 #define LAN8670_PLCA_CTRL1 0x1F, 0xCA02
99 #define LAN8670_PLCA_STS 0x1F, 0xCA03
100 #define LAN8670_PLCA_TOTMR 0x1F, 0xCA04
101 #define LAN8670_PLCA_BURST 0x1F, 0xCA05
102 
103 //BASIC_CONTROL register
104 #define LAN8670_BASIC_CONTROL_SW_RESET 0x8000
105 #define LAN8670_BASIC_CONTROL_LOOPBACK 0x4000
106 #define LAN8670_BASIC_CONTROL_SPD_SEL_LSB 0x2000
107 #define LAN8670_BASIC_CONTROL_AUTO_NEG_EN 0x1000
108 #define LAN8670_BASIC_CONTROL_PD 0x0800
109 #define LAN8670_BASIC_CONTROL_ISOLATE 0x0400
110 #define LAN8670_BASIC_CONTROL_RE_AUTO_NEG 0x0200
111 #define LAN8670_BASIC_CONTROL_DUPLEX_MODE 0x0100
112 #define LAN8670_BASIC_CONTROL_COL_TEST 0x0080
113 #define LAN8670_BASIC_CONTROL_SPD_SEL_MSB 0x0040
114 
115 //BASIC_STATUS register
116 #define LAN8670_BASIC_STATUS_100BT4 0x8000
117 #define LAN8670_BASIC_STATUS_100BTX_FD 0x4000
118 #define LAN8670_BASIC_STATUS_100BTX_HD 0x2000
119 #define LAN8670_BASIC_STATUS_10BT_FD 0x1000
120 #define LAN8670_BASIC_STATUS_10BT_HD 0x0800
121 #define LAN8670_BASIC_STATUS_100BT2_FD 0x0400
122 #define LAN8670_BASIC_STATUS_100BT2_HD 0x0200
123 #define LAN8670_BASIC_STATUS_EXT_STAT 0x0100
124 #define LAN8670_BASIC_STATUS_MF_PRE_SUP 0x0040
125 #define LAN8670_BASIC_STATUS_AUTO_NEG_COMP 0x0020
126 #define LAN8670_BASIC_STATUS_RMT_FAULT 0x0010
127 #define LAN8670_BASIC_STATUS_AUTO_NEG 0x0008
128 #define LAN8670_BASIC_STATUS_LINK_STAT 0x0004
129 #define LAN8670_BASIC_STATUS_JAB_DET 0x0002
130 #define LAN8670_BASIC_STATUS_EXT_CAP 0x0001
131 
132 //PHY_ID0 register
133 #define LAN8670_PHY_ID0_OUI_2_9 0xFF00
134 #define LAN8670_PHY_ID0_OUI_2_9_DEFAULT 0x0000
135 #define LAN8670_PHY_ID0_OUI_10_17 0x00FF
136 #define LAN8670_PHY_ID0_OUI_10_17_DEFAULT 0x0007
137 
138 //PHY_ID1 register
139 #define LAN8670_PHY_ID1_OUI_18_23 0xFC00
140 #define LAN8670_PHY_ID1_OUI_18_23_DEFAULT 0xC000
141 #define LAN8670_PHY_ID1_MODEL 0x03F0
142 #define LAN8670_PHY_ID1_MODEL_DEFAULT 0x0160
143 #define LAN8670_PHY_ID1_REV 0x000F
144 #define LAN8670_PHY_ID1_REV_0 0x0000
145 #define LAN8670_PHY_ID1_REV_2 0x0002
146 
147 //MMDCTRL register
148 #define LAN8670_MMDCTRL_FNCTN 0xC000
149 #define LAN8670_MMDCTRL_FNCTN_ADDR 0x0000
150 #define LAN8670_MMDCTRL_FNCTN_DATA_NO_POST_INC 0x4000
151 #define LAN8670_MMDCTRL_FNCTN_DATA_POST_INC_RW 0x8000
152 #define LAN8670_MMDCTRL_FNCTN_DATA_POST_INC_W 0xC000
153 #define LAN8670_MMDCTRL_DEVAD 0x001F
154 #define LAN8670_MMDCTRL_DEVAD_PMA_PMD 0x0001
155 #define LAN8670_MMDCTRL_DEVAD_PCS 0x0002
156 #define LAN8670_MMDCTRL_DEVAD_VENDOR_SPECIFIC_2 0x001F
157 
158 //MMDAD register
159 #define LAN8670_MMDAD_ADR_DATA 0xFFFF
160 
161 //STRAP_CTRL0 register
162 #define LAN8670_STRAP_CTRL0_MITYP 0x0180
163 #define LAN8670_STRAP_CTRL0_MITYP_RMII 0x0080
164 #define LAN8670_STRAP_CTRL0_MITYP_MII 0x0100
165 #define LAN8670_STRAP_CTRL0_PKGTYP 0x0060
166 #define LAN8670_STRAP_CTRL0_PKGTYP_32_PIN 0x0020
167 #define LAN8670_STRAP_CTRL0_PKGTYP_24_PIN 0x0040
168 #define LAN8670_STRAP_CTRL0_PKGTYP_36_PIN 0x0060
169 #define LAN8670_STRAP_CTRL0_SMIADR 0x001F
170 
171 //PMA_PMD_EXT_ABILITY register
172 #define LAN8670_PMA_PMD_EXT_ABILITY_T1SABL 0x0008
173 #define LAN8670_PMA_PMD_EXT_ABILITY_T1LABL 0x0004
174 
175 //T1PMAPMDCTL register
176 #define LAN8670_T1PMAPMDCTL_TYPSEL 0x000F
177 #define LAN8670_T1PMAPMDCTL_TYPSEL_100BASE_T1 0x0000
178 #define LAN8670_T1PMAPMDCTL_TYPSEL_1000BASE_T1 0x0001
179 #define LAN8670_T1PMAPMDCTL_TYPSEL_10BASE_T1L 0x0002
180 #define LAN8670_T1PMAPMDCTL_TYPSEL_10BASE_T1S 0x0003
181 
182 //T1SPMACTL register
183 #define LAN8670_T1SPMACTL_RST 0x8000
184 #define LAN8670_T1SPMACTL_TXD 0x4000
185 #define LAN8670_T1SPMACTL_LPE 0x0800
186 #define LAN8670_T1SPMACTL_MDE 0x0400
187 #define LAN8670_T1SPMACTL_LBE 0x0001
188 
189 //T1SPMASTS register
190 #define LAN8670_T1SPMASTS_LBA 0x2000
191 #define LAN8670_T1SPMASTS_LPA 0x0800
192 #define LAN8670_T1SPMASTS_MDA 0x0400
193 #define LAN8670_T1SPMASTS_RXFA 0x0200
194 #define LAN8670_T1SPMASTS_RXFD 0x0002
195 
196 //T1STSTCTL register
197 #define LAN8670_T1STSTCTL_TSTCTL 0xE000
198 #define LAN8670_T1STSTCTL_TSTCTL_NORMAL 0x0000
199 #define LAN8670_T1STSTCTL_TSTCTL_TEST_MODE_1 0x2000
200 #define LAN8670_T1STSTCTL_TSTCTL_TEST_MODE_2 0x4000
201 #define LAN8670_T1STSTCTL_TSTCTL_TEST_MODE_3 0x6000
202 #define LAN8670_T1STSTCTL_TSTCTL_TEST_MODE_4 0x8000
203 
204 //T1SPCSCTL register
205 #define LAN8670_T1SPCSCTL_RST 0x8000
206 #define LAN8670_T1SPCSCTL_LBE 0x4000
207 #define LAN8670_T1SPCSCTL_DUPLEX 0x0100
208 
209 //T1SPCSSTS register
210 #define LAN8670_T1SPCSSTS_FAULT 0x0080
211 
212 //T1SPCSDIAG1 register
213 #define LAN8670_T1SPCSDIAG1_RMTJABCNT 0xFFFF
214 
215 //T1SPCSDIAG2 register
216 #define LAN8670_T1SPCSDIAG2_CORTXCNT 0xFFFF
217 
218 //CTRL1 register
219 #define LAN8670_CTRL1_DIGLBE 0x0002
220 
221 //STS1 register
222 #define LAN8670_STS1_TXCOL 0x0400
223 #define LAN8670_STS1_TXJAB 0x0200
224 #define LAN8670_STS1_EMPCYC 0x0080
225 #define LAN8670_STS1_RXINTO 0x0040
226 #define LAN8670_STS1_UNEXPB 0x0020
227 #define LAN8670_STS1_BCNBFTO 0x0010
228 #define LAN8670_STS1_PLCASYM 0x0004
229 #define LAN8670_STS1_ESDERR 0x0002
230 #define LAN8670_STS1_DEC5B 0x0001
231 
232 //STS2 register
233 #define LAN8670_STS2_RESETC 0x0800
234 
235 //STS3 register
236 #define LAN8670_STS3_ERRTOID 0x0080
237 
238 //IMSK1 register
239 #define LAN8670_IMSK1_TXCOLM 0x0400
240 #define LAN8670_IMSK1_TXJABM 0x0200
241 #define LAN8670_IMSK1_EMPCYCM 0x0080
242 #define LAN8670_IMSK1_RXINTOM 0x0040
243 #define LAN8670_IMSK1_UNEXPBM 0x0020
244 #define LAN8670_IMSK1_BCNBFTOM 0x0010
245 #define LAN8670_IMSK1_PLCASYMM 0x0004
246 #define LAN8670_IMSK1_ESDERRM 0x0002
247 #define LAN8670_IMSK1_DEC5BM 0x0001
248 
249 //IMSK2 register
250 #define LAN8670_IMSK2_RESETCM 0x0800
251 
252 //CTRCTRL register
253 #define LAN8670_CTRCTRL_TOCTRE 0x0002
254 #define LAN8670_CTRCTRL_BCNCTRE 0x0001
255 
256 //TOCNTH register
257 #define LAN8670_TOCNTH_TOCNT_31_16 0xFFFF
258 
259 //TOCNTL register
260 #define LAN8670_TOCNTL_TOCNT_15_0 0xFFFF
261 
262 //BCNCNTH register
263 #define LAN8670_BCNCNTH_BCNCNT_31_16 0xFFFF
264 
265 //BCNCNTL register
266 #define LAN8670_BCNCNTL_BCNCNT_15_0 0xFFFF
267 
268 //PADCTRL3 register
269 #define LAN8670_PADCTRL3_PDRV4 0xC000
270 #define LAN8670_PADCTRL3_PDRV4_LOW 0x0000
271 #define LAN8670_PADCTRL3_PDRV4_MEDIUM_LOW 0x4000
272 #define LAN8670_PADCTRL3_PDRV4_MEDIUM_HIGH 0x8000
273 #define LAN8670_PADCTRL3_PDRV4_HIGH 0xC000
274 #define LAN8670_PADCTRL3_PDRV3 0x3000
275 #define LAN8670_PADCTRL3_PDRV3_LOW 0x0000
276 #define LAN8670_PADCTRL3_PDRV3_MEDIUM_LOW 0x1000
277 #define LAN8670_PADCTRL3_PDRV3_MEDIUM_HIGH 0x2000
278 #define LAN8670_PADCTRL3_PDRV3_HIGH 0x3000
279 #define LAN8670_PADCTRL3_PDRV2 0x0C00
280 #define LAN8670_PADCTRL3_PDRV2_LOW 0x0000
281 #define LAN8670_PADCTRL3_PDRV2_MEDIUM_LOW 0x0400
282 #define LAN8670_PADCTRL3_PDRV2_MEDIUM_HIGH 0x0800
283 #define LAN8670_PADCTRL3_PDRV2_HIGH 0x0C00
284 #define LAN8670_PADCTRL3_PDRV1 0x0300
285 #define LAN8670_PADCTRL3_PDRV1_LOW 0x0000
286 #define LAN8670_PADCTRL3_PDRV1_MEDIUM_LOW 0x0100
287 #define LAN8670_PADCTRL3_PDRV1_MEDIUM_HIGH 0x0200
288 #define LAN8670_PADCTRL3_PDRV1_HIGH 0x0300
289 
290 //MIDVER register
291 #define LAN8670_MIDVER_IDM 0xFF00
292 #define LAN8670_MIDVER_IDM_DEFAULT 0x0A00
293 #define LAN8670_MIDVER_VER 0x00FF
294 #define LAN8670_MIDVER_VER_DEFAULT 0x0010
295 
296 //PLCA_CTRL0 register
297 #define LAN8670_PLCA_CTRL0_EN 0x8000
298 #define LAN8670_PLCA_CTRL0_RST 0x4000
299 
300 //PLCA_CTRL1 register
301 #define LAN8670_PLCA_CTRL1_NCNT 0xFF00
302 #define LAN8670_PLCA_CTRL1_NCNT_DEFAULT 0x0800
303 #define LAN8670_PLCA_CTRL1_ID 0x00FF
304 #define LAN8670_PLCA_CTRL1_ID_PLCA_COORDINATOR 0x0000
305 #define LAN8670_PLCA_CTRL1_ID_PLCA_DISABLED 0x00FF
306 
307 //PLCA_STS register
308 #define LAN8670_PLCA_STS_PST 0x8000
309 
310 //PLCA_TOTMR register
311 #define LAN8670_PLCA_TOTMR_TOTMR 0x00FF
312 #define LAN8670_PLCA_TOTMR_TOTMR_DEFAULT 0x0020
313 
314 //PLCA_BURST register
315 #define LAN8670_PLCA_BURST_MAXBC 0xFF00
316 #define LAN8670_PLCA_BURST_MAXBC_DISABLED 0x0000
317 #define LAN8670_PLCA_BURST_BTMR 0x00FF
318 #define LAN8670_PLCA_BURST_BTMR_DEFAULT 0x0080
319 
320 //C++ guard
321 #ifdef __cplusplus
322 extern "C" {
323 #endif
324 
325 //LAN8670 Ethernet PHY driver
326 extern const PhyDriver lan8670PhyDriver;
327 
328 //LAN8670 related functions
329 error_t lan8670Init(NetInterface *interface);
330 void lan8670InitHook(NetInterface *interface);
331 
332 void lan8670Tick(NetInterface *interface);
333 
334 void lan8670EnableIrq(NetInterface *interface);
335 void lan8670DisableIrq(NetInterface *interface);
336 
337 void lan8670EventHandler(NetInterface *interface);
338 
339 void lan8670WritePhyReg(NetInterface *interface, uint8_t address,
340  uint16_t data);
341 
342 uint16_t lan8670ReadPhyReg(NetInterface *interface, uint8_t address);
343 
344 void lan8670DumpPhyReg(NetInterface *interface);
345 
346 void lan8670WriteMmdReg(NetInterface *interface, uint8_t devAddr,
347  uint16_t regAddr, uint16_t data);
348 
349 uint16_t lan8670ReadMmdReg(NetInterface *interface, uint8_t devAddr,
350  uint16_t regAddr);
351 
352 void lan8670ModifyMmdReg(NetInterface *interface, uint8_t devAddr,
353  uint16_t regAddr, uint16_t mask, uint16_t data);
354 
355 //C++ guard
356 #ifdef __cplusplus
357 }
358 #endif
359 
360 #endif
error_t
Error codes.
Definition: error.h:43
uint8_t data[]
Definition: ethernet.h:222
Ipv6Addr address[]
Definition: ipv6.h:316
void lan8670EventHandler(NetInterface *interface)
LAN8670 event handler.
void lan8670DisableIrq(NetInterface *interface)
Disable interrupts.
void lan8670EnableIrq(NetInterface *interface)
Enable interrupts.
void lan8670Tick(NetInterface *interface)
LAN8670 timer handler.
void lan8670WritePhyReg(NetInterface *interface, uint8_t address, uint16_t data)
Write PHY register.
void lan8670InitHook(NetInterface *interface)
LAN8670 custom configuration.
const PhyDriver lan8670PhyDriver
LAN8670 Ethernet PHY driver.
void lan8670WriteMmdReg(NetInterface *interface, uint8_t devAddr, uint16_t regAddr, uint16_t data)
Write MMD register.
error_t lan8670Init(NetInterface *interface)
LAN8670 PHY transceiver initialization.
uint16_t lan8670ReadMmdReg(NetInterface *interface, uint8_t devAddr, uint16_t regAddr)
Read MMD register.
void lan8670DumpPhyReg(NetInterface *interface)
Dump PHY registers for debugging purpose.
uint16_t lan8670ReadPhyReg(NetInterface *interface, uint8_t address)
Read PHY register.
void lan8670ModifyMmdReg(NetInterface *interface, uint8_t devAddr, uint16_t regAddr, uint16_t mask, uint16_t data)
Modify MMD register.
uint16_t regAddr
#define NetInterface
Definition: net.h:36
Network interface controller abstraction layer.
Ethernet PHY driver.
Definition: nic.h:308
uint8_t mask
Definition: web_socket.h:319