summaryrefslogtreecommitdiff
path: root/libcpu/aarch64/common/gtimer.c
diff options
context:
space:
mode:
Diffstat (limited to 'libcpu/aarch64/common/gtimer.c')
-rw-r--r--libcpu/aarch64/common/gtimer.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/libcpu/aarch64/common/gtimer.c b/libcpu/aarch64/common/gtimer.c
new file mode 100644
index 0000000000..74187a92cb
--- /dev/null
+++ b/libcpu/aarch64/common/gtimer.c
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2011-12-20 GuEe-GUI first version
+ */
+
+#include <rtthread.h>
+#include <rthw.h>
+#include <gtimer.h>
+#include <cpuport.h>
+
+#define EL1_PHY_TIMER_IRQ_NUM 30
+
+static volatile rt_uint64_t timer_step;
+
+static void rt_hw_timer_isr(int vector, void *parameter)
+{
+ rt_hw_set_gtimer_val(timer_step);
+ rt_tick_increase();
+}
+
+void rt_hw_gtimer_init(void)
+{
+ rt_hw_interrupt_install(EL1_PHY_TIMER_IRQ_NUM, rt_hw_timer_isr, RT_NULL, "tick");
+ __ISB();
+ timer_step = rt_hw_get_gtimer_frq();
+ __DSB();
+ timer_step /= RT_TICK_PER_SECOND;
+ rt_hw_gtimer_local_enable();
+}
+
+void rt_hw_gtimer_local_enable(void)
+{
+ rt_hw_gtimer_disable();
+ rt_hw_set_gtimer_val(timer_step);
+ rt_hw_interrupt_umask(EL1_PHY_TIMER_IRQ_NUM);
+ rt_hw_gtimer_enable();
+}
+
+void rt_hw_gtimer_local_disable(void)
+{
+ rt_hw_gtimer_disable();
+ rt_hw_interrupt_mask(EL1_PHY_TIMER_IRQ_NUM);
+}