mbv: minor cleanup
This commit is contained in:
parent
73edb77577
commit
af768cbb09
@ -6,10 +6,6 @@ bootloader: ## Build the bootloader in docker
|
||||
helloworld: ## Build the helloworld app in docker
|
||||
docker build -o . --target export --build-arg TARGET=helloworld.bin .
|
||||
|
||||
.PHONY: wozmon
|
||||
wozmon: ## Build the wozmon app in docker
|
||||
docker build -o . --target export --build-arg TARGET=wozmon.bin .
|
||||
|
||||
.PHONY: timer
|
||||
timer: ## Build the timer app in docker
|
||||
docker build -o . --target export --build-arg TARGET=timer.bin .
|
||||
|
@ -1,12 +1,11 @@
|
||||
#include <cstdint>
|
||||
|
||||
#include "gpio.h"
|
||||
#include "pol0.h"
|
||||
|
||||
struct Gpio {
|
||||
volatile uint32_t data;
|
||||
};
|
||||
namespace {
|
||||
|
||||
#define gpio0 ((Gpio*)GPIO0_BASE)
|
||||
Gpio* gpio0;
|
||||
|
||||
void sleep(int ms) {
|
||||
for (int m = 0; m < ms; m++) {
|
||||
@ -16,7 +15,10 @@ void sleep(int ms) {
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int main() {
|
||||
gpio0 = Gpio::Instance(GPIO0_BASE);
|
||||
int out = 0;
|
||||
|
||||
while (1) {
|
||||
|
@ -1,25 +1,17 @@
|
||||
#include <cstdint>
|
||||
|
||||
#include "bios.h"
|
||||
#include "gpio.h"
|
||||
#include "intc.h"
|
||||
#include "interrupts.h"
|
||||
#include "pol0.h"
|
||||
#include "timer.h"
|
||||
|
||||
extern "C" {
|
||||
void BiosWozmon();
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
struct Gpio {
|
||||
volatile uint32_t data;
|
||||
};
|
||||
|
||||
Gpio* leds = reinterpret_cast<Gpio*>(GPIO0_BASE);
|
||||
Gpio* leds;
|
||||
Timer* timer;
|
||||
|
||||
}
|
||||
|
||||
void Timer0Isr() {
|
||||
static int counter = 0;
|
||||
leds->data = counter++;
|
||||
@ -38,7 +30,10 @@ void SetupTimer() {
|
||||
EnableInterrupts();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int main() {
|
||||
leds = Gpio::Instance(GPIO0_BASE);
|
||||
leds->data = 0xa0;
|
||||
|
||||
SetupTimer();
|
||||
|
@ -1,21 +1,14 @@
|
||||
#include <cstdint>
|
||||
|
||||
#include "gpio.h"
|
||||
#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);
|
||||
Gpio* leds;
|
||||
|
||||
XUartLite uart0_inst;
|
||||
XUartLite_Config uart0_config = {
|
||||
@ -52,9 +45,10 @@ void InitUarts() {
|
||||
SetIrqEnabled(UART0_IRQN, true);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace
|
||||
|
||||
int main() {
|
||||
leds = Gpio::Instance(GPIO0_BASE);
|
||||
leds->data = 0xa0;
|
||||
|
||||
InitUarts();
|
||||
|
@ -1,168 +0,0 @@
|
||||
#include <cstdint>
|
||||
|
||||
#include "xuartlite.h"
|
||||
|
||||
struct Gpio {
|
||||
volatile uint32_t data;
|
||||
};
|
||||
|
||||
#define gpio0 ((Gpio*)0x40000000)
|
||||
|
||||
namespace {
|
||||
constexpr uintptr_t kUart0BaseAddress = 0x40600000;
|
||||
XUartLite uart0_inst;
|
||||
XUartLite_Config uart0_config = {
|
||||
.DeviceId = 0,
|
||||
.RegBaseAddr = kUart0BaseAddress,
|
||||
.BaudRate = 115200,
|
||||
.UseParity = false,
|
||||
.DataBits = 8,
|
||||
};
|
||||
|
||||
XUartLite* uart0 = &uart0_inst;
|
||||
|
||||
void InitUarts() {
|
||||
XUartLite_CfgInitialize(uart0, &uart0_config, uart0_config.RegBaseAddr);
|
||||
}
|
||||
|
||||
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);
|
||||
while (XUartLite_IsSending(uart0)) {}
|
||||
}
|
||||
|
||||
void Jump(uint32_t addr) {
|
||||
auto jump = reinterpret_cast<void (*)()>(addr);
|
||||
jump();
|
||||
}
|
||||
|
||||
constexpr uint8_t kBackspace = 0x7f;
|
||||
constexpr uint8_t kOtherBackspace = 0x08;
|
||||
|
||||
uint8_t ReadHexNibble(uint8_t c) {
|
||||
// lowercase only
|
||||
if (c <= '9') {
|
||||
return c - '0';
|
||||
}
|
||||
return 10 + (c - 'a');
|
||||
}
|
||||
|
||||
uint32_t ReadHex(const char* buf) {
|
||||
uint32_t out = 0;
|
||||
while (*buf == ' ') {
|
||||
buf++;
|
||||
}
|
||||
for (int i = 0; i < 8; i++) {
|
||||
uint8_t c = ReadHexNibble(*buf);
|
||||
if (c > 0xf) {
|
||||
break;
|
||||
}
|
||||
out = (out << 4) + c;
|
||||
buf++;
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
void WriteHexNibble(uint8_t c) {
|
||||
if (c > 9) {
|
||||
UartWrite('a' + c - 10);
|
||||
} else {
|
||||
UartWrite('0' + c);
|
||||
}
|
||||
}
|
||||
|
||||
void UartWriteUint32(uint32_t a) {
|
||||
for (int i = 0; i < 8; i++) {
|
||||
WriteHexNibble((a >> 28) & 0xf);
|
||||
a <<= 4;
|
||||
}
|
||||
}
|
||||
|
||||
void UartWriteUint8(uint8_t a) {
|
||||
WriteHexNibble(a >> 4);
|
||||
WriteHexNibble(a & 0xf);
|
||||
}
|
||||
|
||||
void UartDump(uint32_t addr, int count) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
UartWrite(' ');
|
||||
UartWriteUint8(*reinterpret_cast<uint8_t*>(addr + i));
|
||||
}
|
||||
}
|
||||
|
||||
void DumpHex(uint32_t addr) {
|
||||
addr &= 0xfffffffc;
|
||||
UartWriteUint32(addr);
|
||||
UartWrite(':');
|
||||
UartDump(addr, 4);
|
||||
UartWrite('\r');
|
||||
UartWrite('\n');
|
||||
}
|
||||
|
||||
int FindChar(const char* buf, uint8_t c) {
|
||||
int found = 0;
|
||||
while (*buf) {
|
||||
if (*buf == c) {
|
||||
return found;
|
||||
}
|
||||
found++;
|
||||
buf++;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
int main() {
|
||||
gpio0->data = 1;
|
||||
uint32_t cur_addr = 0;
|
||||
uint32_t cur_data = 0;
|
||||
|
||||
char inbuf[64] = {};
|
||||
char* inptr = inbuf;
|
||||
|
||||
InitUarts();
|
||||
|
||||
while (1) {
|
||||
uint8_t c = UartRead();
|
||||
UartWrite(c); // echo
|
||||
if (c == '\r') {
|
||||
gpio0->data = 0x55;
|
||||
*inptr = 0;
|
||||
if (inptr == inbuf) {
|
||||
cur_addr += 4;
|
||||
} else if (FindChar(inbuf, 'r') >= 0) {
|
||||
Jump(cur_addr);
|
||||
} else {
|
||||
cur_addr = ReadHex(inbuf);
|
||||
UartWrite('\n');
|
||||
}
|
||||
DumpHex(cur_addr);
|
||||
int assigned = FindChar(inbuf, ':');
|
||||
if (assigned >= 0) {
|
||||
cur_data = ReadHex(inbuf + assigned + 1);
|
||||
*(reinterpret_cast<uint32_t*>(cur_addr)) = cur_data;
|
||||
}
|
||||
inptr = inbuf;
|
||||
} else if (c == kBackspace) {
|
||||
inptr--;
|
||||
if (inptr < inbuf) {
|
||||
inptr = inbuf;
|
||||
continue;
|
||||
}
|
||||
UartWrite(kOtherBackspace);
|
||||
UartWrite(' ');
|
||||
UartWrite(kOtherBackspace);
|
||||
} else {
|
||||
*inptr++ = c;
|
||||
}
|
||||
}
|
||||
}
|
1
mbv/configure
vendored
1
mbv/configure
vendored
@ -275,7 +275,6 @@ all = [
|
||||
bootloader_image,
|
||||
|
||||
app_image("helloworld"),
|
||||
app_image("wozmon"),
|
||||
app_image("timer"),
|
||||
app_image("uart"),
|
||||
]
|
||||
|
12
mbv/hal/bios.h
Normal file
12
mbv/hal/bios.h
Normal file
@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
extern "C" {
|
||||
|
||||
uint8_t BiosUartRead();
|
||||
void BiosUartWrite(uint8_t);
|
||||
void BiosWozmon();
|
||||
void BiosUartWriteNibble(uint8_t);
|
||||
|
||||
}
|
11
mbv/hal/gpio.h
Normal file
11
mbv/hal/gpio.h
Normal file
@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
struct Gpio {
|
||||
volatile uint32_t data;
|
||||
|
||||
static Gpio* Instance(uint32_t base) {
|
||||
return reinterpret_cast<Gpio*>(base);
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue
Block a user