From 9edebe637b87b2edc22748ce880e1759082e545d Mon Sep 17 00:00:00 2001 From: Paul Mathieu Date: Thu, 4 Sep 2025 15:01:50 +0200 Subject: [PATCH] mbv: move a few things around --- mbv/Makefile | 6 +- mbv/apps/async/gpio.h | 27 ---- mbv/apps/async/main.cc | 43 ++++-- mbv/apps/async/main2.cc | 108 ---------------- mbv/apps/async/trace.cc | 71 ---------- mbv/apps/async/trace.h | 51 -------- mbv/apps/async/uart.cc | 14 +- mbv/apps/async/uart2.cc | 122 ------------------ mbv/apps/async/uart2.h | 18 --- mbv/apps/async/uart_async.h | 4 +- mbv/apps/helloworld/helloworld.cc | 4 +- mbv/apps/timer/timer.cc | 14 +- mbv/apps/uart/uart.cc | 8 +- mbv/bootloader/bootloader.cc | 2 +- mbv/configure | 19 +-- mbv/hal/uart/Makefile | 39 ------ .../common => xilinx}/clocking/xil_clocking.c | 0 .../common => xilinx}/clocking/xil_clocking.h | 0 .../common => xilinx}/intr/xinterrupt_wrap.c | 0 .../common => xilinx}/intr/xinterrupt_wrap.h | 0 mbv/hal/{lib/common => xilinx}/print.c | 0 mbv/hal/{lib/common => xilinx}/sleep.h | 0 .../common => xilinx}/versal/xil_error_node.h | 0 .../{lib/common => xilinx}/versal/xil_hw.h | 0 mbv/hal/{lib/common => xilinx}/xbasic_types.h | 0 mbv/hal/{lib/common => xilinx}/xdebug.h | 0 mbv/hal/{lib/common => xilinx}/xenv.h | 0 .../{lib/common => xilinx}/xenv_standalone.h | 0 mbv/hal/{lib/common => xilinx}/xil_assert.c | 0 mbv/hal/{lib/common => xilinx}/xil_assert.h | 0 .../common => xilinx}/xil_cache_vxworks.h | 0 mbv/hal/{lib/common => xilinx}/xil_hal.h | 0 mbv/hal/{lib/common => xilinx}/xil_io.h | 0 .../{lib/common => xilinx}/xil_macroback.h | 0 mbv/hal/{lib/common => xilinx}/xil_mem.c | 0 mbv/hal/{lib/common => xilinx}/xil_mem.h | 0 mbv/hal/{lib/common => xilinx}/xil_printf.c | 0 mbv/hal/{lib/common => xilinx}/xil_printf.h | 0 .../{lib/common => xilinx}/xil_sleepcommon.c | 0 .../{lib/common => xilinx}/xil_testcache.c | 0 .../{lib/common => xilinx}/xil_testcache.h | 0 mbv/hal/{lib/common => xilinx}/xil_testio.c | 0 mbv/hal/{lib/common => xilinx}/xil_testio.h | 0 mbv/hal/{lib/common => xilinx}/xil_testmem.c | 0 mbv/hal/{lib/common => xilinx}/xil_testmem.h | 0 mbv/hal/{lib/common => xilinx}/xil_types.h | 0 mbv/hal/{lib/common => xilinx}/xil_util.c | 0 mbv/hal/{lib/common => xilinx}/xil_util.h | 0 .../{lib/common => xilinx}/xplatform_info.c | 0 .../{lib/common => xilinx}/xplatform_info.h | 0 mbv/hal/{lib/common => xilinx}/xstatus.h | 0 mbv/{apps/async => lib}/async.cc | 6 - mbv/{apps/async => lib}/async.h | 4 - mbv/{apps/async => lib}/buffer.h | 0 mbv/{apps/async => lib}/itoa.h | 0 mbv/{apps/async => lib}/lock.cc | 0 mbv/{apps/async => lib}/lock.h | 2 +- mbv/{apps/async => lib}/ring_buffer.h | 0 58 files changed, 68 insertions(+), 494 deletions(-) delete mode 100644 mbv/apps/async/gpio.h delete mode 100644 mbv/apps/async/main2.cc delete mode 100644 mbv/apps/async/trace.cc delete mode 100644 mbv/apps/async/trace.h delete mode 100644 mbv/apps/async/uart2.cc delete mode 100644 mbv/apps/async/uart2.h delete mode 100644 mbv/hal/uart/Makefile rename mbv/hal/{lib/common => xilinx}/clocking/xil_clocking.c (100%) rename mbv/hal/{lib/common => xilinx}/clocking/xil_clocking.h (100%) rename mbv/hal/{lib/common => xilinx}/intr/xinterrupt_wrap.c (100%) rename mbv/hal/{lib/common => xilinx}/intr/xinterrupt_wrap.h (100%) rename mbv/hal/{lib/common => xilinx}/print.c (100%) rename mbv/hal/{lib/common => xilinx}/sleep.h (100%) rename mbv/hal/{lib/common => xilinx}/versal/xil_error_node.h (100%) rename mbv/hal/{lib/common => xilinx}/versal/xil_hw.h (100%) rename mbv/hal/{lib/common => xilinx}/xbasic_types.h (100%) rename mbv/hal/{lib/common => xilinx}/xdebug.h (100%) rename mbv/hal/{lib/common => xilinx}/xenv.h (100%) rename mbv/hal/{lib/common => xilinx}/xenv_standalone.h (100%) rename mbv/hal/{lib/common => xilinx}/xil_assert.c (100%) rename mbv/hal/{lib/common => xilinx}/xil_assert.h (100%) rename mbv/hal/{lib/common => xilinx}/xil_cache_vxworks.h (100%) rename mbv/hal/{lib/common => xilinx}/xil_hal.h (100%) rename mbv/hal/{lib/common => xilinx}/xil_io.h (100%) rename mbv/hal/{lib/common => xilinx}/xil_macroback.h (100%) rename mbv/hal/{lib/common => xilinx}/xil_mem.c (100%) rename mbv/hal/{lib/common => xilinx}/xil_mem.h (100%) rename mbv/hal/{lib/common => xilinx}/xil_printf.c (100%) rename mbv/hal/{lib/common => xilinx}/xil_printf.h (100%) rename mbv/hal/{lib/common => xilinx}/xil_sleepcommon.c (100%) rename mbv/hal/{lib/common => xilinx}/xil_testcache.c (100%) rename mbv/hal/{lib/common => xilinx}/xil_testcache.h (100%) rename mbv/hal/{lib/common => xilinx}/xil_testio.c (100%) rename mbv/hal/{lib/common => xilinx}/xil_testio.h (100%) rename mbv/hal/{lib/common => xilinx}/xil_testmem.c (100%) rename mbv/hal/{lib/common => xilinx}/xil_testmem.h (100%) rename mbv/hal/{lib/common => xilinx}/xil_types.h (100%) rename mbv/hal/{lib/common => xilinx}/xil_util.c (100%) rename mbv/hal/{lib/common => xilinx}/xil_util.h (100%) rename mbv/hal/{lib/common => xilinx}/xplatform_info.c (100%) rename mbv/hal/{lib/common => xilinx}/xplatform_info.h (100%) rename mbv/hal/{lib/common => xilinx}/xstatus.h (100%) rename mbv/{apps/async => lib}/async.cc (91%) rename mbv/{apps/async => lib}/async.h (97%) rename mbv/{apps/async => lib}/buffer.h (100%) rename mbv/{apps/async => lib}/itoa.h (100%) rename mbv/{apps/async => lib}/lock.cc (100%) rename mbv/{apps/async => lib}/lock.h (93%) rename mbv/{apps/async => lib}/ring_buffer.h (100%) diff --git a/mbv/Makefile b/mbv/Makefile index 83d9c8e..0a10f6d 100644 --- a/mbv/Makefile +++ b/mbv/Makefile @@ -28,14 +28,10 @@ dev: dev-image ## Run a dev container .PHONY: clean clean: ## Remove generated files - rm -rf *.elf *.bin $(all_objects) $(deps) - rm -rf test/ *.dSYM $(test_deps) *.o + rm -rf *.elf *.bin .PHONY: help help: ## Show this help @echo Noteworthy targets: @egrep '^[a-zA-Z_-]+:.*?## .*$$' $(firstword $(MAKEFILE_LIST)) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' .DEFAULT_GOAL := help - -#-include $(deps) -#-include $(test_deps) diff --git a/mbv/apps/async/gpio.h b/mbv/apps/async/gpio.h deleted file mode 100644 index 23e4a22..0000000 --- a/mbv/apps/async/gpio.h +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once - -#include - -struct Gpio { - volatile uint32_t data; -}; - -#define gpio0 ((Gpio*)0x40000000) - -inline void ToggleLed(int which) { - uint8_t data = gpio0->data; - data ^= (0x1 << which); - gpio0->data = data; -} - -inline void SetLed(int which) { - uint8_t data = gpio0->data; - data |= (0x1 << which); - gpio0->data = data; -} - -inline void ClearLed(int which) { - uint8_t data = gpio0->data; - data &= ~(0x1 << which); - gpio0->data = data; -} diff --git a/mbv/apps/async/main.cc b/mbv/apps/async/main.cc index 8249766..2fb9ef7 100644 --- a/mbv/apps/async/main.cc +++ b/mbv/apps/async/main.cc @@ -1,11 +1,11 @@ -#include "async.h" -#include "buffer.h" -#include "gpio.h" -#include "intc.h" -#include "interrupts.h" -#include "pol0.h" -#include "timer.h" -#include "trace.h" +#include "hal/gpio.h" +#include "hal/intc.h" +#include "hal/interrupts.h" +#include "hal/pol0.h" +#include "hal/timer.h" +#include "lib/async.h" +#include "lib/buffer.h" + #include "uart.h" #include "uart_async.h" @@ -21,6 +21,26 @@ Timer* timer0; volatile uint32_t t1overflowsecs = 0; volatile uint32_t t1overflowusecs = 0; +Gpio* gpio0; + +void ToggleLed(int which) { + uint8_t data = gpio0->data; + data ^= (0x1 << which); + gpio0->data = data; +} + +void SetLed(int which) { + uint8_t data = gpio0->data; + data |= (0x1 << which); + gpio0->data = data; +} + +void ClearLed(int which) { + uint8_t data = gpio0->data; + data &= ~(0x1 << which); + gpio0->data = data; +} + void Uart0Isr() { HandleUartIsr(); } void Timer0Isr() { @@ -85,12 +105,14 @@ async::task<> blink() { } // namespace int main() { + gpio0 = Gpio::Instance(GPIO0_BASE); + gpio0->data = 0; + SetupUart(); UartWriteBlocking("uart setup done\r\n"); SetupTimer(); UartWriteBlocking("timer setup done\r\n"); - gpio0->data = 0; SetupInterrupts(); auto e = echo(); @@ -112,8 +134,7 @@ int main() { #include -#include "itoa.h" -#include "lock.h" +#include "lib/lock.h" extern unsigned char _heap_begin, _heap_end; diff --git a/mbv/apps/async/main2.cc b/mbv/apps/async/main2.cc deleted file mode 100644 index eb59a9e..0000000 --- a/mbv/apps/async/main2.cc +++ /dev/null @@ -1,108 +0,0 @@ -#include "buffer.h" -#include "gpio.h" -#include "intc.h" -#include "interrupts.h" -#include "pol0.h" -#include "timer.h" -#include "trace.h" -#include "uart2.h" - -namespace { - -Timer* timer0; - -void Uart0Isr() { - // ToggleLed(7); - HandleUartIsr(); -} - -void Timer0Isr() { - SetLed(6); - __builtin_trap(); -} - -void SetupUart() { - InitUarts(); - - intc::SetIsr(UART0_IRQN, Uart0Isr); - intc::SetIrqEnabled(UART0_IRQN, true); -} - -void SetupTimer() { - timer0 = Timer::Instance(TIMER0_BASE); - // timer0->SetupAsWdt(100'000 * 1000); - timer0->EnableT1(); - - intc::SetIsr(TIMER0_IRQN, Timer0Isr); - intc::SetIrqEnabled(TIMER0_IRQN, true); -} - -void SetupInterrupts() { - intc::EnableInterrupts(); - SetExternalInterruptHandler(intc::InterruptHandler); - EnableExternalInterrupts(); - EnableInterrupts(true); -} - -} // namespace - -int main() { - SetupUart(); - UartWriteCrash("uart setup done\r\n"); - SetupTimer(); - UartWriteCrash("timer setup done\r\n"); - - SetupInterrupts(); - - UartWriteCrash("init done. starting main loop\r\n"); - - UartEcho(); - - // should never get here -} - -/// stdlib stuff - -#include - -#include - -#include "itoa.h" -#include "lock.h" - -extern unsigned char _heap_begin, _heap_end; - -extern "C" void* _sbrk(int increment) { - static unsigned char* heap = &_heap_begin; - unsigned char* prev_heap = heap; - if (heap + increment >= &_heap_end) { - UartWriteCrash("Heap overflow!\r\n"); - return reinterpret_cast(-1); - } - heap += increment; - return prev_heap; -} - -extern "C" int _gettimeofday(struct timeval* tv, void* tzvp) { - (void)tzvp; - uint32_t ticks = timer0->GetT1Ticks(); - tv->tv_sec = ticks / 100000000; - tv->tv_usec = (ticks % 100000000) / 100; - - return 0; -} - -extern "C" uint8_t __atomic_exchange_1(volatile void* ptr, uint8_t val, - int memorder) { - (void)memorder; - auto* dest = reinterpret_cast(ptr); - bool ret; - - { - InterruptLock lock; - ret = *dest; - *dest = val; - } - - return ret; -} diff --git a/mbv/apps/async/trace.cc b/mbv/apps/async/trace.cc deleted file mode 100644 index f2d2a08..0000000 --- a/mbv/apps/async/trace.cc +++ /dev/null @@ -1,71 +0,0 @@ -#include "trace.h" - -#include -#include - -#include "itoa.h" -#include "lock.h" -#include "uart.h" - -namespace tracing { -namespace { - -struct Event { - uint32_t timestamp; - TraceEvent event; -}; - -constexpr size_t kTraceBufferSize = 256; -std::array buffer; -size_t write_ptr = 0; -size_t size = 0; - -} // namespace - -void trace(int raw_event) { trace(static_cast(raw_event)); } - -void trace(TraceEvent event) { - const std::chrono::system_clock::time_point now = - std::chrono::system_clock::now(); - const uint32_t uptime_ticks = now.time_since_epoch().count(); - - { - InterruptLock lock; - - buffer[write_ptr] = {.timestamp = uptime_ticks, .event = event}; - - write_ptr = (write_ptr + 1) % buffer.size(); - size = std::min(size + 1, kTraceBufferSize); - -#if TRACE_DUMP_WHEN_FULL - if (size == kTraceBufferSize) { - dump(); - } -#endif // TRACE_DUMP_WHEN_FULL - } -} - -void dump() { - InterruptLock lock; - - if (size == kTraceBufferSize) { - std::rotate(buffer.begin(), buffer.begin() + write_ptr, buffer.end()); - } - - char number[] = "00000000"; - - UartWriteCrash("----\r\n"); - for (Event event : std::span{buffer}.subspan(0, size)) { - itoa(static_cast(event.timestamp), number); - UartWriteCrash(number); - UartWriteCrash(" "); - itoa(static_cast(event.event), number); - UartWriteCrash(number); - UartWriteCrash("\r\n"); - } - UartWriteCrash("----\r\n"); - - size = 0; - write_ptr = 0; -} -} // namespace tracing diff --git a/mbv/apps/async/trace.h b/mbv/apps/async/trace.h deleted file mode 100644 index a3b4b96..0000000 --- a/mbv/apps/async/trace.h +++ /dev/null @@ -1,51 +0,0 @@ -#pragma once - -#define TRACE_DUMP_WHEN_FULL 0 - -#ifdef __x86_64__ -#include -#define TRACE(x) printf(#x "\n") -#else // __x86_64__ -#define TRACE(...) tracing::trace(__VA_ARGS__) -#endif // __x86_64__ - -#include - -namespace tracing { -enum class TraceEvent : uint8_t { - kUnknown = 0, - - kUartIsr = 1, - kUartRxCb = 2, - kUartTxCb = 3, - - kUartSend = 10, - kUartRecv = 11, - kUartTxBufferFull = 12, - kUartTxBufferNotFull = 13, - - kUartWriteDone = 20, - - kAsyncResume = 4, - kAsyncEnqueue = 5, - kAsyncTask = 6, - kAsyncResumeSetPending = 7, - kAsyncAwaitWasNotified = 8, - kAsyncSchedule = 9, - - kAsyncTaskDone = 14, - kAsyncException = 15, - kAsyncCallParent = 16, - kAsyncCallParentDone = 17, - kAsyncCoAwait = 18, - kAsyncSuspend = 19, - kAsyncDestroy = 21, - - kAsyncGimmeWaiting = 22, - kAsyncGimmeResume = 23, -}; - -void trace(TraceEvent event); -void trace(int raw_event); -void dump(); -} // namespace tracing diff --git a/mbv/apps/async/uart.cc b/mbv/apps/async/uart.cc index de3cd99..602aa84 100644 --- a/mbv/apps/async/uart.cc +++ b/mbv/apps/async/uart.cc @@ -1,14 +1,14 @@ #include "uart.h" -#include "async.h" -#include "gpio.h" -#include "lock.h" -#include "pol0.h" -#include "ring_buffer.h" -#include "trace.h" -#include "uart_async.h" +#include "hal/gpio.h" +#include "hal/pol0.h" +#include "lib/async.h" +#include "lib/lock.h" +#include "lib/ring_buffer.h" #include "xuartlite.h" +#include "uart_async.h" + namespace { using async::AwaitableType; diff --git a/mbv/apps/async/uart2.cc b/mbv/apps/async/uart2.cc deleted file mode 100644 index 2a551cf..0000000 --- a/mbv/apps/async/uart2.cc +++ /dev/null @@ -1,122 +0,0 @@ -#include "uart2.h" - -#include "gpio.h" -#include "lock.h" -#include "pol0.h" -#include "ring_buffer.h" -#include "xuartlite.h" - -namespace { - -constexpr uintptr_t kUart0BaseAddress = UART0_BASE; -XUartLite uart0_inst; -XUartLite_Config uart0_config = { - .DeviceId = 0, - .RegBaseAddr = kUart0BaseAddress, - .BaudRate = 115200, - .UseParity = false, - .DataBits = 8, -}; - -constexpr size_t kUartRxBufferSize = 256; -std::array rx_buffer = {}; -RingBuffer rx_ring_buffer{.buffer = rx_buffer}; - -constexpr size_t kUartTxBufferSize = 256; -std::array tx_buffer = {}; -RingBuffer tx_ring_buffer{.buffer = tx_buffer}; - -XUartLite* uart0 = &uart0_inst; - -volatile int sending = 0; - -void StartReceiving() { - while (1) { - if (rx_ring_buffer.FreeSpace() < 1) { - // woops, full. discard some data - // TODO: keep track of overrun stats - rx_ring_buffer.Pop(1); - } - if (XUartLite_Recv(uart0, rx_ring_buffer.RawWritePointer(), 1) < 1) { - break; - } - rx_ring_buffer.Push(1); - } -} - -void StartSending() { - if (sending > 0) { - return; - } - size_t tosend = tx_ring_buffer.ContiguousAvailableData(); - if (tosend < 1) { - return; - } - sending += 1; - XUartLite_Send(uart0, tx_ring_buffer.RawReadPointer(), tosend); -} - -std::byte UartReadByte() { - std::byte c; - while (!rx_ring_buffer.Load(std::span{&c, 1})) { - } - - return c; -} - -void UartWriteByte(std::byte c) { - while (!tx_ring_buffer.Store(std::span{&c, 1})) { - } - { - InterruptLock lock; - StartSending(); - } -} - -} // namespace - -void InitUarts() { - XUartLite_CfgInitialize(uart0, &uart0_config, uart0_config.RegBaseAddr); - - XUartLite_SetSendHandler(uart0, HandleUartTxFromIsr, nullptr); - XUartLite_SetRecvHandler(uart0, HandleUartRxFromIsr, nullptr); - StartReceiving(); - XUartLite_EnableInterrupt(uart0); -} - -void UartWriteCrash(std::span data) { - XUartLite_DisableInterrupt(uart0); - while (data.size() > 0) { - while (XUartLite_IsSending(uart0)) { - } - auto* dat = - reinterpret_cast(const_cast(data.data())); - uint8_t sent = XUartLite_Send(uart0, dat, data.size()); - data = data.subspan(sent); - } - while (XUartLite_IsSending(uart0)) { - } - XUartLite_Send(uart0, nullptr, - 0); // reset buffer before enabling interrupts - XUartLite_EnableInterrupt(uart0); -} - -void UartEcho() { - while (1) { - std::byte c = UartReadByte(); - UartWriteByte(c); - } -} - -void HandleUartTxFromIsr(void*, unsigned int transmitted) { - sending -= 1; - tx_ring_buffer.Pop(transmitted); - StartSending(); -} - -void HandleUartRxFromIsr(void*, unsigned int transmitted) { - rx_ring_buffer.Push(transmitted); - StartReceiving(); -} - -void HandleUartIsr() { XUartLite_InterruptHandler(uart0); } diff --git a/mbv/apps/async/uart2.h b/mbv/apps/async/uart2.h deleted file mode 100644 index 54fa55f..0000000 --- a/mbv/apps/async/uart2.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include -#include - -void InitUarts(); - -// send and poll the uart until transmitted -void UartWriteCrash(std::span data); -inline void UartWriteCrash(std::string_view s) { - return UartWriteCrash(std::as_bytes(std::span{s.data(), s.size()})); -} - -void UartEcho(); - -void HandleUartTxFromIsr(void*, unsigned int transmitted); -void HandleUartRxFromIsr(void*, unsigned int); -void HandleUartIsr(); diff --git a/mbv/apps/async/uart_async.h b/mbv/apps/async/uart_async.h index d9a8134..add72ba 100644 --- a/mbv/apps/async/uart_async.h +++ b/mbv/apps/async/uart_async.h @@ -3,8 +3,8 @@ #include #include -#include "async.h" -#include "buffer.h" +#include "lib/async.h" +#include "lib/buffer.h" async::task UartRead(int size); async::task UartReadLoop(); diff --git a/mbv/apps/helloworld/helloworld.cc b/mbv/apps/helloworld/helloworld.cc index 9a5360e..ccf19f8 100644 --- a/mbv/apps/helloworld/helloworld.cc +++ b/mbv/apps/helloworld/helloworld.cc @@ -1,7 +1,7 @@ #include -#include "gpio.h" -#include "pol0.h" +#include "hal/gpio.h" +#include "hal/pol0.h" namespace { diff --git a/mbv/apps/timer/timer.cc b/mbv/apps/timer/timer.cc index 195c035..3d9d8d7 100644 --- a/mbv/apps/timer/timer.cc +++ b/mbv/apps/timer/timer.cc @@ -1,12 +1,12 @@ -#include "timer.h" - #include -#include "bios.h" -#include "gpio.h" -#include "intc.h" -#include "interrupts.h" -#include "pol0.h" +#include "hal/bios.h" +#include "hal/gpio.h" +#include "hal/intc.h" +#include "hal/interrupts.h" +#include "hal/pol0.h" +#include "hal/timer.h" + namespace { diff --git a/mbv/apps/uart/uart.cc b/mbv/apps/uart/uart.cc index 4376b31..91e6bd8 100644 --- a/mbv/apps/uart/uart.cc +++ b/mbv/apps/uart/uart.cc @@ -1,9 +1,9 @@ #include -#include "gpio.h" -#include "intc.h" -#include "interrupts.h" -#include "pol0.h" +#include "hal/gpio.h" +#include "hal/intc.h" +#include "hal/interrupts.h" +#include "hal/pol0.h" #include "xuartlite.h" namespace { diff --git a/mbv/bootloader/bootloader.cc b/mbv/bootloader/bootloader.cc index f7f15f3..a6cf0c4 100644 --- a/mbv/bootloader/bootloader.cc +++ b/mbv/bootloader/bootloader.cc @@ -1,6 +1,6 @@ #include -#include "pol0.h" +#include "hal/pol0.h" #include "xuartlite.h" uint8_t UartRead(); diff --git a/mbv/configure b/mbv/configure index d32f559..a5c6f36 100755 --- a/mbv/configure +++ b/mbv/configure @@ -25,9 +25,9 @@ class Config: hostlibs = "-lgtest -lgmock -lgtest_main" hostldflags = "-fprofile-instr-generate -fcoverage-mapping" include_dirs = [ - "hal", + ".", "hal/uart", - "hal/lib/common", + "hal/xilinx", ] common_flags = [ "-g", @@ -269,10 +269,15 @@ hal = source_set("hal", [ "hal/intc.cc", "hal/interrupts.cc", "hal/start.cc", - "hal/lib/common/xil_assert.c", "hal/uart/xuartlite.c", - "hal/uart/xuartlite_stats.c", "hal/uart/xuartlite_intr.c", + "hal/uart/xuartlite_stats.c", + "hal/xilinx/xil_assert.c", + ]) + +lib = source_set("lib", [ + "lib/async.cc", + "lib/lock.cc", ]) bootloader = source_set("bootloader", glob.glob("./bootloader/**/*.cc", recursive=True)) @@ -289,23 +294,21 @@ def app_image(app, sources=None): return build_image( source_set(app, sources), linker_script="apps/app.ld", - dependencies=[hal], + dependencies=[hal, lib], elf_out=f"{app}.elf", bin_out=f"{app}.bin", ) all = [ build_source_set(hal), + build_source_set(lib), bootloader_image, app_image("helloworld"), app_image("timer"), app_image("uart"), app_image("async", sources=[ - "apps/async/async.cc", - "apps/async/lock.cc", "apps/async/main.cc", - "apps/async/trace.cc", "apps/async/uart.cc", ]), ] diff --git a/mbv/hal/uart/Makefile b/mbv/hal/uart/Makefile deleted file mode 100644 index 5feeb49..0000000 --- a/mbv/hal/uart/Makefile +++ /dev/null @@ -1,39 +0,0 @@ -DRIVER_LIB_VERSION = 1.0 -COMPILER= -ARCHIVER= -CP=cp -COMPILER_FLAGS= -EXTRA_COMPILER_FLAGS= -LIB=libxil.a - -CC_FLAGS = $(COMPILER_FLAGS) -ECC_FLAGS = $(EXTRA_COMPILER_FLAGS) - -RELEASEDIR=../../../lib/ -INCLUDEDIR=../../../include/ -INCLUDES=-I./. -I$(INCLUDEDIR) - -SRCFILES:=$(wildcard *.c) - -OBJECTS = $(addprefix $(RELEASEDIR), $(addsuffix .o, $(basename $(wildcard *.c)))) - -libs: $(OBJECTS) - -DEPFILES := $(SRCFILES:%.c=$(RELEASEDIR)%.d) - -include $(wildcard $(DEPFILES)) - -include $(wildcard ../../../../dep.mk) - -$(RELEASEDIR)%.o: %.c - ${COMPILER} $(CC_FLAGS) $(ECC_FLAGS) $(INCLUDES) $(DEPENDENCY_FLAGS) $< -o $@ - -.PHONY: include -include: $(addprefix $(INCLUDEDIR),$(wildcard *.h)) - -$(INCLUDEDIR)%.h: %.h - $(CP) $< $@ - -clean: - rm -rf ${OBJECTS} - rm -rf $(DEPFILES) diff --git a/mbv/hal/lib/common/clocking/xil_clocking.c b/mbv/hal/xilinx/clocking/xil_clocking.c similarity index 100% rename from mbv/hal/lib/common/clocking/xil_clocking.c rename to mbv/hal/xilinx/clocking/xil_clocking.c diff --git a/mbv/hal/lib/common/clocking/xil_clocking.h b/mbv/hal/xilinx/clocking/xil_clocking.h similarity index 100% rename from mbv/hal/lib/common/clocking/xil_clocking.h rename to mbv/hal/xilinx/clocking/xil_clocking.h diff --git a/mbv/hal/lib/common/intr/xinterrupt_wrap.c b/mbv/hal/xilinx/intr/xinterrupt_wrap.c similarity index 100% rename from mbv/hal/lib/common/intr/xinterrupt_wrap.c rename to mbv/hal/xilinx/intr/xinterrupt_wrap.c diff --git a/mbv/hal/lib/common/intr/xinterrupt_wrap.h b/mbv/hal/xilinx/intr/xinterrupt_wrap.h similarity index 100% rename from mbv/hal/lib/common/intr/xinterrupt_wrap.h rename to mbv/hal/xilinx/intr/xinterrupt_wrap.h diff --git a/mbv/hal/lib/common/print.c b/mbv/hal/xilinx/print.c similarity index 100% rename from mbv/hal/lib/common/print.c rename to mbv/hal/xilinx/print.c diff --git a/mbv/hal/lib/common/sleep.h b/mbv/hal/xilinx/sleep.h similarity index 100% rename from mbv/hal/lib/common/sleep.h rename to mbv/hal/xilinx/sleep.h diff --git a/mbv/hal/lib/common/versal/xil_error_node.h b/mbv/hal/xilinx/versal/xil_error_node.h similarity index 100% rename from mbv/hal/lib/common/versal/xil_error_node.h rename to mbv/hal/xilinx/versal/xil_error_node.h diff --git a/mbv/hal/lib/common/versal/xil_hw.h b/mbv/hal/xilinx/versal/xil_hw.h similarity index 100% rename from mbv/hal/lib/common/versal/xil_hw.h rename to mbv/hal/xilinx/versal/xil_hw.h diff --git a/mbv/hal/lib/common/xbasic_types.h b/mbv/hal/xilinx/xbasic_types.h similarity index 100% rename from mbv/hal/lib/common/xbasic_types.h rename to mbv/hal/xilinx/xbasic_types.h diff --git a/mbv/hal/lib/common/xdebug.h b/mbv/hal/xilinx/xdebug.h similarity index 100% rename from mbv/hal/lib/common/xdebug.h rename to mbv/hal/xilinx/xdebug.h diff --git a/mbv/hal/lib/common/xenv.h b/mbv/hal/xilinx/xenv.h similarity index 100% rename from mbv/hal/lib/common/xenv.h rename to mbv/hal/xilinx/xenv.h diff --git a/mbv/hal/lib/common/xenv_standalone.h b/mbv/hal/xilinx/xenv_standalone.h similarity index 100% rename from mbv/hal/lib/common/xenv_standalone.h rename to mbv/hal/xilinx/xenv_standalone.h diff --git a/mbv/hal/lib/common/xil_assert.c b/mbv/hal/xilinx/xil_assert.c similarity index 100% rename from mbv/hal/lib/common/xil_assert.c rename to mbv/hal/xilinx/xil_assert.c diff --git a/mbv/hal/lib/common/xil_assert.h b/mbv/hal/xilinx/xil_assert.h similarity index 100% rename from mbv/hal/lib/common/xil_assert.h rename to mbv/hal/xilinx/xil_assert.h diff --git a/mbv/hal/lib/common/xil_cache_vxworks.h b/mbv/hal/xilinx/xil_cache_vxworks.h similarity index 100% rename from mbv/hal/lib/common/xil_cache_vxworks.h rename to mbv/hal/xilinx/xil_cache_vxworks.h diff --git a/mbv/hal/lib/common/xil_hal.h b/mbv/hal/xilinx/xil_hal.h similarity index 100% rename from mbv/hal/lib/common/xil_hal.h rename to mbv/hal/xilinx/xil_hal.h diff --git a/mbv/hal/lib/common/xil_io.h b/mbv/hal/xilinx/xil_io.h similarity index 100% rename from mbv/hal/lib/common/xil_io.h rename to mbv/hal/xilinx/xil_io.h diff --git a/mbv/hal/lib/common/xil_macroback.h b/mbv/hal/xilinx/xil_macroback.h similarity index 100% rename from mbv/hal/lib/common/xil_macroback.h rename to mbv/hal/xilinx/xil_macroback.h diff --git a/mbv/hal/lib/common/xil_mem.c b/mbv/hal/xilinx/xil_mem.c similarity index 100% rename from mbv/hal/lib/common/xil_mem.c rename to mbv/hal/xilinx/xil_mem.c diff --git a/mbv/hal/lib/common/xil_mem.h b/mbv/hal/xilinx/xil_mem.h similarity index 100% rename from mbv/hal/lib/common/xil_mem.h rename to mbv/hal/xilinx/xil_mem.h diff --git a/mbv/hal/lib/common/xil_printf.c b/mbv/hal/xilinx/xil_printf.c similarity index 100% rename from mbv/hal/lib/common/xil_printf.c rename to mbv/hal/xilinx/xil_printf.c diff --git a/mbv/hal/lib/common/xil_printf.h b/mbv/hal/xilinx/xil_printf.h similarity index 100% rename from mbv/hal/lib/common/xil_printf.h rename to mbv/hal/xilinx/xil_printf.h diff --git a/mbv/hal/lib/common/xil_sleepcommon.c b/mbv/hal/xilinx/xil_sleepcommon.c similarity index 100% rename from mbv/hal/lib/common/xil_sleepcommon.c rename to mbv/hal/xilinx/xil_sleepcommon.c diff --git a/mbv/hal/lib/common/xil_testcache.c b/mbv/hal/xilinx/xil_testcache.c similarity index 100% rename from mbv/hal/lib/common/xil_testcache.c rename to mbv/hal/xilinx/xil_testcache.c diff --git a/mbv/hal/lib/common/xil_testcache.h b/mbv/hal/xilinx/xil_testcache.h similarity index 100% rename from mbv/hal/lib/common/xil_testcache.h rename to mbv/hal/xilinx/xil_testcache.h diff --git a/mbv/hal/lib/common/xil_testio.c b/mbv/hal/xilinx/xil_testio.c similarity index 100% rename from mbv/hal/lib/common/xil_testio.c rename to mbv/hal/xilinx/xil_testio.c diff --git a/mbv/hal/lib/common/xil_testio.h b/mbv/hal/xilinx/xil_testio.h similarity index 100% rename from mbv/hal/lib/common/xil_testio.h rename to mbv/hal/xilinx/xil_testio.h diff --git a/mbv/hal/lib/common/xil_testmem.c b/mbv/hal/xilinx/xil_testmem.c similarity index 100% rename from mbv/hal/lib/common/xil_testmem.c rename to mbv/hal/xilinx/xil_testmem.c diff --git a/mbv/hal/lib/common/xil_testmem.h b/mbv/hal/xilinx/xil_testmem.h similarity index 100% rename from mbv/hal/lib/common/xil_testmem.h rename to mbv/hal/xilinx/xil_testmem.h diff --git a/mbv/hal/lib/common/xil_types.h b/mbv/hal/xilinx/xil_types.h similarity index 100% rename from mbv/hal/lib/common/xil_types.h rename to mbv/hal/xilinx/xil_types.h diff --git a/mbv/hal/lib/common/xil_util.c b/mbv/hal/xilinx/xil_util.c similarity index 100% rename from mbv/hal/lib/common/xil_util.c rename to mbv/hal/xilinx/xil_util.c diff --git a/mbv/hal/lib/common/xil_util.h b/mbv/hal/xilinx/xil_util.h similarity index 100% rename from mbv/hal/lib/common/xil_util.h rename to mbv/hal/xilinx/xil_util.h diff --git a/mbv/hal/lib/common/xplatform_info.c b/mbv/hal/xilinx/xplatform_info.c similarity index 100% rename from mbv/hal/lib/common/xplatform_info.c rename to mbv/hal/xilinx/xplatform_info.c diff --git a/mbv/hal/lib/common/xplatform_info.h b/mbv/hal/xilinx/xplatform_info.h similarity index 100% rename from mbv/hal/lib/common/xplatform_info.h rename to mbv/hal/xilinx/xplatform_info.h diff --git a/mbv/hal/lib/common/xstatus.h b/mbv/hal/xilinx/xstatus.h similarity index 100% rename from mbv/hal/lib/common/xstatus.h rename to mbv/hal/xilinx/xstatus.h diff --git a/mbv/apps/async/async.cc b/mbv/lib/async.cc similarity index 91% rename from mbv/apps/async/async.cc rename to mbv/lib/async.cc index 8310bcf..d1c41cd 100644 --- a/mbv/apps/async/async.cc +++ b/mbv/lib/async.cc @@ -6,7 +6,6 @@ #include #include "lock.h" -#include "trace.h" namespace async { namespace { @@ -33,7 +32,6 @@ std::array(AwaitableType::kNumTypes)> void schedule(std::coroutine_handle<> h, int ms) { InterruptLock lock; - TRACE(tracing::TraceEvent::kAsyncSchedule); std::chrono::system_clock::time_point exp = std::chrono::system_clock::now() + std::chrono::milliseconds(ms); Stuff* news = new Stuff{ @@ -80,9 +78,7 @@ void step() { int stuffinqueue = 0; for (Stuff* s = stuff; s; s = s->next) stuffinqueue++; - TRACE(tracing::TraceEvent::kAsyncTask); stuff->h(); - TRACE(tracing::TraceEvent::kAsyncTaskDone); { InterruptLock lock; @@ -120,12 +116,10 @@ void enqueue(std::coroutine_handle<> h, AwaitableType type) { { InterruptLock lock; - TRACE(tracing::TraceEvent::kAsyncEnqueue); const bool was_notified = std::exchange(notifications[ttype].pending, false); if (was_notified) { - TRACE(tracing::TraceEvent::kAsyncAwaitWasNotified); schedule(h); return; } diff --git a/mbv/apps/async/async.h b/mbv/lib/async.h similarity index 97% rename from mbv/apps/async/async.h rename to mbv/lib/async.h index 88a5537..b9e643c 100644 --- a/mbv/apps/async/async.h +++ b/mbv/lib/async.h @@ -4,8 +4,6 @@ #include #include -#include "trace.h" - namespace async { struct continuation : std::suspend_always { @@ -153,14 +151,12 @@ struct gimme { void await_suspend(std::coroutine_handle<> h) { ha = h; waiting = true; - TRACE(tracing::TraceEvent::kAsyncGimmeWaiting); if (parent) { schedule(parent); } } T await_resume() { waiting = false; - TRACE(tracing::TraceEvent::kAsyncGimmeResume); return std::move(stuff); } diff --git a/mbv/apps/async/buffer.h b/mbv/lib/buffer.h similarity index 100% rename from mbv/apps/async/buffer.h rename to mbv/lib/buffer.h diff --git a/mbv/apps/async/itoa.h b/mbv/lib/itoa.h similarity index 100% rename from mbv/apps/async/itoa.h rename to mbv/lib/itoa.h diff --git a/mbv/apps/async/lock.cc b/mbv/lib/lock.cc similarity index 100% rename from mbv/apps/async/lock.cc rename to mbv/lib/lock.cc diff --git a/mbv/apps/async/lock.h b/mbv/lib/lock.h similarity index 93% rename from mbv/apps/async/lock.h rename to mbv/lib/lock.h index e361a60..ab5bf05 100644 --- a/mbv/apps/async/lock.h +++ b/mbv/lib/lock.h @@ -1,7 +1,7 @@ #pragma once #ifndef __x86_64__ -#include "interrupts.h" +#include "hal/interrupts.h" struct InterruptLock { bool was_on; diff --git a/mbv/apps/async/ring_buffer.h b/mbv/lib/ring_buffer.h similarity index 100% rename from mbv/apps/async/ring_buffer.h rename to mbv/lib/ring_buffer.h