aboutsummaryrefslogtreecommitdiffstats
path: root/src/ar100/timer.c
diff options
context:
space:
mode:
authorElias Bakken <elias@iagent.no>2023-02-21 02:15:01 +0100
committerGitHub <noreply@github.com>2023-02-20 20:15:01 -0500
commitb7978d37b360fb270782a8db5d690342654e6977 (patch)
tree5383243d85dee85a521f466ac966460ee092efa2 /src/ar100/timer.c
parentd7bd7f1f4ba6cecd19daa566fdc1864561269ae1 (diff)
downloadkutter-b7978d37b360fb270782a8db5d690342654e6977.tar.gz
kutter-b7978d37b360fb270782a8db5d690342654e6977.tar.xz
kutter-b7978d37b360fb270782a8db5d690342654e6977.zip
ar100: Support for ar100 (#6054)
Add files to support AR100 Signed-off-by: Elias Bakken <elias@iagent.no>
Diffstat (limited to 'src/ar100/timer.c')
-rw-r--r--src/ar100/timer.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/ar100/timer.c b/src/ar100/timer.c
new file mode 100644
index 00000000..140d9ed0
--- /dev/null
+++ b/src/ar100/timer.c
@@ -0,0 +1,52 @@
+// Timer functions for ar100
+//
+// Copyright (C) 2020-2021 Elias Bakken <elias@iagent.no>
+//
+// This file may be distributed under the terms of the GNU GPLv3 license.
+
+#include "timer.h"
+#include "board/timer_irq.h"
+#include "board/misc.h"
+
+volatile static uint32_t timer_compare;
+static uint8_t interrupt_seen;
+
+uint8_t timer_interrupt_pending(void){
+ if(interrupt_seen){
+ return 0;
+ }
+ if(timer_is_before(mfspr(SPR_TICK_TTCR_ADDR), timer_compare)){
+ return 0;
+ }
+
+ return 1;
+}
+void timer_clear_interrupt(void){
+ interrupt_seen = 1;
+}
+// Set the next timer wake up time
+void timer_set(uint32_t value){
+ timer_compare = value;
+ interrupt_seen = 0;
+}
+
+// Return the current time (in absolute clock ticks).
+uint32_t timer_read_time(void){
+ return mfspr(SPR_TICK_TTCR_ADDR);
+}
+
+void timer_reset(void){
+ mtspr(SPR_TICK_TTCR_ADDR, 0);
+}
+
+// Activate timer dispatch as soon as possible
+void timer_kick(void){
+ timer_set(timer_read_time() + 50);
+}
+
+void timer_init(void){
+ interrupt_seen = 1;
+ mtspr(SPR_TICK_TTMR_ADDR, 3<<30); // continous
+ timer_kick();
+}
+DECL_INIT(timer_init);