same54_eth_driver.c
Go to the documentation of this file.
1 /**
2  * @file same54_eth_driver.c
3  * @brief SAME54 Ethernet MAC driver
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2025 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.5.4
29  **/
30 
31 //Switch to the appropriate trace level
32 #define TRACE_LEVEL NIC_TRACE_LEVEL
33 
34 //Dependencies
35 #include <limits.h>
36 #include "sam.h"
37 #include "core/net.h"
39 #include "debug.h"
40 
41 //Underlying network interface
42 static NetInterface *nicDriverInterface;
43 
44 //IAR EWARM compiler?
45 #if defined(__ICCARM__)
46 
47 //TX buffer
48 #pragma data_alignment = 8
50 //RX buffer
51 #pragma data_alignment = 8
53 //TX buffer descriptors
54 #pragma data_alignment = 4
56 //RX buffer descriptors
57 #pragma data_alignment = 4
59 
60 //Keil MDK-ARM or GCC compiler?
61 #else
62 
63 //TX buffer
65  __attribute__((aligned(8)));
66 //RX buffer
68  __attribute__((aligned(8)));
69 //TX buffer descriptors
71  __attribute__((aligned(4)));
72 //RX buffer descriptors
74  __attribute__((aligned(4)));
75 
76 #endif
77 
78 //TX buffer index
79 static uint_t txBufferIndex;
80 //RX buffer index
81 static uint_t rxBufferIndex;
82 
83 
84 /**
85  * @brief SAME54 Ethernet MAC driver
86  **/
87 
89 {
91  ETH_MTU,
102  TRUE,
103  TRUE,
104  TRUE,
105  FALSE
106 };
107 
108 
109 /**
110  * @brief SAME54 Ethernet MAC initialization
111  * @param[in] interface Underlying network interface
112  * @return Error code
113  **/
114 
116 {
117  error_t error;
118  volatile uint32_t status;
119 
120  //Debug message
121  TRACE_INFO("Initializing SAME54 Ethernet MAC...\r\n");
122 
123  //Save underlying network interface
124  nicDriverInterface = interface;
125 
126  //Enable GMAC bus clocks (CLK_GMAC_APB and CLK_GMAC_AHB)
127  MCLK_REGS->MCLK_APBCMASK |= MCLK_APBCMASK_GMAC_Msk;
128  MCLK_REGS->MCLK_AHBMASK |= MCLK_AHBMASK_GMAC_Msk;
129 
130  //Disable transmit and receive circuits
131  GMAC_REGS->GMAC_NCR = 0;
132 
133  //GPIO configuration
134  same54EthInitGpio(interface);
135 
136  //Configure MDC clock speed
137  GMAC_REGS->GMAC_NCFGR = GMAC_NCFGR_CLK(5);
138  //Enable management port (MDC and MDIO)
139  GMAC_REGS->GMAC_NCR |= GMAC_NCR_MPE_Msk;
140 
141  //Valid Ethernet PHY or switch driver?
142  if(interface->phyDriver != NULL)
143  {
144  //Ethernet PHY initialization
145  error = interface->phyDriver->init(interface);
146  }
147  else if(interface->switchDriver != NULL)
148  {
149  //Ethernet switch initialization
150  error = interface->switchDriver->init(interface);
151  }
152  else
153  {
154  //The interface is not properly configured
155  error = ERROR_FAILURE;
156  }
157 
158  //Any error to report?
159  if(error)
160  {
161  return error;
162  }
163 
164  //Set the MAC address of the station
165  GMAC_REGS->SA[0].GMAC_SAB = interface->macAddr.w[0] | (interface->macAddr.w[1] << 16);
166  GMAC_REGS->SA[0].GMAC_SAT = interface->macAddr.w[2];
167 
168  //The MAC supports 3 additional addresses for unicast perfect filtering
169  GMAC_REGS->SA[1].GMAC_SAB = 0;
170  GMAC_REGS->SA[2].GMAC_SAB = 0;
171  GMAC_REGS->SA[3].GMAC_SAB = 0;
172 
173  //Initialize hash table
174  GMAC_REGS->GMAC_HRB = 0;
175  GMAC_REGS->GMAC_HRT = 0;
176 
177  //Configure the receive filter
179 
180  //Initialize buffer descriptors
181  same54EthInitBufferDesc(interface);
182 
183  //Clear transmit status register
187 
188  //Clear receive status register
191 
192  //First disable all GMAC interrupts
193  GMAC_REGS->GMAC_IDR = 0xFFFFFFFF;
194 
195  //Only the desired ones are enabled
199 
200  //Read GMAC_ISR register to clear any pending interrupt
201  status = GMAC_REGS->GMAC_ISR;
202  (void) status;
203 
204  //Set priority grouping (3 bits for pre-emption priority, no bits for subpriority)
205  NVIC_SetPriorityGrouping(SAME54_ETH_IRQ_PRIORITY_GROUPING);
206 
207  //Configure GMAC interrupt priority
208  NVIC_SetPriority(GMAC_IRQn, NVIC_EncodePriority(SAME54_ETH_IRQ_PRIORITY_GROUPING,
210 
211  //Enable the GMAC to transmit and receive data
213 
214  //Accept any packets from the upper layer
215  osSetEvent(&interface->nicTxEvent);
216 
217  //Successful initialization
218  return NO_ERROR;
219 }
220 
221 
222 /**
223  * @brief GPIO configuration
224  * @param[in] interface Underlying network interface
225  **/
226 
227 __weak_func void same54EthInitGpio(NetInterface *interface)
228 {
229 //SAME54-Xplained-Pro evaluation board?
230 #if defined(USE_SAME54_XPLAINED_PRO)
231  uint32_t temp;
232 
233  //Enable PORT bus clock (CLK_PORT_APB)
234  MCLK_REGS->MCLK_APBBMASK |= MCLK_APBBMASK_PORT_Msk;
235 
236  //Configure GRX1 (PA12)
237  PORT_REGS->GROUP[0].PORT_PINCFG[12] |= PORT_PINCFG_PMUXEN_Msk;
238  temp = PORT_REGS->GROUP[0].PORT_PMUX[6] & ~PORT_PMUX_PMUXE_Msk;
239  PORT_REGS->GROUP[0].PORT_PMUX[6] = temp | PORT_PMUX_PMUXE(MUX_PA12L_GMAC_GRX1);
240 
241  //Configure GRX0 (PA13)
242  PORT_REGS->GROUP[0].PORT_PINCFG[13] |= PORT_PINCFG_PMUXEN_Msk;
243  temp = PORT_REGS->GROUP[0].PORT_PMUX[6] & ~PORT_PMUX_PMUXO_Msk;
244  PORT_REGS->GROUP[0].PORT_PMUX[6] = temp | PORT_PMUX_PMUXO(MUX_PA13L_GMAC_GRX0);
245 
246  //Configure GTXCK (PA14)
247  PORT_REGS->GROUP[0].PORT_PINCFG[14] |= PORT_PINCFG_PMUXEN_Msk;
248  temp = PORT_REGS->GROUP[0].PORT_PMUX[7] & ~PORT_PMUX_PMUXE_Msk;
249  PORT_REGS->GROUP[0].PORT_PMUX[7] = temp | PORT_PMUX_PMUXE(MUX_PA14L_GMAC_GTXCK);
250 
251  //Configure GRXER (PA15)
252  PORT_REGS->GROUP[0].PORT_PINCFG[15] |= PORT_PINCFG_PMUXEN_Msk;
253  temp = PORT_REGS->GROUP[0].PORT_PMUX[7] & ~PORT_PMUX_PMUXO_Msk;
254  PORT_REGS->GROUP[0].PORT_PMUX[7] = temp | PORT_PMUX_PMUXO(MUX_PA15L_GMAC_GRXER);
255 
256  //Configure GTXEN (PA17)
257  PORT_REGS->GROUP[0].PORT_PINCFG[17] |= PORT_PINCFG_DRVSTR_Msk;
258  PORT_REGS->GROUP[0].PORT_PINCFG[17] |= PORT_PINCFG_PMUXEN_Msk;
259  temp = PORT_REGS->GROUP[0].PORT_PMUX[8] & ~PORT_PMUX_PMUXO_Msk;
260  PORT_REGS->GROUP[0].PORT_PMUX[8] = temp | PORT_PMUX_PMUXO(MUX_PA17L_GMAC_GTXEN);
261 
262  //Configure GTX0 (PA18)
263  PORT_REGS->GROUP[0].PORT_PINCFG[18] |= PORT_PINCFG_DRVSTR_Msk;
264  PORT_REGS->GROUP[0].PORT_PINCFG[18] |= PORT_PINCFG_PMUXEN_Msk;
265  temp = PORT_REGS->GROUP[0].PORT_PMUX[9] & ~PORT_PMUX_PMUXE_Msk;
266  PORT_REGS->GROUP[0].PORT_PMUX[9] = temp | PORT_PMUX_PMUXE(MUX_PA18L_GMAC_GTX0);
267 
268  //Configure GTX1 (PA19)
269  PORT_REGS->GROUP[0].PORT_PINCFG[19] |= PORT_PINCFG_DRVSTR_Msk;
270  PORT_REGS->GROUP[0].PORT_PINCFG[19] |= PORT_PINCFG_PMUXEN_Msk;
271  temp = PORT_REGS->GROUP[0].PORT_PMUX[9] & ~PORT_PMUX_PMUXO_Msk;
272  PORT_REGS->GROUP[0].PORT_PMUX[9] = temp | PORT_PMUX_PMUXO(MUX_PA19L_GMAC_GTX1);
273 
274  //Configure GMDC (PC11)
275  PORT_REGS->GROUP[2].PORT_PINCFG[11] |= PORT_PINCFG_PMUXEN_Msk;
276  temp = PORT_REGS->GROUP[2].PORT_PMUX[5] & ~PORT_PMUX_PMUXO_Msk;
277  PORT_REGS->GROUP[2].PORT_PMUX[5] = temp | PORT_PMUX_PMUXO(MUX_PC11L_GMAC_GMDC);
278 
279  //Configure GMDIO (PC12)
280  PORT_REGS->GROUP[2].PORT_PINCFG[12] |= PORT_PINCFG_PMUXEN_Msk;
281  temp = PORT_REGS->GROUP[2].PORT_PMUX[6] & ~PORT_PMUX_PMUXE_Msk;
282  PORT_REGS->GROUP[2].PORT_PMUX[6] = temp | PORT_PMUX_PMUXE(MUX_PC12L_GMAC_GMDIO);
283 
284  //Configure GRXDV (PC20)
285  PORT_REGS->GROUP[2].PORT_PINCFG[20] |= PORT_PINCFG_PMUXEN_Msk;
286  temp = PORT_REGS->GROUP[2].PORT_PMUX[10] & ~PORT_PMUX_PMUXE_Msk;
287  PORT_REGS->GROUP[2].PORT_PMUX[10] = temp | PORT_PMUX_PMUXE(MUX_PC20L_GMAC_GRXDV);
288 
289  //Select RMII operation mode
290  GMAC_REGS->GMAC_UR &= ~GMAC_UR_MII_Msk;
291 
292  //Configure PHY_RESET (PC21) as an output
293  PORT_REGS->GROUP[2].PORT_DIRSET = PORT_PC21;
294 
295  //Reset PHY transceiver
296  PORT_REGS->GROUP[2].PORT_OUTCLR = PORT_PC21;
297  sleep(10);
298  PORT_REGS->GROUP[2].PORT_OUTSET = PORT_PC21;
299  sleep(10);
300 
301 //SAME54-Curiosity-Ultra evaluation board?
302 #elif defined(USE_SAME54_CURIOSITY_ULTRA)
303  uint32_t temp;
304 
305  //Enable PORT bus clock (CLK_PORT_APB)
306  MCLK_REGS->MCLK_APBBMASK |= MCLK_APBBMASK_PORT_Msk;
307 
308  //Configure GRX1 (PA12)
309  PORT_REGS->GROUP[0].PORT_PINCFG[12] |= PORT_PINCFG_PMUXEN_Msk;
310  temp = PORT_REGS->GROUP[0].PORT_PMUX[6] & ~PORT_PMUX_PMUXE_Msk;
311  PORT_REGS->GROUP[0].PORT_PMUX[6] = temp | PORT_PMUX_PMUXE(MUX_PA12L_GMAC_GRX1);
312 
313  //Configure GRX0 (PA13)
314  PORT_REGS->GROUP[0].PORT_PINCFG[13] |= PORT_PINCFG_PMUXEN_Msk;
315  temp = PORT_REGS->GROUP[0].PORT_PMUX[6] & ~PORT_PMUX_PMUXO_Msk;
316  PORT_REGS->GROUP[0].PORT_PMUX[6] = temp | PORT_PMUX_PMUXO(MUX_PA13L_GMAC_GRX0);
317 
318  //Configure GTXCK (PA14)
319  PORT_REGS->GROUP[0].PORT_PINCFG[14] |= PORT_PINCFG_PMUXEN_Msk;
320  temp = PORT_REGS->GROUP[0].PORT_PMUX[7] & ~PORT_PMUX_PMUXE_Msk;
321  PORT_REGS->GROUP[0].PORT_PMUX[7] = temp | PORT_PMUX_PMUXE(MUX_PA14L_GMAC_GTXCK);
322 
323  //Configure GRXER (PA15)
324  PORT_REGS->GROUP[0].PORT_PINCFG[15] |= PORT_PINCFG_PMUXEN_Msk;
325  temp = PORT_REGS->GROUP[0].PORT_PMUX[7] & ~PORT_PMUX_PMUXO_Msk;
326  PORT_REGS->GROUP[0].PORT_PMUX[7] = temp | PORT_PMUX_PMUXO(MUX_PA15L_GMAC_GRXER);
327 
328  //Configure GTXEN (PA17)
329  PORT_REGS->GROUP[0].PORT_PINCFG[17] |= PORT_PINCFG_DRVSTR_Msk;
330  PORT_REGS->GROUP[0].PORT_PINCFG[17] |= PORT_PINCFG_PMUXEN_Msk;
331  temp = PORT_REGS->GROUP[0].PORT_PMUX[8] & ~PORT_PMUX_PMUXO_Msk;
332  PORT_REGS->GROUP[0].PORT_PMUX[8] = temp | PORT_PMUX_PMUXO(MUX_PA17L_GMAC_GTXEN);
333 
334  //Configure GTX0 (PA18)
335  PORT_REGS->GROUP[0].PORT_PINCFG[18] |= PORT_PINCFG_DRVSTR_Msk;
336  PORT_REGS->GROUP[0].PORT_PINCFG[18] |= PORT_PINCFG_PMUXEN_Msk;
337  temp = PORT_REGS->GROUP[0].PORT_PMUX[9] & ~PORT_PMUX_PMUXE_Msk;
338  PORT_REGS->GROUP[0].PORT_PMUX[9] = temp | PORT_PMUX_PMUXE(MUX_PA18L_GMAC_GTX0);
339 
340  //Configure GTX1 (PA19)
341  PORT_REGS->GROUP[0].PORT_PINCFG[19] |= PORT_PINCFG_DRVSTR_Msk;
342  PORT_REGS->GROUP[0].PORT_PINCFG[19] |= PORT_PINCFG_PMUXEN_Msk;
343  temp = PORT_REGS->GROUP[0].PORT_PMUX[9] & ~PORT_PMUX_PMUXO_Msk;
344  PORT_REGS->GROUP[0].PORT_PMUX[9] = temp | PORT_PMUX_PMUXO(MUX_PA19L_GMAC_GTX1);
345 
346  //Configure GRXDV (PC20)
347  PORT_REGS->GROUP[2].PORT_PINCFG[20] |= PORT_PINCFG_PMUXEN_Msk;
348  temp = PORT_REGS->GROUP[2].PORT_PMUX[10] & ~PORT_PMUX_PMUXE_Msk;
349  PORT_REGS->GROUP[2].PORT_PMUX[10] = temp | PORT_PMUX_PMUXE(MUX_PC20L_GMAC_GRXDV);
350 
351  //Configure GMDC (PC22)
352  PORT_REGS->GROUP[2].PORT_PINCFG[22] |= PORT_PINCFG_PMUXEN_Msk;
353  temp = PORT_REGS->GROUP[2].PORT_PMUX[11] & ~PORT_PMUX_PMUXE_Msk;
354  PORT_REGS->GROUP[2].PORT_PMUX[11] = temp | PORT_PMUX_PMUXE(MUX_PC22L_GMAC_GMDC);
355 
356  //Configure GMDIO (PC23)
357  PORT_REGS->GROUP[2].PORT_PINCFG[23] |= PORT_PINCFG_PMUXEN_Msk;
358  temp = PORT_REGS->GROUP[2].PORT_PMUX[11] & ~PORT_PMUX_PMUXO_Msk;
359  PORT_REGS->GROUP[2].PORT_PMUX[11] = temp | PORT_PMUX_PMUXO(MUX_PC23L_GMAC_GMDIO);
360 
361  //Select RMII operation mode
362  GMAC_REGS->GMAC_UR &= ~GMAC_UR_MII_Msk;
363 
364  //Configure PHY_RESET (PC18) as an output
365  PORT_REGS->GROUP[2].PORT_DIRSET = PORT_PC18;
366 
367  //Reset PHY transceiver
368  PORT_REGS->GROUP[2].PORT_OUTCLR = PORT_PC18;
369  sleep(10);
370  PORT_REGS->GROUP[2].PORT_OUTSET = PORT_PC18;
371  sleep(10);
372 
373 //SAME54-Curiosity-Ultra-v2 evaluation board?
374 #elif defined(USE_SAME54_CURIOSITY_ULTRA_V2)
375  uint32_t temp;
376 
377  //Enable PORT bus clock (CLK_PORT_APB)
378  MCLK_REGS->MCLK_APBBMASK |= MCLK_APBBMASK_PORT_Msk;
379 
380  //Configure GRX1 (PA12)
381  PORT_REGS->GROUP[0].PORT_PINCFG[12] |= PORT_PINCFG_PMUXEN_Msk;
382  temp = PORT_REGS->GROUP[0].PORT_PMUX[6] & ~PORT_PMUX_PMUXE_Msk;
383  PORT_REGS->GROUP[0].PORT_PMUX[6] = temp | PORT_PMUX_PMUXE(MUX_PA12L_GMAC_GRX1);
384 
385  //Configure GRX0 (PA13)
386  PORT_REGS->GROUP[0].PORT_PINCFG[13] |= PORT_PINCFG_PMUXEN_Msk;
387  temp = PORT_REGS->GROUP[0].PORT_PMUX[6] & ~PORT_PMUX_PMUXO_Msk;
388  PORT_REGS->GROUP[0].PORT_PMUX[6] = temp | PORT_PMUX_PMUXO(MUX_PA13L_GMAC_GRX0);
389 
390  //Configure GTXCK (PA14)
391  PORT_REGS->GROUP[0].PORT_PINCFG[14] |= PORT_PINCFG_PMUXEN_Msk;
392  temp = PORT_REGS->GROUP[0].PORT_PMUX[7] & ~PORT_PMUX_PMUXE_Msk;
393  PORT_REGS->GROUP[0].PORT_PMUX[7] = temp | PORT_PMUX_PMUXE(MUX_PA14L_GMAC_GTXCK);
394 
395  //Configure GRXER (PA15)
396  PORT_REGS->GROUP[0].PORT_PINCFG[15] |= PORT_PINCFG_PMUXEN_Msk;
397  temp = PORT_REGS->GROUP[0].PORT_PMUX[7] & ~PORT_PMUX_PMUXO_Msk;
398  PORT_REGS->GROUP[0].PORT_PMUX[7] = temp | PORT_PMUX_PMUXO(MUX_PA15L_GMAC_GRXER);
399 
400  //Configure GTXEN (PA17)
401  PORT_REGS->GROUP[0].PORT_PINCFG[17] |= PORT_PINCFG_DRVSTR_Msk;
402  PORT_REGS->GROUP[0].PORT_PINCFG[17] |= PORT_PINCFG_PMUXEN_Msk;
403  temp = PORT_REGS->GROUP[0].PORT_PMUX[8] & ~PORT_PMUX_PMUXO_Msk;
404  PORT_REGS->GROUP[0].PORT_PMUX[8] = temp | PORT_PMUX_PMUXO(MUX_PA17L_GMAC_GTXEN);
405 
406  //Configure GTX0 (PA18)
407  PORT_REGS->GROUP[0].PORT_PINCFG[18] |= PORT_PINCFG_DRVSTR_Msk;
408  PORT_REGS->GROUP[0].PORT_PINCFG[18] |= PORT_PINCFG_PMUXEN_Msk;
409  temp = PORT_REGS->GROUP[0].PORT_PMUX[9] & ~PORT_PMUX_PMUXE_Msk;
410  PORT_REGS->GROUP[0].PORT_PMUX[9] = temp | PORT_PMUX_PMUXE(MUX_PA18L_GMAC_GTX0);
411 
412  //Configure GTX1 (PA19)
413  PORT_REGS->GROUP[0].PORT_PINCFG[19] |= PORT_PINCFG_DRVSTR_Msk;
414  PORT_REGS->GROUP[0].PORT_PINCFG[19] |= PORT_PINCFG_PMUXEN_Msk;
415  temp = PORT_REGS->GROUP[0].PORT_PMUX[9] & ~PORT_PMUX_PMUXO_Msk;
416  PORT_REGS->GROUP[0].PORT_PMUX[9] = temp | PORT_PMUX_PMUXO(MUX_PA19L_GMAC_GTX1);
417 
418  //Configure GRXDV (PC20)
419  PORT_REGS->GROUP[2].PORT_PINCFG[20] |= PORT_PINCFG_PMUXEN_Msk;
420  temp = PORT_REGS->GROUP[2].PORT_PMUX[10] & ~PORT_PMUX_PMUXE_Msk;
421  PORT_REGS->GROUP[2].PORT_PMUX[10] = temp | PORT_PMUX_PMUXE(MUX_PC20L_GMAC_GRXDV);
422 
423  //Configure GMDC (PC22)
424  PORT_REGS->GROUP[2].PORT_PINCFG[22] |= PORT_PINCFG_PMUXEN_Msk;
425  temp = PORT_REGS->GROUP[2].PORT_PMUX[11] & ~PORT_PMUX_PMUXE_Msk;
426  PORT_REGS->GROUP[2].PORT_PMUX[11] = temp | PORT_PMUX_PMUXE(MUX_PC22L_GMAC_GMDC);
427 
428  //Configure GMDIO (PC23)
429  PORT_REGS->GROUP[2].PORT_PINCFG[23] |= PORT_PINCFG_PMUXEN_Msk;
430  temp = PORT_REGS->GROUP[2].PORT_PMUX[11] & ~PORT_PMUX_PMUXO_Msk;
431  PORT_REGS->GROUP[2].PORT_PMUX[11] = temp | PORT_PMUX_PMUXO(MUX_PC23L_GMAC_GMDIO);
432 
433  //Select RMII operation mode
434  GMAC_REGS->GMAC_UR &= ~GMAC_UR_MII_Msk;
435 
436  //Configure PHY_RESET (PC18) as an output
437  PORT_REGS->GROUP[2].PORT_DIRSET = PORT_PC18;
438 
439  //Reset PHY transceiver
440  PORT_REGS->GROUP[2].PORT_OUTCLR = PORT_PC18;
441  sleep(10);
442  PORT_REGS->GROUP[2].PORT_OUTSET = PORT_PC18;
443  sleep(10);
444 #endif
445 }
446 
447 
448 /**
449  * @brief Initialize buffer descriptors
450  * @param[in] interface Underlying network interface
451  **/
452 
454 {
455  uint_t i;
456  uint32_t address;
457 
458  //Initialize TX buffer descriptors
459  for(i = 0; i < SAME54_ETH_TX_BUFFER_COUNT; i++)
460  {
461  //Calculate the address of the current TX buffer
462  address = (uint32_t) txBuffer[i];
463  //Write the address to the descriptor entry
464  txBufferDesc[i].address = address;
465  //Initialize status field
466  txBufferDesc[i].status = GMAC_TX_USED;
467  }
468 
469  //Mark the last descriptor entry with the wrap flag
470  txBufferDesc[i - 1].status |= GMAC_TX_WRAP;
471  //Initialize TX buffer index
472  txBufferIndex = 0;
473 
474  //Initialize RX buffer descriptors
475  for(i = 0; i < SAME54_ETH_RX_BUFFER_COUNT; i++)
476  {
477  //Calculate the address of the current RX buffer
478  address = (uint32_t) rxBuffer[i];
479  //Write the address to the descriptor entry
480  rxBufferDesc[i].address = address & GMAC_RX_ADDRESS;
481  //Clear status field
482  rxBufferDesc[i].status = 0;
483  }
484 
485  //Mark the last descriptor entry with the wrap flag
486  rxBufferDesc[i - 1].address |= GMAC_RX_WRAP;
487  //Initialize RX buffer index
488  rxBufferIndex = 0;
489 
490  //Start location of the TX descriptor list
491  GMAC_REGS->GMAC_TBQB = (uint32_t) txBufferDesc;
492  //Start location of the RX descriptor list
493  GMAC_REGS->GMAC_RBQB = (uint32_t) rxBufferDesc;
494 }
495 
496 
497 /**
498  * @brief SAME54 Ethernet MAC timer handler
499  *
500  * This routine is periodically called by the TCP/IP stack to handle periodic
501  * operations such as polling the link state
502  *
503  * @param[in] interface Underlying network interface
504  **/
505 
506 void same54EthTick(NetInterface *interface)
507 {
508  //Valid Ethernet PHY or switch driver?
509  if(interface->phyDriver != NULL)
510  {
511  //Handle periodic operations
512  interface->phyDriver->tick(interface);
513  }
514  else if(interface->switchDriver != NULL)
515  {
516  //Handle periodic operations
517  interface->switchDriver->tick(interface);
518  }
519  else
520  {
521  //Just for sanity
522  }
523 }
524 
525 
526 /**
527  * @brief Enable interrupts
528  * @param[in] interface Underlying network interface
529  **/
530 
532 {
533  //Enable Ethernet MAC interrupts
534  NVIC_EnableIRQ(GMAC_IRQn);
535 
536  //Valid Ethernet PHY or switch driver?
537  if(interface->phyDriver != NULL)
538  {
539  //Enable Ethernet PHY interrupts
540  interface->phyDriver->enableIrq(interface);
541  }
542  else if(interface->switchDriver != NULL)
543  {
544  //Enable Ethernet switch interrupts
545  interface->switchDriver->enableIrq(interface);
546  }
547  else
548  {
549  //Just for sanity
550  }
551 }
552 
553 
554 /**
555  * @brief Disable interrupts
556  * @param[in] interface Underlying network interface
557  **/
558 
560 {
561  //Disable Ethernet MAC interrupts
562  NVIC_DisableIRQ(GMAC_IRQn);
563 
564  //Valid Ethernet PHY or switch driver?
565  if(interface->phyDriver != NULL)
566  {
567  //Disable Ethernet PHY interrupts
568  interface->phyDriver->disableIrq(interface);
569  }
570  else if(interface->switchDriver != NULL)
571  {
572  //Disable Ethernet switch interrupts
573  interface->switchDriver->disableIrq(interface);
574  }
575  else
576  {
577  //Just for sanity
578  }
579 }
580 
581 
582 /**
583  * @brief SAME54 Ethernet MAC interrupt service routine
584  **/
585 
586 void GMAC_Handler(void)
587 {
588  bool_t flag;
589  volatile uint32_t isr;
590  volatile uint32_t tsr;
591  volatile uint32_t rsr;
592 
593  //Interrupt service routine prologue
594  osEnterIsr();
595 
596  //This flag will be set if a higher priority task must be woken
597  flag = FALSE;
598 
599  //Each time the software reads GMAC_ISR, it has to check the contents
600  //of GMAC_TSR, GMAC_RSR and GMAC_NSR
601  isr = GMAC_REGS->GMAC_ISR;
602  tsr = GMAC_REGS->GMAC_TSR;
603  rsr = GMAC_REGS->GMAC_RSR;
604  (void) isr;
605 
606  //Packet transmitted?
607  if((tsr & (GMAC_TSR_HRESP_Msk | GMAC_TSR_UND_Msk |
610  {
611  //Only clear TSR flags that are currently set
612  GMAC_REGS->GMAC_TSR = tsr;
613 
614  //Check whether the TX buffer is available for writing
615  if((txBufferDesc[txBufferIndex].status & GMAC_TX_USED) != 0)
616  {
617  //Notify the TCP/IP stack that the transmitter is ready to send
618  flag |= osSetEventFromIsr(&nicDriverInterface->nicTxEvent);
619  }
620  }
621 
622  //Packet received?
624  GMAC_RSR_BNA_Msk)) != 0)
625  {
626  //Set event flag
627  nicDriverInterface->nicEvent = TRUE;
628  //Notify the TCP/IP stack of the event
629  flag |= osSetEventFromIsr(&netEvent);
630  }
631 
632  //Interrupt service routine epilogue
633  osExitIsr(flag);
634 }
635 
636 
637 /**
638  * @brief SAME54 Ethernet MAC event handler
639  * @param[in] interface Underlying network interface
640  **/
641 
643 {
644  error_t error;
645  uint32_t rsr;
646 
647  //Read receive status
648  rsr = GMAC_REGS->GMAC_RSR;
649 
650  //Packet received?
652  GMAC_RSR_BNA_Msk)) != 0)
653  {
654  //Only clear RSR flags that are currently set
655  GMAC_REGS->GMAC_RSR = rsr;
656 
657  //Process all pending packets
658  do
659  {
660  //Read incoming packet
661  error = same54EthReceivePacket(interface);
662 
663  //No more data in the receive buffer?
664  } while(error != ERROR_BUFFER_EMPTY);
665  }
666 }
667 
668 
669 /**
670  * @brief Send a packet
671  * @param[in] interface Underlying network interface
672  * @param[in] buffer Multi-part buffer containing the data to send
673  * @param[in] offset Offset to the first data byte
674  * @param[in] ancillary Additional options passed to the stack along with
675  * the packet
676  * @return Error code
677  **/
678 
680  const NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary)
681 {
682  size_t length;
683 
684  //Retrieve the length of the packet
685  length = netBufferGetLength(buffer) - offset;
686 
687  //Check the frame length
689  {
690  //The transmitter can accept another packet
691  osSetEvent(&interface->nicTxEvent);
692  //Report an error
693  return ERROR_INVALID_LENGTH;
694  }
695 
696  //Make sure the current buffer is available for writing
697  if((txBufferDesc[txBufferIndex].status & GMAC_TX_USED) == 0)
698  {
699  return ERROR_FAILURE;
700  }
701 
702  //Copy user data to the transmit buffer
703  netBufferRead(txBuffer[txBufferIndex], buffer, offset, length);
704 
705  //Set the necessary flags in the descriptor entry
706  if(txBufferIndex < (SAME54_ETH_TX_BUFFER_COUNT - 1))
707  {
708  //Write the status word
709  txBufferDesc[txBufferIndex].status = GMAC_TX_LAST |
711 
712  //Point to the next buffer
713  txBufferIndex++;
714  }
715  else
716  {
717  //Write the status word
718  txBufferDesc[txBufferIndex].status = GMAC_TX_WRAP | GMAC_TX_LAST |
720 
721  //Wrap around
722  txBufferIndex = 0;
723  }
724 
725  //Data synchronization barrier
726  __DSB();
727 
728  //Set the TSTART bit to initiate transmission
729  GMAC_REGS->GMAC_NCR |= GMAC_NCR_TSTART_Msk;
730 
731  //Check whether the next buffer is available for writing
732  if((txBufferDesc[txBufferIndex].status & GMAC_TX_USED) != 0)
733  {
734  //The transmitter can accept another packet
735  osSetEvent(&interface->nicTxEvent);
736  }
737 
738  //Successful processing
739  return NO_ERROR;
740 }
741 
742 
743 /**
744  * @brief Receive a packet
745  * @param[in] interface Underlying network interface
746  * @return Error code
747  **/
748 
750 {
751  static uint32_t temp[ETH_MAX_FRAME_SIZE / 4];
752  error_t error;
753  uint_t i;
754  uint_t j;
755  uint_t sofIndex;
756  uint_t eofIndex;
757  size_t n;
758  size_t size;
759  size_t length;
760 
761  //Initialize variables
762  size = 0;
763  sofIndex = UINT_MAX;
764  eofIndex = UINT_MAX;
765 
766  //Search for SOF and EOF flags
767  for(i = 0; i < SAME54_ETH_RX_BUFFER_COUNT; i++)
768  {
769  //Point to the current entry
770  j = rxBufferIndex + i;
771 
772  //Wrap around to the beginning of the buffer if necessary
774  {
776  }
777 
778  //No more entries to process?
779  if((rxBufferDesc[j].address & GMAC_RX_OWNERSHIP) == 0)
780  {
781  //Stop processing
782  break;
783  }
784 
785  //A valid SOF has been found?
786  if((rxBufferDesc[j].status & GMAC_RX_SOF) != 0)
787  {
788  //Save the position of the SOF
789  sofIndex = i;
790  }
791 
792  //A valid EOF has been found?
793  if((rxBufferDesc[j].status & GMAC_RX_EOF) != 0 && sofIndex != UINT_MAX)
794  {
795  //Save the position of the EOF
796  eofIndex = i;
797  //Retrieve the length of the frame
798  size = rxBufferDesc[j].status & GMAC_RX_LENGTH;
799  //Limit the number of data to read
800  size = MIN(size, ETH_MAX_FRAME_SIZE);
801  //Stop processing since we have reached the end of the frame
802  break;
803  }
804  }
805 
806  //Determine the number of entries to process
807  if(eofIndex != UINT_MAX)
808  {
809  j = eofIndex + 1;
810  }
811  else if(sofIndex != UINT_MAX)
812  {
813  j = sofIndex;
814  }
815  else
816  {
817  j = i;
818  }
819 
820  //Total number of bytes that have been copied from the receive buffer
821  length = 0;
822 
823  //Process incoming frame
824  for(i = 0; i < j; i++)
825  {
826  //Any data to copy from current buffer?
827  if(eofIndex != UINT_MAX && i >= sofIndex && i <= eofIndex)
828  {
829  //Calculate the number of bytes to read at a time
831  //Copy data from receive buffer
832  osMemcpy((uint8_t *) temp + length, rxBuffer[rxBufferIndex], n);
833  //Update byte counters
834  length += n;
835  size -= n;
836  }
837 
838  //Mark the current buffer as free
839  rxBufferDesc[rxBufferIndex].address &= ~GMAC_RX_OWNERSHIP;
840 
841  //Point to the following entry
842  rxBufferIndex++;
843 
844  //Wrap around to the beginning of the buffer if necessary
845  if(rxBufferIndex >= SAME54_ETH_RX_BUFFER_COUNT)
846  {
847  rxBufferIndex = 0;
848  }
849  }
850 
851  //Any packet to process?
852  if(length > 0)
853  {
854  NetRxAncillary ancillary;
855 
856  //Additional options can be passed to the stack along with the packet
857  ancillary = NET_DEFAULT_RX_ANCILLARY;
858 
859  //Pass the packet to the upper layer
860  nicProcessPacket(interface, (uint8_t *) temp, length, &ancillary);
861  //Valid packet received
862  error = NO_ERROR;
863  }
864  else
865  {
866  //No more data in the receive buffer
867  error = ERROR_BUFFER_EMPTY;
868  }
869 
870  //Return status code
871  return error;
872 }
873 
874 
875 /**
876  * @brief Configure MAC address filtering
877  * @param[in] interface Underlying network interface
878  * @return Error code
879  **/
880 
882 {
883  uint_t i;
884  uint_t j;
885  uint_t k;
886  uint8_t *p;
887  uint32_t hashTable[2];
888  MacAddr unicastMacAddr[3];
889  MacFilterEntry *entry;
890 
891  //Debug message
892  TRACE_DEBUG("Updating MAC filter...\r\n");
893 
894  //Set the MAC address of the station
895  GMAC_REGS->SA[0].GMAC_SAB = interface->macAddr.w[0] | (interface->macAddr.w[1] << 16);
896  GMAC_REGS->SA[0].GMAC_SAT = interface->macAddr.w[2];
897 
898  //The MAC supports 3 additional addresses for unicast perfect filtering
899  unicastMacAddr[0] = MAC_UNSPECIFIED_ADDR;
900  unicastMacAddr[1] = MAC_UNSPECIFIED_ADDR;
901  unicastMacAddr[2] = MAC_UNSPECIFIED_ADDR;
902 
903  //The hash table is used for multicast address filtering
904  hashTable[0] = 0;
905  hashTable[1] = 0;
906 
907  //The MAC address filter contains the list of MAC addresses to accept
908  //when receiving an Ethernet frame
909  for(i = 0, j = 0; i < MAC_ADDR_FILTER_SIZE; i++)
910  {
911  //Point to the current entry
912  entry = &interface->macAddrFilter[i];
913 
914  //Valid entry?
915  if(entry->refCount > 0)
916  {
917  //Multicast address?
918  if(macIsMulticastAddr(&entry->addr))
919  {
920  //Point to the MAC address
921  p = entry->addr.b;
922 
923  //Apply the hash function
924  k = (p[0] >> 6) ^ p[0];
925  k ^= (p[1] >> 4) ^ (p[1] << 2);
926  k ^= (p[2] >> 2) ^ (p[2] << 4);
927  k ^= (p[3] >> 6) ^ p[3];
928  k ^= (p[4] >> 4) ^ (p[4] << 2);
929  k ^= (p[5] >> 2) ^ (p[5] << 4);
930 
931  //The hash value is reduced to a 6-bit index
932  k &= 0x3F;
933 
934  //Update hash table contents
935  hashTable[k / 32] |= (1 << (k % 32));
936  }
937  else
938  {
939  //Up to 3 additional MAC addresses can be specified
940  if(j < 3)
941  {
942  //Save the unicast address
943  unicastMacAddr[j++] = entry->addr;
944  }
945  }
946  }
947  }
948 
949  //Configure the first unicast address filter
950  if(j >= 1)
951  {
952  //The address is activated when SAT register is written
953  GMAC_REGS->SA[1].GMAC_SAB = unicastMacAddr[0].w[0] | (unicastMacAddr[0].w[1] << 16);
954  GMAC_REGS->SA[1].GMAC_SAT = unicastMacAddr[0].w[2];
955  }
956  else
957  {
958  //The address is deactivated when SAB register is written
959  GMAC_REGS->SA[1].GMAC_SAB = 0;
960  }
961 
962  //Configure the second unicast address filter
963  if(j >= 2)
964  {
965  //The address is activated when SAT register is written
966  GMAC_REGS->SA[2].GMAC_SAB = unicastMacAddr[1].w[0] | (unicastMacAddr[1].w[1] << 16);
967  GMAC_REGS->SA[2].GMAC_SAT = unicastMacAddr[1].w[2];
968  }
969  else
970  {
971  //The address is deactivated when SAB register is written
972  GMAC_REGS->SA[2].GMAC_SAB = 0;
973  }
974 
975  //Configure the third unicast address filter
976  if(j >= 3)
977  {
978  //The address is activated when SAT register is written
979  GMAC_REGS->SA[3].GMAC_SAB = unicastMacAddr[2].w[0] | (unicastMacAddr[2].w[1] << 16);
980  GMAC_REGS->SA[3].GMAC_SAT = unicastMacAddr[2].w[2];
981  }
982  else
983  {
984  //The address is deactivated when SAB register is written
985  GMAC_REGS->SA[3].GMAC_SAB = 0;
986  }
987 
988  //Configure the multicast hash table
989  GMAC_REGS->GMAC_HRB = hashTable[0];
990  GMAC_REGS->GMAC_HRT = hashTable[1];
991 
992  //Debug message
993  TRACE_DEBUG(" HRB = %08" PRIX32 "\r\n", GMAC_REGS->GMAC_HRB);
994  TRACE_DEBUG(" HRT = %08" PRIX32 "\r\n", GMAC_REGS->GMAC_HRT);
995 
996  //Successful processing
997  return NO_ERROR;
998 }
999 
1000 
1001 /**
1002  * @brief Adjust MAC configuration parameters for proper operation
1003  * @param[in] interface Underlying network interface
1004  * @return Error code
1005  **/
1006 
1008 {
1009  uint32_t config;
1010 
1011  //Read network configuration register
1012  config = GMAC_REGS->GMAC_NCFGR;
1013 
1014  //10BASE-T or 100BASE-TX operation mode?
1015  if(interface->linkSpeed == NIC_LINK_SPEED_100MBPS)
1016  {
1017  config |= GMAC_NCFGR_SPD_Msk;
1018  }
1019  else
1020  {
1021  config &= ~GMAC_NCFGR_SPD_Msk;
1022  }
1023 
1024  //Half-duplex or full-duplex mode?
1025  if(interface->duplexMode == NIC_FULL_DUPLEX_MODE)
1026  {
1027  config |= GMAC_NCFGR_FD_Msk;
1028  }
1029  else
1030  {
1031  config &= ~GMAC_NCFGR_FD_Msk;
1032  }
1033 
1034  //Write configuration value back to NCFGR register
1035  GMAC_REGS->GMAC_NCFGR = config;
1036 
1037  //Successful processing
1038  return NO_ERROR;
1039 }
1040 
1041 
1042 /**
1043  * @brief Write PHY register
1044  * @param[in] opcode Access type (2 bits)
1045  * @param[in] phyAddr PHY address (5 bits)
1046  * @param[in] regAddr Register address (5 bits)
1047  * @param[in] data Register value
1048  **/
1049 
1050 void same54EthWritePhyReg(uint8_t opcode, uint8_t phyAddr,
1051  uint8_t regAddr, uint16_t data)
1052 {
1053  uint32_t temp;
1054 
1055  //Valid opcode?
1056  if(opcode == SMI_OPCODE_WRITE)
1057  {
1058  //Set up a write operation
1059  temp = GMAC_MAN_CLTTO_Msk | GMAC_MAN_OP(1) | GMAC_MAN_WTN(2);
1060  //PHY address
1061  temp |= GMAC_MAN_PHYA(phyAddr);
1062  //Register address
1063  temp |= GMAC_MAN_REGA(regAddr);
1064  //Register value
1065  temp |= GMAC_MAN_DATA(data);
1066 
1067  //Start a write operation
1068  GMAC_REGS->GMAC_MAN = temp;
1069  //Wait for the write to complete
1070  while((GMAC_REGS->GMAC_NSR & GMAC_NSR_IDLE_Msk) == 0)
1071  {
1072  }
1073  }
1074  else
1075  {
1076  //The MAC peripheral only supports standard Clause 22 opcodes
1077  }
1078 }
1079 
1080 
1081 /**
1082  * @brief Read PHY register
1083  * @param[in] opcode Access type (2 bits)
1084  * @param[in] phyAddr PHY address (5 bits)
1085  * @param[in] regAddr Register address (5 bits)
1086  * @return Register value
1087  **/
1088 
1089 uint16_t same54EthReadPhyReg(uint8_t opcode, uint8_t phyAddr,
1090  uint8_t regAddr)
1091 {
1092  uint16_t data;
1093  uint32_t temp;
1094 
1095  //Valid opcode?
1096  if(opcode == SMI_OPCODE_READ)
1097  {
1098  //Set up a read operation
1099  temp = GMAC_MAN_CLTTO_Msk | GMAC_MAN_OP(2) | GMAC_MAN_WTN(2);
1100  //PHY address
1101  temp |= GMAC_MAN_PHYA(phyAddr);
1102  //Register address
1103  temp |= GMAC_MAN_REGA(regAddr);
1104 
1105  //Start a read operation
1106  GMAC_REGS->GMAC_MAN = temp;
1107  //Wait for the read to complete
1108  while((GMAC_REGS->GMAC_NSR & GMAC_NSR_IDLE_Msk) == 0)
1109  {
1110  }
1111 
1112  //Get register value
1113  data = GMAC_REGS->GMAC_MAN & GMAC_MAN_DATA_Msk;
1114  }
1115  else
1116  {
1117  //The MAC peripheral only supports standard Clause 22 opcodes
1118  data = 0;
1119  }
1120 
1121  //Return the value of the PHY register
1122  return data;
1123 }
bool_t osSetEventFromIsr(OsEvent *event)
Set an event object to the signaled state from an interrupt service routine.
#define SAME54_ETH_RX_BUFFER_SIZE
#define GMAC_NCFGR_MTIHEN_Msk
#define GMAC_NCFGR_CLK
#define GMAC_IER_RLEX_Msk
uint8_t opcode
Definition: dns_common.h:191
int bool_t
Definition: compiler_port.h:61
#define GMAC_TX_LENGTH
Transmit buffer descriptor.
error_t same54EthSendPacket(NetInterface *interface, const NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary)
Send a packet.
#define netEvent
Definition: net_legacy.h:196
@ NIC_FULL_DUPLEX_MODE
Definition: nic.h:125
#define GMAC_IER_HRESP_Msk
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 GMAC_NSR_IDLE_Msk
uint8_t p
Definition: ndp.h:300
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:89
#define MAC_ADDR_FILTER_SIZE
Definition: ethernet.h:95
#define SAME54_ETH_TX_BUFFER_SIZE
#define TRUE
Definition: os_port.h:50
uint8_t data[]
Definition: ethernet.h:224
Receive buffer descriptor.
#define sleep(delay)
Definition: os_port.h:310
#define GMAC_NCR_RXEN_Msk
#define ETH_MAX_FRAME_SIZE
Definition: ethernet.h:110
uint_t refCount
Reference count for the current entry.
Definition: ethernet.h:266
#define GMAC_TSR_RLE_Msk
#define GMAC_RX_WRAP
#define GMAC_TSR_UND_Msk
#define GMAC_MAN_PHYA
uint16_t same54EthReadPhyReg(uint8_t opcode, uint8_t phyAddr, uint8_t regAddr)
Read PHY register.
#define SAME54_ETH_IRQ_SUB_PRIORITY
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 GMAC_TSR_TFC_Msk
#define osExitIsr(flag)
void same54EthEnableIrq(NetInterface *interface)
Enable interrupts.
#define GMAC_RX_EOF
#define GMAC_MAN_DATA
#define SMI_OPCODE_WRITE
Definition: nic.h:66
#define SAME54_ETH_IRQ_GROUP_PRIORITY
#define GMAC_TSR_HRESP_Msk
#define GMAC_TX_USED
#define GMAC_MAN_OP
void same54EthTick(NetInterface *interface)
SAME54 Ethernet MAC timer handler.
__weak_func void same54EthInitGpio(NetInterface *interface)
GPIO configuration.
#define FALSE
Definition: os_port.h:46
#define GMAC_IRQn
#define GMAC_NCFGR_SPD_Msk
#define GMAC_TSR_TXGO_Msk
#define osMemcpy(dest, src, length)
Definition: os_port.h:144
error_t
Error codes.
Definition: error.h:43
#define GMAC_IER_RCOMP_Msk
#define GMAC_RX_ADDRESS
void same54EthDisableIrq(NetInterface *interface)
Disable interrupts.
const NicDriver same54EthDriver
SAME54 Ethernet MAC driver.
const NetRxAncillary NET_DEFAULT_RX_ANCILLARY
Definition: net_misc.c:105
@ ERROR_FAILURE
Generic error code.
Definition: error.h:45
error_t same54EthUpdateMacConfig(NetInterface *interface)
Adjust MAC configuration parameters for proper operation.
#define SAME54_ETH_RX_BUFFER_COUNT
#define txBuffer
#define NetRxAncillary
Definition: net_misc.h:40
#define NetInterface
Definition: net.h:36
MacAddr addr
MAC address.
Definition: ethernet.h:265
#define GMAC_NCR_MPE_Msk
@ ERROR_INVALID_LENGTH
Definition: error.h:111
@ ERROR_BUFFER_EMPTY
Definition: error.h:142
#define GMAC_TSR_TXCOMP_Msk
void GMAC_Handler(void)
SAME54 Ethernet MAC interrupt service routine.
#define NetTxAncillary
Definition: net_misc.h:36
#define GMAC_NCFGR_FD_Msk
#define SMI_OPCODE_READ
Definition: nic.h:67
#define GMAC_NCR_TXEN_Msk
#define TRACE_INFO(...)
Definition: debug.h:105
uint8_t length
Definition: tcp.h:375
size_t netBufferGetLength(const NetBuffer *buffer)
Get the actual length of a multi-part buffer.
Definition: net_mem.c:297
#define MIN(a, b)
Definition: os_port.h:63
#define GMAC_RSR_BNA_Msk
#define rxBuffer
#define GMAC_RX_SOF
#define GMAC_TSR_UBR_Msk
MacAddr
Definition: ethernet.h:197
#define GMAC_NCR_TSTART_Msk
#define TRACE_DEBUG(...)
Definition: debug.h:119
#define GMAC_IER_TUR_Msk
#define GMAC_REGS
uint16_t regAddr
void same54EthInitBufferDesc(NetInterface *interface)
Initialize buffer descriptors.
#define GMAC_RX_LENGTH
#define ETH_MTU
Definition: ethernet.h:116
#define GMAC_TX_LAST
uint8_t n
MAC filter table entry.
Definition: ethernet.h:264
Ipv6Addr address[]
Definition: ipv6.h:325
#define osEnterIsr()
#define GMAC_IER_TFC_Msk
void same54EthWritePhyReg(uint8_t opcode, uint8_t phyAddr, uint8_t regAddr, uint16_t data)
Write PHY register.
#define GMAC_IER_ROVR_Msk
error_t same54EthUpdateMacAddrFilter(NetInterface *interface)
Configure MAC address filtering.
#define GMAC_MAN_WTN
#define GMAC_RSR_HNO_Msk
void osSetEvent(OsEvent *event)
Set the specified event object to the signaled state.
SAME54 Ethernet MAC driver.
#define GMAC_RSR_RXOVR_Msk
#define GMAC_IER_TCOMP_Msk
@ NIC_LINK_SPEED_100MBPS
Definition: nic.h:112
error_t same54EthInit(NetInterface *interface)
SAME54 Ethernet MAC initialization.
unsigned int uint_t
Definition: compiler_port.h:57
TCP/IP stack core.
#define GMAC_RSR_REC_Msk
void same54EthEventHandler(NetInterface *interface)
SAME54 Ethernet MAC event handler.
NIC driver.
Definition: nic.h:286
#define GMAC_RX_OWNERSHIP
#define GMAC_MAN_REGA
#define GMAC_NCFGR_MAXFS_Msk
#define GMAC_TSR_COL_Msk
#define GMAC_IER_RXUBR_Msk
error_t same54EthReceivePacket(NetInterface *interface)
Receive a packet.
#define GMAC_MAN_CLTTO_Msk
const MacAddr MAC_UNSPECIFIED_ADDR
Definition: ethernet.c:53
#define GMAC_MAN_DATA_Msk
@ NO_ERROR
Success.
Definition: error.h:44
__attribute__((naked))
AVR32 Ethernet MAC interrupt wrapper.
Debugging facilities.
#define GMAC_TX_WRAP
#define SAME54_ETH_IRQ_PRIORITY_GROUPING
#define SAME54_ETH_TX_BUFFER_COUNT
@ NIC_TYPE_ETHERNET
Ethernet interface.
Definition: nic.h:83