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.0
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  static uint32_t temp[MIMXRT1170_ETH2_TX_BUFFER_SIZE / 4];
749  size_t length;
750 
751  //Retrieve the length of the packet
752  length = netBufferGetLength(buffer) - offset;
753 
754  //Check the frame length
756  {
757  //The transmitter can accept another packet
758  osSetEvent(&interface->nicTxEvent);
759  //Report an error
760  return ERROR_INVALID_LENGTH;
761  }
762 
763  //Make sure the current buffer is available for writing
764  if((txBufferDesc[txBufferIndex][0] & ENET_TBD0_R) != 0)
765  {
766  return ERROR_FAILURE;
767  }
768 
769  //Copy user data to the transmit buffer
770  netBufferRead(temp, buffer, offset, length);
771  osMemcpy(txBuffer[txBufferIndex], temp, (length + 3) & ~3UL);
772 
773  //Clear BDU flag
774  txBufferDesc[txBufferIndex][4] = 0;
775 
776  //Check current index
777  if(txBufferIndex < (MIMXRT1170_ETH2_TX_BUFFER_COUNT - 1))
778  {
779  //Give the ownership of the descriptor to the DMA engine
780  txBufferDesc[txBufferIndex][0] = ENET_TBD0_R | ENET_TBD0_L |
782 
783  //Point to the next buffer
784  txBufferIndex++;
785  }
786  else
787  {
788  //Give the ownership of the descriptor to the DMA engine
789  txBufferDesc[txBufferIndex][0] = ENET_TBD0_R | ENET_TBD0_W |
791 
792  //Wrap around
793  txBufferIndex = 0;
794  }
795 
796  //Data synchronization barrier
797  __DSB();
798 
799  //Instruct the DMA to poll the transmit descriptor list
800  ENET_1G->TDAR = ENET_TDAR_TDAR_MASK;
801 
802  //Check whether the next buffer is available for writing
803  if((txBufferDesc[txBufferIndex][0] & ENET_TBD0_R) == 0)
804  {
805  //The transmitter can accept another packet
806  osSetEvent(&interface->nicTxEvent);
807  }
808 
809  //Successful processing
810  return NO_ERROR;
811 }
812 
813 
814 /**
815  * @brief Receive a packet
816  * @param[in] interface Underlying network interface
817  * @return Error code
818  **/
819 
821 {
822  static uint32_t temp[MIMXRT1170_ETH2_RX_BUFFER_SIZE / 4];
823  error_t error;
824  size_t n;
825  NetRxAncillary ancillary;
826 
827  //Current buffer available for reading?
828  if((rxBufferDesc[rxBufferIndex][0] & ENET_RBD0_E) == 0)
829  {
830  //The frame should not span multiple buffers
831  if((rxBufferDesc[rxBufferIndex][0] & ENET_RBD0_L) != 0)
832  {
833  //Check whether an error occurred
834  if((rxBufferDesc[rxBufferIndex][0] & (ENET_RBD0_LG | ENET_RBD0_NO |
836  {
837  //Retrieve the length of the frame
838  n = rxBufferDesc[rxBufferIndex][0] & ENET_RBD0_DATA_LENGTH;
839  //Limit the number of data to read
841 
842  //Copy data from the receive buffer
843  osMemcpy(temp, rxBuffer[rxBufferIndex], (n + 3) & ~3UL);
844 
845  //Additional options can be passed to the stack along with the packet
846  ancillary = NET_DEFAULT_RX_ANCILLARY;
847 
848  //Pass the packet to the upper layer
849  nicProcessPacket(interface, (uint8_t *) temp, n, &ancillary);
850 
851  //Valid packet received
852  error = NO_ERROR;
853  }
854  else
855  {
856  //The received packet contains an error
857  error = ERROR_INVALID_PACKET;
858  }
859  }
860  else
861  {
862  //The packet is not valid
863  error = ERROR_INVALID_PACKET;
864  }
865 
866  //Clear BDU flag
867  rxBufferDesc[rxBufferIndex][4] = 0;
868 
869  //Check current index
870  if(rxBufferIndex < (MIMXRT1170_ETH2_RX_BUFFER_COUNT - 1))
871  {
872  //Give the ownership of the descriptor back to the DMA engine
873  rxBufferDesc[rxBufferIndex][0] = ENET_RBD0_E;
874  //Point to the next buffer
875  rxBufferIndex++;
876  }
877  else
878  {
879  //Give the ownership of the descriptor back to the DMA engine
880  rxBufferDesc[rxBufferIndex][0] = ENET_RBD0_E | ENET_RBD0_W;
881  //Wrap around
882  rxBufferIndex = 0;
883  }
884 
885  //Instruct the DMA to poll the receive descriptor list
886  ENET_1G->RDAR = ENET_RDAR_RDAR_MASK;
887  }
888  else
889  {
890  //No more data in the receive buffer
891  error = ERROR_BUFFER_EMPTY;
892  }
893 
894  //Return status code
895  return error;
896 }
897 
898 
899 /**
900  * @brief Configure MAC address filtering
901  * @param[in] interface Underlying network interface
902  * @return Error code
903  **/
904 
906 {
907  uint_t i;
908  uint_t k;
909  uint32_t crc;
910  uint32_t value;
911  uint32_t unicastHashTable[2];
912  uint32_t multicastHashTable[2];
913  MacFilterEntry *entry;
914 
915  //Debug message
916  TRACE_DEBUG("Updating MAC filter...\r\n");
917 
918  //Set the MAC address of the station (upper 16 bits)
919  value = interface->macAddr.b[5];
920  value |= (interface->macAddr.b[4] << 8);
921  ENET_1G->PAUR = ENET_PAUR_PADDR2(value) | ENET_PAUR_TYPE(0x8808);
922 
923  //Set the MAC address of the station (lower 32 bits)
924  value = interface->macAddr.b[3];
925  value |= (interface->macAddr.b[2] << 8);
926  value |= (interface->macAddr.b[1] << 16);
927  value |= (interface->macAddr.b[0] << 24);
928  ENET_1G->PALR = ENET_PALR_PADDR1(value);
929 
930  //Clear hash table (unicast address filtering)
931  unicastHashTable[0] = 0;
932  unicastHashTable[1] = 0;
933 
934  //Clear hash table (multicast address filtering)
935  multicastHashTable[0] = 0;
936  multicastHashTable[1] = 0;
937 
938  //The MAC address filter contains the list of MAC addresses to accept
939  //when receiving an Ethernet frame
940  for(i = 0; i < MAC_ADDR_FILTER_SIZE; i++)
941  {
942  //Point to the current entry
943  entry = &interface->macAddrFilter[i];
944 
945  //Valid entry?
946  if(entry->refCount > 0)
947  {
948  //Compute CRC over the current MAC address
949  crc = mimxrt1170Eth2CalcCrc(&entry->addr, sizeof(MacAddr));
950 
951  //The upper 6 bits in the CRC register are used to index the
952  //contents of the hash table
953  k = (crc >> 26) & 0x3F;
954 
955  //Multicast address?
956  if(macIsMulticastAddr(&entry->addr))
957  {
958  //Update the multicast hash table
959  multicastHashTable[k / 32] |= (1 << (k % 32));
960  }
961  else
962  {
963  //Update the unicast hash table
964  unicastHashTable[k / 32] |= (1 << (k % 32));
965  }
966  }
967  }
968 
969  //Write the hash table (unicast address filtering)
970  ENET_1G->IALR = unicastHashTable[0];
971  ENET_1G->IAUR = unicastHashTable[1];
972 
973  //Write the hash table (multicast address filtering)
974  ENET_1G->GALR = multicastHashTable[0];
975  ENET_1G->GAUR = multicastHashTable[1];
976 
977  //Debug message
978  TRACE_DEBUG(" IALR = %08" PRIX32 "\r\n", ENET_1G->IALR);
979  TRACE_DEBUG(" IAUR = %08" PRIX32 "\r\n", ENET_1G->IAUR);
980  TRACE_DEBUG(" GALR = %08" PRIX32 "\r\n", ENET_1G->GALR);
981  TRACE_DEBUG(" GAUR = %08" PRIX32 "\r\n", ENET_1G->GAUR);
982 
983  //Successful processing
984  return NO_ERROR;
985 }
986 
987 
988 /**
989  * @brief Adjust MAC configuration parameters for proper operation
990  * @param[in] interface Underlying network interface
991  * @return Error code
992  **/
993 
995 {
996  //Disable Ethernet MAC while modifying configuration registers
997  ENET_1G->ECR &= ~ENET_ECR_ETHEREN_MASK;
998 
999  //1000BASE-T operation mode?
1000  if(interface->linkSpeed == NIC_LINK_SPEED_1GBPS)
1001  {
1002  ENET_1G->ECR |= ENET_ECR_SPEED_MASK;
1003  ENET_1G->RCR &= ~ENET_RCR_RMII_10T_MASK;
1004  }
1005  //100BASE-TX operation mode?
1006  else if(interface->linkSpeed == NIC_LINK_SPEED_100MBPS)
1007  {
1008  ENET_1G->ECR &= ~ENET_ECR_SPEED_MASK;
1009  ENET_1G->RCR &= ~ENET_RCR_RMII_10T_MASK;
1010  }
1011  //10BASE-T operation mode?
1012  else
1013  {
1014  ENET_1G->ECR &= ~ENET_ECR_SPEED_MASK;
1015  ENET_1G->RCR |= ENET_RCR_RMII_10T_MASK;
1016  }
1017 
1018  //Half-duplex or full-duplex mode?
1019  if(interface->duplexMode == NIC_FULL_DUPLEX_MODE)
1020  {
1021  //Full-duplex mode
1022  ENET_1G->TCR |= ENET_TCR_FDEN_MASK;
1023  //Receive path operates independently of transmit
1024  ENET_1G->RCR &= ~ENET_RCR_DRT_MASK;
1025  }
1026  else
1027  {
1028  //Half-duplex mode
1029  ENET_1G->TCR &= ~ENET_TCR_FDEN_MASK;
1030  //Disable reception of frames while transmitting
1031  ENET_1G->RCR |= ENET_RCR_DRT_MASK;
1032  }
1033 
1034  //Reset buffer descriptors
1035  mimxrt1170Eth2InitBufferDesc(interface);
1036 
1037  //Re-enable Ethernet MAC
1038  ENET_1G->ECR |= ENET_ECR_ETHEREN_MASK;
1039  //Instruct the DMA to poll the receive descriptor list
1040  ENET_1G->RDAR = ENET_RDAR_RDAR_MASK;
1041 
1042  //Successful processing
1043  return NO_ERROR;
1044 }
1045 
1046 
1047 /**
1048  * @brief Write PHY register
1049  * @param[in] opcode Access type (2 bits)
1050  * @param[in] phyAddr PHY address (5 bits)
1051  * @param[in] regAddr Register address (5 bits)
1052  * @param[in] data Register value
1053  **/
1054 
1055 void mimxrt1170Eth2WritePhyReg(uint8_t opcode, uint8_t phyAddr,
1056  uint8_t regAddr, uint16_t data)
1057 {
1058  uint32_t temp;
1059 
1060  //Valid opcode?
1061  if(opcode == SMI_OPCODE_WRITE)
1062  {
1063  //Set up a write operation
1064  temp = ENET_MMFR_ST(1) | ENET_MMFR_OP(1) | ENET_MMFR_TA(2);
1065  //PHY address
1066  temp |= ENET_MMFR_PA(phyAddr);
1067  //Register address
1068  temp |= ENET_MMFR_RA(regAddr);
1069  //Register value
1070  temp |= ENET_MMFR_DATA(data);
1071 
1072  //Clear MII interrupt flag
1073  ENET_1G->EIR = ENET_EIR_MII_MASK;
1074  //Start a write operation
1075  ENET_1G->MMFR = temp;
1076 
1077  //Wait for the write to complete
1078  while((ENET_1G->EIR & ENET_EIR_MII_MASK) == 0)
1079  {
1080  }
1081  }
1082  else
1083  {
1084  //The MAC peripheral only supports standard Clause 22 opcodes
1085  }
1086 }
1087 
1088 
1089 /**
1090  * @brief Read PHY register
1091  * @param[in] opcode Access type (2 bits)
1092  * @param[in] phyAddr PHY address (5 bits)
1093  * @param[in] regAddr Register address (5 bits)
1094  * @return Register value
1095  **/
1096 
1097 uint16_t mimxrt1170Eth2ReadPhyReg(uint8_t opcode, uint8_t phyAddr,
1098  uint8_t regAddr)
1099 {
1100  uint16_t data;
1101  uint32_t temp;
1102 
1103  //Valid opcode?
1104  if(opcode == SMI_OPCODE_READ)
1105  {
1106  //Set up a read operation
1107  temp = ENET_MMFR_ST(1) | ENET_MMFR_OP(2) | ENET_MMFR_TA(2);
1108  //PHY address
1109  temp |= ENET_MMFR_PA(phyAddr);
1110  //Register address
1111  temp |= ENET_MMFR_RA(regAddr);
1112 
1113  //Clear MII interrupt flag
1114  ENET_1G->EIR = ENET_EIR_MII_MASK;
1115  //Start a read operation
1116  ENET_1G->MMFR = temp;
1117 
1118  //Wait for the read to complete
1119  while((ENET_1G->EIR & ENET_EIR_MII_MASK) == 0)
1120  {
1121  }
1122 
1123  //Get register value
1124  data = ENET_1G->MMFR & ENET_MMFR_DATA_MASK;
1125  }
1126  else
1127  {
1128  //The MAC peripheral only supports standard Clause 22 opcodes
1129  data = 0;
1130  }
1131 
1132  //Return the value of the PHY register
1133  return data;
1134 }
1135 
1136 
1137 /**
1138  * @brief CRC calculation
1139  * @param[in] data Pointer to the data over which to calculate the CRC
1140  * @param[in] length Number of bytes to process
1141  * @return Resulting CRC value
1142  **/
1143 
1144 uint32_t mimxrt1170Eth2CalcCrc(const void *data, size_t length)
1145 {
1146  uint_t i;
1147  uint_t j;
1148  uint32_t crc;
1149  const uint8_t *p;
1150 
1151  //Point to the data over which to calculate the CRC
1152  p = (uint8_t *) data;
1153  //CRC preset value
1154  crc = 0xFFFFFFFF;
1155 
1156  //Loop through data
1157  for(i = 0; i < length; i++)
1158  {
1159  //Update CRC value
1160  crc ^= p[i];
1161 
1162  //The message is processed bit by bit
1163  for(j = 0; j < 8; j++)
1164  {
1165  if((crc & 0x01) != 0)
1166  {
1167  crc = (crc >> 1) ^ 0xEDB88320;
1168  }
1169  else
1170  {
1171  crc = crc >> 1;
1172  }
1173  }
1174  }
1175 
1176  //Return CRC value
1177  return crc;
1178 }
#define rxBuffer
#define txBuffer
__attribute__((naked))
AVR32 Ethernet MAC interrupt wrapper.
unsigned int uint_t
Definition: compiler_port.h:50
int bool_t
Definition: compiler_port.h:53
Debugging facilities.
#define TRACE_DEBUG(...)
Definition: debug.h:107
#define TRACE_INFO(...)
Definition: debug.h:95
uint8_t n
uint8_t opcode
Definition: dns_common.h:188
error_t
Error codes.
Definition: error.h:43
@ ERROR_BUFFER_EMPTY
Definition: error.h:141
@ NO_ERROR
Success.
Definition: error.h:44
@ ERROR_INVALID_PACKET
Definition: error.h:140
@ ERROR_INVALID_LENGTH
Definition: error.h:111
@ ERROR_FAILURE
Generic error code.
Definition: error.h:45
#define macIsMulticastAddr(macAddr)
Definition: ethernet.h:133
#define ETH_MTU
Definition: ethernet.h:116
uint8_t data[]
Definition: ethernet.h:222
MacAddr
Definition: ethernet.h:195
#define MAC_ADDR_FILTER_SIZE
Definition: ethernet.h:95
Ipv6Addr address[]
Definition: ipv6.h:316
#define ENET_RBD0_E
#define ENET_RBD0_DATA_LENGTH
#define ENET_TBD2_INT
#define ENET_TBD0_W
#define ENET_TBD0_R
#define ENET_RBD0_L
#define ENET_RBD0_NO
#define ENET_RBD0_W
#define ENET_RBD0_LG
#define ENET_TBD0_DATA_LENGTH
#define ENET_RBD2_INT
#define ENET_RBD0_OV
#define ENET_TBD0_TC
#define ENET_RBD0_CR
#define ENET_TBD0_L
#define ENET_RBD0_TR
error_t mimxrt1170Eth2UpdateMacConfig(NetInterface *interface)
Adjust MAC configuration parameters for proper operation.
error_t mimxrt1170Eth2ReceivePacket(NetInterface *interface)
Receive a packet.
void mimxrt1170Eth2DisableIrq(NetInterface *interface)
Disable interrupts.
void ENET_1G_IRQHandler(void)
Ethernet MAC interrupt.
uint16_t mimxrt1170Eth2ReadPhyReg(uint8_t opcode, uint8_t phyAddr, uint8_t regAddr)
Read PHY register.
void mimxrt1170Eth2InitBufferDesc(NetInterface *interface)
Initialize buffer descriptors.
uint32_t mimxrt1170Eth2CalcCrc(const void *data, size_t length)
CRC calculation.
const NicDriver mimxrt1170Eth2Driver
i.MX RT1170 Ethernet MAC driver (ENET_1G instance)
error_t mimxrt1170Eth2Init(NetInterface *interface)
i.MX RT1170 Ethernet MAC initialization
error_t mimxrt1170Eth2SendPacket(NetInterface *interface, const NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary)
Send a packet.
void mimxrt1170Eth2EnableIrq(NetInterface *interface)
Enable interrupts.
void mimxrt1170Eth2WritePhyReg(uint8_t opcode, uint8_t phyAddr, uint8_t regAddr, uint16_t data)
Write PHY register.
void mimxrt1170Eth2EventHandler(NetInterface *interface)
i.MX RT1170 Ethernet MAC event handler
__weak_func void mimxrt1170Eth2InitGpio(NetInterface *interface)
GPIO configuration.
error_t mimxrt1170Eth2UpdateMacAddrFilter(NetInterface *interface)
Configure MAC address filtering.
void mimxrt1170Eth2Tick(NetInterface *interface)
i.MX RT1170 Ethernet MAC timer handler
NXP i.MX RT1170 Gigabit Ethernet MAC driver (ENET_1G instance)
#define MIMXRT1170_ETH2_RX_BUFFER_COUNT
#define MIMXRT1170_ETH2_IRQ_SUB_PRIORITY
#define MIMXRT1170_ETH2_TX_BUFFER_COUNT
#define MIMXRT1170_ETH2_RX_BUFFER_SIZE
#define MIMXRT1170_ETH2_RAM_SECTION
#define MIMXRT1170_ETH2_IRQ_PRIORITY_GROUPING
#define MIMXRT1170_ETH2_TX_BUFFER_SIZE
#define MIMXRT1170_ETH2_IRQ_GROUP_PRIORITY
uint16_t regAddr
uint8_t p
Definition: ndp.h:300
TCP/IP stack core.
#define NetInterface
Definition: net.h:36
#define netEvent
Definition: net_legacy.h:196
size_t netBufferGetLength(const NetBuffer *buffer)
Get the actual length of a multi-part buffer.
Definition: net_mem.c:297
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:674
const NetRxAncillary NET_DEFAULT_RX_ANCILLARY
Definition: net_misc.c:101
#define NetRxAncillary
Definition: net_misc.h:40
#define NetTxAncillary
Definition: net_misc.h:36
void nicProcessPacket(NetInterface *interface, uint8_t *packet, size_t length, NetRxAncillary *ancillary)
Handle a packet received by the network controller.
Definition: nic.c:391
#define SMI_OPCODE_WRITE
Definition: nic.h:66
@ NIC_TYPE_ETHERNET
Ethernet interface.
Definition: nic.h:83
#define SMI_OPCODE_READ
Definition: nic.h:67
@ NIC_FULL_DUPLEX_MODE
Definition: nic.h:125
@ NIC_LINK_SPEED_100MBPS
Definition: nic.h:112
@ NIC_LINK_SPEED_1GBPS
Definition: nic.h:113
#define osMemset(p, value, length)
Definition: os_port.h:135
#define osMemcpy(dest, src, length)
Definition: os_port.h:141
#define MIN(a, b)
Definition: os_port.h:63
#define TRUE
Definition: os_port.h:50
#define FALSE
Definition: os_port.h:46
#define sleep(delay)
Definition: os_port.h:301
bool_t osSetEventFromIsr(OsEvent *event)
Set an event object to the signaled state from an interrupt service routine.
void osSetEvent(OsEvent *event)
Set the specified event object to the signaled state.
#define osEnterIsr()
#define osExitIsr(flag)
MAC filter table entry.
Definition: ethernet.h:262
MacAddr addr
MAC address.
Definition: ethernet.h:263
uint_t refCount
Reference count for the current entry.
Definition: ethernet.h:264
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:89
NIC driver.
Definition: nic.h:283
uint8_t length
Definition: tcp.h:368
uint8_t value[]
Definition: tcp.h:369