/*---------------------------------------------------------------------------* Project: CtrBrom - libraries - OS File: os_timer.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 void timer_handler(void); #if 0 // miya static void i_osTimerInterruptHandler(void); static void i_osWatchdogInterruptHandler( void ); #endif static void i_osStartTimer( u32 count, u8 preScale, OSTimerRepeat repeat, OSTimerIntrReq ireq ); static void i_osStartWatchDog( u32 count, u8 preScale, OSTimerRepeat repeat, OSTimerIntrReq ireq, OSWatchdogMode watchdogMode ); static u32 osTimerClock = OS_TIMER_CLOCK_DEFAULT; /*---------------------------------------------------------------------------* Name: osInitTimer Description: Initialize Timers Arguments: None Returns: None *---------------------------------------------------------------------------*/ void osInitTimer( void ) { static BOOL isInit; if ( isInit == FALSE ) { isInit = TRUE; osInitInterrupt(); osTimerClock = OS_TIMER_CLOCK_DEFAULT; osDisableTimerAndWatchdog(); osStopTimer(); osStopWatchDog(); osSetInterruptHandler( OS_INTR_ID_TIMER, timer_handler ); //osSetInterruptHandler( OS_INTR_ID_TIMER, timer_handler ); //osSetInterruptHandler( OS_INTR_ID_WATCHDOG, i_osWatchdogInterruptHandler ); reg_OS_IDR_SET_IE0 = REG_OS_IDR_SET_IE0_TM_MASK; osEnableTimerAndWatchdog(); } } /*---------------------------------------------------------------------------* Name: i_osTimerInterruptHandler Description: Timer interrupt handler Arguments: None. Returns: None. *---------------------------------------------------------------------------*/ #if 0 // miya static void i_osTimerInterruptHandler( void ) { reg_OS_CPUTM_EVT = HW_CPUTM_EVT_FLAG; } /*---------------------------------------------------------------------------* Name: i_osWatchdogInterruptHandler Description: Watchdog interrupt handler Arguments: None. Returns: None. *---------------------------------------------------------------------------*/ static void i_osWatchdogInterruptHandler( void ) { reg_OS_CPUWD_EVT = HW_CPUWD_EVT_FLAG; } #endif /*---------------------------------------------------------------------------* Name: osStartTimerWithUSec Description: Start Timer Arguments: micro second Returns: None *---------------------------------------------------------------------------*/ void osStartTimerWithUSec( u32 usec, u8 preScale ) { u32 count = ((usec) * (osTimerClock / 1000)) / (preScale+1) / 1000; i_osStartTimer( count, preScale, OS_TM_AUTO_RELOAD, OS_TM_INTR_REQ_ENABLE ); } /*---------------------------------------------------------------------------* Name: osStartTimerWithMSec Description: Start Timer Arguments: milli second Returns: None *---------------------------------------------------------------------------*/ void osStartTimerWithMSec( u32 msec, u8 preScale ) { u32 count = (((msec) * osTimerClock / 1000)) / (preScale+1); i_osStartTimer( count, preScale, OS_TM_AUTO_RELOAD, OS_TM_INTR_REQ_ENABLE ); } /*---------------------------------------------------------------------------* Name: osStartTimer Description: Start Timer Arguments: interval Returns: None *---------------------------------------------------------------------------*/ void osStartTimer( u32 count, u8 preScale ) { i_osStartTimer( count, preScale, OS_TM_AUTO_RELOAD, OS_TM_INTR_REQ_ENABLE ); } /*---------------------------------------------------------------------------* Name: osStartWatchdog Description: Start Watchdog Arguments: interval watchdogMode Returns: None *---------------------------------------------------------------------------*/ void osStartWatchDog( u32 count, u8 preScale, OSWatchdogMode watchdogMode ) { i_osStartWatchDog( count, preScale, OS_TM_AUTO_RELOAD, OS_TM_INTR_REQ_DISABLE, watchdogMode ); } /*---------------------------------------------------------------------------* Name: i_osStartTimer Description: Start Timer Arguments: None Returns: None *---------------------------------------------------------------------------*/ static void i_osStartTimer( u32 count, u8 preScale, OSTimerRepeat repeat, OSTimerIntrReq ireq ) { OSIntrMode intr = osDisableInterrupts(); reg_OS_TM_CNT = 0; reg_OS_TM_LD = count; reg_OS_TM_CNT = REG_OS_TM_CNT_E_MASK | repeat | ireq | ((preScale < /*---------------------------------------------------------------------------* Name: osEnableTimerAndWatchdog Description: Enable Timer & Watchdog Arguments: None Returns: previous status *---------------------------------------------------------------------------*/ ASM BOOL osEnableTimerAndWatchdog( void ) { stmfd sp!, {r4, lr} // stack requires 8byte alignment bl __cpp(osDisableInterrupts) mrc p15, 0, r4, c15, c12, 0 orr r1, r4, #HW_C15_COUNT_ENABLE mcr p15, 0, r1, c15, c12, 0 // 引数 r0 は osDisableInterrupts の返り値 bl __cpp(osRestoreInterrupts) and r0, r4, #HW_CPUTM_ENABLE // retuen value ldmfd sp!, {r4, pc} // stack requires 8byte alignment } /*---------------------------------------------------------------------------* Name: osDisableTimerAndWatchdog Description: Enable Timer & Watchdog Arguments: None Returns: previous status *---------------------------------------------------------------------------*/ ASM BOOL osDisableTimerAndWatchdog( void ) { stmfd sp!, {r4, lr} // stack requires 8byte alignment bl __cpp(osDisableInterrupts) mrc p15, 0, r4, c15, c12, 0 bic r1, r4, #HW_C15_COUNT_ENABLE mcr p15, 0, r1, c15, c12, 0 // 引数 r0 は osDisableInterrupts の返り値 bl __cpp(osRestoreInterrupts) and r0, r4, #HW_CPUTM_ENABLE // retuen value ldmfd sp!, {r4, pc} // stack requires 8byte alignment } #include /*====== End of main.c ======*/