distortos  v0.7.0
object-oriented C++ RTOS for microcontrollers
SpiMasterLowLevelInterruptBased.hpp
Go to the documentation of this file.
1 
12 #ifndef SOURCE_CHIP_STM32_PERIPHERALS_SPIV1_INCLUDE_DISTORTOS_CHIP_SPIMASTERLOWLEVELINTERRUPTBASED_HPP_
13 #define SOURCE_CHIP_STM32_PERIPHERALS_SPIV1_INCLUDE_DISTORTOS_CHIP_SPIMASTERLOWLEVELINTERRUPTBASED_HPP_
14 
16 
17 namespace distortos
18 {
19 
20 namespace chip
21 {
22 
23 class SpiPeripheral;
24 
34 {
35 public:
36 
43  constexpr explicit SpiMasterLowLevelInterruptBased(const SpiPeripheral& spiPeripheral) :
44  spiPeripheral_{spiPeripheral},
46  readBuffer_{},
47  writeBuffer_{},
48  size_{},
49  readPosition_{},
51  dummyData_{},
52  started_{},
53  wordLength_{8}
54  {
55 
56  }
57 
65 
81  void configure(devices::SpiMode mode, uint32_t clockFrequency, uint8_t wordLength, bool lsbFirst,
82  uint32_t dummyData) override;
83 
90  void interruptHandler();
91 
100  int start() override;
101 
122  void startTransfer(devices::SpiMasterBase& spiMasterBase, const void* writeBuffer, void* readBuffer,
123  size_t size) override;
124 
134  void stop() override;
135 
136 private:
137 
142  bool isStarted() const
143  {
144  return started_;
145  }
146 
151  bool isTransferInProgress() const
152  {
153  return size_ != 0;
154  }
155 
160  void writeNextItem();
161 
164 
167 
169  uint8_t* volatile readBuffer_;
170 
172  const uint8_t* volatile writeBuffer_;
173 
175  volatile size_t size_;
176 
178  volatile size_t readPosition_;
179 
181  volatile size_t writePosition_;
182 
184  uint16_t dummyData_;
185 
187  bool started_;
188 
190  uint8_t wordLength_;
191 };
192 
193 } // namespace chip
194 
195 } // namespace distortos
196 
197 #endif // SOURCE_CHIP_STM32_PERIPHERALS_SPIV1_INCLUDE_DISTORTOS_CHIP_SPIMASTERLOWLEVELINTERRUPTBASED_HPP_
Definition: SpiMasterBase.hpp:28
bool started_
true if driver is started, false otherwise
Definition: SpiMasterLowLevelInterruptBased.hpp:187
volatile size_t size_
size of transfer (size of readBuffer_ and/or writeBuffer_), bytes
Definition: SpiMasterLowLevelInterruptBased.hpp:175
bool isStarted() const
Definition: SpiMasterLowLevelInterruptBased.hpp:142
SpiMasterLowLevel class header.
bool isTransferInProgress() const
Definition: SpiMasterLowLevelInterruptBased.hpp:151
int start() override
Starts low-level SPI master driver.
Definition: STM32-SPIv1-SpiMasterLowLevelInterruptBased.cpp:84
void startTransfer(devices::SpiMasterBase &spiMasterBase, const void *writeBuffer, void *readBuffer, size_t size) override
Starts asynchronous transfer.
Definition: STM32-SPIv1-SpiMasterLowLevelInterruptBased.cpp:96
volatile size_t writePosition_
current position in writeBuffer_
Definition: SpiMasterLowLevelInterruptBased.hpp:181
SpiMode
Definition: SpiMode.hpp:29
constexpr SpiMasterLowLevelInterruptBased(const SpiPeripheral &spiPeripheral)
SpiMasterLowLevelInterruptBased's constructor.
Definition: SpiMasterLowLevelInterruptBased.hpp:43
void interruptHandler()
Interrupt handler.
Definition: STM32-SPIv1-SpiMasterLowLevelInterruptBased.cpp:47
Definition: SpiMasterLowLevel.hpp:33
const SpiPeripheral & spiPeripheral_
reference to raw SPI peripheral
Definition: SpiMasterLowLevelInterruptBased.hpp:163
SpiPeripheral class is a raw SPI peripheral for SPIv1 in STM32.
Definition: STM32-SPIv1-SpiPeripheral.hpp:24
Top-level namespace of distortos project.
Definition: buttons.hpp:33
volatile size_t readPosition_
current position in readBuffer_
Definition: SpiMasterLowLevelInterruptBased.hpp:178
uint16_t dummyData_
dummy data that will be sent if write buffer of transfer is nullptr
Definition: SpiMasterLowLevelInterruptBased.hpp:184
uint8_t wordLength_
selected word length, bits, {8, 16}
Definition: SpiMasterLowLevelInterruptBased.hpp:190
void stop() override
Stops low-level SPI master driver.
Definition: STM32-SPIv1-SpiMasterLowLevelInterruptBased.cpp:114
~SpiMasterLowLevelInterruptBased() override
SpiMasterLowLevelInterruptBased's destructor.
Definition: STM32-SPIv1-SpiMasterLowLevelInterruptBased.cpp:31
void configure(devices::SpiMode mode, uint32_t clockFrequency, uint8_t wordLength, bool lsbFirst, uint32_t dummyData) override
Configures parameters of low-level SPI master driver.
Definition: STM32-SPIv1-SpiMasterLowLevelInterruptBased.cpp:36
void writeNextItem()
Writes next item to SPI peripheral.
Definition: STM32-SPIv1-SpiMasterLowLevelInterruptBased.cpp:129
Definition: SpiMasterLowLevelInterruptBased.hpp:33
devices::SpiMasterBase *volatile spiMasterBase_
pointer to SpiMasterBase object associated with this one
Definition: SpiMasterLowLevelInterruptBased.hpp:166
uint8_t *volatile readBuffer_
buffer to which the data is being written, nullptr to ignore received data
Definition: SpiMasterLowLevelInterruptBased.hpp:169
const uint8_t *volatile writeBuffer_
buffer with data that is being transmitted, nullptr to send dummy data
Definition: SpiMasterLowLevelInterruptBased.hpp:172