aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2024-12-04 00:47:54 -0700
committerJosh Rahm <joshuarahm@gmail.com>2024-12-04 00:47:54 -0700
commit03b84b89f6361df556749a4c73679a6cbcedd28a (patch)
treeee5a6569feddc3bc32ab0bdb485affb56d7fafbe
parentd6d04862de9126d0930ae1f4b95ff6077c6eda63 (diff)
downloadch573-03b84b89f6361df556749a4c73679a6cbcedd28a.tar.gz
ch573-03b84b89f6361df556749a4c73679a6cbcedd28a.tar.bz2
ch573-03b84b89f6361df556749a4c73679a6cbcedd28a.zip
Implemented listener system for systick.
-rw-r--r--include/systick.h9
-rw-r--r--linker/ls.ld6
-rw-r--r--src/main.c4
-rw-r--r--src/systick.c7
4 files changed, 26 insertions, 0 deletions
diff --git a/include/systick.h b/include/systick.h
index 8933a31..285b9b8 100644
--- a/include/systick.h
+++ b/include/systick.h
@@ -2,8 +2,17 @@
#include <stdint.h>
+typedef void (*systick_cb_t)(void);
+
void set_systick(uint64_t systick_value);
uint64_t get_systick();
int systick_interrupt();
+
+#define On_SysTick() \
+ static void __local_on_systick__(void); \
+ __attribute__(( \
+ __section__(".systick_callbacks"))) static volatile systick_cb_t \
+ __FILE__##__LINE__ = __local_on_systick__; \
+ static void __local_on_systick__()
diff --git a/linker/ls.ld b/linker/ls.ld
index 4ac7dc6..08e1901 100644
--- a/linker/ls.ld
+++ b/linker/ls.ld
@@ -36,6 +36,12 @@ SECTIONS
CLOCK_CHANGE_LISTENERS_END = .;
} > flash AT>flash
+ .systick_callbacks : ALIGN(0x04) {
+ SYSTICK_LISTENERS_START = .;
+ KEEP(*(.systick_callbacks));
+ SYSTICK_LISTENERS_END = .;
+ } > flash AT>flash
+
ISR_VECTOR_IN_FLASH = LOADADDR(.isr_vector);
.isr_vector : ALIGN(0x04) {
ISR_VECTOR_START = .;
diff --git a/src/main.c b/src/main.c
index 9f5808b..c80ab30 100644
--- a/src/main.c
+++ b/src/main.c
@@ -250,3 +250,7 @@ int main(void)
return 0;
}
+
+On_SysTick() {
+ printf("Systick BOI!\n");
+}
diff --git a/src/systick.c b/src/systick.c
index 506f6df..3cd7bfa 100644
--- a/src/systick.c
+++ b/src/systick.c
@@ -28,7 +28,14 @@ int systick_interrupt()
return SYSTICK_I.counter_interrupt_flag.get(SYSTICK);
}
+extern systick_cb_t SYSTICK_LISTENERS_START;
+extern systick_cb_t SYSTICK_LISTENERS_END;
IRQ(systick)
{
+ systick_cb_t* cur = &SYSTICK_LISTENERS_START;
+ while (cur != &SYSTICK_LISTENERS_END) {
+ (*cur)();
+ ++cur;
+ }
SYSTICK_I.counter_interrupt_flag.set(SYSTICK, 0);
}