From 8d81f4f9c4f4395809fa2a54e6999651c65696f6 Mon Sep 17 00:00:00 2001 From: Paul Mathieu Date: Tue, 17 May 2022 21:27:47 -0700 Subject: [PATCH] arm: separate async stuff from main uart --- arm/main.cc | 3 ++- arm/uart.cc | 1 + arm/uart.h | 9 --------- arm/uart_async.h | 13 +++++++++++++ 4 files changed, 16 insertions(+), 10 deletions(-) create mode 100644 arm/uart_async.h diff --git a/arm/main.cc b/arm/main.cc index abeadd0..bd3332a 100644 --- a/arm/main.cc +++ b/arm/main.cc @@ -6,6 +6,7 @@ #include "timer.h" #include "trace.h" #include "uart.h" +#include "uart_async.h" namespace { using async::AwaitableType; @@ -38,7 +39,6 @@ void SetupTimer() { timer0->SetupAsWdt(100000 * 4000); timer0->EnableT1(); } -} // namespace async::task<> echo() { while (1) { @@ -46,6 +46,7 @@ async::task<> echo() { co_await UartWrite(buff.data); } } +} // namespace int main() { SetupUart(); diff --git a/arm/uart.cc b/arm/uart.cc index cab5a07..123e75f 100644 --- a/arm/uart.cc +++ b/arm/uart.cc @@ -1,4 +1,5 @@ #include "uart.h" +#include "uart_async.h" #include "async.h" #include "gpio.h" diff --git a/arm/uart.h b/arm/uart.h index 7021b71..affd6ed 100644 --- a/arm/uart.h +++ b/arm/uart.h @@ -3,17 +3,8 @@ #include #include -#include "async.h" -#include "buffer.h" - void InitUarts(); -async::task UartRead(int size); -async::task<> UartWrite(std::span data); -inline async::task<> UartWrite(std::string_view s) { - co_await UartWrite(std::as_bytes(std::span{s.data(), s.size()})); -} - // block until the provided buffer is full void UartReadBlocking(std::span data); inline uint8_t UartReadByteBlocking() { diff --git a/arm/uart_async.h b/arm/uart_async.h new file mode 100644 index 0000000..44d0937 --- /dev/null +++ b/arm/uart_async.h @@ -0,0 +1,13 @@ +#pragma once + +#include +#include + +#include "async.h" +#include "buffer.h" + +async::task UartRead(int size); +async::task<> UartWrite(std::span data); +inline async::task<> UartWrite(std::string_view s) { + co_await UartWrite(std::as_bytes(std::span{s.data(), s.size()})); +}