From bef877266c6af17c90581f56f5d4217fd4ecce23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Calixte?= Date: Sat, 20 Mar 2021 11:42:10 +0100 Subject: better names --- arm9/src/timer3.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 arm9/src/timer3.c (limited to 'arm9/src/timer3.c') diff --git a/arm9/src/timer3.c b/arm9/src/timer3.c new file mode 100644 index 00000000..7bf66398 --- /dev/null +++ b/arm9/src/timer3.c @@ -0,0 +1,67 @@ +#include "timer3.h" + +struct Timer3Data timer3_data; + + +THUMB_FUNC void Init_Timer3() +{ + timer3_data.Timer3Counter = 0; + timer3_data.NeedReset = FALSE; + + reg_OS_TM3CNT_H = 0; + reg_OS_TM3CNT_L = 0; + reg_OS_TM3CNT_H = 0xc1; // start timer3 with f/64 and irq enable + + OS_SetIrqFunction(0x40, &CountUpTimer3); + OS_EnableIrqMask(0x40); // irq on timer3 overflow +} + + +THUMB_FUNC void CountUpTimer3() +{ + timer3_data.Timer3Counter++; + + if (timer3_data.NeedReset) + { + reg_OS_TM3CNT_H = 0; + reg_OS_TM3CNT_L = 0; + reg_OS_TM3CNT_H = 0xc1; + timer3_data.NeedReset = FALSE; + } + u32 *ptr = (u32 *)0x027e0000; + u32 offset = 0xffe; + ptr[offset] |= 0x40; + + OS_SetIrqFunction(0x40, &CountUpTimer3); +} + +THUMB_FUNC u64 internal_GetTimer3Count() +{ + OSIntrMode intr_mode = OS_DisableInterrupts(); + + vu16 timer3 = reg_OS_TM3CNT_L; + vu64 timer3_counter = timer3_data.Timer3Counter & 0x0000ffffffffffff; + + if (reg_OS_IF & 64 && !(timer3 & 0x8000)) + { + timer3_counter++; + } + + OS_RestoreInterrupts(intr_mode); + return (timer3_counter << 16) | timer3; +} + +THUMB_FUNC u64 GetTimer3Count() +{ + return internal_GetTimer3Count(); +} + +THUMB_FUNC u64 Timer3CountToMilliSeconds(u64 count) +{ + return (count *64) / 33514; +} + +THUMB_FUNC u64 Timer3CountToSeconds(u64 count) +{ + return (count *64) / HW_SYSTEM_CLOCK; +} -- cgit v1.2.3 From 8bfbd3f4983d0843b352b403f08c2894d1001ba1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Calixte?= Date: Sun, 21 Mar 2021 09:17:05 +0100 Subject: use HW_INTR_CHECK_BUF macro --- arm9/src/timer3.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'arm9/src/timer3.c') diff --git a/arm9/src/timer3.c b/arm9/src/timer3.c index 7bf66398..75689326 100644 --- a/arm9/src/timer3.c +++ b/arm9/src/timer3.c @@ -28,9 +28,8 @@ THUMB_FUNC void CountUpTimer3() reg_OS_TM3CNT_H = 0xc1; timer3_data.NeedReset = FALSE; } - u32 *ptr = (u32 *)0x027e0000; - u32 offset = 0xffe; - ptr[offset] |= 0x40; + + *(vu32 *)HW_INTR_CHECK_BUF |= 0x40; OS_SetIrqFunction(0x40, &CountUpTimer3); } -- cgit v1.2.3 From 2aa4e10d388c15f0c4a2f7bf5a27c7560d80ed7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Calixte?= Date: Sun, 21 Mar 2021 09:20:11 +0100 Subject: use hex constant for flag check --- arm9/src/timer3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'arm9/src/timer3.c') diff --git a/arm9/src/timer3.c b/arm9/src/timer3.c index 75689326..1799fd24 100644 --- a/arm9/src/timer3.c +++ b/arm9/src/timer3.c @@ -41,7 +41,7 @@ THUMB_FUNC u64 internal_GetTimer3Count() vu16 timer3 = reg_OS_TM3CNT_L; vu64 timer3_counter = timer3_data.Timer3Counter & 0x0000ffffffffffff; - if (reg_OS_IF & 64 && !(timer3 & 0x8000)) + if (reg_OS_IF & 0x40 && !(timer3 & 0x8000)) { timer3_counter++; } -- cgit v1.2.3