lpc23xx_eth_driver.c
Go to the documentation of this file.
1 /**
2  * @file lpc23xx_eth_driver.c
3  * @brief LPC2300 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.0
29  **/
30 
31 //Switch to the appropriate trace level
32 #define TRACE_LEVEL NIC_TRACE_LEVEL
33 
34 //Dependencies
35 #include "lpc23xx.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 descriptors
53 #pragma data_alignment = 4
55 //Transmit status array
56 #pragma data_alignment = 4
58 //Receive descriptors
59 #pragma data_alignment = 4
61 //Receive status array
62 #pragma data_alignment = 8
64 
65 //Keil MDK-ARM or GCC compiler?
66 #else
67 
68 //Transmit buffer
70  __attribute__((aligned(4)));
71 //Receive buffer
73  __attribute__((aligned(4)));
74 //Transmit descriptors
76  __attribute__((aligned(4)));
77 //Transmit status array
79  __attribute__((aligned(4)));
80 //Receive descriptors
82  __attribute__((aligned(4)));
83 //Receive status array
85  __attribute__((aligned(8)));
86 
87 #endif
88 
89 
90 /**
91  * @brief LPC23xx Ethernet MAC driver
92  **/
93 
95 {
97  ETH_MTU,
108  TRUE,
109  TRUE,
110  TRUE,
111  FALSE
112 };
113 
114 
115 /**
116  * @brief LPC23xx Ethernet MAC initialization
117  * @param[in] interface Underlying network interface
118  * @return Error code
119  **/
120 
122 {
123  error_t error;
124 
125  //Debug message
126  TRACE_INFO("Initializing LPC23xx Ethernet MAC...\r\n");
127 
128  //Save underlying network interface
129  nicDriverInterface = interface;
130 
131  //Power up EMAC controller
132  PCONP |= PCONP_PCENET;
133 
134  //GPIO configuration
135  lpc23xxEthInitGpio(interface);
136 
137  //Reset host registers, transmit datapath and receive datapath
139 
140  //Reset EMAC controller
143 
144  //Initialize MAC related registers
145  MAC_MAC1 = 0;
147  MAC_IPGR = IPGR_DEFAULT_VALUE;
148  MAC_CLRT = CLRT_DEFAULT_VALUE;
149 
150  //Select RMII mode
151  MAC_COMMAND = COMMAND_RMII;
152 
153  //Configure MDC clock
154  MAC_MCFG = MCFG_CLOCK_SELECT_DIV28;
155  //Reset MII management interface
156  MAC_MCFG |= MCFG_RESET_MII_MGMT;
157  MAC_MCFG &= ~MCFG_RESET_MII_MGMT;
158 
159  //Valid Ethernet PHY or switch driver?
160  if(interface->phyDriver != NULL)
161  {
162  //Ethernet PHY initialization
163  error = interface->phyDriver->init(interface);
164  }
165  else if(interface->switchDriver != NULL)
166  {
167  //Ethernet switch initialization
168  error = interface->switchDriver->init(interface);
169  }
170  else
171  {
172  //The interface is not properly configured
173  error = ERROR_FAILURE;
174  }
175 
176  //Any error to report?
177  if(error)
178  {
179  return error;
180  }
181 
182  //Initialize TX and RX descriptor arrays
183  lpc23xxEthInitDesc(interface);
184 
185  //Set the MAC address of the station
186  MAC_SA0 = interface->macAddr.w[2];
187  MAC_SA1 = interface->macAddr.w[1];
188  MAC_SA2 = interface->macAddr.w[0];
189 
190  //Initialize hash table
191  MAC_HASHFILTERL = 0;
192  MAC_HASHFILTERH = 0;
193 
194  //Configure the receive filter
195  MAC_RXFILTERCTRL = RFC_ACCEPT_PERFECT_EN |
197 
198  //Program the MAXF register with the maximum frame length to be accepted
199  MAC_MAXF = LPC23XX_ETH_RX_BUFFER_SIZE;
200 
201  //Reset EMAC interrupt flags
202  MAC_INTCLEAR = 0xFFFF;
203  //Enable desired EMAC interrupts
204  MAC_INTENABLE = INT_TX_DONE | INT_RX_DONE;
205 
206  //The interrupt request is assigned to the IRQ category
207  VICIntSelect &= ~VIC_INT_ETHERNET;
208  //Register interrupt handler
209  VICVectAddr21 = (uint32_t) lpc23xxEthIrqHandler;
210  //Configure interrupt priority
211  VICVectPriority21 = LPC23XX_ETH_IRQ_PRIORITY;
212 
213  //Enable transmission and reception
214  MAC_COMMAND |= COMMAND_TX_ENABLE | COMMAND_RX_ENABLE;
215  //Allow frames to be received
216  MAC_MAC1 |= MAC1_RECEIVE_ENABLE;
217 
218  //Accept any packets from the upper layer
219  osSetEvent(&interface->nicTxEvent);
220 
221  //Successful initialization
222  return NO_ERROR;
223 }
224 
225 
226 /**
227  * @brief GPIO configuration
228  * @param[in] interface Underlying network interface
229  **/
230 
231 __weak_func void lpc23xxEthInitGpio(NetInterface *interface)
232 {
233 //LPC2378-STK evaluation board?
234 #if defined(USE_LPC2378_STK)
235  //Configure P1.0 (ENET_TXD0), P1.1 (ENET_TXD1), P1.4 (ENET_TX_EN), P1.8 (ENET_CRS),
236  //P1.9 (ENET_RXD0), P1.10 (ENET_RXD1), P1.14 (RX_ER) and P1.15 (ENET_REF_CLK)
237  PINSEL2 &= ~(PINSEL2_P1_0_MASK | PINSEL2_P1_1_MASK |
238  PINSEL2_P1_4_MASK | PINSEL2_P1_8_MASK | PINSEL2_P1_9_MASK |
239  PINSEL2_P1_10_MASK | PINSEL2_P1_14_MASK | PINSEL2_P1_15_MASK);
240 
241  PINSEL2 |= PINSEL2_P1_0_ENET_TXD0 | PINSEL2_P1_1_ENET_TXD1 |
242  PINSEL2_P1_4_ENET_TX_EN | PINSEL2_P1_8_ENET_CRS | PINSEL2_P1_9_ENET_RXD0 |
243  PINSEL2_P1_10_ENET_RXD1 | PINSEL2_P1_14_ENET_RX_ER | PINSEL2_P1_15_ENET_REF_CLK;
244 
245  //Configure P1.16 (ENET_MDC) and P1.17 (ENET_MDIO)
246  PINSEL3 &= ~(PINSEL3_P1_16_MASK | PINSEL3_P1_17_MASK);
247  PINSEL3 |= PINSEL3_P1_16_ENET_MDC | PINSEL3_P1_17_ENET_MDIO;
248 #endif
249 }
250 
251 
252 /**
253  * @brief Initialize TX and RX descriptors
254  * @param[in] interface Underlying network interface
255  **/
256 
258 {
259  uint_t i;
260 
261  //Initialize TX descriptors
262  for(i = 0; i < LPC23XX_ETH_TX_BUFFER_COUNT; i++)
263  {
264  //Base address of the buffer containing transmit data
265  txDesc[i].packet = (uint32_t) txBuffer[i];
266  //Transmit descriptor control word
267  txDesc[i].control = 0;
268  //Transmit status information word
269  txStatus[i].info = 0;
270  }
271 
272  //Initialize RX descriptors
273  for(i = 0; i < LPC23XX_ETH_RX_BUFFER_COUNT; i++)
274  {
275  //Base address of the buffer for storing receive data
276  rxDesc[i].packet = (uint32_t) rxBuffer[i];
277  //Receive descriptor control word
279  //Receive status information word
280  rxStatus[i].info = 0;
281  //Receive status HashCRC word
282  rxStatus[i].hashCrc = 0;
283  }
284 
285  //Initialize EMAC transmit descriptor registers
286  MAC_TXDESCRIPTOR = (uint32_t) txDesc;
287  MAC_TXSTATUS = (uint32_t) txStatus;
288  MAC_TXDESCRIPTORNUM = LPC23XX_ETH_TX_BUFFER_COUNT - 1;
289  MAC_TXPRODUCEINDEX = 0;
290 
291  //Initialize EMAC receive descriptor registers
292  MAC_RXDESCRIPTOR = (uint32_t) rxDesc;
293  MAC_RXSTATUS = (uint32_t) rxStatus;
294  MAC_RXDESCRIPTORNUM = LPC23XX_ETH_RX_BUFFER_COUNT - 1;
295  MAC_RXCONSUMEINDEX = 0;
296 }
297 
298 
299 /**
300  * @brief LPC23xx Ethernet MAC timer handler
301  *
302  * This routine is periodically called by the TCP/IP stack to handle periodic
303  * operations such as polling the link state
304  *
305  * @param[in] interface Underlying network interface
306  **/
307 
308 void lpc23xxEthTick(NetInterface *interface)
309 {
310  //Valid Ethernet PHY or switch driver?
311  if(interface->phyDriver != NULL)
312  {
313  //Handle periodic operations
314  interface->phyDriver->tick(interface);
315  }
316  else if(interface->switchDriver != NULL)
317  {
318  //Handle periodic operations
319  interface->switchDriver->tick(interface);
320  }
321  else
322  {
323  //Just for sanity
324  }
325 }
326 
327 
328 /**
329  * @brief Enable interrupts
330  * @param[in] interface Underlying network interface
331  **/
332 
334 {
335  //Enable Ethernet MAC interrupts
336  VICIntEnable = VIC_INT_ETHERNET;
337 
338  //Valid Ethernet PHY or switch driver?
339  if(interface->phyDriver != NULL)
340  {
341  //Enable Ethernet PHY interrupts
342  interface->phyDriver->enableIrq(interface);
343  }
344  else if(interface->switchDriver != NULL)
345  {
346  //Enable Ethernet switch interrupts
347  interface->switchDriver->enableIrq(interface);
348  }
349  else
350  {
351  //Just for sanity
352  }
353 }
354 
355 
356 /**
357  * @brief Disable interrupts
358  * @param[in] interface Underlying network interface
359  **/
360 
362 {
363  //Disable Ethernet MAC interrupts
364  VICIntEnClr = VIC_INT_ETHERNET;
365 
366  //Valid Ethernet PHY or switch driver?
367  if(interface->phyDriver != NULL)
368  {
369  //Disable Ethernet PHY interrupts
370  interface->phyDriver->disableIrq(interface);
371  }
372  else if(interface->switchDriver != NULL)
373  {
374  //Disable Ethernet switch interrupts
375  interface->switchDriver->disableIrq(interface);
376  }
377  else
378  {
379  //Just for sanity
380  }
381 }
382 
383 
384 /**
385  * @brief LPC23xx Ethernet MAC interrupt service routine
386  **/
387 
388 __irq void lpc23xxEthIrqHandler(void)
389 {
390  uint_t i;
391  bool_t flag;
392  uint32_t status;
393 
394  //Interrupt service routine prologue
395  osEnterIsr();
396 
397  //This flag will be set if a higher priority task must be woken
398  flag = FALSE;
399 
400  //Read interrupt status register
401  status = MAC_INTSTATUS;
402 
403  //Packet transmitted?
404  if((status & INT_TX_DONE) != 0)
405  {
406  //Clear TxDone interrupt flag
407  MAC_INTCLEAR = INT_TX_DONE;
408 
409  //Get the index of the next descriptor
410  i = MAC_TXPRODUCEINDEX + 1;
411 
412  //Wrap around if necessary
414  {
415  i = 0;
416  }
417 
418  //Check whether the TX buffer is available for writing
419  if(i != MAC_TXCONSUMEINDEX)
420  {
421  //Notify the TCP/IP stack that the transmitter is ready to send
422  flag |= osSetEventFromIsr(&nicDriverInterface->nicTxEvent);
423  }
424  }
425 
426  //Packet received?
427  if((status & INT_RX_DONE) != 0)
428  {
429  //Disable RxDone interrupts
430  MAC_INTENABLE &= ~INT_RX_DONE;
431 
432  //Set event flag
433  nicDriverInterface->nicEvent = TRUE;
434  //Notify the TCP/IP stack of the event
435  flag |= osSetEventFromIsr(&netEvent);
436  }
437 
438  //Interrupt service routine epilogue
439  osExitIsr(flag);
440 }
441 
442 
443 /**
444  * @brief LPC23xx Ethernet MAC event handler
445  * @param[in] interface Underlying network interface
446  **/
447 
449 {
450  error_t error;
451 
452  //Packet received?
453  if((MAC_INTSTATUS & INT_RX_DONE) != 0)
454  {
455  //Clear RxDone interrupt flag
456  MAC_INTCLEAR = INT_RX_DONE;
457 
458  //Process all pending packets
459  do
460  {
461  //Read incoming packet
462  error = lpc23xxEthReceivePacket(interface);
463 
464  //No more data in the receive buffer?
465  } while(error != ERROR_BUFFER_EMPTY);
466  }
467 
468  //Re-enable TxDone and RxDone interrupts
469  MAC_INTENABLE = INT_TX_DONE | INT_RX_DONE;
470 }
471 
472 
473 /**
474  * @brief Send a packet
475  * @param[in] interface Underlying network interface
476  * @param[in] buffer Multi-part buffer containing the data to send
477  * @param[in] offset Offset to the first data byte
478  * @param[in] ancillary Additional options passed to the stack along with
479  * the packet
480  * @return Error code
481  **/
482 
484  const NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary)
485 {
486  uint_t i;
487  uint_t j;
488  size_t length;
489 
490  //Retrieve the length of the packet
491  length = netBufferGetLength(buffer) - offset;
492 
493  //Check the frame length
494  if(!length)
495  {
496  //The transmitter can accept another packet
497  osSetEvent(&interface->nicTxEvent);
498  //We are done since the buffer is empty
499  return NO_ERROR;
500  }
502  {
503  //The transmitter can accept another packet
504  osSetEvent(&interface->nicTxEvent);
505  //Report an error
506  return ERROR_INVALID_LENGTH;
507  }
508 
509  //Get the index of the current descriptor
510  i = MAC_TXPRODUCEINDEX;
511  //Get the index of the next descriptor
512  j = i + 1;
513 
514  //Wrap around if necessary
516  {
517  j = 0;
518  }
519 
520  //Check whether the transmit descriptor array is full
521  if(j == MAC_TXCONSUMEINDEX)
522  {
523  return ERROR_FAILURE;
524  }
525 
526  //Copy user data to the transmit buffer
527  netBufferRead((uint8_t *) txDesc[i].packet, buffer, offset, length);
528 
529  //Write the transmit control word
530  txDesc[i].control = TX_CTRL_INTERRUPT | TX_CTRL_LAST |
532 
533  //Increment index and wrap around if necessary
534  if(++i >= LPC23XX_ETH_TX_BUFFER_COUNT)
535  {
536  i = 0;
537  }
538 
539  //Save the resulting value
540  MAC_TXPRODUCEINDEX = i;
541 
542  //Get the index of the next descriptor
543  j = i + 1;
544 
545  //Wrap around if necessary
547  {
548  j = 0;
549  }
550 
551  //Check whether the next buffer is available for writing
552  if(j != MAC_TXCONSUMEINDEX)
553  {
554  //The transmitter can accept another packet
555  osSetEvent(&interface->nicTxEvent);
556  }
557 
558  //Successful write operation
559  return NO_ERROR;
560 }
561 
562 
563 /**
564  * @brief Receive a packet
565  * @param[in] interface Underlying network interface
566  * @return Error code
567  **/
568 
570 {
571  error_t error;
572  size_t n;
573  uint_t i;
574  NetRxAncillary ancillary;
575 
576  //Point to the current descriptor
577  i = MAC_RXCONSUMEINDEX;
578 
579  //Current buffer available for reading?
580  if(i != MAC_RXPRODUCEINDEX)
581  {
582  //Retrieve the length of the frame
583  n = (rxStatus[i].info & RX_STATUS_SIZE) + 1;
584  //Limit the number of data to read
586 
587  //Additional options can be passed to the stack along with the packet
588  ancillary = NET_DEFAULT_RX_ANCILLARY;
589 
590  //Pass the packet to the upper layer
591  nicProcessPacket(interface, (uint8_t *) rxDesc[i].packet, n, &ancillary);
592 
593  //Increment index and wrap around if necessary
594  if(++i >= LPC23XX_ETH_RX_BUFFER_COUNT)
595  {
596  i = 0;
597  }
598 
599  //Save the resulting value
600  MAC_RXCONSUMEINDEX = i;
601 
602  //Valid packet received
603  error = NO_ERROR;
604  }
605  else
606  {
607  //No more data in the receive buffer
608  error = ERROR_BUFFER_EMPTY;
609  }
610 
611  //Return status code
612  return error;
613 }
614 
615 
616 /**
617  * @brief Configure MAC address filtering
618  * @param[in] interface Underlying network interface
619  * @return Error code
620  **/
621 
623 {
624  uint_t i;
625  uint_t k;
626  uint32_t crc;
627  uint32_t hashTable[2];
628  MacFilterEntry *entry;
629 
630  //Debug message
631  TRACE_DEBUG("Updating MAC filter...\r\n");
632 
633  //Set the MAC address of the station
634  MAC_SA0 = interface->macAddr.w[2];
635  MAC_SA1 = interface->macAddr.w[1];
636  MAC_SA2 = interface->macAddr.w[0];
637 
638  //Clear hash table
639  hashTable[0] = 0;
640  hashTable[1] = 0;
641 
642  //The MAC address filter contains the list of MAC addresses to accept
643  //when receiving an Ethernet frame
644  for(i = 0; i < MAC_ADDR_FILTER_SIZE; i++)
645  {
646  //Point to the current entry
647  entry = &interface->macAddrFilter[i];
648 
649  //Valid entry?
650  if(entry->refCount > 0)
651  {
652  //Compute CRC over the current MAC address
653  crc = lpc23xxEthCalcCrc(&entry->addr, sizeof(MacAddr));
654  //Bits [28:23] are used to form the hash
655  k = (crc >> 23) & 0x3F;
656  //Update hash table contents
657  hashTable[k / 32] |= (1 << (k % 32));
658  }
659  }
660 
661  //Write the hash table
662  MAC_HASHFILTERL = hashTable[0];
663  MAC_HASHFILTERH = hashTable[1];
664 
665  //Debug message
666  TRACE_DEBUG(" HashFilterL = %08" PRIX32 "\r\n", MAC_HASHFILTERL);
667  TRACE_DEBUG(" HashFilterH = %08" PRIX32 "\r\n", MAC_HASHFILTERH);
668 
669  //Successful processing
670  return NO_ERROR;
671 }
672 
673 
674 /**
675  * @brief Adjust MAC configuration parameters for proper operation
676  * @param[in] interface Underlying network interface
677  * @return Error code
678  **/
679 
681 {
682  //10BASE-T or 100BASE-TX operation mode?
683  if(interface->linkSpeed == NIC_LINK_SPEED_100MBPS)
684  {
685  MAC_SUPP = SUPP_SPEED;
686  }
687  else
688  {
689  MAC_SUPP = 0;
690  }
691 
692  //Half-duplex or full-duplex mode?
693  if(interface->duplexMode == NIC_FULL_DUPLEX_MODE)
694  {
695  //The MAC operates in full-duplex mode
696  MAC_MAC2 |= MAC2_FULL_DUPLEX;
697  MAC_COMMAND |= COMMAND_FULL_DUPLEX;
698  //Configure Back-to-Back Inter-Packet Gap
699  MAC_IPGT = IPGT_FULL_DUPLEX;
700  }
701  else
702  {
703  //The MAC operates in half-duplex mode
704  MAC_MAC2 &= ~MAC2_FULL_DUPLEX;
705  MAC_COMMAND &= ~COMMAND_FULL_DUPLEX;
706  //Configure Back-to-Back Inter-Packet Gap
707  MAC_IPGT = IPGT_HALF_DUPLEX;
708  }
709 
710  //Successful processing
711  return NO_ERROR;
712 }
713 
714 
715 /**
716  * @brief Write PHY register
717  * @param[in] opcode Access type (2 bits)
718  * @param[in] phyAddr PHY address (5 bits)
719  * @param[in] regAddr Register address (5 bits)
720  * @param[in] data Register value
721  **/
722 
723 void lpc23xxEthWritePhyReg(uint8_t opcode, uint8_t phyAddr,
724  uint8_t regAddr, uint16_t data)
725 {
726  //Valid opcode?
727  if(opcode == SMI_OPCODE_WRITE)
728  {
729  //Clear MCMD register
730  MAC_MCMD = 0;
731 
732  //PHY address
733  MAC_MADR = (phyAddr << 8) & MADR_PHY_ADDRESS;
734  //Register address
735  MAC_MADR |= regAddr & MADR_REGISTER_ADDRESS;
736  //Data to be written in the PHY register
737  MAC_MWTD = data & MWTD_WRITE_DATA;
738 
739  //Wait for the write to complete
740  while((MAC_MIND & MIND_BUSY) != 0)
741  {
742  }
743  }
744  else
745  {
746  //The MAC peripheral only supports standard Clause 22 opcodes
747  }
748 }
749 
750 
751 /**
752  * @brief Read PHY register
753  * @param[in] opcode Access type (2 bits)
754  * @param[in] phyAddr PHY address (5 bits)
755  * @param[in] regAddr Register address (5 bits)
756  * @return Register value
757  **/
758 
759 uint16_t lpc23xxEthReadPhyReg(uint8_t opcode, uint8_t phyAddr,
760  uint8_t regAddr)
761 {
762  uint16_t data;
763 
764  //Valid opcode?
765  if(opcode == SMI_OPCODE_READ)
766  {
767  //PHY address
768  MAC_MADR = (phyAddr << 8) & MADR_PHY_ADDRESS;
769  //Register address
770  MAC_MADR |= regAddr & MADR_REGISTER_ADDRESS;
771 
772  //Start a read operation
773  MAC_MCMD = MCMD_READ;
774  //Wait for the read to complete
775  while((MAC_MIND & MIND_BUSY) != 0)
776  {
777  }
778 
779  //Clear MCMD register
780  MAC_MCMD = 0;
781 
782  //Get register value
783  data = MAC_MRDD & MRDD_READ_DATA;
784  }
785  else
786  {
787  //The MAC peripheral only supports standard Clause 22 opcodes
788  data = 0;
789  }
790 
791  //Return the value of the PHY register
792  return data;
793 }
794 
795 
796 /**
797  * @brief CRC calculation
798  * @param[in] data Pointer to the data over which to calculate the CRC
799  * @param[in] length Number of bytes to process
800  * @return Resulting CRC value
801  **/
802 
803 uint32_t lpc23xxEthCalcCrc(const void *data, size_t length)
804 {
805  uint_t i;
806  uint_t j;
807  uint32_t crc;
808  const uint8_t *p;
809 
810  //Point to the data over which to calculate the CRC
811  p = (uint8_t *) data;
812  //CRC preset value
813  crc = 0xFFFFFFFF;
814 
815  //Loop through data
816  for(i = 0; i < length; i++)
817  {
818  //The message is processed bit by bit
819  for(j = 0; j < 8; j++)
820  {
821  //Update CRC value
822  if((((crc >> 31) ^ (p[i] >> j)) & 0x01) != 0)
823  {
824  crc = (crc << 1) ^ 0x04C11DB7;
825  }
826  else
827  {
828  crc = crc << 1;
829  }
830  }
831  }
832 
833  //Return CRC value
834  return crc;
835 }
#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_LENGTH
Definition: error.h:111
@ ERROR_FAILURE
Generic error code.
Definition: error.h:45
#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
#define MCFG_RESET_MII_MGMT
#define MAC1_SOFT_RESET
#define COMMAND_TX_RESET
#define MWTD_WRITE_DATA
#define MCFG_CLOCK_SELECT_DIV28
#define TX_CTRL_INTERRUPT
#define COMMAND_RX_ENABLE
#define COMMAND_RMII
#define MADR_REGISTER_ADDRESS
#define SUPP_SPEED
#define MAC1_RESET_TX
#define COMMAND_FULL_DUPLEX
#define TX_CTRL_PAD
#define MAC2_FULL_DUPLEX
#define TX_CTRL_SIZE
#define MAC2_CRC_ENABLE
#define MAC1_RESET_MCS_TX
#define MAC2_PAD_CRC_ENABLE
#define COMMAND_REG_RESET
#define COMMAND_TX_ENABLE
#define MADR_PHY_ADDRESS
#define RFC_ACCEPT_BROADCAST_EN
#define IPGT_FULL_DUPLEX
#define MAC1_SIMULATION_RESET
#define INT_TX_DONE
#define IPGT_HALF_DUPLEX
#define RX_CTRL_INTERRUPT
#define MAC1_RESET_MCS_RX
#define COMMAND_RX_RESET
#define CLRT_DEFAULT_VALUE
#define MAC1_RESET_RX
#define MRDD_READ_DATA
#define MAC1_RECEIVE_ENABLE
#define IPGR_DEFAULT_VALUE
#define RFC_ACCEPT_PERFECT_EN
#define TX_CTRL_CRC
#define RX_STATUS_SIZE
#define INT_RX_DONE
#define MCMD_READ
#define RFC_ACCEPT_MULTICAST_HASH_EN
#define TX_CTRL_LAST
#define MIND_BUSY
error_t lpc23xxEthInit(NetInterface *interface)
LPC23xx Ethernet MAC initialization.
uint32_t lpc23xxEthCalcCrc(const void *data, size_t length)
CRC calculation.
const NicDriver lpc23xxEthDriver
LPC23xx Ethernet MAC driver.
void lpc23xxEthDisableIrq(NetInterface *interface)
Disable interrupts.
__weak_func void lpc23xxEthInitGpio(NetInterface *interface)
GPIO configuration.
void lpc23xxEthTick(NetInterface *interface)
LPC23xx Ethernet MAC timer handler.
void lpc23xxEthEventHandler(NetInterface *interface)
LPC23xx Ethernet MAC event handler.
void lpc23xxEthInitDesc(NetInterface *interface)
Initialize TX and RX descriptors.
void lpc23xxEthEnableIrq(NetInterface *interface)
Enable interrupts.
uint16_t lpc23xxEthReadPhyReg(uint8_t opcode, uint8_t phyAddr, uint8_t regAddr)
Read PHY register.
error_t lpc23xxEthUpdateMacConfig(NetInterface *interface)
Adjust MAC configuration parameters for proper operation.
void lpc23xxEthWritePhyReg(uint8_t opcode, uint8_t phyAddr, uint8_t regAddr, uint16_t data)
Write PHY register.
error_t lpc23xxEthUpdateMacAddrFilter(NetInterface *interface)
Configure MAC address filtering.
error_t lpc23xxEthSendPacket(NetInterface *interface, const NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary)
Send a packet.
__irq void lpc23xxEthIrqHandler(void)
LPC23xx Ethernet MAC interrupt service routine.
error_t lpc23xxEthReceivePacket(NetInterface *interface)
Receive a packet.
LPC2300 Ethernet MAC driver.
#define LPC23XX_ETH_RX_BUFFER_COUNT
#define LPC23XX_ETH_RX_BUFFER_SIZE
#define LPC23XX_ETH_TX_BUFFER_COUNT
#define LPC23XX_ETH_IRQ_PRIORITY
#define LPC23XX_ETH_TX_BUFFER_SIZE
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
#define MIN(a, b)
Definition: os_port.h:63
#define TRUE
Definition: os_port.h:50
#define FALSE
Definition: os_port.h:46
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)
Receive descriptor.
Receive status.
Transmit descriptor.
Transmit status.
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