PX4 Firmware
PX4 Autopilot Software http://px4.io
__EXPORT::SPI Class Reference

Abstract class for character device on SPI. More...

#include <SPI.hpp>

Inheritance diagram for __EXPORT::SPI:
Collaboration diagram for __EXPORT::SPI:

Public Member Functions

 SPI (const SPI &)=delete
 
SPIoperator= (const SPI &)=delete
 
 SPI (SPI &&)=delete
 
SPIoperator= (SPI &&)=delete
 

Protected Types

enum  LockMode {
  LOCK_PREEMPTION, LOCK_THREADS, LOCK_NONE, LOCK_PREEMPTION,
  LOCK_THREADS, LOCK_NONE
}
 Locking modes supported by the driver. More...
 
enum  LockMode {
  LOCK_PREEMPTION, LOCK_THREADS, LOCK_NONE, LOCK_PREEMPTION,
  LOCK_THREADS, LOCK_NONE
}
 Locking modes supported by the driver. More...
 

Protected Member Functions

 SPI (const char *name, const char *devname, int bus, uint32_t device, enum spi_mode_e mode, uint32_t frequency)
 Constructor. More...
 
virtual ~SPI ()
 
virtual int init () override
 
virtual int probe ()
 Check for the presence of the device on the bus. More...
 
int transfer (uint8_t *send, uint8_t *recv, unsigned len)
 Perform a SPI transfer. More...
 
int transferhword (uint16_t *send, uint16_t *recv, unsigned len)
 Perform a SPI 16 bit transfer. More...
 
void set_frequency (uint32_t frequency)
 Set the SPI bus frequency This is used to change frequency on the fly. More...
 
uint32_t get_frequency ()
 
void set_lockmode (enum LockMode mode)
 Set the SPI bus locking mode. More...
 
int _transfer (uint8_t *send, uint8_t *recv, unsigned len)
 
int _transferhword (uint16_t *send, uint16_t *recv, unsigned len)
 
virtual bool external () const override
 
 SPI (const char *name, const char *devname, int bus, uint32_t device, enum spi_mode_e mode, uint32_t frequency)
 Constructor. More...
 
virtual ~SPI ()
 
virtual int init ()
 
virtual int probe ()
 Check for the presence of the device on the bus. More...
 
int transfer (uint8_t *send, uint8_t *recv, unsigned len)
 Perform a SPI transfer. More...
 
int transferhword (uint16_t *send, uint16_t *recv, unsigned len)
 Perform a SPI 16 bit transfer. More...
 
void set_frequency (uint32_t frequency)
 Set the SPI bus frequency This is used to change frequency on the fly. More...
 
uint32_t get_frequency ()
 
void set_lockmode (enum LockMode mode)
 Set the SPI bus locking mode. More...
 
bool external ()
 

Private Member Functions

 SPI (const SPI &)
 
SPI operator= (const SPI &)
 

Private Attributes

uint32_t _device
 
enum spi_mode_e _mode
 
uint32_t _frequency
 
struct spi_dev_s * _dev
 
LockMode _locking_mode {LOCK_THREADS}
 selected locking mode More...
 
int _fd {-1}
 

Detailed Description

Abstract class for character device on SPI.

Definition at line 51 of file SPI.hpp.

Member Enumeration Documentation

◆ LockMode [1/2]

enum __EXPORT::SPI::LockMode
protected

Locking modes supported by the driver.

Enumerator
LOCK_PREEMPTION 

the default; lock against all forms of preemption.

LOCK_THREADS 

lock only against other threads, using SPI_LOCK

LOCK_NONE 

perform no locking, only safe if the bus is entirely private

LOCK_PREEMPTION 

the default; lock against all forms of preemption.

LOCK_THREADS 

lock only against other threads, using SPI_LOCK

LOCK_NONE 

perform no locking, only safe if the bus is entirely private

Definition at line 77 of file SPI.hpp.

◆ LockMode [2/2]

enum __EXPORT::SPI::LockMode
protected

Locking modes supported by the driver.

Enumerator
LOCK_PREEMPTION 

the default; lock against all forms of preemption.

LOCK_THREADS 

lock only against other threads, using SPI_LOCK

LOCK_NONE 

perform no locking, only safe if the bus is entirely private

LOCK_PREEMPTION 

the default; lock against all forms of preemption.

LOCK_THREADS 

lock only against other threads, using SPI_LOCK

LOCK_NONE 

perform no locking, only safe if the bus is entirely private

Definition at line 78 of file SPI.hpp.

Constructor & Destructor Documentation

◆ SPI() [1/5]

__EXPORT::SPI::SPI ( const SPI )
delete

◆ SPI() [2/5]

__EXPORT::SPI::SPI ( SPI &&  )
delete

