From 1dd141a11f808f0ebef30ce40407f35f63dfed87 Mon Sep 17 00:00:00 2001 From: nakasima Date: Thu, 18 Dec 2008 01:32:38 +0000 Subject: [PATCH] =?UTF-8?q?=E3=83=81=E3=83=83=E3=82=AF=E4=BF=AE=E6=AD=A3?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-09-30%20-%20paladin.7z/paladin/ctr_firmware@120 b871894f-2f95-9b40-918c-086798483c85 --- .../build/libraries/os/common/os_tick.c | 26 ++++++++---- .../bootrom/include/brom/os/ARM11/interrupt.h | 27 ++++++++++++ .../bootrom/include/brom/os/ARM9/interrupt.h | 16 +++---- trunk/bootrom/include/brom/os/ARM9/timer.h | 42 ++++++++++++++++--- trunk/bootrom/include/brom/os/common/tick.h | 12 ++++-- 5 files changed, 98 insertions(+), 25 deletions(-) diff --git a/trunk/bootrom/build/libraries/os/common/os_tick.c b/trunk/bootrom/build/libraries/os/common/os_tick.c index d560931..472f965 100644 --- a/trunk/bootrom/build/libraries/os/common/os_tick.c +++ b/trunk/bootrom/build/libraries/os/common/os_tick.c @@ -75,7 +75,7 @@ void osInitTick(void) #ifdef SDK_ARM11 osStopTimer(); - osStartTimer(OS_TICK_LO_MASK+1, 0); + osStartTimer(OS_TICK_LO_LIMIT, 0); #else // SDK_ARM9 //---- OS reserves OSi_TICK_TIMER timer SDK_ASSERT(!i_osIsTimerReserved(OSi_TICK_TIMER)); @@ -131,7 +131,7 @@ static void i_osCountUpTick(void) { #ifdef SDK_ARM11 osStopTimer(); - osStartTimer(OS_TICK_LO_MASK+1, 0); + osStartTimer(OS_TICK_LO_LIMIT, 0); #else // SDK_ARM9 osSetTimerControl(OSi_TICK_TIMER, 0); osSetTimerCount((OSTimer)OSi_TICK_TIMER, (u16)0); @@ -164,27 +164,34 @@ u64 osGetTick(void) SDK_ASSERT(i_osUseTick); #ifdef SDK_ARM11 - countL = reg_OS_TM_COUNT; - countH = i_osTickCounter << OS_TICK_HI_SHIFT; + countL = OS_TICK_LO_LIMIT - reg_OS_TM_COUNT; #else // SDK_ARM9 countL = *(REGType16 *)((u32)REG_TM0CNT_L_ADDR + OSi_TICK_TIMER * 4); +#endif // SDK_ARM9 countH = i_osTickCounter; //---- check if timer interrupt bit is on - if (reg_OS_IF & OSi_TICK_IE_TIMER && !(countL & 0x8000)) + if (osIsInterruptPending(OSi_TICK_IE_TIMER_ID) && + // countLが0xFFFFで直後に割り込み要求が来た場合の対策 +#ifdef SDK_ARM11 + // ダウンカウンタなので + (countL & OS_TICK_LO_MSB) +#else // SDK_ARM9 + // アップカウンタなので + !(countL & OS_TICK_LO_MSB) +#endif // SDK_ARM9 + ) { countH++; } countH <<= OS_TICK_HI_SHIFT; -#endif // SDK_ARM9 (void)osRestoreInterrupts(prev); return countH | countL; } -#ifdef SDK_ARM9 /*---------------------------------------------------------------------------* Name: osGetTickLo @@ -197,9 +204,12 @@ u64 osGetTick(void) u16 osGetTickLo(void) { SDK_ASSERT(OSi_UseTick); +#ifdef SDK_ARM11 + return reg_OS_TM_COUNT; +#else // SDK_ARM9 return *(REGType16 *)((u32)REG_TM0CNT_L_ADDR + OSi_TICK_TIMER * 4); -} #endif // SDK_ARM9 +} /*---------------------------------------------------------------------------* Name: i_osSetTick diff --git a/trunk/bootrom/include/brom/os/ARM11/interrupt.h b/trunk/bootrom/include/brom/os/ARM11/interrupt.h index c3df901..38b625c 100644 --- a/trunk/bootrom/include/brom/os/ARM11/interrupt.h +++ b/trunk/bootrom/include/brom/os/ARM11/interrupt.h @@ -76,6 +76,33 @@ BOOL osDisableInterruptID( OSIntrID id ); *---------------------------------------------------------------------------*/ BOOL osRestoreInterruptID( OSIntrID id, BOOL state ); +/*---------------------------------------------------------------------------* + Name: osIsInterruptIDPending + + Description: set Interrupt Clear Pending Register + + Arguments: Interrupt Distributor ID + + Returns: TRUE if last state is pending + *---------------------------------------------------------------------------*/ +static inline BOOL osIsInterruptPending( OSIntrID id ) +{ +#ifdef SDK_ARM11 + u32 ofs = id/32; + u32 sft = id%32; + BOOL retval; + + retval = TRUE & (reg_OS_IDR_SET_PND[ofs] >> sft); +#else // SDK_ARM9 + OSIntrMask prep = reg_OS_IF; + BOOL retval; + + retval = TRUE & (BOOL)(prep >> id); +#endif // SDK_ARM9 + + return retval; +} + /*---------------------------------------------------------------------------* Name: osSetInterruptPendingID diff --git a/trunk/bootrom/include/brom/os/ARM9/interrupt.h b/trunk/bootrom/include/brom/os/ARM9/interrupt.h index 2c425b9..0cea514 100644 --- a/trunk/bootrom/include/brom/os/ARM9/interrupt.h +++ b/trunk/bootrom/include/brom/os/ARM9/interrupt.h @@ -177,18 +177,18 @@ BOOL osClearInterruptPendingID( OSIntrID id ); *---------------------------------------------------------------------------*/ static inline BOOL osIsInterruptPending( OSIntrID id ) { -#ifdef SDK_ARM9 - OSIntrMask prep = reg_OS_IF; - BOOL retval; - - retval = TRUE & (BOOL)(prep >> id); -#else // MPCORE +#ifdef SDK_ARM11 u32 ofs = id/32; u32 sft = id%32; BOOL retval; - retval = TRUE & (reg_OS_IDR_SET_PENDING_WP[ofs] >> sft); -#endif // MPCORE + retval = TRUE & (reg_OS_IDR_SET_PND[ofs] >> sft); +#else // SDK_ARM9 + OSIntrMask prep = reg_OS_IF; + BOOL retval; + + retval = TRUE & (BOOL)(prep >> id); +#endif // SDK_ARM9 return retval; } diff --git a/trunk/bootrom/include/brom/os/ARM9/timer.h b/trunk/bootrom/include/brom/os/ARM9/timer.h index 31aee6f..01d1f59 100644 --- a/trunk/bootrom/include/brom/os/ARM9/timer.h +++ b/trunk/bootrom/include/brom/os/ARM9/timer.h @@ -28,9 +28,23 @@ extern "C" { #include -#ifndef SDK_ARM11 - //---------------------------------------------------------------------- +#ifdef SDK_ARM11 + +//---- pre-scaler +typedef u8 OSTimerPrescaler; + +//---- timer number +typedef enum +{ + OS_TIMER_0 = 0, + OS_TIMER_1 = 1, + OS_TIMER_NUM +} +OSTimer; + +#else // SDK_ARM9 + //---- pre-scaler typedef enum { @@ -48,7 +62,7 @@ typedef enum OS_TIMER_1 = 1, OS_TIMER_2 = 2, OS_TIMER_3 = 3, - OS_TIMER_NUM = 4 + OS_TIMER_NUM } OSTimer; @@ -69,6 +83,9 @@ typedef enum } OSTimer48; +#endif // SDK_ARM9 + + //================================================================================ // TIMER //================================================================================ @@ -95,8 +112,11 @@ void osInitTimer( void ); *---------------------------------------------------------------------------*/ static inline void osSetTimerCount( OSTimer id, u16 count ) { - SDK_ASSERT(OS_TIMER_0 <= id && id <= OS_TIMER_3); + SDK_ASSERT(OS_TIMER_0 <= id && id < OS_TIMER_NUM); +#ifdef SDK_ARM11 +#else // SDK_ARM9 *((REGType16 *)((u32)REG_TM0CNT_L_ADDR + id * 4)) = count; +#endif // SDK_ARM9 } /*---------------------------------------------------------------------------* @@ -111,8 +131,11 @@ static inline void osSetTimerCount( OSTimer id, u16 count ) *---------------------------------------------------------------------------*/ static inline void osSetTimerControl( OSTimer id, u16 control ) { - SDK_ASSERT(OS_TIMER_0 <= id && id <= OS_TIMER_3); + SDK_ASSERT(OS_TIMER_0 <= id && id < OS_TIMER_NUM); +#ifdef SDK_ARM11 +#else // SDK_ARM9 *((REGType16 *)((u32)REG_TM0CNT_H_ADDR + id * 4)) = control; +#endif // SDK_ARM9 } /*---------------------------------------------------------------------------* @@ -130,6 +153,9 @@ static inline void osSetTimerControl( OSTimer id, u16 control ) // use 1 timer, 16bit counter, timer interrupt occurs by overflow // void osStartTimer( OSTimer id, u16 count, OSTimerPrescaler preScale ); + +#ifndef SDK_ARM11 + // // use 2 timers, 32bit counter, timer interrupt occurs by overflow // @@ -143,6 +169,8 @@ void osStartTimer48( OSTimer48 id, u64 count, OSTimerPrescaler preScale ); // void osStartTimer64( u64 count, OSTimerPrescaler preScale ); +#endif // SDK_ARM11 + /*---------------------------------------------------------------------------* Name: osStopTimer @@ -157,6 +185,9 @@ void osStartTimer64( u64 count, OSTimerPrescaler preScale ); // stop a timer // void osStopTimer( OSTimer id ); + +#ifndef SDK_ARM11 + // // stop 2 timers // @@ -170,7 +201,6 @@ void osStopTimer48( OSTimer48 id ); // void osStopTimer64( void ); - #endif // SDK_ARM11 diff --git a/trunk/bootrom/include/brom/os/common/tick.h b/trunk/bootrom/include/brom/os/common/tick.h index c47eae1..2f671c1 100644 --- a/trunk/bootrom/include/brom/os/common/tick.h +++ b/trunk/bootrom/include/brom/os/common/tick.h @@ -45,12 +45,18 @@ extern void i_osSetTick( u64 ); //---- conversion tick count <-> real time count #ifdef SDK_ARM11 #define OS_SYSTEM_CLOCK HW_CPU_CLOCK -#define OS_TICK_HI_SHIFT 31 // 2の累乗単位でチック管理するのであれば32は指定できない(ロード値0では割り込み発生せず) -#define OS_TICK_LO_MASK ((u32)((1ULL<>1)) +#define OS_TICK_LO_LIMIT OS_TICK_HI_LSB #else // SDK_ARM9 #define OS_SYSTEM_CLOCK HW_SYSTEM_CLOCK #define OS_TICK_HI_SHIFT 16 // ロード値0でも割り込み発生 -#define OS_TICK_LO_MASK ((u16)((1ULL<>1)) +#define OS_TICK_LO_LIMIT OS_TICK_HI_LSB #endif // SDK_ARM9 //---- sec to tick