#include #include "xuartlite.h" struct Gpio { volatile uint32_t data; }; #define gpio0 ((Gpio*) 0x40000000) namespace { 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(""); } } } } // 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); } } }