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@121 b871894f-2f95-9b40-918c-086798483c85
This commit is contained in:
parent
1dd141a11f
commit
02b41b1238
@ -17,8 +17,8 @@
|
||||
#include <brom/os.h>
|
||||
|
||||
|
||||
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 <<REG_OS_TM_CNT_PS_SHIFT) & REG_OS_TM_CNT_PS_MASK);
|
||||
|
||||
osRestoreInterrupts( intr );
|
||||
@ -188,12 +188,12 @@ static void i_osStartTimer( u32 count, u8 preScale, OSTimerRepeat repeat, OSTime
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
static void i_osStartWatchdog( u32 count, u8 preScale, OSTimerRepeat repeat, OSTimerIntrReq ireq,
|
||||
static void i_osStartWatchdog( u32 count, u8 preScale, OSTimerReload reload, OSTimerIntrReq ireq,
|
||||
OSWatchdogMode watchdogMode )
|
||||
{
|
||||
reg_OS_WD_CNT = 0;
|
||||
reg_OS_WD_LD = count;
|
||||
reg_OS_WD_CNT = REG_OS_WD_CNT_E_MASK | repeat | ireq
|
||||
reg_OS_WD_CNT = REG_OS_WD_CNT_E_MASK | reload | ireq
|
||||
| ((preScale <<REG_OS_WD_CNT_PS_SHIFT) & REG_OS_WD_CNT_PS_MASK)
|
||||
| watchdogMode;
|
||||
}
|
||||
|
||||
@ -18,12 +18,17 @@
|
||||
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
#ifdef SDK_ARM9
|
||||
#define REG_OS_TMCNT_H_E_MASK REG_OS_TM0CNT_H_E_MASK
|
||||
#define REG_OS_TMCNT_H_I_MASK REG_OS_TM0CNT_H_I_MASK
|
||||
#define REG_OS_TMCNT_H_CH_MASK REG_OS_TM1CNT_H_CH_MASK
|
||||
#endif // SDK_ARM9
|
||||
|
||||
//---- if OS reserved each timer, bit=1
|
||||
static u8 i_osTimerReserved[OS_TIMER_NUM];
|
||||
#ifdef SDK_ARM11
|
||||
static u8 i_osTimerControl[OS_TIMER_NUM];
|
||||
#endif // SDK_ARM11
|
||||
|
||||
u8 i_osIsTimerReserved(int timerNum);
|
||||
void i_osSetTimerReserved(int timerNum);
|
||||
@ -46,9 +51,29 @@ void osInitTimer( void )
|
||||
|
||||
if ( isInit == FALSE )
|
||||
{
|
||||
OSIntrMode intr = osDisableInterrupts();
|
||||
|
||||
isInit = TRUE;
|
||||
|
||||
#ifdef SDK_ARM11
|
||||
|
||||
osTimerClock = OS_TIMER_CLOCK_DEFAULT;
|
||||
|
||||
osStopTimer();
|
||||
osStopWatchdog();
|
||||
osResetWatchdog();
|
||||
osDisableWatchdog();
|
||||
|
||||
i_osTimerControl[OS_TIMER_0] = 0;
|
||||
i_osTimerControl[OS_TIMER_1] = 0;
|
||||
|
||||
#else // SDK_ARM9
|
||||
|
||||
osStopTimer64();
|
||||
|
||||
#endif // SDK_ARM9
|
||||
|
||||
osRestoreInterrupts( intr );
|
||||
}
|
||||
}
|
||||
|
||||
@ -108,12 +133,29 @@ void i_osUnsetTimerReserved( int timer_id )
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
#ifdef SDK_ARM11
|
||||
//
|
||||
// use 1 timer, 16bit counter, timer<id> 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<id> 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
|
||||
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -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<id> 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<id+1> 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
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user