fix OS_InitLock.

add speed-1 and OS_ChangeSpeedOfARM9.

git-svn-id: file:///Users/lillianskinner/Downloads/platinum/twl/twl_wrapsdk/trunk@280 4ee2a332-4b2b-5046-8439-1ba90f034370
This commit is contained in:
nakasima 2007-09-19 06:34:12 +00:00
parent 2b12f4abac
commit 2ce85b99b8
10 changed files with 387 additions and 5 deletions

View File

@ -38,13 +38,13 @@ SRCDIR += $(TWL_NITROSDK_ROOT)/build/libraries/os/common/src \
$(TWL_NITROSDK_ROOT)/build/libraries/os/ARM9/src \ $(TWL_NITROSDK_ROOT)/build/libraries/os/ARM9/src \
SRCS = \ SRCS = \
os_system.c \
os_init.c \ os_init.c \
os_interrupt.c \ os_interrupt.c \
os_irqHandler.c \ os_irqHandler.c \
os_irqTable.c \ os_irqTable.c \
os_spinLock.c \ os_spinLock.c \
os_printf.c \ os_printf.c \
os_system.c \
os_entropy.c \ os_entropy.c \
os_thread.c \ os_thread.c \
os_context.c \ os_context.c \

View File

@ -283,6 +283,11 @@ void OS_InitLock(void)
// Code for SUB PROCESSOR // Code for SUB PROCESSOR
// //
while (lockp->ownerID != OS_MAINP_SYSTEM_LOCK_ID - 1)
{
OSi_WaitByLoop();
}
lockp->extension = 0; lockp->extension = 0;
while (lockp->ownerID != OS_MAINP_SYSTEM_LOCK_ID) while (lockp->ownerID != OS_MAINP_SYSTEM_LOCK_ID)
{ {

View File

@ -114,7 +114,7 @@
$NoKeywords: $ $NoKeywords: $
*---------------------------------------------------------------------------*/ *---------------------------------------------------------------------------*/
#include <nitro/os.h> #include <twl/os.h>
#include <nitro/code32.h> #include <nitro/code32.h>
//============================================================================ //============================================================================
@ -398,3 +398,47 @@ void OS_WaitVBlankIntr(void)
#endif #endif
OS_WaitIrq(TRUE, OS_IE_V_BLANK); OS_WaitIrq(TRUE, OS_IE_V_BLANK);
} }
#ifdef SDK_ARM9
/*---------------------------------------------------------------------------*
Name: OS_ChangeSpeedOfARM9
Description: change speed of arm9
Arguments: None
Returns: None
*---------------------------------------------------------------------------*/
typedef void (*OSi_ChangeSpeedOfARM9Entry)( OSSpeedOfARM9 clock );
static asm void OSi_ChangeSpeedOfARM9Core( OSSpeedOfARM9 clock )
{
ldr r3, =REG_CLK_ADDR
ldr r2, =REG_CFG_CLK_ARM2X_MASK
ldrh r1, [r3]
bic r1, r1, r2
orr r1, r1, r0
strh r1, [r3]
mov r0, #8
@1:
subs r0, r0, #4 // 1 cycle
bge @1 // 3 cycle
bx lr
ltorg
}
void OS_ChangeSpeedOfARM9( OSSpeedOfARM9 clock, void* itcm )
{
OSi_ChangeSpeedOfARM9Entry entry = itcm;
MIi_CpuCopyFast( OSi_ChangeSpeedOfARM9Core, itcm, 64 );
entry( clock );
}
#endif // SDK_ARM9

View File

@ -20,11 +20,12 @@ include $(TWLSDK_ROOT)/build/buildtools/commondefs
#---------------------------------------------------------------------------- #----------------------------------------------------------------------------
SUBDIRS = alarm-1 \ SUBDIRS = alarm-1 \
sleep-1 \ sleep-1 \
speed-1 \
svc-rsa \ svc-rsa \
svc-sha1 \ svc-sha1 \
debugLED \ debugLED \
#---------------------------------------------------------------------------- #----------------------------------------------------------------------------

View File

