This module provides a driver for the ksz8851snl ethernet controller. More...
![]() |
Data Structures | |
struct | KSZ8851SLN_mib_t |
The MIB (Management Information Base) Counters that the ksz8851snl device expose to the host. More... | |
Defines | |
#define | KSZ8851SNL_INT_LINK_CHANGE 0x8000 |
Enable link change interrupt. | |
#define | KSZ8851SNL_INT_TX_DONE 0x4000 |
Enable transmit done interrupt. | |
#define | KSZ8851SNL_INT_RX_DONE 0x2000 |
Enable receive interrupt. | |
#define | KSZ8851SNL_INT_RX_OVERRUN 0x0800 |
Enable receive overrun interrupt. | |
#define | KSZ8851SNL_INT_TX_STOPPED 0x0200 |
Enable transmit process stopped interrupt. | |
#define | KSZ8851SNL_INT_RX_STOPPED 0x0100 |
Enable receive process stopped interrupt. | |
#define | KSZ8851SNL_INT_TX_SPACE 0x0040 |
Enable transmit space available interrupt. | |
#define | KSZ8851SNL_INT_RX_WOL_FRAME 0x0020 |
Enable WOL on receive wake-up frame detect interrupt. | |
#define | KSZ8851SNL_INT_MAGIC 0x0010 |
Enable magic packet detect interrupt. | |
#define | KSZ8851SNL_INT_LINKUP 0x0008 |
Enable link up detect interrupt. | |
#define | KSZ8851SNL_INT_ENERGY 0x0004 |
Enable detect interrupt. | |
#define | KSZ8851SNL_INT_SPI_ERROR 0x0002 |
Enable receive SPI bus error interrupt. | |
#define | KSZ8851SNL_INT_ENABLE_MASK |
Service RX done, link change and error IRQs. | |
Functions | |
void | KSZ8851SNL_Init (void) |
Initialize the registers of the ethernet controller. | |
void | KSZ8851SNL_Enable (void) |
Enable RX and TX. | |
uint16_t | KSZ8851SNL_Receive (uint16_t length, uint8_t *buffer) |
Performs the actual receive of a raw frame over the network. | |
bool | KSZ8851SNL_TransmitBegin (uint16_t length) |
Prepares for a transmission of an ethernet frame over the network. | |
void | KSZ8851SNL_Transmit (uint16_t length, const uint8_t *buffer) |
Transmit a chunk of data to the ethernet controller. | |
void | KSZ8851SNL_TransmitEnd (uint16_t length) |
Ends a transmission of an ethernet frame to the ethernet controller. | |
void | KSZ8851SNL_MacAddressGet (uint8_t *macAddress) |
Get the MAC address of the current board. | |
void | KSZ8851SNL_PMECRStatusClear (uint16_t flags) |
Clear PMECR (Power Management Event Control Register) flags. | |
void | KSZ8851SNL_FrameCounterSet (void) |
FrameCounter. | |
uint16_t | KSZ8851SNL_FrameCounterGet (void) |
FrameCounter. | |
void | KSZ8851SNL_IntEnable (void) |
enables the chip interrupts | |
void | KSZ8851SNL_IntDisable (void) |
disables the chip interrupts | |
void | KSZ8851SNL_IntClear (uint16_t flags) |
Clear interrupt flags. | |
uint16_t | KSZ8851SNL_IntGet (void) |
Get interrupt flags. | |
uint16_t | KSZ8851SNL_RXQCRGet (void) |
Get RXQCR register. | |
uint16_t | KSZ8851SNL_PHYStatusGet (void) |
Get the PHY status. | |
void | KSZ8851SNL_TxQueueReset (void) |
Reset TxQueue. | |
void | KSZ8851SNL_RxQueueReset (void) |
Reset RxQueue. | |
void | KSZ8851SNL_RegistersDump (void) |
Prints the value of the registers of the ethernet controller. | |
void | KSZ8851SNL_AllRegistersDump (void) |
Prints the value of the registers of the ethernet controller. | |
void | KSZ8851SNL_MIBCountersDump (void) |
Dumps the Management Information Base Counters. | |
void | KSZ8851SNL_MIBCountersUpdate (void) |
Update the Management Information Base Counters. | |
void | KSZ8851SNL_SPI_Init (void) |
KSZ8851SNL_SPI_Init Initialize SPI interface to Ethernet controller. | |
uint16_t | KSZ8851SNL_SPI_ReadRegister (uint8_t reg) |
Read ethernet controller register. | |
void | KSZ8851SNL_SPI_WriteRegister (uint8_t reg, uint16_t value) |
Write ethernet controller register. | |
void | KSZ8851SNL_SPI_ReadFifo (int numBytes, uint8_t *data) |
Read data from the ethernet controller RX FIFO. | |
void | KSZ8851SNL_SPI_WriteFifoBegin (void) |
Start writing to the ethernet controller FIFO. | |
void | KSZ8851SNL_SPI_WriteFifo (int numBytes, const uint8_t *data) |
Continue writing ethernet controller FIFO. | |
void | KSZ8851SNL_SPI_WriteFifoEnd (void) |
Stop read/write the ethernet controller FIFO. |
This module provides a driver for the ksz8851snl ethernet controller.
The ksz8851snl is a single-chip ethernet controller which supports 10/100 Mbps full and half-duplex communication. It has integrated 12KiB RX FIFO and a 6KiB TX FIFO and it is controlled using SPI. This module contains functions for the necessary SPI commands for reading/writing registers and reading from and writing to the FIFO's.
#define KSZ8851SNL_INT_ENABLE_MASK |
(KSZ8851SNL_INT_RX_DONE | \ KSZ8851SNL_INT_RX_STOPPED | \ KSZ8851SNL_INT_TX_STOPPED | \ KSZ8851SNL_INT_LINK_CHANGE | \ KSZ8851SNL_INT_SPI_ERROR)
Service RX done, link change and error IRQs.
Definition at line 68 of file ksz8851snl.h.
Referenced by KSZ8851SNL_Enable(), and KSZ8851SNL_IntEnable().
#define KSZ8851SNL_INT_ENERGY 0x0004 |
Enable detect interrupt.
Definition at line 63 of file ksz8851snl.h.
#define KSZ8851SNL_INT_LINK_CHANGE 0x8000 |
Enable link change interrupt.
Definition at line 43 of file ksz8851snl.h.
#define KSZ8851SNL_INT_LINKUP 0x0008 |
Enable link up detect interrupt.
Definition at line 61 of file ksz8851snl.h.
#define KSZ8851SNL_INT_MAGIC 0x0010 |
Enable magic packet detect interrupt.
Definition at line 59 of file ksz8851snl.h.
#define KSZ8851SNL_INT_RX_DONE 0x2000 |
Enable receive interrupt.
Definition at line 47 of file ksz8851snl.h.
#define KSZ8851SNL_INT_RX_OVERRUN 0x0800 |
Enable receive overrun interrupt.
Definition at line 49 of file ksz8851snl.h.
#define KSZ8851SNL_INT_RX_STOPPED 0x0100 |
Enable receive process stopped interrupt.
Definition at line 53 of file ksz8851snl.h.
#define KSZ8851SNL_INT_RX_WOL_FRAME 0x0020 |
Enable WOL on receive wake-up frame detect interrupt.
Definition at line 57 of file ksz8851snl.h.
#define KSZ8851SNL_INT_SPI_ERROR 0x0002 |
Enable receive SPI bus error interrupt.
Definition at line 65 of file ksz8851snl.h.
#define KSZ8851SNL_INT_TX_DONE 0x4000 |
Enable transmit done interrupt.
Definition at line 45 of file ksz8851snl.h.
#define KSZ8851SNL_INT_TX_SPACE 0x0040 |
Enable transmit space available interrupt.
Definition at line 55 of file ksz8851snl.h.
#define KSZ8851SNL_INT_TX_STOPPED 0x0200 |
Enable transmit process stopped interrupt.
Definition at line 51 of file ksz8851snl.h.
void KSZ8851SNL_AllRegistersDump | ( | void | ) |
Prints the value of the registers of the ethernet controller.
Definition at line 437 of file ksz8851snl.c.
References KSZ8851SNL_SPI_ReadRegister().
void KSZ8851SNL_Enable | ( | void | ) |
Enable RX and TX.
Definition at line 712 of file ksz8851snl.c.
References IER, KSZ8851SNL_INT_ENABLE_MASK, KSZ8851SNL_SPI_ReadRegister(), KSZ8851SNL_SPI_WriteRegister(), RX_FLOW_CTRL_RX_ENABLE, RXCR1, TX_FLOW_CTRL_ENABLE, and TXCR.
uint16_t KSZ8851SNL_FrameCounterGet | ( | void | ) |
FrameCounter.
Definition at line 612 of file ksz8851snl.c.
void KSZ8851SNL_FrameCounterSet | ( | void | ) |
FrameCounter.
Definition at line 558 of file ksz8851snl.c.
References KSZ8851SNL_SPI_ReadRegister(), MSB_POS, and RXFCTR.
void KSZ8851SNL_Init | ( | void | ) |
Initialize the registers of the ethernet controller.
Definition at line 620 of file ksz8851snl.c.
References CHIP_ID_MASK, CIDER, CLEAR_INT, FCLWR, FD_PTR_AUTO_INC, FRAME_COUNT_THRESHOLD, GLOBAL_SOFT_RESET, GRR, ISR, KSZ8851SNL_CHIP_ID, KSZ8851SNL_MacAddressGet(), KSZ8851SNL_SPI_Init(), KSZ8851SNL_SPI_ReadRegister(), KSZ8851SNL_SPI_WriteRegister(), MARH, MARL, MARM, P1CR, PHY_RESET, PHYRR, PORT1_AUTO_NEG_RESTART, PORT1_CONFIG, RX_FLOW_CTRL1_CONFIG, RX_FLOW_CTRL2_CONFIG, RXCR1, RXCR2, RXFCTR, RXFDPR, RXQ_CMD_CONFIG, RXQCR, TX_FLOW_CTRL_CONFIG, TXCR, and TXFDPR.
void KSZ8851SNL_IntClear | ( | uint16_t | flags | ) |
Clear interrupt flags.
[in] | flags | The interrupt flags to clear |
Definition at line 521 of file ksz8851snl.c.
References ISR, and KSZ8851SNL_SPI_WriteRegister().
void KSZ8851SNL_IntDisable | ( | void | ) |
disables the chip interrupts
Definition at line 508 of file ksz8851snl.c.
References IER, KSZ8851SNL_SPI_WriteRegister(), and NO_INT.
void KSZ8851SNL_IntEnable | ( | void | ) |
enables the chip interrupts
Definition at line 492 of file ksz8851snl.c.
References IER, KSZ8851SNL_INT_ENABLE_MASK, and KSZ8851SNL_SPI_WriteRegister().
uint16_t KSZ8851SNL_IntGet | ( | void | ) |
Get interrupt flags.
Definition at line 529 of file ksz8851snl.c.
References ISR, and KSZ8851SNL_SPI_ReadRegister().
void KSZ8851SNL_MacAddressGet | ( | uint8_t * | macAddress | ) |
Get the MAC address of the current board.
[out] | macAddress | data buffer to store the macAddress |
Definition at line 950 of file ksz8851snl.c.
References BYTE_SIZE, HIGH_QMU_MAC_H, HIGH_QMU_MAC_L, and MID_QMU_MAC_H.
Referenced by KSZ8851SNL_Init().
void KSZ8851SNL_MIBCountersDump | ( | void | ) |
Dumps the Management Information Base Counters.
Definition at line 409 of file ksz8851snl.c.
References KSZ8851SLN_mib_t::RxBroadcastCnt, KSZ8851SLN_mib_t::RxByteCnt, KSZ8851SLN_mib_t::RxCRCErrorCnt, KSZ8851SLN_mib_t::RxFragmentsCnt, KSZ8851SLN_mib_t::RxJabbersCnt, KSZ8851SLN_mib_t::RxMulticastCnt, KSZ8851SLN_mib_t::RxOversizeCnt, KSZ8851SLN_mib_t::RxPausePktsCnt, KSZ8851SLN_mib_t::RxSymbolErrorCnt, KSZ8851SLN_mib_t::RxUndersizePktCnt, KSZ8851SLN_mib_t::RxUnicastCnt, KSZ8851SLN_mib_t::TxBroadcastPktsCnt, KSZ8851SLN_mib_t::TxByteCnt, KSZ8851SLN_mib_t::TxDeferredCnt, KSZ8851SLN_mib_t::TxMulticastPktsCnt, KSZ8851SLN_mib_t::TxPausePktsCnt, KSZ8851SLN_mib_t::TxTotalCollisionCnt, and KSZ8851SLN_mib_t::TxUnicastPktsCnt.
void KSZ8851SNL_MIBCountersUpdate | ( | void | ) |
Update the Management Information Base Counters.
Definition at line 382 of file ksz8851snl.c.
References MIB_RxBroadcast, MIB_RxByte, MIB_RxCRCError, MIB_RxFragments, MIB_RxJabbers, MIB_RxMulticast, MIB_RxOversize, MIB_RxPausePkts, MIB_RxSymbolError, MIB_RxUndersizePkt, MIB_RxUnicast, MIB_TxBroadcastPkts, MIB_TxByte, MIB_TxDeferred, MIB_TxMulticastPkts, MIB_TxPausePkts, MIB_TxTotalCollision, MIB_TxUnicastPkts, MIBCountersRead(), KSZ8851SLN_mib_t::RxBroadcastCnt, KSZ8851SLN_mib_t::RxByteCnt, KSZ8851SLN_mib_t::RxCRCErrorCnt, KSZ8851SLN_mib_t::RxFragmentsCnt, KSZ8851SLN_mib_t::RxJabbersCnt, KSZ8851SLN_mib_t::RxMulticastCnt, KSZ8851SLN_mib_t::RxOversizeCnt, KSZ8851SLN_mib_t::RxPausePktsCnt, KSZ8851SLN_mib_t::RxSymbolErrorCnt, KSZ8851SLN_mib_t::RxUndersizePktCnt, KSZ8851SLN_mib_t::RxUnicastCnt, KSZ8851SLN_mib_t::TxBroadcastPktsCnt, KSZ8851SLN_mib_t::TxByteCnt, KSZ8851SLN_mib_t::TxDeferredCnt, KSZ8851SLN_mib_t::TxMulticastPktsCnt, KSZ8851SLN_mib_t::TxPausePktsCnt, KSZ8851SLN_mib_t::TxTotalCollisionCnt, and KSZ8851SLN_mib_t::TxUnicastPktsCnt.
uint16_t KSZ8851SNL_PHYStatusGet | ( | void | ) |
Get the PHY status.
Definition at line 971 of file ksz8851snl.c.
References KSZ8851SNL_SPI_ReadRegister(), and P1SR.
void KSZ8851SNL_PMECRStatusClear | ( | uint16_t | flags | ) |
Clear PMECR (Power Management Event Control Register) flags.
[in] | flags | The PMECR flags to clear |
Definition at line 541 of file ksz8851snl.c.
References KSZ8851SNL_SPI_ReadRegister(), KSZ8851SNL_SPI_WriteRegister(), and PMECR.
uint16_t KSZ8851SNL_Receive | ( | uint16_t | length, | |
uint8_t * | buffer | |||
) |
Performs the actual receive of a raw frame over the network.
[in] | length | the length of the buffer |
[in] | buffer | buffer to fill with an ethernet frame |
Definition at line 875 of file ksz8851snl.c.
References CHECKSUM_VALID_FRAME_MASK, FD_PTR_AUTO_INC, KSZ8851SNL_SPI_ReadFifo(), KSZ8851SNL_SPI_ReadRegister(), KSZ8851SNL_SPI_WriteRegister(), ReleaseIncosistentFrame(), RX_BYTE_CNT_MASK, RXFDPR, RXFHBCR, RXFHSR, RXQ_START_DMA, RXQCR, and VALID_FRAME_MASK.
void KSZ8851SNL_RegistersDump | ( | void | ) |
Prints the value of the registers of the ethernet controller.
Definition at line 457 of file ksz8851snl.c.
References CIDER, GRR, IER, ISR, KSZ8851SNL_SPI_ReadRegister(), MARH, MARL, MARM, OBCR, P1CR, P1MBCR, PHYRR, RXCR1, RXCR2, RXFCTR, RXFDPR, RXFHSR, RXQCR, TXCR, TXFDPR, TXMIR, TXNTFSR, and TXQCR.
uint16_t KSZ8851SNL_RXQCRGet | ( | void | ) |
Get RXQCR register.
Definition at line 550 of file ksz8851snl.c.
References KSZ8851SNL_SPI_ReadRegister(), and RXQCR.
void KSZ8851SNL_RxQueueReset | ( | void | ) |
Reset RxQueue.
Definition at line 591 of file ksz8851snl.c.
References KSZ8851SNL_SPI_ReadRegister(), KSZ8851SNL_SPI_WriteRegister(), RX_FLOW_CTRL_FLUSH_QUEUE, RX_FLOW_CTRL_RX_ENABLE, and RXCR1.
void KSZ8851SNL_SPI_Init | ( | void | ) |
KSZ8851SNL_SPI_Init Initialize SPI interface to Ethernet controller.
Definition at line 57 of file ksz8851snl_spi.c.
References BOGUS_BYTE, ETH_CS_PIN, and ETH_CS_PORT.
Referenced by KSZ8851SNL_Init().
void KSZ8851SNL_SPI_ReadFifo | ( | int | numBytes, | |
uint8_t * | data | |||
) |
Read data from the ethernet controller RX FIFO.
Make sure that the ethernet controller is in DMA mode before calling this function. This is configured by setting bit 3 in the RXQCR register. This bit should also be cleared whenever you want to access the control registers.
When reading data from the controller the first 4 bytes is always dummy data and is skipped by this function.
[in] | numBytes | Number of bytes to read, 1-12K |
[out] | data | Buffer where the bytes are inserted. |
Definition at line 257 of file ksz8851snl_spi.c.
References KSZ8851SNL_SPI_Receive(), KSZ8851SNL_SPI_SetChipSelect(), KSZ8851SNL_SPI_Transmit(), and OPCODE_FIFO_READ.
Referenced by KSZ8851SNL_Receive().
uint16_t KSZ8851SNL_SPI_ReadRegister | ( | uint8_t | reg | ) |
Read ethernet controller register.
[in] | reg | Register to read |
SPI Command Format
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |op | byte | reg[7:2] | ... | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
op=00 "Register Read" byte=0011 "Read register at reg" byte=1100 "Read register at reg+2" reg=6 most significant bits of the register address
Definition at line 167 of file ksz8851snl_spi.c.
References ADDRESS_MS2B_POS, ADDRESS_SHIFT, BYTE_ENABLE, BYTE_ENABLE_SHIFT, KSZ8851SNL_SPI_SetChipSelect(), OPCODE_REG_READ, REG_MASK, and rxBuffer.
Referenced by KSZ8851SNL_AllRegistersDump(), KSZ8851SNL_Enable(), KSZ8851SNL_FrameCounterSet(), KSZ8851SNL_Init(), KSZ8851SNL_IntGet(), KSZ8851SNL_PHYStatusGet(), KSZ8851SNL_PMECRStatusClear(), KSZ8851SNL_Receive(), KSZ8851SNL_RegistersDump(), KSZ8851SNL_RXQCRGet(), KSZ8851SNL_RxQueueReset(), KSZ8851SNL_TransmitBegin(), KSZ8851SNL_TransmitEnd(), KSZ8851SNL_TxQueueReset(), MIBCountersRead(), and ReleaseIncosistentFrame().
void KSZ8851SNL_SPI_WriteFifo | ( | int | numBytes, | |
const uint8_t * | data | |||
) |
Continue writing ethernet controller FIFO.
[in] | numBytes | Number of bytes to write, 1-12K |
[in] | data | Actual bytes to write |
Definition at line 289 of file ksz8851snl_spi.c.
References KSZ8851SNL_SPI_Transmit().
Referenced by KSZ8851SNL_Transmit(), KSZ8851SNL_TransmitBegin(), and KSZ8851SNL_TransmitEnd().
void KSZ8851SNL_SPI_WriteFifoBegin | ( | void | ) |
Start writing to the ethernet controller FIFO.
Definition at line 275 of file ksz8851snl_spi.c.
References KSZ8851SNL_SPI_SetChipSelect(), KSZ8851SNL_SPI_Transmit(), and OPCODE_FIFO_WRITE.
Referenced by KSZ8851SNL_TransmitBegin().
void KSZ8851SNL_SPI_WriteFifoEnd | ( | void | ) |
Stop read/write the ethernet controller FIFO.
Definition at line 301 of file ksz8851snl_spi.c.
References KSZ8851SNL_SPI_SetChipSelect().
Referenced by KSZ8851SNL_TransmitEnd().
void KSZ8851SNL_SPI_WriteRegister | ( | uint8_t | reg, | |
uint16_t | value | |||
) |
Write ethernet controller register.
[in] | reg | Register to write |
[in] | value | The value to be written into the register |
SPI Command Format
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |op | byte | reg[7:2] | ... | 16 bit value | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
op=01 "Register Write" byte=0011 "Write register at reg" byte=1100 "Write register at reg+2" reg=6 most significant bits of the register address
Definition at line 209 of file ksz8851snl_spi.c.
References ADDRESS_MS2B_POS, ADDRESS_SHIFT, BYTE_ENABLE, BYTE_ENABLE_SHIFT, KSZ8851SNL_SPI_SetChipSelect(), KSZ8851SNL_SPI_Transmit(), OPCODE_REG_WRITE, and REG_MASK.
Referenced by KSZ8851SNL_Enable(), KSZ8851SNL_Init(), KSZ8851SNL_IntClear(), KSZ8851SNL_IntDisable(), KSZ8851SNL_IntEnable(), KSZ8851SNL_PMECRStatusClear(), KSZ8851SNL_Receive(), KSZ8851SNL_RxQueueReset(), KSZ8851SNL_TransmitBegin(), KSZ8851SNL_TransmitEnd(), KSZ8851SNL_TxQueueReset(), MIBCountersRead(), and ReleaseIncosistentFrame().
void KSZ8851SNL_Transmit | ( | uint16_t | length, | |
const uint8_t * | buffer | |||
) |
Transmit a chunk of data to the ethernet controller.
The chunk can be either a full ethernet frame or a partial chunk of an ethernet frame.
[in] | length | the length of the data buffer to be transmitted |
[in] | buffer | the buffer that contains data to be transmitted |
Definition at line 801 of file ksz8851snl.c.
References KSZ8851SNL_SPI_WriteFifo().
bool KSZ8851SNL_TransmitBegin | ( | uint16_t | length | ) |
Prepares for a transmission of an ethernet frame over the network.
[in] | length | the length of frame to be transmitted |
Definition at line 737 of file ksz8851snl.c.
References FRAME_ID_MASK, KSZ8851SNL_SPI_ReadRegister(), KSZ8851SNL_SPI_WriteFifo(), KSZ8851SNL_SPI_WriteFifoBegin(), KSZ8851SNL_SPI_WriteRegister(), LSB_MASK, MSB_POS, RXQ_START_DMA, RXQCR, TX_MEM_AVAIL_MASK, TXMIR, TXQ_ENQUEUE, and TXQCR.
void KSZ8851SNL_TransmitEnd | ( | uint16_t | length | ) |
Ends a transmission of an ethernet frame to the ethernet controller.
This will make sure that data is correctly padded. And will not return until the packet is sent.
[in] | length | the length of the complete frame. This is needed so we can pad the transmission to a 4 byte boundary |
Definition at line 819 of file ksz8851snl.c.
References KSZ8851SNL_SPI_ReadRegister(), KSZ8851SNL_SPI_WriteFifo(), KSZ8851SNL_SPI_WriteFifoEnd(), KSZ8851SNL_SPI_WriteRegister(), RXQ_START_DMA, RXQCR, TXQ_ENQUEUE, and TXQCR.
void KSZ8851SNL_TxQueueReset | ( | void | ) |
Reset TxQueue.
Definition at line 569 of file ksz8851snl.c.
References KSZ8851SNL_SPI_ReadRegister(), KSZ8851SNL_SPI_WriteRegister(), TX_FLOW_CTRL_ENABLE, TX_FLOW_CTRL_FLUSH_QUEUE, and TXCR.