aboutsummaryrefslogtreecommitdiff
path: root/bcmclock.h
diff options
context:
space:
mode:
authorvetch <vetch97@gmail.com>2020-01-02 17:54:31 +0100
committervetch <vetch97@gmail.com>2020-01-02 17:54:31 +0100
commitab7b754bb32022336527c1a2d5d710b95a589d0e (patch)
tree19f508f06c72efcbdd2cfad46949ed6f1ae45a3c /bcmclock.h
parent5e1e6796109c892c4300c3da17c35e7874a40107 (diff)
parent6bf5a3b8c6e8a5d1cb3fb4880a5d9688ab094c62 (diff)
downloadrpi-MMU-example-ab7b754bb32022336527c1a2d5d710b95a589d0e.tar.gz
rpi-MMU-example-ab7b754bb32022336527c1a2d5d710b95a589d0e.zip
Merge branch 'bob' of https://repo.or.cz/RPi-MMU-example into alice
# Conflicts: # .gitignore # PL0_test.ld # demo_functionality.c # interrupt_vector.S # interrupts.c # kernel.c # memory.h
Diffstat (limited to 'bcmclock.h')
-rw-r--r--bcmclock.h35
1 files changed, 35 insertions, 0 deletions
diff --git a/bcmclock.h b/bcmclock.h
new file mode 100644
index 0000000..dd7136b
--- /dev/null
+++ b/bcmclock.h
@@ -0,0 +1,35 @@
+#ifndef BCMCLOCK_H
+#define BCMCLOCK_H
+
+#include <stdint.h>
+
+#include "global.h"
+
+#define ST_BASE (PERIF_BASE + 0x3000) // System Timer
+
+#define ST_CS (ST_BASE + 0x0) // System Timer Control/Status
+#define ST_CLO (ST_BASE + 0x4) // System Timer Counter Lower 32 bits
+#define ST_CHI (ST_BASE + 0x8) // System Timer Counter Higher 32 bits
+#define ST_C0 (ST_BASE + 0xC) // System Timer Compare 0
+#define ST_C1 (ST_BASE + 0x10) // System Timer Compare 1
+#define ST_C2 (ST_BASE + 0x14) // System Timer Compare 2
+#define ST_C3 (ST_BASE + 0x18) // System Timer Compare 3
+
+static inline void bcmclk_enable_timer_irq(void)
+{
+ *(uint32_t volatile*) ARM_ENABLE_IRQS_1 = 1 << 3;
+}
+
+static inline void bcmclk_disable_timer_irq(void)
+{
+ *(uint32_t volatile*) ARM_DISABLE_IRQS_1 = 1 << 3;
+}
+
+static inline void bcmclk_irq_settimeout(uint32_t timeout)
+{
+ uint32_t clock_now = *(uint32_t volatile*) ST_CLO;
+ *(uint32_t volatile*) ST_C3 = clock_now + timeout;
+ *(uint32_t volatile*) ST_CS = 1 << 3;
+}
+
+#endif // BCMCLOCK_H