Ksz8851snlKit Drivers
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. | |
| 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. | |
| 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. | |
| 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. | |
| void | KSZ8851SNL_MIBCountersDump (void) | 
| Dumps the Management Information Base Counters. | |
| void | KSZ8851SNL_MIBCountersUpdate (void) | 
| Update the Management Information Base Counters. | |
| uint16_t | KSZ8851SNL_PHYStatusGet (void) | 
| Get the PHY status. | |
| void | KSZ8851SNL_PMECRStatusClear (uint16_t flags) | 
| Clear PMECR (Power Management Event Control Register) flags. | |
| uint16_t | KSZ8851SNL_Receive (uint16_t length, uint8_t *buffer) | 
| Performs the actual receive of a raw frame over the network. | |
| void | KSZ8851SNL_RegistersDump (void) | 
| Prints the value of the registers of the ethernet controller. | |
| 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. | |
| void | KSZ8851SNL_SPI_ReadFifo (int numBytes, uint8_t *data) | 
| Read data from the ethernet controller RX FIFO. | |
| uint16_t | KSZ8851SNL_SPI_ReadRegister (uint8_t reg) | 
| Read ethernet controller register. | |
| void | KSZ8851SNL_SPI_WriteFifo (int numBytes, const uint8_t *data) | 
| Continue writing ethernet controller FIFO. | |
| 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. | |
| 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. | |
| bool | KSZ8851SNL_TransmitBegin (uint16_t length) | 
| Prepares for a transmission of an ethernet frame over the network. | |
| void | KSZ8851SNL_TransmitEnd (uint16_t length) | 
| Ends a transmission of an ethernet frame to the ethernet controller. | |
| void | KSZ8851SNL_TxQueueReset (void) | 
| Reset TxQueue. | |
Macro Definition Documentation
| #define KSZ8851SNL_INT_ENABLE_MASK | 
Service RX done, link change and error IRQs.
        Definition at line
        
         67
        
        of file
        
         ksz8851snl.h
        
        .
       
| #define KSZ8851SNL_INT_ENERGY 0x0004 | 
Enable detect interrupt
        Definition at line
        
         62
        
        of file
        
         ksz8851snl.h
        
        .
       
| #define KSZ8851SNL_INT_LINK_CHANGE 0x8000 | 
Enable link change interrupt
        Definition at line
        
         42
        
        of file
        
         ksz8851snl.h
        
        .
       
| #define KSZ8851SNL_INT_LINKUP 0x0008 | 
Enable link up detect interrupt
        Definition at line
        
         60
        
        of file
        
         ksz8851snl.h
        
        .
       
| #define KSZ8851SNL_INT_MAGIC 0x0010 | 
Enable magic packet detect interrupt
        Definition at line
        
         58
        
        of file
        
         ksz8851snl.h
        
        .
       
| #define KSZ8851SNL_INT_RX_DONE 0x2000 | 
Enable receive interrupt
        Definition at line
        
         46
        
        of file
        
         ksz8851snl.h
        
        .
       
| #define KSZ8851SNL_INT_RX_OVERRUN 0x0800 | 
Enable receive overrun interrupt
        Definition at line
        
         48
        
        of file
        
         ksz8851snl.h
        
        .
       
| #define KSZ8851SNL_INT_RX_STOPPED 0x0100 | 
Enable receive process stopped interrupt
        Definition at line
        
         52
        
        of file
        
         ksz8851snl.h
        
        .
       
| #define KSZ8851SNL_INT_RX_WOL_FRAME 0x0020 | 
Enable WOL on receive wake-up frame detect interrupt
        Definition at line
        
         56
        
        of file
        
         ksz8851snl.h
        
        .
       
| #define KSZ8851SNL_INT_SPI_ERROR 0x0002 | 
Enable receive SPI bus error interrupt
        Definition at line
        
         64
        
        of file
        
         ksz8851snl.h
        
        .
       
| #define KSZ8851SNL_INT_TX_DONE 0x4000 | 
Enable transmit done interrupt
        Definition at line
        
         44
        
        of file
        
         ksz8851snl.h
        
        .
       
| #define KSZ8851SNL_INT_TX_SPACE 0x0040 | 
Enable transmit space available interrupt
        Definition at line
        
         54
        
        of file
        
         ksz8851snl.h
        
        .
       
| #define KSZ8851SNL_INT_TX_STOPPED 0x0200 | 
Enable transmit process stopped interrupt
        Definition at line
        
         50
        
        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
        
         439
        
        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
        
         519
        
        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
        
         940
        
        of file
        
         ksz8851snl.c
        
        .
       
| void KSZ8851SNL_MIBCountersDump | ( | void | 
            | ) | 
Dumps the Management Information Base Counters.
- Note
- Support method used for debugging.
        Definition at line
        
         411
        
        of file
        
         ksz8851snl.c
        
        .
       
| void KSZ8851SNL_MIBCountersUpdate | ( | void | 
            | ) | 
Update the Management Information Base Counters.
- Note
- Support method used for debugging.
        Definition at line
        
         384
        
        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
        
         539
        
        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
        
         870
        
        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
        
         457
        
        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
        
         55
        
        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
        
         246
        
        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
        
         158
        
        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
        
         278
        
        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
        
         199
        
        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
        
         798
        
        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
        
         737
        
        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
        
         816
        
        of file
        
         ksz8851snl.c
        
        .