distortos  v0.4.0
object-oriented C++ RTOS for microcontrollers
ChipSpiMasterLowLevel.hpp
Go to the documentation of this file.
1 
12 #ifndef SOURCE_CHIP_STM32_PERIPHERALS_SPIV1_INCLUDE_DISTORTOS_CHIP_CHIPSPIMASTERLOWLEVEL_HPP_
13 #define SOURCE_CHIP_STM32_PERIPHERALS_SPIV1_INCLUDE_DISTORTOS_CHIP_CHIPSPIMASTERLOWLEVEL_HPP_
14 
17 
19 
20 namespace distortos
21 {
22 
23 namespace chip
24 {
25 
33 {
34 public:
35 
36  class Parameters;
37 
38 #ifdef CONFIG_CHIP_STM32_SPIV1_SPI1_ENABLE
39 
41  static const Parameters spi1Parameters;
42 
43 #endif // def CONFIG_CHIP_STM32_SPIV1_SPI1_ENABLE
44 
45 #ifdef CONFIG_CHIP_STM32_SPIV1_SPI2_ENABLE
46 
48  static const Parameters spi2Parameters;
49 
50 #endif // def CONFIG_CHIP_STM32_SPIV1_SPI2_ENABLE
51 
52 #ifdef CONFIG_CHIP_STM32_SPIV1_SPI3_ENABLE
53 
55  static const Parameters spi3Parameters;
56 
57 #endif // def CONFIG_CHIP_STM32_SPIV1_SPI3_ENABLE
58 
59 #ifdef CONFIG_CHIP_STM32_SPIV1_SPI4_ENABLE
60 
62  static const Parameters spi4Parameters;
63 
64 #endif // def CONFIG_CHIP_STM32_SPIV1_SPI4_ENABLE
65 
66 #ifdef CONFIG_CHIP_STM32_SPIV1_SPI5_ENABLE
67 
69  static const Parameters spi5Parameters;
70 
71 #endif // def CONFIG_CHIP_STM32_SPIV1_SPI5_ENABLE
72 
73 #ifdef CONFIG_CHIP_STM32_SPIV1_SPI6_ENABLE
74 
76  static const Parameters spi6Parameters;
77 
78 #endif // def CONFIG_CHIP_STM32_SPIV1_SPI6_ENABLE
79 
86  constexpr explicit ChipSpiMasterLowLevel(const Parameters& parameters) :
87  parameters_{parameters},
89  readBuffer_{},
90  writeBuffer_{},
91  size_{},
92  readPosition_{},
94  errorSet_{}
95  {
96 
97  }
98 
105  ~ChipSpiMasterLowLevel() override;
106 
121  std::pair<int, uint32_t> configure(devices::SpiMode mode, uint32_t clockFrequency, uint8_t wordLength,
122  bool lsbFirst) override;
123 
140  void interruptHandler();
141 
151  int start(devices::SpiMasterBase& spiMasterBase) override;
152 
171  int startTransfer(const void* writeBuffer, void* readBuffer, size_t size) override;
172 
181  int stop() override;
182 
183 private:
184 
189  bool isStarted() const
190  {
191  return spiMasterBase_ != nullptr;
192  }
193 
198  bool isTransferInProgress() const
199  {
200  return size_ != 0;
201  }
202 
205 
208 
210  uint8_t* volatile readBuffer_;
211 
213  const uint8_t* volatile writeBuffer_;
214 
216  volatile size_t size_;
217 
219  volatile size_t readPosition_;
220 
222  volatile size_t writePosition_;
223 
226 };
227 
228 } // namespace chip
229 
230 } // namespace distortos
231 
232 #endif // SOURCE_CHIP_STM32_PERIPHERALS_SPIV1_INCLUDE_DISTORTOS_CHIP_CHIPSPIMASTERLOWLEVEL_HPP_
std::pair< int, uint32_t > configure(devices::SpiMode mode, uint32_t clockFrequency, uint8_t wordLength, bool lsbFirst) override
Configures parameters of low-level SPI master driver.
Definition: STM32-SPIv1-ChipSpiMasterLowLevel.cpp:237
Definition: SpiMasterBase.hpp:32
parameters for construction of SPI master low-level drivers
Definition: STM32-SPIv1-ChipSpiMasterLowLevel.cpp:32
SpiMasterLowLevel class header.
SpiMasterErrorSet class header.
uint8_t *volatile readBuffer_
buffer to which the data is being written, nullptr to ignore received data
Definition: ChipSpiMasterLowLevel.hpp:210
~ChipSpiMasterLowLevel() override
SpiMasterLowLevel&#39;s destructor.
Definition: STM32-SPIv1-ChipSpiMasterLowLevel.cpp:228
const uint8_t *volatile writeBuffer_
buffer with data that is being transmitted, nullptr to send dummy data
Definition: ChipSpiMasterLowLevel.hpp:213
devices::SpiMasterBase * spiMasterBase_
pointer to SpiMasterBase object associated with this one
Definition: ChipSpiMasterLowLevel.hpp:207
int startTransfer(const void *writeBuffer, void *readBuffer, size_t size) override
Starts asynchronous transfer.
Definition: STM32-SPIv1-ChipSpiMasterLowLevel.cpp:379
volatile size_t writePosition_
current position in writeBuffer_
Definition: ChipSpiMasterLowLevel.hpp:222
const Parameters & parameters_
reference to configuration parameters
Definition: ChipSpiMasterLowLevel.hpp:204
int start(devices::SpiMasterBase &spiMasterBase) override
Starts low-level SPI master driver.
Definition: STM32-SPIv1-ChipSpiMasterLowLevel.cpp:366
bool isTransferInProgress() const
Definition: ChipSpiMasterLowLevel.hpp:198
devices::SpiMasterErrorSet errorSet_
current set of detected errors
Definition: ChipSpiMasterLowLevel.hpp:225
SpiMode
Definition: SpiMode.hpp:29
Definition: SpiMasterLowLevel.hpp:35
Definition: SpiMasterErrorSet.hpp:29
distortos configuration
Top-level namespace of distortos project.
void interruptHandler()
Interrupt handler.
Definition: STM32-SPIv1-ChipSpiMasterLowLevel.cpp:273
volatile size_t readPosition_
current position in readBuffer_
Definition: ChipSpiMasterLowLevel.hpp:219
constexpr ChipSpiMasterLowLevel(const Parameters &parameters)
ChipSpiMasterLowLevel&#39;s constructor.
Definition: ChipSpiMasterLowLevel.hpp:86
Definition: ChipSpiMasterLowLevel.hpp:32
int stop() override
Stops low-level SPI master driver.
Definition: STM32-SPIv1-ChipSpiMasterLowLevel.cpp:405
volatile size_t size_
size of transfer (size of readBuffer_ and/or writeBuffer_), bytes
Definition: ChipSpiMasterLowLevel.hpp:216
bool isStarted() const
Definition: ChipSpiMasterLowLevel.hpp:189