skullc-peripherals/Utility/Inc/utility_asyncaurtlogger.hpp
Erki faa1685e18
All checks were successful
continuous-integration/drone/push Build is passing
Add async UART logger (running on DMA).
2021-03-21 17:03:06 +02:00

50 lines
926 B
C++

/*
* utility_asyncaurtlogger.hpp
*
* Created on: Mar 20, 2021
* Author: erki
*/
#ifndef SKULLC_UTILITY_ASYNCAURTLOGGER_HPP_
#define SKULLC_UTILITY_ASYNCAURTLOGGER_HPP_
#include "utility_ilogger.hpp"
#include "utility_ringbuffer.hpp"
#include "usart.h"
namespace Utility
{
class AsyncUARTLogger : public ILogger
{
public:
explicit AsyncUARTLogger(UART_HandleTypeDef* huart);
AsyncUARTLogger() = delete;
AsyncUARTLogger(const AsyncUARTLogger&) = delete;
AsyncUARTLogger(AsyncUARTLogger&&) = delete;
void log(const char* format, ...);
private:
struct _Data
{
std::array<char, 255> buffer;
std::int32_t length;
};
Ringbuffer<_Data, 10> _buffer_queue;
UART_HandleTypeDef* _huart;
bool _in_flight = false;
static AsyncUARTLogger* _this;
static void _txCompleteCallback(UART_HandleTypeDef* huart);
void _sendNextLog();
};
}
#endif /* SKULLC_UTILITY_ASYNCAURTLOGGER_HPP_ */