diff --git a/build/libraries/os/ARM9/Makefile b/build/libraries/os/ARM9/Makefile index a8f7940..4b8ee56 100644 --- a/build/libraries/os/ARM9/Makefile +++ b/build/libraries/os/ARM9/Makefile @@ -38,13 +38,13 @@ SRCDIR += $(TWL_NITROSDK_ROOT)/build/libraries/os/common/src \ $(TWL_NITROSDK_ROOT)/build/libraries/os/ARM9/src \ SRCS = \ + os_system.c \ os_init.c \ os_interrupt.c \ os_irqHandler.c \ os_irqTable.c \ os_spinLock.c \ os_printf.c \ - os_system.c \ os_entropy.c \ os_thread.c \ os_context.c \ diff --git a/build/libraries/os/common/os_spinLock.c b/build/libraries/os/common/os_spinLock.c index 637acee..71d191a 100644 --- a/build/libraries/os/common/os_spinLock.c +++ b/build/libraries/os/common/os_spinLock.c @@ -283,6 +283,11 @@ void OS_InitLock(void) // Code for SUB PROCESSOR // + while (lockp->ownerID != OS_MAINP_SYSTEM_LOCK_ID - 1) + { + OSi_WaitByLoop(); + } + lockp->extension = 0; while (lockp->ownerID != OS_MAINP_SYSTEM_LOCK_ID) { diff --git a/build/libraries/os/common/os_system.c b/build/libraries/os/common/os_system.c index 31309da..1542c53 100644 --- a/build/libraries/os/common/os_system.c +++ b/build/libraries/os/common/os_system.c @@ -114,7 +114,7 @@ $NoKeywords: $ *---------------------------------------------------------------------------*/ -#include +#include #include //============================================================================ @@ -398,3 +398,47 @@ void OS_WaitVBlankIntr(void) #endif 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 + diff --git a/build/tests/os/Makefile b/build/tests/os/Makefile index 9cbfef5..584a53d 100644 --- a/build/tests/os/Makefile +++ b/build/tests/os/Makefile @@ -20,11 +20,12 @@ include $(TWLSDK_ROOT)/build/buildtools/commondefs #---------------------------------------------------------------------------- -SUBDIRS = alarm-1 \ - sleep-1 \ +SUBDIRS = alarm-1 \ + sleep-1 \ + speed-1 \ svc-rsa \ svc-sha1 \ - debugLED \ + debugLED \ #---------------------------------------------------------------------------- diff --git a/build/tests/os/speed-1/ARM7/Makefile b/build/tests/os/speed-1/ARM7/Makefile new file mode 100644 index 0000000..927d172 --- /dev/null +++ b/build/tests/os/speed-1/ARM7/Makefile @@ -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 ===== diff --git a/build/tests/os/speed-1/ARM7/src/main.c b/build/tests/os/speed-1/ARM7/src/main.c new file mode 100644 index 0000000..c799f71 --- /dev/null +++ b/build/tests/os/speed-1/ARM7/src/main.c @@ -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 + +#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(); +} diff --git a/build/tests/os/speed-1/ARM9/Makefile b/build/tests/os/speed-1/ARM9/Makefile new file mode 100644 index 0000000..8ab2e82 --- /dev/null +++ b/build/tests/os/speed-1/ARM9/Makefile @@ -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 ===== diff --git a/build/tests/os/speed-1/ARM9/src/main.c b/build/tests/os/speed-1/ARM9/src/main.c new file mode 100644 index 0000000..982ac26 --- /dev/null +++ b/build/tests/os/speed-1/ARM9/src/main.c @@ -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 + +#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(); +} + diff --git a/build/tests/os/speed-1/Makefile b/build/tests/os/speed-1/Makefile new file mode 100644 index 0000000..df55ffe --- /dev/null +++ b/build/tests/os/speed-1/Makefile @@ -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 ===== diff --git a/include/twl/os/common/system.h b/include/twl/os/common/system.h index 866ffae..b963e00 100644 --- a/include/twl/os/common/system.h +++ b/include/twl/os/common/system.h @@ -35,6 +35,9 @@ typedef enum } OSChipType; +//---- entry point type +typedef void (*OSEntryPoint) (void); + typedef u32 OSCpuCycle; #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) ) +#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 } /* extern "C" */