| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE.md file. | |
| 4 | |
| 5 #ifndef PLATFORMS_STM_DISCO_FLETCH_SRC_UART_H_ | |
| 6 #define PLATFORMS_STM_DISCO_FLETCH_SRC_UART_H_ | |
| 7 | |
| 8 #include <inttypes.h> | |
| 9 | |
| 10 #include <cmsis_os.h> | |
| 11 #include <stm32f7xx_hal.h> | |
| 12 | |
| 13 #include "platforms/stm/disco_fletch/src/circular_buffer.h" | |
| 14 | |
| 15 // Interface to the universal asynchronous receiver/transmitter | |
| 16 // (UART). | |
| 17 class Uart { | |
| 18 public: | |
| 19 // Access the UART on the first UART port. | |
| 20 Uart(); | |
| 21 | |
| 22 // Start processing the UART. | |
| 23 void Start(); | |
| 24 | |
| 25 // Read up to count bytes from the UART into the buffer starting at | |
| 26 // buffer. | |
| 27 // | |
| 28 // This will block until at least one byte can be read. | |
| 29 size_t Read(uint8_t* buffer, size_t count); | |
| 30 | |
| 31 | |
| 32 // Read up to count bytes from the buffer starting at buffer to the | |
| 33 // UART. | |
| 34 // | |
| 35 // This will block until at least one byte can be written. | |
| 36 size_t Write(const uint8_t* buffer, size_t count); | |
| 37 | |
| 38 private: | |
| 39 static const int kTxBlockSize = 10; | |
| 40 | |
| 41 void Task(); | |
| 42 | |
| 43 void EnsureTransmission(); | |
| 44 | |
| 45 UART_HandleTypeDef* uart_; | |
| 46 int error_count_; | |
| 47 osSemaphoreDef(semaphore_def_); | |
| 48 osSemaphoreId(semaphore_); | |
| 49 | |
| 50 // Receive status. | |
| 51 uint8_t rx_data_; // The one byte received at the time. | |
| 52 CircularBuffer* rx_buffer_; | |
| 53 | |
| 54 // Transmit status. | |
| 55 fletch::Mutex* tx_mutex_; | |
| 56 uint8_t tx_data_[kTxBlockSize]; // Buffer send to the HAL. | |
| 57 bool tx_pending_; | |
| 58 CircularBuffer* tx_buffer_; | |
| 59 | |
| 60 friend void __UartTask(const void*); | |
| 61 }; | |
| 62 | |
| 63 #endif // PLATFORMS_STM_DISCO_FLETCH_SRC_UART_H_ | |
| OLD | NEW |