Robobo
spi.h File Reference
#include "../chip.h"

Go to the source code of this file.

Macros

#define SPI_PCS(npcs)   ((~(1 << (npcs)) & 0xF) << 16)
 
#define SPI_SCBR(baudrate, masterClock)   ((uint32_t) ((masterClock) / (baudrate)) << 8)
 
#define SPI_DLYBS(delay, masterClock)   ((uint32_t) ((((masterClock) / 1000000) * (delay)) / 1000) << 16)
 
#define SPI_DLYBCT(delay, masterClock)   ((uint32_t) ((((masterClock) / 1000000) * (delay)) / 32000) << 24)
 

Functions

void SPI_Enable (Spi *spi)
 Enables a SPI peripheral. More...
 
void SPI_Disable (Spi *spi)
 Disables a SPI peripheral. More...
 
void SPI_EnableIt (Spi *spi, uint32_t dwSources)
 Enables one or more interrupt sources of a SPI peripheral. More...
 
void SPI_DisableIt (Spi *spi, uint32_t dwSources)
 Disables one or more interrupt sources of a SPI peripheral. More...
 
void SPI_Configure (Spi *spi, uint32_t dwId, uint32_t dwConfiguration)
 Configures a SPI peripheral as specified. The configuration can be computed using several macros (see SPI Configuration Macros). More...
 
void SPI_ConfigureNPCS (Spi *spi, uint32_t dwNpcs, uint32_t dwConfiguration)
 Configures a chip select of a SPI peripheral. The chip select configuration is computed using several macros (see SPI Configuration Macros). More...
 
uint32_t SPI_Read (Spi *spi)
 Reads and returns the last word of data received by a SPI peripheral. This method must be called after a successful SPI_Write call. More...
 
void SPI_Write (Spi *spi, uint32_t dwNpcs, uint16_t wData)
 Sends data through a SPI peripheral. If the SPI is configured to use a fixed peripheral select, the npcs value is meaningless. Otherwise, it identifies the component which shall be addressed. More...
 
uint32_t SPI_GetStatus (Spi *spi)
 Get the current status register of the given SPI peripheral. More...
 
uint32_t SPI_IsFinished (Spi *pSpi)
 Check if SPI transfer finish. More...
 

Detailed Description

Interface for Serial Peripheral Interface (SPI) controller.

Macro Definition Documentation

#define SPI_DLYBCT (   delay,
  masterClock 
)    ((uint32_t) ((((masterClock) / 1000000) * (delay)) / 32000) << 24)

Calculates the value of the CSR DLYBCT field given the desired delay (in ns)

#define SPI_DLYBS (   delay,
  masterClock 
)    ((uint32_t) ((((masterClock) / 1000000) * (delay)) / 1000) << 16)

Calculates the value of the CSR DLYBS field given the desired delay (in ns)

#define SPI_PCS (   npcs)    ((~(1 << (npcs)) & 0xF) << 16)

Here are several macros which should be used when configuring a SPI peripheral.

SPI Configuration Macros

#define SPI_SCBR (   baudrate,
  masterClock 
)    ((uint32_t) ((masterClock) / (baudrate)) << 8)

Calculates the value of the CSR SCBR field given the baudrate and MCK.

Function Documentation

void SPI_Configure ( Spi spi,
uint32_t  dwId,
uint32_t  dwConfiguration 
)

Configures a SPI peripheral as specified. The configuration can be computed using several macros (see SPI Configuration Macros).

Parameters
spiPointer to an Spi instance.
idPeripheral ID of the SPI.
configurationValue of the SPI configuration register.
void SPI_ConfigureNPCS ( Spi spi,
uint32_t  dwNpcs,
uint32_t  dwConfiguration 
)

Configures a chip select of a SPI peripheral. The chip select configuration is computed using several macros (see SPI Configuration Macros).

Parameters
spiPointer to an Spi instance.
npcsChip select to configure (0, 1, 2 or 3).
configurationDesired chip select configuration.
void SPI_Disable ( Spi spi)

Disables a SPI peripheral.

Parameters
spiPointer to an Spi instance.
void SPI_DisableIt ( Spi spi,
uint32_t  dwSources 
)

Disables one or more interrupt sources of a SPI peripheral.

Parameters
spiPointer to an Spi instance.
sourcesBitwise OR of selected interrupt sources.
void SPI_Enable ( Spi spi)

Enables a SPI peripheral.

Parameters
spiPointer to an Spi instance.
void SPI_EnableIt ( Spi spi,
uint32_t  dwSources 
)

Enables one or more interrupt sources of a SPI peripheral.

Parameters
spiPointer to an Spi instance.
sourcesBitwise OR of selected interrupt sources.
uint32_t SPI_GetStatus ( Spi spi)

Get the current status register of the given SPI peripheral.

Note
This resets the internal value of the status register, so further read may yield different values.
Parameters
spiPointer to a Spi instance.
Returns
SPI status register.
uint32_t SPI_IsFinished ( Spi spi)

Check if SPI transfer finish.

Parameters
spiPointer to an Spi instance.
Returns
Returns 1 if there is no pending write operation on the SPI; otherwise returns 0.
uint32_t SPI_Read ( Spi spi)

Reads and returns the last word of data received by a SPI peripheral. This method must be called after a successful SPI_Write call.

Parameters
spiPointer to an Spi instance.
Returns
readed data.
void SPI_Write ( Spi spi,
uint32_t  dwNpcs,
uint16_t  wData 
)

Sends data through a SPI peripheral. If the SPI is configured to use a fixed peripheral select, the npcs value is meaningless. Otherwise, it identifies the component which shall be addressed.

Parameters
spiPointer to an Spi instance.
npcsChip select of the component to address (0, 1, 2 or 3).
dataWord of data to send.