ksz8851snl_spi.c File Reference

SPI interface API for KSZ8851SNL Ethernet controller.

License

Copyright 2018 Silicon Laboratories Inc. www.silabs.com

SPDX-License-Identifier: Zlib

The licensor of this software is Silicon Laboratories Inc.

This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.

Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:

  1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
  2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
  3. This notice may not be removed or altered from any source distribution.

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 45 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 46 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 39 of file ksz8851snl_spi.c .

Referenced by KSZ8851SNL_SPI_Init() .

#define BYTE_ENABLE   0x03

Enable 2 byte register read/write

Definition at line 47 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 48 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 52 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 53 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 43 of file ksz8851snl_spi.c .

Referenced by KSZ8851SNL_SPI_ReadFifo() .

#define OPCODE_FIFO_WRITE   0xC0

Opcode for writing to FIFO

Definition at line 44 of file ksz8851snl_spi.c .

Referenced by KSZ8851SNL_SPI_WriteFifoBegin() .

#define OPCODE_REG_READ   0x00

Opcode for reading a register

Definition at line 41 of file ksz8851snl_spi.c .

Referenced by KSZ8851SNL_SPI_ReadRegister() .

#define OPCODE_REG_WRITE   0x40

Opcode for writing a register

Definition at line 42 of file ksz8851snl_spi.c .

Referenced by KSZ8851SNL_SPI_WriteRegister() .

#define REG_MASK   0x03

Register mask

Definition at line 40 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 126 of file ksz8851snl_spi.c .

References 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 154 of file ksz8851snl_spi.c .

References ETH_CS_PIN , and ETH_CS_PORT .

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 97 of file ksz8851snl_spi.c .

References ECODE_EMDRV_SPIDRV_OK , SL_MIN , and SPIDRV_MTransmitB() .

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