distortos  v0.7.0
object-oriented C++ RTOS for microcontrollers
DmaChannel.hpp
Go to the documentation of this file.
1 
12 #ifndef SOURCE_CHIP_STM32_PERIPHERALS_DMAV2_INCLUDE_DISTORTOS_CHIP_DMACHANNEL_HPP_
13 #define SOURCE_CHIP_STM32_PERIPHERALS_DMAV2_INCLUDE_DISTORTOS_CHIP_DMACHANNEL_HPP_
14 
15 #include "distortos/assert.h"
16 
17 #include "estd/EnumClassFlags.hpp"
18 
19 #include <utility>
20 
21 #include <cerrno>
22 #include <cstddef>
23 #include <cstdint>
24 
25 namespace distortos
26 {
27 
28 namespace chip
29 {
30 
32 enum class DmaChannelFlags : uint32_t
33 {
38 
40  dmaFlowController = 0 << 5,
42  peripheralFlowController = 1 << 5,
43 
45  peripheralToMemory = 0 << 6,
47  memoryToPeripheral = 1 << 6,
48 
50  peripheralFixed = 0 << 9,
52  peripheralIncrement = 1 << 9,
53 
55  memoryFixed = 0 << 10,
57  memoryIncrement = 1 << 10,
58 
60  peripheralDataSize1 = 0 << 11,
62  peripheralDataSize2 = 1 << 11,
64  peripheralDataSize4 = 2 << 11,
65 
67  memoryDataSize1 = 0 << 13,
69  memoryDataSize2 = 1 << 13,
71  memoryDataSize4 = 2 << 13,
72 
74  lowPriority = 0 << 16,
76  mediumPriority = 1 << 16,
78  highPriority = 2 << 16,
80  veryHighPriority = 3 << 16,
81 
83  peripheralBurstSize1 = 0 << 21,
85  peripheralBurstSize4 = 1 << 21,
87  peripheralBurstSize8 = 2 << 21,
89  peripheralBurstSize16 = 3 << 21,
90 
92  memoryBurstSize1 = 0 << 23,
94  memoryBurstSize4 = 1 << 23,
96  memoryBurstSize8 = 2 << 23,
98  memoryBurstSize16 = 3 << 23,
99 
106 
115 };
116 
117 } // namespace chip
118 
119 } // namespace distortos
120 
121 namespace estd
122 {
123 
125 template<>
127 {
128 
129 };
130 
131 } // namespace estd
132 
133 namespace distortos
134 {
135 
136 namespace chip
137 {
138 
139 class DmaChannelFunctor;
140 class DmaChannelPeripheral;
141 class DmaPeripheral;
142 
150 {
151  friend class DmaChannelHandle;
152 
153 public:
154 
157 
165  constexpr DmaChannel(const DmaPeripheral& dmaPeripheral, const DmaChannelPeripheral& dmaChannelPeripheral) :
166  dmaPeripheral_{dmaPeripheral},
167  dmaChannelPeripheral_{dmaChannelPeripheral},
168  functor_{},
169  request_{}
170  {
171 
172  }
173 
181  {
182  assert(functor_ == nullptr);
183  }
184 
193  void interruptHandler();
194 
195 private:
196 
201  size_t getTransactionsLeft() const;
202 
211  void release();
212 
226  int reserve(uint8_t request, DmaChannelFunctor& functor);
227 
249  void startTransfer(uintptr_t memoryAddress, uintptr_t peripheralAddress, size_t transactions, Flags flags) const;
250 
262  void stopTransfer() const;
263 
266 
269 
272 
274  uint8_t request_;
275 };
276 
277 } // namespace chip
278 
279 } // namespace distortos
280 
281 #endif // SOURCE_CHIP_STM32_PERIPHERALS_DMAV2_INCLUDE_DISTORTOS_CHIP_DMACHANNEL_HPP_
Collection of useful templates.
Definition: DmaChannel.hpp:121
size_t getTransactionsLeft() const
Definition: STM32-DMAv2-DmaChannel.cpp:217
memory burst size - single transfer
DmaChannelFlags
DMA transfer configuration flags.
Definition: DmaChannel.hpp:32
DmaChannelFlags Flags
import DmaChannelFlags
Definition: DmaChannel.hpp:156
Tag struct used to enable bitwise operators for selected enum class flags.
Definition: EnumClassFlags.hpp:30
memory and peripheral data size - 1 byte
uint8_t request_
request identifier with which this object is associated
Definition: DmaChannel.hpp:274
memory burst size - incremental burst of 16 beats
Definition: DmaChannel.hpp:149
memory and peripheral data size - 4 bytes
peripheral address is incremented after each transaction
peripheral burst size - single transfer
DmaChannelPeripheral class is a raw DMA channel peripheral for DMAv2 in STM32.
Definition: STM32-DMAv2-DmaChannelPeripheral.hpp:24
DmaChannelFunctor * functor_
pointer to DmaChannelFunctor object associated with this one
Definition: DmaChannel.hpp:271
assert() macro
memory and peripheral burst size - incremental burst of 16 beats
DmaPeripheral class is a raw DMA peripheral for DMAv2 in STM32.
Definition: STM32-DMAv2-DmaPeripheral.hpp:24
memory burst size - incremental burst of 8 beats
Definition: DmaChannelHandle.hpp:29
Top-level namespace of distortos project.
Definition: buttons.hpp:33
memory address is incremented after each transaction
const DmaChannelPeripheral & dmaChannelPeripheral_
reference to raw DMA channel peripheral
Definition: DmaChannel.hpp:268
void stopTransfer() const
Stops transfer.
Definition: STM32-DMAv2-DmaChannel.cpp:295
~DmaChannel()
DmaChannel's destructor.
Definition: DmaChannel.hpp:180
Definition: DmaChannelFunctor.hpp:29
memory and peripheral burst size - incremental burst of 8 beats
memory and peripheral burst size - incremental burst of 4 beats
constexpr DmaChannel(const DmaPeripheral &dmaPeripheral, const DmaChannelPeripheral &dmaChannelPeripheral)
DmaChannel's constructor.
Definition: DmaChannel.hpp:165
peripheral burst size - incremental burst of 8 beats
Header with templated bitwise operators for enum class flags.
peripheral burst size - incremental burst of 4 beats
memory and peripheral data size - 2 bytes
memory and peripheral burst size - single transfer
peripheral burst size - incremental burst of 16 beats
void release()
Releases low-level DMA channel driver.
Definition: STM32-DMAv2-DmaChannel.cpp:222
const DmaPeripheral & dmaPeripheral_
reference to raw DMA peripheral
Definition: DmaChannel.hpp:265
memory burst size - incremental burst of 4 beats
int reserve(uint8_t request, DmaChannelFunctor &functor)
Reserves low-level DMA channel driver for exclusive use.
Definition: STM32-DMAv2-DmaChannel.cpp:228
void startTransfer(uintptr_t memoryAddress, uintptr_t peripheralAddress, size_t transactions, Flags flags) const
Configures and starts asynchronous transfer.
Definition: STM32-DMAv2-DmaChannel.cpp:243
void interruptHandler()
Interrupt handler.
Definition: STM32-DMAv2-DmaChannel.cpp:189