Now you can download a copy of these docs so you can use them offline! Download now

#include <SPI.h>

Inheritance diagram for SPI:
Collaboration diagram for SPI:

Public Types

enum  tFrameMode { kChipSelect, kPreLatchPulse, kPostLatchPulse, kPreAndPostLatchPulse }
 
enum  tSPIConstants { kReceiveFIFODepth =512, kTransmitFIFODepth =512 }
 

Public Member Functions

 SPI (DigitalOutput &clk, DigitalOutput &mosi, DigitalInput &miso)
 
 SPI (DigitalOutput *clk, DigitalOutput *mosi, DigitalInput *miso)
 
 SPI (DigitalOutput &clk, DigitalOutput &mosi)
 
 SPI (DigitalOutput *clk, DigitalOutput *mosi)
 
 SPI (DigitalOutput &clk, DigitalInput &miso)
 
 SPI (DigitalOutput *clk, DigitalInput *miso)
 
virtual ~SPI ()
 
void SetBitsPerWord (uint32_t bits)
 
uint32_t GetBitsPerWord ()
 
void SetClockRate (double hz)
 
void SetMSBFirst ()
 
void SetLSBFirst ()
 
void SetSampleDataOnFalling ()
 
void SetSampleDataOnRising ()
 
void SetSlaveSelect (DigitalOutput *ss, tFrameMode mode=kChipSelect, bool activeLow=false)
 
void SetSlaveSelect (DigitalOutput &ss, tFrameMode mode=kChipSelect, bool activeLow=false)
 
DigitalOutputGetSlaveSelect (tFrameMode *mode=NULL, bool *activeLow=NULL)
 
void SetClockActiveLow ()
 
void SetClockActiveHigh ()
 
virtual void ApplyConfig ()
 
virtual uint16_t GetOutputFIFOAvailable ()
 
virtual uint16_t GetNumReceived ()
 
virtual bool IsDone ()
 
bool HadReceiveOverflow ()
 
virtual void Write (uint32_t data)
 
virtual uint32_t Read (bool initiate=false)
 
virtual void Reset ()
 
virtual void ClearReceivedData ()
 
- Public Member Functions inherited from SensorBase
 SensorBase ()
 
virtual ~SensorBase ()
 
- Public Member Functions inherited from ErrorBase
virtual ErrorGetError ()
 Retrieve the current error. Get the current error information associated with this sensor.
 
virtual const ErrorGetError () const
 
virtual void SetErrnoError (const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber) const
 Set error information associated with a C library call that set an error to the "errno" global variable. More...
 
virtual void SetImaqError (int success, const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber) const
 Set the current error information associated from the nivision Imaq API. More...
 
virtual void SetError (Error::Code code, const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber) const
 Set the current error information associated with this sensor. More...
 
virtual void SetWPIError (const char *errorMessage, const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber) const
 Set the current error information associated with this sensor. More...
 
virtual void CloneError (ErrorBase *rhs) const
 
virtual void ClearError () const
 Clear the current error information associated with this sensor.
 
virtual bool StatusIsFatal () const
 Check if the current error code represents a fatal error. More...
 

Protected Attributes

tSPI * m_spi
 
tSPI::tConfig m_config
 
tSPI::tChannels m_channels
 
DigitalOutputm_ss
 
- Protected Attributes inherited from ErrorBase
Error m_error
 

Static Protected Attributes

static SEM_ID m_semaphore = NULL
 
- Static Protected Attributes inherited from ErrorBase
static SEM_ID _globalErrorMutex = semMCreate(SEM_Q_PRIORITY | SEM_DELETE_SAFE | SEM_INVERSION_SAFE)
 
static Error _globalError
 

Additional Inherited Members

- Static Public Member Functions inherited from SensorBase
static void DeleteSingletons ()
 
static uint32_t GetDefaultAnalogModule ()
 
static uint32_t GetDefaultDigitalModule ()
 
static uint32_t GetDefaultSolenoidModule ()
 
static bool CheckAnalogModule (uint8_t moduleNumber)
 
static bool CheckDigitalModule (uint8_t moduleNumber)
 
static bool CheckPWMModule (uint8_t moduleNumber)
 
static bool CheckRelayModule (uint8_t moduleNumber)
 
static bool CheckSolenoidModule (uint8_t moduleNumber)
 
static bool CheckDigitalChannel (uint32_t channel)
 
