ksz8851snl_spi.c File Reference

SPI interface API for KSZ8851SNL Ethernet controller.

License

Copyright 2018 Silicon Laboratories Inc. www.silabs.com

The licensor of this software is Silicon Laboratories Inc. Your use of this software is governed by the terms of Silicon Labs Master Software License Agreement (MSLA) available at www.silabs.com/about-us/legal/master-software-license-agreement. This software is distributed to you in Source Code format and is governed by the sections of the MSLA applicable to Source Code.

Definition in file ksz8851snl_spi.c .

#include <stdio.h>
#include <stdint.h>
#include " ksz8851snl_spi.h "
#include " em_assert.h "
#include " em_common.h "
#include " em_gpio.h "
#include " spidrv.h "

Macros

#define ADDRESS_MS2B_POS 0x06
#define ADDRESS_SHIFT 0x02
#define BOGUS_BYTE 0xFF
#define BYTE_ENABLE 0x03
#define BYTE_ENABLE_SHIFT 0x02
#define ETH_CS_PIN 3
#define ETH_CS_PORT gpioPortD
#define OPCODE_FIFO_READ 0x80
#define OPCODE_FIFO_WRITE 0xC0
#define OPCODE_REG_READ 0x00
#define OPCODE_REG_WRITE 0x40
#define REG_MASK 0x03

Functions

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.
static void KSZ8851SNL_SPI_Receive (int numBytes, uint8_t *buffer)
Receive a series of bytes over the spi link.
static void KSZ8851SNL_SPI_SetChipSelect (bool enable)
Select/deselect the ksz8851snl chip. This will clear/set the chip select GPIO pin connected to the ksz8851snl. The chip has active low chip select.
static void KSZ8851SNL_SPI_Transmit (int numBytes, const uint8_t *data)
Transmits a series of bytes over the spi link.
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.

Macro Definition Documentation

#define ADDRESS_MS2B_POS   0x06

Most significant 2 Bytes of the address position

Definition at line 32 of file ksz8851snl_spi.c .

Referenced by KSZ8851SNL_SPI_ReadRegister() , and KSZ8851SNL_SPI_WriteRegister() .

#define ADDRESS_SHIFT   0x02

Number of positions to shift the register address

Definition at line 33 of file ksz8851snl_spi.c .

Referenced by KSZ8851SNL_SPI_ReadRegister() , and KSZ8851SNL_SPI_WriteRegister() .

#define BOGUS_BYTE   0xFF

Bogus byte used for receiving via SPI

Definition at line 26 of file ksz8851snl_spi.c .

Referenced by KSZ8851SNL_SPI_Init() .

#define BYTE_ENABLE   0x03

Enable 2 byte register read/write

Definition at line 34 of file ksz8851snl_spi.c .

Referenced by KSZ8851SNL_SPI_ReadRegister() , and KSZ8851SNL_SPI_WriteRegister() .

#define BYTE_ENABLE_SHIFT   0x02

Number of positions to shitf the byte enable bits

Definition at line 35 of file ksz8851snl_spi.c .

Referenced by KSZ8851SNL_SPI_ReadRegister() , and KSZ8851SNL_SPI_WriteRegister() .

#define ETH_CS_PIN   3

SPI CHIP SELECT Pin

Definition at line 39 of file ksz8851snl_spi.c .

Referenced by KSZ8851SNL_SPI_Init() , and KSZ8851SNL_SPI_SetChipSelect() .

#define ETH_CS_PORT   gpioPortD

SPI CHIP SELECT Port

Definition at line 40 of file ksz8851snl_spi.c .

Referenced by KSZ8851SNL_SPI_Init() , and KSZ8851SNL_SPI_SetChipSelect() .

#define OPCODE_FIFO_READ   0x80

Opcode for reading from FIFO

Definition at line 30 of file ksz8851snl_spi.c .

Referenced by KSZ8851SNL_SPI_ReadFifo() .

#define OPCODE_FIFO_WRITE   0xC0

Opcode for writing to FIFO

Definition at line 31 of file ksz8851snl_spi.c .

Referenced by KSZ8851SNL_SPI_WriteFifoBegin() .

#define OPCODE_REG_READ   0x00

Opcode for reading a register

Definition at line 28 of file ksz8851snl_spi.c .

Referenced by KSZ8851SNL_SPI_ReadRegister() .

#define OPCODE_REG_WRITE   0x40

Opcode for writing a register

Definition at line 29 of file ksz8851snl_spi.c .

Referenced by KSZ8851SNL_SPI_WriteRegister() .

#define REG_MASK   0x03

Register mask

Definition at line 27 of file ksz8851snl_spi.c .

Referenced by KSZ8851SNL_SPI_ReadRegister() , and KSZ8851SNL_SPI_WriteRegister() .

Function Documentation

static void KSZ8851SNL_SPI_Receive ( int numBytes,
uint8_t * buffer
)
static

Receive a series of bytes over the spi link.

Parameters
[in] numBytes the number of data bytes to be received
[in] buffer the destination buffer

Definition at line 113 of file ksz8851snl_spi.c .

References DMADRV_MAX_XFER_COUNT , ECODE_EMDRV_SPIDRV_OK , SL_MIN , and SPIDRV_MReceiveB() .

Referenced by KSZ8851SNL_SPI_ReadFifo() .

static void KSZ8851SNL_SPI_SetChipSelect ( bool enable )
static

Select/deselect the ksz8851snl chip. This will clear/set the chip select GPIO pin connected to the ksz8851snl. The chip has active low chip select.

Parameters
[in] enable true will select the ksz8851snl chip false will deselect the ksz8851snl chip.

Definition at line 141 of file ksz8851snl_spi.c .

References ETH_CS_PIN , ETH_CS_PORT , GPIO_PinOutClear() , and GPIO_PinOutSet() .

Referenced by KSZ8851SNL_SPI_ReadFifo() , KSZ8851SNL_SPI_ReadRegister() , KSZ8851SNL_SPI_WriteFifoBegin() , KSZ8851SNL_SPI_WriteFifoEnd() , and KSZ8851SNL_SPI_WriteRegister() .

static void KSZ8851SNL_SPI_Transmit ( int numBytes,
const uint8_t * data
)
static

Transmits a series of bytes over the spi link.

Parameters
[in] numBytes the number of data bytes to be transmitted
[in] data actual data to be transmitted

Definition at line 84 of file ksz8851snl_spi.c .

References DMADRV_MAX_XFER_COUNT , ECODE_EMDRV_SPIDRV_OK , SL_MIN , and SPIDRV_MTransmitB() .

Referenced by KSZ8851SNL_SPI_ReadFifo() , KSZ8851SNL_SPI_WriteFifo() , KSZ8851SNL_SPI_WriteFifoBegin() , and KSZ8851SNL_SPI_WriteRegister() .