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@122 b871894f-2f95-9b40-918c-086798483c85
This commit is contained in:
parent
02b41b1238
commit
25de14554c
@ -28,7 +28,6 @@ BROM_CODEGEN_ALL ?= TRUE
|
||||
SRCDIR = . ../common
|
||||
|
||||
SRCS = \
|
||||
os_alarm.c \
|
||||
os_init.c \
|
||||
os_system.c \
|
||||
os_timer.c \
|
||||
@ -39,6 +38,8 @@ SRCS = \
|
||||
os_thread.c \
|
||||
os_context.c \
|
||||
|
||||
# os_alarm.c \
|
||||
|
||||
TARGET_LIB = libos$(BROM_LIBSUFFIX).a
|
||||
|
||||
include $(CTRBROM_ROOT)/build/buildtools/commondefs
|
||||
|
||||
@ -1,332 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*
|
||||
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 <brom/os.h>
|
||||
|
||||
|
||||
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;
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: osInitTimer
|
||||
|
||||
Description: Initialize Timers
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
void osInitTimer( void )
|
||||
{
|
||||
static BOOL isInit;
|
||||
|
||||
if ( isInit == FALSE )
|
||||
{
|
||||
OSIntrMode intr = osDisableInterrupts();
|
||||
|
||||
isInit = TRUE;
|
||||
|
||||
osTimerClock = OS_TIMER_CLOCK_DEFAULT;
|
||||
|
||||
osStopTimer();
|
||||
osStopWatchdog();
|
||||
osResetWatchdog();
|
||||
osDisableWatchdog();
|
||||
|
||||
osRestoreInterrupts( intr );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
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: osStartWatchdogWithUSec
|
||||
|
||||
Description: Start Watchdog
|
||||
|
||||
Arguments: micro second
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
void osStartWatchdogWithUSec( u32 usec, u8 preScale, OSWatchdogMode watchdogMode )
|
||||
{
|
||||
u32 count = ((usec) * (osTimerClock / 1000)) / (preScale+1) / 1000;
|
||||
|
||||
i_osStartWatchdog( count, preScale, OS_TM_SINGLE_SHOT, OS_TM_INTR_REQ_ENABLE, watchdogMode );
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: osStartWatchdogWithMSec
|
||||
|
||||
Description: Start Watchdog
|
||||
|
||||
Arguments: milli second
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
void osStartWatchdogWithMSec( u32 msec, u8 preScale, OSWatchdogMode watchdogMode )
|
||||
{
|
||||
u32 count = (((msec) * osTimerClock / 1000)) / (preScale+1);
|
||||
|
||||
i_osStartWatchdog( count, preScale, OS_TM_SINGLE_SHOT, OS_TM_INTR_REQ_ENABLE, watchdogMode );
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: osStartWatchdog
|
||||
|
||||
Description: Start Watchdog
|
||||
|
||||
Arguments: interval
|
||||
watchdogMode
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
void osStartWatchdog( u32 count, u8 preScale, OSWatchdogMode watchdogMode )
|
||||
{
|
||||
i_osStartWatchdog( count, preScale, OS_TM_SINGLE_SHOT, OS_TM_INTR_REQ_DISABLE, watchdogMode );
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: i_osStartTimer
|
||||
|
||||
Description: Start Timer
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
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 | reload | ireq
|
||||
| ((preScale <<REG_OS_TM_CNT_PS_SHIFT) & REG_OS_TM_CNT_PS_MASK);
|
||||
|
||||
osRestoreInterrupts( intr );
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: i_osStartWatchdog
|
||||
|
||||
Description: Start Watchdog
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
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 | reload | ireq
|
||||
| ((preScale <<REG_OS_WD_CNT_PS_SHIFT) & REG_OS_WD_CNT_PS_MASK)
|
||||
| watchdogMode;
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: osStopTimer
|
||||
|
||||
Description: Stop Timer
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
void osStopTimer( void )
|
||||
{
|
||||
reg_OS_TM_CNT = 0;
|
||||
reg_OS_TM_IF = REG_OS_TM_IF_IF_MASK;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: osStopWatchdog
|
||||
|
||||
Description: Stop Watchdog
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
void osStopWatchdog( void )
|
||||
{
|
||||
reg_OS_WD_CNT = 0;
|
||||
reg_OS_WD_IF = REG_OS_WD_IF_IF_MASK;
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
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 );
|
||||
}
|
||||
|
||||
#include <brom/code32.h>
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
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)
|
||||
|
||||
mov r0, r4
|
||||
// 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)
|
||||
|
||||
mov r0, r4
|
||||
// and r0, r4, #HW_CPUTM_ENABLE // retuen value
|
||||
ldmfd sp!, {r4, pc} // stack requires 8byte alignment
|
||||
}
|
||||
|
||||
#include <brom/codereset.h>
|
||||
|
||||
/*====== End of main.c ======*/
|
||||
@ -18,6 +18,9 @@
|
||||
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
//---- timer number tick uses
|
||||
#define OSi_TICK_TIMER OS_TIMER_0
|
||||
|
||||
#ifdef SDK_ARM11
|
||||
//---- timer interrupt ID
|
||||
#define OSi_TICK_IE_TIMER_ID OS_INTR_ID_TIMER
|
||||
@ -29,9 +32,6 @@
|
||||
//---- timer interrupt mask (must be same number with OSi_TICK_TIMER)
|
||||
#define OSi_TICK_IE_TIMER REG_OS_IF_T0_MASK
|
||||
|
||||
//---- timer number tick uses
|
||||
#define OSi_TICK_TIMER OS_TIMER_0
|
||||
|
||||
//---- 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
|
||||
@ -74,8 +74,9 @@ void osInitTick(void)
|
||||
i_osTickCounter = 0;
|
||||
|
||||
#ifdef SDK_ARM11
|
||||
osStopTimer();
|
||||
osStartTimer(OS_TICK_LO_LIMIT, 0);
|
||||
osStopTimer(OSi_TICK_TIMER);
|
||||
osEnableTimerReload(OSi_TICK_TIMER);
|
||||
osStartTimer(OSi_TICK_TIMER, OS_TICK_LO_LIMIT, 0);
|
||||
#else // SDK_ARM9
|
||||
//---- OS reserves OSi_TICK_TIMER timer
|
||||
SDK_ASSERT(!i_osIsTimerReserved(OSi_TICK_TIMER));
|
||||
@ -130,8 +131,8 @@ static void i_osCountUpTick(void)
|
||||
if (i_osNeedResetTimer)
|
||||
{
|
||||
#ifdef SDK_ARM11
|
||||
osStopTimer();
|
||||
osStartTimer(OS_TICK_LO_LIMIT, 0);
|
||||
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);
|
||||
@ -232,10 +233,10 @@ void i_osSetTick(u64 count)
|
||||
i_osTickCounter = (u64)(count >> OS_TICK_HI_SHIFT);
|
||||
|
||||
#ifdef SDK_ARM11
|
||||
osStopTimer();
|
||||
osStopTimer(OSi_TICK_TIMER);
|
||||
osClearInterruptPendingID(OSi_TICK_IE_TIMER_ID);
|
||||
|
||||
osStartTimer((u32)(count & OS_TICK_LO_MASK), 0);
|
||||
osStartTimer(OSi_TICK_TIMER, (u32)(count & OS_TICK_LO_MASK), 0);
|
||||
|
||||
#else // SDK_ARM9
|
||||
osSetTimerControl(OSi_TICK_TIMER, 0);
|
||||
|
||||
@ -57,10 +57,8 @@ void osInitTimer( void )
|
||||
|
||||
#ifdef SDK_ARM11
|
||||
|
||||
osTimerClock = OS_TIMER_CLOCK_DEFAULT;
|
||||
|
||||
osStopTimer();
|
||||
osStopWatchdog();
|
||||
osStopTimer(OS_TIMER_0);
|
||||
osStopTimer(OS_TIMER_1);
|
||||
osResetWatchdog();
|
||||
osDisableWatchdog();
|
||||
|
||||
@ -146,7 +144,7 @@ void osStartTimer( OSTimer id, OSTimerCount count, OSTimerPrescaler preScale )
|
||||
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);
|
||||
(preScale << REG_OS_TM_CNT_PS_SHIFT));
|
||||
}
|
||||
|
||||
#else // SDK_ARM9
|
||||
@ -250,6 +248,9 @@ void osStopTimer( OSTimer id )
|
||||
SDK_ASSERT(!i_osIsTimerReserved(id));
|
||||
|
||||
osSetTimerControl(id, 0);
|
||||
#ifdef SDK_ARM11
|
||||
osClearTimerEventFlag(id);
|
||||
#endif // SDK_ARM11
|
||||
}
|
||||
|
||||
#ifdef SDK_ARM9
|
||||
@ -304,6 +305,61 @@ void osStopTimer64( void )
|
||||
#endif // SDK_ARM9
|
||||
|
||||
#ifdef SDK_ARM11
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: osIsEnableTimerReload
|
||||
|
||||
Description: check if specified timer is enabling reload
|
||||
|
||||
Arguments: timerNum : timerNo (0-1)
|
||||
|
||||
Returns: non-0 if repeated
|
||||
*---------------------------------------------------------------------------*/
|
||||
u8 osIsEnableTimerReload( OSTimer 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: osEnableTimerReload
|
||||
|
||||
Description: enable specified timer to reload
|
||||
|
||||
Arguments: timerNum : timerNo (0-1)
|
||||
|
||||
Returns: None.
|
||||
*---------------------------------------------------------------------------*/
|
||||
void osEnableTimerReload( OSTimer 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: osDisableTimerReload
|
||||
|
||||
Description: disable specified timer to reload
|
||||
|
||||
Arguments: timerNum : timerNo (0-1)
|
||||
|
||||
Returns: None.
|
||||
*---------------------------------------------------------------------------*/
|
||||
void osDisableTimerReload( OSTimer 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: osResetWatchdog
|
||||
|
||||
@ -338,60 +394,5 @@ void osDisableWatchdog( void )
|
||||
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
|
||||
|
||||
@ -35,12 +35,11 @@ extern "C" {
|
||||
#include <brom/os/common/alarm.h>
|
||||
#include <brom/os/common/mutex.h>
|
||||
#include <brom/os/common/thread.h>
|
||||
#include <brom/os/common/timer.h>
|
||||
#ifdef SDK_ARM11
|
||||
#include <brom/os/ARM11/interrupt.h>
|
||||
#include <brom/os/ARM11/timer.h>
|
||||
#else // SDK_ARM9
|
||||
#include <brom/os/ARM9/interrupt.h>
|
||||
#include <brom/os/ARM9/timer.h>
|
||||
#endif // SDK_ARM9
|
||||
#if 0
|
||||
#include <brom/os/common/systemWork.h>
|
||||
|
||||
@ -1,191 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*
|
||||
Project: CtrBrom - OS - include
|
||||
File: timer.h
|
||||
|
||||
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$
|
||||
*---------------------------------------------------------------------------*/
|
||||
#ifndef BROM_OS_TIMER_H_
|
||||
#define BROM_OS_TIMER_H_
|
||||
|
||||
#include <brom/types.h>
|
||||
#include <ctr/arm_reg.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define OS_TIMER_CLOCK_DEFAULT HW_CPU_CLOCK
|
||||
|
||||
#define OSi_WATCHDOG_DISABLE_CODE_0 0x12345678
|
||||
#define OSi_WATCHDOG_DISABLE_CODE_1 0x87654321
|
||||
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
//---- 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
|
||||
{
|
||||
OS_CPU_TIMER = 0,
|
||||
OS_CPU_WATCHDOG = 1
|
||||
}
|
||||
OSTimerID;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
OS_WD_WATCHDOG_MODE = REG_OS_WD_CNT_M_MASK,
|
||||
OS_WD_TIMER_MODE = 0
|
||||
}
|
||||
OSWatchdogMode;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
OS_TM_AUTO_RELOAD = REG_OS_TM_CNT_RLD_MASK,
|
||||
OS_TM_SINGLE_SHOT = 0
|
||||
}
|
||||
OSTimerReload;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
OS_TM_INTR_REQ_ENABLE = REG_OS_TM_CNT_IT_MASK,
|
||||
OS_TM_INTR_REQ_DISABLE = 0
|
||||
}
|
||||
OSTimerIntrReq;
|
||||
|
||||
|
||||
void osInitTimer( void );
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: osStartTimerWithUSec
|
||||
|
||||
Description: Start Timer
|
||||
|
||||
Arguments: micro second
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
void osStartTimerWithUSec( u32 usec, u8 preScale );
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: osStartTimerWithMSec
|
||||
|
||||
Description: Start Timer
|
||||
|
||||
Arguments: milli second
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
void osStartTimerWithMSec( u32 msec, u8 preScale );
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: osStartTimer
|
||||
|
||||
Description: Start Timer
|
||||
|
||||
Arguments: interval
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
void osStartTimer( u32 count, u8 preScale );
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: osStopTimer
|
||||
|
||||
Description: Stop Timer
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
void osStopTimer( void );
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: osStartWatchdogWithUSec
|
||||
|
||||
Description: Start Watchdog
|
||||
|
||||
Arguments: micro second
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
void osStartWatchdogWithUSec( u32 usec, u8 preScale, OSWatchdogMode watchdogMode );
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: osStartWatchdogWithMSec
|
||||
|
||||
Description: Start Watchdog
|
||||
|
||||
Arguments: milli second
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
void osStartWatchdogWithMSec( u32 msec, u8 preScale, OSWatchdogMode watchdogMode );
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: osStartWatchdog
|
||||
|
||||
Description: Start Watchdog
|
||||
|
||||
Arguments: interval
|
||||
watchdogMode
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
void osStartWatchDog( u32 count, u8 preScale, OSWatchdogMode watchdogMode );
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: osStopWatchdog
|
||||
|
||||
Description: Stop Watchdog
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
void osStopWatchdog( void );
|
||||
|
||||
BOOL osEnableTimerAndWatchdog( void );
|
||||
BOOL osDisableTimerAndWatchdog( void );
|
||||
void osResetWatchdog( void );
|
||||
void osDisableWatchdog( void );
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif // BROM_OS_TIMER_H_
|
||||
@ -24,11 +24,7 @@ extern "C" {
|
||||
#include <brom/misc.h>
|
||||
#include <brom/types.h>
|
||||
#include <ctr/ioreg.h>
|
||||
#ifdef SDK_ARM11
|
||||
#include <brom/os/ARM11/timer.h>
|
||||
#else // SDK_ARM9
|
||||
#include <brom/os/ARM9/timer.h>
|
||||
#endif // SDK_ARM9
|
||||
#include <brom/os/common/timer.h>
|
||||
|
||||
|
||||
//---- unit of tick
|
||||
|
||||
@ -30,6 +30,12 @@ extern "C" {
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
#ifdef SDK_ARM11
|
||||
|
||||
#define OS_TIMER_CLOCK_DEFAULT HW_CPU_CLOCK
|
||||
|
||||
#define OSi_WATCHDOG_DISABLE_CODE_0 0x12345678
|
||||
#define OSi_WATCHDOG_DISABLE_CODE_1 0x87654321
|
||||
|
||||
//---- control
|
||||
typedef u32 OSTimerControl;
|
||||
|
||||
@ -124,7 +130,7 @@ 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;
|
||||
*((REGType32 *)((u32)REG_TM_LD_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
|
||||
@ -144,12 +150,29 @@ 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;
|
||||
*((REGType32 *)((u32)REG_TM_CNT_ADDR + id * (REG_WD_CNT_ADDR-REG_TM_CNT_ADDR))) = control;
|
||||
#else // SDK_ARM9
|
||||
*((REGType16 *)((u32)REG_TM0CNT_H_ADDR + id * 4)) = control;
|
||||
#endif // SDK_ARM9
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: osClearTimerEventFlag
|
||||
|
||||
Description: clear timer event flag
|
||||
|
||||
Arguments: id timerNo
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
static inline void osClearTimerEventFlag( OSTimer id )
|
||||
{
|
||||
#ifdef SDK_ARM11
|
||||
SDK_ASSERT(OS_TIMER_0 <= id && id < OS_TIMER_NUM);
|
||||
*((REGType32 *)((u32)REG_TM_IF_ADDR + id * (REG_WD_CNT_ADDR-REG_TM_CNT_ADDR))) = REG_OS_TM_IF_IF_MASK;
|
||||
#endif // SDK_ARM11
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: osStartTimer
|
||||
|
||||
@ -217,6 +240,39 @@ void osStopTimer64( void );
|
||||
#endif // SDK_ARM9
|
||||
|
||||
#ifdef SDK_ARM11
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: osIsEnableTimerReload
|
||||
|
||||
Description: check if specified timer is enabling reload
|
||||
|
||||
Arguments: timerNum : timerNo (0-1)
|
||||
|
||||
Returns: non-0 if repeated
|
||||
*---------------------------------------------------------------------------*/
|
||||
u8 osIsEnableTimerReload( OSTimer timer_id );
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: osEnableTimerReload
|
||||
|
||||
Description: enable specified timer to reload
|
||||
|
||||
Arguments: timerNum : timerNo (0-1)
|
||||
|
||||
Returns: None.
|
||||
*---------------------------------------------------------------------------*/
|
||||
void osEnableTimerReload( OSTimer timer_id );
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: osDisableTimerReload
|
||||
|
||||
Description: disable specified timer to reload
|
||||
|
||||
Arguments: timerNum : timerNo (0-1)
|
||||
|
||||
Returns: None.
|
||||
*---------------------------------------------------------------------------*/
|
||||
void osDisableTimerReload( OSTimer timer_id );
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: osResetWatchdog
|
||||
|
||||
@ -239,39 +295,6 @@ void osResetWatchdog( void );
|
||||
*---------------------------------------------------------------------------*/
|
||||
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