タイマーライブラリ追加。

git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-09-30%20-%20paladin.7z/paladin/ctr_firmware@87 b871894f-2f95-9b40-918c-086798483c85
This commit is contained in:
nakasima 2008-12-09 00:51:05 +00:00
parent c17002f94f
commit 63c169ea3c
7 changed files with 960 additions and 0 deletions

View File

@ -0,0 +1,46 @@
#! make -f
#----------------------------------------------------------------------------
# Project: CtrBrom - libraries - os
# File: Makefile
#
# 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$
#----------------------------------------------------------------------------
SUBDIRS =
SUBMAKES =
#----------------------------------------------------------------------------
# build ARM & THUMB libraries
BROM_CODEGEN_ALL ?= TRUE
SRCDIR = . ../common
SRCS = \
os_timer.c \
TARGET_LIB = libos$(BROM_LIBSUFFIX).a
include $(CTRBROM_ROOT)/build/buildtools/commondefs
INSTALL_TARGETS = $(TARGETS)
INSTALL_DIR = $(BROM_INSTALL_LIBDIR)
#----------------------------------------------------------------------------
do-build: $(TARGETS)
include $(CTRBROM_ROOT)/build/buildtools/modulerules
#===== End of Makefile =====

View File

@ -0,0 +1,334 @@
/*---------------------------------------------------------------------------*
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>
#include <brom/memorymap.h>
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 <<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, OSTimerRepeat repeat, 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
| ((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;
}
/*---------------------------------------------------------------------------*
Name: osStopWatchdog
Description: Stop Watchdog
Arguments: None
Returns: None
*---------------------------------------------------------------------------*/
void osStopWatchDog( void )
{
reg_OS_WD_CNT = 0;
}
/*---------------------------------------------------------------------------*
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 )
{
reg_OS_WD_DIS = TRUE;
}
#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)
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 <brom/codereset.h>
/*====== End of main.c ======*/

View File

@ -0,0 +1,55 @@
#! make -f
#----------------------------------------------------------------------------
# Project: TwlBrom - libraries_sp - os
# File: Makefile
#
# 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$
#----------------------------------------------------------------------------
SUBDIRS =
#SUBMAKES = Makefile.CALLTRACE \
# Makefile.FUNCTIONCOST
#----------------------------------------------------------------------------
# build ARM & THUMB libraries
BROM_CODEGEN_ALL ?= TRUE
# Codegen for sub processer
BROM_PROC = ARM9
SRCDIR = . ../common
SRCS = \
os_tick.c \
os_timer.c \
TARGET_LIB = libos_sp$(BROM_LIBSUFFIX).a
#----------------------------------------------------------------------------
include $(CTRBROM_ROOT)/build/buildtools/commondefs
INSTALL_TARGETS = $(TARGETS)
INSTALL_DIR = $(BROM_INSTALL_LIBDIR)
#----------------------------------------------------------------------------
do-build: $(TARGETS)
include $(CTRBROM_ROOT)/build/buildtools/modulerules
#===== End of Makefile =====

View File

