NetBurner 3.1
SPIModule Class Reference

SPI Peripheral Module Class. More...

#include <dspi.h>

Public Member Functions

 SPIModule (uint8_t SPIModule)
 Create a SPI object. More...
 
 SPIModule (uint8_t SPIModule, uint32_t baudRateInBps, uint8_t transferSizeInBits=8, uint8_t peripheralChipSelects=0x00, uint8_t chipSelectPolarity=0x0F, uint8_t clockPolarity=0, uint8_t clockPhase=1, BOOL doutHiz=TRUE, uint8_t csToClockDelay=0, uint8_t delayAfterTransfer=0)
 Create a SPI object and Initialize with parameters. More...
 
uint8_t Init (uint32_t baudRateInBps=2000000, uint8_t transferSizeInBits=8, uint8_t peripheralChipSelects=0x00, uint8_t chipSelectPolarity=0x0F, uint8_t clockPolarity=0, uint8_t clockPhase=1, BOOL doutHiz=TRUE, uint8_t csToClockDelay=0, uint8_t delayAfterTransfer=0)
 Initialize an existing SPI object. More...
 
uint32_t SetBusSpeed (uint32_t maxSpeed)
 Set the SPI bus speed Will attempt to set the desired bus speed. It may be different based on the available system characteristics. More...
 
uint8_t Start (uint8_t *transmitBufferPtr, volatile uint8_t *receiveBufferPtr, uint32_t byteCount, int csReturnToInactive=DEASSERT_AFTER_LAST)
 Start a SPI transfer. More...
 
uint8_t Tx (uint8_t *transmitBufferPtr, uint32_t byteCount, int csReturnToInactive=DEASSERT_AFTER_LAST)
 Convenience function for unidirectional transmit. More...
 
uint8_t Rx (uint8_t *receiveBufferPtr, uint32_t byteCount, int csReturnToInactive=DEASSERT_AFTER_LAST)
 Convenience function for unidirectional receive. More...
 
bool RegisterSem (OS_SEM *finishedSem)
 Register a semaphore for the SPI module. More...
 
bool ClrSem ()
 Clear a semaphore registration. More...
 
OS_SEMGetSem ()
 Obtain a pointer to the SPI finished semaphore. More...
 
bool Done ()
 Function to check SPI status. More...
 
uint32_t GetActualBaudrate ()
 Returns the active baud rate. More...
 
bool SetCS (uint8_t CS)
 Set the chip select configuration for the SPI object's bus transactions. More...
 

Static Public Member Functions

static BOOL Done (uint8_t SPIModule)
 Static function to check SPI status. More...
 

Detailed Description

SPI Peripheral Module Class.

Class definition for SPI module objects

Constructor & Destructor Documentation

◆ SPIModule() [1/2]

SPIModule::SPIModule ( uint8_t  SPIModule)

Create a SPI object.

This constructor will create the object, but will not initialize the SPI module. You must call the Init() member function to initialize.

Parameters
SPIModuleSPI module number (0 or 1)

◆ SPIModule() [2/2]

SPIModule::SPIModule ( uint8_t  SPIModule,
uint32_t  baudRateInBps,
uint8_t  transferSizeInBits = 8,
uint8_t  peripheralChipSelects = 0x00,
uint8_t  chipSelectPolarity = 0x0F,
uint8_t  clockPolarity = 0,
uint8_t  clockPhase = 1,
BOOL  doutHiz = TRUE,
uint8_t  csToClockDelay = 0,
uint8_t  delayAfterTransfer = 0 
)

Create a SPI object and Initialize with parameters.

Creaets a SPI object and initializes the SPI module. You do not need to call the Init() member function.

Parameters
SPIModuleSPI module number (0 or 1)
baudRateInBpsMaximum baud rate requested
transferSizeInBitsNumber of bits per transfer: 8, 16 or 32
peripheralChipSelectsSPI chip selects to use for transfer
chipSelectPolarity0 = inactive logic level low, 1 = high
clockPolarity0 = inactive logic level low, 1 = high
clockPhase0 = data captured leading edge clock, changed following edge. 1 = data changed leading edge clock, captured following edge.
doutHizData output high impedance between transfers
csToClockDelayDelay from chip select to valid clock (default is 0)
delayAfterTransferChip select mode DspiChipSelectMode

Member Function Documentation

◆ ClrSem()

bool SPIModule::ClrSem ( )
inline

Clear a semaphore registration.

Returns
true if the the clear was successful, false if a SPI transaction is in progress

◆ Done() [1/2]

bool SPIModule::Done ( )
inline

Function to check SPI status.

Called as a class method on a specific SPI object. For example: MySpi.Done()

Returns
true if SPI is finished, false if active

◆ Done() [2/2]

static BOOL SPIModule::Done ( uint8_t  SPIModule)
static