◆ SPI() [3/5]

__EXPORT::SPI::SPI ( const char *  name,
const char *  devname,
int  bus,
uint32_t  device,
enum spi_mode_e  mode,
uint32_t  frequency 
)
protected

Constructor.

Parameters
nameDriver name
devnameDevice node name
busSPI bus on which the device lives
deviceDevice handle (used by SPI_SELECT)
modeSPI clock/data mode
frequencySPI clock frequency

◆ ~SPI() [1/2]

virtual __EXPORT::SPI::~SPI ( )
protectedvirtual

◆ SPI() [4/5]

SPI::SPI ( const char *  name,
const char *  devname,
int  bus,
uint32_t  device,
enum spi_mode_e  mode,
uint32_t  frequency 
)
protected

Constructor.

Parameters
nameDriver name
devnameDevice node name
busSPI bus on which the device lives
deviceDevice handle (used by SPI_SELECT)
modeSPI clock/data mode
frequencySPI clock frequency

Definition at line 60 of file SPI.cpp.

◆ ~SPI() [2/2]

SPI::~SPI ( )
protectedvirtual

Definition at line 75 of file SPI.cpp.

◆ SPI() [5/5]

__EXPORT::SPI::SPI ( const SPI )
private

Member Function Documentation

◆ _transfer()

int SPI::_transfer ( uint8_t *  send,
uint8_t *  recv,
unsigned  len 
)
protected

Definition at line 160 of file SPI.cpp.

References _dev, _device, _frequency, and _mode.

Referenced by transfer().

Here is the caller graph for this function:

◆ _transferhword()

int SPI::_transferhword ( uint16_t *  send,
uint16_t *  recv,
unsigned  len 
)
protected

Definition at line 212 of file SPI.cpp.

References _dev, _device, _frequency, and _mode.

Referenced by transferhword().

Here is the caller graph for this function:

◆ external() [1/2]

virtual bool __EXPORT::SPI::external ( ) const
inlineoverrideprotectedvirtual

Definition at line 167 of file SPI.hpp.

◆ external() [2/2]

bool __EXPORT::SPI::external ( )
inlineprotected

Definition at line 168 of file SPI.hpp.

◆ get_frequency() [1/2]

uint32_t __EXPORT::SPI::get_frequency ( )
inlineprotected

Definition at line 142 of file SPI.hpp.

◆ get_frequency() [2/2]

uint32_t __EXPORT::SPI::get_frequency ( )
inlineprotected

Definition at line 143 of file SPI.hpp.

◆ init() [1/2]

virtual int __EXPORT::SPI::init ( )
overrideprotectedvirtual

◆ init() [2/2]

int SPI::init ( )
protectedvirtual

Definition at line 81 of file SPI.cpp.

References _dev, _device, _frequency, DEVICE_DEBUG, DEVICE_LOG, ToneAlarmInterface::init(), OK, and probe().

Here is the call graph for this function:

◆ operator=() [1/3]

SPI& __EXPORT::SPI::operator= ( const SPI )
delete

◆ operator=() [2/3]

SPI& __EXPORT::SPI::operator= ( SPI &&  )
delete

◆ operator=() [3/3]

SPI __EXPORT::SPI::operator= ( const SPI )
private

◆ probe() [1/2]

virtual int __EXPORT::SPI::probe ( )
inlineprotectedvirtual

Check for the presence of the device on the bus.

Definition at line 88 of file SPI.hpp.

References send().

Referenced by init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ probe() [2/2]

virtual int __EXPORT::SPI::probe ( )
inlineprotectedvirtual

Check for the presence of the device on the bus.

Definition at line 89 of file SPI.hpp.

References send().

Here is the call graph for this function:

◆ set_frequency() [1/2]

void __EXPORT::SPI::set_frequency ( uint32_t  frequency)
inlineprotected

Set the SPI bus frequency This is used to change frequency on the fly.

Some sensors (such as the MPU6000) need a lower frequency for setup registers and can handle higher frequency for sensor value registers

Parameters
frequencyFrequency to set (Hz)

Definition at line 141 of file SPI.hpp.

◆ set_frequency() [2/2]

void __EXPORT::SPI::set_frequency ( uint32_t  frequency)
inlineprotected

Set the SPI bus frequency This is used to change frequency on the fly.

Some sensors (such as the MPU6000) need a lower frequency for setup registers and can handle higher frequency for sensor value registers

Parameters
frequencyFrequency to set (Hz)

Definition at line 142 of file SPI.hpp.

◆ set_lockmode() [1/2]

void __EXPORT::SPI::set_lockmode ( enum LockMode  mode)
inlineprotected

Set the SPI bus locking mode.

