synth/arm/main.cc

55 lines
1.0 KiB
C++
Raw Normal View History

2022-05-08 06:00:22 +00:00
#include <cstdint>
2022-05-09 03:55:58 +00:00
#include "xuartlite.h"
2022-05-08 06:00:22 +00:00
struct Gpio {
volatile uint32_t data;
};
#define gpio0 ((Gpio*) 0x40000000)
2022-05-09 03:55:58 +00:00
namespace {
2022-05-08 06:00:22 +00:00
2022-05-09 03:55:58 +00:00
constexpr uintptr_t kUart0BaseAddress = 0x40001000;
XUartLite uart0;
XUartLite_Config uart0_config = {
.DeviceId = 0,
.RegBaseAddr = kUart0BaseAddress,
.BaudRate = 115200,
.UseParity = false,
.DataBits = 8,
};
[[maybe_unused]]
void sleep(int ms) {
for (int i = 0; i < ms; i++) {
// sleep for 1 ms
for (int j = 0; j < 50000; j++) {
asm("");
}
}
2022-05-08 06:00:22 +00:00
}
2022-05-09 03:55:58 +00:00
} // namespace
int main() {
int recv = 0;
gpio0->data = 37;
XUartLite_CfgInitialize(&uart0, &uart0_config, uart0_config.RegBaseAddr);
while (true) {
uint8_t c;
int received_bytes = XUartLite_Recv(&uart0, &c, 1);
if (received_bytes < 1) {
continue;
}
recv++;
gpio0->data = recv & 0xff;
XUartLite_Send(&uart0, &c, 1);
if (c == '\r') {
c = '\n';
XUartLite_Send(&uart0, &c, 1);
}
}
}