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

Selects one of two chips using a single pin. More...

#include <ChipBinarySelectManager.hpp>

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

Public Member Functions

 ChipBinarySelectManager ()
 Default constructor. More...
 
 ChipBinarySelectManager (std::unique_ptr< DigitalPinAccess > &&dpa, int initSel=0)
 Constructs a ChipBinarySelectManager with a pin for selection. More...
 
 ~ChipBinarySelectManager ()
 Calls shutdown(). More...
 
void setSelectPin (std::unique_ptr< DigitalPinAccess > &&dpa, int initSel=0)
 Sets the DigitalPinAccess object to use for the chip select line. More...
 
virtual bool validChip (int chipId) const noexcept
 The only valid chip IDs for this manager are 0 and 1, and they are 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...
 

Private Attributes

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

Additional Inherited Members

- 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...
 

Detailed Description

Selects one of two chips using a single pin.

This means one of the chips will always be selected. Not all chips will function properly using this scheme. At least some EEPROM's have no problem with it. The hardware implementation may require an inverter. Chip ID 0 is selected with a logic low, and ID 1 with a logic high.

Even though a chip is always selected, an access object should always be requested prior to using either chip. This will ensure the correct chip is selected by a multi-threaded program, and will work properly if the chip selection implementation is changed.

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
Todo:
Change select() and deselect() to ensure that the operations force a state change, at least momentarily, on the select line.
Author
Jeff Jackowski

Definition at line 39 of file ChipBinarySelectManager.hpp.

Constructor & Destructor Documentation

◆ ChipBinarySelectManager() [1/2]

duds::hardware::interface::ChipBinarySelectManager::ChipBinarySelectManager ( )

Default constructor.

Definition at line 73 of file ChipBinarySelectManager.cpp.

◆ ChipBinarySelectManager() [2/2]

duds::hardware::interface::ChipBinarySelectManager::ChipBinarySelectManager ( std::unique_ptr< DigitalPinAccess > &&  dpa,
int  initSel = 0 
)

Constructs a ChipBinarySelectManager with a pin for selection.

Parameters
dpaThe access object for the select pin.
initSelNon-zero to initially select ID 1 (logic high), or zero for ID 0 (logic low).
Exceptions
ChipSelectInUseA ChipAccess object provided by this manager currently exists.
PinDoesNotExistThe DigitalPinAccess object does not provide access to any pin.
DigitalPinCannotOutputErrorThe pin cannot output.

Definition at line 75 of file ChipBinarySelectManager.cpp.

◆ ~ChipBinarySelectManager()

duds::hardware::interface::ChipBinarySelectManager::~ChipBinarySelectManager ( )

Calls shutdown().

Definition at line 81 of file ChipBinarySelectManager.cpp.

Member Function Documentation

◆ deselect()

void duds::hardware::interface::ChipBinarySelectManager::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 ChipBinarySelectManager.cpp.

◆ select()

void duds::hardware::interface::ChipBinarySelectManager::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 ChipBinarySelectManager.cpp.

◆ setSelectPin()

void duds::hardware::interface::ChipBinarySelectManager::setSelectPin ( std::unique_ptr< DigitalPinAccess > &&  dpa,
int  initSel = 0 
)

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

Parameters
dpaThe access object for the select pin.
initSelThe initially selected chip ID. Must be 0 or 1.
Exceptions
ChipSelectInUseA ChipAccess object provided by this manager currently exists.
PinDoesNotExistThe DigitalPinAccess object does not provide access to any pin.
DigitalPinCannotOutputErrorThe pin cannot output.

Definition at line 27 of file ChipBinarySelectManager.cpp.

Referenced by ChipBinarySelectManager().

◆ validChip()

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

The only valid chip IDs for this manager are 0 and 1, and they are only valid once a DigitalPinAccess object has been provided.

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

Definition at line 15 of file ChipBinarySelectManager.cpp.

Member Data Documentation

◆ selpin

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

The access object for the select pin.

Definition at line 43 of file ChipBinarySelectManager.hpp.

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


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