DUDS
Distributed Update of Data from Something
duds::hardware::interface::ChipPinSelectManager Class Reference

Selects a single chip using a single pin. More...

#include <ChipPinSelectManager.hpp>

Inheritance diagram for duds::hardware::interface::ChipPinSelectManager:
Collaboration diagram for duds::hardware::interface::ChipPinSelectManager:

Public Types

enum  SelectState { SelectLow, SelectHigh }
 The list of possible pin states that can be used to select a chip. More...
 

Public Member Functions

 ChipPinSelectManager ()
 Default constructor. More...
 
 ChipPinSelectManager (std::unique_ptr< DigitalPinAccess > &&dpa, SelectState selectState=SelectLow)
 Constructs a ChipPinSelectManager with a pin to use for selection. More...
 
 ~ChipPinSelectManager ()
 Calls shutdown(). More...
 
void setSelectPin (std::unique_ptr< DigitalPinAccess > &&dpa, SelectState selectState=SelectLow)
 Sets the DigitalPinAccess object to use for the chip select line. More...
 
virtual bool validChip (int chipId) const noexcept
 The only valid chip ID for this manager is 1, and it is only valid once a DigitalPinAccess object has been provided. More...
 
- Public Member Functions inherited from duds::hardware::interface::ChipSelectManager
 ChipSelectManager ()
 
virtual ~ChipSelectManager ()=0
 Derived non-abstract classes must call shutdown() in thier destructor. More...
 
std::unique_ptr< ChipAccessaccess (int chipId)
 Acquires access to the requested chip and issues a ChipAccess object. More...
 
void access (ChipAccess &acc, int chipId)
 Acquires access to the requested chip and modifies an existing ChipAccess object to provide that access. More...
 
bool inUse () const
 Returns true if an access object provided by this manager exists. More...
 
std::unique_ptr< ChipAccessselect (int chipId)
 Selects the requested chip and issues a ChipAccess object. More...
 
void select (ChipAccess &acc, int chipId)
 Selects the requested chip and modifies a ChipAccess object to further control chip selection. More...
 

Protected Member Functions

virtual void deselect ()
 Deselects the chip identified by cid. More...
 
virtual void select ()
 Selects the chip identified by cid. More...
 
- Protected Member Functions inherited from duds::hardware::interface::ChipSelectManager
void baseAccess (std::unique_lock< std::mutex > &lock, int chipId)
 Obtains the resources for providing an access object, but does not make an access object. More...
 
void changeChip (int chipId)
 Changes the chip in use while continuing to use an existing access object. More...
 
void shutdown ()
 Waits on a ChipAccess object if one is in use, then begins forcing any threads waiting on access to wake up and throw exceptions. More...
 

Protected Attributes

SelectState selstate
 True when the chip is selected with a high logic level. More...
 
- Protected Attributes inherited from duds::hardware::interface::ChipSelectManager
std::mutex block
 Used to synchonize access. More...
 
int cid
 Selected chip ID, or -1 to terminate. More...
 

Private Attributes

std::unique_ptr< DigitalPinAccessselpin
 The access object for the select pin. More...
 

Detailed Description

Selects a single chip using a single pin.

This is the simplest chip select implementation. It uses a DigitalPinAccess object to operate a single select pin. By using a DigitalPinAccess object, the pin will be flagged as in-use by it's DigitalPort to prevent the select pin from being used for some other purpose.

The pin used for chip selection must support output. This class allows any output type, but will select the first output type supported in this order:

  1. Push-pull
  2. Drive low
  3. Drive high
Author
Jeff Jackowski

Definition at line 31 of file ChipPinSelectManager.hpp.

Member Enumeration Documentation

◆ SelectState

The list of possible pin states that can be used to select a chip.

Enumerator
SelectLow 

Indicates the chip is selected when the pin is driven low, or doesn't drive the line if the output type can only drive high.

SelectHigh 

Indicates the chip is selected when the pin is driven high, or doesn't drive the line if the output type can only drive low.

Definition at line 40 of file ChipPinSelectManager.hpp.

Constructor & Destructor Documentation

◆ ChipPinSelectManager() [1/2]

duds::hardware::interface::ChipPinSelectManager::ChipPinSelectManager ( )
inline

Default constructor.

Definition at line 65 of file ChipPinSelectManager.hpp.

◆ ~ChipPinSelectManager()

duds::hardware::interface::ChipPinSelectManager::~ChipPinSelectManager ( )

Calls shutdown().

Definition at line 69 of file ChipPinSelectManager.cpp.

Referenced by ChipPinSelectManager().

◆ ChipPinSelectManager() [2/2]

duds::hardware::interface::ChipPinSelectManager::ChipPinSelectManager ( std::unique_ptr< DigitalPinAccess > &&  dpa,
SelectState  selectState = SelectLow 
)

Constructs a ChipPinSelectManager with a pin to use for selection.

Parameters
dpaThe access object for the select pin.
selectStateThe pin state that selects the device.
Exceptions
ChipSelectInUseA ChipAccess object provided by this manager currently exists.
PinUnsupportedOperationThe given pin does not support output.
PinDoesNotExistThe DigitalPinAccess object does not provide access to any pin.

Definition at line 62 of file ChipPinSelectManager.cpp.

Member Function Documentation

◆ deselect()

void duds::hardware::interface::ChipPinSelectManager::deselect ( )
protectedvirtual

Deselects the chip identified by cid.

If the chip is already deselected, it must remain deselected.

Note
There is no need for thread synchronization in this function.

Implements duds::hardware::interface::ChipSelectManager.

Definition at line 23 of file ChipPinSelectManager.cpp.

◆ select()

void duds::hardware::interface::ChipPinSelectManager::select ( )
protectedvirtual

Selects the chip identified by cid.

If the chip is already selected, it must remain selected.

Note
There is no need for thread synchronization in this function.

Implements duds::hardware::interface::ChipSelectManager.

Definition at line 19 of file ChipPinSelectManager.cpp.

◆ setSelectPin()

void duds::hardware::interface::ChipPinSelectManager::setSelectPin ( std::unique_ptr< DigitalPinAccess > &&  dpa,
SelectState  selectState = SelectLow 
)

Sets the DigitalPinAccess object to use for the chip select line.

Parameters
dpaThe access object for the select pin.
selectStateThe pin state that selects the device.
Exceptions
ChipSelectInUseA ChipAccess object provided by this manager currently exists.
PinUnsupportedOperationThe given pin does not support output.
PinDoesNotExistThe DigitalPinAccess object does not provide access to any pin.

Definition at line 27 of file ChipPinSelectManager.cpp.

Referenced by ChipPinSelectManager().

◆ validChip()

bool duds::hardware::interface::ChipPinSelectManager::validChip ( int  chipId) const
virtualnoexcept

The only valid chip ID for this manager is 1, and it is only valid once a DigitalPinAccess object has been provided.

Implements duds::hardware::interface::ChipSelectManager.

Definition at line 15 of file ChipPinSelectManager.cpp.

Referenced by ChipPinSelectManager().

Member Data Documentation

◆ selpin

std::unique_ptr<DigitalPinAccess> duds::hardware::interface::ChipPinSelectManager::selpin
private

The access object for the select pin.

Definition at line 35 of file ChipPinSelectManager.hpp.

Referenced by deselect(), select(), and setSelectPin().

◆ selstate

SelectState duds::hardware::interface::ChipPinSelectManager::selstate
protected

True when the chip is selected with a high logic level.

Definition at line 60 of file ChipPinSelectManager.hpp.

Referenced by deselect(), select(), and setSelectPin().


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