diff options
author | Revo <projectrevotpp@hotmail.com> | 2020-06-25 01:30:36 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-25 01:30:36 -0400 |
commit | 40c3f6e85a2d25d3d98b2cfdaf1dd6872bbb4a6d (patch) | |
tree | a3b78fd54d27e7ead3c0ec3ff7e62ca87909a8e0 /arm7/lib | |
parent | ce09e79eb9ca2b384fb1c64f0946661b30ae75ea (diff) | |
parent | e34791ca4a781fc37717ac0ea7c2ac9fd5d65c2e (diff) |
Merge pull request #188 from Cleverking2003/master
OS_tick
Diffstat (limited to 'arm7/lib')
-rw-r--r-- | arm7/lib/include/OS_tick.h | 11 | ||||
-rw-r--r-- | arm7/lib/include/OS_timer.h | 6 | ||||
-rw-r--r-- | arm7/lib/src/OS_tick.c | 54 |
3 files changed, 71 insertions, 0 deletions
diff --git a/arm7/lib/include/OS_tick.h b/arm7/lib/include/OS_tick.h new file mode 100644 index 00000000..7ee9544a --- /dev/null +++ b/arm7/lib/include/OS_tick.h @@ -0,0 +1,11 @@ +#ifndef POKEDIAMOND_OS_TICK_H +#define POKEDIAMOND_OS_TICK_H + +#include "nitro/OS_tick_shared.h" + +void OS_InitTick(void); +u16 OS_IsTickAvailable(void); +void OSi_CountUpTick(void); +OSTick OS_GetTick(void); + +#endif diff --git a/arm7/lib/include/OS_timer.h b/arm7/lib/include/OS_timer.h new file mode 100644 index 00000000..fee42c6f --- /dev/null +++ b/arm7/lib/include/OS_timer.h @@ -0,0 +1,6 @@ +#ifndef POKEDIAMOND_OS_TIMER_H +#define POKEDIAMOND_OS_TIMER_H + +#include "nitro/OS_timer_shared.h" + +#endif diff --git a/arm7/lib/src/OS_tick.c b/arm7/lib/src/OS_tick.c new file mode 100644 index 00000000..e45b6833 --- /dev/null +++ b/arm7/lib/src/OS_tick.c @@ -0,0 +1,54 @@ +#include "OS_interrupt.h" +#include "OS_system.h" +#include "OS_tick.h" +#include "OS_timer.h" +#include "function_target.h" + +extern void OSi_SetTimerReserved(u32); + +static u16 OSi_UseTick; +static OSTick OSi_TickCounter; +static BOOL OSi_NeedResetTimer; + +ARM_FUNC void OS_InitTick(void) { + if (OSi_UseTick == 0) { + OSi_UseTick = 1; + OSi_SetTimerReserved(0); + OSi_TickCounter = 0; + OS_SetTimerControl(OS_TIMER_0, 0); + OS_SetTimerCount(OS_TIMER_0, 0); + OS_SetTimerControl(OS_TIMER_0, 0xc1); + OS_SetIrqFunction(8, OSi_CountUpTick); + (void)OS_EnableIrqMask(8); + OSi_NeedResetTimer = 0; + } +} + +ARM_FUNC u16 OS_IsTickAvailable(void) { + return OSi_UseTick; +} + +ARM_FUNC void OSi_CountUpTick(void) { + OSi_TickCounter++; + if (OSi_NeedResetTimer != 0) { + OS_SetTimerControl(OS_TIMER_0, 0); + OS_SetTimerCount(OS_TIMER_0, 0); + OS_SetTimerControl(OS_TIMER_0, 0xc1); + OSi_NeedResetTimer = 0; + } + OSi_EnterTimerCallback(0, (void(*)(void*))OSi_CountUpTick, NULL); +} + +ARM_FUNC OSTick OS_GetTick(void) { + OSIntrMode prev = OS_DisableInterrupts(); + vu16 countL = *(REGType16 *)((u32)®_OS_TM0CNT_L + OS_TIMER_0 * 4); + vu64 countH = OSi_TickCounter & 0xffffffffffffULL; + + if (reg_OS_IF & 8 && !(countL & 0x8000)) { + countH++; + } + + (void)OS_RestoreInterrupts(prev); + + return (countH << 16) | countL; +} |