Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
KSZ8851SNL ethernet PHY driver

This is a low level driver for the KSZ8851SNL ethernet PHY through 4-wire SPI.

It provides functions for configuring and communicating with the ethernet PHY.

Before writing data to the ethernet PHY call ksz8851snl_init() which will set up the physical interface and the PHY. A file named conf_eth.h is needed to define which interface to use. In addition one also need to define the pins KSZ8851SNL_RSTN_PIN, KSZ8851SNL_CS_PIN and KSZ8851SNL_INTN_EIC_PIN and the PHY KSZ8851SNL_CLOCK_SPEED.

Warning
This driver is not reentrant and can not be used in interrupt\ service routines without extra care.

An example conf_eth.h file could look like

* // Interface configuration for SAM D20 Xplained Pro
* #define KSZ8851SNL_SPI EXT1_SPI_MODULE
* #define KSZ8851SNL_SPI_IRQn SERCOM0_IRQn
*
* // Pins configuration.
* #define KSZ8851SNL_RSTN_PIN EXT1_PIN_6
* #define KSZ8851SNL_CS_PIN EXT1_PIN_15
* #define KSZ8851SNL_INTN_EIC_CHANNEL EXT1_IRQ_INPUT
* #define KSZ8851SNL_INTN_EIC_PIN EXT1_IRQ_PIN
* #define KSZ8851SNL_INTN_EIC_PIN_MUX EXT1_IRQ_PINMUX
*
* // SPI settings.
* #define KSZ8851SNL_SPI_PINMUX_SETTING EXT1_SPI_SERCOM_MUX_SETTING
* #define KSZ8851SNL_SPI_PINMUX_PAD0 EXT1_SPI_SERCOM_PINMUX_PAD0
* #define KSZ8851SNL_SPI_PINMUX_PAD1 PINMUX_UNUSED
* #define KSZ8851SNL_SPI_PINMUX_PAD2 EXT1_SPI_SERCOM_PINMUX_PAD2
* #define KSZ8851SNL_SPI_PINMUX_PAD3 EXT1_SPI_SERCOM_PINMUX_PAD3
* #define KSZ8851SNL_CLOCK_SPEED 10000000UL
*

Dependencies

This driver depends on the following modules:

Variables

struct spi_module ksz8851snl_master
 
struct spi_slave_inst ksz8851snl_slave
 

PHY register read/write functions

uint16_t ksz8851_reg_read (uint16_t reg)
 Read a register value. More...
 
void ksz8851_reg_write (uint16_t reg, uint16_t wrdata)
 Write a register value. More...
 
void ksz8851_reg_setbits (uint16_t reg, uint16_t bits_to_set)
 Read register content, set bitmask and write back to register. More...
 
void ksz8851_reg_clrbits (uint16_t reg, uint16_t bits_to_clr)
 Read register content, clear bitmask and write back to register. More...
 

PHY FIFO read/write functions

void ksz8851_fifo_read (uint8_t *buf, uint32_t len)
 Read internal fifo buffer. More...
 
void ksz8851_fifo_write_begin (uint32_t tot_len)
 Start to write internal fifo buffer. More...
 
void ksz8851_fifo_write (uint8_t *buf, uint32_t len)
 Write internal fifo buffer. More...
 
void ksz8851_fifo_write_end (uint32_t pad)
 Complete write operation. More...
 

Initialization and configuration

uint32_t ksz8851snl_init (void)
 Initialize the PHY controller. More...
 
void configure_intn (void(*p_handler)(void))
 Configure the INTN interrupt. More...
 

void ksz8851_fifo_read ( uint8_t *  buf,
uint32_t  len 
)

Read internal fifo buffer.

Parameters
bufthe buffer to store the data from the fifo buffer.
lenthe amount of data to read.

References FIFO_READ, ksz8851snl_master, ksz8851snl_slave, spi_read_buffer_wait(), spi_select_slave(), and spi_transceive_buffer_wait().

Referenced by ksz8851snl_read(), and ksz8851snl_update().

void ksz8851_fifo_write ( uint8_t *  buf,
uint32_t  len 
)

Write internal fifo buffer.

Parameters
bufthe buffer to send to the fifo buffer.
lenthe size of the pbuf element to write.

References ksz8851snl_master, and spi_write_buffer_wait().

Referenced by ksz8851snl_send(), and ksz8851snl_update().

void ksz8851_fifo_write_begin ( uint32_t  tot_len)

Start to write internal fifo buffer.

Parameters
tot_lenthe total amount of data to write.

References FIFO_WRITE, ksz8851snl_master, ksz8851snl_slave, spi_select_slave(), and spi_write_buffer_wait().

Referenced by ksz8851snl_send(), and ksz8851snl_update().

void ksz8851_fifo_write_end ( uint32_t  pad)

Complete write operation.

Parameters
padamount of dummy data (bytes) to write to keep 32 bits alignment in the internal FIFO.

References ksz8851snl_master, ksz8851snl_slave, spi_select_slave(), and spi_write_buffer_wait().

Referenced by ksz8851snl_send(), and ksz8851snl_update().

void ksz8851_reg_clrbits ( uint16_t  reg,
uint16_t  bits_to_clr 
)

Read register content, clear bitmask and write back to register.

Parameters
regthe register address to modify.
bits_to_setbitmask to apply.

References ksz8851_reg_read(), and ksz8851_reg_write().

Referenced by ksz8851snl_init(), ksz8851snl_read(), ksz8851snl_send(), and ksz8851snl_update().

uint16_t ksz8851_reg_read ( uint16_t  reg)

Read a register value.

Parameters
regthe register address to modify.
Returns
the register value.

References CMD_READ, ksz8851snl_master, ksz8851snl_slave, REG_ADDR_MASK, spi_select_slave(), and spi_transceive_buffer_wait().

Referenced by ksz8851_reg_clrbits(), ksz8851_reg_setbits(), ksz8851snl_init(), ksz8851snl_read(), ksz8851snl_send(), and ksz8851snl_update().

void ksz8851_reg_setbits ( uint16_t  reg,
uint16_t  bits_to_set 
)

Read register content, set bitmask and write back to register.

Parameters
regthe register address to modify.
bits_to_setbitmask to apply.

References ksz8851_reg_read(), and ksz8851_reg_write().

Referenced by ksz8851snl_init(), ksz8851snl_read(), ksz8851snl_send(), and ksz8851snl_update().

void ksz8851_reg_write ( uint16_t  reg,
uint16_t  wrdata 
)

Write a register value.

Parameters
regthe register address to modify.
wrdatathe new register value.

References CMD_WRITE, ksz8851snl_master, ksz8851snl_slave, REG_ADDR_MASK, spi_select_slave(), and spi_transceive_buffer_wait().

Referenced by init(), ksz8851_reg_clrbits(), ksz8851_reg_setbits(), ksz8851snl_init(), ksz8851snl_read(), ksz8851snl_send(), and ksz8851snl_update().