Declarations of spi_driver functions.
This is the Adesto SPI driver. It supports standard SPI, dual SPI, and Quad SPI. Functionality is built in for a trigger GPIO as well as a JEDEC reset.
Initialization of the driver takes place with the SPI_ConfigureSingleSPIIOs() function which should be called after the pins have been set as GPIOs but before adesto layer commands are run.
Definition in file spi_driver.h.
#include "user_config.h"
Go to the source code of this file.
Macros | |
#define | SPI_CSB_PORT USER_CONFIG_CSB_PORT |
Base register used for CSb control. More... | |
#define | SPI_TRIGGER_PORT USER_CONFIG_TRIGGER_PORT |
Base register used for TRIGGER control. More... | |
#define | SPI_SCK_PORT USER_CONFIG_SCK_PORT |
Base register used for SCK control. More... | |
#define | SPI_MOSI_PORT USER_CONFIG_MOSI_PORT |
Base register used for MOSI control. More... | |
#define | SPI_MISO_PORT USER_CONFIG_MISO_PORT |
Base register used for MISO control. More... | |
#define | SPI_WPB_PORT USER_CONFIG_IO2_PORT |
Base register used for WPb control. More... | |
#define | SPI_HOLDB_PORT USER_CONFIG_IO3_PORT |
Base register used for HOLDb control. More... | |
#define | SPI_CSB_PIN USER_CONFIG_CSB_PIN |
#define | SPI_TRIGGER_PIN USER_CONFIG_TRIGGER_PIN |
Pin number for TRIGGER. More... | |
#define | SPI_SCK_PIN USER_CONFIG_SCK_PIN |
Pin number for SCK. More... | |
#define | SPI_MOSI_PIN USER_CONFIG_MOSI_PIN |
Pin number for MOSI. More... | |
#define | SPI_MISO_PIN USER_CONFIG_MISO_PIN |
Pin number for MISO. More... | |
#define | SPI_WPB_PIN USER_CONFIG_IO2_PIN |
Pin number for WPb - IO2. More... | |
#define | SPI_HOLDB_PIN USER_CONFIG_IO3_PIN |
Pin number for HOLDb - IO3. More... | |
#define | DELAY 5U |
Half clock period delay interval. More... | |
#define | SPI 0 |
#define | QPI 1 |
Functions | |
void | SPI_PinInit (uint32_t port, uint32_t pin, enum directionIO direction) |
Initializes a given pin as either an input or output. More... | |
void | SPI_PinClear (uint32_t port, uint32_t pin) |
Clears a given pin on a port to LOW. More... | |
void | SPI_PinSet (uint32_t port, uint32_t pin) |
Sets a given pin on a port to HIGH. More... | |
uint32_t | SPI_PinRead (uint32_t port, uint32_t pin) |
Reads the voltage on a given pin. More... | |
void | SPI_Exchange (uint8_t *txBuffer, uint32_t txNumBytes, uint8_t *rxBuffer, uint32_t rxNumBytes, uint32_t dummyNumBytes) |
Sends and receives bytes based on the function parameters. MISO and MOSI fill their standard SPI roles. More... | |
void | SPI_DualExchange (uint8_t standardSPINumBytes, uint8_t *txBuffer, uint32_t txNumBytes, uint8_t *rxBuffer, uint32_t rxNumBytes, uint32_t dummyNumBytes) |
Sends and receives bytes based on the function parameters. MOSI is used for the opcode and address, then MISO or MOSI are switched for transmission and receiving such that data is transmitted from/to the flash device along both lines. Their state will then be reverted to original SPI functionality. More... | |
void | SPI_QuadExchange (uint8_t standardSPINumBytes, uint8_t *txBuffer, uint32_t txNumBytes, uint8_t *rxBuffer, uint32_t rxNumBytes, uint32_t dummyNumBytes) |
Sends and receives bytes based on the function parameters. MOSI can used for the opcode and address, then MISO, MOSI, HOLDb, WPb are switched for transmission and receiving such that data is transmitted from/to the flash device along all 4 lines. Their state will then be reverted to original SPI functionality. More... | |
uint8_t | SPI_ReceiveByte () |
Receives a byte along MISO and returns the value received. More... | |
uint8_t | SPI_DualReceiveByte () |
Receives a byte along both MOSI and MISO and returns the value received. More... | |
void | SPI_SendByte (uint8_t transmittedByte) |
Sends a byte along MOSI. More... | |
void | SPI_DualSendByte (uint8_t transmittedByte) |
Sends a byte along both MOSI and MISO. More... | |
void | SPI_ClockTick () |
Toggles the clock: current_state->high->low. More... | |
void | SPI_SendBit (uint8_t transmittedBit) |
Sends a single bit along MOSI while toggling the clock. More... | |
void | SPI_Delay (uint32_t delayTime) |
Performs a delayTime number of NOPs. More... | |
void | SPI_ConfigureSingleSPIIOs () |
Configure the IOs for SPI bit banging usage. 4 pins are needed: CSb, SCK, MOSI, MISO. More... | |
void | SPI_ReturnToSingleSPIIOs () |
Returns MISO and MOSI pins to their standard SPI state as an input and output. More... | |
void | SPI_ConfigureDualSPIIOsInput () |
Configures SPIO IOs for dual input. This changes the MOSI pin from an output to an input so that the slave can drive both SI and SO. More... | |
void | SPI_ConfigureDualSPIIOsOutput () |
Configures SPIO IOs for dual output. This changes the MISO pin from an input to an output so that the master can drive both SI and SO. More... | |
void | SPI_ConfigureQuadSPIIOsInput () |
Configures SPIO IOs for quad input. This changes the MOSI, WPb, and HOLDb pins to inputs so that the slave can drive all 4 IOs. More... | |
void | SPI_ConfigureQuadSPIIOsOutput () |
Configures SPIO IOs for quad output. This changes the MISO pin to an output so that the master can drive all 4 IOs. More... | |
void | SPI_QuadSendByte (uint8_t transmittedByte) |
Sends a byte along MISO, MOSI, WPb, and HOLDb. More... | |
uint8_t | SPI_QuadReceiveByte () |
Receives a byte along MOSI, MISO, HOLDb, and WPb and returns the value received. More... | |
void | SPI_Trigger () |
Triggers a falling edge on the SPI_TRIGGER_PORT/PIN output. More... | |
void | SPI_JEDECReset () |
Performs a JEDEC reset on the SPI device. More... | |
#define DELAY 5U |
Half clock period delay interval.
Definition at line 108 of file spi_driver.h.
#define QPI 1 |
Definition at line 111 of file spi_driver.h.
#define SPI 0 |
Definition at line 110 of file spi_driver.h.
#define SPI_CSB_PIN USER_CONFIG_CSB_PIN |
Pin number for CSb
Definition at line 94 of file spi_driver.h.
#define SPI_CSB_PORT USER_CONFIG_CSB_PORT |
Base register used for CSb control.
Definition at line 61 of file spi_driver.h.
#define SPI_HOLDB_PIN USER_CONFIG_IO3_PIN |
Pin number for HOLDb - IO3.
Definition at line 106 of file spi_driver.h.
#define SPI_HOLDB_PORT USER_CONFIG_IO3_PORT |
Base register used for HOLDb control.
Definition at line 85 of file spi_driver.h.
#define SPI_MISO_PIN USER_CONFIG_MISO_PIN |
Pin number for MISO.
Definition at line 102 of file spi_driver.h.
#define SPI_MISO_PORT USER_CONFIG_MISO_PORT |
Base register used for MISO control.
Definition at line 77 of file spi_driver.h.
#define SPI_MOSI_PIN USER_CONFIG_MOSI_PIN |
Pin number for MOSI.
Definition at line 100 of file spi_driver.h.
#define SPI_MOSI_PORT USER_CONFIG_MOSI_PORT |
Base register used for MOSI control.
Definition at line 73 of file spi_driver.h.
#define SPI_SCK_PIN USER_CONFIG_SCK_PIN |
Pin number for SCK.
Definition at line 98 of file spi_driver.h.
#define SPI_SCK_PORT USER_CONFIG_SCK_PORT |
Base register used for SCK control.
Definition at line 69 of file spi_driver.h.
#define SPI_TRIGGER_PIN USER_CONFIG_TRIGGER_PIN |
Pin number for TRIGGER.
Definition at line 96 of file spi_driver.h.
#define SPI_TRIGGER_PORT USER_CONFIG_TRIGGER_PORT |
Base register used for TRIGGER control.
Definition at line 65 of file spi_driver.h.
#define SPI_WPB_PIN USER_CONFIG_IO2_PIN |
Pin number for WPb - IO2.
Definition at line 104 of file spi_driver.h.
#define SPI_WPB_PORT USER_CONFIG_IO2_PORT |
Base register used for WPb control.
Definition at line 81 of file spi_driver.h.
void SPI_ClockTick | ( | ) |
Toggles the clock: current_state->high->low.
void |
Definition at line 149 of file spi_driver.c.
void SPI_ConfigureDualSPIIOsInput | ( | ) |
Configures SPIO IOs for dual input. This changes the MOSI pin from an output to an input so that the slave can drive both SI and SO.
void |
Definition at line 101 of file spi_driver.c.
void SPI_ConfigureDualSPIIOsOutput | ( | ) |
Configures SPIO IOs for dual output. This changes the MISO pin from an input to an output so that the master can drive both SI and SO.
void |
Definition at line 121 of file spi_driver.c.
void SPI_ConfigureQuadSPIIOsInput | ( | ) |
Configures SPIO IOs for quad input. This changes the MOSI, WPb, and HOLDb pins to inputs so that the slave can drive all 4 IOs.
void |
Definition at line 108 of file spi_driver.c.
void SPI_ConfigureQuadSPIIOsOutput | ( | ) |
Configures SPIO IOs for quad output. This changes the MISO pin to an output so that the master can drive all 4 IOs.
void |
Definition at line 128 of file spi_driver.c.
void SPI_ConfigureSingleSPIIOs | ( | ) |
Configure the IOs for SPI bit banging usage. 4 pins are needed: CSb, SCK, MOSI, MISO.
void |
Definition at line 61 of file spi_driver.c.
void SPI_Delay | ( | uint32_t | delayTime | ) |
Performs a delayTime number of NOPs.
delayTime | The number of NOPs to be run. |
void |
Definition at line 140 of file spi_driver.c.
void SPI_DualExchange | ( | uint8_t | standardSPINumBytes, |
uint8_t * | txBuffer, | ||
uint32_t | txNumBytes, | ||
uint8_t * | rxBuffer, | ||
uint32_t | rxNumBytes, | ||
uint32_t | dummyNumBytes | ||
) |
Sends and receives bytes based on the function parameters. MOSI is used for the opcode and address, then MISO or MOSI are switched for transmission and receiving such that data is transmitted from/to the flash device along both lines. Their state will then be reverted to original SPI functionality.
standardSPINumBytes | The number of bytes to be sent in standard single SPI mode. Note: Dummy bytes will be sent in standard single SPI mode. |
*txBuffer | A pointer to the tx byte array to be transmitted. Should have tx_bytes elements. |
txNumBytes | The total number of bytes to be transmitted including those in standard SPI. |
*rxBuffer | A pointer to the rx byte array where received data will be stored. Should have rx_bytes elements. |
rxNumBytes | The number of bytes to be received. |
dummyNumBytes | The number of dummy bytes to be sent. |
void |
Definition at line 355 of file spi_driver.c.
uint8_t SPI_DualReceiveByte | ( | ) |
Receives a byte along both MOSI and MISO and returns the value received.
uint8_t | The byte received in Little Endian format. |
Definition at line 268 of file spi_driver.c.
void SPI_DualSendByte | ( | uint8_t | transmittedByte | ) |
Sends a byte along both MOSI and MISO.
transmittedByte | Byte to be sent. |
void |
Definition at line 180 of file spi_driver.c.
void SPI_Exchange | ( | uint8_t * | txBuffer, |
uint32_t | txNumBytes, | ||
uint8_t * | rxBuffer, | ||
uint32_t | rxNumBytes, | ||
uint32_t | dummyNumBytes | ||
) |
Sends and receives bytes based on the function parameters. MISO and MOSI fill their standard SPI roles.
*txBuffer | A pointer to the tx byte array to be transmitted. Should have tx_bytes elements. |
txNumBytes | The number of bytes to be transmitted. |
*rxBuffer | A pointer to the rx byte array where received data will be stored. Should have rx_bytes elements. |
rxNumBytes | The number of bytes to be received. |
dummyNumBytes | The number of dummy bytes to be sent. |
void |
Definition at line 325 of file spi_driver.c.
void SPI_JEDECReset | ( | ) |
Performs a JEDEC reset on the SPI device.
void |
Definition at line 492 of file spi_driver.c.
void SPI_PinClear | ( | uint32_t | port, |
uint32_t | pin | ||
) |
Clears a given pin on a port to LOW.
port | The port number. |
pin | The pin number. |
void |
Definition at line 47 of file spi_driver.c.
void SPI_PinInit | ( | uint32_t | port, |
uint32_t | pin, | ||
enum directionIO | direction | ||
) |
Initializes a given pin as either an input or output.
port | The port number. The type must be redefined based on the GPIO driver being used. |
pin | The pin number. |
direction | INPUT or OUTPUT. See the directionIO enum type. |
void |
Definition at line 43 of file spi_driver.c.
uint32_t SPI_PinRead | ( | uint32_t | port, |
uint32_t | pin | ||
) |
Reads the voltage on a given pin.
port | The port number. |
pin | The pin number. |
32-bit | word, 0 = LOW, 1 = HIGH. |
Definition at line 56 of file spi_driver.c.
void SPI_PinSet | ( | uint32_t | port, |
uint32_t | pin | ||
) |
Sets a given pin on a port to HIGH.
port | The port number. |
pin | The pin number. |
void |
Definition at line 51 of file spi_driver.c.
void SPI_QuadExchange | ( | uint8_t | standardSPINumBytes, |
uint8_t * | txBuffer, | ||
uint32_t | txNumBytes, | ||
uint8_t * | rxBuffer, | ||
uint32_t | rxNumBytes, | ||
uint32_t | dummyNumBytes | ||
) |
Sends and receives bytes based on the function parameters. MOSI can used for the opcode and address, then MISO, MOSI, HOLDb, WPb are switched for transmission and receiving such that data is transmitted from/to the flash device along all 4 lines. Their state will then be reverted to original SPI functionality.
standardSPINumBytes | The number of bytes to be sent in standard single SPI mode. Note: Dummy bytes will be sent in standard single SPI mode based on the input parameters. |
*txBuffer | A pointer to the tx byte array to be transmitted. Should have tx_bytes elements. |
txNumBytes | The total number of bytes to be transmitted including those in standard SPI. |
*rxBuffer | A pointer to the rx byte array where received data will be stored. Should have rx_bytes elements. |
rxNumBytes | The number of bytes to be received. |
dummyNumBytes | The number of dummy bytes to be sent. |
void |
Definition at line 406 of file spi_driver.c.
uint8_t SPI_QuadReceiveByte | ( | ) |
Receives a byte along MOSI, MISO, HOLDb, and WPb and returns the value received.
uint8_t | The byte received in Little Endian format. |
Definition at line 292 of file spi_driver.c.
void SPI_QuadSendByte | ( | uint8_t | transmittedByte | ) |
Sends a byte along MISO, MOSI, WPb, and HOLDb.
transmittedByte | Byte to be sent. |
void |
Definition at line 211 of file spi_driver.c.
uint8_t SPI_ReceiveByte | ( | ) |
Receives a byte along MISO and returns the value received.
uint8_t | The byte received in Little Endian format. |
Definition at line 251 of file spi_driver.c.
void SPI_ReturnToSingleSPIIOs | ( | ) |
Returns MISO and MOSI pins to their standard SPI state as an input and output.
void |
Definition at line 85 of file spi_driver.c.
void SPI_SendBit | ( | uint8_t | transmittedBit | ) |
Sends a single bit along MOSI while toggling the clock.
transmittedBit | Bit to be sent, either 1 or 0. |
void |
Definition at line 157 of file spi_driver.c.
void SPI_SendByte | ( | uint8_t | transmittedByte | ) |
Sends a byte along MOSI.
transmittedByte | Byte to be sent. |
void |
Definition at line 170 of file spi_driver.c.
void SPI_Trigger | ( | ) |
Triggers a falling edge on the SPI_TRIGGER_PORT/PIN output.
void |
Definition at line 485 of file spi_driver.c.