mimxrt1170_eth2_driver.c
Go to the documentation of this file.
1 /**
2  * @file mimxrt1170_eth2_driver.c
3  * @brief NXP i.MX RT1170 Gigabit Ethernet MAC driver (ENET_1G instance)
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.4
29  **/
30 
31 //Switch to the appropriate trace level
32 #define TRACE_LEVEL NIC_TRACE_LEVEL
33 
34 //Dependencies
35 #include "fsl_device_registers.h"
36 #include "fsl_gpio.h"
37 #include "fsl_iomuxc.h"
38 #include "core/net.h"
40 #include "debug.h"
41 
42 //Underlying network interface
43 static NetInterface *nicDriverInterface;
44 
45 //IAR EWARM compiler?
46 #if defined(__ICCARM__)
47 
48 //TX buffer
49 #pragma data_alignment = 64
50 #pragma location = MIMXRT1170_ETH2_RAM_SECTION
52 //RX buffer
53 #pragma data_alignment = 64
54 #pragma location = MIMXRT1170_ETH2_RAM_SECTION
56 //TX buffer descriptors
57 #pragma data_alignment = 64
58 #pragma location = MIMXRT1170_ETH2_RAM_SECTION
59 static uint32_t txBufferDesc[MIMXRT1170_ETH2_TX_BUFFER_COUNT][8];
60 //RX buffer descriptors
61 #pragma data_alignment = 64
62 #pragma location = MIMXRT1170_ETH2_RAM_SECTION
63 static uint32_t rxBufferDesc[MIMXRT1170_ETH2_RX_BUFFER_COUNT][8];
64 
65 //ARM or GCC compiler?
66 #else
67 
68 //TX buffer
70  __attribute__((aligned(64), __section__(MIMXRT1170_ETH2_RAM_SECTION)));
71 //RX buffer
73  __attribute__((aligned(64), __section__(MIMXRT1170_ETH2_RAM_SECTION)));
74 //TX buffer descriptors
75 static uint32_t txBufferDesc[MIMXRT1170_ETH2_TX_BUFFER_COUNT][8]
76  __attribute__((aligned(64), __section__(MIMXRT1170_ETH2_RAM_SECTION)));
77 //RX buffer descriptors
78 static uint32_t rxBufferDesc[MIMXRT1170_ETH2_RX_BUFFER_COUNT][8]
79  __attribute__((aligned(64), __section__(MIMXRT1170_ETH2_RAM_SECTION)));
80 
81 #endif
82 
83 //TX buffer index
84 static uint_t txBufferIndex;
85 //RX buffer index
86 static uint_t rxBufferIndex;
87 
88 
89 /**
90  * @brief i.MX RT1170 Ethernet MAC driver (ENET_1G instance)
91  **/
92 
94 {
96  ETH_MTU,
107  TRUE,
108  TRUE,
109  TRUE,
110  FALSE
111 };
112 
113 
114 /**
115  * @brief i.MX RT1170 Ethernet MAC initialization
116  * @param[in] interface Underlying network interface
117  * @return Error code
118  **/
119 
121 {
122  error_t error;
123  uint32_t value;
124 
125  //Debug message
126  TRACE_INFO("Initializing i.MX RT1170 Ethernet MAC (ENET_1G)...\r\n");
127 
128  //Save underlying network interface
129  nicDriverInterface = interface;
130 
131  //Enable ENET_1G peripheral clock
132  CLOCK_EnableClock(kCLOCK_Enet_1g);
133 
134  //GPIO configuration
135  mimxrt1170Eth2InitGpio(interface);
136 
137  //Reset ENET_1G module
138  ENET_1G->ECR = ENET_ECR_RESET_MASK;
139  //Wait for the reset to complete
140  while((ENET_1G->ECR & ENET_ECR_RESET_MASK) != 0)
141  {
142  }
143 
144  //Receive control register
145  ENET_1G->RCR = ENET_RCR_MAX_FL(MIMXRT1170_ETH2_RX_BUFFER_SIZE) |
146  ENET_RCR_RGMII_EN_MASK | ENET_RCR_MII_MODE_MASK;
147 
148  //Transmit control register
149  ENET_1G->TCR = 0;
150  //Configure MDC clock frequency
151  ENET_1G->MSCR = ENET_MSCR_HOLDTIME(10) | ENET_MSCR_MII_SPEED(120);
152 
153  //Valid Ethernet PHY or switch driver?
154  if(interface->phyDriver != NULL)
155  {
156  //Ethernet PHY initialization
157  error = interface->phyDriver->init(interface);
158  }
159  else if(interface->switchDriver != NULL)
160  {
161  //Ethernet switch initialization
162  error = interface->switchDriver->init(interface);
163  }
164  else
165  {
166  //The interface is not properly configured
167  error = ERROR_FAILURE;
168  }
169 
170  //Any error to report?
171  if(error)
172  {
173  return error;
174  }
175 
176  //Set the MAC address of the station (upper 16 bits)
177  value = interface->macAddr.b[5];
178  value |= (interface->macAddr.b[4] << 8);
179  ENET_1G->PAUR = ENET_PAUR_PADDR2(value) | ENET_PAUR_TYPE(0x8808);
180 
181  //Set the MAC address of the station (lower 32 bits)
182  value = interface->macAddr.b[3];
183  value |= (interface->macAddr.b[2] << 8);
184  value |= (interface->macAddr.b[1] << 16);
185  value |= (interface->macAddr.b[0] << 24);
186  ENET_1G->PALR = ENET_PALR_PADDR1(value);
187 
188  //Hash table for unicast address filtering
189  ENET_1G->IALR = 0;
190  ENET_1G->IAUR = 0;
191  //Hash table for multicast address filtering
192  ENET_1G->GALR = 0;
193  ENET_1G->GAUR = 0;
194 
195  //Disable transmit accelerator functions
196  ENET_1G->TACC = 0;
197  //Disable receive accelerator functions
198  ENET_1G->RACC = 0;
199 
200  //Use enhanced buffer descriptors
201  ENET_1G->ECR = ENET_ECR_DBSWP_MASK | ENET_ECR_EN1588_MASK;
202 
203  //Reset statistics counters
204  ENET_1G->MIBC = ENET_MIBC_MIB_CLEAR_MASK;
205  ENET_1G->MIBC = 0;
206 
207  //Initialize buffer descriptors
208  mimxrt1170Eth2InitBufferDesc(interface);
209 
210  //Clear any pending interrupts
211  ENET_1G->EIR = 0xFFFFFFFF;
212  //Enable desired interrupts
213  ENET_1G->EIMR = ENET_EIMR_TXF_MASK | ENET_EIMR_RXF_MASK | ENET_EIMR_EBERR_MASK;
214 
215  //Set priority grouping (4 bits for pre-emption priority, no bits for subpriority)
216  NVIC_SetPriorityGrouping(MIMXRT1170_ETH2_IRQ_PRIORITY_GROUPING);
217 
218  //Configure ENET_1G interrupt priority
219  NVIC_SetPriority(ENET_1G_IRQn, NVIC_EncodePriority(MIMXRT1170_ETH2_IRQ_PRIORITY_GROUPING,
221 
222  //Enable Ethernet MAC
223  ENET_1G->ECR |= ENET_ECR_ETHEREN_MASK;
224  //Instruct the DMA to poll the receive descriptor list
225  ENET_1G->RDAR = ENET_RDAR_RDAR_MASK;
226 
227  //Accept any packets from the upper layer
228  osSetEvent(&interface->nicTxEvent);
229 
230  //Successful initialization
231  return NO_ERROR;
232 }
233 
234 
235 /**
236  * @brief GPIO configuration
237  * @param[in] interface Underlying network interface
238  **/
239 
240 __weak_func void mimxrt1170Eth2InitGpio(NetInterface *interface)
241 {
242 //MIMXRT1170-EVK evaluation board?
243 #if defined(USE_MIMXRT1170_EVK)
244  gpio_pin_config_t pinConfig;
245  clock_root_config_t rootConfig = {0};
246 #if 0
247  clock_sys_pll1_config_t sysPll1Config = {0};
248 
249  //Initialize system PLL1
250  sysPll1Config.pllDiv2En = true;
251  CLOCK_InitSysPll1(&sysPll1Config);
252 #endif
253 
254  //Generate 125MHz root clock
255  rootConfig.clockOff = false;
256  rootConfig.mux = kCLOCK_ENET2_ClockRoot_MuxSysPll1Div2;
257  rootConfig.div = 4;
258  CLOCK_SetRootClock(kCLOCK_Root_Enet2, &rootConfig);
259 
260 #if 0
261  //Initialize PLL PFD3 (528*18/24 = 396MHz)
262  CLOCK_InitPfd(kCLOCK_PllSys2, kCLOCK_Pfd3, 24);
263 
264  //Generate 198MHz bus clock
265  rootConfig.clockOff = false;
266  rootConfig.mux = kCLOCK_BUS_ClockRoot_MuxSysPll2Pfd3;
267  rootConfig.div = 2;
268  CLOCK_SetRootClock(kCLOCK_Root_Bus, &rootConfig);
269 #endif
270 
271  //ENET_1G_TX_CLK is driven by ENET2_CLK_ROOT
272  IOMUXC_GPR->GPR5 &= ~IOMUXC_GPR_GPR5_ENET1G_TX_CLK_SEL_MASK;
273  //Enable ENET_1G_TX_CLK output
274  IOMUXC_GPR->GPR5 |= IOMUXC_GPR_GPR5_ENET1G_RGMII_EN_MASK;
275 
276  //Enable IOMUXC clock
277  CLOCK_EnableClock(kCLOCK_Iomuxc);
278 
279  //Configure GPIO_DISP_B1_00 pin as ENET_1G_RX_EN
280  IOMUXC_SetPinMux(IOMUXC_GPIO_DISP_B1_00_ENET_1G_RX_EN, 0);
281 
282  //Set GPIO_DISP_B1_00 pad properties
283  IOMUXC_SetPinConfig(IOMUXC_GPIO_DISP_B1_00_ENET_1G_RX_EN,
284  IOMUXC_SW_PAD_CTL_PAD_DWP_LOCK(0) |
285  IOMUXC_SW_PAD_CTL_PAD_DWP(0) |
286  IOMUXC_SW_PAD_CTL_PAD_ODE(0) |
287  IOMUXC_SW_PAD_CTL_PAD_PULL(2) |
288  IOMUXC_SW_PAD_CTL_PAD_PDRV(0));
289 
290  //Configure GPIO_DISP_B1_01 pin as ENET_1G_RX_CLK
291  IOMUXC_SetPinMux(IOMUXC_GPIO_DISP_B1_01_ENET_1G_RX_CLK, 0);
292 
293  //Set GPIO_DISP_B1_01 pad properties
294  IOMUXC_SetPinConfig(IOMUXC_GPIO_DISP_B1_01_ENET_1G_RX_CLK,
295  IOMUXC_SW_PAD_CTL_PAD_DWP_LOCK(0) |
296  IOMUXC_SW_PAD_CTL_PAD_DWP(0) |
297  IOMUXC_SW_PAD_CTL_PAD_ODE(0) |
298  IOMUXC_SW_PAD_CTL_PAD_PULL(2) |
299  IOMUXC_SW_PAD_CTL_PAD_PDRV(0));
300 
301  //Configure GPIO_DISP_B1_02 pin as ENET_1G_RX_DATA00
302  IOMUXC_SetPinMux(IOMUXC_GPIO_DISP_B1_02_ENET_1G_RX_DATA00, 0);
303 
304  //Set GPIO_DISP_B1_02 pad properties
305  IOMUXC_SetPinConfig(IOMUXC_GPIO_DISP_B1_02_ENET_1G_RX_DATA00,
306  IOMUXC_SW_PAD_CTL_PAD_DWP_LOCK(0) |
307  IOMUXC_SW_PAD_CTL_PAD_DWP(0) |
308  IOMUXC_SW_PAD_CTL_PAD_ODE(0) |
309  IOMUXC_SW_PAD_CTL_PAD_PULL(2) |
310  IOMUXC_SW_PAD_CTL_PAD_PDRV(0));
311 
312  //Configure GPIO_DISP_B1_03 pin as ENET_1G_RX_DATA01
313  IOMUXC_SetPinMux(IOMUXC_GPIO_DISP_B1_03_ENET_1G_RX_DATA01, 0);
314 
315  //Set GPIO_DISP_B1_03 pad properties
316  IOMUXC_SetPinConfig(IOMUXC_GPIO_DISP_B1_03_ENET_1G_RX_DATA01,
317  IOMUXC_SW_PAD_CTL_PAD_DWP_LOCK(0) |
318  IOMUXC_SW_PAD_CTL_PAD_DWP(0) |
319  IOMUXC_SW_PAD_CTL_PAD_ODE(0) |
320  IOMUXC_SW_PAD_CTL_PAD_PULL(2) |
321  IOMUXC_SW_PAD_CTL_PAD_PDRV(0));
322 
323  //Configure GPIO_DISP_B1_04 pin as ENET_1G_RX_DATA02
324  IOMUXC_SetPinMux(IOMUXC_GPIO_DISP_B1_04_ENET_1G_RX_DATA02, 0);
325 
326  //Set GPIO_DISP_B1_04 pad properties
327  IOMUXC_SetPinConfig(IOMUXC_GPIO_DISP_B1_04_ENET_1G_RX_DATA02,
328  IOMUXC_SW_PAD_CTL_PAD_DWP_LOCK(0) |
329  IOMUXC_SW_PAD_CTL_PAD_DWP(0) |
330  IOMUXC_SW_PAD_CTL_PAD_ODE(0) |
331  IOMUXC_SW_PAD_CTL_PAD_PULL(2) |
332  IOMUXC_SW_PAD_CTL_PAD_PDRV(0));
333 
334  //Configure GPIO_DISP_B1_05 pin as ENET_1G_RX_DATA03
335  IOMUXC_SetPinMux(IOMUXC_GPIO_DISP_B1_05_ENET_1G_RX_DATA03, 0);
336 
337  //Set GPIO_DISP_B1_05 pad properties
338  IOMUXC_SetPinConfig(IOMUXC_GPIO_DISP_B1_05_ENET_1G_RX_DATA03,
339  IOMUXC_SW_PAD_CTL_PAD_DWP_LOCK(0) |
340  IOMUXC_SW_PAD_CTL_PAD_DWP(0) |
341  IOMUXC_SW_PAD_CTL_PAD_ODE(0) |
342  IOMUXC_SW_PAD_CTL_PAD_PULL(2) |
343  IOMUXC_SW_PAD_CTL_PAD_PDRV(0));
344 
345  //Configure GPIO_DISP_B1_06 pin as ENET_1G_TX_DATA03
346  IOMUXC_SetPinMux(IOMUXC_GPIO_DISP_B1_06_ENET_1G_TX_DATA03, 0);
347 
348  //Set GPIO_DISP_B1_06 pad properties
349  IOMUXC_SetPinConfig(IOMUXC_GPIO_DISP_B1_06_ENET_1G_TX_DATA03,
350  IOMUXC_SW_PAD_CTL_PAD_DWP_LOCK(0) |
351  IOMUXC_SW_PAD_CTL_PAD_DWP(0) |
352  IOMUXC_SW_PAD_CTL_PAD_ODE(0) |
353  IOMUXC_SW_PAD_CTL_PAD_PULL(3) |
354  IOMUXC_SW_PAD_CTL_PAD_PDRV(0));
355 
356  //Configure GPIO_DISP_B1_07 pin as ENET_1G_TX_DATA02
357  IOMUXC_SetPinMux(IOMUXC_GPIO_DISP_B1_07_ENET_1G_TX_DATA02, 0);
358 
359  //Set GPIO_DISP_B1_07 pad properties
360  IOMUXC_SetPinConfig(IOMUXC_GPIO_DISP_B1_07_ENET_1G_TX_DATA02,
361  IOMUXC_SW_PAD_CTL_PAD_DWP_LOCK(0) |
362  IOMUXC_SW_PAD_CTL_PAD_DWP(0) |
363  IOMUXC_SW_PAD_CTL_PAD_ODE(0) |
364  IOMUXC_SW_PAD_CTL_PAD_PULL(3) |
365  IOMUXC_SW_PAD_CTL_PAD_PDRV(0));
366 
367  //Configure GPIO_DISP_B1_08 pin as ENET_1G_TX_DATA01
368  IOMUXC_SetPinMux(IOMUXC_GPIO_DISP_B1_08_ENET_1G_TX_DATA01, 0);
369 
370  //Set GPIO_DISP_B1_08 pad properties
371  IOMUXC_SetPinConfig(IOMUXC_GPIO_DISP_B1_08_ENET_1G_TX_DATA01,
372  IOMUXC_SW_PAD_CTL_PAD_DWP_LOCK(0) |
373  IOMUXC_SW_PAD_CTL_PAD_DWP(0) |
374  IOMUXC_SW_PAD_CTL_PAD_ODE(0) |
375  IOMUXC_SW_PAD_CTL_PAD_PULL(3) |
376  IOMUXC_SW_PAD_CTL_PAD_PDRV(0));
377 
378  //Configure GPIO_DISP_B1_09 pin as ENET_1G_TX_DATA00
379  IOMUXC_SetPinMux(IOMUXC_GPIO_DISP_B1_09_ENET_1G_TX_DATA00, 0);
380 
381  //Set GPIO_DISP_B1_09 pad properties
382  IOMUXC_SetPinConfig(IOMUXC_GPIO_DISP_B1_09_ENET_1G_TX_DATA00,
383  IOMUXC_SW_PAD_CTL_PAD_DWP_LOCK(0) |
384  IOMUXC_SW_PAD_CTL_PAD_DWP(0) |
385  IOMUXC_SW_PAD_CTL_PAD_ODE(0) |
386  IOMUXC_SW_PAD_CTL_PAD_PULL(3) |
387  IOMUXC_SW_PAD_CTL_PAD_PDRV(0));
388 
389  //Configure GPIO_DISP_B1_10 pin as ENET_1G_TX_EN
390  IOMUXC_SetPinMux(IOMUXC_GPIO_DISP_B1_10_ENET_1G_TX_EN, 0);
391 
392  //Set GPIO_DISP_B1_10 pad properties
393  IOMUXC_SetPinConfig(IOMUXC_GPIO_DISP_B1_10_ENET_1G_TX_EN,
394  IOMUXC_SW_PAD_CTL_PAD_DWP_LOCK(0) |
395  IOMUXC_SW_PAD_CTL_PAD_DWP(0) |
396  IOMUXC_SW_PAD_CTL_PAD_ODE(0) |
397  IOMUXC_SW_PAD_CTL_PAD_PULL(3) |
398  IOMUXC_SW_PAD_CTL_PAD_PDRV(0));
399 
400  //Configure GPIO_DISP_B1_11 pin as ENET_1G_TX_CLK
401  IOMUXC_SetPinMux(IOMUXC_GPIO_DISP_B1_11_ENET_1G_TX_CLK_IO, 0);
402 
403  //Set GPIO_DISP_B1_11 pad properties
404  IOMUXC_SetPinConfig(IOMUXC_GPIO_DISP_B1_11_ENET_1G_TX_CLK_IO,
405  IOMUXC_SW_PAD_CTL_PAD_DWP_LOCK(0) |
406  IOMUXC_SW_PAD_CTL_PAD_DWP(0) |
407  IOMUXC_SW_PAD_CTL_PAD_ODE(0) |
408  IOMUXC_SW_PAD_CTL_PAD_PULL(3) |
409  IOMUXC_SW_PAD_CTL_PAD_PDRV(0));
410 
411  //Configure GPIO_EMC_B2_19 pin as ENET_1G_MDC
412  IOMUXC_SetPinMux(IOMUXC_GPIO_EMC_B2_19_ENET_1G_MDC, 0);
413 
414  //Set GPIO_EMC_B2_19 pad properties
415  IOMUXC_SetPinConfig(IOMUXC_GPIO_EMC_B2_19_ENET_1G_MDC,
416  IOMUXC_SW_PAD_CTL_PAD_DWP_LOCK(0) |
417  IOMUXC_SW_PAD_CTL_PAD_DWP(0) |
418  IOMUXC_SW_PAD_CTL_PAD_ODE(0) |
419  IOMUXC_SW_PAD_CTL_PAD_PULL(3) |
420  IOMUXC_SW_PAD_CTL_PAD_PDRV(0));
421 
422  //Configure GPIO_EMC_B2_20 pin as ENET_1G_MDIO
423  IOMUXC_SetPinMux(IOMUXC_GPIO_EMC_B2_20_ENET_1G_MDIO, 0);
424 
425  //Set GPIO_EMC_B2_20 pad properties
426  IOMUXC_SetPinConfig(IOMUXC_GPIO_EMC_B2_20_ENET_1G_MDIO,
427  IOMUXC_SW_PAD_CTL_PAD_DWP_LOCK(0) |
428  IOMUXC_SW_PAD_CTL_PAD_DWP(0) |
429  IOMUXC_SW_PAD_CTL_PAD_ODE(0) |
430  IOMUXC_SW_PAD_CTL_PAD_PULL(1) |
431  IOMUXC_SW_PAD_CTL_PAD_PDRV(0));
432 
433  //Configure GPIO_DISP_B2_13 pin as GPIO11_IO14
434  IOMUXC_SetPinMux(IOMUXC_GPIO_DISP_B2_13_GPIO11_IO14, 0);
435 
436  //Set GPIO_DISP_B2_13 pad properties
437  IOMUXC_SetPinConfig(IOMUXC_GPIO_DISP_B2_13_GPIO11_IO14,
438  IOMUXC_SW_PAD_CTL_PAD_DWP_LOCK(0) |
439  IOMUXC_SW_PAD_CTL_PAD_DWP(0) |
440  IOMUXC_SW_PAD_CTL_PAD_ODE(0) |
441  IOMUXC_SW_PAD_CTL_PAD_PUS(0) |
442  IOMUXC_SW_PAD_CTL_PAD_PUE(0) |
443  IOMUXC_SW_PAD_CTL_PAD_DSE(1) |
444  IOMUXC_SW_PAD_CTL_PAD_SRE(0));
445 
446  //Configure GPIO_DISP_B2_12 pin as GPIO11_IO13
447  IOMUXC_SetPinMux(IOMUXC_GPIO_DISP_B2_12_GPIO11_IO13, 0);
448 
449  //Set GPIO_DISP_B2_12 pad properties
450  IOMUXC_SetPinConfig(IOMUXC_GPIO_DISP_B2_12_GPIO11_IO13,
451  IOMUXC_SW_PAD_CTL_PAD_DWP_LOCK(0) |
452  IOMUXC_SW_PAD_CTL_PAD_DWP(0) |
453  IOMUXC_SW_PAD_CTL_PAD_ODE(0) |
454  IOMUXC_SW_PAD_CTL_PAD_PUS(0) |
455  IOMUXC_SW_PAD_CTL_PAD_PUE(0) |
456  IOMUXC_SW_PAD_CTL_PAD_DSE(1) |
457  IOMUXC_SW_PAD_CTL_PAD_SRE(0));
458 
459  //Configure ENET_1G_RST as an output
460  pinConfig.direction = kGPIO_DigitalOutput;
461  pinConfig.outputLogic = 0;
462  pinConfig.interruptMode = kGPIO_NoIntmode;
463  GPIO_PinInit(GPIO11, 14, &pinConfig);
464 
465  //Configure ENET_1G_INT as an input
466  pinConfig.direction = kGPIO_DigitalInput;
467  pinConfig.outputLogic = 0;
468  pinConfig.interruptMode = kGPIO_NoIntmode;
469  GPIO_PinInit(GPIO11, 13, &pinConfig);
470 
471  //Reset PHY transceiver (hard reset)
472  GPIO_PinWrite(GPIO11, 14, 0);
473  sleep(10);
474  GPIO_PinWrite(GPIO11, 14, 1);
475  sleep(10);
476 #endif
477 }
478 
479 
480 /**
481  * @brief Initialize buffer descriptors
482  * @param[in] interface Underlying network interface
483  **/
484 
486 {
487  uint_t i;
488  uint32_t address;
489 
490  //Clear TX and RX buffer descriptors
491  osMemset(txBufferDesc, 0, sizeof(txBufferDesc));
492  osMemset(rxBufferDesc, 0, sizeof(rxBufferDesc));
493 
494  //Initialize TX buffer descriptors
495  for(i = 0; i < MIMXRT1170_ETH2_TX_BUFFER_COUNT; i++)
496  {
497  //Calculate the address of the current TX buffer
498  address = (uint32_t) txBuffer[i];
499  //Transmit buffer address
500  txBufferDesc[i][1] = address;
501  //Generate interrupts
502  txBufferDesc[i][2] = ENET_TBD2_INT;
503  }
504 
505  //Mark the last descriptor entry with the wrap flag
506  txBufferDesc[i - 1][0] |= ENET_TBD0_W;
507  //Initialize TX buffer index
508  txBufferIndex = 0;
509 
510  //Initialize RX buffer descriptors
511  for(i = 0; i < MIMXRT1170_ETH2_RX_BUFFER_COUNT; i++)
512  {
513  //Calculate the address of the current RX buffer
514  address = (uint32_t) rxBuffer[i];
515  //The descriptor is initially owned by the DMA
516  rxBufferDesc[i][0] = ENET_RBD0_E;
517  //Receive buffer address
518  rxBufferDesc[i][1] = address;
519  //Generate interrupts
520  rxBufferDesc[i][2] = ENET_RBD2_INT;
521  }
522 
523  //Mark the last descriptor entry with the wrap flag
524  rxBufferDesc[i - 1][0] |= ENET_RBD0_W;
525  //Initialize RX buffer index
526  rxBufferIndex = 0;
527 
528  //Start location of the TX descriptor list
529  ENET_1G->TDSR = (uint32_t) txBufferDesc;
530  //Start location of the RX descriptor list
531  ENET_1G->RDSR = (uint32_t) rxBufferDesc;
532  //Maximum receive buffer size
533  ENET_1G->MRBR = MIMXRT1170_ETH2_RX_BUFFER_SIZE;
534 }
535 
536 
537 /**
538  * @brief i.MX RT1170 Ethernet MAC timer handler
539  *
540  * This routine is periodically called by the TCP/IP stack to handle periodic
541  * operations such as polling the link state
542  *
543  * @param[in] interface Underlying network interface
544  **/
545 
547 {
548  //Valid Ethernet PHY or switch driver?
549  if(interface->phyDriver != NULL)
550  {
551  //Handle periodic operations
552  interface->phyDriver->tick(interface);
553  }
554  else if(interface->switchDriver != NULL)
555  {
556  //Handle periodic operations
557  interface->switchDriver->tick(interface);
558  }
559  else
560  {
561  //Just for sanity
562  }
563 }
564 
565 
566 /**
567  * @brief Enable interrupts
568  * @param[in] interface Underlying network interface
569  **/
570 
572 {
573  //Enable Ethernet MAC interrupts
574  NVIC_EnableIRQ(ENET_1G_IRQn);
575 
576  //Valid Ethernet PHY or switch driver?
577  if(interface->phyDriver != NULL)
578  {
579  //Enable Ethernet PHY interrupts
580  interface->phyDriver->enableIrq(interface);
581  }
582  else if(interface->switchDriver != NULL)
583  {
584  //Enable Ethernet switch interrupts
585  interface->switchDriver->enableIrq(interface);
586  }
587  else
588  {
589  //Just for sanity
590  }
591 }
592 
593 
594 /**
595  * @brief Disable interrupts
596  * @param[in] interface Underlying network interface
597  **/
598 
600 {
601  //Disable Ethernet MAC interrupts
602  NVIC_DisableIRQ(ENET_1G_IRQn);
603 
604  //Valid Ethernet PHY or switch driver?
605  if(interface->phyDriver != NULL)
606  {
607  //Disable Ethernet PHY interrupts
608  interface->phyDriver->disableIrq(interface);
609  }
610  else if(interface->switchDriver != NULL)
611  {
612  //Disable Ethernet switch interrupts
613  interface->switchDriver->disableIrq(interface);
614  }
615  else
616  {
617  //Just for sanity
618  }
619 }
620 
621 
622 /**
623  * @brief Ethernet MAC interrupt
624  **/
625 
627 {
628  bool_t flag;
629  uint32_t events;
630 
631  //Interrupt service routine prologue
632  osEnterIsr();
633 
634  //This flag will be set if a higher priority task must be woken
635  flag = FALSE;
636  //Read interrupt event register
637  events = ENET_1G->EIR;
638 
639  //Packet transmitted?
640  if((events & ENET_EIR_TXF_MASK) != 0)
641  {
642  //Clear TXF interrupt flag
643  ENET_1G->EIR = ENET_EIR_TXF_MASK;
644 
645  //Check whether the TX buffer is available for writing
646  if((txBufferDesc[txBufferIndex][0] & ENET_TBD0_R) == 0)
647  {
648  //Notify the TCP/IP stack that the transmitter is ready to send
649  flag = osSetEventFromIsr(&nicDriverInterface->nicTxEvent);
650  }
651 
652  //Instruct the DMA to poll the transmit descriptor list
653  ENET_1G->TDAR = ENET_TDAR_TDAR_MASK;
654  }
655 
656  //Packet received?
657  if((events & ENET_EIR_RXF_MASK) != 0)
658  {
659  //Disable RXF interrupt
660  ENET_1G->EIMR &= ~ENET_EIMR_RXF_MASK;
661 
662  //Set event flag
663  nicDriverInterface->nicEvent = TRUE;
664  //Notify the TCP/IP stack of the event
665  flag = osSetEventFromIsr(&netEvent);
666  }
667 
668  //System bus error?
669  if((events & ENET_EIR_EBERR_MASK) != 0)
670  {
671  //Disable EBERR interrupt
672  ENET_1G->EIMR &= ~ENET_EIMR_EBERR_MASK;
673 
674  //Set event flag
675  nicDriverInterface->nicEvent = TRUE;
676  //Notify the TCP/IP stack of the event
677  flag |= osSetEventFromIsr(&netEvent);
678  }
679 
680  //Interrupt service routine epilogue
681  osExitIsr(flag);
682 }
683 
684 
685 /**
686  * @brief i.MX RT1170 Ethernet MAC event handler
687  * @param[in] interface Underlying network interface
688  **/
689 
691 {
692  error_t error;
693  uint32_t status;
694 
695  //Read interrupt event register
696  status = ENET_1G->EIR;
697 
698  //Packet received?
699  if((status & ENET_EIR_RXF_MASK) != 0)
700  {
701  //Clear RXF interrupt flag
702  ENET_1G->EIR = ENET_EIR_RXF_MASK;
703 
704  //Process all pending packets
705  do
706  {
707  //Read incoming packet
708  error = mimxrt1170Eth2ReceivePacket(interface);
709 
710  //No more data in the receive buffer?
711  } while(error != ERROR_BUFFER_EMPTY);
712  }
713 
714  //System bus error?
715  if((status & ENET_EIR_EBERR_MASK) != 0)
716  {
717  //Clear EBERR interrupt flag
718  ENET_1G->EIR = ENET_EIR_EBERR_MASK;
719 
720  //Disable Ethernet MAC
721  ENET_1G->ECR &= ~ENET_ECR_ETHEREN_MASK;
722  //Reset buffer descriptors
723  mimxrt1170Eth2InitBufferDesc(interface);
724  //Resume normal operation
725  ENET_1G->ECR |= ENET_ECR_ETHEREN_MASK;
726  //Instruct the DMA to poll the receive descriptor list
727  ENET_1G->RDAR = ENET_RDAR_RDAR_MASK;
728  }
729 
730  //Re-enable Ethernet MAC interrupts
731  ENET_1G->EIMR = ENET_EIMR_TXF_MASK | ENET_EIMR_RXF_MASK | ENET_EIMR_EBERR_MASK;
732 }
733 
734 
735 /**
736  * @brief Send a packet
737  * @param[in] interface Underlying network interface
738  * @param[in] buffer Multi-part buffer containing the data to send
739  * @param[in] offset Offset to the first data byte
740  * @param[in] ancillary Additional options passed to the stack along with
741  * the packet
742  * @return Error code
743  **/
744 
746  const NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary)
747 {
748  size_t length;
749 
750  //Retrieve the length of the packet
751  length = netBufferGetLength(buffer) - offset;
752 
753  //Check the frame length
755  {
756  //The transmitter can accept another packet
757  osSetEvent(&interface->nicTxEvent);
758  //Report an error
759  return ERROR_INVALID_LENGTH;
760  }
761 
762  //Make sure the current buffer is available for writing
763  if((txBufferDesc[txBufferIndex][0] & ENET_TBD0_R) != 0)
764  {
765  return ERROR_FAILURE;
766  }
767 
768  //Copy user data to the transmit buffer
769  netBufferRead(txBuffer[txBufferIndex], buffer, offset, length);
770 
771  //Clear BDU flag
772  txBufferDesc[txBufferIndex][4] = 0;
773 
774  //Check current index
775  if(txBufferIndex < (MIMXRT1170_ETH2_TX_BUFFER_COUNT - 1))
776  {
777  //Give the ownership of the descriptor to the DMA engine
778  txBufferDesc[txBufferIndex][0] = ENET_TBD0_R | ENET_TBD0_L |
780 
781  //Point to the next buffer
782  txBufferIndex++;
783  }
784  else
785  {
786  //Give the ownership of the descriptor to the DMA engine
787  txBufferDesc[txBufferIndex][0] = ENET_TBD0_R | ENET_TBD0_W |
789 
790  //Wrap around
791  txBufferIndex = 0;
792  }
793 
794  //Data synchronization barrier
795  __DSB();
796 
797  //Instruct the DMA to poll the transmit descriptor list
798  ENET_1G->TDAR = ENET_TDAR_TDAR_MASK;
799 
800  //Check whether the next buffer is available for writing
801  if((txBufferDesc[txBufferIndex][0] & ENET_TBD0_R) == 0)
802  {
803  //The transmitter can accept another packet
804  osSetEvent(&interface->nicTxEvent);
805  }
806 
807  //Successful processing
808  return NO_ERROR;
809 }
810 
811 
812 /**
813  * @brief Receive a packet
814  * @param[in] interface Underlying network interface
815  * @return Error code
816  **/
817 
819 {
820  error_t error;
821  size_t n;
822  NetRxAncillary ancillary;
823 
824  //Current buffer available for reading?
825  if((rxBufferDesc[rxBufferIndex][0] & ENET_RBD0_E) == 0)
826  {
827  //The frame should not span multiple buffers
828  if((rxBufferDesc[rxBufferIndex][0] & ENET_RBD0_L) != 0)
829  {
830  //Check whether an error occurred
831  if((rxBufferDesc[rxBufferIndex][0] & (ENET_RBD0_LG | ENET_RBD0_NO |
833  {
834  //Retrieve the length of the frame
835  n = rxBufferDesc[rxBufferIndex][0] & ENET_RBD0_DATA_LENGTH;
836  //Limit the number of data to read
838 
839  //Additional options can be passed to the stack along with the packet
840  ancillary = NET_DEFAULT_RX_ANCILLARY;
841 
842  //Pass the packet to the upper layer
843  nicProcessPacket(interface, rxBuffer[rxBufferIndex], n, &ancillary);
844 
845  //Valid packet received
846  error = NO_ERROR;
847  }
848  else
849  {
850  //The received packet contains an error
851  error = ERROR_INVALID_PACKET;
852  }
853  }
854  else
855  {
856  //The packet is not valid
857  error = ERROR_INVALID_PACKET;
858  }
859 
860  //Clear BDU flag
861  rxBufferDesc[rxBufferIndex][4] = 0;
862 
863  //Check current index
864  if(rxBufferIndex < (MIMXRT1170_ETH2_RX_BUFFER_COUNT - 1))
865  {
866  //Give the ownership of the descriptor back to the DMA engine
867  rxBufferDesc[rxBufferIndex][0] = ENET_RBD0_E;
868  //Point to the next buffer
869  rxBufferIndex++;
870  }
871  else
872  {
873  //Give the ownership of the descriptor back to the DMA engine
874  rxBufferDesc[rxBufferIndex][0] = ENET_RBD0_E | ENET_RBD0_W;
875  //Wrap around
876  rxBufferIndex = 0;
877  }
878 
879  //Instruct the DMA to poll the receive descriptor list
880  ENET_1G->RDAR = ENET_RDAR_RDAR_MASK;
881  }
882  else
883  {
884  //No more data in the receive buffer
885  error = ERROR_BUFFER_EMPTY;
886  }
887 
888  //Return status code
889  return error;
890 }
891 
892 
893 /**
894  * @brief Configure MAC address filtering
895  * @param[in] interface Underlying network interface
896  * @return Error code
897  **/
898 
900 {
901  uint_t i;
902  uint_t k;
903  uint32_t crc;
904  uint32_t value;
905  uint32_t unicastHashTable[2];
906  uint32_t multicastHashTable[2];
907  MacFilterEntry *entry;
908 
909  //Debug message
910  TRACE_DEBUG("Updating MAC filter...\r\n");
911 
912  //Set the MAC address of the station (upper 16 bits)
913  value = interface->macAddr.b[5];
914  value |= (interface->macAddr.b[4] << 8);
915  ENET_1G->PAUR = ENET_PAUR_PADDR2(value) | ENET_PAUR_TYPE(0x8808);
916 
917  //Set the MAC address of the station (lower 32 bits)
918  value = interface->macAddr.b[3];
919  value |= (interface->macAddr.b[2] << 8);
920  value |= (interface->macAddr.b[1] << 16);
921  value |= (interface->macAddr.b[0] << 24);
922  ENET_1G->PALR = ENET_PALR_PADDR1(value);
923 
924  //Clear hash table (unicast address filtering)
925  unicastHashTable[0] = 0;
926  unicastHashTable[1] = 0;
927 
928  //Clear hash table (multicast address filtering)
929  multicastHashTable[0] = 0;
930  multicastHashTable[1] = 0;
931 
932  //The MAC address filter contains the list of MAC addresses to accept
933  //when receiving an Ethernet frame
934  for(i = 0; i < MAC_ADDR_FILTER_SIZE; i++)
935  {
936  //Point to the current entry
937  entry = &interface->macAddrFilter[i];
938 
939  //Valid entry?
940  if(entry->refCount > 0)
941  {
942  //Compute CRC over the current MAC address
943  crc = mimxrt1170Eth2CalcCrc(&entry->addr, sizeof(MacAddr));
944 
945  //The upper 6 bits in the CRC register are used to index the
946  //contents of the hash table
947  k = (crc >> 26) & 0x3F;
948 
949  //Multicast address?
950  if(macIsMulticastAddr(&entry->addr))
951  {
952  //Update the multicast hash table
953  multicastHashTable[k / 32] |= (1 << (k % 32));
954  }
955  else
956  {
957  //Update the unicast hash table
958  unicastHashTable[k / 32] |= (1 << (k % 32));
959  }
960  }
961  }
962 
963  //Write the hash table (unicast address filtering)
964  ENET_1G->IALR = unicastHashTable[0];
965  ENET_1G->IAUR = unicastHashTable[1];
966 
967  //Write the hash table (multicast address filtering)
968  ENET_1G->GALR = multicastHashTable[0];
969  ENET_1G->GAUR = multicastHashTable[1];
970 
971  //Debug message
972  TRACE_DEBUG(" IALR = %08" PRIX32 "\r\n", ENET_1G->IALR);
973  TRACE_DEBUG(" IAUR = %08" PRIX32 "\r\n", ENET_1G->IAUR);
974  TRACE_DEBUG(" GALR = %08" PRIX32 "\r\n", ENET_1G->GALR);
975  TRACE_DEBUG(" GAUR = %08" PRIX32 "\r\n", ENET_1G->GAUR);
976 
977  //Successful processing
978  return NO_ERROR;
979 }
980 
981 
982 /**
983  * @brief Adjust MAC configuration parameters for proper operation
984  * @param[in] interface Underlying network interface
985  * @return Error code
986  **/
987 
989 {
990  //Disable Ethernet MAC while modifying configuration registers
991  ENET_1G->ECR &= ~ENET_ECR_ETHEREN_MASK;
992 
993  //1000BASE-T operation mode?
994  if(interface->linkSpeed == NIC_LINK_SPEED_1GBPS)
995  {
996  ENET_1G->ECR |= ENET_ECR_SPEED_MASK;
997  ENET_1G->RCR &= ~ENET_RCR_RMII_10T_MASK;
998  }
999  //100BASE-TX operation mode?
1000  else if(interface->linkSpeed == NIC_LINK_SPEED_100MBPS)
1001  {
1002  ENET_1G->ECR &= ~ENET_ECR_SPEED_MASK;
1003  ENET_1G->RCR &= ~ENET_RCR_RMII_10T_MASK;
1004  }
1005  //10BASE-T operation mode?
1006  else
1007  {
1008  ENET_1G->ECR &= ~ENET_ECR_SPEED_MASK;
1009  ENET_1G->RCR |= ENET_RCR_RMII_10T_MASK;
1010  }
1011 
1012  //Half-duplex or full-duplex mode?
1013  if(interface->duplexMode == NIC_FULL_DUPLEX_MODE)
1014  {
1015  //Full-duplex mode
1016  ENET_1G->TCR |= ENET_TCR_FDEN_MASK;
1017  //Receive path operates independently of transmit
1018  ENET_1G->RCR &= ~ENET_RCR_DRT_MASK;
1019  }
1020  else
1021  {
1022  //Half-duplex mode
1023  ENET_1G->TCR &= ~ENET_TCR_FDEN_MASK;
1024  //Disable reception of frames while transmitting
1025  ENET_1G->RCR |= ENET_RCR_DRT_MASK;
1026  }
1027 
1028  //Reset buffer descriptors
1029  mimxrt1170Eth2InitBufferDesc(interface);
1030 
1031  //Re-enable Ethernet MAC
1032  ENET_1G->ECR |= ENET_ECR_ETHEREN_MASK;
1033  //Instruct the DMA to poll the receive descriptor list
1034  ENET_1G->RDAR = ENET_RDAR_RDAR_MASK;
1035 
1036  //Successful processing
1037  return NO_ERROR;
1038 }
1039 
1040 
1041 /**
1042  * @brief Write PHY register
1043  * @param[in] opcode Access type (2 bits)
1044  * @param[in] phyAddr PHY address (5 bits)
1045  * @param[in] regAddr Register address (5 bits)
1046  * @param[in] data Register value
1047  **/
1048 
1049 void mimxrt1170Eth2WritePhyReg(uint8_t opcode, uint8_t phyAddr,
1050  uint8_t regAddr, uint16_t data)
1051 {
1052  uint32_t temp;
1053 
1054  //Valid opcode?
1055  if(opcode == SMI_OPCODE_WRITE)
1056  {
1057  //Set up a write operation
1058  temp = ENET_MMFR_ST(1) | ENET_MMFR_OP(1) | ENET_MMFR_TA(2);
1059  //PHY address
1060  temp |= ENET_MMFR_PA(phyAddr);
1061  //Register address
1062  temp |= ENET_MMFR_RA(regAddr);
1063  //Register value
1064  temp |= ENET_MMFR_DATA(data);
1065 
1066  //Clear MII interrupt flag
1067  ENET_1G->EIR = ENET_EIR_MII_MASK;
1068  //Start a write operation
1069  ENET_1G->MMFR = temp;
1070 
1071  //Wait for the write to complete
1072  while((ENET_1G->EIR & ENET_EIR_MII_MASK) == 0)
1073  {
1074  }
1075  }
1076  else
1077  {
1078  //The MAC peripheral only supports standard Clause 22 opcodes
1079  }
1080 }
1081 
1082 
1083 /**
1084  * @brief Read PHY register
1085  * @param[in] opcode Access type (2 bits)
1086  * @param[in] phyAddr PHY address (5 bits)
1087  * @param[in] regAddr Register address (5 bits)
1088  * @return Register value
1089  **/
1090 
1091 uint16_t mimxrt1170Eth2ReadPhyReg(uint8_t opcode, uint8_t phyAddr,
1092  uint8_t regAddr)
1093 {
1094  uint16_t data;
1095  uint32_t temp;
1096 
1097  //Valid opcode?
1098  if(opcode == SMI_OPCODE_READ)
1099  {
1100  //Set up a read operation
1101  temp = ENET_MMFR_ST(1) | ENET_MMFR_OP(2) | ENET_MMFR_TA(2);
1102  //PHY address
1103  temp |= ENET_MMFR_PA(phyAddr);
1104  //Register address
1105  temp |= ENET_MMFR_RA(regAddr);
1106 
1107  //Clear MII interrupt flag
1108  ENET_1G->EIR = ENET_EIR_MII_MASK;
1109  //Start a read operation
1110  ENET_1G->MMFR = temp;
1111 
1112  //Wait for the read to complete
1113  while((ENET_1G->EIR & ENET_EIR_MII_MASK) == 0)
1114  {
1115  }
1116 
1117  //Get register value
1118  data = ENET_1G->MMFR & ENET_MMFR_DATA_MASK;
1119  }
1120  else
1121  {
1122  //The MAC peripheral only supports standard Clause 22 opcodes
1123  data = 0;
1124  }
1125 
1126  //Return the value of the PHY register
1127  return data;
1128 }
1129 
1130 
1131 /**
1132  * @brief CRC calculation
1133  * @param[in] data Pointer to the data over which to calculate the CRC
1134  * @param[in] length Number of bytes to process
1135  * @return Resulting CRC value
1136  **/
1137 
1138 uint32_t mimxrt1170Eth2CalcCrc(const void *data, size_t length)
1139 {
1140  uint_t i;
1141  uint_t j;
1142  uint32_t crc;
1143  const uint8_t *p;
1144 
1145  //Point to the data over which to calculate the CRC
1146  p = (uint8_t *) data;
1147  //CRC preset value
1148  crc = 0xFFFFFFFF;
1149 
1150  //Loop through data
1151  for(i = 0; i < length; i++)
1152  {
1153  //Update CRC value
1154  crc ^= p[i];
1155 
1156  //The message is processed bit by bit
1157  for(j = 0; j < 8; j++)
1158  {
1159  if((crc & 0x01) != 0)
1160  {
1161  crc = (crc >> 1) ^ 0xEDB88320;
1162  }
1163  else
1164  {
1165  crc = crc >> 1;
1166  }
1167  }
1168  }
1169 
1170  //Return CRC value
1171  return crc;
1172 }
bool_t osSetEventFromIsr(OsEvent *event)
Set an event object to the signaled state from an interrupt service routine.
@ NIC_LINK_SPEED_1GBPS
Definition: nic.h:113
void mimxrt1170Eth2WritePhyReg(uint8_t opcode, uint8_t phyAddr, uint8_t regAddr, uint16_t data)
Write PHY register.
uint8_t opcode
Definition: dns_common.h:188
int bool_t
Definition: compiler_port.h:53
void mimxrt1170Eth2EnableIrq(NetInterface *interface)
Enable interrupts.
#define netEvent
Definition: net_legacy.h:196
@ NIC_FULL_DUPLEX_MODE
Definition: nic.h:125
#define ENET_TBD0_L
void mimxrt1170Eth2DisableIrq(NetInterface *interface)
Disable interrupts.
size_t netBufferRead(void *dest, const NetBuffer *src, size_t srcOffset, size_t length)
Read data from a multi-part buffer.
Definition: net_mem.c:690
#define MIMXRT1170_ETH2_RX_BUFFER_COUNT
#define ENET_RBD0_DATA_LENGTH
#define MIMXRT1170_ETH2_IRQ_PRIORITY_GROUPING
uint8_t p
Definition: ndp.h:300
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:89
error_t mimxrt1170Eth2Init(NetInterface *interface)
i.MX RT1170 Ethernet MAC initialization
#define MAC_ADDR_FILTER_SIZE
Definition: ethernet.h:95
#define TRUE
Definition: os_port.h:50
uint8_t data[]
Definition: ethernet.h:222
#define sleep(delay)
Definition: os_port.h:307
uint_t refCount
Reference count for the current entry.
Definition: ethernet.h:264
#define ENET_TBD0_DATA_LENGTH
#define ENET_TBD0_W
#define ENET_TBD0_TC
void nicProcessPacket(NetInterface *interface, uint8_t *packet, size_t length, NetRxAncillary *ancillary)
Handle a packet received by the network controller.
Definition: nic.c:392
#define macIsMulticastAddr(macAddr)
Definition: ethernet.h:133
#define osExitIsr(flag)
#define SMI_OPCODE_WRITE
Definition: nic.h:66
void ENET_1G_IRQHandler(void)
Ethernet MAC interrupt.
#define ENET_RBD0_L
void mimxrt1170Eth2InitBufferDesc(NetInterface *interface)
Initialize buffer descriptors.
#define FALSE
Definition: os_port.h:46
void mimxrt1170Eth2Tick(NetInterface *interface)
i.MX RT1170 Ethernet MAC timer handler
error_t mimxrt1170Eth2SendPacket(NetInterface *interface, const NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary)
Send a packet.
error_t
Error codes.
Definition: error.h:43
NXP i.MX RT1170 Gigabit Ethernet MAC driver (ENET_1G instance)
const NetRxAncillary NET_DEFAULT_RX_ANCILLARY
Definition: net_misc.c:104
@ ERROR_FAILURE
Generic error code.
Definition: error.h:45
#define MIMXRT1170_ETH2_TX_BUFFER_COUNT
#define txBuffer
#define NetRxAncillary
Definition: net_misc.h:40
@ ERROR_INVALID_PACKET
Definition: error.h:140
#define NetInterface
Definition: net.h:36
MacAddr addr
MAC address.
Definition: ethernet.h:263
@ ERROR_INVALID_LENGTH
Definition: error.h:111
#define ENET_RBD0_W
@ ERROR_BUFFER_EMPTY
Definition: error.h:141
#define ENET_RBD0_TR
#define NetTxAncillary
Definition: net_misc.h:36
#define MIMXRT1170_ETH2_TX_BUFFER_SIZE
#define SMI_OPCODE_READ
Definition: nic.h:67
#define TRACE_INFO(...)
Definition: debug.h:95
uint8_t length
Definition: tcp.h:368
size_t netBufferGetLength(const NetBuffer *buffer)
Get the actual length of a multi-part buffer.
Definition: net_mem.c:297
__weak_func void mimxrt1170Eth2InitGpio(NetInterface *interface)
GPIO configuration.
#define MIN(a, b)
Definition: os_port.h:63
error_t mimxrt1170Eth2ReceivePacket(NetInterface *interface)
Receive a packet.
#define rxBuffer
MacAddr
Definition: ethernet.h:195
#define ENET_RBD0_LG
#define TRACE_DEBUG(...)
Definition: debug.h:107
uint16_t regAddr
#define ENET_RBD0_CR
uint16_t mimxrt1170Eth2ReadPhyReg(uint8_t opcode, uint8_t phyAddr, uint8_t regAddr)
Read PHY register.
#define ENET_RBD0_OV
#define ETH_MTU
Definition: ethernet.h:116
uint8_t n
const NicDriver mimxrt1170Eth2Driver
i.MX RT1170 Ethernet MAC driver (ENET_1G instance)
MAC filter table entry.
Definition: ethernet.h:262
Ipv6Addr address[]
Definition: ipv6.h:325
#define osEnterIsr()
#define ENET_TBD0_R
#define MIMXRT1170_ETH2_IRQ_GROUP_PRIORITY
uint8_t value[]
Definition: tcp.h:369
uint32_t mimxrt1170Eth2CalcCrc(const void *data, size_t length)
CRC calculation.
#define ENET_TBD2_INT
#define MIMXRT1170_ETH2_RAM_SECTION
#define ENET_RBD0_E
error_t mimxrt1170Eth2UpdateMacAddrFilter(NetInterface *interface)
Configure MAC address filtering.
error_t mimxrt1170Eth2UpdateMacConfig(NetInterface *interface)
Adjust MAC configuration parameters for proper operation.
void osSetEvent(OsEvent *event)
Set the specified event object to the signaled state.
#define MIMXRT1170_ETH2_RX_BUFFER_SIZE
void mimxrt1170Eth2EventHandler(NetInterface *interface)
i.MX RT1170 Ethernet MAC event handler
@ NIC_LINK_SPEED_100MBPS
Definition: nic.h:112
unsigned int uint_t
Definition: compiler_port.h:50
#define osMemset(p, value, length)
Definition: os_port.h:135
TCP/IP stack core.
NIC driver.
Definition: nic.h:286
#define ENET_RBD0_NO
#define MIMXRT1170_ETH2_IRQ_SUB_PRIORITY
#define ENET_RBD2_INT
@ NO_ERROR
Success.
Definition: error.h:44
__attribute__((naked))
AVR32 Ethernet MAC interrupt wrapper.
Debugging facilities.
@ NIC_TYPE_ETHERNET
Ethernet interface.
Definition: nic.h:83