EFM32 Jade Gecko 12 Software Documentation
efm32jg12-doc-5.1.2
|
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. | |
#define KSZ8851SNL_INT_ENABLE_MASK |
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.
void KSZ8851SNL_AllRegistersDump | ( | void | ) |
Prints the value of the registers of the ethernet controller.
Definition at line 440 of file ksz8851snl.c.
References KSZ8851SNL_SPI_ReadRegister().
void KSZ8851SNL_IntClear | ( | uint16_t | flags | ) |
Clear interrupt flags.
[in] | flags | The 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.
[out] | macAddress | data buffer to store the macAddress |
Definition at line 957 of file ksz8851snl.c.
void KSZ8851SNL_MIBCountersDump | ( | void | ) |
Dumps the Management Information Base Counters.
Definition at line 412 of file ksz8851snl.c.
void KSZ8851SNL_MIBCountersUpdate | ( | void | ) |
Update the Management Information Base Counters.
Definition at line 385 of file ksz8851snl.c.
void KSZ8851SNL_PMECRStatusClear | ( | uint16_t | flags | ) |
Clear PMECR (Power Management Event Control Register) flags.
[in] | flags | The 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.
[in] | length | the length of the buffer |
[in] | buffer | buffer to fill with an ethernet frame |
Definition at line 882 of file ksz8851snl.c.
void KSZ8851SNL_RegistersDump | ( | void | ) |
Prints the value of the registers of the ethernet controller.
Definition at line 460 of file ksz8851snl.c.
void KSZ8851SNL_SPI_Init | ( | void | ) |
KSZ8851SNL_SPI_Init Initialize SPI interface to Ethernet controller.
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.
[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.
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, rxBuffer, and SPIDRV_MTransferB().
Referenced by KSZ8851SNL_AllRegistersDump().
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().
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.
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 808 of file ksz8851snl.c.
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 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.
[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 826 of file ksz8851snl.c.