From ea1fc9a0c36fea36cc5eced2316b321735ed1aa5 Mon Sep 17 00:00:00 2001 From: Egor Ananyin Date: Wed, 24 Jun 2020 20:19:35 +0300 Subject: OS_tick done --- arm7/lib/include/OS_tick.h | 11 ++++++++++ arm7/lib/include/OS_timer.h | 32 +++++++++++++++++++++++++++ arm7/lib/src/OS_tick.c | 53 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 96 insertions(+) create mode 100644 arm7/lib/include/OS_tick.h create mode 100644 arm7/lib/include/OS_timer.h create mode 100644 arm7/lib/src/OS_tick.c (limited to 'arm7/lib') diff --git a/arm7/lib/include/OS_tick.h b/arm7/lib/include/OS_tick.h new file mode 100644 index 00000000..892e0499 --- /dev/null +++ b/arm7/lib/include/OS_tick.h @@ -0,0 +1,11 @@ +#ifndef POKEDIAMOND_OS_TICK_H +#define POKEDIAMOND_OS_TICK_H + +#include "OS_timer.h" + +void OS_InitTick(void); +u16 OS_IsTickAvailable(void); +void OSi_CountUpTick(void); +u64 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..697842fe --- /dev/null +++ b/arm7/lib/include/OS_timer.h @@ -0,0 +1,32 @@ +#ifndef POKEDIAMOND_OS_TIMER_H +#define POKEDIAMOND_OS_TIMER_H + +#include "consts.h" + +typedef enum +{ + OS_TIMER_PRESCALER_1 = (0UL << REG_OS_TM0CNT_H_PS_SHIFT), + OS_TIMER_PRESCALER_64 = (1UL << REG_OS_TM0CNT_H_PS_SHIFT), + OS_TIMER_PRESCALER_256 = (2UL << REG_OS_TM0CNT_H_PS_SHIFT), + OS_TIMER_PRESCALER_1024 = (3UL << REG_OS_TM0CNT_H_PS_SHIFT) +} OSTimerPrescaler; + +typedef enum +{ + OS_TIMER_0 = 0, + OS_TIMER_1 = 1, + OS_TIMER_2 = 2, + OS_TIMER_3 = 3 +} OSTimer; + +static inline void OS_SetTimerCount(OSTimer id, u16 count) +{ + *((REGType16 *)((u32)®_OS_TM0CNT_L + id * 4)) = count; +} + +static inline void OS_SetTimerControl(OSTimer id, u16 control) +{ + *((REGType16 *)((u32)®_OS_TM0CNT_H + id * 4)) = control; +} + +#endif \ No newline at end of file diff --git a/arm7/lib/src/OS_tick.c b/arm7/lib/src/OS_tick.c new file mode 100644 index 00000000..063b05c9 --- /dev/null +++ b/arm7/lib/src/OS_tick.c @@ -0,0 +1,53 @@ +#include "OS_interrupt.h" +#include "OS_system.h" +#include "OS_tick.h" +#include "function_target.h" + +extern void OSi_SetTimerReserved(u32); + +static u16 OSi_UseTick; +static u64 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 u64 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; +} -- cgit v1.2.3 From 60d9344c63e43abd81ccca87891b2ccdc05c6f93 Mon Sep 17 00:00:00 2001 From: Egor Ananyin Date: Wed, 24 Jun 2020 20:20:23 +0300 Subject: eof --- arm7/lib/include/OS_timer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'arm7/lib') diff --git a/arm7/lib/include/OS_timer.h b/arm7/lib/include/OS_timer.h index 697842fe..b00967ca 100644 --- a/arm7/lib/include/OS_timer.h +++ b/arm7/lib/include/OS_timer.h @@ -29,4 +29,4 @@ static inline void OS_SetTimerControl(OSTimer id, u16 control) *((REGType16 *)((u32)®_OS_TM0CNT_H + id * 4)) = control; } -#endif \ No newline at end of file +#endif -- cgit v1.2.3 From 2f08757512dc9a57c66226ccbc56852598917c14 Mon Sep 17 00:00:00 2001 From: Egor Ananyin Date: Wed, 24 Jun 2020 20:31:49 +0300 Subject: Shared things --- arm7/lib/include/OS_tick.h | 4 ++-- arm7/lib/include/OS_timer.h | 28 +--------------------------- arm7/lib/src/OS_tick.c | 5 +++-- 3 files changed, 6 insertions(+), 31 deletions(-) (limited to 'arm7/lib') diff --git a/arm7/lib/include/OS_tick.h b/arm7/lib/include/OS_tick.h index 892e0499..7ee9544a 100644 --- a/arm7/lib/include/OS_tick.h +++ b/arm7/lib/include/OS_tick.h @@ -1,11 +1,11 @@ #ifndef POKEDIAMOND_OS_TICK_H #define POKEDIAMOND_OS_TICK_H -#include "OS_timer.h" +#include "nitro/OS_tick_shared.h" void OS_InitTick(void); u16 OS_IsTickAvailable(void); void OSi_CountUpTick(void); -u64 OS_GetTick(void); +OSTick OS_GetTick(void); #endif diff --git a/arm7/lib/include/OS_timer.h b/arm7/lib/include/OS_timer.h index b00967ca..fee42c6f 100644 --- a/arm7/lib/include/OS_timer.h +++ b/arm7/lib/include/OS_timer.h @@ -1,32 +1,6 @@ #ifndef POKEDIAMOND_OS_TIMER_H #define POKEDIAMOND_OS_TIMER_H -#include "consts.h" - -typedef enum -{ - OS_TIMER_PRESCALER_1 = (0UL << REG_OS_TM0CNT_H_PS_SHIFT), - OS_TIMER_PRESCALER_64 = (1UL << REG_OS_TM0CNT_H_PS_SHIFT), - OS_TIMER_PRESCALER_256 = (2UL << REG_OS_TM0CNT_H_PS_SHIFT), - OS_TIMER_PRESCALER_1024 = (3UL << REG_OS_TM0CNT_H_PS_SHIFT) -} OSTimerPrescaler; - -typedef enum -{ - OS_TIMER_0 = 0, - OS_TIMER_1 = 1, - OS_TIMER_2 = 2, - OS_TIMER_3 = 3 -} OSTimer; - -static inline void OS_SetTimerCount(OSTimer id, u16 count) -{ - *((REGType16 *)((u32)®_OS_TM0CNT_L + id * 4)) = count; -} - -static inline void OS_SetTimerControl(OSTimer id, u16 control) -{ - *((REGType16 *)((u32)®_OS_TM0CNT_H + id * 4)) = control; -} +#include "nitro/OS_timer_shared.h" #endif diff --git a/arm7/lib/src/OS_tick.c b/arm7/lib/src/OS_tick.c index 063b05c9..e45b6833 100644 --- a/arm7/lib/src/OS_tick.c +++ b/arm7/lib/src/OS_tick.c @@ -1,12 +1,13 @@ #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 u64 OSi_TickCounter; +static OSTick OSi_TickCounter; static BOOL OSi_NeedResetTimer; ARM_FUNC void OS_InitTick(void) { @@ -38,7 +39,7 @@ ARM_FUNC void OSi_CountUpTick(void) { OSi_EnterTimerCallback(0, (void(*)(void*))OSi_CountUpTick, NULL); } -ARM_FUNC u64 OS_GetTick(void) { +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; -- cgit v1.2.3