mirror of
https://github.com/rvtr/ctr_firmware.git
synced 2025-10-31 07:51:08 -04:00
git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-09-30%20-%20paladin.7z/paladin/ctr_firmware@130 b871894f-2f95-9b40-918c-086798483c85
237 lines
6.6 KiB
C
237 lines
6.6 KiB
C
/*---------------------------------------------------------------------------*
|
||
Project: CtrBrom - libraries - OS
|
||
File: os_tick.c
|
||
|
||
Copyright 2008 Nintendo. All rights reserved.
|
||
|
||
These coded instructions, statements, and computer programs contain
|
||
proprietary information of Nintendo of America Inc. and/or Nintendo
|
||
Company Ltd., and are protected by Federal copyright law. They may
|
||
not be disclosed to third parties or copied or duplicated in any form,
|
||
in whole or in part, without the prior written consent of Nintendo.
|
||
|
||
$Date:: $
|
||
$Rev$
|
||
$Author$
|
||
*---------------------------------------------------------------------------*/
|
||
#include <brom/os.h>
|
||
|
||
|
||
//----------------------------------------------------------------------
|
||
#ifdef SDK_ARM9
|
||
//---- timer interrupt mask (must be same number with OSi_TICK_TIMER)
|
||
#define OSi_TICK_IE_TIMER (OS_IE_TIMER0 << OSi_TICK_TIMER)
|
||
|
||
//---- timer control setting for tick
|
||
#define OSi_TICK_TIMERCONTROL ( REG_OS_TM0CNT_H_E_MASK | REG_OS_TM0CNT_H_I_MASK | OS_TIMER_PRESCALER_64 )
|
||
#endif // SDK_ARM9
|
||
|
||
//---- flag for initialization tick
|
||
static u16 i_osUseTick = FALSE;
|
||
|
||
//---- tick counter
|
||
vu64 i_osTickCounter;
|
||
|
||
//---- flag for need to re-set timer
|
||
BOOL i_osNeedResetTimer = FALSE;
|
||
|
||
extern u16 i_osIsTimerReserved(int timerNum);
|
||
extern void i_osSetTimerReserved(int timerNum);
|
||
|
||
static void i_osCountUpTick(void);
|
||
|
||
/*---------------------------------------------------------------------------*
|
||
Name: osInitTick
|
||
|
||
Description: initialize 'tick system'
|
||
|
||
Arguments: None
|
||
|
||
Returns: None
|
||
*---------------------------------------------------------------------------*/
|
||
void osInitTick(void)
|
||
{
|
||
if (!i_osUseTick)
|
||
{
|
||
i_osUseTick = TRUE;
|
||
|
||
//---- disable timer interrupt
|
||
osDisableInterruptID(OSi_TICK_IE_TIMER_ID);
|
||
|
||
osInitInterrupt();
|
||
osInitTimer();
|
||
|
||
i_osTickCounter = 0;
|
||
|
||
//---- OS reserves OSi_TICK_TIMER timer
|
||
SDK_ASSERT(!i_osIsTimerReserved(OSi_TICK_TIMER));
|
||
i_osSetTimerReserved(OSi_TICK_TIMER);
|
||
|
||
#ifdef SDK_ARM11
|
||
osStopTimer(OSi_TICK_TIMER);
|
||
osEnableTimerReload(OSi_TICK_TIMER);
|
||
osStartTimer(OSi_TICK_TIMER, OS_TICK_LO_LIMIT, 0);
|
||
#else // SDK_ARM9
|
||
//---- setting timer
|
||
osSetTimerControl(OSi_TICK_TIMER, 0);
|
||
osSetTimerCount((OSTimer)OSi_TICK_TIMER, (u16)0);
|
||
osSetTimerControl(OSi_TICK_TIMER, (u16)OSi_TICK_TIMERCONTROL);
|
||
#endif // SDK_ARM9
|
||
|
||
//---- set interrupt callback
|
||
osSetInterruptHandler( OSi_TICK_IE_TIMER_ID, i_osCountUpTick );
|
||
|
||
//---- enable timer interrupt
|
||
osEnableInterruptID(OSi_TICK_IE_TIMER_ID);
|
||
|
||
//---- need to reset
|
||
i_osNeedResetTimer = TRUE;
|
||
}
|
||
}
|
||
|
||
/*---------------------------------------------------------------------------*
|
||
Name: osIsTickAvailable
|
||
|
||
Description: check tick system is available
|
||
|
||
Arguments: None
|
||
|
||
Returns: if available, TRUE.
|
||
*---------------------------------------------------------------------------*/
|
||
BOOL osIsTickAvailable(void)
|
||
{
|
||
return i_osUseTick;
|
||
}
|
||
|
||
|
||
/*---------------------------------------------------------------------------*
|
||
Name: i_osCountUpTick
|
||
|
||
Description: timer interrupt handle.
|
||
|
||
Arguments: None
|
||
|
||
Returns: None
|
||
*---------------------------------------------------------------------------*/
|
||
static void i_osCountUpTick(void)
|
||
{
|
||
i_osTickCounter++;
|
||
|
||
//---- setting for timer
|
||
if (i_osNeedResetTimer)
|
||
{
|
||
#ifdef SDK_ARM11
|
||
osStopTimer(OSi_TICK_TIMER);
|
||
osStartTimer(OSi_TICK_TIMER, OS_TICK_LO_LIMIT, 0);
|
||
#else // SDK_ARM9
|
||
osSetTimerControl(OSi_TICK_TIMER, 0);
|
||
osSetTimerCount((OSTimer)OSi_TICK_TIMER, (u16)0);
|
||
osSetTimerControl(OSi_TICK_TIMER, (u16)OSi_TICK_TIMERCONTROL);
|
||
#endif // SDK_ARM9
|
||
|
||
i_osNeedResetTimer = FALSE;
|
||
}
|
||
|
||
// <20><><EFBFBD><EFBFBD><EFBFBD>͂<EFBFBD><CD82><EFBFBD><EFBFBD>Ȃ<EFBFBD><C882>Ă<EFBFBD><C482>A<EFBFBD><41><EFBFBD><EFBFBD><EFBFBD>R<EFBFBD>[<5B><><EFBFBD>o<EFBFBD>b<EFBFBD>N<EFBFBD><4E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>邩<EFBFBD><E982A9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȃ<EFBFBD><C882>H
|
||
// //---- reset callback
|
||
// OSi_EnterTimerCallback(OSi_TICK_TIMER, (void (*)(void *))i_osCountUpTick, 0);
|
||
}
|
||
|
||
/*---------------------------------------------------------------------------*
|
||
Name: osGetTick
|
||
|
||
Description: get tick value
|
||
|
||
Arguments: None
|
||
|
||
Returns: tick value
|
||
*---------------------------------------------------------------------------*/
|
||
u64 osGetTick(void)
|
||
{
|
||
vu32 countL;
|
||
vu64 countH;
|
||
|
||
OSIntrMode prev = osDisableInterrupts();
|
||
SDK_ASSERT(i_osUseTick);
|
||
|
||
countL = osGetTimerCount(OSi_TICK_TIMER);
|
||
#ifdef SDK_ARM11
|
||
countL = OS_TICK_LO_LIMIT - countL;
|
||
#endif // SDK_ARM11
|
||
countH = i_osTickCounter;
|
||
|
||
//---- check if timer interrupt bit is on
|
||
if (osIsInterruptPendingID(OSi_TICK_IE_TIMER_ID) &&
|
||
// countL<74><4C>0xFFFF<46>Œ<EFBFBD><C592><EFBFBD><EFBFBD>Ɋ<EFBFBD><C98A>荞<EFBFBD>ݗv<DD97><76><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ꍇ<EFBFBD>̑<CC91>
|
||
#ifdef SDK_ARM11
|
||
// <20>_<EFBFBD>E<EFBFBD><45><EFBFBD>J<EFBFBD>E<EFBFBD><45><EFBFBD>^<5E>Ȃ̂<C882>
|
||
(countL & OS_TICK_LO_MSB)
|
||
#else // SDK_ARM9
|
||
// <20>A<EFBFBD>b<EFBFBD>v<EFBFBD>J<EFBFBD>E<EFBFBD><45><EFBFBD>^<5E>Ȃ̂<C882>
|
||
!(countL & OS_TICK_LO_MSB)
|
||
#endif // SDK_ARM9
|
||
)
|
||
{
|
||
countH++;
|
||
}
|
||
|
||
countH <<= OS_TICK_HI_SHIFT;
|
||
|
||
(void)osRestoreInterrupts(prev);
|
||
|
||
return countH | countL;
|
||
}
|
||
|
||
/*---------------------------------------------------------------------------*
|
||
Name: osGetTickLo
|
||
|
||
Description: get tick value (only u16 part)
|
||
|
||
Arguments: None
|
||
|
||
Returns: tick value (only u16 part)
|
||
*---------------------------------------------------------------------------*/
|
||
OSTimerCount osGetTickLo(void)
|
||
{
|
||
SDK_ASSERT(OSi_UseTick);
|
||
return osGetTimerCount(OSi_TICK_TIMER);
|
||
}
|
||
|
||
/*---------------------------------------------------------------------------*
|
||
Name: i_osSetTick
|
||
|
||
Description: set tick value
|
||
|
||
Arguments: count value of tick to be set
|
||
|
||
Returns: None
|
||
*---------------------------------------------------------------------------*/
|
||
void i_osSetTick(u64 count)
|
||
{
|
||
OSIntrMode prev;
|
||
|
||
SDK_ASSERT(i_osUseTick);
|
||
prev = osDisableInterrupts();
|
||
|
||
i_osNeedResetTimer = TRUE;
|
||
|
||
i_osTickCounter = (u64)(count >> OS_TICK_HI_SHIFT);
|
||
|
||
#ifdef SDK_ARM11
|
||
osStopTimer(OSi_TICK_TIMER);
|
||
osClearInterruptPendingID(OSi_TICK_IE_TIMER_ID);
|
||
|
||
osStartTimer(OSi_TICK_TIMER, (u32)(count & OS_TICK_LO_MASK), 0);
|
||
|
||
#else // SDK_ARM9
|
||
osSetTimerControl(OSi_TICK_TIMER, 0);
|
||
osClearInterruptPendingID(OSi_TICK_IE_TIMER_ID);
|
||
|
||
osSetTimerCount((OSTimer)OSi_TICK_TIMER, (u16)(count & OS_TICK_LO_MASK));
|
||
osSetTimerControl(OSi_TICK_TIMER, (u16)OSi_TICK_TIMERCONTROL);
|
||
|
||
#endif // SDK_ARM9
|
||
|
||
(void)osRestoreInterrupts(prev);
|
||
}
|