static bool CheckRelayChannel (uint32_t channel)
 
static bool CheckPWMChannel (uint32_t channel)
 
static bool CheckAnalogChannel (uint32_t channel)
 
static bool CheckSolenoidChannel (uint32_t channel)
 
- Static Public Member Functions inherited from ErrorBase
static void SetGlobalError (Error::Code code, const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber)
 
static void SetGlobalWPIError (const char *errorMessage, const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber)
 
static ErrorGetGlobalError ()
 
- Static Public Attributes inherited from SensorBase
static const uint32_t kSystemClockTicksPerMicrosecond = 40
 
static const uint32_t kDigitalChannels = 14
 
static const uint32_t kAnalogChannels = 8
 
static const uint32_t kAnalogModules = 2
 
static const uint32_t kDigitalModules = 2
 
static const uint32_t kSolenoidChannels = 8
 
static const uint32_t kSolenoidModules = 2
 
static const uint32_t kPwmChannels = 10
 
static const uint32_t kRelayChannels = 8
 
static const uint32_t kChassisSlots = 8
 
- Protected Member Functions inherited from SensorBase
void AddToSingletonList ()
 
- Protected Member Functions inherited from ErrorBase
 ErrorBase ()
 Initialize the instance status to 0 for now.
 

Detailed Description

SPI bus interface class.

This class is intended to be used by sensor (and other SPI device) drivers. It probably should not be used directly.

The FPGA only supports a single SPI interface.

Definition at line 24 of file SPI.h.

Constructor & Destructor Documentation

SPI::SPI ( DigitalOutput clk,
DigitalOutput mosi,
DigitalInput miso 
)

Constructor for input and output.

Parameters
clkThe digital output for the clock signal.
mosiThe digital output for the written data to the slave (master-out slave-in).
misoThe digital input for the input data from the slave (master-in slave-out).

Definition at line 31 of file SPI.cpp.

SPI::SPI ( DigitalOutput clk,
DigitalOutput mosi,
DigitalInput miso 
)

Constructor for input and output.

Parameters
clkThe digital output for the clock signal.
mosiThe digital output for the written data to the slave (master-out slave-in).
misoThe digital input for the input data from the slave (master-in slave-out).

Definition at line 45 of file SPI.cpp.

SPI::SPI ( DigitalOutput clk,
DigitalOutput mosi 
)

Constructor for output only.

Parameters
clkThe digital output for the clock signal.
mosiThe digital output for the written data to the slave (master-out slave-in).

Definition at line 57 of file SPI.cpp.

SPI::SPI ( DigitalOutput clk,
DigitalOutput mosi 
)

Constructor for output only.

Parameters
clkThe digital output for the clock signal.
mosiThe digital output for the written data to the slave (master-out slave-in).

Definition at line 69 of file SPI.cpp.

SPI::SPI ( DigitalOutput clk,
DigitalInput miso 
)

Constructor for input only.

Parameters
clkThe digital output for the clock signal.
misoThe digital input for the input data from the slave (master-in slave-out).

Definition at line 81 of file SPI.cpp.

SPI::SPI ( DigitalOutput clk,
DigitalInput miso 
)

Constructor for input only.

Parameters
clkThe digital output for the clock signal.
misoThe digital input for the input data from the slave (master-in slave-out).

Definition at line 93 of file SPI.cpp.

SPI::~SPI ( )
virtual

Destructor.

Definition at line 101 of file SPI.cpp.

Member Function Documentation

void SPI::ApplyConfig ( )
virtual

Apply configuration settings and reset the SPI logic.

Definition at line 361 of file SPI.cpp.

void SPI::ClearReceivedData ( )
virtual

Empty the receive FIFO.

Definition at line 521 of file SPI.cpp.

uint32_t SPI::GetBitsPerWord ( )

Get the number of bits from each word that the slave transmits or receives.

Returns
The number of bits in one frame (1 to 32 bits).

Definition at line 187 of file SPI.cpp.

uint16_t SPI::GetNumReceived ( )
virtual

Get the number of words received and currently available to be read from the receive FIFO.

Returns
The number of words available to read.

Definition at line 392 of file SPI.cpp.

uint16_t SPI::GetOutputFIFOAvailable ( )
virtual

Get the number of words that can currently be stored before being transmitted to the device.

Returns
The number of words available to be written.

Definition at line 378 of file SPI.cpp.

