EFM32 Jade Gecko 12 Software Documentation  efm32jg12-doc-5.1.2
Ksz8851snl

Detailed Description

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.

Data Structures

struct  KSZ8851SLN_mib_s
 The MIB (Management Information Base) Counters that the ksz8851snl device expose to the host. More...
 

Macros

#define KSZ8851SNL_INT_ENABLE_MASK
 
#define KSZ8851SNL_INT_ENERGY   0x0004
 
#define KSZ8851SNL_INT_LINK_CHANGE   0x8000
 
#define KSZ8851SNL_INT_LINKUP   0x0008
 
#define KSZ8851SNL_INT_MAGIC   0x0010
 
#define KSZ8851SNL_INT_RX_DONE   0x2000
 
#define KSZ8851SNL_INT_RX_OVERRUN   0x0800
 
#define KSZ8851SNL_INT_RX_STOPPED   0x0100
 
#define KSZ8851SNL_INT_RX_WOL_FRAME   0x0020
 
#define KSZ8851SNL_INT_SPI_ERROR   0x0002
 
#define KSZ8851SNL_INT_TX_DONE   0x4000
 
#define KSZ8851SNL_INT_TX_SPACE   0x0040
 
#define KSZ8851SNL_INT_TX_STOPPED   0x0200
 

Typedefs

typedef struct KSZ8851SLN_mib_s KSZ8851SLN_mib_t
 The MIB (Management Information Base) Counters that the ksz8851snl device expose to the host.
 

Functions

void KSZ8851SNL_AllRegistersDump (void)
 Prints the value of the registers of the ethernet controller. More...
 
void KSZ8851SNL_Enable (void)
 Enable RX and TX.
 
uint16_t KSZ8851SNL_FrameCounterGet (void)
 FrameCounter.
 
void KSZ8851SNL_FrameCounterSet (void)
 FrameCounter.
 
void KSZ8851SNL_Init (void)
 Initialize the registers of the ethernet controller.
 
void KSZ8851SNL_IntClear (uint16_t flags)
 Clear interrupt flags. More...
 
void KSZ8851SNL_IntDisable (void)
 disables the chip interrupts
 
void KSZ8851SNL_IntEnable (void)
 enables the chip interrupts
 
uint16_t KSZ8851SNL_IntGet (void)
 Get interrupt flags.
 
void KSZ8851SNL_MacAddressGet (uint8_t *macAddress)
 Get the MAC address of the current board. More...
 
void KSZ8851SNL_MIBCountersDump (void)
 Dumps the Management Information Base Counters. More...
 
void KSZ8851SNL_MIBCountersUpdate (void)
 Update the Management Information Base Counters. More...
 
uint16_t KSZ8851SNL_PHYStatusGet (void)
 Get the PHY status.
 
void KSZ8851SNL_PMECRStatusClear (uint16_t flags)
 Clear PMECR (Power Management Event Control Register) flags. More...
 
uint16_t KSZ8851SNL_Receive (uint16_t length, uint8_t *buffer)
 Performs the actual receive of a raw frame over the network. More...
 
void KSZ8851SNL_RegistersDump (void)
 Prints the value of the registers of the ethernet controller. More...
 
uint16_t KSZ8851SNL_RXQCRGet (void)
 Get RXQCR register.
 
void KSZ8851SNL_RxQueueReset (void)
 Reset RxQueue.
 
void KSZ8851SNL_SPI_Init (void)
 KSZ8851SNL_SPI_Init Initialize SPI interface to Ethernet controller. More...
 
void KSZ8851SNL_SPI_ReadFifo (int numBytes, uint8_t *data)
 Read data from the ethernet controller RX FIFO. More...
 
uint16_t KSZ8851SNL_SPI_ReadRegister (uint8_t reg)
 Read ethernet controller register. More...
 
void KSZ8851SNL_SPI_WriteFifo (int numBytes, const uint8_t *data)
 Continue writing ethernet controller FIFO. More...
 
void KSZ8851SNL_SPI_WriteFifoBegin (void)
 Start writing to the ethernet controller FIFO.
 
void KSZ8851SNL_SPI_WriteFifoEnd (void)
 Stop read/write the ethernet controller FIFO.
 
void KSZ8851SNL_SPI_WriteRegister (uint8_t reg, uint16_t value)
 Write ethernet controller register. More...
 
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. More...
 
bool KSZ8851SNL_TransmitBegin (uint16_t length)
 Prepares for a transmission of an ethernet frame over the network. More...
 
void KSZ8851SNL_TransmitEnd (uint16_t length)
 Ends a transmission of an ethernet frame to the ethernet controller. More...
 
void KSZ8851SNL_TxQueueReset (void)
 Reset TxQueue.
 

Macro Definition Documentation