@ -0,0 +1,201 @@
/*---------------------------------------------------------------------------*
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>
#include <brom/memorymap.h>
//----------------------------------------------------------------------
//---- 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 )
//---- timer number tick uses
#define OSi_TICK_TIMER OS_TIMER_3
//---- timer interrupt mask (must be same number with OSi_TICK_TIMER)
#define OSi_TICK_IE_TIMER REG_OS_IF_T3_MASK
//---- timer interrupt ID
#define OSi_TICK_IE_TIMER_ID OS_INTR_ID_TIMER3
//---- 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;
//---- OS reserves OSi_TICK_TIMER timer
SDK_ASSERT(!i_osIsTimerReserved(OSi_TICK_TIMER));
i_osSetTimerReserved(OSi_TICK_TIMER);
//---- setting timer
i_osTickCounter = 0;
i_osSetTimerControl(OSi_TICK_TIMER, 0);
i_osSetTimerCount((OSTimer)OSi_TICK_TIMER, (u16)0);
i_osSetTimerControl(OSi_TICK_TIMER, (u16)OSi_TICK_TIMERCONTROL);
//---- set interrupt callback
osSetInterruptHandler( OS_INTR_ID_TIMER3, i_osCountUpTick );
osSetMultiInterruptMask( OS_INTR_ID_TIMER3, (OSIntrMask)0xffffffff ); // , osInitTimerの真似
//---- enable timer interrupt
osEnableInterruptID(OSi_TICK_IE_TIMER_ID);
//---- need to reset
i_osNeedResetTimer = FALSE;
}
}
/*---------------------------------------------------------------------------*
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)
{
i_osSetTimerControl(OSi_TICK_TIMER, 0);
i_osSetTimerCount((OSTimer)OSi_TICK_TIMER, (u16)0);
i_osSetTimerControl(OSi_TICK_TIMER, (u16)OSi_TICK_TIMERCONTROL);
i_osNeedResetTimer = FALSE;
}
// これはやらなくても、毎回コールバックがかかるから問題ない?
// //---- 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)
{
vu16 countL;
vu64 countH;
OSIntrMode prev = osDisableInterrupts();
SDK_ASSERT(i_osUseTick);
countL = *(REGType16 *)((u32)REG_TM0CNT_L_ADDR + OSi_TICK_TIMER * 4);
countH = i_osTickCounter & 0xffffffffffffULL;
//---- check if timer interrupt bit is on
if (reg_OS_IF & OSi_TICK_IE_TIMER && !(countL & 0x8000))
{
countH++;
}
(void)osRestoreInterrupts(prev);
return (countH << 16) | countL;
}
/*---------------------------------------------------------------------------*
Name: osGetTickLo
Description: get tick value (only u16 part)
Arguments: None
Returns: tick value (only u16 part)
*---------------------------------------------------------------------------*/
u16 osGetTickLo(void)
{
SDK_ASSERT(OSi_UseTick);
return *(REGType16 *)((u32)REG_TM0CNT_L_ADDR + OSi_TICK_TIMER * 4);
}
/*---------------------------------------------------------------------------*
Name: osSetTick
Description: set tick value
Arguments: count value of tick to be set
Returns: None
*---------------------------------------------------------------------------*/
void osSetTick(u64 count)
{
OSIntrMode prev;
SDK_ASSERT(i_osUseTick);
prev = osDisableInterrupts();
reg_OS_IF = OSi_TICK_IE_TIMER;
i_osNeedResetTimer = TRUE;
i_osTickCounter = (u64)(count >> 16);
i_osSetTimerControl(OSi_TICK_TIMER, 0);
i_osSetTimerCount((OSTimer)OSi_TICK_TIMER, (u16)(count & 0xffff));
i_osSetTimerControl(OSi_TICK_TIMER, (u16)OSi_TICK_TIMERCONTROL);
(void)osRestoreInterrupts(prev);
}

View File

