DUDS
Distributed Update of Data from Something
ChipAccess.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 CHIPACCESS_HPP
11 #define CHIPACCESS_HPP
12 
14 
15 namespace duds { namespace hardware { namespace interface {
16 
22 class ChipAccess : boost::noncopyable {
26  friend std::unique_ptr<ChipAccess> ChipSelectManager::access(int);
30  friend void ChipSelectManager::access(ChipAccess &, int);
34  std::shared_ptr<ChipSelectManager> manager;
39  ChipAccess(const std::shared_ptr<ChipSelectManager> &m) : manager(m) { }
40  public:
44  ChipAccess() { }
49  retire();
50  }
54  void retire() {
55  if (manager) {
56  manager->retire(this);
57  manager.reset();
58  }
59  }
63  void select() {
64  manager->select();
65  }
69  void deselect() {
70  manager->deselect();
71  }
88  void changeChip(int chipId) {
89  manager->changeChip(chipId);
90  }
91 };
92 
93 } } }
94 
95 
96 #endif // #ifndef CHIPACCESS_HPP
void changeChip(int chipId)
Changes the chip in use while not giving up access to the chip selector.
Definition: ChipAccess.hpp:88
ChipAccess()
Makes a ChipAccess object that has no access.
Definition: ChipAccess.hpp:44
An object used to provide chip select control to a single user at a time.
Definition: ChipAccess.hpp:22
void deselect()
Deselects the chip.
Definition: ChipAccess.hpp:69
std::unique_ptr< ChipAccess > access(int chipId)
Acquires access to the requested chip and issues a ChipAccess object.
~ChipAccess()
Relinquishes access.
Definition: ChipAccess.hpp:48
void retire()
Relinquish access.
Definition: ChipAccess.hpp:54
ChipAccess(const std::shared_ptr< ChipSelectManager > &m)
Constructs a ChipAccess object for use with the given manager.
Definition: ChipAccess.hpp:39
void select()
Selects the chip.
Definition: ChipAccess.hpp:63
std::shared_ptr< ChipSelectManager > manager
The manager to which this object is attached.
Definition: ChipAccess.hpp:34