arm: add host uart driver tests
All host tests currently pass Some async refactors may not work well on device, will try later
This commit is contained in:
55
arm/async.h
55
arm/async.h
@@ -1,19 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <coroutine>
|
||||
#include <chrono>
|
||||
#include <utility>
|
||||
|
||||
#include "trace.h"
|
||||
|
||||
#ifdef __clang__
|
||||
#include <experimental/coroutine>
|
||||
namespace std {
|
||||
using namespace experimental;
|
||||
}
|
||||
#else // __clang__
|
||||
#include <coroutine>
|
||||
#endif // __clang__
|
||||
|
||||
namespace async {
|
||||
|
||||
struct task_final_suspend {
|
||||
@@ -23,6 +14,11 @@ struct task_final_suspend {
|
||||
TRACE(tracing::TraceEvent::kAsyncCallParent);
|
||||
parent();
|
||||
TRACE(tracing::TraceEvent::kAsyncCallParentDone);
|
||||
|
||||
if (parent && parent.done()) {
|
||||
TRACE(tracing::TraceEvent::kAsyncDestroy);
|
||||
parent.destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
void await_resume() noexcept(true) {}
|
||||
@@ -30,6 +26,7 @@ struct task_final_suspend {
|
||||
std::coroutine_handle<> parent;
|
||||
};
|
||||
|
||||
#if 0
|
||||
template <typename T>
|
||||
struct gimme {
|
||||
// child interface
|
||||
@@ -87,6 +84,40 @@ struct gimme {
|
||||
T stuff;
|
||||
std::coroutine_handle<> parent;
|
||||
};
|
||||
#else
|
||||
|
||||
template <typename T>
|
||||
struct gimme {
|
||||
// child interface
|
||||
bool await_ready() { return false; }
|
||||
void await_suspend(std::coroutine_handle<> h) {
|
||||
ha = h;
|
||||
waiting = true;
|
||||
TRACE(tracing::TraceEvent::kAsyncGimmeWaiting);
|
||||
}
|
||||
T await_resume() {
|
||||
waiting = false;
|
||||
TRACE(tracing::TraceEvent::kAsyncGimmeResume);
|
||||
return std::move(stuff);
|
||||
}
|
||||
|
||||
// parent interface
|
||||
void feed(T&& s) {
|
||||
if (!waiting) {
|
||||
__builtin_trap();
|
||||
}
|
||||
if (!ha) {
|
||||
__builtin_trap();
|
||||
}
|
||||
stuff = s;
|
||||
ha.resume();
|
||||
}
|
||||
|
||||
bool waiting = false;
|
||||
std::coroutine_handle<> ha;
|
||||
T stuff;
|
||||
};
|
||||
#endif
|
||||
|
||||
template <typename T = void>
|
||||
struct task;
|
||||
@@ -117,7 +148,8 @@ struct task<void> {
|
||||
TRACE(tracing::TraceEvent::kAsyncCoAwait);
|
||||
h();
|
||||
if (h.done()) {
|
||||
TRACE(tracing::TraceEvent::kAsyncDestroy); h.destroy();
|
||||
TRACE(tracing::TraceEvent::kAsyncDestroy);
|
||||
h.destroy();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -206,6 +238,7 @@ void enqueue(std::coroutine_handle<> h, AwaitableType type);
|
||||
void resume(AwaitableType type); // typically called from an ISR
|
||||
|
||||
void main_loop(bool (*idle_function)());
|
||||
void step();
|
||||
|
||||
inline auto await(AwaitableType type) {
|
||||
struct awaitable {
|
||||
|
||||
Reference in New Issue
Block a user