@ -0,0 +1,274 @@
/*---------------------------------------------------------------------------*
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>
#include <brom/memorymap.h>
void timer_handler(void);
//----------------------------------------------------------------------
#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
//---- if OS reserved each timer, bit=1
static u8 i_osTimerReserved[OS_TIMER_NUM];
u8 i_osIsTimerReserved(int timerNum);
void i_osSetTimerReserved(int timerNum);
void i_osUnsetTimerReserved(int timerNum);
/*---------------------------------------------------------------------------*
Name: osInitTimer
Description: Initialize Timers
Arguments: None
Returns: None
*---------------------------------------------------------------------------*/
void osInitTimer( void )
{
static BOOL isInit;
if ( isInit == FALSE )
{
isInit = TRUE;
osInitInterrupt();
i_osStopTimer64();
{
OSIntrMask imask = 0xffffffff;
osSetInterruptHandler( OS_INTR_ID_TIMER1, timer_handler );
osSetMultiInterruptMask( OS_INTR_ID_TIMER1, imask );
}
osEnableInterruptID( OS_INTR_ID_TIMER1 );
i_osStartTimer32( OS_TIMER32_01, (u32)i_osMSecToTick32( 1 ), OS_TIMER_PRESCALER_64 );
}
}
//================================================================================
/*---------------------------------------------------------------------------*
Name: i_osIsTimerReserved
Description: check if specified timer is reserved for OS
Arguments: timerNum : timerNo (0-3)
Returns: non-0 if reserved
*---------------------------------------------------------------------------*/
u8 i_osIsTimerReserved( int timer_id )
{
return i_osTimerReserved[timer_id];
}
/*---------------------------------------------------------------------------*
Name: i_osSetTimerReserved
Description: set specified timer to reserved for OS
Arguments: timerNum : timerNo (0-3)
Returns: None.
*---------------------------------------------------------------------------*/
void i_osSetTimerReserved( int timer_id )
{
i_osTimerReserved[timer_id] = TRUE;
}
/*---------------------------------------------------------------------------*
Name: i_osUnsetTimerReserved
Description: unset specified timer to reserved for OS
Arguments: timerNum : timerNo (0-3)
Returns: None.
*---------------------------------------------------------------------------*/
void i_osUnsetTimerReserved( int timer_id )
{
i_osTimerReserved[timer_id] = FALSE;
}
//================================================================================
/*---------------------------------------------------------------------------*
Name: i_osStartTimer
Description: set timer(s) and start
Arguments: id timerNo
count count value to be set to timer
preScale preScale
Returns: None
*---------------------------------------------------------------------------*/
//
// use 1 timer, 16bit counter, timer<id> interrupt occurs by overflow
//
void i_osStartTimer( OSTimer id, u16 count, OSTimerPrescaler preScale )
{
SDK_ASSERT(OS_TIMER_0 <= id && id <= OS_TIMER_3);
SDK_ASSERT(OS_TIMER_PRESCALER_1 <= preScale && preScale <= OS_TIMER_PRESCALER_1024);
//---- check if system reserved
SDK_ASSERT(!i_osIsTimerReserved(id));
i_osSetTimerCount(id, (u16)~count);
i_osSetTimerControl(id, (u16)(REG_OS_TMCNT_H_E_MASK | REG_OS_TMCNT_H_I_MASK | preScale));
}
//
// use 2 timers, 32bit counter, timer<id+1> interrupt occurs by overflow
//
void i_osStartTimer32( OSTimer32 id, u32 count, OSTimerPrescaler preScale )
{
SDK_ASSERT(OS_TIMER32_01 <= id && id <= OS_TIMER32_23);
SDK_ASSERT(OS_TIMER_PRESCALER_1 <= preScale && preScale <= OS_TIMER_PRESCALER_1024);
//---- check if system reserved
SDK_ASSERT(!i_osIsTimerReserved(id));
SDK_ASSERT(!i_osIsTimerReserved(id + 1));
i_osSetTimerCount((OSTimer)((int)id + 1), (u16)((~count >> 16) & 0xffff));
i_osSetTimerCount((OSTimer)id, (u16)(~count & 0xffff));
i_osSetTimerControl((OSTimer)((int)id + 1),
REG_OS_TMCNT_H_E_MASK | REG_OS_TMCNT_H_I_MASK | REG_OS_TMCNT_H_CH_MASK);
i_osSetTimerControl((OSTimer)id, (u16)(REG_OS_TMCNT_H_E_MASK | preScale));
}
//
// use 3 timers, 48bit counter, timer<id+2> interrupt occurs by overflow
//
void i_osStartTimer48( OSTimer48 id, u64 count, OSTimerPrescaler preScale )
{
SDK_ASSERT(OS_TIMER48_012 <= id && id <= OS_TIMER48_123);
SDK_ASSERT(OS_TIMER_PRESCALER_1 <= preScale && preScale <= OS_TIMER_PRESCALER_1024);
//---- check if system reserved
SDK_ASSERT(!i_osIsTimerReserved(id));
SDK_ASSERT(!i_osIsTimerReserved(id + 1));
SDK_ASSERT(!i_osIsTimerReserved(id + 2));
i_osSetTimerCount((OSTimer)((int)id + 2), (u16)((~count >> 32) & 0xffff));
i_osSetTimerCount((OSTimer)((int)id + 1), (u16)((~count >> 16) & 0xffff));
i_osSetTimerCount((OSTimer)id, (u16)(~count & 0xffff));
i_osSetTimerControl((OSTimer)((int)id + 2),
REG_OS_TMCNT_H_E_MASK | REG_OS_TMCNT_H_I_MASK | REG_OS_TMCNT_H_CH_MASK);
i_osSetTimerControl((OSTimer)((int)id + 1), REG_OS_TMCNT_H_E_MASK | REG_OS_TMCNT_H_CH_MASK);
i_osSetTimerControl((OSTimer)id, (u16)(REG_OS_TMCNT_H_E_MASK | preScale));
}
//
// use all 4 timers, 64bit counter, timer3 interrupt occurs by overflow
//
void i_osStartTimer64( u64 count, OSTimerPrescaler preScale )
{
SDK_ASSERT(OS_TIMER_PRESCALER_1 <= preScale && preScale <= OS_TIMER_PRESCALER_1024);
//---- check if system reserved
SDK_ASSERT(!i_osIsTimerReserved(OS_TIMER_0));
SDK_ASSERT(!i_osIsTimerReserved(OS_TIMER_1));
SDK_ASSERT(!i_osIsTimerReserved(OS_TIMER_2));
SDK_ASSERT(!i_osIsTimerReserved(OS_TIMER_3));
i_osSetTimerCount(OS_TIMER_3, (u16)((~count >> 48) & 0xffff));
i_osSetTimerCount(OS_TIMER_2, (u16)((~count >> 32) & 0xffff));
i_osSetTimerCount(OS_TIMER_1, (u16)((~count >> 16) & 0xffff));
i_osSetTimerCount(OS_TIMER_0, (u16)(~count & 0xffff));
i_osSetTimerControl(OS_TIMER_3,
REG_OS_TMCNT_H_E_MASK | REG_OS_TMCNT_H_I_MASK | REG_OS_TMCNT_H_CH_MASK);
i_osSetTimerControl(OS_TIMER_2, REG_OS_TMCNT_H_E_MASK | REG_OS_TMCNT_H_CH_MASK);
i_osSetTimerControl(OS_TIMER_1, REG_OS_TMCNT_H_E_MASK | REG_OS_TMCNT_H_CH_MASK);
i_osSetTimerControl(OS_TIMER_0, (u16)(REG_OS_TMCNT_H_E_MASK | preScale));
}
/*---------------------------------------------------------------------------*
Name: i_osStopTimer
Description: stop timer(s)
Arguments: id timerNo
Returns: None
*---------------------------------------------------------------------------*/
//
// stop a timer
//
void i_osStopTimer( OSTimer id )
{
SDK_ASSERT(OS_TIMER_0 <= id && id <= OS_TIMER_3);
//---- check if system reserved
SDK_ASSERT(!i_osIsTimerReserved(id));
i_osSetTimerControl(id, 0);
}
//
// stop 2 timers
//
void i_osStopTimer32( OSTimer32 id )
{
SDK_ASSERT(OS_TIMER32_01 <= id && id <= OS_TIMER32_23);
//---- check if system reserved
SDK_ASSERT(!i_osIsTimerReserved(id));
SDK_ASSERT(!i_osIsTimerReserved(id + 1));
i_osStopTimer((OSTimer)((int)id + 1));
i_osStopTimer((OSTimer)id);
}
//
// stop 3 timers
//
void i_osStopTimer48( OSTimer48 id )
{
SDK_ASSERT(OS_TIMER48_012 <= id && id <= OS_TIMER48_123);
//---- check if system reserved
SDK_ASSERT(!i_osIsTimerReserved(id));
SDK_ASSERT(!i_osIsTimerReserved(id + 1));
SDK_ASSERT(!i_osIsTimerReserved(id + 2));
i_osStopTimer((OSTimer)((int)id + 2));
i_osStopTimer((OSTimer)((int)id + 1));
i_osStopTimer((OSTimer)id);
}
//
// stop all 4 timers
//
void i_osStopTimer64( void )
{
//---- check if system reserved
SDK_ASSERT(!i_osIsTimerReserved(OS_TIMER_0));
SDK_ASSERT(!i_osIsTimerReserved(OS_TIMER_1));
SDK_ASSERT(!i_osIsTimerReserved(OS_TIMER_2));
SDK_ASSERT(!i_osIsTimerReserved(OS_TIMER_3));
i_osStopTimer(OS_TIMER_3);
i_osStopTimer(OS_TIMER_2);
i_osStopTimer(OS_TIMER_1);
i_osStopTimer(OS_TIMER_0);
}

