ctr_firmware/trunk/bootrom/include/brom/os/common/system.h
nakasima 707f66fe25 割り込み処理のマージ。
git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-09-30%20-%20paladin.7z/paladin/ctr_firmware@128 b871894f-2f95-9b40-918c-086798483c85
2008-12-19 05:44:06 +00:00

215 lines
6.1 KiB
C

/*---------------------------------------------------------------------------*
Project: CtrBrom - OS - include
File: system.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_SYSTEM_H_
#define BROM_OS_SYSTEM_H_
#ifndef SDK_ASM
#include <brom/types.h>
#endif
#include <ctr/arm_reg.h>
#include <brom/os/common/tick.h>
#ifdef __cplusplus
extern "C" {
#endif
//----------------------------------------------------------------------------
typedef u32 OSCpuCycle;
#define OS_CPU_CLOCK HW_CPU_CLOCK
//---- sec to cpu cycle
// 150nsec - 30sec
#define OS_SEC_TO_CPUCYC( sec ) ((OSCpuCycle)( ( OS_CPU_CLOCK * (u32)(sec)) ))
#define OS_MSEC_TO_CPUCYC( msec ) ((OSCpuCycle)( ((OS_CPU_CLOCK/1000) * (u32)(msec)) ))
#define OS_USEC_TO_CPUCYC( usec ) ((OSCpuCycle)( ((OS_CPU_CLOCK/1000) * (u32)(usec)) / 1000 ))
#define OS_NSEC_TO_CPUCYC( nsec ) ((OSCpuCycle)( ((OS_CPU_CLOCK/1000) * (u32)(nsec)) / (1000 * 1000) ))
//---- cpu cycle to sec
// 150nsec - 30sec
#define OS_CPUCYC_TO_SEC( cyc ) ( ((u32)(cyc) ) / OS_CPU_CLOCK )
#define OS_CPUCYC_TO_MSEC( cyc ) ( ((u32)(cyc) ) / (OS_CPU_CLOCK/1000) )
#define OS_CPUCYC_TO_USEC( cyc ) ( ((u32)(cyc) * 1000) / (OS_CPU_CLOCK/1000) )
#define OS_CPUCYC_TO_NSEC( cyc ) ( ((u32)(cyc) * 1000 * 1000) / (OS_CPU_CLOCK/1000) )
#ifndef SDK_ASM
#define OS_EXIT_STRING_1 "*** Exit ctr program (status="
#define OS_EXIT_STRING_2 "%d).\n"
#define OS_EXIT_STRING OS_EXIT_STRING_1 OS_EXIT_STRING_2
typedef enum
{
OS_PROCMODE_USR = HW_PSR_USR_MODE,
OS_PROCMODE_FIQ = HW_PSR_FIQ_MODE,
OS_PROCMODE_IRQ = HW_PSR_IRQ_MODE,
OS_PROCMODE_SVC = HW_PSR_SVC_MODE,
OS_PROCMODE_ABORT = HW_PSR_ABORT_MODE,
OS_PROCMODE_UNDEF = HW_PSR_UNDEF_MODE,
OS_PROCMODE_SYS = HW_PSR_SYS_MODE
}
OSProcMode;
#ifdef SDK_ARM9
#define OS_SVC_STACK_SIZE 0x1000
#define OS_IRQ_STACK_SIZE 0x1000
#else // SDK_MPCORE
#endif // SDK_MPCORE
//---- sec to cpu cycle
// 150nsec - 30sec
static inline OSCpuCycle i_osSecToCpuCycle( u32 sec )
{
return OS_SEC_TO_CPUCYC( sec );
}
static inline OSCpuCycle i_osMSecToCpuCycle( u32 msec )
{
return OS_MSEC_TO_CPUCYC( msec );
}
static inline OSCpuCycle i_osUSecToCpuCycle( u32 usec )
{
return OS_USEC_TO_CPUCYC( usec );
}
static inline OSCpuCycle i_osNSecToCpuCycle( u32 nsec )
{
return OS_NSEC_TO_CPUCYC( nsec );
}
//---- cpu cycle to sec
// 150nsec - 30sec
static inline u32 i_osCpuCycleToSec( OSCpuCycle cyc )
{
return OS_CPUCYC_TO_SEC( cyc );
}
static inline u32 i_osCpuCycleToMSec( OSCpuCycle cyc )
{
return OS_CPUCYC_TO_MSEC( cyc );
}
static inline u32 i_osCpuCycleToUSec( OSCpuCycle cyc )
{
return OS_CPUCYC_TO_USEC( cyc );
}
static inline u32 i_osCpuCycleToNSec( OSCpuCycle cyc )
{
return OS_CPUCYC_TO_NSEC( cyc );
}
//============================================================================
// PROCESSER MODE
//============================================================================
/*---------------------------------------------------------------------------*
Name: osGetProcMode
Description: Get processor mode from CPSR
Arguments: None.
Returns: CPU processor mode (field 0x10-0x1f)
*---------------------------------------------------------------------------*/
OSProcMode osGetProcMode(void);
//============================================================================
// WAIT
//============================================================================
/*---------------------------------------------------------------------------*
Name: i_osWaitCpuCycles
Description: Loop and Wait for specified CPU cycles at least
150nsec - 30sec
Arguments: cycles waiting CPU cycle
Returns: None
*---------------------------------------------------------------------------*/
void i_osWaitCpuCycles( OSCpuCycle cycle );
//============================================================================
// TERMINATE and HALT
//============================================================================
/*---------------------------------------------------------------------------*
Name: osTerminate
Description: Halt CPU and loop
Arguments: None
Returns: None
*---------------------------------------------------------------------------*/
void osTerminate(void);
/*---------------------------------------------------------------------------*
Name: osHalt
Description: Halt CPU
Arguments: None
Returns: None
*---------------------------------------------------------------------------*/
void osHalt(void);
#ifdef SDK_ARM11
/*---------------------------------------------------------------------------*
Name: osHaltUntilEvent
Description: Halt CPU Core until Event
Arguments: None
Returns: None
*---------------------------------------------------------------------------*/
void osHaltUntilEvent( void );
#endif // SDK_ARM11
/*---------------------------------------------------------------------------*
Name: osExit
Description: Display exit string and Terminate.
This is useful for 'loadrun' tool command.
Arguments: status : exit status
Returns: -- (Never return)
*---------------------------------------------------------------------------*/
void osExit(int status);
#endif /* SDK_ASM */
#ifdef __cplusplus
} /* extern "C" */
#endif
/* BROM_OS_SYSTEM_H_ */
#endif