Go to the documentation of this file.
32 #define TRACE_LEVEL NIC_TRACE_LEVEL
79 TRACE_INFO(
"Initializing KSZ8851 Ethernet controller...\r\n");
81 #if (KSZ8851_SPI_SUPPORT == ENABLED)
83 interface->spiDriver->init();
87 if(interface->extIntDriver != NULL)
89 interface->extIntDriver->init();
169 interface->nicEvent =
TRUE;
206 if(interface->extIntDriver != NULL)
208 interface->extIntDriver->enableIrq();
221 if(interface->extIntDriver != NULL)
223 interface->extIntDriver->disableIrq();
259 interface->nicEvent =
TRUE;
288 interface->nicEvent =
TRUE;
347 interface->linkState =
TRUE;
352 interface->linkState =
FALSE;
368 while(frameCount > 0)
554 uint16_t hashTable[4];
561 osMemset(hashTable, 0,
sizeof(hashTable));
568 entry = &interface->macAddrFilter[i];
576 k = (crc >> 26) & 0x3F;
578 hashTable[k / 16] |= (1 << (k % 16));
608 #if (KSZ8851_SPI_SUPPORT == ENABLED)
622 interface->spiDriver->assertCs();
625 interface->spiDriver->transfer(command | (
address >> 6));
626 interface->spiDriver->transfer(
address << 2);
629 interface->spiDriver->transfer(
LSB(
data));
630 interface->spiDriver->transfer(
MSB(
data));
633 interface->spiDriver->deassertCs();
660 #if (KSZ8851_SPI_SUPPORT == ENABLED)
675 interface->spiDriver->assertCs();
678 interface->spiDriver->transfer(command | (
address >> 6));
679 interface->spiDriver->transfer(
address << 2);
682 data = interface->spiDriver->transfer(0x00);
684 data |= interface->spiDriver->transfer(0x00) << 8;
687 interface->spiDriver->deassertCs();
718 #if (KSZ8851_SPI_SUPPORT == ENABLED)
722 interface->spiDriver->assertCs();
728 for(i = 0; i <
length; i++)
730 interface->spiDriver->transfer(
data[i]);
734 for(; (i % 4) != 0; i++)
736 interface->spiDriver->transfer(0x00);
740 interface->spiDriver->deassertCs();
745 for(i = 0; i <
length; i += 2)
751 for(; (i % 4) != 0; i += 2)
768 #if (KSZ8851_SPI_SUPPORT == ENABLED)
772 interface->spiDriver->assertCs();
778 for(i = 0; i < 4; i++)
780 interface->spiDriver->transfer(0x00);
784 for(i = 0; i < 4; i++)
786 interface->spiDriver->transfer(0x00);
790 for(i = 0; i <
length; i++)
792 data[i] = interface->spiDriver->transfer(0x00);
796 for(; (i % 4) != 0; i++)
798 interface->spiDriver->transfer(0x00);
802 interface->spiDriver->deassertCs();
815 for(i = 0; i <
length; i += 2)
818 data [i] = temp & 0xFF;
819 data [i + 1] = (temp >> 8) & 0xFF;
823 for(; (i % 4) != 0; i += 2)
882 p = (uint8_t *)
data;
887 for(i = 0; i <
length; i++)
890 for(j = 0; j < 8; j++)
893 if((((crc >> 31) ^ (
p[i] >> j)) & 0x01) != 0)
895 crc = (crc << 1) ^ 0x04C11DB7;
916 #if (TRACE_LEVEL >= TRACE_LEVEL_DEBUG)
922 for(i = 0; i < 256; i += 16)
928 for(j = 0; j < 16; j += 2)
bool_t osSetEventFromIsr(OsEvent *event)
Set an event object to the signaled state from an interrupt service routine.
#define KSZ8851_RXCR1_RXME
void nicNotifyLinkChange(NetInterface *interface)
Process link state change notification.
#define KSZ8851_TXCR_TXPE
void ksz8851EventHandler(NetInterface *interface)
KSZ8851 event handler.
void ksz8851ClearBit(NetInterface *interface, uint8_t address, uint16_t mask)
Clear bit field.
#define KSZ8851_RXCR1_RXE
#define KSZ8851_P1SR_LINK_GOOD
void ksz8851WriteFifo(NetInterface *interface, const uint8_t *data, size_t length)
Write TX FIFO.
#define KSZ8851_RXQCR_RXFCTE
#define KSZ8851_CMD_RD_FIFO
#define KSZ8851_P1CR_FORCE_DUPLEX
#define KSZ8851_RXFHSR_RXFTL
size_t netBufferRead(void *dest, const NetBuffer *src, size_t srcOffset, size_t length)
Read data from a multi-part buffer.
uint16_t frameId
Identify a frame and its associated status.
Structure describing a buffer that spans multiple chunks.
#define MAC_ADDR_FILTER_SIZE
#define KSZ8851_CIDER_REV_ID_A3
void ksz8851Tick(NetInterface *interface)
KSZ8851 timer handler.
uint_t refCount
Reference count for the current entry.
const NicDriver ksz8851Driver
KSZ8851 driver.
#define KSZ8851_P1CR_RESTART_AN
#define KSZ8851_CMD_RD_REG
#define KSZ8851_TXCR_TXFCE
#define KSZ8851_ISR_RXWFDIS
void nicProcessPacket(NetInterface *interface, uint8_t *packet, size_t length, NetRxAncillary *ancillary)
Handle a packet received by the network controller.
#define KSZ8851_RXCR1_RXPAFMA
#define KSZ8851_ISR_TXSAIS
void ksz8851WriteReg(NetInterface *interface, uint8_t address, uint16_t data)
Write KSZ8851 register.
#define KSZ8851_RXFHSR_RXMR
void ksz8851DumpReg(NetInterface *interface)
Dump registers for debugging purpose.
#define KSZ8851_P1SR_OPERATION_SPEED
#define KSZ8851_ISR_RXMPDIS
error_t ksz8851Init(NetInterface *interface)
KSZ8851 controller initialization.
#define KSZ8851_CMD_WR_REG
#define KSZ8851_ISR_RXPSIS
bool_t ksz8851IrqHandler(NetInterface *interface)
KSZ8851 interrupt service routine.
void ksz8851ReadFifo(NetInterface *interface, uint8_t *data, size_t length)
Read RX FIFO.
const NetRxAncillary NET_DEFAULT_RX_ANCILLARY
@ ERROR_FAILURE
Generic error code.
#define KSZ8851_ISR_TXPSIS
#define KSZ8851_CMD_WR_FIFO
#define KSZ8851_TXQCR_METFE
#define KSZ8851_TXMIR_TXMA
size_t netBufferGetLength(const NetBuffer *buffer)
Get the actual length of a multi-part buffer.
error_t ksz8851UpdateMacAddrFilter(NetInterface *interface)
Configure MAC address filtering.
#define KSZ8851_RXCR2_IUFFP
#define KSZ8851_RXQCR_ADRFE
#define KSZ8851_RXCR1_RXBE
__weak_func void ksz8851InitHook(NetInterface *interface)
KSZ8851 custom configuration.
#define KSZ8851_TXFDPR_TXFPAI
#define KSZ8851_ETH_TX_BUFFER_SIZE
#define KSZ8851_RXQCR_RRXEF
#define KSZ8851_P1SR_OPERATION_DUPLEX
#define KSZ8851_RXFDPR_RXFPAI
#define KSZ8851_RXFHSR_RXRF
#define KSZ8851_ISR_RXOIS
error_t ksz8851ReceivePacket(NetInterface *interface)
Receive a packet.
#define KSZ8851_ISR_SPIBEIS
uint16_t ksz8851ReadReg(NetInterface *interface, uint8_t address)
Read KSZ8851 register.
#define KSZ8851_TXCR_TXCE
KSZ8851 Ethernet controller.
#define KSZ8851_RXCR2_RXIUFCEZ
void ksz8851DisableIrq(NetInterface *interface)
Disable interrupts.
void osSetEvent(OsEvent *event)
Set the specified event object to the signaled state.
#define KSZ8851_ETH_RX_BUFFER_SIZE
#define KSZ8851_RXCR2_SRDBL_SINGLE_FRAME
#define KSZ8851_CIDER_FAMILY_ID_DEFAULT
void ksz8851EnableIrq(NetInterface *interface)
Enable interrupts.
#define KSZ8851_RXCR1_RXFCE
#define KSZ8851_RXFHSR_RXFV
#define KSZ8851_TX_CTRL_TXIC
#define osMemset(p, value, length)
#define KSZ8851_CIDER_CHIP_ID_DEFAULT
error_t ksz8851SendPacket(NetInterface *interface, const NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary)
Send a packet.
#define KSZ8851_RXQCR_SDA
void ksz8851SetBit(NetInterface *interface, uint8_t address, uint16_t mask)
Set bit field.
#define KSZ8851_RXCR1_RXUE
#define KSZ8851_RXFHBCR_RXBC
#define KSZ8851_TX_CTRL_TXFID
uint32_t ksz8851CalcCrc(const void *data, size_t length)
CRC calculation.
#define KSZ8851_RXFHSR_RXCE
@ NIC_TYPE_ETHERNET
Ethernet interface.