@ -0,0 +1,44 @@
#! make -f
#----------------------------------------------------------------------------
# Project: TwlSDK - OS - demos - sleep-1
# File: Makefile
#
# Copyright 2007 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.
#
# $Log: $
# $NoKeywords: $
#----------------------------------------------------------------------------
SUBDIRS =
#----------------------------------------------------------------------------
#TWL_CODEGEN = THUMB
TWL_PROC = ARM7
TARGET_BIN = main.axf
SRCS = main.c
#SRCDIR = # using default
#LCFILE = # using default
include $(TWLSDK_ROOT)/build/buildtools/commondefs
#----------------------------------------------------------------------------
do-build: $(TARGETS)
include $(TWLSDK_ROOT)/build/buildtools/modulerules
#===== End of Makefile =====

View File

@ -0,0 +1,101 @@
/*---------------------------------------------------------------------------*
Project: NitroSDK - OS - demos - speed-1
File: main.c
Copyright 2007 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.
$Log: main.c,v $
$NoKeywords: $
*---------------------------------------------------------------------------*/
#include <twl.h>
#define MY_SPIN_CYCLES 0x00080000
#define OSi_IDLE_CHECKNUM_SIZE ( sizeof(u32)*2 )
#define OSi_IDLE_SVC_SIZE ( sizeof(u32)*16 ) // arm7 svc stacks 14 words
#define OSi_IDLE_THREAD_STACK_SIZE ( OSi_IDLE_CHECKNUM_SIZE + OSi_IDLE_SVC_SIZE )
extern u32 OSi_IdleThreadStack[OSi_IDLE_THREAD_STACK_SIZE / sizeof(u32)];
extern OSThread OSi_IdleThread;
/*---------------------------------------------------------------------------*
Name: OSi_IdleThreadProc
Description: procedure of idle thread which system creates
Arguments: None
Returns: None (never return)
*---------------------------------------------------------------------------*/
static void OSi_IdleThreadProc(void *)
{
(void)OS_EnableInterrupts();
while (1)
{
OS_Halt();
}
// never return
}
// VBlank interrupt handler
static void VBlankIntr(void)
{
//---- 割り込みチェックフラグ
OS_SetIrqCheckFlag(OS_IE_V_BLANK);
}
/*---------------------------------------------------------------------------*
Name: TwlSpMain
Description: main
Arguments: None
Returns: None
*---------------------------------------------------------------------------*/
void TwlSpMain()
{
OS_Init();
OS_Printf("ARM7 starts.\n");
// create idle thread to sleep in main thread
OS_CreateThread(&OSi_IdleThread,
OSi_IdleThreadProc,
(void *)NULL,
OSi_IdleThreadStack + OSi_IDLE_THREAD_STACK_SIZE / sizeof(u32),
OSi_IDLE_THREAD_STACK_SIZE,
OS_THREAD_PRIORITY_MAX /*pseudo. change at next line. */ );
OSi_IdleThread.priority = OS_THREAD_PRIORITY_MAX + 1; // lower priority than the lowest (=OS_THREAD_PRIORITY_MAX)
OSi_IdleThread.state = OS_THREAD_STATE_READY;
//---- Vブランク設定
(void)OS_SetIrqFunction(OS_IE_V_BLANK, VBlankIntr);
(void)OS_EnableIrqMask(OS_IE_V_BLANK);
(void)OS_EnableIrq();
(void)GX_VBlankIntr(TRUE);
OS_InitTick();
while (1)
{
OSTick start, end;
OS_WaitVBlankIntr();
start = OS_GetTick();
OS_SpinWait( MY_SPIN_CYCLES );
end = OS_GetTick();
OS_Printf( "SpinWait period of ARM7: %d ms\n", OS_TicksToMicroSeconds( end - start ) );
}
// done
OS_TPrintf("\nARM7 ends.\n");
OS_Terminate();
}

View File

@ -0,0 +1,43 @@
#! make -f
#----------------------------------------------------------------------------
# Project: TwlSDK - OS - demos - sleep-1
# File: Makefile
#
# Copyright 2007 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.
#
# $Log: $
# $NoKeywords: $
#----------------------------------------------------------------------------
SUBDIRS =
#----------------------------------------------------------------------------
#TWL_CODEGEN = THUMB
TARGET_BIN = main.axf
SRCS = main.c
#SRCDIR = # using default
#LCFILE = # using default
include $(TWLSDK_ROOT)/build/buildtools/commondefs
#----------------------------------------------------------------------------
do-build: $(TARGETS)
include $(TWLSDK_ROOT)/build/buildtools/modulerules
#===== End of Makefile =====

View File

