DUDS
Distributed Update of Data from Something
ChipSelect.hpp
Go to the documentation of this file.
1 /*
2  * This file is part of the DUDS project. It is subject to the BSD-style
3  * license terms in the LICENSE file found in the top-level directory of this
4  * distribution and at https://github.com/jjackowski/duds/blob/master/LICENSE.
5  * No part of DUDS, including this file, may be copied, modified, propagated,
6  * or distributed except according to the terms contained in the LICENSE file.
7  *
8  * Copyright (C) 2017 Jeff Jackowski
9  */
10 #ifndef CHIPSELECT_HPP
11 #define CHIPSELECT_HPP
12 
14 
15 namespace duds { namespace hardware { namespace interface {
16 
17 class ChipSelectManager;
18 
24 class ChipSelect {
28  std::shared_ptr<ChipSelectManager> mgr;
32  int cid;
33 public:
38  ChipSelect() noexcept;
47  ChipSelect(const std::shared_ptr<ChipSelectManager> &csm, int chipId);
56  ChipSelect(std::shared_ptr<ChipSelectManager> &&csm, int chipId);
65  std::unique_ptr<ChipAccess> access();
76  void access(ChipAccess &acc);
85  std::unique_ptr<ChipAccess> select();
96  void select(ChipAccess &acc);
100  bool haveManager() const {
101  return (bool)mgr;
102  }
106  const std::shared_ptr<ChipSelectManager> &manager() const {
107  return mgr;
108  }
112  bool configured() const {
113  return mgr && (cid >= 0);
114  }
119  operator bool () const {
120  return configured();
121  }
125  int chipId() const {
126  return cid;
127  }
136  void modify(const std::shared_ptr<ChipSelectManager> &csm, int chipId);
145  void modify(std::shared_ptr<ChipSelectManager> &&csm, int chipId);
150  void reset() noexcept;
151 };
152 
153 } } }
154 
155 
156 #endif // #ifndef CHIPSELECT_HPP
int chipId() const
Returns the chip ID of the chip this object will select.
Definition: ChipSelect.hpp:125
void modify(const std::shared_ptr< ChipSelectManager > &csm, int chipId)
Changes the manager and chip to select.
Definition: ChipSelect.cpp:64
STL namespace.
bool configured() const
Returns true if this object was configured with a chip to select.
Definition: ChipSelect.hpp:112
An object to wrap together a ChipSelectManager and chip ID to simplify code that needs to repeatedly ...
Definition: ChipSelect.hpp:24
bool haveManager() const
Returns true if this object has an associated manager.
Definition: ChipSelect.hpp:100
An object used to provide chip select control to a single user at a time.
Definition: ChipAccess.hpp:22
ChipSelect() noexcept
Initializes the object to a non-configured state.
Definition: ChipSelect.cpp:16
std::unique_ptr< ChipAccess > access()
Obtains a ChipAccess object.
Definition: ChipSelect.cpp:32
void reset() noexcept
Returns the object to the default constructed state of not having a manager or a valid chip ID...
Definition: ChipSelect.cpp:92
const std::shared_ptr< ChipSelectManager > & manager() const
Returns the associated manager object.
Definition: ChipSelect.hpp:106
std::unique_ptr< ChipAccess > select()
Obtains an access object and selects the chip.
Definition: ChipSelect.cpp:48
std::shared_ptr< ChipSelectManager > mgr
The manager that will handle the selection.
Definition: ChipSelect.hpp:28
The base class for all chip selection managers, the classes that handle the output state to select a ...