summaryrefslogtreecommitdiff
path: root/arm9/lib/src
diff options
context:
space:
mode:
authorred031000 <rubenru09@aol.com>2020-06-13 17:59:30 +0100
committerred031000 <rubenru09@aol.com>2020-06-13 18:00:14 +0100
commit339366f19680e505d5ff9763375f0fc159b5baed (patch)
tree8793acb7d216df9adba3b87aed39b54f177b7b9a /arm9/lib/src
parentc4263506fa96acc210d1cf356023a3ffde805a0b (diff)
arm9 OS_tick
Diffstat (limited to 'arm9/lib/src')
-rw-r--r--arm9/lib/src/OS_tick.c70
1 files changed, 70 insertions, 0 deletions
diff --git a/arm9/lib/src/OS_tick.c b/arm9/lib/src/OS_tick.c
new file mode 100644
index 00000000..f5f2df30
--- /dev/null
+++ b/arm9/lib/src/OS_tick.c
@@ -0,0 +1,70 @@
+#include "function_target.h"
+#include "OS_tick.h"
+#include "OS_interrupt.h"
+#include "OS_timer.h"
+#include "OS_system.h"
+
+static u16 OSi_UseTick = FALSE;
+vu64 OSi_TickCounter;
+BOOL OSi_NeedResetTimer = FALSE;
+
+extern void OSi_SetTimerReserved(u32 param1);
+
+ARM_FUNC void OS_InitTick(void)
+{
+ if (OSi_UseTick)
+ {
+ return;
+ }
+ OSi_UseTick = 1;
+ OSi_SetTimerReserved(0);
+ OSi_TickCounter = 0;
+ reg_OS_TM0CNT_H = 0;
+ reg_OS_TM0CNT_L = 0;
+ reg_OS_TM0CNT_H = 0xc1;
+ OS_SetIrqFunction(8, OSi_CountUpTick);
+ (void)OS_EnableIrqMask(8);
+ OSi_NeedResetTimer = FALSE;
+}
+
+ARM_FUNC BOOL OS_IsTickAvailable(void)
+{
+ return OSi_UseTick;
+}
+
+ARM_FUNC static void OSi_CountUpTick(void)
+{
+ OSi_TickCounter++;
+
+ if (OSi_NeedResetTimer)
+ {
+ OS_SetTimerControl(OS_TIMER_0, 0);
+ OS_SetTimerCount(OS_TIMER_0, 0);
+ OS_SetTimerControl(OS_TIMER_0, OSi_TICK_TIMERCONTROL);
+
+ OSi_NeedResetTimer = FALSE;
+ }
+
+ OSi_EnterTimerCallback(OS_TIMER_0, (void (*)(void *))OSi_CountUpTick, 0);
+}
+
+ARM_FUNC OSTick OS_GetTick(void)
+{
+ OSIntrMode prev = OS_DisableInterrupts();
+ vu16 countL = *(REGType16 *)((u32)&reg_OS_TM0CNT_L + OS_TIMER_0 * 4);
+ vu64 countH = OSi_TickCounter & 0xffffffffffffULL;
+
+ if (reg_OS_IF & OS_IE_TIMER0 && !(countL & 0x8000))
+ {
+ countH++;
+ }
+
+ (void)OS_RestoreInterrupts(prev);
+
+ return (countH << 16) | countL;
+}
+
+ARM_FUNC u16 OS_GetTickLo(void)
+{
+ return reg_OS_TM0CNT_L;
+}