DigitalOutput * SPI::GetSlaveSelect ( tFrameMode *  mode = NULL,
bool *  activeLow = NULL 
)

Get the slave select line behavior.

Parameters
modeFrame mode: kChipSelect: active for the duration of the frame. kPreLatchPulse: pulses before the transfer of each frame. kPostLatchPulse: pulses after the transfer of each frame. kPreAndPostLatchPulse: pulses before and after each frame.
activeLowTrue if slave select line is active low.
Returns
The slave select digital output.

Definition at line 327 of file SPI.cpp.

bool SPI::HadReceiveOverflow ( )

Determine if the receive FIFO was full when attempting to add new data at end of a transfer.

Returns
True if the receive FIFO overflowed.

Definition at line 419 of file SPI.cpp.

bool SPI::IsDone ( )
virtual

Have all pending transfers completed?

Returns
True if no transfers are pending.

Definition at line 405 of file SPI.cpp.

uint32_t SPI::Read ( bool  initiate = false)
virtual

Read a word from the receive FIFO.

Waits for the current transfer to complete if the receive FIFO is empty.

If the receive FIFO is empty, there is no active transfer, and initiate is false, errors.

Parameters
initiateIf true, this function pushes "0" into the transmit buffer and initiates a transfer. If false, this function assumes that data is already in the receive FIFO from a previous write.

Definition at line 466 of file SPI.cpp.

void SPI::Reset ( )
virtual

Stop any transfer in progress and empty the transmit FIFO.

Definition at line 511 of file SPI.cpp.

void SPI::SetBitsPerWord ( uint32_t  bits)

Configure the number of bits from each word that the slave transmits or receives.

Parameters
bitsThe number of bits in one frame (1 to 32 bits).

Definition at line 176 of file SPI.cpp.

void SPI::SetClockActiveHigh ( )

Configure the clock output line to be active high. This is sometimes called clock polarity low.

Definition at line 353 of file SPI.cpp.

void SPI::SetClockActiveLow ( )

Configure the clock output line to be active low. This is sometimes called clock polarity high.

Definition at line 344 of file SPI.cpp.

void SPI::SetClockRate ( double  hz)

Configure the rate of the generated clock signal. The default and maximum value is 76,628.4 Hz.

Parameters
hzThe clock rate in Hertz.

Definition at line 198 of file SPI.cpp.

void SPI::SetLSBFirst ( )

Configure the order that bits are sent and received on the wire to be least significant bit first.

Definition at line 229 of file SPI.cpp.

void SPI::SetMSBFirst ( )

Configure the order that bits are sent and received on the wire to be most significant bit first.

Definition at line 220 of file SPI.cpp.

void SPI::SetSampleDataOnFalling ( )

Configure that the data is stable on the falling edge and the data changes on the rising edge.

Definition at line 238 of file SPI.cpp.

void SPI::SetSampleDataOnRising ( )

Configure that the data is stable on the rising edge and the data changes on the falling edge.

Definition at line 247 of file SPI.cpp.

void SPI::SetSlaveSelect ( DigitalOutput ss,
tFrameMode  mode = kChipSelect,
bool  activeLow = false 
)

Configure the slave select line behavior.

Parameters
ssslave select digital output.
modeFrame mode: kChipSelect: active for the duration of the frame. kPreLatchPulse: pulses before the transfer of each frame. kPostLatchPulse: pulses after the transfer of each frame. kPreAndPostLatchPulse: pulses before and after each frame.
activeLowTrue if slave select line is active low.

Definition at line 263 of file SPI.cpp.

void SPI::SetSlaveSelect ( DigitalOutput ss,
tFrameMode  mode = kChipSelect,
bool  activeLow = false 
)

Configure the slave select line behavior.

Parameters
ssslave select digital output.
modeFrame mode: kChipSelect: active for the duration of the frame. kPreLatchPulse: pulses before the transfer of each frame. kPostLatchPulse: pulses after the transfer of each frame. kPreAndPostLatchPulse: pulses before and after each frame.
activeLowTrue if slave select line is active low.

Definition at line 311 of file SPI.cpp.

void SPI::Write ( uint32_t  data)
virtual

Write a word to the slave device. Blocks until there is space in the output FIFO.

If not running in output only mode, also saves the data received on the MISO input during the transfer into the receive FIFO.

Definition at line 434 of file SPI.cpp.


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

Generated on Sat Apr 26 2014 12:26:47 for WPILibC++ by doxygen 1.8.6