diff --git a/arm/main.cc b/arm/main.cc index 815073d..ad2b54f 100644 --- a/arm/main.cc +++ b/arm/main.cc @@ -14,7 +14,8 @@ namespace { using async::AwaitableType; void Uart0Isr() { - tracing::trace(tracing::TraceEvent::kUartIsr); + ToggleLed(7); + //tracing::trace(tracing::TraceEvent::kUartIsr); HandleUartIsr(); } @@ -36,28 +37,73 @@ void SetupTimer() { NVIC_EnableIRQ(Timer0_IRQn); } + +#if 0 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101133 async::task<> echo() { + async::task reader = UartReadLoop(); + async::gimme> feeder; + async::task<> writer = UartWriteLoop(feeder); + writer.h.resume(); // advance to first yield while (1) { - buffer buff = co_await UartRead(1); - co_await UartWrite(buff.data); + SetLed(1); + uint8_t c = co_await reader; + ClearLed(1); + ToggleLed(2); + co_await feeder.feed(std::as_bytes(std::span{&c, 1})); + } +} +#endif + +async::task<> echo() { + async::task reader = UartReadLoop(); + while (1) { + SetLed(1); + uint8_t c = co_await reader; + ClearLed(1); + ToggleLed(2); + co_await UartWrite(std::as_bytes(std::span{&c, 1})); + } +} + +async::task<> dump_trace() { + while (1) { + co_await async::delay(5000); +// tracing::dump(); } } } // namespace +#define XUL_SR_RX_FIFO_FULL 0x02 /* receive FIFO full */ +#define XUL_SR_RX_FIFO_VALID_DATA 0x01 /* data in receive FIFO */ + int main() { _vector_table[16 + HardFault_IRQn] = reinterpret_cast(crash::HardFaultHandler); SetupUart(); + UartWriteBlocking("uart setup done\r\n"); SetupTimer(); + UartWriteBlocking("timer setup done\r\n"); async::schedule(echo().h); + async::schedule(dump_trace().h); + + tracing::trace(tracing::TraceEvent::kUartIsr); + tracing::trace(tracing::TraceEvent::kUartIsr); + + UartWriteBlocking("init done. starting main loop\r\n"); async::main_loop([]() { static int cnt = 0; timer0->Pet(); if ((cnt++ % 100000) == 0) { ToggleLed(0); + ClearLed(7); + ClearLed(2); + ClearLed(3); + ClearLed(4); + + LogStuff(); } return false; }); diff --git a/arm/prog.py b/arm/prog.py index b86d6d5..d15370d 100644 --- a/arm/prog.py +++ b/arm/prog.py @@ -42,6 +42,12 @@ def main(): write(s, offset, dat) jump(s, offset) + while True: + dat = s.read() + if not dat: + break + sys.stdout.buffer.write(dat) + if __name__ == "__main__": main()