distortos  v0.4.0
object-oriented C++ RTOS for microcontrollers
ChipUartLowLevel.hpp
Go to the documentation of this file.
1 
12 #ifndef SOURCE_CHIP_STM32_PERIPHERALS_USARTV1_INCLUDE_DISTORTOS_CHIP_CHIPUARTLOWLEVEL_HPP_
13 #define SOURCE_CHIP_STM32_PERIPHERALS_USARTV1_INCLUDE_DISTORTOS_CHIP_CHIPUARTLOWLEVEL_HPP_
14 
16 
18 
19 namespace distortos
20 {
21 
22 namespace chip
23 {
24 
32 {
33 public:
34 
36  constexpr static uint8_t minCharacterLength {7};
37 
39  constexpr static uint8_t maxCharacterLength {9};
40 
41  class Parameters;
42 
43 #ifdef CONFIG_CHIP_STM32_USARTV1_USART1_ENABLE
44 
46  static const Parameters usart1Parameters;
47 
48 #endif // def CONFIG_CHIP_STM32_USARTV1_USART1_ENABLE
49 
50 #ifdef CONFIG_CHIP_STM32_USARTV1_USART2_ENABLE
51 
53  static const Parameters usart2Parameters;
54 
55 #endif // def CONFIG_CHIP_STM32_USARTV1_USART2_ENABLE
56 
57 #ifdef CONFIG_CHIP_STM32_USARTV1_USART3_ENABLE
58 
60  static const Parameters usart3Parameters;
61 
62 #endif // def CONFIG_CHIP_STM32_USARTV1_USART3_ENABLE
63 
64 #ifdef CONFIG_CHIP_STM32_USARTV1_UART4_ENABLE
65 
67  static const Parameters uart4Parameters;
68 
69 #endif // def CONFIG_CHIP_STM32_USARTV1_UART4_ENABLE
70 
71 #ifdef CONFIG_CHIP_STM32_USARTV1_UART5_ENABLE
72 
74  static const Parameters uart5Parameters;
75 
76 #endif // def CONFIG_CHIP_STM32_USARTV1_UART5_ENABLE
77 
78 #ifdef CONFIG_CHIP_STM32_USARTV1_USART6_ENABLE
79 
81  static const Parameters usart6Parameters;
82 
83 #endif // def CONFIG_CHIP_STM32_USARTV1_USART6_ENABLE
84 
85 #ifdef CONFIG_CHIP_STM32_USARTV1_UART7_ENABLE
86 
88  static const Parameters uart7Parameters;
89 
90 #endif // def CONFIG_CHIP_STM32_USARTV1_UART7_ENABLE
91 
92 #ifdef CONFIG_CHIP_STM32_USARTV1_UART8_ENABLE
93 
95  static const Parameters uart8Parameters;
96 
97 #endif // def CONFIG_CHIP_STM32_USARTV1_UART8_ENABLE
98 
99 #ifdef CONFIG_CHIP_STM32_USARTV1_UART9_ENABLE
100 
102  static const Parameters uart9Parameters;
103 
104 #endif // def CONFIG_CHIP_STM32_USARTV1_UART9_ENABLE
105 
106 #ifdef CONFIG_CHIP_STM32_USARTV1_UART10_ENABLE
107 
109  static const Parameters uart10Parameters;
110 
111 #endif // def CONFIG_CHIP_STM32_USARTV1_UART10_ENABLE
112 
119  constexpr explicit ChipUartLowLevel(const Parameters& parameters) :
120  parameters_{parameters},
121  uartBase_{},
122  readBuffer_{},
123  readSize_{},
124  readPosition_{},
125  writeBuffer_{},
126  writeSize_{},
128  {
129 
130  }
131 
138  ~ChipUartLowLevel() override;
139 
146  void interruptHandler();
147 
166  std::pair<int, uint32_t> start(devices::UartBase& uartBase, uint32_t baudRate, uint8_t characterLength,
167  devices::UartParity parity, bool _2StopBits) override;
168 
187  int startRead(void* buffer, size_t size) override;
188 
206  int startWrite(const void* buffer, size_t size) override;
207 
216  int stop() override;
217 
226  size_t stopRead() override;
227 
237  size_t stopWrite() override;
238 
239 private:
240 
245  bool isStarted() const
246  {
247  return uartBase_ != nullptr;
248  }
249 
254  bool isReadInProgress() const
255  {
256  return readBuffer_ != nullptr;
257  }
258 
263  bool isWriteInProgress() const
264  {
265  return writeBuffer_ != nullptr;
266  }
267 
270 
273 
275  uint8_t* volatile readBuffer_;
276 
278  volatile size_t readSize_;
279 
281  volatile size_t readPosition_;
282 
284  const uint8_t* volatile writeBuffer_;
285 
287  volatile size_t writeSize_;
288 
290  volatile size_t writePosition_;
291 };
292 
293 } // namespace chip
294 
295 } // namespace distortos
296 
297 #endif // SOURCE_CHIP_STM32_PERIPHERALS_USARTV1_INCLUDE_DISTORTOS_CHIP_CHIPUARTLOWLEVEL_HPP_
uint8_t *volatile readBuffer_
buffer to which the data is being written
Definition: ChipUartLowLevel.hpp:275
size_t stopRead() override
Stops asynchronous read operation.
Definition: STM32-USARTv1-ChipUartLowLevel.cpp:424
size_t stopWrite() override
Stops asynchronous write operation.
Definition: STM32-USARTv1-ChipUartLowLevel.cpp:437
bool isReadInProgress() const
Definition: ChipUartLowLevel.hpp:254
devices::UartBase * uartBase_
pointer to UartBase object associated with this one
Definition: ChipUartLowLevel.hpp:272
parameters for construction of UART low-level drivers
Definition: STM32-USARTv1-ChipUartLowLevel.cpp:59
constexpr ChipUartLowLevel(const Parameters &parameters)
ChipUartLowLevel&#39;s constructor.
Definition: ChipUartLowLevel.hpp:119
~ChipUartLowLevel() override
ChipUartLowLevel&#39;s destructor.
Definition: STM32-USARTv1-ChipUartLowLevel.cpp:271
UartLowLevel class header.
const uint8_t *volatile writeBuffer_
buffer with data that is being transmitted
Definition: ChipUartLowLevel.hpp:284
volatile size_t readSize_
size of readBuffer_, bytes
Definition: ChipUartLowLevel.hpp:278
Definition: UartBase.hpp:30
distortos configuration
const Parameters & parameters_
reference to configuration parameters
Definition: ChipUartLowLevel.hpp:269
Top-level namespace of distortos project.
int startWrite(const void *buffer, size_t size) override
Starts asynchronous write operation.
Definition: STM32-USARTv1-ChipUartLowLevel.cpp:384
volatile size_t writeSize_
size of writeBuffer_, bytes
Definition: ChipUartLowLevel.hpp:287
UartParity
Definition: UartParity.hpp:29
static constexpr uint8_t maxCharacterLength
maximum allowed value for UART character length
Definition: ChipUartLowLevel.hpp:39
Definition: UartLowLevel.hpp:35
Definition: ChipUartLowLevel.hpp:31
int stop() override
Stops low-level UART driver.
Definition: STM32-USARTv1-ChipUartLowLevel.cpp:410
volatile size_t readPosition_
current position in readBuffer_
Definition: ChipUartLowLevel.hpp:281
static constexpr uint8_t minCharacterLength
minimum allowed value for UART character length
Definition: ChipUartLowLevel.hpp:36
int startRead(void *buffer, size_t size) override
Starts asynchronous read operation.
Definition: STM32-USARTv1-ChipUartLowLevel.cpp:363
void interruptHandler()
Interrupt handler.
Definition: STM32-USARTv1-ChipUartLowLevel.cpp:280
volatile size_t writePosition_
current position in writeBuffer_
Definition: ChipUartLowLevel.hpp:290
std::pair< int, uint32_t > start(devices::UartBase &uartBase, uint32_t baudRate, uint8_t characterLength, devices::UartParity parity, bool _2StopBits) override
Starts low-level UART driver.
Definition: STM32-USARTv1-ChipUartLowLevel.cpp:323
bool isStarted() const
Definition: ChipUartLowLevel.hpp:245
bool isWriteInProgress() const
Definition: ChipUartLowLevel.hpp:263