63 lines
1.2 KiB
C++
63 lines
1.2 KiB
C++
#include <cstdint>
|
|
|
|
#include "gpio.h"
|
|
#include "uart.h"
|
|
|
|
namespace {
|
|
|
|
uint8_t UartRead() {
|
|
uint8_t c;
|
|
while (XUartLite_Recv(uart0, &c, 1) < 1) {
|
|
}
|
|
return c;
|
|
}
|
|
|
|
void UartWrite(uint8_t c) { XUartLite_Send(uart0, &c, 1); }
|
|
|
|
uint32_t UartRead32() {
|
|
uint32_t val = 0;
|
|
|
|
// little endian
|
|
val |= (UartRead() << 0);
|
|
val |= (UartRead() << 8);
|
|
val |= (UartRead() << 16);
|
|
val |= (UartRead() << 24);
|
|
|
|
return val;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
int main() {
|
|
gpio0->data = 1;
|
|
|
|
InitUarts();
|
|
|
|
while (1) {
|
|
uint8_t c = UartRead();
|
|
if (c == 'c') {
|
|
uint32_t addr = UartRead32();
|
|
uint32_t bytes = UartRead32();
|
|
|
|
uint8_t* start = reinterpret_cast<uint8_t*>(addr);
|
|
uint8_t* end = reinterpret_cast<uint8_t*>(addr + bytes);
|
|
for (uint8_t* ptr = start; ptr < end; ptr++) {
|
|
*ptr = UartRead();
|
|
}
|
|
|
|
UartWrite('a');
|
|
UartWrite(bytes);
|
|
gpio0->data = 0xf0;
|
|
} else if (c == 'j') {
|
|
uint32_t addr = UartRead32();
|
|
|
|
gpio0->data = 0x55;
|
|
|
|
addr |= 0x0001;
|
|
|
|
auto jump = reinterpret_cast<void (*)()>(addr);
|
|
jump();
|
|
}
|
|
}
|
|
}
|