diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-03-26 21:20:54 -0600 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-03-26 21:20:54 -0600 |
commit | 0378f059440d4702203f9bc005894f7b53cad889 (patch) | |
tree | ad738d3ce97e2f76071b6b2f448eecc8526d6bd0 | |
parent | 61b14883c1ddbd5985c681ef7b559cf3c8c15525 (diff) |
Have libhw_generic be independent of libcr, rename libhw to libhw_cr
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | HACKING.md | 2 | ||||
-rw-r--r-- | cmd/sbc_harness/CMakeLists.txt | 2 | ||||
-rw-r--r-- | lib9p/tests/test_server/CMakeLists.txt | 2 | ||||
-rw-r--r-- | libhw/CMakeLists.txt | 38 | ||||
-rw-r--r-- | libhw_cr/CMakeLists.txt | 43 | ||||
-rw-r--r-- | libhw_cr/alarmclock.c | 23 | ||||
-rw-r--r-- | libhw_cr/host_alarmclock.c (renamed from libhw/host_alarmclock.c) | 2 | ||||
-rw-r--r-- | libhw_cr/host_include/libhw/host_alarmclock.h (renamed from libhw/host_include/libhw/host_alarmclock.h) | 0 | ||||
-rw-r--r-- | libhw_cr/host_include/libhw/host_net.h (renamed from libhw/host_include/libhw/host_net.h) | 0 | ||||
-rw-r--r-- | libhw_cr/host_net.c (renamed from libhw/host_net.c) | 2 | ||||
-rw-r--r-- | libhw_cr/host_util.c (renamed from libhw/host_util.c) | 2 | ||||
-rw-r--r-- | libhw_cr/host_util.h (renamed from libhw/host_util.h) | 8 | ||||
-rw-r--r-- | libhw_cr/rp2040_dma.c (renamed from libhw/rp2040_dma.c) | 2 | ||||
-rw-r--r-- | libhw_cr/rp2040_dma.h (renamed from libhw/rp2040_dma.h) | 8 | ||||
-rw-r--r-- | libhw_cr/rp2040_gpioirq.c (renamed from libhw/rp2040_gpioirq.c) | 2 | ||||
-rw-r--r-- | libhw_cr/rp2040_gpioirq.h (renamed from libhw/rp2040_gpioirq.h) | 8 | ||||
-rw-r--r-- | libhw_cr/rp2040_hwspi.c (renamed from libhw/rp2040_hwspi.c) | 2 | ||||
-rw-r--r-- | libhw_cr/rp2040_hwtimer.c (renamed from libhw/rp2040_hwtimer.c) | 2 | ||||
-rw-r--r-- | libhw_cr/rp2040_include/libhw/rp2040_hwspi.h (renamed from libhw/rp2040_include/libhw/rp2040_hwspi.h) | 0 | ||||
-rw-r--r-- | libhw_cr/rp2040_include/libhw/rp2040_hwtimer.h (renamed from libhw/rp2040_include/libhw/rp2040_hwtimer.h) | 0 | ||||
-rw-r--r-- | libhw_cr/rp2040_include/libhw/w5500.h (renamed from libhw/rp2040_include/libhw/w5500.h) | 0 | ||||
-rw-r--r-- | libhw_cr/w5500.c (renamed from libhw/w5500.c) | 2 | ||||
-rw-r--r-- | libhw_cr/w5500_ll.h (renamed from libhw/w5500_ll.h) | 8 | ||||
-rw-r--r-- | libhw_generic/CMakeLists.txt | 1 | ||||
-rw-r--r-- | libhw_generic/alarmclock.c | 18 |
26 files changed, 95 insertions, 84 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index c7bf993..b379a8f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -140,7 +140,7 @@ add_subdirectory(libobj) add_subdirectory(libcr) add_subdirectory(libcr_ipc) add_subdirectory(libhw_generic) -add_subdirectory(libhw) +add_subdirectory(libhw_cr) add_subdirectory(libdhcp) add_subdirectory(libusb) add_subdirectory(lib9p) @@ -18,8 +18,8 @@ Our own tiny cooperative-multitasking OS: - `libcr/`: The kernel (a simple coroutine library) - `libcr_ipc/`: IPC primatives (semaphores, mutexes, channels, ...) for libcr - - `libhw/`: The hardware drivers - `libhw_generic/`: The hardware abstraction layer + - `libhw_cr/`: The hardware drivers Libraries for generic parts of what the harness is doing: diff --git a/cmd/sbc_harness/CMakeLists.txt b/cmd/sbc_harness/CMakeLists.txt index d7923c2..fa42b47 100644 --- a/cmd/sbc_harness/CMakeLists.txt +++ b/cmd/sbc_harness/CMakeLists.txt @@ -24,7 +24,7 @@ target_link_libraries(sbc_harness_objs libmisc libusb libdhcp - libhw + libhw_cr lib9p lib9p_util ) diff --git a/lib9p/tests/test_server/CMakeLists.txt b/lib9p/tests/test_server/CMakeLists.txt index 74a759d..5313917 100644 --- a/lib9p/tests/test_server/CMakeLists.txt +++ b/lib9p/tests/test_server/CMakeLists.txt @@ -18,7 +18,7 @@ target_link_libraries(test_server_objs libmisc lib9p lib9p_util - libhw + libhw_cr ) # Analyze the stack ############################################################ diff --git a/libhw/CMakeLists.txt b/libhw/CMakeLists.txt deleted file mode 100644 index 242a3fa..0000000 --- a/libhw/CMakeLists.txt +++ /dev/null @@ -1,38 +0,0 @@ -# libhw/CMakeLists.txt - Device drivers -# -# Copyright (C) 2024-2025 Luke T. Shumaker <lukeshu@lukeshu.com> -# SPDX-License-Identifier: AGPL-3.0-or-later - -add_library(libhw INTERFACE) -target_link_libraries(libhw INTERFACE - libhw_generic -) - -if (PICO_PLATFORM STREQUAL "rp2040") - target_include_directories(libhw SYSTEM INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/rp2040_include) - target_link_libraries(libhw INTERFACE - libcr_ipc - ) - target_sources(libhw INTERFACE - rp2040_dma.c - rp2040_gpioirq.c - rp2040_hwspi.c - rp2040_hwtimer.c - w5500.c - ) - target_link_libraries(libhw INTERFACE - hardware_gpio - hardware_irq - hardware_spi - hardware_timer - ) -endif() - -if (PICO_PLATFORM STREQUAL "host") - target_include_directories(libhw SYSTEM INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/host_include) - target_sources(libhw INTERFACE - host_util.c - host_alarmclock.c - host_net.c - ) -endif() diff --git a/libhw_cr/CMakeLists.txt b/libhw_cr/CMakeLists.txt new file mode 100644 index 0000000..caeac21 --- /dev/null +++ b/libhw_cr/CMakeLists.txt @@ -0,0 +1,43 @@ +# libhw_cr/CMakeLists.txt - Device drivers for libcr +# +# Copyright (C) 2024-2025 Luke T. Shumaker <lukeshu@lukeshu.com> +# SPDX-License-Identifier: AGPL-3.0-or-later + +add_library(libhw_cr INTERFACE) +target_link_libraries(libhw_cr INTERFACE + libhw_generic + libcr +) + +target_sources(libhw_cr INTERFACE + alarmclock.c +) + +if (PICO_PLATFORM STREQUAL "rp2040") + target_include_directories(libhw_cr SYSTEM INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/rp2040_include) + target_link_libraries(libhw_cr INTERFACE + libcr_ipc + ) + target_sources(libhw_cr INTERFACE + rp2040_dma.c + rp2040_gpioirq.c + rp2040_hwspi.c + rp2040_hwtimer.c + w5500.c + ) + target_link_libraries(libhw_cr INTERFACE + hardware_gpio + hardware_irq + hardware_spi + hardware_timer + ) +endif() + +if (PICO_PLATFORM STREQUAL "host") + target_include_directories(libhw_cr SYSTEM INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/host_include) + target_sources(libhw_cr INTERFACE + host_util.c + host_alarmclock.c + host_net.c + ) +endif() diff --git a/libhw_cr/alarmclock.c b/libhw_cr/alarmclock.c new file mode 100644 index 0000000..6eec52b --- /dev/null +++ b/libhw_cr/alarmclock.c @@ -0,0 +1,23 @@ +/* libhw_cr/alarmclock.c - sleep() implementation for libcr + * + * Copyright (C) 2024-2025 Luke T. Shumaker <lukeshu@lukeshu.com> + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +#include <libcr/coroutine.h> + +#include <libhw/generic/alarmclock.h> + +static void alarmclock_sleep_intrhandler(void *_arg) { + cid_t cid = *(cid_t *)_arg; + cr_unpause_from_intrhandler(cid); +} + +void alarmclock_sleep_until_ns(lo_interface alarmclock clock, uint64_t abstime_ns) { + bool saved = cr_save_and_disable_interrupts(); + cid_t cid = cr_getcid(); + struct alarmclock_trigger trigger; + LO_CALL(clock, add_trigger, &trigger, abstime_ns, alarmclock_sleep_intrhandler, &cid); + cr_pause_and_yield(); + cr_restore_interrupts(saved); +} diff --git a/libhw/host_alarmclock.c b/libhw_cr/host_alarmclock.c index 19ece7c..2f255e0 100644 --- a/libhw/host_alarmclock.c +++ b/libhw_cr/host_alarmclock.c @@ -1,4 +1,4 @@ -/* libhw/host_alarmclock.c - <libhw/generic/alarmclock.h> implementation for POSIX hosts +/* libhw_cr/host_alarmclock.c - <libhw/generic/alarmclock.h> implementation for POSIX hosts * * Copyright (C) 2024-2025 Luke T. Shumaker <lukeshu@lukeshu.com> * SPDX-License-Identifier: AGPL-3.0-or-later diff --git a/libhw/host_include/libhw/host_alarmclock.h b/libhw_cr/host_include/libhw/host_alarmclock.h index 89df68a..89df68a 100644 --- a/libhw/host_include/libhw/host_alarmclock.h +++ b/libhw_cr/host_include/libhw/host_alarmclock.h diff --git a/libhw/host_include/libhw/host_net.h b/libhw_cr/host_include/libhw/host_net.h index fced229..fced229 100644 --- a/libhw/host_include/libhw/host_net.h +++ b/libhw_cr/host_include/libhw/host_net.h diff --git a/libhw/host_net.c b/libhw_cr/host_net.c index e89cd66..f1c988c 100644 --- a/libhw/host_net.c +++ b/libhw_cr/host_net.c @@ -1,4 +1,4 @@ -/* libhw/host_net.c - <libhw/generic/net.h> implementation for hosted glibc +/* libhw_cr/host_net.c - <libhw/generic/net.h> implementation for hosted glibc * * Copyright (C) 2024-2025 Luke T. Shumaker <lukeshu@lukeshu.com> * SPDX-License-Identifier: AGPL-3.0-or-later diff --git a/libhw/host_util.c b/libhw_cr/host_util.c index b862e39..958ed9c 100644 --- a/libhw/host_util.c +++ b/libhw_cr/host_util.c @@ -1,4 +1,4 @@ -/* libhw/host_util.c - Utilities for GNU/Linux hosts +/* libhw_cr/host_util.c - Utilities for GNU/Linux hosts * * Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com> * SPDX-License-Identifier: AGPL-3.0-or-later diff --git a/libhw/host_util.h b/libhw_cr/host_util.h index f3ef6b4..8c53fab 100644 --- a/libhw/host_util.h +++ b/libhw_cr/host_util.h @@ -1,11 +1,11 @@ -/* libhw/host_util.h - Utilities for GNU/Linux hosts +/* libhw_cr/host_util.h - Utilities for GNU/Linux hosts * * Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com> * SPDX-License-Identifier: AGPL-3.0-or-later */ -#ifndef _LIBHW_HOST_UTIL_H_ -#define _LIBHW_HOST_UTIL_H_ +#ifndef _LIBHW_CR_HOST_UTIL_H_ +#define _LIBHW_CR_HOST_UTIL_H_ #include <time.h> /* for struct timespec */ #include <sys/time.h> /* for struct timeval */ @@ -44,4 +44,4 @@ static inline uint64_t ns_from_host_ns_time(host_ns_time_t host_time) { ((uint64_t)host_time.tv_nsec); } -#endif /* _LIBHW_HOST_UTIL_H_ */ +#endif /* _LIBHW_CR_HOST_UTIL_H_ */ diff --git a/libhw/rp2040_dma.c b/libhw_cr/rp2040_dma.c index dfbf136..69116bf 100644 --- a/libhw/rp2040_dma.c +++ b/libhw_cr/rp2040_dma.c @@ -1,4 +1,4 @@ -/* libhw/rp2040_dma.c - Utilities for sharing the DMA IRQs +/* libhw_cr/rp2040_dma.c - Utilities for sharing the DMA IRQs * * Copyright (C) 2025 Luke T. Shumaker <lukeshu@lukeshu.com> * SPDX-License-Identifier: AGPL-3.0-or-later diff --git a/libhw/rp2040_dma.h b/libhw_cr/rp2040_dma.h index c8d69b1..e295adf 100644 --- a/libhw/rp2040_dma.h +++ b/libhw_cr/rp2040_dma.h @@ -1,4 +1,4 @@ -/* libhw/rp2040_dma.h - Utilities for using DMA on the RP2040 (replaces <hardware/dma.h>) +/* libhw_cr/rp2040_dma.h - Utilities for using DMA on the RP2040 (replaces <hardware/dma.h>) * * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. * SPDX-License-Identifier: BSD-3-Clause @@ -7,8 +7,8 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ -#ifndef _LIBHW_RP2040_DMA_H_ -#define _LIBHW_RP2040_DMA_H_ +#ifndef _LIBHW_CR_RP2040_DMA_H_ +#define _LIBHW_CR_RP2040_DMA_H_ #include <assert.h> #include <stdint.h> /* for uint32_t */ @@ -125,4 +125,4 @@ struct dma_alias3_short3 { READ_ADDR ; }; #define _DMA_TRIGGER_trans_count struct dma_alias1 #define _DMA_TRIGGER_ctrl struct dma_alias0 -#endif /* _LIBHW_RP2040_DMA_H_ */ +#endif /* _LIBHW_CR_RP2040_DMA_H_ */ diff --git a/libhw/rp2040_gpioirq.c b/libhw_cr/rp2040_gpioirq.c index 2f0ceac..1ae74f9 100644 --- a/libhw/rp2040_gpioirq.c +++ b/libhw_cr/rp2040_gpioirq.c @@ -1,4 +1,4 @@ -/* libhw/rp2040_gpioirq.c - Utilities for sharing the GPIO IRQ (IO_IRQ_BANK0) +/* libhw_cr/rp2040_gpioirq.c - Utilities for sharing the GPIO IRQ (IO_IRQ_BANK0) * * Copyright (C) 2025 Luke T. Shumaker <lukeshu@lukeshu.com> * SPDX-License-Identifier: AGPL-3.0-or-later diff --git a/libhw/rp2040_gpioirq.h b/libhw_cr/rp2040_gpioirq.h index 06041c9..75a264f 100644 --- a/libhw/rp2040_gpioirq.h +++ b/libhw_cr/rp2040_gpioirq.h @@ -1,11 +1,11 @@ -/* libhw/rp2040_gpioirq.h - Utilities for sharing the GPIO IRQ (IO_IRQ_BANK0) +/* libhw_cr/rp2040_gpioirq.h - Utilities for sharing the GPIO IRQ (IO_IRQ_BANK0) * * Copyright (C) 2025 Luke T. Shumaker <lukeshu@lukeshu.com> * SPDX-License-Identifier: AGPL-3.0-or-later */ -#ifndef _LIBHW_RP2040_GPIOIRQ_H_ -#define _LIBHW_RP2040_GPIOIRQ_H_ +#ifndef _LIBHW_CR_RP2040_GPIOIRQ_H_ +#define _LIBHW_CR_RP2040_GPIOIRQ_H_ #include <hardware/gpio.h> /* for enum gpio_irq_level */ @@ -30,4 +30,4 @@ typedef void (*gpioirq_handler_t)(void *arg, uint gpio, enum gpio_irq_level even */ void gpioirq_set_and_enable_exclusive_handler(uint gpio, enum gpio_irq_level event, gpioirq_handler_t fn, void *arg); -#endif /* _LIBHW_RP2040_GPIOIRQ_H_ */ +#endif /* _LIBHW_CR_RP2040_GPIOIRQ_H_ */ diff --git a/libhw/rp2040_hwspi.c b/libhw_cr/rp2040_hwspi.c index f747b1e..7b57792 100644 --- a/libhw/rp2040_hwspi.c +++ b/libhw_cr/rp2040_hwspi.c @@ -1,4 +1,4 @@ -/* libhw/rp2040_hwspi.c - <libhw/generic/spi.h> implementation for the RP2040's ARM Primecell SSP (PL022) +/* libhw_cr/rp2040_hwspi.c - <libhw/generic/spi.h> implementation for the RP2040's ARM Primecell SSP (PL022) * * Copyright (C) 2024-2025 Luke T. Shumaker <lukeshu@lukeshu.com> * SPDX-License-Identifier: AGPL-3.0-or-later diff --git a/libhw/rp2040_hwtimer.c b/libhw_cr/rp2040_hwtimer.c index ada6246..8227abb 100644 --- a/libhw/rp2040_hwtimer.c +++ b/libhw_cr/rp2040_hwtimer.c @@ -1,4 +1,4 @@ -/* libhw/rp2040_hwtimer.c - <libhw/generic/alarmclock.h> implementation for the RP2040's hardware timer +/* libhw_cr/rp2040_hwtimer.c - <libhw/generic/alarmclock.h> implementation for the RP2040's hardware timer * * Copyright (C) 2024-2025 Luke T. Shumaker <lukeshu@lukeshu.com> * SPDX-License-Identifier: AGPL-3.0-or-later diff --git a/libhw/rp2040_include/libhw/rp2040_hwspi.h b/libhw_cr/rp2040_include/libhw/rp2040_hwspi.h index eb54cdc..eb54cdc 100644 --- a/libhw/rp2040_include/libhw/rp2040_hwspi.h +++ b/libhw_cr/rp2040_include/libhw/rp2040_hwspi.h diff --git a/libhw/rp2040_include/libhw/rp2040_hwtimer.h b/libhw_cr/rp2040_include/libhw/rp2040_hwtimer.h index 40e4172..40e4172 100644 --- a/libhw/rp2040_include/libhw/rp2040_hwtimer.h +++ b/libhw_cr/rp2040_include/libhw/rp2040_hwtimer.h diff --git a/libhw/rp2040_include/libhw/w5500.h b/libhw_cr/rp2040_include/libhw/w5500.h index 51effba..51effba 100644 --- a/libhw/rp2040_include/libhw/w5500.h +++ b/libhw_cr/rp2040_include/libhw/w5500.h diff --git a/libhw/w5500.c b/libhw_cr/w5500.c index c4d36f3..295add2 100644 --- a/libhw/w5500.c +++ b/libhw_cr/w5500.c @@ -1,4 +1,4 @@ -/* libhw/w5500.c - <libhw/generic/net.h> implementation for the WIZnet W5500 chip +/* libhw_cr/w5500.c - <libhw/generic/net.h> implementation for the WIZnet W5500 chip * * Copyright (C) 2024-2025 Luke T. Shumaker <lukeshu@lukeshu.com> * SPDX-License-Identifier: AGPL-3.0-or-later diff --git a/libhw/w5500_ll.h b/libhw_cr/w5500_ll.h index 3822ad4..8f5f9ec 100644 --- a/libhw/w5500_ll.h +++ b/libhw_cr/w5500_ll.h @@ -1,4 +1,4 @@ -/* libhw/w5500_ll.h - Low-level header library for the WIZnet W5500 chip +/* libhw_cr/w5500_ll.h - Low-level header library for the WIZnet W5500 chip * * Based entirely on the W5500 datasheet, v1.1.0. * https://docs.wiznet.io/img/products/w5500/W5500_ds_v110e.pdf @@ -7,8 +7,8 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ -#ifndef _LIBHW_W5500_LL_H_ -#define _LIBHW_W5500_LL_H_ +#ifndef _LIBHW_CR_W5500_LL_H_ +#define _LIBHW_CR_W5500_LL_H_ #include <alloca.h> /* for alloca() */ #include <stdint.h> /* for uint{n}_t */ @@ -458,4 +458,4 @@ static_assert(sizeof(struct w5500ll_block_sock_reg) == 0x30); val; \ }) -#endif /* _LIBHW_W5500_LL_H_ */ +#endif /* _LIBHW_CR_W5500_LL_H_ */ diff --git a/libhw_generic/CMakeLists.txt b/libhw_generic/CMakeLists.txt index e38fbe9..b1632aa 100644 --- a/libhw_generic/CMakeLists.txt +++ b/libhw_generic/CMakeLists.txt @@ -8,7 +8,6 @@ target_include_directories(libhw_generic SYSTEM INTERFACE ${CMAKE_CURRENT_SOURCE target_link_libraries(libhw_generic INTERFACE libmisc libobj - libcr ) target_sources(libhw_generic INTERFACE diff --git a/libhw_generic/alarmclock.c b/libhw_generic/alarmclock.c index 7fd049e..31fbbaf 100644 --- a/libhw_generic/alarmclock.c +++ b/libhw_generic/alarmclock.c @@ -1,25 +1,9 @@ -/* libhw_generic/alarmclock.c - Device-independent <libhw/generic/alarmclock.h> utilities +/* libhw_generic/alarmclock.c - Device-independent <libhw/generic/alarmclock.h> storage * * Copyright (C) 2024-2025 Luke T. Shumaker <lukeshu@lukeshu.com> * SPDX-License-Identifier: AGPL-3.0-or-later */ -#include <libcr/coroutine.h> - #include <libhw/generic/alarmclock.h> lo_interface alarmclock bootclock = {0}; - -static void alarmclock_sleep_intrhandler(void *_arg) { - cid_t cid = *(cid_t *)_arg; - cr_unpause_from_intrhandler(cid); -} - -void alarmclock_sleep_until_ns(lo_interface alarmclock clock, uint64_t abstime_ns) { - bool saved = cr_save_and_disable_interrupts(); - cid_t cid = cr_getcid(); - struct alarmclock_trigger trigger; - LO_CALL(clock, add_trigger, &trigger, abstime_ns, alarmclock_sleep_intrhandler, &cid); - cr_pause_and_yield(); - cr_restore_interrupts(saved); -} |