View File

@ -0,0 +1,34 @@
#! make -f
#----------------------------------------------------------------------------
# Project: CtrBrom - libraries - os
# File: Makefile
#
# 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 $(CTRBROM_ROOT)/build/buildtools/commondefs
#----------------------------------------------------------------------------
SUBDIRS = ARM11
#ifdef CTR_WITH_ARM9
SUBDIRS += ARM9
#endif
#----------------------------------------------------------------------------
include $(CTRBROM_ROOT)/build/buildtools/modulerules
#===== End of Makefile =====

View File

@ -24,6 +24,8 @@
extern "C" {
#endif
#define OS_TIMER_CLOCK_DEFAULT HW_CPU_CLOCK
//----------------------------------------------------------------------
//---- timer ID
@ -41,6 +43,20 @@ typedef enum
}
OSWatchdogMode;
typedef enum
{
OS_TM_AUTO_RELOAD = HW_CPUTM_AUTO_RELOAD,
OS_TM_SINGLE_SHOT = HW_CPUTM_SINGLE_SHOT
}
OSTimerRepeat;
typedef enum
{
OS_TM_INTR_REQ_ENABLE = HW_CPUTM_INTR_ENABLE,
OS_TM_INTR_REQ_DISABLE = 0
}
OSTimerIntrReq;
void osInitTimer( void );