This set the SPI locking mode. For devices competing with NuttX SPI drivers on a bus the right lock mode is LOCK_THREADS.

Parameters
modeLocking mode

Definition at line 152 of file SPI.hpp.

◆ set_lockmode() [2/2]

void __EXPORT::SPI::set_lockmode ( enum LockMode  mode)
inlineprotected

Set the SPI bus locking mode.

This set the SPI locking mode. For devices competing with NuttX SPI drivers on a bus the right lock mode is LOCK_THREADS.

Parameters
modeLocking mode

Definition at line 153 of file SPI.hpp.

◆ transfer() [1/2]

int __EXPORT::SPI::transfer ( uint8_t *  send,
uint8_t *  recv,
unsigned  len 
)
protected

Perform a SPI transfer.

If called from interrupt context, this interface does not lock the bus and may interfere with non-interrupt-context callers.

Clients in a mixed interrupt/non-interrupt configuration must ensure appropriate interlocking.

At least one of send or recv must be non-null.

Parameters
sendBytes to send to the device, or nullptr if no data is to be sent.
recvBuffer for receiving bytes from the device, or nullptr if no bytes are to be received.
lenNumber of bytes to transfer.
Returns
OK if the exchange was successful, -errno otherwise.

◆ transfer() [2/2]

int SPI::transfer ( uint8_t *  send,
uint8_t *  recv,
unsigned  len 
)
protected

Perform a SPI transfer.

If called from interrupt context, this interface does not lock the bus and may interfere with non-interrupt-context callers.

Clients in a mixed interrupt/non-interrupt configuration must ensure appropriate interlocking.

At least one of send or recv must be non-null.

Parameters
sendBytes to send to the device, or nullptr if no data is to be sent.
recvBuffer for receiving bytes from the device, or nullptr if no bytes are to be received.
lenNumber of bytes to transfer.
Returns
OK if the exchange was successful, -errno otherwise.

Definition at line 125 of file SPI.cpp.

References _dev, _locking_mode, _transfer(), LOCK_NONE, LOCK_PREEMPTION, LOCK_THREADS, and state.

Here is the call graph for this function:

◆ transferhword() [1/2]

int __EXPORT::SPI::transferhword ( uint16_t *  send,
uint16_t *  recv,
unsigned  len 
)
protected

Perform a SPI 16 bit transfer.

If called from interrupt context, this interface does not lock the bus and may interfere with non-interrupt-context callers.

Clients in a mixed interrupt/non-interrupt configuration must ensure appropriate interlocking.

At least one of send or recv must be non-null.

Parameters
sendWords to send to the device, or nullptr if no data is to be sent.
recvWords for receiving bytes from the device, or nullptr if no bytes are to be received.
lenNumber of words to transfer.
Returns
OK if the exchange was successful, -errno otherwise.

◆ transferhword() [2/2]

int SPI::transferhword ( uint16_t *  send,
uint16_t *  recv,
unsigned  len 
)
protected

Perform a SPI 16 bit transfer.

If called from interrupt context, this interface does not lock the bus and may interfere with non-interrupt-context callers.

Clients in a mixed interrupt/non-interrupt configuration must ensure appropriate interlocking.

At least one of send or recv must be non-null.

Parameters
sendWords to send to the device, or nullptr if no data is to be sent.
recvWords for receiving bytes from the device, or nullptr if no bytes are to be received.
lenNumber of words to transfer.
Returns
OK if the exchange was successful, -errno otherwise.

Definition at line 177 of file SPI.cpp.

References _dev, _locking_mode, _transferhword(), LOCK_NONE, LOCK_PREEMPTION, LOCK_THREADS, and state.

Here is the call graph for this function:

Member Data Documentation

◆ _dev

struct spi_dev_s* __EXPORT::SPI::_dev
private

Definition at line 158 of file SPI.hpp.

Referenced by _transfer(), _transferhword(), init(), transfer(), and transferhword().

◆ _device

uint32_t __EXPORT::SPI::_device
private

Definition at line 155 of file SPI.hpp.

Referenced by _transfer(), _transferhword(), and init().

◆ _fd

int __EXPORT::SPI::_fd {-1}
private

Definition at line 156 of file SPI.hpp.

◆ _frequency

uint32_t __EXPORT::SPI::_frequency
private

Definition at line 157 of file SPI.hpp.

Referenced by _transfer(), _transferhword(), and init().

◆ _locking_mode

LockMode __EXPORT::SPI::_locking_mode {LOCK_THREADS}
private

selected locking mode

Definition at line 160 of file SPI.hpp.

Referenced by transfer(), and transferhword().

◆ _mode

enum spi_mode_e __EXPORT::SPI::_mode
private

Definition at line 156 of file SPI.hpp.

Referenced by _transfer(), and _transferhword().


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