arm: async uart writes & fixes

This commit is contained in:
2022-05-17 10:17:56 -07:00
parent e9f623e754
commit e39cdc5709
13 changed files with 232 additions and 190 deletions

View File

@@ -10,14 +10,9 @@
namespace {
using async::AwaitableType;
void HandleUartRxFromIsr(void*, unsigned int) {
tracing::trace(tracing::TraceEvent::kUartRxCb);
async::resume(AwaitableType::kUartRx);
}
void Uart0Isr() {
tracing::trace(tracing::TraceEvent::kUartIsr);
XUartLite_InterruptHandler(uart0);
HandleUartIsr();
}
void Timer0Isr() {
@@ -36,10 +31,6 @@ void SetupUart() {
vector_table[16 + Timer0_IRQn] = reinterpret_cast<uint32_t>(Timer0Isr);
NVIC_SetPriority(Uart0_IRQn, 3);
NVIC_EnableIRQ(Uart0_IRQn);
XUartLite_SetSendHandler(uart0, HandleUartTxFromIsr, nullptr);
XUartLite_SetRecvHandler(uart0, HandleUartRxFromIsr, nullptr);
XUartLite_EnableInterrupt(uart0);
}
void SetupTimer() {
@@ -49,20 +40,10 @@ void SetupTimer() {
}
} // namespace
async::task<buffer> UartRead(int size) {
auto buff = buffer::make(size);
auto* data = reinterpret_cast<uint8_t*>(buff.data.data());
size_t received = XUartLite_Recv(uart0, data, buff.data.size());
if (received < buff.data.size()) {
co_await async::await(AwaitableType::kUartRx);
}
co_return buff;
}
async::task<> echo() {
while (1) {
buffer buff = co_await UartRead(1);
UartSend(buff.data);
co_await UartWrite(buff.data);
}
}