ncn26010_driver.c
Go to the documentation of this file.
1 /**
2  * @file ncn26010_driver.c
3  * @brief Onsemi NCN26010 10Base-T1S Ethernet controller
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 "core/net.h"
37 #include "debug.h"
38 
39 
40 /**
41  * @brief NCN26010 driver
42  **/
43 
45 {
47  ETH_MTU,
55  NULL,
56  NULL,
57  NULL,
58  TRUE,
59  TRUE,
60  TRUE,
61  FALSE
62 };
63 
64 
65 /**
66  * @brief NCN26010 controller initialization
67  * @param[in] interface Underlying network interface
68  * @return Error code
69  **/
70 
72 {
73  uint32_t value;
74 
75  //Debug message
76  TRACE_INFO("Initializing NCN26010 Ethernet controller...\r\n");
77 
78  //Initialize SPI interface
79  interface->spiDriver->init();
80 
81  //Initialize external interrupt line driver
82  if(interface->extIntDriver != NULL)
83  {
84  interface->extIntDriver->init();
85  }
86 
87  //Issue a device reset
89 
90  //Wait for the reset to complete
91  do
92  {
93  //Read reset control and status register
94  value = ncn26010ReadReg(interface, NCN26010_RESET);
95 
96  //The RESET self-clears when the reset finishes
97  } while((value & NCN26010_RESET_RESET) != 0);
98 
99  //Read the STATUS0 register and confirm that the RESETC field is 1
100  do
101  {
102  //Read the status register 0
103  value = ncn26010ReadReg(interface, NCN26010_STATUS0);
104 
105  //Check the value of the RESETC bit
106  } while((value & NCN26010_STATUS0_RESETC) == 0);
107 
108  //Write 1 to the RESETC field in the STATUS0 register to clear this field
110 
111  //Dump MMS0 registers for debugging purpose
112  TRACE_DEBUG("MMS0 registers:\r\n");
113  ncn26010DumpReg(interface, NCN26010_MMS_STD, 0, 16);
114 
115  //Configure DIO LEDs
120 
121 #if (NCN26010_PLCA_SUPPORT == ENABLED)
122  //Set PLCA burst
125 
126  //Set PLCA node count and local ID
130 
131  //Enable PLCA
133 #else
134  //Disable PLCA
135  ncn26010WriteReg(interface, NCN26010_PLCACTRL0, 0);
136 #endif
137 
138  //Perform custom configuration
139  ncn26010InitHook(interface);
140 
141  //Configure the MAC for calculating and appending the FCS
145 
146  //Use factory preprogrammed MAC address?
147  if(macCompAddr(&interface->macAddr, &MAC_UNSPECIFIED_ADDR))
148  {
149  //Read PHYID register
150  value = ncn26010ReadReg(interface, NCN26010_PHYID);
151  //The OUI field records the 22 MSB's of the OUI in reverse order
152  value = reverseInt32(value) << 2;
153 
154  //Save the OUI
155  interface->macAddr.b[0] = value & 0xFF;
156  interface->macAddr.b[1] = (value >> 8) & 0xFF;
157  interface->macAddr.b[2] = (value >> 16) & 0xFF;
158 
159  //Read MACID0 register
160  value = ncn26010ReadReg(interface, NCN26010_MACID0);
161 
162  //Save the lower 16 bits of the unique MAC address
163  interface->macAddr.b[5] = value & 0xFF;
164  interface->macAddr.b[4] = (value >> 8) & 0xFF;
165 
166  //Read MACID1 register
167  value = ncn26010ReadReg(interface, NCN26010_MACID1);
168 
169  //Save the upper 8 bits of the unique MAC address
170  interface->macAddr.b[3] = value & 0xFF;
171 
172  //Generate the 64-bit interface identifier
173  macAddrToEui64(&interface->macAddr, &interface->eui64);
174  }
175 
176  //Configure MAC address filtering
177  ncn26010UpdateMacAddrFilter(interface);
178 
179  //Configure the SPI protocol engine
183 
184  //When the MAC is configured, write 1 to the SYNC field in the CONFIG0
185  //register to indicate that the MAC configuration is complete
186  value = ncn26010ReadReg(interface, NCN26010_CONFIG0);
189 
190  //Enable TX and RX
194 
195  //Enable the physical link
198 
199  //Accept any packets from the upper layer
200  osSetEvent(&interface->nicTxEvent);
201 
202  //Force the TCP/IP stack to poll the status at startup
203  interface->nicEvent = TRUE;
204  //Notify the TCP/IP stack of the event
206 
207  //Successful initialization
208  return NO_ERROR;
209 }
210 
211 
212 /**
213  * @brief NCN26010 custom configuration
214  * @param[in] interface Underlying network interface
215  **/
216 
217 __weak_func void ncn26010InitHook(NetInterface *interface)
218 {
219 }
220 
221 
222 /**
223  * @brief NCN26010 timer handler
224  * @param[in] interface Underlying network interface
225  **/
226 
227 void ncn26010Tick(NetInterface *interface)
228 {
229  uint32_t value;
230  bool_t linkState;
231 
232  //Read PHY status register
234  //Retrieve current link state
235  linkState = (value & NCN26010_PHYSTATUS_LINK_STATUS) ? TRUE : FALSE;
236 
237  //Link up event?
238  if(linkState && !interface->linkState)
239  {
240  //The PHY is only able to operate in 10 Mbps mode
241  interface->linkSpeed = NIC_LINK_SPEED_10MBPS;
242  interface->duplexMode = NIC_HALF_DUPLEX_MODE;
243 
244  //Update link state
245  interface->linkState = TRUE;
246 
247  //Process link state change event
248  nicNotifyLinkChange(interface);
249  }
250  //Link down event?
251  else if(!linkState && interface->linkState)
252  {
253  //Update link state
254  interface->linkState = FALSE;
255 
256  //Process link state change event
257  nicNotifyLinkChange(interface);
258  }
259 }
260 
261 
262 /**
263  * @brief Enable interrupts
264  * @param[in] interface Underlying network interface
265  **/
266 
268 {
269  //Enable interrupts
270  if(interface->extIntDriver != NULL)
271  {
272  interface->extIntDriver->enableIrq();
273  }
274 }
275 
276 
277 /**
278  * @brief Disable interrupts
279  * @param[in] interface Underlying network interface
280  **/
281 
283 {
284  //Disable interrupts
285  if(interface->extIntDriver != NULL)
286  {
287  interface->extIntDriver->disableIrq();
288  }
289 }
290 
291 
292 /**
293  * @brief NCN26010 interrupt service routine
294  * @param[in] interface Underlying network interface
295  * @return TRUE if a higher priority task must be woken. Else FALSE is returned
296  **/
297 
299 {
300  //When the SPI host detects an asserted IRQn from the MACPHY, it should
301  //initiate a data chunk transfer to obtain the current data footer
302  interface->nicEvent = TRUE;
303 
304  //Notify the TCP/IP stack of the event
305  return osSetEventFromIsr(&netEvent);
306 }
307 
308 
309 /**
310  * @brief NCN26010 event handler
311  * @param[in] interface Underlying network interface
312  **/
313 
315 {
316  uint32_t status;
317 
318  //Read buffer status register
319  status = ncn26010ReadReg(interface, NCN26010_BUFSTS);
320 
321  //Process all the data chunks currently available
322  while((status & NCN26010_BUFSTS_RCA) != 0)
323  {
324  //Read incoming packet
325  ncn26010ReceivePacket(interface);
326 
327  //Read buffer status register
328  status = ncn26010ReadReg(interface, NCN26010_BUFSTS);
329  }
330 }
331 
332 
333 /**
334  * @brief Send a packet
335  * @param[in] interface Underlying network interface
336  * @param[in] buffer Multi-part buffer containing the data to send
337  * @param[in] offset Offset to the first data byte
338  * @param[in] ancillary Additional options passed to the stack along with
339  * the packet
340  * @return Error code
341  **/
342 
344  const NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary)
345 {
346  static uint8_t chunk[NCN26010_CHUNK_PAYLOAD_SIZE + 4];
347  size_t i;
348  size_t j;
349  size_t n;
350  size_t length;
351  uint32_t status;
352  uint32_t header;
353  uint32_t footer;
354 
355  //Retrieve the length of the packet
356  length = netBufferGetLength(buffer) - offset;
357 
358  //Read buffer status register
359  status = ncn26010ReadReg(interface, NCN26010_BUFSTS);
360  //Get the number of data chunks available in the transmit buffer
361  n = (status & NCN26010_BUFSTS_TXC) >> 8;
362 
363  //Check the number of transmit credits available
365  {
366  //A data transaction consists of multiple chunks
367  for(i = 0; i < length; i += n)
368  {
369  //The default size of the data chunk payload is 64 bytes
371 
372  //Set up a data transfer
375 
376  //Start of packet?
377  if(i == 0)
378  {
379  //The SPI host shall set the SV bit when the beginning of an
380  //Ethernet frame is present in the current transmit data chunk
381  //payload
382  header |= NCN26010_TX_HEADER_SV;
383  }
384 
385  //End of packet?
386  if((i + n) == length)
387  {
388  //The SPI host shall set the EV bit when the end of an Ethernet
389  //frame is present in the current transmit data chunk payload
390  header |= NCN26010_TX_HEADER_EV;
391 
392  //When EV is 1, the EBO field shall contain the byte offset into
393  //the transmit data chunk payload that points to the last byte of
394  //the Ethernet frame to transmit
395  header |= ((n - 1) << 8) & NCN26010_TX_HEADER_EBO;
396  }
397 
398  //The parity bit is calculated over the transmit data header
399  if(ncn26010CalcParity(header) != 0)
400  {
401  header |= NCN26010_CTRL_HEADER_P;
402  }
403 
404  //A chunk is composed of 4 bytes of overhead plus the configured
405  //payload size
406  STORE32BE(header, chunk);
407 
408  //Copy data chunk payload
409  netBufferRead(chunk + 4, buffer, offset + i, n);
410 
411  //Pad frames shorter than the data chunk payload
413  {
414  osMemset(chunk + 4 + n, 0, NCN26010_CHUNK_PAYLOAD_SIZE - n);
415  }
416 
417  //Pull the CS pin low
418  interface->spiDriver->assertCs();
419 
420  //Perform data transfer
421  for(j = 0; j < (NCN26010_CHUNK_PAYLOAD_SIZE + 4); j++)
422  {
423  chunk[j] = interface->spiDriver->transfer(chunk[j]);
424  }
425 
426  //Terminate the operation by raising the CS pin
427  interface->spiDriver->deassertCs();
428 
429  //Receive data chunks consist of the receive data chunk payload followed
430  //by a 4-byte footer
431  footer = LOAD32BE(chunk + NCN26010_CHUNK_PAYLOAD_SIZE);
432 
433  //The RCA field indicates the number of receive data chunks available
434  if((footer & NCN26010_RX_FOOTER_RCA) != 0)
435  {
436  //Some data chunks are available for reading
437  interface->nicEvent = TRUE;
438  //Notify the TCP/IP stack of the event
440  }
441  }
442  }
443  else
444  {
445  //No sufficient credits available
446  }
447 
448  //The transmitter can accept another packet
449  osSetEvent(&interface->nicTxEvent);
450 
451  //Successful processing
452  return NO_ERROR;
453 }
454 
455 
456 /**
457  * @brief Receive a packet
458  * @param[in] interface Underlying network interface
459  * @return Error code
460  **/
461 
463 {
464  static uint8_t buffer[NCN26010_ETH_RX_BUFFER_SIZE];
465  static uint8_t chunk[NCN26010_CHUNK_PAYLOAD_SIZE + 4];
466  error_t error;
467  size_t i;
468  size_t n;
469  size_t length;
470  uint32_t header;
471  uint32_t footer;
472 
473  //Initialize variable
474  length = 0;
475 
476  //A data transaction consists of multiple chunks
477  while(1)
478  {
479  //Check the length of the received packet
481  {
482  error = ERROR_BUFFER_OVERFLOW;
483  break;
484  }
485 
486  //The SPI host sets NORX to 0 to indicate that it accepts and process
487  //any receive frame data within the current chunk
488  header = NCN26010_TX_HEADER_DNC;
489 
490  //The parity bit is calculated over the transmit data header
491  if(ncn26010CalcParity(header) != 0)
492  {
493  header |= NCN26010_CTRL_HEADER_P;
494  }
495 
496  //Transmit data chunks consist of a 4-byte header followed by the
497  //transmit data chunk payload,
498  STORE32BE(header, chunk);
499 
500  //Clear data chunk payload
501  osMemset(chunk + 4, 0, NCN26010_CHUNK_PAYLOAD_SIZE);
502 
503  //Pull the CS pin low
504  interface->spiDriver->assertCs();
505 
506  //Perform data transfer
507  for(i = 0; i < (NCN26010_CHUNK_PAYLOAD_SIZE + 4); i++)
508  {
509  chunk[i] = interface->spiDriver->transfer(chunk[i]);
510  }
511 
512  //Terminate the operation by raising the CS pin
513  interface->spiDriver->deassertCs();
514 
515  //Receive data chunks consist of the receive data chunk payload followed
516  //by a 4-byte footer
517  footer = LOAD32BE(chunk + NCN26010_CHUNK_PAYLOAD_SIZE);
518 
519  //When the DV bit is 0, the SPI host ignores the chunk payload
520  if((footer & NCN26010_RX_FOOTER_DV) == 0)
521  {
522  error = ERROR_BUFFER_EMPTY;
523  break;
524  }
525 
526  //When the SV bit is 1, the beginning of an Ethernet frame is present in
527  //the current transmit data chunk payload
528  if(length == 0)
529  {
530  if((footer & NCN26010_RX_FOOTER_SV) == 0)
531  {
532  error = ERROR_INVALID_PACKET;
533  break;
534  }
535  }
536  else
537  {
538  if((footer & NCN26010_RX_FOOTER_SV) != 0)
539  {
540  error = ERROR_INVALID_PACKET;
541  break;
542  }
543  }
544 
545  //When EV is 1, the EBO field contains the byte offset into the
546  //receive data chunk payload that points to the last byte of the
547  //received Ethernet frame
548  if((footer & NCN26010_RX_FOOTER_EV) != 0)
549  {
550  n = ((footer & NCN26010_RX_FOOTER_EBO) >> 8) + 1;
551  }
552  else
553  {
555  }
556 
557  //Copy data chunk payload
558  osMemcpy(buffer + length, chunk, n);
559  //Adjust the length of the packet
560  length += n;
561 
562  //When the EV bit is 1, the end of an Ethernet frame is present in the
563  //current receive data chunk payload
564  if((footer & NCN26010_RX_FOOTER_EV) != 0)
565  {
566  NetRxAncillary ancillary;
567 
568  //Additional options can be passed to the stack along with the packet
569  ancillary = NET_DEFAULT_RX_ANCILLARY;
570  //Pass the packet to the upper layer
571  nicProcessPacket(interface, buffer, length, &ancillary);
572 
573  //Successful processing
574  error = NO_ERROR;
575  break;
576  }
577  }
578 
579  //Return status code
580  return error;
581 }
582 
583 
584 /**
585  * @brief Configure MAC address filtering
586  * @param[in] interface Underlying network interface
587  * @return Error code
588  **/
589 
591 {
592  uint_t i;
593  uint_t j;
594  uint32_t value;
595  bool_t acceptMulticast;
596  MacAddr unicastMacAddr[3];
597  MacFilterEntry *entry;
598 
599  //Debug message
600  TRACE_DEBUG("Updating MAC filter...\r\n");
601 
602  //Set the lower 32 bits of the station MAC address
604  (interface->macAddr.b[2] << 24) | (interface->macAddr.b[3] << 16) |
605  (interface->macAddr.b[4] << 8) | interface->macAddr.b[5]);
606 
607  //Set the upper 16 bits of the station MAC address
609  (interface->macAddr.b[0] << 8) | interface->macAddr.b[1]);
610 
611  //The MAC supports 3 additional addresses for unicast perfect filtering
612  unicastMacAddr[0] = MAC_UNSPECIFIED_ADDR;
613  unicastMacAddr[1] = MAC_UNSPECIFIED_ADDR;
614  unicastMacAddr[2] = MAC_UNSPECIFIED_ADDR;
615 
616  //This flag will be set if multicast addresses should be accepted
617  acceptMulticast = FALSE;
618 
619  //The MAC address filter contains the list of MAC addresses to accept
620  //when receiving an Ethernet frame
621  for(i = 0, j = 0; i < MAC_ADDR_FILTER_SIZE; i++)
622  {
623  //Point to the current entry
624  entry = &interface->macAddrFilter[i];
625 
626  //Valid entry?
627  if(entry->refCount > 0)
628  {
629  //Multicast address?
630  if(macIsMulticastAddr(&entry->addr))
631  {
632  //Accept multicast addresses
633  acceptMulticast = TRUE;
634  }
635  else
636  {
637  //Up to 3 additional MAC addresses can be specified
638  if(j < 3)
639  {
640  //Save the unicast address
641  unicastMacAddr[j++] = entry->addr;
642  }
643  }
644  }
645  }
646 
647  //Configure the first unicast address filter
648  if(j >= 1)
649  {
650  //Set the lower 32 bits of the MAC address
652  (unicastMacAddr[0].b[2] << 24) | (unicastMacAddr[0].b[3] << 16) |
653  (unicastMacAddr[0].b[4] << 8) | unicastMacAddr[0].b[5]);
654 
655  //Set the upper 16 bits of the MAC address
657  (unicastMacAddr[0].b[0] << 8) | unicastMacAddr[0].b[1]);
658  }
659  else
660  {
661  ncn26010WriteReg(interface, NCN26010_ADDRFILT1L, 0);
662  ncn26010WriteReg(interface, NCN26010_ADDRFILT1H, 0);
663  }
664 
665  //Configure the second unicast address filter
666  if(j >= 2)
667  {
668  //Set the lower 32 bits of the MAC address
670  (unicastMacAddr[1].b[2] << 24) | (unicastMacAddr[1].b[3] << 16) |
671  (unicastMacAddr[1].b[4] << 8) | unicastMacAddr[1].b[5]);
672 
673  //Set the upper 16 bits of the MAC address
675  (unicastMacAddr[1].b[0] << 8) | unicastMacAddr[1].b[1]);
676  }
677  else
678  {
679  ncn26010WriteReg(interface, NCN26010_ADDRFILT2L, 0);
680  ncn26010WriteReg(interface, NCN26010_ADDRFILT2H, 0);
681  }
682 
683  //Configure the third unicast address filter
684  if(j >= 3)
685  {
686  //Set the lower 32 bits of the MAC address
688  (unicastMacAddr[2].b[2] << 24) | (unicastMacAddr[2].b[3] << 16) |
689  (unicastMacAddr[2].b[4] << 8) | unicastMacAddr[2].b[5]);
690 
691  //Set the upper 16 bits of the MAC address
693  (unicastMacAddr[2].b[0] << 8) | unicastMacAddr[2].b[1]);
694  }
695  else
696  {
697  ncn26010WriteReg(interface, NCN26010_ADDRFILT3L, 0);
698  ncn26010WriteReg(interface, NCN26010_ADDRFILT3H, 0);
699  }
700 
701  //Read MACCTRL0 register
703 
704  //Disable broadcast filter
706  //Enable destination address filter
708 
709  //Enable or disable the reception of multicast frames
710  if(acceptMulticast)
711  {
712  //Disable multicast filter
714  }
715  else
716  {
717  //Enable multicast filter
719  }
720 
721  //Update MACCTRL0 register
723 
724  //Successful processing
725  return NO_ERROR;
726 }
727 
728 
729 /**
730  * @brief Write register
731  * @param[in] interface Underlying network interface
732  * @param[in] mms Register memory map to access
733  * @param[in] address Register address
734  * @param[in] data Register value
735  **/
736 
737 void ncn26010WriteReg(NetInterface *interface, uint8_t mms, uint16_t address,
738  uint32_t data)
739 {
740  uint32_t header;
741 
742  //Set up a register write operation
744  //The MMS field selects the specific register memory map to access
745  header |= (mms << 24) & NCN26010_CTRL_HEADER_MMS;
746  //Address of the first register to access
747  header |= (address << 8) & NCN26010_CTRL_HEADER_ADDR;
748  //Specifies the number of registers to write
749  header |= (0 << 1) & NCN26010_CTRL_HEADER_LEN;
750 
751  //The parity bit is calculated over the control command header
752  if(ncn26010CalcParity(header) != 0)
753  {
754  header |= NCN26010_CTRL_HEADER_P;
755  }
756 
757  //Pull the CS pin low
758  interface->spiDriver->assertCs();
759 
760  //Write control command header
761  interface->spiDriver->transfer((header >> 24) & 0xFF);
762  interface->spiDriver->transfer((header >> 16) & 0xFF);
763  interface->spiDriver->transfer((header >> 8) & 0xFF);
764  interface->spiDriver->transfer(header & 0xFF);
765 
766  //Write data
767  interface->spiDriver->transfer((data >> 24) & 0xFF);
768  interface->spiDriver->transfer((data >> 16) & 0xFF);
769  interface->spiDriver->transfer((data >> 8) & 0xFF);
770  interface->spiDriver->transfer(data & 0xFF);
771 
772  //Send 32 bits of dummy data at the end of the control write command
773  interface->spiDriver->transfer(0x00);
774  interface->spiDriver->transfer(0x00);
775  interface->spiDriver->transfer(0x00);
776  interface->spiDriver->transfer(0x00);
777 
778  //Terminate the operation by raising the CS pin
779  interface->spiDriver->deassertCs();
780 }
781 
782 
783 /**
784  * @brief Read register
785  * @param[in] interface Underlying network interface
786  * @param[in] mms Register memory map to access
787  * @param[in] address Register address
788  * @return Register value
789  **/
790 
791 uint32_t ncn26010ReadReg(NetInterface *interface, uint8_t mms,
792  uint16_t address)
793 {
794  uint32_t data;
795  uint32_t header;
796 
797  //Set up a register read operation
798  header = NCN26010_CTRL_HEADER_AID;
799  //The MMS field selects the specific register memory map to access
800  header |= (mms << 24) & NCN26010_CTRL_HEADER_MMS;
801  //Address of the first register to access
802  header |= (address << 8) & NCN26010_CTRL_HEADER_ADDR;
803  //Specifies the number of registers to read
804  header |= (0 << 1) & NCN26010_CTRL_HEADER_LEN;
805 
806  //The parity bit is calculated over the control command header
807  if(ncn26010CalcParity(header) != 0)
808  {
809  header |= NCN26010_CTRL_HEADER_P;
810  }
811 
812  //Pull the CS pin low
813  interface->spiDriver->assertCs();
814 
815  //Write control command header
816  interface->spiDriver->transfer((header >> 24) & 0xFF);
817  interface->spiDriver->transfer((header >> 16) & 0xFF);
818  interface->spiDriver->transfer((header >> 8) & 0xFF);
819  interface->spiDriver->transfer(header & 0xFF);
820 
821  //Discard the echoed control header
822  interface->spiDriver->transfer(0x00);
823  interface->spiDriver->transfer(0x00);
824  interface->spiDriver->transfer(0x00);
825  interface->spiDriver->transfer(0x00);
826 
827  //Read data
828  data = interface->spiDriver->transfer(0x00) << 24;
829  data |= interface->spiDriver->transfer(0x00) << 16;
830  data |= interface->spiDriver->transfer(0x00) << 8;
831  data |= interface->spiDriver->transfer(0x00);
832 
833  //Terminate the operation by raising the CS pin
834  interface->spiDriver->deassertCs();
835 
836  //Return register value
837  return data;
838 }
839 
840 
841 /**
842  * @brief Dump registers for debugging purpose
843  * @param[in] interface Underlying network interface
844  * @param[in] mms Register memory map to access
845  * @param[in] address Start address
846  * @param[in] num Number of registers to dump
847  **/
848 
849 void ncn26010DumpReg(NetInterface *interface, uint8_t mms, uint16_t address,
850  uint_t num)
851 {
852  uint_t i;
853 
854  //Loop through registers
855  for(i = 0; i < num; i++)
856  {
857  //Display current register
858  TRACE_DEBUG("0x%02" PRIX16 ": 0x%08" PRIX32 "\r\n", address + i,
859  ncn26010ReadReg(interface, mms, address + i));
860  }
861 
862  //Terminate with a line feed
863  TRACE_DEBUG("\r\n");
864 }
865 
866 
867 /**
868  * @brief Calculate parity bit over a 32-bit data
869  * @param[in] data 32-bit bit stream
870  * @return Odd parity bit computed over the supplied data
871  **/
872 
873 uint32_t ncn26010CalcParity(uint32_t data)
874 {
875  //Calculate the odd parity bit computed over the supplied bit stream
876  data ^= data >> 1;
877  data ^= data >> 2;
878  data ^= data >> 4;
879  data ^= data >> 8;
880  data ^= data >> 16;
881 
882  //Return '1' when the number of bits set to one in the supplied bit
883  //stream is even (resulting in an odd number of ones when the parity is
884  //included), otherwise return '0'
885  return ~data & 0x01;
886 }
unsigned int uint_t
Definition: compiler_port.h:50
int bool_t
Definition: compiler_port.h:53
uint32_t reverseInt32(uint32_t value)
Reverse bit order in a 32-bit word.
Definition: cpu_endian.c:123
#define LOAD32BE(p)
Definition: cpu_endian.h:210
#define STORE32BE(a, p)
Definition: cpu_endian.h:286
Debugging facilities.
#define TRACE_DEBUG(...)
Definition: debug.h:107
#define TRACE_INFO(...)
Definition: debug.h:95
uint8_t n
error_t
Error codes.
Definition: error.h:43
@ ERROR_BUFFER_EMPTY
Definition: error.h:141
@ NO_ERROR
Success.
Definition: error.h:44
@ ERROR_BUFFER_OVERFLOW
Definition: error.h:142
@ ERROR_INVALID_PACKET
Definition: error.h:140
const MacAddr MAC_UNSPECIFIED_ADDR
Definition: ethernet.c:53
void macAddrToEui64(const MacAddr *macAddr, Eui64 *interfaceId)
Map a MAC address to the IPv6 modified EUI-64 identifier.
Definition: ethernet.c:944
#define macIsMulticastAddr(macAddr)
Definition: ethernet.h:133
#define ETH_MTU
Definition: ethernet.h:116
uint8_t data[]
Definition: ethernet.h:222
#define macCompAddr(macAddr1, macAddr2)
Definition: ethernet.h:130
MacAddr
Definition: ethernet.h:195
#define MAC_ADDR_FILTER_SIZE
Definition: ethernet.h:95
Ipv6Addr address[]
Definition: ipv6.h:316
uint8_t b
Definition: nbns_common.h:104
const NicDriver ncn26010Driver
NCN26010 driver.
bool_t ncn26010IrqHandler(NetInterface *interface)
NCN26010 interrupt service routine.
__weak_func void ncn26010InitHook(NetInterface *interface)
NCN26010 custom configuration.
uint32_t ncn26010CalcParity(uint32_t data)
Calculate parity bit over a 32-bit data.
void ncn26010DumpReg(NetInterface *interface, uint8_t mms, uint16_t address, uint_t num)
Dump registers for debugging purpose.
void ncn26010DisableIrq(NetInterface *interface)
Disable interrupts.
error_t ncn26010Init(NetInterface *interface)
NCN26010 controller initialization.
error_t ncn26010UpdateMacAddrFilter(NetInterface *interface)
Configure MAC address filtering.
error_t ncn26010ReceivePacket(NetInterface *interface)
Receive a packet.
void ncn26010EnableIrq(NetInterface *interface)
Enable interrupts.
error_t ncn26010SendPacket(NetInterface *interface, const NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary)
Send a packet.
void ncn26010EventHandler(NetInterface *interface)
NCN26010 event handler.
void ncn26010WriteReg(NetInterface *interface, uint8_t mms, uint16_t address, uint32_t data)
Write register.
uint32_t ncn26010ReadReg(NetInterface *interface, uint8_t mms, uint16_t address)
Read register.
void ncn26010Tick(NetInterface *interface)
NCN26010 timer handler.
Onsemi NCN26010 10Base-T1S Ethernet controller.
#define NCN26010_DIOCFG_VAL0
#define NCN26010_PLCACTRL0_PCLA_EN
#define NCN26010_CTRL_HEADER_AID
#define NCN26010_MACID1
#define NCN26010_NODE_COUNT
#define NCN26010_PHYSTATUS_LINK_STATUS
#define NCN26010_MACID0
#define NCN26010_PHYID
#define NCN26010_MACCTRL0_ADRF
#define NCN26010_DIOCFG_SLEW_RATE_0
#define NCN26010_TX_HEADER_NORX
#define NCN26010_ADDRFILT3L
#define NCN26010_PLCABURST_BTMR_DEFAULT
#define NCN26010_CONFIG0_SYNC
#define NCN26010_RESET_RESET
#define NCN26010_CTRL_HEADER_MMS
#define NCN26010_CTRL_HEADER_WNR
#define NCN26010_PLCACTRL0
#define NCN26010_MACCTRL0_TXEN
#define NCN26010_TX_HEADER_DNC
#define NCN26010_ADDRFILT0H
#define NCN26010_ETH_RX_BUFFER_SIZE
#define NCN26010_MACCTRL0
#define NCN26010_LOCAL_ID
#define NCN26010_TX_HEADER_EBO
#define NCN26010_PHYCTRL_LINK_CONTROL
#define NCN26010_STATUS0
#define NCN26010_CTRL_HEADER_LEN
#define NCN26010_PLCACTRL1
#define NCN26010_ADDRFILT0L
#define NCN26010_ADDRFILT1H
#define NCN26010_CONFIG0_TXCTHRESH_16_CREDITS
#define NCN26010_TX_HEADER_SV
#define NCN26010_RESET
#define NCN26010_BUFSTS
#define NCN26010_ADDRFILT2H
#define NCN26010_BUFSTS_TXC
#define NCN26010_ADDRFILT1L
#define NCN26010_RX_FOOTER_EBO
#define NCN26010_TX_HEADER_DV
#define NCN26010_CHUNK_PAYLOAD_SIZE
#define NCN26010_RX_FOOTER_EV
#define NCN26010_BUFSTS_RCA
#define NCN26010_CONFIG0_CSARFE
#define NCN26010_MMS_STD
#define NCN26010_MACCTRL0_FCSA
#define NCN26010_STATUS0_RESETC
#define NCN26010_CTRL_HEADER_ADDR
#define NCN26010_DIOCFG_FN0_LED_TX
#define NCN26010_PHYSTATUS
#define NCN26010_PLCABURST_MAXBC_DEFAULT
#define NCN26010_RX_FOOTER_SV
#define NCN26010_DIOCFG
#define NCN26010_CONFIG0_ZARFE
#define NCN26010_MACCTRL0_RXEN
#define NCN26010_PHYCTRL
#define NCN26010_MACCTRL0_BCSF
#define NCN26010_TX_HEADER_EV
#define NCN26010_DIOCFG_FN1_LED_RX
#define NCN26010_PLCACTRL1_ID
#define NCN26010_RX_FOOTER_DV
#define NCN26010_DIOCFG_VAL1
#define NCN26010_MACCTRL0_MCSF
#define NCN26010_ADDRFILT3H
#define NCN26010_CTRL_HEADER_P
#define NCN26010_ADDRFILT2L
#define NCN26010_CONFIG0
#define NCN26010_PLCACTRL1_NCNT
#define NCN26010_DIOCFG_SLEW_RATE_1
#define NCN26010_PLCABURST
#define NCN26010_CONFIG0_CPS_64_BYTES
#define NCN26010_ADDRFILTnH_EN
#define NCN26010_RX_FOOTER_RCA
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
void nicNotifyLinkChange(NetInterface *interface)
Process link state change notification.
Definition: nic.c:548
@ NIC_TYPE_ETHERNET
Ethernet interface.
Definition: nic.h:83
@ NIC_HALF_DUPLEX_MODE
Definition: nic.h:124
@ NIC_LINK_SPEED_10MBPS
Definition: nic.h:111
#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
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.
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