distortos  v0.5.0
object-oriented C++ RTOS for microcontrollers
SpiMaster.hpp
Go to the documentation of this file.
1 
12 #ifndef INCLUDE_DISTORTOS_DEVICES_COMMUNICATION_SPIMASTER_HPP_
13 #define INCLUDE_DISTORTOS_DEVICES_COMMUNICATION_SPIMASTER_HPP_
14 
17 
18 #include "distortos/Mutex.hpp"
19 
20 namespace distortos
21 {
22 
23 class Semaphore;
24 
25 namespace devices
26 {
27 
28 class SpiDevice;
29 class SpiMasterLowLevel;
30 
37 class SpiMaster : private SpiMasterBase
38 {
39 public:
40 
47  constexpr explicit SpiMaster(SpiMasterLowLevel& spiMaster) :
50  ret_{},
51  semaphore_{},
52  spiMaster_{spiMaster},
53  openCount_{}
54  {
55 
56  }
57 
66  ~SpiMaster() override;
67 
80  int close();
81 
103  std::pair<int, size_t> executeTransaction(const SpiDevice& device, SpiMasterOperationRange operationRange);
104 
117  int open();
118 
119 private:
120 
127  void notifyWaiter(int ret = {});
128 
143  void transferCompleteEvent(SpiMasterErrorSet errorSet, size_t bytesTransfered) override;
144 
147 
150 
152  volatile int ret_;
153 
156 
159 
161  uint8_t openCount_;
162 };
163 
164 } // namespace devices
165 
166 } // namespace distortos
167 
168 #endif // INCLUDE_DISTORTOS_DEVICES_COMMUNICATION_SPIMASTER_HPP_
Definition: SpiMasterBase.hpp:32
priority inheritance protocol, similar to PTHREAD_PRIO_INHERIT
normal mutex, similar to PTHREAD_MUTEX_NORMAL
Semaphore is the basic synchronization primitive.
Definition: Semaphore.hpp:30
~SpiMaster() override
SpiMaster&#39;s destructor.
Definition: SpiMaster.cpp:39
SpiMasterOperationRange operationRange_
range of operations that are part of currently handled transaction
Definition: SpiMaster.hpp:149
SpiMasterLowLevel & spiMaster_
reference to low-level implementation of SpiMasterLowLevel interface
Definition: SpiMaster.hpp:158
Mutex mutex_
mutex used to serialize access to this object
Definition: SpiMaster.hpp:146
volatile int ret_
error codes detected in transferCompleteEvent()
Definition: SpiMaster.hpp:152
int close()
Closes SPI master.
Definition: SpiMaster.cpp:56
Definition: SpiMasterLowLevel.hpp:35
Definition: SpiMasterErrorSet.hpp:29
Mutex class header.
Definition: SpiDevice.hpp:38
SpiMasterBase class header.
Top-level namespace of distortos project.
Semaphore *volatile semaphore_
pointer to semaphore used to notify waiting thread about completion of transaction ...
Definition: SpiMaster.hpp:155
Mutex is the basic synchronization primitive.
Definition: Mutex.hpp:30
Definition: SpiMaster.hpp:37
void transferCompleteEvent(SpiMasterErrorSet errorSet, size_t bytesTransfered) override
"Transfer complete" event
Definition: SpiMaster.cpp:167
constexpr SpiMaster(SpiMasterLowLevel &spiMaster)
SpiMaster&#39;s constructor.
Definition: SpiMaster.hpp:47
uint8_t openCount_
number of times this device was opened but not yet closed
Definition: SpiMaster.hpp:161
SpiMasterOperationRange type alias header.
void notifyWaiter(int ret={})
Notifies waiting thread about completion of transaction.
Definition: SpiMaster.cpp:159
int open()
Opens SPI master.
Definition: SpiMaster.cpp:132
std::pair< int, size_t > executeTransaction(const SpiDevice &device, SpiMasterOperationRange operationRange)
Executes series of operations as a single atomic transaction.
Definition: SpiMaster.cpp:79