88 lines
1.8 KiB
C++
88 lines
1.8 KiB
C++
#include <cstdint>
|
|
|
|
#include "intc.h"
|
|
#include "interrupts.h"
|
|
#include "pol0.h"
|
|
#include "xuartlite.h"
|
|
|
|
extern "C" {
|
|
void BiosWozmon();
|
|
}
|
|
|
|
namespace {
|
|
|
|
struct Gpio {
|
|
volatile uint32_t data;
|
|
};
|
|
|
|
Gpio* leds = reinterpret_cast<Gpio*>(GPIO0_BASE);
|
|
|
|
XUartLite uart0_inst;
|
|
XUartLite_Config uart0_config = {
|
|
.DeviceId = 0,
|
|
.RegBaseAddr = UART0_BASE,
|
|
.BaudRate = 115200,
|
|
.UseParity = false,
|
|
.DataBits = 8,
|
|
};
|
|
|
|
XUartLite* uart0 = &uart0_inst;
|
|
|
|
volatile int incoming = 0;
|
|
|
|
void HandleUartRxFromIsr(void*, unsigned int) {
|
|
incoming += 1;
|
|
}
|
|
|
|
void HandleUartTxFromIsr(void*, unsigned int) {
|
|
}
|
|
|
|
void Uart0Isr() {
|
|
XUartLite_InterruptHandler(uart0);
|
|
}
|
|
|
|
void InitUarts() {
|
|
XUartLite_CfgInitialize(uart0, &uart0_config, uart0_config.RegBaseAddr);
|
|
|
|
XUartLite_SetSendHandler(uart0, HandleUartTxFromIsr, nullptr);
|
|
XUartLite_SetRecvHandler(uart0, HandleUartRxFromIsr, nullptr);
|
|
XUartLite_EnableInterrupt(uart0);
|
|
|
|
SetIsr(UART0_IRQN, Uart0Isr);
|
|
SetIrqEnabled(UART0_IRQN, true);
|
|
}
|
|
|
|
}
|
|
|
|
int main() {
|
|
leds->data = 0xa0;
|
|
|
|
InitUarts();
|
|
EnableInterrupts();
|
|
SetExternalInterruptHandler(InterruptHandler);
|
|
EnableExternalInterrupts();
|
|
|
|
int counter = 0;
|
|
|
|
uint8_t c;
|
|
while (XUartLite_Recv(uart0, &c, 1) > 0) {
|
|
XUartLite_Send(uart0, &c, 1);
|
|
while (XUartLite_IsSending(uart0)) {}
|
|
}
|
|
leds->data = 0xa1;
|
|
while (1) {
|
|
// should disable interrupts around this
|
|
if (incoming > 0) {
|
|
counter += 1;
|
|
leds->data = counter;
|
|
XUartLite_Send(uart0, &c, 1);
|
|
while (XUartLite_IsSending(uart0)) {}
|
|
while (XUartLite_Recv(uart0, &c, 1) > 0) {
|
|
XUartLite_Send(uart0, &c, 1);
|
|
while (XUartLite_IsSending(uart0)) {}
|
|
}
|
|
incoming -= 1;
|
|
}
|
|
}
|
|
}
|