From 0cee338ff138fdd8697ab0ba3c0577733febf26b Mon Sep 17 00:00:00 2001 From: nakasima Date: Tue, 29 May 2007 12:06:49 +0000 Subject: [PATCH] add mic. git-svn-id: file:///Users/lillianskinner/Downloads/platinum/twl/twl_wrapsdk/trunk@95 4ee2a332-4b2b-5046-8439-1ba90f034370 --- build/libraries/snd/ARM7/Makefile | 3 +- build/libraries/snd/ARM7/snd_mic.c | 178 ++++++++++++++++++++++ build/tests/snd/Makefile | 2 + build/tests/snd/mic-1/ARM7/Makefile | 44 ++++++ build/tests/snd/mic-1/ARM7/src/main.c | 63 ++++++++ build/tests/snd/mic-1/ARM9/Makefile | 43 ++++++ build/tests/snd/mic-1/ARM9/src/main.c | 35 +++++ build/tests/snd/mic-1/Makefile | 32 ++++ build/tests/snd/mic-2/ARM7/Makefile | 44 ++++++ build/tests/snd/mic-2/ARM7/src/main.c | 207 ++++++++++++++++++++++++++ build/tests/snd/mic-2/ARM9/Makefile | 43 ++++++ build/tests/snd/mic-2/ARM9/src/main.c | 35 +++++ build/tests/snd/mic-2/Makefile | 32 ++++ include/twl.h | 1 + include/twl/mic.h | 25 ++++ include/twl/os/common/system.h | 19 +++ include/twl/snd/ARM7/snd_mic.h | 86 +++++++++++ 17 files changed, 891 insertions(+), 1 deletion(-) create mode 100644 build/libraries/snd/ARM7/snd_mic.c create mode 100644 build/tests/snd/mic-1/ARM7/Makefile create mode 100644 build/tests/snd/mic-1/ARM7/src/main.c create mode 100644 build/tests/snd/mic-1/ARM9/Makefile create mode 100644 build/tests/snd/mic-1/ARM9/src/main.c create mode 100644 build/tests/snd/mic-1/Makefile create mode 100644 build/tests/snd/mic-2/ARM7/Makefile create mode 100644 build/tests/snd/mic-2/ARM7/src/main.c create mode 100644 build/tests/snd/mic-2/ARM9/Makefile create mode 100644 build/tests/snd/mic-2/ARM9/src/main.c create mode 100644 build/tests/snd/mic-2/Makefile create mode 100644 include/twl/mic.h create mode 100644 include/twl/snd/ARM7/snd_mic.h diff --git a/build/libraries/snd/ARM7/Makefile b/build/libraries/snd/ARM7/Makefile index bc91a05..21d89f8 100644 --- a/build/libraries/snd/ARM7/Makefile +++ b/build/libraries/snd/ARM7/Makefile @@ -43,7 +43,8 @@ SRCS = \ snd_alarm.c \ snd_command.c \ snd_data.c \ - snd_i2s.c + snd_i2s.c \ + snd_mic.c \ TARGET_LIB = libsnd_sp$(TWL_LIBSUFFIX).a diff --git a/build/libraries/snd/ARM7/snd_mic.c b/build/libraries/snd/ARM7/snd_mic.c new file mode 100644 index 0000000..5a71b72 --- /dev/null +++ b/build/libraries/snd/ARM7/snd_mic.c @@ -0,0 +1,178 @@ +/*---------------------------------------------------------------------------* + Project: CtrSDK - MIC + File: mic.c + + Copyright 2006 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: $ + *---------------------------------------------------------------------------*/ + +#include +#include + + +static void MICi_ExDmaRecvAsync( u32 dmaNo, void *dest, s32 size ); +void MICi_ExDmaInterruptHandler( void ); + +void MICi_DmaInterruptHandler( void ); +void MICi_FifoInterruptHandler( void ); + +static MICWork micWork; + + +/*---------------------------------------------------------------------------* + Name: MICi_Start + + Description: start MIC + + Arguments: dtc : enable DTC or not + + Returns: None + *---------------------------------------------------------------------------*/ +void MICi_Start( MICSampleRate smp, u32 dmaNo, void *dest, s32 size ) +{ + MICWork *wp = &micWork; + + OSIntrMode enabled; + + wp->dmaNo = dmaNo; + wp->buf = dest; + wp->bufSize = size; + + MICi_Stop(); + + enabled = OS_DisableInterrupts(); + + if ( dest != NULL ) + { + if ( MI_EXDMA_CH_MIN <= dmaNo && dmaNo <= MI_EXDMA_CH_MAX ) + { + u32 ch = dmaNo + MI_EXDMA_CH_MIN; + + MIi_StopExDma( dmaNo ); + + MICi_ExDmaRecvAsync( dmaNo, dest, size ); + + OS_SetIrqFunction( OS_IE_DMA4 + ch, MICi_ExDmaInterruptHandler ); + + reg_OS_IF = (OS_IE_DMA4 << ch); + reg_OS_IE |= (OS_IE_DMA4 << ch); // enable mic dma interrupt + } + } + + SND_Enable(); + + // start monoral sampling + reg_SND_MICCNT = (u8)REG_SND_MICCNT_FIFO_CLR_MASK; + reg_SND_MICCNT = (u8)(REG_SND_MICCNT_E_MASK | REG_SND_MICCNT_NR_MASK | MIC_INTR_OVERFLOW + | smp); + + (void)OS_RestoreInterrupts(enabled); +} + +/*---------------------------------------------------------------------------* + Name: MICi_Stop + + Description: stop MIC + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void MICi_Stop( void ) +{ + MICWork *wp = &micWork; + + OSIntrMode enabled = OS_DisableInterrupts(); + + if ( reg_SND_MICCNT & REG_SND_MICCNT_E_MASK ) + { + u32 dmaNo = wp->dmaNo; + + reg_SND_MICCNT &= ~REG_SND_MICCNT_E_MASK; + + if ( MI_EXDMA_CH_MIN <= dmaNo && dmaNo <= MI_EXDMA_CH_MAX ) + { + u32 ch = dmaNo + MI_EXDMA_CH_MIN; + + MIi_StopExDma( dmaNo ); + + reg_OS_IE &= ~(OS_IE_DMA4 << ch); // disable mic dma interrupt + reg_OS_IF = (OS_IE_DMA4 << ch); + } + else + { + reg_OS_IE2 &= ~(OS_IE_MIC >> 32); // disable mic fifo interrupt + reg_OS_IF2 = (OS_IE_MIC >> 32); + } + } + + (void)OS_RestoreInterrupts(enabled); +} + +/*---------------------------------------------------------------------------* + Name: MICi_ExDmaRecvAsync + + Description: receive data with DMA + async version + + Arguments: dmaNo : DMA channel No. + dest : destination address + size : size (byte) + + Returns: None + *---------------------------------------------------------------------------*/ +static void MICi_ExDmaRecvAsync( u32 dmaNo, void *dest, s32 size ) +{ + u32 interval = (0x2C0 * 16) - 16; + MIExDmaPrescaler prescale = MI_EXDMA_PRESCALER_1; + + MIi_ExDmaRecvAsyncCore( dmaNo, (void*)REG_MIC_FIFO_ADDR, dest, + (u32)size, (u32)size, + MI_EXDMA_BLOCK_32B, interval, prescale, + MI_EXDMA_CONTINUOUS_ON, MI_EXDMA_SRC_RLD_ON, MI_EXDMA_DEST_RLD_ON, + MI_EXDMA_TIMING_MIC ); +} + +/*---------------------------------------------------------------------------* + Name: MICi_ExDmaInterruptHandler + + Description: interrupt handler + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void MICi_ExDmaInterruptHandler( void ) +{ +// MICWork *wp = &micWork; + +// OS_TPrintf( "*" ); + +// MICi_ExDmaRecvAsync( wp->dmaNo, wp->buf, wp->bufSize ); +} + +/*---------------------------------------------------------------------------* + Name: MICi_FifoInterruptHandler + + Description: interrupt handler + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void MICi_FifoInterruptHandler( void ) +{ + MICWork *wp = &micWork; + + MIi_CpuSend32( (void*)REG_MIC_FIFO_ADDR, wp->buf, (u32)wp->bufSize ); +} + + diff --git a/build/tests/snd/Makefile b/build/tests/snd/Makefile index 31fb70f..285231d 100644 --- a/build/tests/snd/Makefile +++ b/build/tests/snd/Makefile @@ -22,6 +22,8 @@ include $(TWLSDK_ROOT)/build/buildtools/commondefs SUBDIRS = channel \ capture \ + mic-1 \ + mic-2 \ #---------------------------------------------------------------------------- diff --git a/build/tests/snd/mic-1/ARM7/Makefile b/build/tests/snd/mic-1/ARM7/Makefile new file mode 100644 index 0000000..962ad7f --- /dev/null +++ b/build/tests/snd/mic-1/ARM7/Makefile @@ -0,0 +1,44 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlSDK - SND - demos - channel +# 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 = mic7_1.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/snd/mic-1/ARM7/src/main.c b/build/tests/snd/mic-1/ARM7/src/main.c new file mode 100644 index 0000000..78de828 --- /dev/null +++ b/build/tests/snd/mic-1/ARM7/src/main.c @@ -0,0 +1,63 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - tests - snd - mic-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 +#include + +#include + +// ===== スレッド優先度 ===== + +#define THREAD_PRIO_SND 6 + +#define MY_MIC_BUF_LEN 0x100 + +u16 micBuf[MY_MIC_BUF_LEN] __attribute__ ((aligned (32))); + +void TwlSpMain(void) +{ + int i, ii; + + OS_Init(); + OS_InitThread(); + + // サウンド初期化 + SND_Init(THREAD_PRIO_SND); + + OS_TPrintf("\nARM7 starts.\n"); + + MICi_Start( MIC_SMP_ALL, MIC_DEFAULT_DMA_NO, micBuf, sizeof(micBuf) ); + OS_TPrintf( "\nMIC starts.\n"); + + OS_SpinWait( OS_MSEC_TO_CPUCYC( 60 ) ); + + MICi_Stop(); + OS_TPrintf( "\nMIC stops.\n"); + + OS_TPrintf( "\nDump mic buffer.\n" ); + for (i=0; i + +/*---------------------------------------------------------------------------* + Name: TwlMain + + Description: main + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void TwlMain() +{ + OS_Init(); + + OS_TPrintf("\nARM9 starts.\n"); + OS_TPrintf("\nARM9 ends.\n"); + OS_Terminate(); +} + diff --git a/build/tests/snd/mic-1/Makefile b/build/tests/snd/mic-1/Makefile new file mode 100644 index 0000000..078ec37 --- /dev/null +++ b/build/tests/snd/mic-1/Makefile @@ -0,0 +1,32 @@ +#! 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: $ +#---------------------------------------------------------------------------- + +include $(TWLSDK_ROOT)/build/buildtools/commondefs + + +#---------------------------------------------------------------------------- + +SUBDIRS = \ + ARM7 \ + ARM9 \ + +#---------------------------------------------------------------------------- + +include $(TWLSDK_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/tests/snd/mic-2/ARM7/Makefile b/build/tests/snd/mic-2/ARM7/Makefile new file mode 100644 index 0000000..da04480 --- /dev/null +++ b/build/tests/snd/mic-2/ARM7/Makefile @@ -0,0 +1,44 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlSDK - SND - demos - channel +# 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 = mic7_2.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/snd/mic-2/ARM7/src/main.c b/build/tests/snd/mic-2/ARM7/src/main.c new file mode 100644 index 0000000..bc8cc1e --- /dev/null +++ b/build/tests/snd/mic-2/ARM7/src/main.c @@ -0,0 +1,207 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - tests - snd - mic-2 + 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 +#include + +#include + + +#define ENABLE_PSG + +#define MY_MIC_BUF_LEN 0x100 + +#define MPI 3.14159265358979323846 + +#define MY_SND_16 + +#ifdef MY_SND_16 +#define MY_SND_BYTES 2 +#define MY_SND_DATA_MAX 0x7fff +#define MY_SND_WAVE_FMT SND_WAVE_FORMAT_PCM16 +#define MY_SND_CAP_FMT SND_CAPTURE_FORMAT_PCM16 +typedef s16 mySndType; +#else +#define MY_SND_BYTES 1 +#define MY_SND_DATA_MAX 0x7f +#define MY_SND_WAVE_FMT SND_WAVE_FORMAT_PCM8 +#define MY_SND_CAP_FMT SND_CAPTURE_FORMAT_PCM8 +typedef s8 mySndType; +#endif + +#define MY_SND_FREQ 0x160 // 0x200 + +#define MY_SND_BUF_LEN (0x0400/MY_SND_BYTES) +#define MY_SND_CAPTURE_LEN (0x1000/MY_SND_BYTES) + +u16 micBuf[MY_MIC_BUF_LEN] __attribute__ ((aligned (32))); + +mySndType wavBuf[2][MY_SND_BUF_LEN] __attribute__ ((aligned (32))); +mySndType capBuf[2][MY_SND_CAPTURE_LEN] __attribute__ ((aligned (32))); + + +static void MY_SndInit( void ) +{ + OSIntrMode enabled; + int i; + + for (i=0; i + +/*---------------------------------------------------------------------------* + Name: TwlMain + + Description: main + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void TwlMain() +{ + OS_Init(); + + OS_TPrintf("\nARM9 starts.\n"); + OS_TPrintf("\nARM9 ends.\n"); + OS_Terminate(); +} + diff --git a/build/tests/snd/mic-2/Makefile b/build/tests/snd/mic-2/Makefile new file mode 100644 index 0000000..078ec37 --- /dev/null +++ b/build/tests/snd/mic-2/Makefile @@ -0,0 +1,32 @@ +#! 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: $ +#---------------------------------------------------------------------------- + +include $(TWLSDK_ROOT)/build/buildtools/commondefs + + +#---------------------------------------------------------------------------- + +SUBDIRS = \ + ARM7 \ + ARM9 \ + +#---------------------------------------------------------------------------- + +include $(TWLSDK_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/include/twl.h b/include/twl.h index 97b06c6..017d870 100644 --- a/include/twl.h +++ b/include/twl.h @@ -21,6 +21,7 @@ #include #include #include +#include #ifdef SDK_DEBUGGER_KMC #include #endif // SDK_DEBUGGER_KMC diff --git a/include/twl/mic.h b/include/twl/mic.h new file mode 100644 index 0000000..4553c0f --- /dev/null +++ b/include/twl/mic.h @@ -0,0 +1,25 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - include - MIC + File: mic.h + + 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: $ + *---------------------------------------------------------------------------*/ + +#ifndef TWL_MIC_H_ +#define TWL_MIC_H_ + +#ifdef SDK_ARM7 +#include +#endif // SDK_ARM7 + +/* TWL_MIC_H_ */ +#endif diff --git a/include/twl/os/common/system.h b/include/twl/os/common/system.h index 48c5fb3..866ffae 100644 --- a/include/twl/os/common/system.h +++ b/include/twl/os/common/system.h @@ -35,6 +35,25 @@ typedef enum } OSChipType; +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) ) + + #ifdef __cplusplus } /* extern "C" */ diff --git a/include/twl/snd/ARM7/snd_mic.h b/include/twl/snd/ARM7/snd_mic.h new file mode 100644 index 0000000..457e4ee --- /dev/null +++ b/include/twl/snd/ARM7/snd_mic.h @@ -0,0 +1,86 @@ +/*---------------------------------------------------------------------------* + Project: CtrSDK - MIC - include + File: snd_mic.h + + Copyright 2006 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: $ + *---------------------------------------------------------------------------*/ +#ifndef TWL_SND_MIC_H_ +#define TWL_SND_MIC_H_ + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum +{ + MIC_INTR_DISABLE = (0x0UL << REG_SND_MICCNT_IM_SHIFT), + MIC_INTR_HALF = (0x1UL << REG_SND_MICCNT_IM_SHIFT), + MIC_INTR_OVERFLOW = (0x2UL << REG_SND_MICCNT_IM_SHIFT), + MIC_INTR_HALF_OVERFLOW = (0x3UL << REG_SND_MICCNT_IM_SHIFT) +} +MICIntrCond; + +typedef enum +{ + MIC_SMP_ALL = (0x0UL << REG_SND_MICCNT_FIFO_SMP_SHIFT), + MIC_SMP_1_2 = (0x1UL << REG_SND_MICCNT_FIFO_SMP_SHIFT), + MIC_SMP_1_3 = (0x2UL << REG_SND_MICCNT_FIFO_SMP_SHIFT), + MIC_SMP_1_4 = (0x3UL << REG_SND_MICCNT_FIFO_SMP_SHIFT) +} +MICSampleRate; + + +typedef struct +{ + u32 dmaNo; // DMA No + void* buf; + s32 bufSize; +} +MICWork; + + +#define MIC_DEFAULT_DMA_NO 6 + + +/*---------------------------------------------------------------------------* + Name: MICi_Start + + Description: start MIC + + Arguments: id : slave id + + Returns: None + *---------------------------------------------------------------------------*/ +void MICi_Start( MICSampleRate smp, u32 dmaNo, void *dest, s32 size ); + +/*---------------------------------------------------------------------------* + Name: MICi_Stop + + Description: stop MIC + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void MICi_Stop( void ); + + +#ifdef __cplusplus +} /* extern "C" */ + +#endif + +/* TWL_SND_MIC_H_ */ +#endif