m2sxxx_eth_driver.c
Go to the documentation of this file.
1 /**
2  * @file m2sxxx_eth_driver.c
3  * @brief SmartFusion2 (M2Sxxx) Ethernet MAC driver
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneTCP Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.4.4
29  **/
30 
31 //Switch to the appropriate trace level
32 #define TRACE_LEVEL NIC_TRACE_LEVEL
33 
34 //Dependencies
35 #include "m2sxxx.h"
36 #include "core/net.h"
38 #include "debug.h"
39 
40 //Underlying network interface
41 static NetInterface *nicDriverInterface;
42 
43 //IAR EWARM compiler?
44 #if defined(__ICCARM__)
45 
46 //Transmit buffer
47 #pragma data_alignment = 4
49 //Receive buffer
50 #pragma data_alignment = 4
52 //Transmit DMA descriptors
53 #pragma data_alignment = 4
55 //Receive DMA descriptors
56 #pragma data_alignment = 4
58 
59 //Keil MDK-ARM or GCC compiler?
60 #else
61 
62 //Transmit buffer
64  __attribute__((aligned(4)));
65 //Receive buffer
67  __attribute__((aligned(4)));
68 //Transmit DMA descriptors
70  __attribute__((aligned(4)));
71 //Receive DMA descriptors
73  __attribute__((aligned(4)));
74 
75 #endif
76 
77 //Pointer to the current TX DMA descriptor
78 static M2sxxxTxDmaDesc *txCurDmaDesc;
79 //Pointer to the current RX DMA descriptor
80 static M2sxxxRxDmaDesc *rxCurDmaDesc;
81 
82 
83 /**
84  * @brief M2Sxxx Ethernet MAC driver
85  **/
86 
88 {
90  ETH_MTU,
101  TRUE,
102  TRUE,
103  TRUE,
104  FALSE
105 };
106 
107 
108 /**
109  * @brief M2Sxxx Ethernet MAC initialization
110  * @param[in] interface Underlying network interface
111  * @return Error code
112  **/
113 
115 {
116  error_t error;
117 
118  //Debug message
119  TRACE_INFO("Initializing M2Sxxx Ethernet MAC...\r\n");
120 
121  //Save underlying network interface
122  nicDriverInterface = interface;
123 
124  //Disable EDAC feature
125  SYSREG->EDAC_CR &= ~(EDAC_CR_MAC_EDAC_RX_EN | EDAC_CR_MAC_EDAC_TX_EN);
126 
127  //Reset the MAC module
130 
131  //Reset the interface module
132  MAC->INTERFACE_CTRL = INTERFACE_CTRL_RESET;
133 
134  //Reset FIFOs
135  MAC->FIFO_CFG0 = FIFO_CFG0_HSTRSTFT | FIFO_CFG0_HSTRSTST |
137 
138  //Take the MAC module out of reset
139  MAC->CFG1 = 0;
140  //Take the interface module out of reset
141  MAC->INTERFACE_CTRL = 0;
142  //Take the FIFOs out of reset
143  MAC->FIFO_CFG0 = 0;
144 
145  //Select interface mode (MII, RMII, GMII or TBI)
146  m2sxxxEthInitGpio(interface);
147 
148  //Select the proper divider for the MDC clock
149  MAC->MII_CONFIG = MII_CONFIG_CLKSEL_DIV28;
150 
151  //Valid Ethernet PHY or switch driver?
152  if(interface->phyDriver != NULL)
153  {
154  //Ethernet PHY initialization
155  error = interface->phyDriver->init(interface);
156  }
157  else if(interface->switchDriver != NULL)
158  {
159  //Ethernet switch initialization
160  error = interface->switchDriver->init(interface);
161  }
162  else
163  {
164  //The interface is not properly configured
165  error = ERROR_FAILURE;
166  }
167 
168  //Any error to report?
169  if(error)
170  {
171  return error;
172  }
173 
174  //Set the upper 16 bits of the MAC address
175  MAC->STATION_ADDRESS2 = (interface->macAddr.b[0] << 16) |
176  (interface->macAddr.b[1] << 24);
177 
178  //Set the lower 32 bits of the MAC address
179  MAC->STATION_ADDRESS1 = interface->macAddr.b[2] |
180  (interface->macAddr.b[3] << 8) |
181  (interface->macAddr.b[4] << 16) |
182  (interface->macAddr.b[5] << 24);
183 
184  //Maximum frame length to be accepted
185  MAC->MAX_FRAME_LENGTH = M2SXXX_ETH_RX_BUFFER_SIZE;
186 
187  //Disable flow control
188  MAC->CFG1 = 0;
189 
190  //All short frames will be zero-padded to 60 bytes and a valid CRC
191  //is then appended
194 
195  //Enable TX and RX FIFOs
196  MAC->FIFO_CFG0 = FIFO_CFG0_FTFENREQ | FIFO_CFG0_STFENREQ |
198 
199  //Use default FIFO configuration
200  MAC->FIFO_CFG1 = FIFO_CFG1_DEFAULT_VALUE;
201  MAC->FIFO_CFG2 = FIFO_CFG2_DEFAULT_VALUE;
202  MAC->FIFO_CFG3 = FIFO_CFG3_DEFAULT_VALUE;
203 
204  //Drop frames less than 64 bytes
205  MAC->FIFO_CFG5 = FIFO_CFG5_HSTDRPLT64 | FIFO_CFG5_HSTFLTRFRMDC;
206 
207  //Specify the statistics vectors that will be checked
208  MAC->FIFO_CFG5 &= ~(FIFO_CFG5_TRUNCATED | FIFO_CFG5_RECEPTION_OK |
210 
211  //Configure frame filtering
212  MAC->FIFO_CFG4 = FIFO_CFG4_TRUNCATED | FIFO_CFG4_INVALID_CRC |
214 
215  //Initialize DMA descriptor lists
216  m2sxxxEthInitDmaDesc(interface);
217 
218  //Enable the desired Ethernet interrupts
220 
221  //Set priority grouping (4 bits for pre-emption priority, no bits for subpriority)
222  NVIC_SetPriorityGrouping(M2SXXX_ETH_IRQ_PRIORITY_GROUPING);
223 
224  //Configure Ethernet interrupt priority
225  NVIC_SetPriority(EthernetMAC_IRQn, NVIC_EncodePriority(M2SXXX_ETH_IRQ_PRIORITY_GROUPING,
227 
228  //Enable transmission and reception
229  MAC->CFG1 |= CFG1_TX_EN | CFG1_RX_EN;
230  //Enable the DMA transfer of received packets
231  MAC->DMA_RX_CTRL = DMA_RX_CTRL_RX_EN;
232 
233  //Accept any packets from the upper layer
234  osSetEvent(&interface->nicTxEvent);
235 
236  //Successful initialization
237  return NO_ERROR;
238 }
239 
240 
241 /**
242  * @brief GPIO configuration
243  * @param[in] interface Underlying network interface
244  **/
245 
246 __weak_func void m2sxxxEthInitGpio(NetInterface *interface)
247 {
248 //SF2-STARTER-KIT-ES-2 evaluation board?
249 #if defined(USE_SF2_STARTER_KIT_ES_2)
250  //Select MII interface mode
251  SYSREG->MAC_CR = MAC_CR_ETH_PHY_MODE_MII;
252 #endif
253 }
254 
255 
256 /**
257  * @brief Initialize DMA descriptor lists
258  * @param[in] interface Underlying network interface
259  **/
260 
262 {
263  uint_t i;
264 
265  //Initialize TX DMA descriptor list
266  for(i = 0; i < M2SXXX_ETH_TX_BUFFER_COUNT; i++)
267  {
268  //Transmit buffer address
269  txDmaDesc[i].addr = (uint32_t) txBuffer[i];
270  //The descriptor is initially owned by the user
271  txDmaDesc[i].size = DMA_DESC_EMPTY_FLAG;
272  //Next descriptor address
273  txDmaDesc[i].next = (uint32_t) &txDmaDesc[i + 1];
274  }
275 
276  //The last descriptor is chained to the first entry
277  txDmaDesc[i - 1].next = (uint32_t) &txDmaDesc[0];
278  //Point to the very first descriptor
279  txCurDmaDesc = &txDmaDesc[0];
280 
281  //Initialize RX DMA descriptor list
282  for(i = 0; i < M2SXXX_ETH_RX_BUFFER_COUNT; i++)
283  {
284  //Receive buffer address
285  rxDmaDesc[i].addr = (uint32_t) rxBuffer[i];
286  //The descriptor is initially owned by the DMA
287  rxDmaDesc[i].size = DMA_DESC_EMPTY_FLAG;
288  //Next descriptor address
289  rxDmaDesc[i].next = (uint32_t) &rxDmaDesc[i + 1];
290  }
291 
292  //The last descriptor is chained to the first entry
293  rxDmaDesc[i - 1].next = (uint32_t) &rxDmaDesc[0];
294  //Point to the very first descriptor
295  rxCurDmaDesc = &rxDmaDesc[0];
296 
297  //Start location of the TX descriptor list
298  MAC->DMA_TX_DESC = (uint32_t) txDmaDesc;
299  //Start location of the RX descriptor list
300  MAC->DMA_RX_DESC = (uint32_t) rxDmaDesc;
301 }
302 
303 
304 /**
305  * @brief M2Sxxx Ethernet MAC timer handler
306  *
307  * This routine is periodically called by the TCP/IP stack to handle periodic
308  * operations such as polling the link state
309  *
310  * @param[in] interface Underlying network interface
311  **/
312 
313 void m2sxxxEthTick(NetInterface *interface)
314 {
315  //Valid Ethernet PHY or switch driver?
316  if(interface->phyDriver != NULL)
317  {
318  //Handle periodic operations
319  interface->phyDriver->tick(interface);
320  }
321  else if(interface->switchDriver != NULL)
322  {
323  //Handle periodic operations
324  interface->switchDriver->tick(interface);
325  }
326  else
327  {
328  //Just for sanity
329  }
330 }
331 
332 
333 /**
334  * @brief Enable interrupts
335  * @param[in] interface Underlying network interface
336  **/
337 
339 {
340  //Enable Ethernet MAC interrupts
341  NVIC_EnableIRQ(EthernetMAC_IRQn);
342 
343  //Valid Ethernet PHY or switch driver?
344  if(interface->phyDriver != NULL)
345  {
346  //Enable Ethernet PHY interrupts
347  interface->phyDriver->enableIrq(interface);
348  }
349  else if(interface->switchDriver != NULL)
350  {
351  //Enable Ethernet switch interrupts
352  interface->switchDriver->enableIrq(interface);
353  }
354  else
355  {
356  //Just for sanity
357  }
358 }
359 
360 
361 /**
362  * @brief Disable interrupts
363  * @param[in] interface Underlying network interface
364  **/
365 
367 {
368  //Disable Ethernet MAC interrupts
369  NVIC_DisableIRQ(EthernetMAC_IRQn);
370 
371  //Valid Ethernet PHY or switch driver?
372  if(interface->phyDriver != NULL)
373  {
374  //Disable Ethernet PHY interrupts
375  interface->phyDriver->disableIrq(interface);
376  }
377  else if(interface->switchDriver != NULL)
378  {
379  //Disable Ethernet switch interrupts
380  interface->switchDriver->disableIrq(interface);
381  }
382  else
383  {
384  //Just for sanity
385  }
386 }
387 
388 
389 /**
390  * @brief M2Sxxx Ethernet MAC interrupt service routine
391  **/
392 
394 {
395  bool_t flag;
396  uint32_t status;
397 
398  //Interrupt service routine prologue
399  osEnterIsr();
400 
401  //This flag will be set if a higher priority task must be woken
402  flag = FALSE;
403 
404  //Read interrupt status register
405  status = MAC->DMA_IRQ;
406 
407  //Packet transmitted?
408  if((status & DMA_IRQ_TX_PKT_SENT) != 0)
409  {
410  //Clear TX interrupt flag
411  MAC->DMA_TX_STATUS = DMA_TX_STATUS_TX_PKT_SENT;
412 
413  //Check whether the TX buffer is available for writing
414  if((txCurDmaDesc->size & DMA_DESC_EMPTY_FLAG) != 0)
415  {
416  //Notify the TCP/IP stack that the transmitter is ready to send
417  flag |= osSetEventFromIsr(&nicDriverInterface->nicTxEvent);
418  }
419  }
420 
421  //Packet received?
422  if((status & DMA_IRQ_RX_PKT_RECEIVED) != 0)
423  {
424  //Disable RX interrupt
425  MAC->DMA_IRQ_MASK &= ~DMA_IRQ_MASK_RX_PKT_RECEIVED;
426 
427  //Set event flag
428  nicDriverInterface->nicEvent = TRUE;
429  //Notify the TCP/IP stack of the event
430  flag |= osSetEventFromIsr(&netEvent);
431  }
432 
433  //Interrupt service routine epilogue
434  osExitIsr(flag);
435 }
436 
437 
438 /**
439  * @brief M2Sxxx Ethernet MAC event handler
440  * @param[in] interface Underlying network interface
441  **/
442 
444 {
445  //Packet received?
446  if((MAC->DMA_RX_STATUS & DMA_RX_STATUS_RX_PKT_RECEIVED) != 0)
447  {
448  //Process all the pending packets
449  while((MAC->DMA_RX_STATUS & DMA_RX_STATUS_RX_PKT_RECEIVED) != 0)
450  {
451  //Clear RX interrupt flag
452  MAC->DMA_RX_STATUS = DMA_RX_STATUS_RX_PKT_RECEIVED;
453  //Read incoming packet
454  m2sxxxEthReceivePacket(interface);
455  }
456  }
457 
458  //Re-enable Ethernet interrupts
460 }
461 
462 
463 /**
464  * @brief Send a packet
465  * @param[in] interface Underlying network interface
466  * @param[in] buffer Multi-part buffer containing the data to send
467  * @param[in] offset Offset to the first data byte
468  * @param[in] ancillary Additional options passed to the stack along with
469  * the packet
470  * @return Error code
471  **/
472 
474  const NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary)
475 {
476  size_t length;
477 
478  //Retrieve the length of the packet
479  length = netBufferGetLength(buffer) - offset;
480 
481  //Check the frame length
483  {
484  //The transmitter can accept another packet
485  osSetEvent(&interface->nicTxEvent);
486  //Report an error
487  return ERROR_INVALID_LENGTH;
488  }
489 
490  //Make sure the current buffer is available for writing
491  if((txCurDmaDesc->size & DMA_DESC_EMPTY_FLAG) == 0)
492  {
493  return ERROR_FAILURE;
494  }
495 
496  //Copy user data to the transmit buffer
497  netBufferRead((uint8_t *) txCurDmaDesc->addr, buffer, offset, length);
498 
499  //Set the packet length and give the ownership of the descriptor to the DMA
500  txCurDmaDesc->size = length & DMA_DESC_SIZE_MASK;
501 
502  //Check whether DMA transfers are suspended
503  if((MAC->DMA_TX_CTRL & DMA_TX_CTRL_TX_EN) == 0)
504  {
505  //Set the start position in the ring buffer
506  MAC->DMA_TX_DESC = (uint32_t) txCurDmaDesc;
507  }
508 
509  //Instruct the DMA controller to transfer the packet
510  MAC->DMA_TX_CTRL = DMA_TX_CTRL_TX_EN;
511 
512  //Point to the next descriptor in the list
513  txCurDmaDesc = (M2sxxxTxDmaDesc *) txCurDmaDesc->next;
514 
515  //Check whether the next buffer is available for writing
516  if((txCurDmaDesc->size & DMA_DESC_EMPTY_FLAG) != 0)
517  {
518  //The transmitter can accept another packet
519  osSetEvent(&interface->nicTxEvent);
520  }
521 
522  //Data successfully written
523  return NO_ERROR;
524 }
525 
526 
527 /**
528  * @brief Receive a packet
529  * @param[in] interface Underlying network interface
530  * @return Error code
531  **/
532 
534 {
535  error_t error;
536  size_t n;
537  NetRxAncillary ancillary;
538 
539  //Current buffer available for reading?
540  if((rxCurDmaDesc->size & DMA_DESC_EMPTY_FLAG) == 0)
541  {
542  //Retrieve the length of the frame
543  n = rxCurDmaDesc->size & DMA_DESC_SIZE_MASK;
544  //Limit the number of data to read
546 
547  //Additional options can be passed to the stack along with the packet
548  ancillary = NET_DEFAULT_RX_ANCILLARY;
549 
550  //Pass the packet to the upper layer
551  nicProcessPacket(interface, (uint8_t *) rxCurDmaDesc->addr, n, &ancillary);
552 
553  //Give the ownership of the descriptor back to the DMA
554  rxCurDmaDesc->size = DMA_DESC_EMPTY_FLAG;
555 
556  //Check whether DMA transfers are suspended
557  if((MAC->DMA_RX_CTRL & DMA_RX_CTRL_RX_EN) == 0)
558  {
559  //Set the start position in the ring buffer
560  MAC->DMA_RX_DESC = (uint32_t) rxCurDmaDesc;
561  }
562 
563  //Enable the DMA transfer of received packets
564  MAC->DMA_RX_CTRL = DMA_RX_CTRL_RX_EN;
565  //Point to the next descriptor in the list
566  rxCurDmaDesc = (M2sxxxRxDmaDesc *) rxCurDmaDesc->next;
567 
568  //Valid packet received
569  error = NO_ERROR;
570  }
571  else
572  {
573  //Check whether DMA transfers are suspended
574  if((MAC->DMA_RX_CTRL & DMA_RX_CTRL_RX_EN) == 0)
575  {
576  //Set the start position in the ring buffer
577  MAC->DMA_RX_DESC = (uint32_t) rxCurDmaDesc;
578  }
579 
580  //Enable the DMA transfer of received packets
581  MAC->DMA_RX_CTRL = DMA_RX_CTRL_RX_EN;
582 
583  //No more data in the receive buffer
584  error = ERROR_BUFFER_EMPTY;
585  }
586 
587  //Return status code
588  return error;
589 }
590 
591 
592 /**
593  * @brief Configure MAC address filtering
594  * @param[in] interface Underlying network interface
595  * @return Error code
596  **/
597 
599 {
600  //Ethernet MAC does not implement multicast filtering
601  return NO_ERROR;
602 }
603 
604 
605 /**
606  * @brief Adjust MAC configuration parameters for proper operation
607  * @param[in] interface Underlying network interface
608  * @return Error code
609  **/
610 
612 {
613  uint32_t temp;
614 
615  //10BASE-T or 100BASE-TX operation mode?
616  if(interface->linkSpeed == NIC_LINK_SPEED_100MBPS)
617  {
618  //The link operates at 100 Mbps
619  temp = SYSREG->MAC_CR & ~MAC_CR_ETH_LINE_SPEED;
620  SYSREG->MAC_CR = temp | MAC_CR_ETH_LINE_SPEED_100MBPS;
621 
622  //Configure the RMII module with the current operating speed
623  MAC->INTERFACE_CTRL |= INTERFACE_CTRL_SPEED;
624 
625  //Use nibble mode
626  temp = MAC->CFG2 & ~CFG2_INTERFACE_MODE;
627  MAC->CFG2 = temp | CFG2_INTERFACE_MODE_NIBBLE;
628  }
629  else
630  {
631  //The link operates at 10 Mbps
632  if((SYSREG->MAC_CR & MAC_CR_ETH_PHY_MODE) == MAC_CR_ETH_PHY_MODE_MII)
633  {
634  temp = SYSREG->MAC_CR & ~MAC_CR_ETH_LINE_SPEED;
635  SYSREG->MAC_CR = temp | MAC_CR_ETH_LINE_SPEED_100MBPS;
636  }
637  else
638  {
639  temp = SYSREG->MAC_CR & ~MAC_CR_ETH_LINE_SPEED;
640  SYSREG->MAC_CR = temp | MAC_CR_ETH_LINE_SPEED_10MBPS;
641  }
642 
643  //Configure the RMII module with the current operating speed
644  MAC->INTERFACE_CTRL &= ~INTERFACE_CTRL_SPEED;
645 
646  //Use nibble mode
647  temp = MAC->CFG2 & ~CFG2_INTERFACE_MODE;
648  MAC->CFG2 = temp | CFG2_INTERFACE_MODE_NIBBLE;
649  }
650 
651  //Half-duplex or full-duplex mode?
652  if(interface->duplexMode == NIC_FULL_DUPLEX_MODE)
653  {
654  //Configure MAC to operate in full-duplex mode
655  MAC->CFG2 |= CFG2_FULL_DUPLEX;
656  MAC->FIFO_CFG5 &= ~FIFO_CFG5_CFGHDPLX;
657  }
658  else
659  {
660  //Configure MAC to operate in half-duplex mode
661  MAC->CFG2 &= ~CFG2_FULL_DUPLEX;
662  MAC->FIFO_CFG5 |= FIFO_CFG5_CFGHDPLX;
663  }
664 
665  //Successful processing
666  return NO_ERROR;
667 }
668 
669 
670 /**
671  * @brief Write PHY register
672  * @param[in] opcode Access type (2 bits)
673  * @param[in] phyAddr PHY address (5 bits)
674  * @param[in] regAddr Register address (5 bits)
675  * @param[in] data Register value
676  **/
677 
678 void m2sxxxEthWritePhyReg(uint8_t opcode, uint8_t phyAddr,
679  uint8_t regAddr, uint16_t data)
680 {
681  //Valid opcode?
682  if(opcode == SMI_OPCODE_WRITE)
683  {
684  //Set PHY address and register address
685  MAC->MII_ADDRESS = (phyAddr << MII_ADDRESS_PHY_ADDR_POS) | regAddr;
686  //Start a write operation
687  MAC->MII_CTRL = data;
688 
689  //Wait for the write to complete
690  while((MAC->MII_INDICATORS & MII_INDICATORS_BUSY) != 0)
691  {
692  }
693  }
694  else
695  {
696  //The MAC peripheral only supports standard Clause 22 opcodes
697  }
698 }
699 
700 
701 /**
702  * @brief Read PHY register
703  * @param[in] opcode Access type (2 bits)
704  * @param[in] phyAddr PHY address (5 bits)
705  * @param[in] regAddr Register address (5 bits)
706  * @return Register value
707  **/
708 
709 uint16_t m2sxxxEthReadPhyReg(uint8_t opcode, uint8_t phyAddr,
710  uint8_t regAddr)
711 {
712  uint16_t data;
713 
714  //Valid opcode?
715  if(opcode == SMI_OPCODE_READ)
716  {
717  //Set PHY address and register address
718  MAC->MII_ADDRESS = (phyAddr << MII_ADDRESS_PHY_ADDR_POS) | regAddr;
719  //Start a read operation
720  MAC->MII_COMMAND = MII_COMMAND_READ;
721 
722  //Wait for the read to complete
723  while((MAC->MII_INDICATORS & MII_INDICATORS_BUSY) != 0)
724  {
725  }
726 
727  //Clear command register
728  MAC->MII_COMMAND = 0;
729  //Get register value
730  data = MAC->MII_STATUS;
731  }
732  else
733  {
734  //The MAC peripheral only supports standard Clause 22 opcodes
735  data = 0;
736  }
737 
738  //Return the value of the PHY register
739  return data;
740 }
bool_t osSetEventFromIsr(OsEvent *event)
Set an event object to the signaled state from an interrupt service routine.
#define DMA_IRQ_MASK_RX_PKT_RECEIVED
#define CFG2_PREAMBLE_7
uint8_t opcode
Definition: dns_common.h:188
#define MII_ADDRESS_PHY_ADDR_POS
#define DMA_IRQ_TX_PKT_SENT
int bool_t
Definition: compiler_port.h:53
#define FIFO_CFG5_CFGHDPLX
#define netEvent
Definition: net_legacy.h:196
#define MAC_CR_ETH_LINE_SPEED
#define CFG2_LENGTH_FIELD_CHECK
#define M2SXXX_ETH_IRQ_GROUP_PRIORITY
@ NIC_FULL_DUPLEX_MODE
Definition: nic.h:125
#define MII_CONFIG_CLKSEL_DIV28
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 CFG2_CRC_EN
Transmit DMA descriptor.
#define M2SXXX_ETH_TX_BUFFER_SIZE
#define FIFO_CFG1_DEFAULT_VALUE
#define CFG1_TX_EN
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:89
#define TRUE
Definition: os_port.h:50
uint8_t data[]
Definition: ethernet.h:222
void EthernetMAC_IRQHandler(void)
M2Sxxx Ethernet MAC interrupt service routine.
#define FIFO_CFG5_TRUNCATED
error_t m2sxxxEthUpdateMacAddrFilter(NetInterface *interface)
Configure MAC address filtering.
error_t m2sxxxEthSendPacket(NetInterface *interface, const NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary)
Send a packet.
#define MAC_CR_ETH_LINE_SPEED_100MBPS
#define CFG1_RX_EN
void m2sxxxEthTick(NetInterface *interface)
M2Sxxx Ethernet MAC timer handler.
#define DMA_TX_CTRL_TX_EN
#define M2SXXX_ETH_RX_BUFFER_SIZE
#define MAC_CR_ETH_PHY_MODE
#define INTERFACE_CTRL_RESET
#define DMA_RX_STATUS_RX_PKT_RECEIVED
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 osExitIsr(flag)
SmartFusion2 (M2Sxxx) Ethernet MAC driver.
error_t m2sxxxEthInit(NetInterface *interface)
M2Sxxx Ethernet MAC initialization.
#define SMI_OPCODE_WRITE
Definition: nic.h:66
#define FIFO_CFG5_RECEIVE_ERROR
#define M2SXXX_ETH_IRQ_PRIORITY_GROUPING
error_t m2sxxxEthUpdateMacConfig(NetInterface *interface)
Adjust MAC configuration parameters for proper operation.
#define FALSE
Definition: os_port.h:46
#define CFG2_INTERFACE_MODE
#define EDAC_CR_MAC_EDAC_RX_EN
#define FIFO_CFG4_RECEIVE_ERROR
#define CFG2_INTERFACE_MODE_NIBBLE
#define CFG1_RESET_RX_FUNCTION
error_t
Error codes.
Definition: error.h:43
#define FIFO_CFG0_FTFENREQ
void m2sxxxEthInitDmaDesc(NetInterface *interface)
Initialize DMA descriptor lists.
#define CFG1_RESET_RX_MAC_CTRL
#define FIFO_CFG0_HSTRSTWT
#define FIFO_CFG4_TRUNCATED
const NetRxAncillary NET_DEFAULT_RX_ANCILLARY
Definition: net_misc.c:104
error_t m2sxxxEthReceivePacket(NetInterface *interface)
Receive a packet.
@ ERROR_FAILURE
Generic error code.
Definition: error.h:45
void m2sxxxEthEventHandler(NetInterface *interface)
M2Sxxx Ethernet MAC event handler.
#define txBuffer
#define DMA_IRQ_MASK_TX_PKT_SENT
#define NetRxAncillary
Definition: net_misc.h:40
#define FIFO_CFG0_HSTRSTST
#define MAC_CR_ETH_PHY_MODE_MII
#define NetInterface
Definition: net.h:36
#define FIFO_CFG2_DEFAULT_VALUE
#define FIFO_CFG5_HSTFLTRFRMDC
#define FIFO_CFG5_HSTDRPLT64
@ ERROR_INVALID_LENGTH
Definition: error.h:111
#define FIFO_CFG5_RECEPTION_OK
#define MII_INDICATORS_BUSY
const NicDriver m2sxxxEthDriver
M2Sxxx Ethernet MAC driver.
@ ERROR_BUFFER_EMPTY
Definition: error.h:141
#define NetTxAncillary
Definition: net_misc.h:36
#define FIFO_CFG0_WTMENREQ
#define FIFO_CFG0_HSTRSTSR
#define CFG1_SOFT_RESET
#define SMI_OPCODE_READ
Definition: nic.h:67
#define DMA_RX_CTRL_RX_EN
#define TRACE_INFO(...)
Definition: debug.h:95
#define EDAC_CR_MAC_EDAC_TX_EN
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
#define DMA_DESC_EMPTY_FLAG
#define MIN(a, b)
Definition: os_port.h:63
#define FIFO_CFG3_DEFAULT_VALUE
#define rxBuffer
#define FIFO_CFG0_FRFENREQ
#define MAC_CR_ETH_LINE_SPEED_10MBPS
#define M2SXXX_ETH_IRQ_SUB_PRIORITY
#define CFG1_RESET_TX_MAC_CTRL
uint16_t regAddr
#define DMA_TX_STATUS_TX_PKT_SENT
#define ETH_MTU
Definition: ethernet.h:116
uint8_t n
#define MII_COMMAND_READ
#define osEnterIsr()
#define CFG2_PAD_CRC_EN
#define DMA_IRQ_RX_PKT_RECEIVED
#define FIFO_CFG0_SRFENREQ
#define rxDmaDesc
void osSetEvent(OsEvent *event)
Set the specified event object to the signaled state.
#define FIFO_CFG0_HSTRSTFR
__weak_func void m2sxxxEthInitGpio(NetInterface *interface)
GPIO configuration.
void m2sxxxEthDisableIrq(NetInterface *interface)
Disable interrupts.
#define CFG1_RESET_TX_FUNCTION
#define txDmaDesc
@ NIC_LINK_SPEED_100MBPS
Definition: nic.h:112
unsigned int uint_t
Definition: compiler_port.h:50
void m2sxxxEthEnableIrq(NetInterface *interface)
Enable interrupts.
TCP/IP stack core.
NIC driver.
Definition: nic.h:286
#define CFG2_FULL_DUPLEX
#define DMA_DESC_SIZE_MASK
Receive DMA descriptor.
#define FIFO_CFG0_STFENREQ
uint16_t m2sxxxEthReadPhyReg(uint8_t opcode, uint8_t phyAddr, uint8_t regAddr)
Read PHY register.
#define INTERFACE_CTRL_SPEED
#define M2SXXX_ETH_TX_BUFFER_COUNT
void m2sxxxEthWritePhyReg(uint8_t opcode, uint8_t phyAddr, uint8_t regAddr, uint16_t data)
Write PHY register.
@ NO_ERROR
Success.
Definition: error.h:44
__attribute__((naked))
AVR32 Ethernet MAC interrupt wrapper.
Debugging facilities.
#define FIFO_CFG0_HSTRSTFT
#define M2SXXX_ETH_RX_BUFFER_COUNT
@ NIC_TYPE_ETHERNET
Ethernet interface.
Definition: nic.h:83
#define FIFO_CFG5_INVALID_CRC
#define FIFO_CFG4_INVALID_CRC