From bbaf1a132b0e95d6d289a7ba1ef8e56399e9857d Mon Sep 17 00:00:00 2001 From: shirait Date: Sat, 23 Jun 2007 09:03:51 +0000 Subject: [PATCH] fix SDIP err git-svn-id: file:///Users/lillianskinner/Downloads/platinum/twl/twl_wrapsdk/trunk@130 4ee2a332-4b2b-5046-8439-1ba90f034370 --- build/libraries/devices/sdmc/ARM7/Makefile | 7 ++--- build/libraries/devices/sdmc/ARM7/drsdmc.c | 4 +-- build/libraries/devices/sdmc/ARM7/sdif.c | 12 ++++----- build/libraries/devices/sdmc/ARM7/sdmc.c | 19 +++++++------- build/tests/Makefile | 11 ++++---- build/tests/fatfs/fatfs_sd/ARM7/src/main.c | 30 ++++++++++++++++++---- include/twl/devices/sdmc/ARM7/sdmc.h | 17 ++++++++++-- include/twl/rtfs.h | 17 ++++++++++++ include/twl/sdmc.h | 17 ++++++++++++ 9 files changed, 100 insertions(+), 34 deletions(-) create mode 100644 include/twl/rtfs.h create mode 100644 include/twl/sdmc.h diff --git a/build/libraries/devices/sdmc/ARM7/Makefile b/build/libraries/devices/sdmc/ARM7/Makefile index 1d09af5..afa2d01 100644 --- a/build/libraries/devices/sdmc/ARM7/Makefile +++ b/build/libraries/devices/sdmc/ARM7/Makefile @@ -28,11 +28,6 @@ TWL_PROC = ARM7 SRCDIR = ../common/src src -INCDIR = ../common -INCDIR += $(TWLSDK_ROOT)/include/twl \ - $(TWLSDK_ROOT)/include/twl/devices/sdmc/ARM7 \ - $(TWLSDK_ROOT)/include/twl/fatfs/ARM7 \ - SRCS = \ sdmc.c \ sdif.c \ @@ -52,6 +47,8 @@ endif include $(TWLSDK_ROOT)/build/buildtools/commondefs +GINCLUDES += $(TWL_INCDIR)/twl/fatfs/ARM7 + INSTALL_TARGETS = $(TARGETS) INSTALL_DIR = $(TWL_INSTALL_LIBDIR) diff --git a/build/libraries/devices/sdmc/ARM7/drsdmc.c b/build/libraries/devices/sdmc/ARM7/drsdmc.c index 81910fa..3c33732 100644 --- a/build/libraries/devices/sdmc/ARM7/drsdmc.c +++ b/build/libraries/devices/sdmc/ARM7/drsdmc.c @@ -11,12 +11,12 @@ in whole or in part, without the prior written consent of Nintendo. *---------------------------------------------------------------------------*/ -#include +#include #include //#if (INCLUDE_SD) #include "sdmc_config.h" -#include "sdmc.h" +#include #include "sdif_ip.h" #include "sdif_reg.h" diff --git a/build/libraries/devices/sdmc/ARM7/sdif.c b/build/libraries/devices/sdmc/ARM7/sdif.c index 5ee0104..92fd93a 100644 --- a/build/libraries/devices/sdmc/ARM7/sdif.c +++ b/build/libraries/devices/sdmc/ARM7/sdif.c @@ -8,7 +8,7 @@ #include #include "sdmc_config.h" #include "sdif_reg.h" /* IP 対応レジスタ定義 */ -#include "sdmc.h" +#include #include "sdif_ip.h" /* IP 対応フラグ定義 */ #if (SD_DEBUG_PRINT_ON == 1) @@ -139,7 +139,7 @@ u16 SD_Command(u16 ucCommand) SD_SetFPGA(SD_CMD,(ucCommand)); /* コマンド発行 */ while(!SD_CheckFPGAReg(SD_INFO1,SD_INFO1_RES_END)){ /* Response end 待ち */ - if(SDCARD_ErrStatus & SDMC_ERR_FPGA_TIMEOUT){ /* タイムアウトチェック */ + if( SDCARD_ErrStatus != SDMC_NORMAL){ /* タイムアウトチェック */ break; } } @@ -196,7 +196,7 @@ u16 SD_AppOpCond(void) { SD_ClrErr((u16)(~SDMC_ERR_FPGA_TIMEOUT)); /* タイムアウト以外のエラーをクリア */ - while(!SDCARD_ErrStatus){ /* エラーが発生しない間は繰り返し */ + while( !SDCARD_ErrStatus){ /* エラーが発生しない間は繰り返し */ /* Argument(31:0) = OCR without busy (0x00100000 = 3.2-3.3V) */ /*ホスト側で電圧を選択できる場合などは、初回にSD_ARG1を0にすることにより カードが対応している電圧を問い合わせることができる。CTRは電圧3.3V決め打ち @@ -242,7 +242,7 @@ u16 SD_SendOpCond(void) SD_ClrErr((u16)(~SDMC_ERR_FPGA_TIMEOUT)); /* タイムアウトエラーをクリア */ - while(!SDCARD_ErrStatus){ /* エラーが発生しない間は繰り返し */ + while( !SDCARD_ErrStatus){ /* エラーが発生しない間は繰り返し */ SD_SetFPGA(SD_ARG0,(0x0000)); /* Argument(15:0) for MMC (None for SD) */ SD_SetFPGA(SD_ARG1,(0x0010)); /* Argument(31:16) for MMC (None for SD) */ SD_Command(SD_CMD_CMD | SEND_OP_COND); /* CMD1発行、レスポンス(R1)待ち */ @@ -487,7 +487,7 @@ u16 SD_SendStatus(void) SD_SetFPGA(SD_CMD,(SD_CMD_CMD | SD_SEND_STATUS)); /* CMD13発行 */ while(!SD_CheckFPGAReg(SD_INFO1,SD_INFO1_RES_END)){ /* Response end (R1)待ち */ - if(SDCARD_ErrStatus & SDMC_ERR_FPGA_TIMEOUT){ + if( SDCARD_ErrStatus != SDMC_NORMAL) { break; } } @@ -1094,7 +1094,7 @@ u16 SD_TransCommand(u16 ucCommand) SD_SetFPGA(SD_CMD,(ucCommand)); /* コマンド発行 */ while(!SD_CheckFPGAReg(SD_INFO1,SD_INFO1_RES_END)){ /* Response end 待ち */ - if(SDCARD_ErrStatus & SDMC_ERR_FPGA_TIMEOUT){ + if( SDCARD_ErrStatus != SDMC_NORMAL) { break; } } diff --git a/build/libraries/devices/sdmc/ARM7/sdmc.c b/build/libraries/devices/sdmc/ARM7/sdmc.c index 2bc019f..c833626 100644 --- a/build/libraries/devices/sdmc/ARM7/sdmc.c +++ b/build/libraries/devices/sdmc/ARM7/sdmc.c @@ -9,7 +9,7 @@ //#include #include "sdmc_config.h" #include "sdif_reg.h" /* IP 対応レジスタ定義 */ -#include "sdmc.h" +#include #include "sdif_ip.h" /* IP 対応フラグ定義 */ /*#if (SD_DEBUG_PRINT_ON == 1) @@ -120,9 +120,9 @@ static void SDCARD_Thread( void* arg); //SD static void SDCARD_Intr_Thread( void* arg); //SD割り込み処理スレッド SDMC_ERR_CODE sdmcGoIdle( void (*func1)(),void (*func2)()); -/*static*/ SDMC_ERR_CODE i_sdmcInit( void); -/*static*/ SDMC_ERR_CODE SDCARD_Layer_Init(void); -/*static*/ SDMC_ERR_CODE i_sdmcMPInit( void); /* カードドライバ初期化(マルチポート対応) */ +static SDMC_ERR_CODE i_sdmcInit( void); +static SDMC_ERR_CODE SDCARD_Layer_Init(void); +static SDMC_ERR_CODE i_sdmcMPInit( void); /* カードドライバ初期化(マルチポート対応) */ static u16 i_sdmcErrProcess(void); /* エラー時の処理 */ static u16 i_sdmcGetResid(u32 *pResid); /* 書きこみ完了セクタ数の取得 */ @@ -394,13 +394,14 @@ static void SDCARD_Dmy_Handler( void) Description: Initialize SD interface and SD card. 初期化 - Arguments: func1 : カード挿入時コールバック関数 + Arguments: dma_no : DMA番号 + func1 : カード挿入時コールバック関数 func2 : カード排出時コールバック関数 Returns: 0 : success > 0 : error code *---------------------------------------------------------------------------*/ -SDMC_ERR_CODE sdmcInit(void (*func1)(),void (*func2)()) +SDMC_ERR_CODE sdmcInit( SDMC_DMA_NO dma_no, void (*func1)(),void (*func2)()) { #if (TARGET_OS_CTR == 1) T_CALM calm; @@ -580,7 +581,7 @@ SDMC_ERR_CODE sdmcGoIdle( void (*func1)(),void (*func2)()) Returns: 0 : success > 0 : error code *---------------------------------------------------------------------------*/ -/*static*/ SDMC_ERR_CODE i_sdmcInit( void) +static SDMC_ERR_CODE i_sdmcInit( void) { i_sdmcEnable(); @@ -663,7 +664,7 @@ SDMC_ERR_CODE sdmcReset( void) Returns: None *---------------------------------------------------------------------------*/ -/*static*/ SDMC_ERR_CODE SDCARD_Layer_Init(void) +static SDMC_ERR_CODE SDCARD_Layer_Init(void) { u32 ulCSize; // SYSTIM wait_tim, limit_tim; @@ -957,7 +958,7 @@ PRINTDEBUG( "SD_INFO1_MASK : 0x%x\n", (*(vu32 *)(SD_IP_BASE + 0x20)));*/ Returns: 0 : success > 0 : error code *---------------------------------------------------------------------------*/ -/*static*/ SDMC_ERR_CODE i_sdmcMPInit( void) +static SDMC_ERR_CODE i_sdmcMPInit( void) { if(((SD_port_number == SDCARD_PORT0) && (!SD_CheckFPGAReg(SD_INFO1,SD_INFO1_DETECT))) || ((SD_port_number == SDCARD_PORT1) && (!SD_CheckFPGAReg(EXT_CD,EXT_CD_PORT1_DETECT))) || diff --git a/build/tests/Makefile b/build/tests/Makefile index 7db7251..a42f757 100644 --- a/build/tests/Makefile +++ b/build/tests/Makefile @@ -20,11 +20,12 @@ include $(TWLSDK_ROOT)/build/buildtools/commondefs #---------------------------------------------------------------------------- -SUBDIRS = os \ - mi \ - aes \ - snd \ - camera \ +SUBDIRS = os \ + mi \ + aes \ + snd \ + camera \ + fatfs \ #---------------------------------------------------------------------------- diff --git a/build/tests/fatfs/fatfs_sd/ARM7/src/main.c b/build/tests/fatfs/fatfs_sd/ARM7/src/main.c index e572bff..8efb31c 100644 --- a/build/tests/fatfs/fatfs_sd/ARM7/src/main.c +++ b/build/tests/fatfs/fatfs_sd/ARM7/src/main.c @@ -16,7 +16,7 @@ #include #include -#include +#include /*---------------------------------------------------------------------------* 定数定義 @@ -66,10 +66,12 @@ void MY_SdTransferRewind( void) *---------------------------------------------------------------------------*/ void TwlSpMain(void) { + u16 i; OSHeapHandle heapHandle; SDMC_ERR_CODE result; SdmcResultInfo SdResult; PCFD fd; + CHKDISK_STATS dstat; // OS初期化 OS_Init(); @@ -175,7 +177,26 @@ void TwlSpMain(void) #else /*デバイスドライバの登録*/ - PRINTDEBUG( "attach start\n"); + for( i=0; i<2; i++) { + if( (i % 2) == 0) { + /*NANDからブロックライト/リード*/ + result = sdmcSelect( (u16)SDMC_PORT_NAND); + if( result != 0) { + PRINTDEBUG( "sdmcSelect(NAND) failed.\n"); + }else{ + PRINTDEBUG( "sdmcSelect(NAND) success.\n"); + } + }else{ + /*CARDからブロックライト/リード*/ + result = sdmcSelect( (u16)SDMC_PORT_CARD); + if( result != 0) { + PRINTDEBUG( "sdmcSelect(CARD) failed.\n"); + }else{ + PRINTDEBUG( "sdmcSelect(CARD) success.\n"); + } + } + + PRINTDEBUG( "attach start\n"); if( sdmcRtfsAttach( 4) == FALSE) { //sdmcをEドライブにする PRINTDEBUG( "sdmcRtfsAttach failed.\n"); }else{ @@ -193,11 +214,9 @@ void TwlSpMain(void) PRINTDEBUG( "pc_set_default_drive success\n"); /**/ - { - CHKDISK_STATS dstat; + PRINTDEBUG( "pc_check_disk start. please wait.\n"); pc_check_disk( (byte*)"E:", &dstat, 0, 1, 1); PRINTDEBUG( "pc_check_disk end.\n"); - } /*----------*/ fd = po_open( (byte*)"\\sdmc_twl_test.bin", (PO_CREAT|PO_BINARY|PO_WRONLY), PS_IWRITE); @@ -215,6 +234,7 @@ void TwlSpMain(void) } PRINTDEBUG( "po_close success.\n"); /*----------*/ + } #endif PRINTDEBUG( "Sample program ends.\n"); diff --git a/include/twl/devices/sdmc/ARM7/sdmc.h b/include/twl/devices/sdmc/ARM7/sdmc.h index d3fee12..303d8c6 100644 --- a/include/twl/devices/sdmc/ARM7/sdmc.h +++ b/include/twl/devices/sdmc/ARM7/sdmc.h @@ -3,7 +3,7 @@ #define __SDMC_H__ #include -#include +#include #ifdef __cplusplus @@ -21,6 +21,18 @@ typedef enum { }SDMC_PORT_NO; +/********************************************* + DMA番号 +*********************************************/ +typedef enum { + SDMC_USE_DMA_0 = 0, + SDMC_USE_DMA_1 = 1, + SDMC_USE_DMA_2 = 2, + SDMC_USE_DMA_3 = 3, + SDMC_NOUSE_DMA = 0xFF +}SDMC_DMA_NO; + + /********************************************* カードエラーコード(カードエラーステータス設定値)アプリケーション固有のSDCARD_ErrStatusに対して *********************************************/ @@ -78,6 +90,7 @@ typedef struct s16 OutFlag; u16 WP_PERMANENT; u16 WP_TEMPORARY; + u16 port_no; } SDPortContext; @@ -125,7 +138,7 @@ BOOL sdmcCheckMedia( void); /********************************************* 基本API *********************************************/ -SDMC_ERR_CODE sdmcInit(void (*func1)(void),void (*func2)(void)); /* カードドライバ初期化 */ +SDMC_ERR_CODE sdmcInit( SDMC_DMA_NO dma_no, void (*func1)(void),void (*func2)(void)); /* カードドライバ初期化 */ SDMC_ERR_CODE sdmcReset( void); /* カードリセット */ SDMC_ERR_CODE sdmcGetStatus(u16 *status); /* カードドライバの現在の状態を取得する */ diff --git a/include/twl/rtfs.h b/include/twl/rtfs.h new file mode 100644 index 0000000..8be0634 --- /dev/null +++ b/include/twl/rtfs.h @@ -0,0 +1,17 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - IO Register List - + File: twl/ioreg.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. + + *---------------------------------------------------------------------------*/ +#ifdef SDK_ARM9 +#else //SDK_ARM7 +#include +#endif diff --git a/include/twl/sdmc.h b/include/twl/sdmc.h new file mode 100644 index 0000000..c6fde76 --- /dev/null +++ b/include/twl/sdmc.h @@ -0,0 +1,17 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - SD driver - + File: twl/sdmc.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. + + *---------------------------------------------------------------------------*/ +#ifdef SDK_ARM9 +#else //SDK_ARM7 +#include +#endif