diff --git a/trunk/bootrom/build/libraries/os/ARM11/os_timer.c b/trunk/bootrom/build/libraries/os/ARM11/os_timer.c index 13882b3..b60145a 100644 --- a/trunk/bootrom/build/libraries/os/ARM11/os_timer.c +++ b/trunk/bootrom/build/libraries/os/ARM11/os_timer.c @@ -17,8 +17,8 @@ #include -static void i_osStartTimer( u32 count, u8 preScale, OSTimerRepeat repeat, OSTimerIntrReq ireq ); -static void i_osStartWatchdog( u32 count, u8 preScale, OSTimerRepeat repeat, OSTimerIntrReq ireq, +static void i_osStartTimer( u32 count, u8 preScale, OSTimerReload reload, OSTimerIntrReq ireq ); +static void i_osStartWatchdog( u32 count, u8 preScale, OSTimerReload reload, OSTimerIntrReq ireq, OSWatchdogMode watchdogMode ); static u32 osTimerClock = OS_TIMER_CLOCK_DEFAULT; @@ -165,13 +165,13 @@ void osStartWatchdog( u32 count, u8 preScale, OSWatchdogMode watchdogMode ) Returns: None *---------------------------------------------------------------------------*/ -static void i_osStartTimer( u32 count, u8 preScale, OSTimerRepeat repeat, OSTimerIntrReq ireq ) +static void i_osStartTimer( u32 count, u8 preScale, OSTimerReload reload, 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 + reg_OS_TM_CNT = REG_OS_TM_CNT_E_MASK | reload | ireq | ((preScale < interrupt occurs by overflow +// +void osStartTimer( OSTimer id, OSTimerCount count, OSTimerPrescaler preScale ) +{ + SDK_ASSERT(OS_TIMER_0 <= id && id < OS_TIMER_NUM); + //---- check if system reserved + SDK_ASSERT(!i_osIsTimerReserved(id)); + + osSetTimerCount(id, count); + osSetTimerControl(id, REG_OS_TM_CNT_E_MASK | REG_OS_TM_CNT_IT_MASK | + i_osTimerControl[id] | + (preScale << REG_OS_TM_CNT_PS_SHIFT); +} + +#else // SDK_ARM9 // // use 1 timer, 16bit counter, timer interrupt occurs by overflow // void osStartTimer( OSTimer id, u16 count, OSTimerPrescaler preScale ) { - SDK_ASSERT(OS_TIMER_0 <= id && id <= OS_TIMER_3); + SDK_ASSERT(OS_TIMER_0 <= id && id < OS_TIMER_NUM); SDK_ASSERT(OS_TIMER_PRESCALER_1 <= preScale && preScale <= OS_TIMER_PRESCALER_1024); //---- check if system reserved SDK_ASSERT(!i_osIsTimerReserved(id)); @@ -187,6 +229,7 @@ void osStartTimer64( u64 count, OSTimerPrescaler preScale ) osSetTimerControl(OS_TIMER_0, (u16)(REG_OS_TMCNT_H_E_MASK | preScale)); } +#endif // SDK_ARM9 /*---------------------------------------------------------------------------* Name: i_osStopTimer @@ -202,13 +245,15 @@ void osStartTimer64( u64 count, OSTimerPrescaler preScale ) // void osStopTimer( OSTimer id ) { - SDK_ASSERT(OS_TIMER_0 <= id && id <= OS_TIMER_3); + SDK_ASSERT(OS_TIMER_0 <= id && id < OS_TIMER_NUM); //---- check if system reserved SDK_ASSERT(!i_osIsTimerReserved(id)); osSetTimerControl(id, 0); } +#ifdef SDK_ARM9 + // // stop 2 timers // @@ -256,4 +301,97 @@ void osStopTimer64( void ) osStopTimer(OS_TIMER_0); } +#endif // SDK_ARM9 + +#ifdef SDK_ARM11 +/*---------------------------------------------------------------------------* + Name: osResetWatchdog + + Description: Reset Watchdog + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void osResetWatchdog( void ) +{ + reg_OS_WD_RST = TRUE; +} + + +/*---------------------------------------------------------------------------* + Name: osDisableWatchdog + + Description: Disable Watchdog + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void osDisableWatchdog( void ) +{ + OSIntrMode intr = osDisableInterrupts(); + + reg_OS_WD_DIS = OSi_WATCHDOG_DISABLE_CODE_0; + reg_OS_WD_DIS = OSi_WATCHDOG_DISABLE_CODE_1; + + osRestoreInterrupts( intr ); +} + +/*---------------------------------------------------------------------------* + Name: osIsTimerReload + + Description: check if specified timer is enabling reload + + Arguments: timerNum : timerNo (0-1) + + Returns: non-0 if repeated + *---------------------------------------------------------------------------*/ +u8 osIsTimerReload( int timer_id ) +{ + SDK_ASSERT(OS_TIMER_0 <= id && id < OS_TIMER_NUM); + return i_osTimerControl[timer_id] & REG_OS_WD_CNT_RLD_MASK ? TRUE : FALSE; +} + +/*---------------------------------------------------------------------------* + Name: osSetTimerReload + + Description: set specified timer to reload + + Arguments: timerNum : timerNo (0-1) + + Returns: None. + *---------------------------------------------------------------------------*/ +void osSetTimerReload( int timer_id ) +{ + SDK_ASSERT(OS_TIMER_0 <= id && id < OS_TIMER_NUM); + + OSIntrMode intr = osDisableInterrupts(); + + i_osTimerControl[timer_id] |= REG_OS_WD_CNT_RLD_MASK; + + osRestoreInterrupts( intr ); +} + +/*---------------------------------------------------------------------------* + Name: osUnsetTimerReload + + Description: unset specified timer to reload + + Arguments: timerNum : timerNo (0-1) + + Returns: None. + *---------------------------------------------------------------------------*/ +void osUnsetTimerReload( int timer_id ) +{ + SDK_ASSERT(OS_TIMER_0 <= id && id < OS_TIMER_NUM); + + OSIntrMode intr = osDisableInterrupts(); + + i_osTimerControl[timer_id] &= ~REG_OS_WD_CNT_RLD_MASK; + + osRestoreInterrupts( intr ); +} + +#endif // SDK_ARM11 diff --git a/trunk/bootrom/build/libraries/os/common/os_alarm.c b/trunk/bootrom/build/libraries/os/common/os_alarm.c index 188f5bb..7770309 100644 --- a/trunk/bootrom/build/libraries/os/common/os_alarm.c +++ b/trunk/bootrom/build/libraries/os/common/os_alarm.c @@ -91,9 +91,10 @@ static void i_osSetTimer(OSAlarm *alarm) #else // SDK_ARM9 if (delta < 0) { + // ARM9‚Í0xFFFFÝ’è‹ÖŽ~ timerCount = (u16)~1; } - else if (delta < 0x10000) + else if (delta < OS_TICK_HI_LSB) { timerCount = (u16)(~delta); } diff --git a/trunk/bootrom/include/brom/os/ARM11/timer.h b/trunk/bootrom/include/brom/os/ARM11/timer.h index 056feb7..4c219a7 100644 --- a/trunk/bootrom/include/brom/os/ARM11/timer.h +++ b/trunk/bootrom/include/brom/os/ARM11/timer.h @@ -31,6 +31,24 @@ extern "C" { //---------------------------------------------------------------------- +//---- control +typedef u32 OSTimerControl; + +//---- count +typedef u32 OSTimerCount; + +//---- pre-scaler +typedef u8 OSTimerPrescaler; + +//---- timer number +typedef enum +{ + OS_TIMER_0 = 0, + OS_TIMER_1 = 1, + OS_TIMER_NUM +} +OSTimer; + //---- timer ID typedef enum { @@ -51,7 +69,7 @@ typedef enum OS_TM_AUTO_RELOAD = REG_OS_TM_CNT_RLD_MASK, OS_TM_SINGLE_SHOT = 0 } -OSTimerRepeat; +OSTimerReload; typedef enum { diff --git a/trunk/bootrom/include/brom/os/ARM9/timer.h b/trunk/bootrom/include/brom/os/ARM9/timer.h index 01d1f59..541ce3a 100644 --- a/trunk/bootrom/include/brom/os/ARM9/timer.h +++ b/trunk/bootrom/include/brom/os/ARM9/timer.h @@ -30,6 +30,11 @@ extern "C" { //---------------------------------------------------------------------- #ifdef SDK_ARM11 +//---- control +typedef u32 OSTimerControl; + +//---- count +typedef u32 OSTimerCount; //---- pre-scaler typedef u8 OSTimerPrescaler; @@ -44,6 +49,11 @@ typedef enum OSTimer; #else // SDK_ARM9 +//---- control +typedef u16 OSTimerControl; + +//---- count +typedef u16 OSTimerCount; //---- pre-scaler typedef enum @@ -110,10 +120,11 @@ void osInitTimer( void ); Returns: None *---------------------------------------------------------------------------*/ -static inline void osSetTimerCount( OSTimer id, u16 count ) +static inline void osSetTimerCount( OSTimer id, OSTimerCount count ) { SDK_ASSERT(OS_TIMER_0 <= id && id < OS_TIMER_NUM); #ifdef SDK_ARM11 + *((REGType32 *)((u32)REG_TM_COUNT_ADDR + id * (REG_WD_CNT_ADDR-REG_TM_CNT_ADDR))) = count; #else // SDK_ARM9 *((REGType16 *)((u32)REG_TM0CNT_L_ADDR + id * 4)) = count; #endif // SDK_ARM9 @@ -129,10 +140,11 @@ static inline void osSetTimerCount( OSTimer id, u16 count ) Returns: None *---------------------------------------------------------------------------*/ -static inline void osSetTimerControl( OSTimer id, u16 control ) +static inline void osSetTimerControl( OSTimer id, OSTimerControl control ) { SDK_ASSERT(OS_TIMER_0 <= id && id < OS_TIMER_NUM); #ifdef SDK_ARM11 + *((REGType32 *)((u32)REG_TM_CNT_ADDR + id * (REG_WD_CNT_ADDR-REG_TM_CNT_ADDR))) = count; #else // SDK_ARM9 *((REGType16 *)((u32)REG_TM0CNT_H_ADDR + id * 4)) = control; #endif // SDK_ARM9 @@ -149,13 +161,14 @@ static inline void osSetTimerControl( OSTimer id, u16 control ) Returns: None *---------------------------------------------------------------------------*/ +#ifdef SDK_ARM11 +void osStartTimer( OSTimer id, OSTimerCount count, OSTimerPrescaler preScale ); + +#else // SDK_ARM9 // // use 1 timer, 16bit counter, timer interrupt occurs by overflow // -void osStartTimer( OSTimer id, u16 count, OSTimerPrescaler preScale ); - -#ifndef SDK_ARM11 - +void osStartTimer( OSTimer id, OSTimerCount count, OSTimerPrescaler preScale ); // // use 2 timers, 32bit counter, timer interrupt occurs by overflow // @@ -169,7 +182,7 @@ void osStartTimer48( OSTimer48 id, u64 count, OSTimerPrescaler preScale ); // void osStartTimer64( u64 count, OSTimerPrescaler preScale ); -#endif // SDK_ARM11 +#endif // SDK_ARM9 /*---------------------------------------------------------------------------* @@ -186,7 +199,7 @@ void osStartTimer64( u64 count, OSTimerPrescaler preScale ); // void osStopTimer( OSTimer id ); -#ifndef SDK_ARM11 +#ifdef SDK_ARM9 // // stop 2 timers @@ -201,6 +214,64 @@ void osStopTimer48( OSTimer48 id ); // void osStopTimer64( void ); +#endif // SDK_ARM9 + +#ifdef SDK_ARM11 +/*---------------------------------------------------------------------------* + Name: osResetWatchdog + + Description: Reset Watchdog + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void osResetWatchdog( void ); + +/*---------------------------------------------------------------------------* + Name: osDisableWatchdog + + Description: Disable Watchdog + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void osDisableWatchdog( void ); + +/*---------------------------------------------------------------------------* + Name: osIsTimerRepeat + + Description: check if specified timer is enabling repeat + + Arguments: timerNum : timerNo (0-1) + + Returns: non-0 if repeated + *---------------------------------------------------------------------------*/ +u8 osIsTimerRepeat( int timer_id ); + +/*---------------------------------------------------------------------------* + Name: osSetTimerRepeat + + Description: set specified timer to repeat + + Arguments: timerNum : timerNo (0-1) + + Returns: None. + *---------------------------------------------------------------------------*/ +void osSetTimerRepeat( int timer_id ); + +/*---------------------------------------------------------------------------* + Name: osUnsetTimerRepeat + + Description: unset specified timer to repeat + + Arguments: timerNum : timerNo (0-1) + + Returns: None. + *---------------------------------------------------------------------------*/ +void osUnsetTimerRepeat( int timer_id ); + #endif // SDK_ARM11