Static function to check SPI status.

Is called as a class wide static method. For example: SPIModule::Done(0)

Parameters
SPIModuleThe SPI module to check, 0, 1 or 2
Returns
true if SPI is finished, false if active

◆ GetActualBaudrate()

uint32_t SPIModule::GetActualBaudrate ( )
inline

Returns the active baud rate.

The baud rate will be set to the value specified when the SPI module is initialized. If that value is not possible, the next lowest baud rate will be chosen.

Returns
The actual SPI module baud rate

◆ GetSem()

OS_SEM* SPIModule::GetSem ( )
inline

Obtain a pointer to the SPI finished semaphore.

Returns
A pointer to the semaphore

◆ Init()

uint8_t SPIModule::Init ( uint32_t  baudRateInBps = 2000000,
uint8_t  transferSizeInBits = 8,
uint8_t  peripheralChipSelects = 0x00,
uint8_t  chipSelectPolarity = 0x0F,
uint8_t  clockPolarity = 0,
uint8_t  clockPhase = 1,
BOOL  doutHiz = TRUE,
uint8_t  csToClockDelay = 0,
uint8_t  delayAfterTransfer = 0 
)

Initialize an existing SPI object.

Parameters
SPIModuleSPI module number (0 or 1)
baudRateInBpsMaximum baud rate requested
transferSizeInBitsNumber of bits per transfer: 8, 16 or 32
peripheralChipSelectsSPI chip selects to use for transfer
chipSelectPolarity0 = inactive logic level low, 1 = high
clockPolarity0 = inactive logic level low, 1 = high
clockPhase0 = data captured leading edge clock, changed following edge. 1 = data changed leading edge clock, captured following edge.
doutHizData output high impedance between transfers
csToClockDelayDelay from chip select to valid clock (default is 0)
delayAfterTransferChip select mode DspiChipSelectMode
Returns
The current state of the SPI bus DspiState

◆ RegisterSem()

bool SPIModule::RegisterSem ( OS_SEM finishedSem)

Register a semaphore for the SPI module.

The SPI module will post to this semaphore when a transaction is complete

Parameters
finishedSemPointer to the semaphore
Returns
true if the registration was successful, false if a SPI transaction is in progress

◆ Rx()

uint8_t SPIModule::Rx ( uint8_t *  receiveBufferPtr,
uint32_t  byteCount,
int  csReturnToInactive = DEASSERT_AFTER_LAST 
)
inline

Convenience function for unidirectional receive.

Parameters
transmitBufferPtrPointer to the buffer containing the data to transmit
byteCountNumber of bytes to transmit
csReturnToInactiveChip select state
Returns
The current state of the SPI bus DspiState

◆ SetBusSpeed()

uint32_t SPIModule::SetBusSpeed ( uint32_t  maxSpeed)

Set the SPI bus speed Will attempt to set the desired bus speed. It may be different based on the available system characteristics.

Parameters
maxSpeedThe maximum desired bus speed
Returns
The actual bus speed

◆ SetCS()

bool SPIModule::SetCS ( uint8_t  CS)
inline

Set the chip select configuration for the SPI object's bus transactions.

Parameters
Chipselect to set, 0 - 3.
Returns
true if successful, false if SPI is currently active

◆ Start()

uint8_t SPIModule::Start ( uint8_t *  transmitBufferPtr,
volatile uint8_t *  receiveBufferPtr,
uint32_t  byteCount,
int  csReturnToInactive = DEASSERT_AFTER_LAST 
)

Start a SPI transfer.

  • If configured for 8 bits per transfer then the data must be uint8_t aligned
  • If configured for > than 8 bits per transfer then the data must be uint16_t aligned
  • If configured for > than 16 bits per transfer then the data must be uint32_t aligned
  • If either RX or TX pointer is assigned 'null' then that communication direction will not occur.
  • If DSPI_Finished points to a semaphore, then the DSPI will POST to it when the transfer is complete.
  • The semaphore is optional, but it can increase efficiency.
Parameters
transmitBufferPtrPointer to the buffer containing the data to transmit
receiveBufferPtrPointer to the buffer to store the received data
byteCountNumber of bytes to transmit
csReturnToInactiveChip select state
Returns
The current state of the SPI bus DspiState

◆ Tx()

uint8_t SPIModule::Tx ( uint8_t *  transmitBufferPtr,
uint32_t  byteCount,
int  csReturnToInactive = DEASSERT_AFTER_LAST 
)
inline

Convenience function for unidirectional transmit.

Parameters
transmitBufferPtrPointer to the buffer containing the data to transmit
byteCountNumber of bytes to transmit
csReturnToInactiveChip select state
Returns
The current state of the SPI bus DspiState

The documentation for this class was generated from the following file: