distortos  v0.7.0
object-oriented C++ RTOS for microcontrollers
SynchronousSdMmcCardLowLevel.hpp
Go to the documentation of this file.
1 
12 #ifndef INCLUDE_DISTORTOS_DEVICES_MEMORY_SYNCHRONOUSSDMMCCARDLOWLEVEL_HPP_
13 #define INCLUDE_DISTORTOS_DEVICES_MEMORY_SYNCHRONOUSSDMMCCARDLOWLEVEL_HPP_
14 
17 
18 #include "distortos/Semaphore.hpp"
19 
20 namespace distortos
21 {
22 
23 namespace devices
24 {
25 
26 class SdMmcCardLowLevel;
27 
30 {
31 public:
32 
39  constexpr explicit SynchronousSdMmcCardLowLevel(SdMmcCardLowLevel& sdMmcCard) :
40  semaphore_{0, 1},
41  sdMmcCard_{sdMmcCard},
42  result_{}
43  {
44 
45  }
46 
58  void configure(const SdMmcCardLowLevel::BusMode busMode, const uint32_t clockFrequency) const
59  {
60  sdMmcCard_.configure(busMode, clockFrequency);
61  }
62 
88  Result executeTransaction(const uint8_t command, const uint32_t argument,
89  const SdMmcCardLowLevel::Response response, const SdMmcCardLowLevel::Transfer transfer)
90  {
91  sdMmcCard_.startTransaction(*this, command, argument, response, transfer);
92  while (semaphore_.wait() != 0);
93  return result_;
94  }
95 
105  int start() const
106  {
107  return sdMmcCard_.start();
108  }
109 
119  void stop() const
120  {
121  sdMmcCard_.stop();
122  }
123 
124 private:
125 
134  void transactionCompleteEvent(Result result) override;
135 
138 
141 
144 };
145 
146 } // namespace devices
147 
148 } // namespace distortos
149 
150 #endif // INCLUDE_DISTORTOS_DEVICES_MEMORY_SYNCHRONOUSSDMMCCARDLOWLEVEL_HPP_
Semaphore is the basic synchronization primitive.
Definition: Semaphore.hpp:30
Semaphore semaphore_
semaphore used to notify waiting thread about completion of transaction
Definition: SynchronousSdMmcCardLowLevel.hpp:137
command response
Definition: SdMmcCardLowLevel.hpp:47
transfer associated with transaction
Definition: SdMmcCardLowLevel.hpp:138
SynchronousSdMmcCardLowLevel is a synchronous wrapper for SdMmcCardLowLevel which implements SdMmcCar...
Definition: SynchronousSdMmcCardLowLevel.hpp:29
Result
result of transaction
Definition: SdMmcCardBase.hpp:35
virtual int start()=0
Starts low-level SD/MMC card driver.
SdMmcCardLowLevel class header.
SdMmcCardLowLevel & sdMmcCard_
reference to asynchronous low-level implementation of SdMmcCardLowLevel interface
Definition: SynchronousSdMmcCardLowLevel.hpp:140
int wait()
Locks the semaphore.
Definition: Semaphore.cpp:72
Semaphore class header.
int start() const
Starts low-level SD/MMC card driver.
Definition: SynchronousSdMmcCardLowLevel.hpp:105
SdMmcCardBase class header.
Definition: SdMmcCardLowLevel.hpp:31
constexpr SynchronousSdMmcCardLowLevel(SdMmcCardLowLevel &sdMmcCard)
SynchronousSdMmcCardLowLevel's constructor.
Definition: SynchronousSdMmcCardLowLevel.hpp:39
virtual void stop()=0
Stops low-level SD/MMC card driver.
Result executeTransaction(const uint8_t command, const uint32_t argument, const SdMmcCardLowLevel::Response response, const SdMmcCardLowLevel::Transfer transfer)
Executes transaction.
Definition: SynchronousSdMmcCardLowLevel.hpp:88
Top-level namespace of distortos project.
Definition: buttons.hpp:33
void configure(const SdMmcCardLowLevel::BusMode busMode, const uint32_t clockFrequency) const
Configures parameters of low-level SD/MMC card driver.
Definition: SynchronousSdMmcCardLowLevel.hpp:58
Definition: SdMmcCardBase.hpp:30
BusMode
bus mode
Definition: SdMmcCardLowLevel.hpp:36
Result result_
result of transaction passed to transactionCompleteEvent()
Definition: SynchronousSdMmcCardLowLevel.hpp:143
void transactionCompleteEvent(Result result) override
"Transaction complete" event
Definition: SynchronousSdMmcCardLowLevel.cpp:26
void stop() const
Stops low-level SD/MMC card driver.
Definition: SynchronousSdMmcCardLowLevel.hpp:119
virtual void configure(BusMode busMode, uint32_t clockFrequency)=0
Configures parameters of low-level SD/MMC card driver.
virtual void startTransaction(SdMmcCardBase &sdMmcCardBase, uint8_t command, uint32_t argument, Response response, Transfer transfer)=0
Starts asynchronous transaction.