aboutsummaryrefslogtreecommitdiff
path: root/tests/simple_mesh/test.c
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2025-02-24 21:31:46 +0200
committerKimplul <kimi.h.kuparinen@gmail.com>2025-02-24 21:31:46 +0200
commite991095180f774e3582329447c291a11499989ba (patch)
tree0708d2308a229b932a84d8ae803b31d296f9fc0f /tests/simple_mesh/test.c
parent238116c1cf08b93335abd493df110a669786553e (diff)
downloadgran-e991095180f774e3582329447c291a11499989ba.tar.gz
gran-e991095180f774e3582329447c291a11499989ba.zip
overhaul meshes
+ Previous name was grid
Diffstat (limited to 'tests/simple_mesh/test.c')
-rw-r--r--tests/simple_mesh/test.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/simple_mesh/test.c b/tests/simple_mesh/test.c
new file mode 100644
index 0000000..b1bbe84
--- /dev/null
+++ b/tests/simple_mesh/test.c
@@ -0,0 +1,55 @@
+__attribute__((always_inline))
+static inline void print_int8(volatile char *uart, unsigned x)
+{
+ *uart = ((x >> 4) & 0xf) + '0';
+ *uart = ((x >> 0) & 0xf) + '0';
+}
+
+__attribute__((always_inline))
+static inline void print_addr(volatile char *uart, unsigned x, unsigned y)
+{
+ *uart = '(';
+ print_int8(uart, x);
+ *uart = ',';
+ *uart = ' ';
+ print_int8(uart, y);
+ *uart = ')';
+ *uart = '\n';
+}
+
+__attribute__((always_inline))
+static inline unsigned wrap(unsigned x, unsigned X)
+{
+ return x + 1 >= X ? 0 : x + 1;
+}
+
+__attribute__((always_inline))
+static inline unsigned next_idx(unsigned x, unsigned y, unsigned X, unsigned Y)
+{
+ unsigned yi = wrap(y, Y);
+ unsigned xi = yi < y ? wrap(x, X) : x;
+
+ return (xi << 16) | yi;
+}
+
+void _start(unsigned x, unsigned y, unsigned X, unsigned Y)
+{
+ volatile char *uart = (char *)4096;
+ volatile unsigned *control = (unsigned *)(1ULL << 48);
+
+ if (x == 0 && y == 2) {
+ goto do_work;
+ } else {
+ while (*control != ((x << 16) | y)) {}
+ }
+
+do_work:
+ print_addr(uart, x, y);
+ *control = next_idx(x, y, X, Y);
+
+ if (x == X - 1 && y == Y - 1)
+ asm("ebreak");
+
+ /* otherwise just loop */
+ while (1) {}
+}