@ -0,0 +1,77 @@
/*---------------------------------------------------------------------------*
Project: NitroSDK - OS - demos - speed-1
File: main.c
Copyright 2007 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.
$Log: main.c,v $
$NoKeywords: $
*---------------------------------------------------------------------------*/
#include <twl.h>
#define MY_SPIN_CYCLES 0x00080000
// VBlank interrupt handler
static void VBlankIntr(void)
{
//---- 割り込みチェックフラグ
OS_SetIrqCheckFlag(OS_IE_V_BLANK);
}
/*---------------------------------------------------------------------------*
Name: TwlMain
Description: main
Arguments: None
Returns: None
*---------------------------------------------------------------------------*/
void TwlMain()
{
OS_Init();
OS_Printf("ARM9 starts.\n");
OS_InitTick();
//---- Vブランク設定
(void)OS_SetIrqFunction(OS_IE_V_BLANK, VBlankIntr);
(void)OS_EnableIrqMask(OS_IE_V_BLANK);
(void)OS_EnableIrq();
(void)GX_VBlankIntr(TRUE);
while (1)
{
OSTick start, end;
OS_WaitVBlankIntr();
OS_ChangeSpeedOfARM9( OS_SPEED_ARM9_X1, (void*)(HW_ITCM + HW_ITCM_SIZE/2) );
start = OS_GetTick();
OS_SpinWait( MY_SPIN_CYCLES );
end = OS_GetTick();
OS_Printf( "SpinWait period of ARM9 X1: %d us\n", OS_TicksToMicroSeconds( end - start ) );
OS_WaitVBlankIntr();
OS_ChangeSpeedOfARM9( OS_SPEED_ARM9_X2, (void*)(HW_ITCM + HW_ITCM_SIZE/2) );
start = OS_GetTick();
OS_SpinWait( MY_SPIN_CYCLES );
end = OS_GetTick();
OS_Printf( "SpinWait period of ARM9 X2: %d us\n", OS_TicksToMicroSeconds( end - start ) );
}
// done
OS_TPrintf("\nARM9 ends.\n");
OS_Terminate();
}

View File

@ -0,0 +1,42 @@
#! make -f
#----------------------------------------------------------------------------
# Project: TwlSDK - build
# File: Makefile
#
# Copyright 2007 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.
#
# $Log: $
# $NoKeywords: $
#----------------------------------------------------------------------------
SUBDIRS = \
ARM7 \
ARM9 \
#----------------------------------------------------------------------------
TARGET_BIN = speed-1.srl
MAKEROM_ARM9 = ARM9/bin/$(TWL_BUILDTYPE_ARM9)/main.axf
MAKEROM_ARM7 = ARM7/bin/$(TWL_BUILDTYPE_ARM7)/main.axf
#----------------------------------------------------------------------------
include $(TWLSDK_ROOT)/build/buildtools/commondefs
#----------------------------------------------------------------------------
ifeq ($(TWL_PLATFORM),TS)
do-build: $(TARGETS)
endif
include $(TWLSDK_ROOT)/build/buildtools/modulerules
#===== End of Makefile =====

View File

@ -35,6 +35,9 @@ typedef enum
} }
OSChipType; OSChipType;
//---- entry point type
typedef void (*OSEntryPoint) (void);
typedef u32 OSCpuCycle; typedef u32 OSCpuCycle;
#define OS_CPU_CLOCK HW_CPU_CLOCK #define OS_CPU_CLOCK HW_CPU_CLOCK
@ -54,6 +57,28 @@ typedef u32 OSCpuCycle;
#define OS_CPUCYC_TO_NSEC( cyc ) ( ((u32)(cyc) * 1000 * 1000) / (OS_CPU_CLOCK/1000) ) #define OS_CPUCYC_TO_NSEC( cyc ) ( ((u32)(cyc) * 1000 * 1000) / (OS_CPU_CLOCK/1000) )
#ifdef SDK_ARM9
typedef enum
{
OS_SPEED_ARM9_X1 = 0,
OS_SPEED_ARM9_X2 = REG_CFG_CLK_ARM2X_MASK
}
OSSpeedOfARM9;
/*---------------------------------------------------------------------------*
Name: OS_ChangeSpeedOfARM9
Description: change speed of arm9
Arguments: None
Returns: None
*---------------------------------------------------------------------------*/
void OS_ChangeSpeedOfARM9( OSSpeedOfARM9 clock, void* itcm );
#endif // SDK_ARM9
#ifdef __cplusplus #ifdef __cplusplus
} /* extern "C" */ } /* extern "C" */