mbv: i really though async would work this time
There's still a glitch/race somewhere.
This commit is contained in:
@@ -11,11 +11,9 @@
|
||||
|
||||
namespace {
|
||||
|
||||
using async::AwaitableType;
|
||||
Timer* timer0;
|
||||
|
||||
void Uart0Isr() {
|
||||
ToggleLed(7);
|
||||
HandleUartIsr();
|
||||
}
|
||||
|
||||
@@ -48,16 +46,23 @@ void SetupInterrupts() {
|
||||
}
|
||||
|
||||
async::task<> echo() {
|
||||
async::task<uint8_t> reader = UartReadLoop();
|
||||
async::task<std::byte> reader = UartReadLoop();
|
||||
async::gimme<std::span<const std::byte>> feeder;
|
||||
async::task<> writer = UartWriteLoop(feeder);
|
||||
writer.h.resume(); // advance to first yield
|
||||
while (1) {
|
||||
SetLed(1);
|
||||
uint8_t c = co_await reader;
|
||||
std::byte c = co_await reader;
|
||||
ClearLed(1);
|
||||
ToggleLed(2);
|
||||
feeder.feed(std::as_bytes(std::span{&c, 1}));
|
||||
co_await feeder.feed(std::span{&c, 1});
|
||||
}
|
||||
}
|
||||
|
||||
async::task<> blink() {
|
||||
while (1) {
|
||||
co_await async::delay(500);
|
||||
ToggleLed(0);
|
||||
timer0->Pet();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,25 +70,19 @@ async::task<> echo() {
|
||||
|
||||
int main() {
|
||||
SetupUart();
|
||||
UartWriteCrash("uart setup done\r\n");
|
||||
UartWriteBlocking("uart setup done\r\n");
|
||||
SetupTimer();
|
||||
UartWriteCrash("timer setup done\r\n");
|
||||
UartWriteBlocking("timer setup done\r\n");
|
||||
|
||||
gpio0->data = 0;
|
||||
SetupInterrupts();
|
||||
|
||||
async::schedule(echo().h);
|
||||
async::schedule(blink().h);
|
||||
|
||||
UartWriteCrash("init done. starting main loop\r\n");
|
||||
UartWriteBlocking("init done. starting main loop\r\n");
|
||||
|
||||
async::main_loop([]() {
|
||||
static int cnt = 0;
|
||||
timer0->Pet();
|
||||
if ((cnt++ % 100000) == 0) {
|
||||
ToggleLed(0);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
async::main_loop(nullptr);
|
||||
// should never get here
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user