synth/arm/main.cc

66 lines
1.3 KiB
C++
Raw Normal View History

2022-05-17 03:56:25 +00:00
#include "async.h"
#include "aum1_cm1.h"
#include "buffer.h"
#include "crash.h"
#include "gpio.h"
2022-05-17 03:56:25 +00:00
#include "timer.h"
#include "trace.h"
#include "uart.h"
#include "uart_async.h"
2022-05-08 06:00:22 +00:00
2022-05-09 03:55:58 +00:00
namespace {
2022-05-17 03:56:25 +00:00
using async::AwaitableType;
2022-05-08 06:00:22 +00:00
2022-05-17 03:56:25 +00:00
void Uart0Isr() {
tracing::trace(tracing::TraceEvent::kUartIsr);
2022-05-17 17:17:56 +00:00
HandleUartIsr();
2022-05-17 03:56:25 +00:00
}
void Timer0Isr() {
tracing::dump();
__builtin_trap();
}
void SetupUart() {
InitUarts();
auto* vector_table = reinterpret_cast<uint32_t*>(0x0);
vector_table[16 + HardFault_IRQn] =
reinterpret_cast<uint32_t>(crash::HardFaultHandler);
vector_table[16 + Uart0_IRQn] = reinterpret_cast<uint32_t>(Uart0Isr);
vector_table[16 + Timer0_IRQn] = reinterpret_cast<uint32_t>(Timer0Isr);
NVIC_SetPriority(Uart0_IRQn, 3);
NVIC_EnableIRQ(Uart0_IRQn);
}
2022-05-09 03:55:58 +00:00
2022-05-17 03:56:25 +00:00
void SetupTimer() {
NVIC_EnableIRQ(Timer0_IRQn);
timer0->SetupAsWdt(100000 * 4000);
timer0->EnableT1();
}
2022-05-09 03:55:58 +00:00
2022-05-17 03:56:25 +00:00
async::task<> echo() {
while (1) {
buffer buff = co_await UartRead(1);
2022-05-17 17:17:56 +00:00
co_await UartWrite(buff.data);
2022-05-17 03:56:25 +00:00
}
}
} // namespace
2022-05-17 03:56:25 +00:00
int main() {
SetupUart();
SetupTimer();
2022-05-17 03:56:25 +00:00
async::schedule(echo().h);
async::main_loop([]() {
static int cnt = 0;
timer0->Pet();
if ((cnt++ % 100000) == 0) {
ToggleLed(0);
}
});
// should never get here
}