#define KSZ8851SNL_INT_ENABLE_MASK
Value:
KSZ8851SNL_INT_RX_STOPPED | \
KSZ8851SNL_INT_TX_STOPPED | \
KSZ8851SNL_INT_LINK_CHANGE | \
KSZ8851SNL_INT_SPI_ERROR)
#define KSZ8851SNL_INT_RX_DONE
Definition: ksz8851snl.h:47

Service RX done, link change and error IRQs.

Definition at line 68 of file ksz8851snl.h.

#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.

Function Documentation

void KSZ8851SNL_AllRegistersDump ( void  )

Prints the value of the registers of the ethernet controller.

Note
Support method used for debugging.

Definition at line 440 of file ksz8851snl.c.

References KSZ8851SNL_SPI_ReadRegister().

void KSZ8851SNL_IntClear ( uint16_t  flags)

Clear interrupt flags.

Parameters
[in]flagsThe interrupt flags to clear

Definition at line 524 of file ksz8851snl.c.

void KSZ8851SNL_MacAddressGet ( uint8_t *  macAddress)

Get the MAC address of the current board.

Note
Support method used for minimizing the code size.
Parameters
[out]macAddressdata buffer to store the macAddress

Definition at line 957 of file ksz8851snl.c.

void KSZ8851SNL_MIBCountersDump ( void  )

Dumps the Management Information Base Counters.

Note
Support method used for debugging.

Definition at line 412 of file ksz8851snl.c.

void KSZ8851SNL_MIBCountersUpdate ( void  )

Update the Management Information Base Counters.

Note
Support method used for debugging.

Definition at line 385 of file ksz8851snl.c.

void KSZ8851SNL_PMECRStatusClear ( uint16_t  flags)

Clear PMECR (Power Management Event Control Register) flags.

Parameters
[in]flagsThe PMECR flags to clear

Definition at line 544 of file ksz8851snl.c.

uint16_t KSZ8851SNL_Receive ( uint16_t  length,
uint8_t *  buffer 
)

Performs the actual receive of a raw frame over the network.

Parameters
[in]lengththe length of the buffer
[in]bufferbuffer to fill with an ethernet frame
Returns
received packet length, 0 in case of failure

Definition at line 882 of file ksz8851snl.c.

void KSZ8851SNL_RegistersDump ( void  )

Prints the value of the registers of the ethernet controller.

Note
Support method used for debugging.

Definition at line 460 of file ksz8851snl.c.

void KSZ8851SNL_SPI_Init ( void  )

KSZ8851SNL_SPI_Init Initialize SPI interface to Ethernet controller.

Note
To enable access, be sure to call the functions BSP_PeripheralAccess(BSP_ETH, true); before using this interface.

Definition at line 57 of file ksz8851snl_spi.c.

References SPIDRV_Init::bitOrder, SPIDRV_Init::bitRate, BOGUS_BYTE, SPIDRV_Init::clockMode, SPIDRV_Init::csControl, SPIDRV_Init::dummyTxValue, ECODE_EMDRV_SPIDRV_OK, ETH_CS_PIN, ETH_CS_PORT, SPIDRV_Init::frameLength, GPIO_PinModeSet(), gpioModePushPull, SPIDRV_Init(), SPIDRV_MASTER_USART1, spidrvBitOrderMsbFirst, spidrvClockMode0, and spidrvCsControlApplication.

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.

Parameters
[in]numBytesNumber of bytes to read, 1-12K
[out]dataBuffer 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.

uint16_t KSZ8851SNL_SPI_ReadRegister ( uint8_t  reg)

Read ethernet controller register.

Parameters
[in]regRegister to read
Returns
value of the register

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, rxBuffer, and SPIDRV_MTransferB().

Referenced by KSZ8851SNL_AllRegistersDump().

void KSZ8851SNL_SPI_WriteFifo ( int  numBytes,
const uint8_t *  data 
)

Continue writing ethernet controller FIFO.

Parameters
[in]numBytesNumber of bytes to write, 1-12K
[in]dataActual bytes to write

Definition at line 289 of file ksz8851snl_spi.c.

References KSZ8851SNL_SPI_Transmit().

void KSZ8851SNL_SPI_WriteRegister ( uint8_t  reg,
uint16_t  value 
)

Write ethernet controller register.

Parameters
[in]regRegister to write
[in]valueThe 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.

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.

Note
If the ethernet packet is divided into several packet buffers then this function should be called for each chunk in order.
Parameters
[in]lengththe length of the data buffer to be transmitted
[in]bufferthe buffer that contains data to be transmitted

Definition at line 808 of file ksz8851snl.c.

bool KSZ8851SNL_TransmitBegin ( uint16_t  length)

Prepares for a transmission of an ethernet frame over the network.

Parameters
[in]lengththe length of frame to be transmitted
Returns
true if transmission is initialized, false if there is not enough tx memory left on the ethernet controller.

Definition at line 744 of file ksz8851snl.c.

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.

Parameters
[in]lengththe length of the complete frame. This is needed so we can pad the transmission to a 4 byte boundary

Definition at line 826 of file ksz8851snl.c.