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@123 b871894f-2f95-9b40-918c-086798483c85
325 lines
8.9 KiB
C
325 lines
8.9 KiB
C
/*---------------------------------------------------------------------------*
|
|
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_
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#include <brom/misc.h>
|
|
#include <brom/types.h>
|
|
#include <ctr/ioreg.h>
|
|
|
|
#include <brom/os/common/interrupt_common.h>
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
#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;
|
|
|
|
//---- 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;
|
|
|
|
#else // SDK_ARM9
|
|
//---- control
|
|
typedef u16 OSTimerControl;
|
|
|
|
//---- count
|
|
typedef u16 OSTimerCount;
|
|
|
|
//---- pre-scaler
|
|
typedef enum
|
|
{
|
|
OS_TIMER_PRESCALER_1 = (0UL << REG_OS_TM0CNT_H_PS_SHIFT), // x 1
|
|
OS_TIMER_PRESCALER_64 = (1UL << REG_OS_TM0CNT_H_PS_SHIFT), // x 64
|
|
OS_TIMER_PRESCALER_256 = (2UL << REG_OS_TM0CNT_H_PS_SHIFT), // x 256
|
|
OS_TIMER_PRESCALER_1024 = (3UL << REG_OS_TM0CNT_H_PS_SHIFT) // x 1024
|
|
}
|
|
OSTimerPrescaler;
|
|
|
|
//---- timer number
|
|
typedef enum
|
|
{
|
|
OS_TIMER_0 = 0,
|
|
OS_TIMER_1 = 1,
|
|
OS_TIMER_2 = 2,
|
|
OS_TIMER_3 = 3,
|
|
OS_TIMER_NUM
|
|
}
|
|
OSTimer;
|
|
|
|
//---- timer number ( if use 32 bit timer )
|
|
typedef enum
|
|
{
|
|
OS_TIMER32_01 = 0,
|
|
OS_TIMER32_12 = 1,
|
|
OS_TIMER32_23 = 2
|
|
}
|
|
OSTimer32;
|
|
|
|
//---- timer number ( if use 48 bit timer )
|
|
typedef enum
|
|
{
|
|
OS_TIMER48_012 = 0,
|
|
OS_TIMER48_123 = 1
|
|
}
|
|
OSTimer48;
|
|
|
|
#endif // SDK_ARM9
|
|
|
|
|
|
//================================================================================
|
|
// TIMER
|
|
//================================================================================
|
|
/*---------------------------------------------------------------------------*
|
|
Name: osInitTimer
|
|
|
|
Description: Initialize Timers
|
|
|
|
Arguments: None
|
|
|
|
Returns: None
|
|
*---------------------------------------------------------------------------*/
|
|
void osInitTimer( void );
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
Name: osSetTimerCount
|
|
|
|
Description: set timer count
|
|
|
|
Arguments: id timerNo
|
|
count count value to be set to timer
|
|
|
|
Returns: None
|
|
*---------------------------------------------------------------------------*/
|
|
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_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
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
Name: osGetTimerCount
|
|
|
|
Description: get timer count
|
|
|
|
Arguments: id timerNo
|
|
|
|
Returns: None
|
|
*---------------------------------------------------------------------------*/
|
|
static inline OSTimerCount osGetTimerCount( OSTimer id)
|
|
{
|
|
SDK_ASSERT(OS_TIMER_0 <= id && id < OS_TIMER_NUM);
|
|
#ifdef SDK_ARM11
|
|
return *((REGType32 *)((u32)REG_TM_COUNT_ADDR + id * (REG_WD_CNT_ADDR-REG_TM_CNT_ADDR)));
|
|
#else // SDK_ARM9
|
|
return *((REGType16 *)((u32)REG_TM0CNT_L_ADDR + id * 4));
|
|
#endif // SDK_ARM9
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
Name: osSetTimerControl
|
|
|
|
Description: set timer control
|
|
|
|
Arguments: id timerNo
|
|
control control value to be set to timer
|
|
|
|
Returns: None
|
|
*---------------------------------------------------------------------------*/
|
|
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))) = 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
|
|
|
|
Description: set timer(s) and start
|
|
|
|
Arguments: id timerNo
|
|
count count value to be set to timer
|
|
preScale preScale
|
|
|
|
Returns: None
|
|
*---------------------------------------------------------------------------*/
|
|
void osStartTimer( OSTimer id, OSTimerCount count, OSTimerPrescaler preScale );
|
|
|
|
#ifdef SDK_ARM9
|
|
//
|
|
// use 1 timer, 16bit counter, timer<id> interrupt occurs by overflow
|
|
//
|
|
//void osStartTimer( OSTimer id, OSTimerCount count, OSTimerPrescaler preScale );
|
|
//
|
|
// use 2 timers, 32bit counter, timer<id+1> interrupt occurs by overflow
|
|
//
|
|
void osStartTimer32( OSTimer32 id, u32 count, OSTimerPrescaler preScale );
|
|
//
|
|
// use 3 timers, 48bit counter, timer<id+2> interrupt occurs by overflow
|
|
//
|
|
void osStartTimer48( OSTimer48 id, u64 count, OSTimerPrescaler preScale );
|
|
//
|
|
// use all 4 timers, 64bit counter, timer3 interrupt occurs by overflow
|
|
//
|
|
void osStartTimer64( u64 count, OSTimerPrescaler preScale );
|
|
|
|
#endif // SDK_ARM9
|
|
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
Name: osStopTimer
|
|
|
|
Description: stop timer(s)
|
|
|
|
Arguments: id timerNo
|
|
|
|
Returns: None
|
|
*---------------------------------------------------------------------------*/
|
|
//
|
|
// stop a timer
|
|
//
|
|
void osStopTimer( OSTimer id );
|
|
|
|
#ifdef SDK_ARM9
|
|
|
|
//
|
|
// stop 2 timers
|
|
//
|
|
void osStopTimer32( OSTimer32 id );
|
|
//
|
|
// stop 3 timers
|
|
//
|
|
void osStopTimer48( OSTimer48 id );
|
|
//
|
|
// stop all 4 timers
|
|
//
|
|
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
|
|
|
|
Description: Reset Watchdog
|
|
|
|
Arguments: None
|
|
|
|
Returns: None
|
|
*---------------------------------------------------------------------------*/
|
|
void osResetWatchdog( void );
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
Name: osDisableWatchdog
|
|
|
|
Description: Disable Watchdog
|
|
|
|
Arguments: None
|
|
|
|
Returns: None
|
|
*---------------------------------------------------------------------------*/
|
|
void osDisableWatchdog( void );
|
|
|
|
#endif // SDK_ARM11
|
|
|
|
|
|
#ifdef __cplusplus
|
|
} /* extern "C" */
|
|
#endif
|
|
|
|
/* BROM_OS_TIMER_H_ */
|
|
#endif
|