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