mirror of
https://github.com/rvtr/twl_wrapsdk.git
synced 2025-10-31 06:11:10 -04:00
Thread不使用版SDドライバ追加、サンプル追加
git-svn-id: file:///Users/lillianskinner/Downloads/platinum/twl/twl_wrapsdk/trunk@102 4ee2a332-4b2b-5046-8439-1ba90f034370
This commit is contained in:
parent
892f15666b
commit
25677ae79a
@ -33,6 +33,7 @@ SUBDIRS = \
|
||||
cdc \
|
||||
snd \
|
||||
camera \
|
||||
devices \
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
export NITRO_BLXCHECKED = yes
|
||||
|
||||
@ -22,6 +22,7 @@ include $(TWLSDK_ROOT)/build/buildtools/commondefs
|
||||
|
||||
SUBDIRS = \
|
||||
sdmc \
|
||||
rom_sdmc \
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
export NITRO_BLXCHECKED = yes
|
||||
|
||||
66
build/libraries/devices/rom_sdmc/ARM7/Makefile
Normal file
66
build/libraries/devices/rom_sdmc/ARM7/Makefile
Normal file
@ -0,0 +1,66 @@
|
||||
#! make -f
|
||||
#----------------------------------------------------------------------------
|
||||
# Project: TwlSDK - libraries - mi/ARM7
|
||||
# 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 =
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
# build ARM & THUMB libraries
|
||||
TWL_CODEGEN_ALL ?= True
|
||||
|
||||
# Codegen for sub processer
|
||||
TWL_PROC = ARM7
|
||||
|
||||
SRCDIR = ../common/src src
|
||||
|
||||
INCDIR = ../common
|
||||
INCDIR += $(TWLSDK_ROOT)/include/twl \
|
||||
$(TWLSDK_ROOT)/include/twl/devices/rom_sdmc/ARM7 \
|
||||
$(TWLSDK_ROOT)/include/twl/fatfs/ARM7 \
|
||||
|
||||
SRCS = \
|
||||
sdmc.c \
|
||||
sdif.c \
|
||||
drsdmc.c
|
||||
|
||||
TARGET_LIB = libromsd_sp$(TWL_LIBSUFFIX).a
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
# DEBUG版ビルドの場合、RELEASE版でビルドして
|
||||
# DEBUG版のライブラリを装います。
|
||||
|
||||
ifdef NITRO_DEBUG
|
||||
NITRO_BUILD_TYPE = RELEASE
|
||||
endif
|
||||
|
||||
include $(TWLSDK_ROOT)/build/buildtools/commondefs
|
||||
|
||||
INSTALL_TARGETS = $(TARGETS)
|
||||
INSTALL_DIR = $(TWL_INSTALL_LIBDIR)
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
do-build: $(TARGETS)
|
||||
|
||||
include $(TWLSDK_ROOT)/build/buildtools/modulerules
|
||||
|
||||
|
||||
#===== End of Makefile =====
|
||||
686
build/libraries/devices/rom_sdmc/ARM7/drsdmc.c
Normal file
686
build/libraries/devices/rom_sdmc/ARM7/drsdmc.c
Normal file
@ -0,0 +1,686 @@
|
||||
/*---------------------------------------------------------------------------*
|
||||
Project: CTR - rtfs interface for SD Memory Card
|
||||
File: drsdmc.h
|
||||
|
||||
Copyright 2006,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.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#include <rtfs.h>
|
||||
#include <portconf.h>
|
||||
//#if (INCLUDE_SD)
|
||||
|
||||
#include "sdmc_config.h"
|
||||
#include "sdmc.h"
|
||||
#include "sdif_ip.h"
|
||||
#include "sdif_reg.h"
|
||||
|
||||
#if (SD_DEBUG_PRINT_ON == 1)
|
||||
#if (CTR_DEF_ENVIRONMENT_DSEMU == 1)
|
||||
#define PRINTDEBUG osTPrintf
|
||||
#else
|
||||
#include <ctr/vlink.h>
|
||||
#define PRINTDEBUG vlink_dos_printf
|
||||
#endif
|
||||
#else
|
||||
#define PRINTDEBUG( ...) ((void)0)
|
||||
#endif
|
||||
|
||||
|
||||
#define NUM_SD_PAGES
|
||||
#define SD_PAGE_SIZE
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
extern変数
|
||||
*---------------------------------------------------------------------------*/
|
||||
//extern ER_ID sdmc_dtq_id;
|
||||
//extern ER_ID sdmc_result_dtq_id;
|
||||
extern void (*func_SDCARD_In)(void); /* カード挿入イベント用コールバック保存用 */
|
||||
extern void (*func_SDCARD_Out)(void); /* カード排出イベント用コールバック保存用 */
|
||||
extern volatile s16 SDCARD_OutFlag; /* カード排出発生判定フラグ */
|
||||
|
||||
extern int rtfs_first_stat_flag[26];
|
||||
|
||||
/*SDメモリカードのスペック構造体*/
|
||||
extern SdmcSpec sdmc_current_spec;
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
extern関数
|
||||
*---------------------------------------------------------------------------*/
|
||||
extern SDMC_ERR_CODE sdmcGoIdle(void (*func1)(),void (*func2)());
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
static変数
|
||||
*---------------------------------------------------------------------------*/
|
||||
static int sdmc_drive_no;
|
||||
void (*func_usr_sdmc_out)(void) = NULL; /* カード排出イベントのユーザコールバック */
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
static関数
|
||||
*---------------------------------------------------------------------------*/
|
||||
void i_sdmcRemovedIntr( void);
|
||||
static void sdi_get_CHS_params( void);
|
||||
static u32 sdi_get_ceil( u32 cval, u32 mval);
|
||||
static void sdi_get_nom( void);
|
||||
static void sdi_get_fatparams( void);
|
||||
static void sdi_build_partition_table( void);
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: sdmcCheckMedia
|
||||
|
||||
Description: MBRのシグネチャおよび
|
||||
パーティションのフォーマット種別をチェックする
|
||||
|
||||
Arguments:
|
||||
|
||||
Returns: TRUE/FALSE
|
||||
(FALSEなら pc_format_media が必要)
|
||||
*---------------------------------------------------------------------------*/
|
||||
BOOL sdmcCheckMedia( void)
|
||||
{
|
||||
u16 i;
|
||||
SdmcResultInfo SdResult;
|
||||
u8* bufp;
|
||||
u32 buffer[512/4];
|
||||
u8 systemid;
|
||||
|
||||
/**/
|
||||
if( sdmcReadFifo( buffer, 1, 0, NULL, &SdResult)) {
|
||||
return( FALSE);
|
||||
}
|
||||
|
||||
bufp = (u8*)buffer;
|
||||
|
||||
/* Check the Signature Word. */
|
||||
if( (bufp[510]!=0x55) || (bufp[511]!=0xAA)) {
|
||||
return( FALSE);
|
||||
}
|
||||
/* Check the System ID of partition. */
|
||||
systemid = bufp[450];
|
||||
if( (systemid!=0x01) && (systemid!=0x04) && (systemid!=0x06) &&
|
||||
(systemid!=0x0B) && (systemid!=0x0C)) {
|
||||
return( FALSE);
|
||||
}
|
||||
/* Check the System ID of unuse partitions. */
|
||||
for( i=1; i<4; i++) {
|
||||
systemid = bufp[450+(16*i)];
|
||||
if( systemid != 0x00) {
|
||||
return( FALSE);
|
||||
}
|
||||
}
|
||||
/**/
|
||||
/*もっと厳密にチェックするならパーティション0開始位置の
|
||||
正当性も調べる*/
|
||||
return( TRUE);
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: sdmcRtfsIo
|
||||
|
||||
Description: 上位層からのセクタリード/ライト要求を受ける
|
||||
|
||||
Arguments: driveno : ドライブ番号
|
||||
block : 開始ブロック番号
|
||||
buffer :
|
||||
count : ブロック数
|
||||
reading : リード要求時にTRUE
|
||||
|
||||
Returns: TRUE/FALSE
|
||||
*---------------------------------------------------------------------------*/
|
||||
BOOL sdmcRtfsIo( int driveno, dword block, void* buffer, word count, BOOLEAN reading)
|
||||
{
|
||||
u16 result;
|
||||
SdmcResultInfo SdResult;
|
||||
|
||||
if( reading) {
|
||||
PRINTDEBUG( "DEVCTL_IO_READ ... block:%x, count:%x -> buf:%x\n", block, count, buffer);
|
||||
result = sdmcReadFifo( buffer, count, block, NULL, &SdResult);
|
||||
// result = sdmcRead( buffer, count, block, NULL, &SdResult);
|
||||
}else{
|
||||
PRINTDEBUG( "DEVCTL_IO_WRITE ... block:%x, count:%x <- buf:%x\n", block, count, buffer);
|
||||
result = sdmcWriteFifo( buffer, count, block, NULL, &SdResult);
|
||||
// result = sdmcWrite( buffer, count, block, NULL, &SdResult);
|
||||
}
|
||||
if( result) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: sdmcRtfsCtrl
|
||||
|
||||
Description: 上位層からのコントロール要求を受ける
|
||||
|
||||
Arguments: driveno : ドライブ番号
|
||||
opcode : 要求の種類
|
||||
pargs :
|
||||
|
||||
Returns:
|
||||
Memo : DRIVE_FLAGS_REMOVABLEの場合、ドライバのIO関数を呼ぶ前に
|
||||
CTRL関数のDEVCTL_CHECK_STATUSが呼ばれる。
|
||||
DEVTEST_CHANGED→DEVTEST_NOCHANGEが確認されるとRTFSはセクタ0を
|
||||
読みに行き、FATパラメータを取得した上で目的のセクタを読みに行く。
|
||||
CTRL関数の前にはDEVCTL_CHECK_STATUSが呼ばれないので、DEVCTL_
|
||||
GET_GEOMETRYでは自前で再挿入をチェックする必要がある。
|
||||
*---------------------------------------------------------------------------*/
|
||||
int sdmcRtfsCtrl( int driveno, int opcode, void* pargs)
|
||||
{
|
||||
DDRIVE *pdr;
|
||||
DEV_GEOMETRY gc;
|
||||
int heads, secptrack;
|
||||
|
||||
pdr = pc_drno_to_drive_struct( driveno);
|
||||
|
||||
switch( opcode) {
|
||||
case DEVCTL_GET_GEOMETRY: //formatまたはpartirionするときにRTFSが使うパラメータ
|
||||
PRINTDEBUG( "DEVCTL_GET_GEOMETRY\n");
|
||||
if( (pdr->drive_flags & DRIVE_FLAGS_INSERTED) == 0) { /* 抜かれていた場合 */
|
||||
if( SDCARD_OutFlag == TRUE) { /* 今現在も抜かれているとき */
|
||||
return( -1);
|
||||
}else{ /* 今現在は再挿入されているとき */
|
||||
/*-- GoIdleセット --*/
|
||||
if( func_SDCARD_Out != i_sdmcRemovedIntr) {
|
||||
func_usr_sdmc_out = func_SDCARD_Out; //ユーザコールバック取得
|
||||
}
|
||||
sdmcGoIdle( func_SDCARD_In, i_sdmcRemovedIntr); //カード初期化シーケンス
|
||||
/*------------------*/
|
||||
}
|
||||
}
|
||||
|
||||
rtfs_memset( &gc, (byte)0, sizeof(gc));
|
||||
|
||||
sdi_get_CHS_params(); //最初に呼ぶこと
|
||||
sdi_get_fatparams();
|
||||
sdi_get_nom();
|
||||
|
||||
PRINTDEBUG( "heads : 0x%x\n", sdmc_current_spec.heads);
|
||||
PRINTDEBUG( "secptrack : 0x%x\n", sdmc_current_spec.secptrack);
|
||||
PRINTDEBUG( "cylinders : 0x%x\n", sdmc_current_spec.cylinders);
|
||||
PRINTDEBUG( "SC : 0x%x\n", sdmc_current_spec.SC);
|
||||
PRINTDEBUG( "BU : 0x%x\n", sdmc_current_spec.BU);
|
||||
PRINTDEBUG( "RDE : 0x%x\n", sdmc_current_spec.RDE);
|
||||
PRINTDEBUG( "SS : 0x%x\n", sdmc_current_spec.SS);
|
||||
PRINTDEBUG( "RSC : 0x%x\n", sdmc_current_spec.RSC);
|
||||
PRINTDEBUG( "FATBITS : 0x%x\n", sdmc_current_spec.FATBITS);
|
||||
PRINTDEBUG( "SF : 0x%x\n", sdmc_current_spec.SF);
|
||||
PRINTDEBUG( "SSA : 0x%x\n", sdmc_current_spec.SSA);
|
||||
PRINTDEBUG( "NOM : 0x%x\n", sdmc_current_spec.NOM);
|
||||
|
||||
gc.dev_geometry_lbas = (sdmc_current_spec.adjusted_memory_capacity);// - sdmc_current_spec.NOM);
|
||||
gc.dev_geometry_heads = sdmc_current_spec.heads;
|
||||
gc.dev_geometry_cylinders = sdmc_current_spec.cylinders;
|
||||
gc.dev_geometry_secptrack = sdmc_current_spec.secptrack;
|
||||
/**/
|
||||
gc.fmt_parms_valid = TRUE;
|
||||
gc.fmt.oemname[0] = 'C';
|
||||
gc.fmt.oemname[1] = 'T';
|
||||
gc.fmt.oemname[2] = 'R';
|
||||
gc.fmt.oemname[3] = '\0';
|
||||
gc.fmt.secpalloc = sdmc_current_spec.SC; /*sectors per cluster(FIX by capacity)*/
|
||||
gc.fmt.secreserved = sdmc_current_spec.RSC;//sdmc_current_spec.RSC;/*reserved sectors(FIX 1 at FAT12,16)*/
|
||||
gc.fmt.numfats = 2;
|
||||
gc.fmt.secpfat = sdmc_current_spec.SF;
|
||||
gc.fmt.numhide = sdmc_current_spec.NOM; /**/
|
||||
gc.fmt.numroot = sdmc_current_spec.RDE; /*FIX*/
|
||||
gc.fmt.mediadesc = 0xF8;
|
||||
gc.fmt.secptrk = sdmc_current_spec.secptrack; //CHS Recommendation
|
||||
gc.fmt.numhead = sdmc_current_spec.heads;
|
||||
gc.fmt.numcyl = sdmc_current_spec.cylinders;
|
||||
gc.fmt.physical_drive_no = driveno;
|
||||
gc.fmt.binary_volume_label = BIN_VOL_LABEL;
|
||||
gc.fmt.text_volume_label[0] = '\0';
|
||||
//TODO:dev_geometry_lbasもセットする必要あるか調べること
|
||||
PRINTDEBUG( "heads : 0x%x, secptrack : 0x%x, cylinders : 0x%x\n", gc.dev_geometry_heads, gc.dev_geometry_secptrack, gc.dev_geometry_cylinders);
|
||||
|
||||
#if (TARGET_OS_CTR == 1)
|
||||
miCpuCopy8( &gc, pargs, sizeof(gc));
|
||||
// copybuff( pargs, &gc, sizeof(gc));
|
||||
#else
|
||||
MI_CpuCopy8( &gc, pargs, sizeof(gc));
|
||||
#endif
|
||||
return( 0);
|
||||
|
||||
case DEVCTL_FORMAT:
|
||||
PRINTDEBUG( "DEVCTL_FORMAT\n");
|
||||
sdi_build_partition_table(); //MBRセクタ(パーティションテーブル含む)書き込み
|
||||
return( 0);
|
||||
|
||||
case DEVCTL_REPORT_REMOVE: //抜かれたとき
|
||||
PRINTDEBUG( "DEVCTL_REPORT_REMOVE\n");
|
||||
pdr->drive_flags &= ~DRIVE_FLAGS_INSERTED;
|
||||
return( 0);
|
||||
|
||||
case DEVCTL_CHECKSTATUS: //REMOVABLEの場合、毎回R/W前に呼ばれる
|
||||
PRINTDEBUG( "DEVCTL_CHECKSTATUS\n");
|
||||
if (!(pdr->drive_flags & DRIVE_FLAGS_REMOVABLE)) { //リムーバブルでない場合
|
||||
return(DEVTEST_NOCHANGE);
|
||||
}
|
||||
if (pdr->drive_flags & DRIVE_FLAGS_INSERTED) { /* 抜かれてない場合 */
|
||||
if( rtfs_first_stat_flag[driveno]) { //初回のCHECKSTATUS時
|
||||
rtfs_first_stat_flag[driveno] = 0;
|
||||
PRINTDEBUG( "CHANGED!\n");
|
||||
return(DEVTEST_CHANGED);
|
||||
}else{
|
||||
PRINTDEBUG( "DEVTEST_NOCHANGE\n");
|
||||
return( DEVTEST_NOCHANGE);
|
||||
}
|
||||
}else{ /* 抜かれていた場合 */
|
||||
if( SDCARD_OutFlag == FALSE) { /* 排出フラグ参照 */
|
||||
pdr->drive_flags |= DRIVE_FLAGS_INSERTED;
|
||||
/*-- GoIdleセット --*/
|
||||
if( func_SDCARD_Out != i_sdmcRemovedIntr) {
|
||||
func_usr_sdmc_out = func_SDCARD_Out; //ユーザコールバック取得
|
||||
}
|
||||
sdmcGoIdle( func_SDCARD_In, i_sdmcRemovedIntr); //カード初期化シーケンス
|
||||
/*------------------*/
|
||||
PRINTDEBUG( "DEVTEST_CHANGED\n");
|
||||
return( DEVTEST_CHANGED); //挿さっている
|
||||
}else{
|
||||
PRINTDEBUG( "DEVTEST_NOMEDIA\n");
|
||||
return( DEVTEST_NOMEDIA); //挿さってない
|
||||
}
|
||||
}
|
||||
|
||||
case DEVCTL_WARMSTART: //attachのときしか呼ばれない
|
||||
PRINTDEBUG( "DEVCTL_WARMSTART\n");
|
||||
/*-- GoIdleセット --*/
|
||||
if( func_SDCARD_Out != i_sdmcRemovedIntr) {
|
||||
func_usr_sdmc_out = func_SDCARD_Out; //ユーザコールバック取得
|
||||
}
|
||||
sdmcGoIdle( func_SDCARD_In, i_sdmcRemovedIntr); //カード初期化シーケンス
|
||||
/*------------------*/
|
||||
pdr->drive_flags |= (DRIVE_FLAGS_VALID | DRIVE_FLAGS_REMOVABLE | DRIVE_FLAGS_PARTITIONED);
|
||||
pdr->partition_number = 0;
|
||||
|
||||
if( SDCARD_OutFlag == FALSE) { /* 排出フラグ参照 */
|
||||
pdr->drive_flags |= DRIVE_FLAGS_INSERTED;
|
||||
}else{ /* カード未挿入のとき */
|
||||
pdr->drive_flags &= (~(DRIVE_FLAGS_INSERTED)); //抜かれているだけではVALIDフラグは落とさないらしい
|
||||
}
|
||||
return( 0);
|
||||
|
||||
case DEVCTL_POWER_RESTORE:
|
||||
PRINTDEBUG( "DEVCTL_POWER_RESTORE\n");
|
||||
break;
|
||||
|
||||
case DEVCTL_POWER_LOSS:
|
||||
PRINTDEBUG( "DEVCTL_POWER_LOSS\n");
|
||||
break;
|
||||
|
||||
default:
|
||||
PRINTDEBUG( "DEVCTL_unknown\n");
|
||||
break;
|
||||
}
|
||||
return( 0);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
抜取コールバック関数
|
||||
|
||||
RTFSが次回"DEVCTL_GET_GEOMETRY"を行うとき、ここでセットしたパラメータを知る
|
||||
*---------------------------------------------------------------------------*/
|
||||
void i_sdmcRemovedIntr( void)
|
||||
{
|
||||
DDRIVE *pdr;
|
||||
|
||||
pdr = pc_drno_to_drive_struct( sdmc_drive_no);
|
||||
if( pdr) {
|
||||
pdr->dev_table_perform_device_ioctl( pdr->driveno,
|
||||
DEVCTL_REPORT_REMOVE,
|
||||
(void*)0);
|
||||
}
|
||||
|
||||
if( func_usr_sdmc_out) {
|
||||
func_usr_sdmc_out(); //ユーザコールバック
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: sdmcRtfsAttach
|
||||
|
||||
Description: sdmcドライバをドライブに割り当てる
|
||||
|
||||
Arguments: driveno : ドライブ番号
|
||||
|
||||
Returns:
|
||||
*---------------------------------------------------------------------------*/
|
||||
BOOL sdmcRtfsAttach( int driveno)
|
||||
{
|
||||
BOOLEAN result;
|
||||
DDRIVE pdr;
|
||||
|
||||
pdr.dev_table_drive_io = sdmcRtfsIo;
|
||||
pdr.dev_table_perform_device_ioctl = sdmcRtfsCtrl;
|
||||
pdr.register_file_address = (dword) 0; /* Not used */
|
||||
pdr.interrupt_number = 0; /* Not used */
|
||||
pdr.drive_flags = 0;//DRIVE_FLAGS_FAILSAFE;
|
||||
pdr.partition_number = 0; /* Not used */
|
||||
pdr.pcmcia_slot_number = 0; /* Not used */
|
||||
pdr.controller_number = 0;
|
||||
pdr.logical_unit_number = 0;
|
||||
|
||||
result = rtfs_attach( driveno, &pdr, "SD"); //構造体がFSライブラリ側にコピーされる
|
||||
|
||||
/*drivenoをグローバル変数に記憶*/
|
||||
sdmc_drive_no = driveno;
|
||||
|
||||
return( result);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*SD File System Specification(仕様書)に基づいた値を出す*/
|
||||
static void sdi_get_CHS_params( void)
|
||||
{
|
||||
int mbytes;
|
||||
|
||||
// mbytes = (sdmc_current_spec.card_capacity / (1024 * 1024)) * 512;
|
||||
mbytes = (sdmc_current_spec.card_capacity >> 11);
|
||||
|
||||
while( 1) {
|
||||
if( mbytes <= 2) {
|
||||
sdmc_current_spec.heads = 2;
|
||||
sdmc_current_spec.secptrack = 16;
|
||||
break;
|
||||
}
|
||||
if( mbytes <= 16) {
|
||||
sdmc_current_spec.heads = 2;
|
||||
sdmc_current_spec.secptrack = 32;
|
||||
break;
|
||||
}
|
||||
if( mbytes <= 32) {
|
||||
sdmc_current_spec.heads = 4;
|
||||
sdmc_current_spec.secptrack = 32;
|
||||
break;
|
||||
}
|
||||
if( mbytes <= 128) {
|
||||
sdmc_current_spec.heads = 8;
|
||||
sdmc_current_spec.secptrack = 32;
|
||||
break;
|
||||
}
|
||||
if( mbytes <= 256) {
|
||||
sdmc_current_spec.heads = 16;
|
||||
sdmc_current_spec.secptrack = 32;
|
||||
break;
|
||||
}
|
||||
if( mbytes <= 504) {
|
||||
sdmc_current_spec.heads = 16;
|
||||
sdmc_current_spec.secptrack = 63;
|
||||
break;
|
||||
}
|
||||
if( mbytes <= 1008) {
|
||||
sdmc_current_spec.heads = 32;
|
||||
sdmc_current_spec.secptrack = 63;
|
||||
break;
|
||||
}
|
||||
if( mbytes <= 2016) {
|
||||
sdmc_current_spec.heads = 64;
|
||||
sdmc_current_spec.secptrack = 63;
|
||||
break;
|
||||
}
|
||||
if( mbytes <= 2048) {
|
||||
sdmc_current_spec.heads = 128;
|
||||
sdmc_current_spec.secptrack = 63;
|
||||
break;
|
||||
}
|
||||
if( mbytes <= 4032) {
|
||||
sdmc_current_spec.heads = 128;
|
||||
sdmc_current_spec.secptrack = 63;
|
||||
break;
|
||||
}
|
||||
if( mbytes <= 32768) {
|
||||
sdmc_current_spec.heads = 255;
|
||||
sdmc_current_spec.secptrack = 63;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*シリンダ数を計算*/
|
||||
sdmc_current_spec.cylinders = (sdmc_current_spec.memory_capacity /
|
||||
(sdmc_current_spec.heads * sdmc_current_spec.secptrack));
|
||||
|
||||
/*memory_capacityを再計算してadjusted_memory_capacityに格納*/
|
||||
sdmc_current_spec.adjusted_memory_capacity = sdmc_current_spec.cylinders *
|
||||
(sdmc_current_spec.heads * sdmc_current_spec.secptrack);
|
||||
}
|
||||
|
||||
|
||||
/*引数を超える最も小さい整数を算出する*/
|
||||
static u32 sdi_get_ceil( u32 cval, u32 mval)
|
||||
{
|
||||
return( (cval / mval) + (1 * (cval % mval != 0)));
|
||||
}
|
||||
|
||||
|
||||
/*マスターブートセクタのセクタ数を返す*/
|
||||
static void sdi_get_nom( void)
|
||||
{
|
||||
u32 RSC = 1; //FAT12,16では1
|
||||
u32 RDE = 512; //ルートディレクトリエントリ。FIX
|
||||
u32 SS = 512; //セクタサイズ。FIX
|
||||
u32 TS, SC, n;
|
||||
u32 MAX, SFdash;
|
||||
|
||||
TS = sdmc_current_spec.adjusted_memory_capacity;
|
||||
SC = sdmc_current_spec.SC;
|
||||
|
||||
sdmc_current_spec.SF = sdi_get_ceil( TS/SC * sdmc_current_spec.FATBITS, SS*8);
|
||||
|
||||
/*-----------------------SDHCのとき----------------------------*/
|
||||
if( sdmc_current_spec.csd_ver2_flag) {
|
||||
sdmc_current_spec.NOM = sdmc_current_spec.BU;
|
||||
do {
|
||||
n = sdi_get_ceil( 2*sdmc_current_spec.SF, sdmc_current_spec.BU);
|
||||
sdmc_current_spec.RSC = (sdmc_current_spec.BU * n) - ( 2 * sdmc_current_spec.SF);
|
||||
if( sdmc_current_spec.RSC < 9) {
|
||||
sdmc_current_spec.RSC += sdmc_current_spec.BU;
|
||||
}
|
||||
sdmc_current_spec.SSA = sdmc_current_spec.RSC + (2 * sdmc_current_spec.SF);
|
||||
do {
|
||||
MAX = ((TS - sdmc_current_spec.NOM - sdmc_current_spec.SSA) / SC) + 1;
|
||||
SFdash = sdi_get_ceil( (2+(MAX-1)) * sdmc_current_spec.FATBITS, SS*8);
|
||||
if( SFdash > sdmc_current_spec.SF) {
|
||||
sdmc_current_spec.SSA += sdmc_current_spec.BU;
|
||||
sdmc_current_spec.RSC += sdmc_current_spec.BU;
|
||||
}else{
|
||||
break;
|
||||
}
|
||||
}while( 1);
|
||||
if( SFdash != sdmc_current_spec.SF) {
|
||||
sdmc_current_spec.SF -= 1;
|
||||
}else{
|
||||
break;
|
||||
}
|
||||
}while( 1);
|
||||
}else{ /*-------------------------SDのとき-------------------------------*/
|
||||
do {
|
||||
sdmc_current_spec.SSA = RSC + ( 2 * sdmc_current_spec.SF) + sdi_get_ceil( 32*RDE, SS);
|
||||
n = sdi_get_ceil( sdmc_current_spec.SSA, sdmc_current_spec.BU);
|
||||
sdmc_current_spec.NOM = (sdmc_current_spec.BU * n) - sdmc_current_spec.SSA;
|
||||
if( sdmc_current_spec.NOM != sdmc_current_spec.BU) {
|
||||
sdmc_current_spec.NOM += sdmc_current_spec.BU;
|
||||
}
|
||||
do {
|
||||
MAX = ((TS - sdmc_current_spec.NOM - sdmc_current_spec.SSA) / SC) + 1;
|
||||
SFdash = sdi_get_ceil( (2+(MAX-1)) * sdmc_current_spec.FATBITS, SS*8);
|
||||
if( SFdash > sdmc_current_spec.SF) {
|
||||
sdmc_current_spec.NOM += sdmc_current_spec.BU;
|
||||
}else{
|
||||
break;
|
||||
}
|
||||
}while( 1);
|
||||
if( SFdash != sdmc_current_spec.SF) {
|
||||
sdmc_current_spec.SF = SFdash;
|
||||
}else{
|
||||
break; //complete
|
||||
}
|
||||
}while( 1);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/*FATのビット数を返す*/
|
||||
static void sdi_get_fatparams( void)
|
||||
{
|
||||
int mbytes;
|
||||
|
||||
// mbytes = (sdmc_current_spec.card_capacity / (1024 * 1024)) * 512;
|
||||
mbytes = (sdmc_current_spec.card_capacity >> 11);
|
||||
|
||||
if( mbytes <= 64) {
|
||||
sdmc_current_spec.FATBITS = 12;
|
||||
sdmc_current_spec.RDE = 512;
|
||||
sdmc_current_spec.RSC = 1;
|
||||
}else{
|
||||
if( mbytes <= 2048) {
|
||||
sdmc_current_spec.FATBITS = 16;
|
||||
sdmc_current_spec.RDE = 512;
|
||||
sdmc_current_spec.RSC = 1;
|
||||
}else{
|
||||
sdmc_current_spec.FATBITS = 32;
|
||||
sdmc_current_spec.RDE = 0; //FAT32のときは未使用。0にしておかないとRTFSが BAD FORMAT を返す。
|
||||
sdmc_current_spec.RSC = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if( mbytes <= 8) {
|
||||
sdmc_current_spec.SC = 16;
|
||||
sdmc_current_spec.BU = 16;
|
||||
return;
|
||||
}
|
||||
if( mbytes <= 64) {
|
||||
sdmc_current_spec.SC = 32;
|
||||
sdmc_current_spec.BU = 32;
|
||||
return;
|
||||
}
|
||||
if( mbytes <= 256) {
|
||||
sdmc_current_spec.SC = 32;
|
||||
sdmc_current_spec.BU = 64;
|
||||
return;
|
||||
}
|
||||
if( mbytes <= 1024) {
|
||||
sdmc_current_spec.SC = 32;
|
||||
sdmc_current_spec.BU = 128;
|
||||
return;
|
||||
}
|
||||
if( mbytes <= 2048) {
|
||||
sdmc_current_spec.SC = 64;
|
||||
sdmc_current_spec.BU = 128;
|
||||
return;
|
||||
}
|
||||
if( mbytes <= 32768) {
|
||||
sdmc_current_spec.SC = 64;
|
||||
sdmc_current_spec.BU = 8192;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/*MBRセクタ(パーティションセクタ含む)を生成して書き込む*/
|
||||
static void sdi_build_partition_table( void)
|
||||
{
|
||||
u16 MbrSectDat[512/2];
|
||||
u32 starting_head, starting_sect, starting_cyl;
|
||||
u32 ending_head, ending_sect, ending_cyl;
|
||||
u32 total_sect;
|
||||
#if (SD_DEBUG_PRINT_ON == 1)
|
||||
u32 starting_data, ending_data;
|
||||
#endif
|
||||
u32 systemid;
|
||||
SdmcResultInfo SdResult;
|
||||
|
||||
/**/
|
||||
starting_head = sdmc_current_spec.NOM % (sdmc_current_spec.heads *
|
||||
sdmc_current_spec.secptrack);
|
||||
starting_head /= sdmc_current_spec.secptrack;
|
||||
|
||||
/**/
|
||||
starting_sect = (sdmc_current_spec.NOM % sdmc_current_spec.secptrack) + 1;
|
||||
|
||||
/**/
|
||||
starting_cyl = sdmc_current_spec.NOM / (sdmc_current_spec.heads *
|
||||
sdmc_current_spec.secptrack);
|
||||
|
||||
/**/
|
||||
total_sect = (sdmc_current_spec.adjusted_memory_capacity - sdmc_current_spec.NOM);
|
||||
ending_head = (sdmc_current_spec.NOM + total_sect - 1) %
|
||||
(sdmc_current_spec.heads * sdmc_current_spec.secptrack);
|
||||
ending_head /= sdmc_current_spec.secptrack;
|
||||
|
||||
/**/
|
||||
ending_sect = ((sdmc_current_spec.NOM + total_sect - 1) %
|
||||
sdmc_current_spec.secptrack) + 1;
|
||||
|
||||
/**/
|
||||
ending_cyl = (sdmc_current_spec.NOM + total_sect - 1) /
|
||||
(sdmc_current_spec.heads * sdmc_current_spec.secptrack);
|
||||
|
||||
/**/
|
||||
if( sdmc_current_spec.FATBITS == 32) { //FAT32のとき
|
||||
if( total_sect < 0xFB0400) { //8032.5MBが閾値(SD FileSystemSpec2.00参照)
|
||||
systemid = 0x0B; /* FAT32 */
|
||||
}else{
|
||||
systemid = 0x0C; /* FAT32(拡張INT13対応) */
|
||||
}
|
||||
}else{ //FAT12,FAT16のとき
|
||||
if( total_sect < 32680) {
|
||||
systemid = 0x01; /* FAT12 */
|
||||
}else if( total_sect < 65536) {
|
||||
systemid = 0x04; /* FAT16(16MB~32MB未満) */
|
||||
}else{
|
||||
systemid = 0x06; /* FAT16(32MB~4GB) */
|
||||
}
|
||||
}
|
||||
|
||||
/*MBRセクタ(パーティションテーブル含む)作成*/
|
||||
#if (TARGET_OS_CTR == 1)
|
||||
miCpuFill8( MbrSectDat, 0, 512);
|
||||
#else
|
||||
MI_CpuFill8( MbrSectDat, 0, 512);
|
||||
#endif
|
||||
MbrSectDat[446/2] = (starting_head<<8);
|
||||
//上位8bit:starting_cylの下位8bit, 下位8bit:starting_cylの上位2bit + starting_sect 6bit.
|
||||
MbrSectDat[448/2] = (starting_cyl<<8) + ((starting_cyl>>2) & 0xC0) + starting_sect;
|
||||
MbrSectDat[450/2] = (ending_head<<8) + systemid;
|
||||
//上位8bit:ending_cylの下位8bit, 下位8bit:ending_cylの上位2bit + ending_sect 6bit.
|
||||
MbrSectDat[452/2] = (ending_cyl<<8) + ((ending_cyl>>2) & 0xC0) + ending_sect;
|
||||
MbrSectDat[454/2] = sdmc_current_spec.NOM;
|
||||
MbrSectDat[456/2] = (sdmc_current_spec.NOM>>16);
|
||||
MbrSectDat[458/2] = total_sect;
|
||||
MbrSectDat[460/2] = (total_sect>>16);
|
||||
MbrSectDat[510/2] = 0xAA55;
|
||||
/*セクタ0に書き込み*/
|
||||
sdmcWriteFifo( MbrSectDat, 1, 0, NULL, &SdResult);
|
||||
|
||||
/**/
|
||||
PRINTDEBUG( "total sect : 0x%x\n", total_sect);
|
||||
PRINTDEBUG( "starting head : 0x%x\n", starting_head);
|
||||
PRINTDEBUG( "starting sect : 0x%x\n", starting_sect);
|
||||
PRINTDEBUG( "starting cyl : 0x%x\n", starting_cyl);
|
||||
PRINTDEBUG( "ending head : 0x%x\n", ending_head);
|
||||
PRINTDEBUG( "ending sect : 0x%x\n", ending_sect);
|
||||
PRINTDEBUG( "ending cyl : 0x%x\n", ending_cyl);
|
||||
PRINTDEBUG( "\n");
|
||||
#if (SD_DEBUG_PRINT_ON == 1)
|
||||
starting_data = (starting_cyl<<8) + ((starting_cyl>>2) & 0xC0) + starting_sect;
|
||||
PRINTDEBUG( "starting data : 0x%x\n", starting_data);
|
||||
ending_data = (ending_cyl<<8) + ((ending_cyl>>2) & 0xC0) + ending_sect;
|
||||
PRINTDEBUG( "endign data : 0x%x\n", ending_data);
|
||||
#endif
|
||||
}
|
||||
|
||||
//#endif /*(INCLUDE_SD)*/
|
||||
1188
build/libraries/devices/rom_sdmc/ARM7/sdif.c
Normal file
1188
build/libraries/devices/rom_sdmc/ARM7/sdif.c
Normal file
File diff suppressed because it is too large
Load Diff
349
build/libraries/devices/rom_sdmc/ARM7/sdif_ip.h
Normal file
349
build/libraries/devices/rom_sdmc/ARM7/sdif_ip.h
Normal file
@ -0,0 +1,349 @@
|
||||
/*
|
||||
** Copyright (c) 2000-2001 Matsushita Electric Industrial Co., Ltd.
|
||||
** All Rights Reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
** $Module SDカードアクセスモジュール・インクルード
|
||||
** $Filename SD_CARD_IP.H
|
||||
** $Version 1.0 版
|
||||
** $Date 01/02/16
|
||||
** $Log 01/02/16 rev1.0作成
|
||||
** 松下電器産業(株)半導体開発本部
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __SD_CARD_IP_H__
|
||||
#define __SD_CARD_IP_H__
|
||||
|
||||
//#define IO3 0 /* Insert Remove SW = FALSE IO3 = TRUE */
|
||||
|
||||
//#define MAX_SD_CLOCK_4M 0 /* MAX SD Clock 4.608MHz */
|
||||
//#define MAX_SD_CLOCK_9M 1 /* MAX SD Clock 9.216MHz */
|
||||
|
||||
|
||||
/*---------------------------------------------
|
||||
ラッパーレジスタのビット制御(フラグ定義)
|
||||
---------------------------------------------*/
|
||||
/* SD_CNTレジスタ */
|
||||
#define SDIF_CNT_USEDTC (0x0001) /* DTC使用フラグ (R/W) */
|
||||
#define SDIF_CNT_USEFIFO (0x0002) /* FIFO使用フラグ (R/W) */
|
||||
#define SDIF_CNT_FULL (0x0100) /* FIFO FULLフラグ (RO) */
|
||||
#define SDIF_CNT_NEMP (0x0200) /* FIFO NOT EMPTYフラグ (RO) */
|
||||
#define SDIF_CNT_FCLR (0x0400) /* FIFO クリアフラグ (WO) */
|
||||
#define SDIF_CNT_FFIE (0x0800) /* FIFO FULLで割り込み (R/W) */
|
||||
#define SDIF_CNT_FEIE (0x1000) /* FIFO EMPTYで割り込み (R/W) */
|
||||
|
||||
#define SDCARD_UseFifoFlag ((*SDIF_CNT) & SDIF_CNT_USEFIFO)
|
||||
|
||||
/*-------------------------------------
|
||||
レジスタのビット制御(フラグ定義)
|
||||
-------------------------------------*/
|
||||
/* SD_CMDレジスタ*/
|
||||
#define SD_CMD_CMD 0x0000 /* SDカードへの通常アクセス(CMD) */
|
||||
#define SD_CMD_ACMD 0x0040 /* SDカードへのセキュリティアクセス(ACMD) */
|
||||
|
||||
/* SD_STOPレジスタ */
|
||||
#define SD_STOP_STP 0x0001 /* データ転送終了を知らせる */
|
||||
#define SD_STOP_SEC_ENABLE 0x0100 /* SD_SECCNTレジスタ有効(セクタカウントレジスタ) */
|
||||
|
||||
/* SD_SECCNTレジスタ */
|
||||
#define SD_SECCNT_END 0x0000 /* SD_SECCNTレジスタ カウントチェック */
|
||||
|
||||
/* SD_SIZEレジスタ */
|
||||
#define SD_SIZE_DATA_LENGTH_1B 0x0001 /* SDカード転送データサイズ 1Bytes */
|
||||
#define SD_SIZE_DATA_LENGTH_2B 0x0002 /* SDカード転送データサイズ 2Bytes */
|
||||
#define SD_SIZE_DATA_LENGTH_4B 0x0004 /* SDカード転送データサイズ 4Bytes */
|
||||
#define SD_SIZE_DATA_LENGTH_8B 0x0008 /* SDカード転送データサイズ 8Bytes (SCR) */
|
||||
#define SD_SIZE_DATA_LENGTH_16B 0x0010 /* SDカード転送データサイズ 16Bytes */
|
||||
#define SD_SIZE_DATA_LENGTH_32B 0x0020 /* SDカード転送データサイズ 32Bytes */
|
||||
#define SD_SIZE_DATA_LENGTH_64B 0x0040 /* SDカード転送データサイズ 64Bytes (SD_Status) */
|
||||
#define SD_SIZE_DATA_LENGTH_128B 0x0080 /* SDカード転送データサイズ 128Bytes */
|
||||
#define SD_SIZE_DATA_LENGTH_256B 0x0100 /* SDカード転送データサイズ 256Bytes */
|
||||
#define SD_SIZE_DATA_LENGTH_512B 0x0200 /* SDカード転送データサイズ 512Bytes (データ) */
|
||||
|
||||
/* SD_OPTIONレジスタ */
|
||||
#define SD_OPTION_WIDTH_1BIT 0x8000 /* ビット幅の選択 1bit幅 */
|
||||
#define SD_OPTION_MSEL_C2NOUSE 0x4000 /* C2モジュール未使用 */
|
||||
#define SD_CD_DETECT_TIME 0xFFF0 /* CD 検出タイムだけをクリアするためのマスク */
|
||||
|
||||
/* SD_INFO2レジスタ */
|
||||
#define SD_INFO2_ERR_ILA 0x8000 /* イリーガルアクセスエラー */
|
||||
#define SD_INFO2_BWE 0x0200 /* SDカードから512byteのデータ書込み要求 */
|
||||
#define SD_INFO2_BRE 0x0100 /* SDカードから512byteのデータ読込み要求 */
|
||||
#define SD_INFO2_ERR_ALLCLR 0x807F /* SD Card エラーレジスタクリア */
|
||||
#define SD_INFO2_ERR_SDDAT0 0x0080 /* SD Card Busy bit */
|
||||
#define SD_INFO2_ERR_RESTIMEOUT 0x0040 /* レスポンスタイムアウトエラー */
|
||||
#define SD_INFO2_ERR_UNDERFLOW 0x0020 /* FIFO アンダーフローエラー */
|
||||
#define SD_INFO2_ERR_OVERFLOW 0x0010 /* FIFO オーバーフローエラー */
|
||||
#define SD_INFO2_ERR_TIMEOUT 0x0008 /* レスポンス以外のタイムアウトエラー */
|
||||
#define SD_INFO2_ERR_END 0x0004 /* フレーム終了認識できないときの(END)エラー */
|
||||
#define SD_INFO2_ERR_CRC 0x0002 /* CRC エラー */
|
||||
#define SD_INFO2_ERR_CMD 0x0001 /* CMDエラー */
|
||||
|
||||
#define SD_INFO2_RW_SET 0x0300 /* SDカード Read/Write 要求割込み要因チェック */
|
||||
#define SD_INFO2_ERROR_SET 0x807F /* SDカード エラー割込み要因チェック */
|
||||
|
||||
/* SD_INFO2_MASKレジスタ */
|
||||
#define SD_INFO2_MASK_ILA 0x8000 /* イリーガルアクセスエラー割込みマスク */
|
||||
#define SD_INFO2_MASK_BWE 0x0200 /* SDカードからのデータ書込み要求割込み禁止 */
|
||||
#define SD_INFO2_MASK_BRE 0x0100 /* SDカードからのデータ読込み要求割込み禁止 */
|
||||
#define SD_INFO2_MASK_ALLERRMASK 0x807F /* 全エラー割り込み禁止 */
|
||||
#define SD_INFO2_MASK_EXCEPT_OVERFLOW 0x802F /* 全エラー割り込み禁止 FIFO Overflow Errorを除く */
|
||||
#define SD_INFO2_MASK_RESTIMEOUT 0x0040 /* Time out 割込みEnable */
|
||||
#define SD_INFO2_MASK_UNDERFLOW 0x0020 /* FIFO アンダーフロー 割込みEnable */
|
||||
#define SD_INFO2_MASK_OVERFLOW 0x0010 /* FIFO オーバーフロー 割込みEnable */
|
||||
#define SD_INFO2_MASK_TIMEOUT 0x0008 /* Time out 割込みEnable */
|
||||
#define SD_INFO2_MASK_END 0x0004 /* END エラー 割込みEnable */
|
||||
#define SD_INFO2_MASK_CRC 0x0002 /* CRC エラー 割込みEnable */
|
||||
#define SD_INFO2_MASK_CMD 0x0001 /* CMD エラー 割込みEnable */
|
||||
#define SD_INFO2_MASK_ERRSET 0x807F /* SDカード エラー割込み要因チェック */
|
||||
|
||||
/* SD_INFO1レジスタ */
|
||||
#define SD_INFO1_DAT3DETECT 0x0400 /* (IO3検出) card detect(検出=1) : CTRでは使用できない*/
|
||||
#define SD_INFO1_DAT3INSERT 0x0200 /* (IO3検出) card inserted(挿入=1) : CTRでは使用できない */
|
||||
#define SD_INFO1_DAT3REMOVE 0x0100 /* (IO3検出) card removed(抜け=1) : CTRでは使用できない */
|
||||
#define SD_INFO1_DAT3INIT 0x0300 /* (IO3検出) の初期化 */
|
||||
#define SD_INFO1_WRITEPROTECT 0x0080 /* write protect(書き込み禁止=1) */
|
||||
#define SD_INFO1_DETECT 0x0020 /* card detect(検出=1) */
|
||||
|
||||
#define SD_INFO1_INSERT 0x0010 /* card inserted(挿入=1) */
|
||||
#define SD_INFO1_REMOVE 0x0008 /* card removed(抜け=1) */
|
||||
|
||||
#define SD_INFO1_ALL_END 0x0004 /* R/W access all end */
|
||||
#define SD_INFO1_RES_END 0x0001 /* Response end */
|
||||
#define SD_INFO1_INIT 0x0005 /* SD Cardの状態を初期化 */
|
||||
|
||||
#define SD_INFO1_SET 0x031D /* SDカード 挿抜 and RWアクセス終了 and レスポンス終了 要求割込み要因チェック */
|
||||
|
||||
/* SD_INFO1_MASKレジスタ (0:割り込み許可、1:割り込み禁止)*/
|
||||
#define SD_INFO1_MASK_DAT3INSERT 0x0200 /* (IO3検出) card inserted(挿入) 割込み禁止 */
|
||||
#define SD_INFO1_MASK_DAT3REMOVE 0x0100 /* (IO3検出) card removed(抜け) 割込み禁止 */
|
||||
#define SD_INFO1_MASK_INSERT 0x0010 /* card inserted(挿入) 割込み禁止 */
|
||||
#define SD_INFO1_MASK_REMOVE 0x0008 /* card removed(抜け) 割込み禁止 */
|
||||
#define SD_INFO1_MASK_ALL_END 0x0004 /* R/W access all end 割込み禁止 */
|
||||
#define SD_INFO1_MASK_RES_END 0x0001 /* Response end 割込み禁止 */
|
||||
|
||||
/* CC_EXT_MODEレジスタ */
|
||||
#define CC_EXT_MODE_PIO 0x0000 /* PIOモード */
|
||||
#define CC_EXT_MODE_DMA 0x0002 /* DMAモード */
|
||||
|
||||
/* SOFT_RSTレジスタ */
|
||||
#define SOFT_RST_SDIF_RST 0x0001 /* SD I/Fモジュールをリセット */
|
||||
|
||||
/* SD_CLK_CTRLレジスタ */
|
||||
#define SD_CLK_CTRL_SDCLKEN 0x0100 /* SDカードクロック出力イネーブル */
|
||||
#define SD_CLK_CTRL_512 0x0180 /* SDクロックの周波数(分周比512)*/
|
||||
#define SD_CLK_CTRL_256 0x0140 /* SDクロックの周波数(分周比256)*/
|
||||
#define SD_CLK_CTRL_128 0x0120 /* SDクロックの周波数(分周比128)*/
|
||||
#define SD_CLK_CTRL_64 0x0110 /* SDクロックの周波数(分周比 64)*/
|
||||
#define SD_CLK_CTRL_32 0x0108 /* SDクロックの周波数(分周比 32)*/
|
||||
#define SD_CLK_CTRL_16 0x0104 /* SDクロックの周波数(分周比 16)*/
|
||||
#define SD_CLK_CTRL_8 0x0102 /* SDクロックの周波数(分周比 8)*/
|
||||
#define SD_CLK_CTRL_4 0x0101 /* SDクロックの周波数(分周比 4)*/
|
||||
#define SD_CLK_CTRL_2 0x0100 /* SDクロックの周波数(分周比 2)*/
|
||||
|
||||
|
||||
/*-------------------------------------
|
||||
マルチポート対応ビット制御(フラグ定義)
|
||||
-------------------------------------*/
|
||||
#define SDCARD_PORT_NO 0x0300 /* カードポート選択数 */
|
||||
#define SDCARD_PORT_NO_MAX 0x04//0x02 /* カードポート最大選択数 */
|
||||
#define SDCARD_PORT_NO_MIN 0x01 /* カードポート最小選択数 */
|
||||
#define SDCARD_PORT_SELECT_NO 0x0001 /* カードポート番号ビット */
|
||||
#define SDCARD_PORT0 0x0000 /* カードポート番号ビット */
|
||||
#define SDCARD_PORT1 0x0001 /* カードポート番号ビット */
|
||||
|
||||
/* EXT_WPレジスタ(ポート1以降のライトプロテクト) */
|
||||
#define EXT_WP_PORT1 0x0001 /* ポート1write protect(書き込み禁止=1)*/
|
||||
|
||||
/* EXT_CDレジスタ */
|
||||
#define EXT_CD_PORT1_REMOVE 0x0001 /* ポート1 card detect(検出=1) */
|
||||
#define EXT_CD_PORT1_INSERT 0x0002 /* ポート1 card inserted(挿入=1) */
|
||||
#define EXT_CD_PORT1_DETECT 0x0004 /* ポート1 card removed(抜け=1) */
|
||||
|
||||
/* EXT_CD_DAT3レジスタ */
|
||||
//#define EXT_CD_PORT1_DAT3INIT 0x0003 /* ポート1 card の状態 (IO3検出) の初期化 */
|
||||
#define EXT_CD_PORT1_DAT3REMOVE 0x0001 /* ポート1 dat3 card detect(検出=1) */
|
||||
#define EXT_CD_PORT1_DAT3INSERT 0x0002 /* ポート1 dat3 card inserted(挿入=1) */
|
||||
#define EXT_CD_PORT1_DAT3DETECT 0x0004 /* ポート1 dat3 card removed(抜け=1) */
|
||||
|
||||
/* EXT_CD_DAT3_MASKレジスタ */
|
||||
#define EXT_CD_MASK_PORT1INSERT 0x0002 /* port1 card inserted(挿入) 割込み禁止 */
|
||||
#define EXT_CD_MASK_PORT1REMOVE 0x0001 /* port1 card removed(抜け) 割込み禁止 */
|
||||
#define EXT_CD_MASK_PORT1DAT3INSERT 0x0002 /* port1 (IO3検出) card inserted(挿入) 割込み禁止 */
|
||||
#define EXT_CD_MASK_PORT1DAT3REMOVE 0x0001 /* port1 (IO3検出) card removed(抜け) 割込み禁止 */
|
||||
|
||||
/*-------------------------------------
|
||||
カードの選択
|
||||
--------------------------------------*/
|
||||
#define SDCARD_DETECT_VISUAL_BIT 0x0400 /*** upper layer card detected visual bit ***/
|
||||
|
||||
/*-------------------------------------
|
||||
ライトプロテクト
|
||||
-------------------------------------*/
|
||||
#define SDCARD_WP_PERMANENT_BIT 0x0020 /*** permanent write protection ***/
|
||||
#define SDCARD_WP_TEMPORARY_BIT 0x0010 /*** temporary write protection ***/
|
||||
|
||||
/*-------------------------------------
|
||||
SD or MMCカードコマンド
|
||||
-------------------------------------*/
|
||||
#define GO_IDLE_STATE (0) /* resets all cards to idle state */
|
||||
#define SEND_OP_COND (1) /* Asks all cards in idle state to send their operation conditions */
|
||||
#define ALL_SEND_CID (2) /* send CID numbers */
|
||||
#define SEND_RELATIVE_ADDR (3) /* ask the card to publish a new relative address(RCA) */
|
||||
#define SET_BUS_WIDTH (6) /* ビット幅の選択 */
|
||||
#define SELECT_CARD (7) /* Command toggles acard between thr Stand-by and Transfer states */
|
||||
#define SEND_CSD (9) /* addressed card sends its card-specific data(CSD) */
|
||||
#define STOP_TRANSMISSION (12) /* forces the card to stop transmission */
|
||||
#define SD_SEND_STATUS (13) /* addressed card sends its status register */
|
||||
#define SET_BLOCKLEN (16) /* sets the block length */
|
||||
#define READ_MULTIPLE_BLOCK (18) /* マルチブロックリード */
|
||||
#define WRITE_MULTIPLE_BLOCK (25) /* マルチブロックライト */
|
||||
#define APP_CMD (55) /* CMD55 */
|
||||
#define SD_STATUS (13) /* ACMD13 Send the SD_CARD status */
|
||||
#define SEND_NUM_WR_SECTORS (22) /* ACMD22 書きこみ完了セクタ数取得 */
|
||||
#define SD_APP_OP_COND (41) /* ACMD41 */
|
||||
#define SEND_SCR (51) /* SD configuration register (SCR) */
|
||||
|
||||
/* MMCplus, eMMCの定義 */
|
||||
#define EXT_CSD_ACCESS (6)
|
||||
|
||||
/* Extended Commandの定義 */
|
||||
#define EXT_NORMAL (0)
|
||||
#define EXT_SDIO (0x4000)
|
||||
|
||||
#define EXT_COM_R3 (0x0700)
|
||||
|
||||
#define EXT_CMD (0x00C0)
|
||||
|
||||
#define SEND_IF_COND (8) /* Physical Layer 2.0 で追加されたコマンド */
|
||||
#define SEND_IF_COND_EXT (EXT_SDIO | EXT_COM_R3 | EXT_CMD | SEND_IF_COND)
|
||||
|
||||
|
||||
/*-------------------------------------
|
||||
IP レジスタアクセス マクロ関数
|
||||
-------------------------------------*/
|
||||
#define SD_OrFPGA(reg,value) ((reg) |= (value));
|
||||
#define SD_AndFPGA(reg,value) ((reg) &= (value));
|
||||
#define SD_SetFPGA(reg,value) ((reg) = (value));
|
||||
#define SD_GetFPGA(dest,reg) ((dest) = (reg));
|
||||
|
||||
/***********************************************************************
|
||||
構造体定数
|
||||
***********************************************************************/
|
||||
typedef union{
|
||||
u32 dat;
|
||||
struct {
|
||||
u16 low;
|
||||
u16 high;
|
||||
} dt2word;
|
||||
} LELONG;
|
||||
|
||||
/*-------------------------------------
|
||||
その他(ビット制御)
|
||||
-------------------------------------*/
|
||||
#define RSP_R3_OCR31 0x8000 /* Use OCR Busy bit Check */
|
||||
#define RSP_R3_OCR_VDD 0x0030 /* Use OCR VDD bit Check (3.2-3.3v,3.3-3.4v is OK)*/
|
||||
|
||||
/*--- SCR[0]に対する4bitバス幅対応フラグのマスク ---*/
|
||||
//SCRのbit50に相当するが、SCRとSD_STATUSはMSBから送られてくることを考慮してある
|
||||
#define SCR_DAT_BUS_WIDTH_4BIT 0x0400 /* SCR DAT Bus width supported 4bit */
|
||||
|
||||
/*--- 127bitCSD (CSD[0]~CSD[7])関連 ---*/
|
||||
#define CSD_VDD_R_CURR_MIN 0x0038 /* "VDD_R_CURR_MIN" (for CSD[3]) */
|
||||
#define CSD_VDD_R_CURR_MAX 0x0007 /* "VDD_R_CURR_MAX" (for CSD[3]) */
|
||||
#define CSD_VDD_W_CURR_MIN 0xE000 /* "VDD_W_CURR_MIN" (for CSD[2]) */
|
||||
#define CSD_VDD_W_CURR_MAX 0x1C00 /* "VDD_W_CURR_MAX" (for CSD[2]) */
|
||||
|
||||
#define CSD_READ_BL_LEN 0x0F00 /* "READ_BL_LEN" (for CSD[4])*/
|
||||
#define CSD_WRITE_BL_LEN_BIT_25_24 0x0003 /* "WRITE_BL_LEN" (for CSD[1])*/
|
||||
#define CSD_WRITE_BL_LEN_BIT_23_22 0xC000 /* "WRITE_BL_LEN" (for CSD[0]*/
|
||||
#define CSD_READ_BL_PARTIAL 0x0080 /* "READ_BL_PARTIAL" (for CSD[4]) */
|
||||
#define CSD_TRANSFER_RATE 0x0700 /* "Transfer rate unit" of "TRAN_SPEED" (for CSD[5]) */
|
||||
#define CSD_TRAN_SPEED_100K 0x0000 /* 100Kbit/s (for CSD Transfer rate) */
|
||||
#define CSD_TRAN_SPEED_1M 0x0001 /* 1Mbit/s (for CSD Transfer rate) */
|
||||
#define CSD_TRAN_SPEED_10M 0x0002 /* 10Mbit/s (for CSD Transfer rate) */
|
||||
#define CSD_TRAN_SPEED_100M 0x0003 /* 100Mbit/s (for CSD Transfer rate) */
|
||||
#define CSD_TRAN_SPEED_OTHER 0x0004 /* Reserve (for CSD Transfer rate) */
|
||||
|
||||
#define CSD_C_SIZE_MULT 0x0380 /* RSP2 の bit[49:47] */
|
||||
#define CSD_C_SIZE_BIT_73_72 0x0003 /* RSP3 の bit[73:72](C_SIZE) */
|
||||
#define CSD_C_SIZE_BIT_71_62 0xFFC0 /* RSP3 の bit[71:62](C_SIZE) */
|
||||
//SDHC(CSD format version2)の場合
|
||||
#define CSD_C_SIZE_BIT_69_56 0x3FFF /* SD_CSD[3] */
|
||||
#define CSD_C_SIZE_BIT_55_48 0xFF00 /* SD_CSD[2] */
|
||||
|
||||
#define CSD_STRUCT_BIT_127_126 0x00C0 /* SD_CSD[7] */
|
||||
|
||||
//#define VDD_R_CURR_MIN 0x0000 /* CSD max read current@VDD min */
|
||||
//#define VDD_R_CURR_MAX 0x0007 /* CSD max read current@VDD max */
|
||||
//#define VDD_W_CURR_MIN 0x0000 /* CSD max write current@VDD min */
|
||||
//#define VDD_W_CURR_MAX 0x0007 /* CSD max write current@VDD max */
|
||||
|
||||
/*--- R1レスポンスの card status(32bit)に対するマスク ---*/
|
||||
#define RSP_R1_STATUS_ERR 0xF9FF0008 /* R1(レスポンス)のカードステータスのチェック */
|
||||
#define SDCARD_STATUS_OUT_OF_RANGE 0x80000000 /* Card Status OUT_OF_RANGE のチェック */
|
||||
#define RSP_R1_CURRENT_STATE 0x1E00 /* CARD current state */
|
||||
/*-------------------------------------------------------*/
|
||||
|
||||
/* レスポンスのRSP0 & RSP_R1_CURRENT_STATEを1ビット右シフトした値に対するフラグ */
|
||||
#define CURRENT_STATE_DATA 0x0500 /* CARD current state data */
|
||||
#define CURRENT_STATE_RCV 0x0600 /* CARD current state rcv */
|
||||
|
||||
/* カードステータス */
|
||||
#define SD_MEMORY_CARD 0x00FF /* SD_CARD_TYPE SD memory card */
|
||||
|
||||
|
||||
/*-------------------------------------
|
||||
プロトタイプ宣言
|
||||
-------------------------------------*/
|
||||
void SD_Init(void); /* SD Cardインターフェース部をリセット&初期設定 */
|
||||
void SD_EnableInfo(void); /* SD Card 挿抜 割り込みイネーブル・ディスエーブル */
|
||||
u16 SD_Command(u16 ucCommand); /* SDカードコマンド送出 */
|
||||
u16 SD_AppCommand(void); /* SDカード RCA = 1をセット後 CMD55 発行 */
|
||||
u16 SD_AppOpCond(void); /* ACMD41 発行 busyでなくなるまで繰り返し */
|
||||
u16 SD_SendOpCond(void); /* CMD1 発行 busyでなくなるまで繰り返し */
|
||||
u16 SD_SendIfCond(void); /* CMD8 発行 (SDHCのみ反応してくる) */
|
||||
u16 SD_SendRelativeAddr(void); /* CMD3 発行 正常終了時 RCA<-ResのRCA */
|
||||
u16 SD_SelectCard(void); /* CMD7 発行 Command toggles acard between the Stand-by and Transfer states */
|
||||
u16 SD_SetBlockLength(u32 ulBlockLength); /* ブロックレングス(1セクタの転送量)の設定 */
|
||||
u16 SD_SendCID(void); /* card identification data の取得コマンド発行 */
|
||||
u16 SD_SendCSD(void); /* card-specific data の取得コマンド発行 */
|
||||
u16 SD_SendSCR(void); /* SD register の取得コマンド発行 */
|
||||
u16 SD_SDStatus(void); /* SD STATUS の取得コマンド発行 */
|
||||
u16 SD_SendStatus(void); /* SD status register の取得コマンド発行 */
|
||||
u16 SD_MultiReadBlock(u32 ulOffset); /* マルチセクタリードコマンド発行 */
|
||||
u16 SD_ClockDivSet(u16 usTranSpeed); /* カードの動作クロック設定 */
|
||||
|
||||
void SD_EnableClock( void); /* SDカードのクロック有効 */
|
||||
void SD_DisableClock( void); /* SDカードのクロック無効(省電力) */
|
||||
|
||||
u16 SD_SelectBitWidth(s16 b4bit); /* ビット幅の選択 */
|
||||
|
||||
u16 MMCP_WriteBusWidth(s16 b4bit);
|
||||
u16 MMCP_BusTest( BOOL readflag);
|
||||
|
||||
|
||||
s16 SD_FPGA_irq(void); /* カード転送要求時のFPGAの制御 */
|
||||
void SD_StopTransmission(void); /* カード転送終了をFPGAに通知する。 */
|
||||
void SD_TransEndFPGA(void); /* カード転送の終了処理(割り込みマスクを戻す) */
|
||||
u16 SD_CheckStatus(BOOL bRead); /* Normal response command カードステータスのチェック */
|
||||
u16 SD_SwapByte(u16 *data); /* 上位byte、下位byteを入れ替える関数 */
|
||||
|
||||
void SD_EnableSeccnt( u32 ulSDCARD_SectorCount); /* SD_SECCNTレジスタ有効化&値設定 */
|
||||
void SD_DisableSeccnt( void); /* SD_SECCNTレジスタ無効化 */
|
||||
|
||||
void SD_SetErr(u16 Error); /* エラーステータスを設定する */
|
||||
void SD_ClrErr(u16 Error); /* エラーステータスをクリアする */
|
||||
|
||||
BOOL SD_CheckFPGAReg(u16 reg,u16 value); /* IPレジスタにフラグが立っているか判定 */
|
||||
|
||||
void SD_TransReadyFPGA(void); /* 転送処理準備FPGA設定 */
|
||||
u16 SD_TransCommand(u16 ucCommand); /* 命令発行処理 */
|
||||
|
||||
u16 SD_MultiWriteBlock(u32 ulOffset); /* マルチセクタライトコマンド発行 */
|
||||
u16 SD_SendNumWRSectors(void); /* ACMD22 書きこみ完了セクタ数取得コマンド発行 */
|
||||
|
||||
|
||||
#endif /* __SD_CARD_IP_H__ */
|
||||
118
build/libraries/devices/rom_sdmc/ARM7/sdif_reg.h
Normal file
118
build/libraries/devices/rom_sdmc/ARM7/sdif_reg.h
Normal file
@ -0,0 +1,118 @@
|
||||
/*---------------------------------------------------------------------------*
|
||||
Project: CTR - SD driver
|
||||
File: sd_ip_reg.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.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef __SD_IP_REG_H__
|
||||
#define __SD_IP_REG_H__
|
||||
|
||||
/*********************************************
|
||||
SD IPレジスタ
|
||||
|
||||
(R/W) : readable and writable
|
||||
(RO) : read only
|
||||
*********************************************/
|
||||
/*#if (CTR_DEF_ENVIRONMENT_DSEMU == 1)
|
||||
#define SD_IP_BASE (0x08030000) // NTR用ブレッドボード設定
|
||||
#else
|
||||
#define SD_IP_BASE (0x400B0000) // IOP実機設定
|
||||
#endif*/
|
||||
#define SD_IP_BASE (0x04004800) // TWL ARM7設定
|
||||
|
||||
|
||||
#define SD_CMD (*(vu16 *)(SD_IP_BASE + 0x00)) /* CMD発行レジスタ(R/W) */
|
||||
#define SD_PORTSEL (*(vu16 *)(SD_IP_BASE + 0x02)) /* ポート選択レジスタ(R/W) */
|
||||
#define SD_ARG0 (*(vu16 *)(SD_IP_BASE + 0x04)) /* Argument[15:0] (R/W) */
|
||||
#define SD_ARG1 (*(vu16 *)(SD_IP_BASE + 0x06)) /* Argument[31:16] (R/W) */
|
||||
#define SD_STOP (*(vu16 *)(SD_IP_BASE + 0x08)) /* 転送終了後STOP、SD_SECCNT有効 (R/W) */
|
||||
#define SD_SECCNT (*(vu16 *)(SD_IP_BASE + 0x0A)) /* 転送セクタ数制御 (R/W) */
|
||||
#define SD_RSP0 (*(vu16 *)(SD_IP_BASE + 0x0C)) /* Response [23:8] (RO) */
|
||||
#define SD_RSP1 (*(vu16 *)(SD_IP_BASE + 0x0E)) /* Response [39:24] (RO) */
|
||||
#define SD_RSP2 (*(vu16 *)(SD_IP_BASE + 0x10)) /* Response [55:40] (RO) */
|
||||
#define SD_RSP3 (*(vu16 *)(SD_IP_BASE + 0x12)) /* Response [71:56] (RO) */
|
||||
#define SD_RSP4 (*(vu16 *)(SD_IP_BASE + 0x14)) /* Response [87:72] (RO) */
|
||||
#define SD_RSP5 (*(vu16 *)(SD_IP_BASE + 0x16)) /* Response [103:88] (RO) */
|
||||
#define SD_RSP6 (*(vu16 *)(SD_IP_BASE + 0x18)) /* Response [119:104] (RO) */
|
||||
#define SD_RSP7 (*(vu16 *)(SD_IP_BASE + 0x1A)) /* Response [127:120] (RO) */
|
||||
#define SD_INFO1 (*(vu16 *)(SD_IP_BASE + 0x1C)) /* SDメモリーカードの状態 (R/W) */
|
||||
#define SD_INFO2 (*(vu16 *)(SD_IP_BASE + 0x1E)) /* バッファ制御とエラー情報 (R/W) */
|
||||
#define SD_INFO1_MASK (*(vu16 *)(SD_IP_BASE + 0x20)) /* SD_INFO1割込みマスク (R/W) */
|
||||
#define SD_INFO2_MASK (*(vu16 *)(SD_IP_BASE + 0x22)) /* SD_INFO2割込みマスク (R/W) */
|
||||
#define SD_CLK_CTRL (*(vu16 *)(SD_IP_BASE + 0x24)) /* SDクロック設定 (R/W) */
|
||||
#define SD_SIZE (*(vu16 *)(SD_IP_BASE + 0x26)) /* ビット幅と転送データ長の設定 (R/W) */
|
||||
#define SD_OPTION (*(vu16 *)(SD_IP_BASE + 0x28)) /* タイムアウト、width、CD検出タイム (R/W) */
|
||||
#define SD_ERR_STS1 (*(vu16 *)(SD_IP_BASE + 0x2C)) /* CMD, CRC, ENDエラー割込み原因 (RO) */
|
||||
#define SD_ERR_STS2 (*(vu16 *)(SD_IP_BASE + 0x2E)) /* タイムアウトエラー割込み原因 (RO) */
|
||||
#define SD_BUF0 (vu16 *)(SD_IP_BASE + 0x30) /* SDバッファ読込/書込データポート (R/W) */
|
||||
#define CC_EXT_MODE (*(vu16 *)(SD_IP_BASE + 0xD8)) /* DMAモード/PIOモード切り替え */
|
||||
#define SOFT_RST (*(vu16 *)(SD_IP_BASE + 0xE0)) /* ソフトウェアリセット (R/W) */
|
||||
#define VERSION (*(vu16 *)(SD_IP_BASE + 0xE2)) /* Version レジスタ (RO) */
|
||||
#define EXT_WP (*(vu16 *)(SD_IP_BASE + 0xF6)) /* 拡張SD Card ライトプロテクト (RO) */
|
||||
#define EXT_CD (*(vu16 *)(SD_IP_BASE + 0xF8)) /* 拡張SD Card 検出、挿入、抜け フラグ (R/W) */
|
||||
#define EXT_CD_DAT3 (*(vu16 *)(SD_IP_BASE + 0xFA)) /* 拡張SD Card 検出、挿入、抜け フラグ (R/W) */
|
||||
#define EXT_CD_MASK (*(vu16 *)(SD_IP_BASE + 0xFC)) /* 拡張SD Card 検出、挿入、抜け 割込みマスク (R/W) */
|
||||
#define EXT_CD_DAT3_MASK (*(vu16 *)(SD_IP_BASE + 0xFE)) /* 拡張SD Card 検出、挿入、抜け 割込みマスク (R/W) */
|
||||
|
||||
|
||||
|
||||
/*********************************************
|
||||
SD I/F(ラッパー)レジスタ
|
||||
*********************************************/
|
||||
/*#if (CTR_DEF_ENVIRONMENT_DSEMU == 1)
|
||||
#define SD_IF_BASE (0x08030100) // NTR用ブレッドボード設定
|
||||
#else
|
||||
#define SD_IF_BASE (0x400B0100) // IOP実機設定
|
||||
#endif*/
|
||||
#define SD_IF_BASE (0x04004900) // IOP実機設定
|
||||
|
||||
|
||||
#define SDIF_CNT ((vu32 *)(SD_IF_BASE+0x00)) /* コントロール */
|
||||
#define SDIF_FDS ((vu32 *)(SD_IF_BASE+0x04)) /* FIFOサイズ */
|
||||
#define SDIF_FSC ((vu32 *)(SD_IF_BASE+0x08)) /* セクタカウント */
|
||||
#define SDIF_FI ((vu32 *)(SD_IF_BASE+0x0c)) /* FIFOウィンドウ */
|
||||
|
||||
#define SDIF_CNT_L ((vu16 *)(SD_IF_BASE+0x00))
|
||||
#define SDIF_CNT_H ((vu16 *)(SD_IF_BASE+0x02))
|
||||
#define SDIF_FDS_L ((vu16 *)(SD_IF_BASE+0x04))
|
||||
#define SDIF_FDS_H ((vu16 *)(SD_IF_BASE+0x06))
|
||||
#define SDIF_FSC_L ((vu16 *)(SD_IF_BASE+0x08))
|
||||
#define SDIF_FSC_H ((vu16 *)(SD_IF_BASE+0x0a))
|
||||
#define SDIF_FI_L ((vu16 *)(SD_IF_BASE+0x0c))
|
||||
#define SDIF_FI_H ((vu16 *)(SD_IF_BASE+0x0e))
|
||||
|
||||
|
||||
|
||||
/*********************************************
|
||||
INTCレジスタ
|
||||
*********************************************/
|
||||
/*#if (CTR_DEF_ENVIRONMENT_DSEMU == 1)
|
||||
#define CTR_INT_BASE (0x08000000)
|
||||
#else
|
||||
#define CTR_INT_BASE (0x40010000)
|
||||
#endif
|
||||
|
||||
|
||||
#define CTR_INT_SE (CTR_INT_BASE + 0x00) //割り込み要求選択レジスタ
|
||||
#define CTR_INT_IE (CTR_INT_BASE + 0x04) //IE
|
||||
#define CTR_INT_IF (CTR_INT_BASE + 0x08) //IF
|
||||
|
||||
#define CTR_IE_SD_MASK (1<<13) //SD割り込みフラグ
|
||||
*/
|
||||
#define CTR_INT_BASE (0x04000000)
|
||||
|
||||
#define CTR_INT_SE (CTR_INT_BASE + 0x208) //割り込み要求選択レジスタ
|
||||
#define CTR_INT_IE (CTR_INT_BASE + 0x218) //IE
|
||||
#define CTR_INT_IF (CTR_INT_BASE + 0x21C) //IF
|
||||
|
||||
#define CTR_IE_SD_MASK (1<<8) //SD割り込みフラグ
|
||||
|
||||
|
||||
#endif /* __SD_IP_REG_H__ */
|
||||
2529
build/libraries/devices/rom_sdmc/ARM7/sdmc.c
Normal file
2529
build/libraries/devices/rom_sdmc/ARM7/sdmc.c
Normal file
File diff suppressed because it is too large
Load Diff
85
build/libraries/devices/rom_sdmc/ARM7/sdmc_config.h
Normal file
85
build/libraries/devices/rom_sdmc/ARM7/sdmc_config.h
Normal file
@ -0,0 +1,85 @@
|
||||
/*
|
||||
** Copyright (c) 2000-2001 Matsushita Electric Industrial Co., Ltd.
|
||||
** All Rights Reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
** $System IP1.1 without C2 サンプルソフト
|
||||
** $Subsystem カードドライバ
|
||||
** $Filename CARDDRV.H
|
||||
** $Version 1.0 版
|
||||
** $Date 01/02/16
|
||||
** $Log 01/02/16 rev1.0作成
|
||||
** 松下電器産業(株)半導体開発本部
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __SDMC_CONFIG_H__
|
||||
#define __SDMC_CONFIG_H__
|
||||
|
||||
|
||||
#include <twl.h>
|
||||
|
||||
#ifdef USE_OS
|
||||
#include <sd_ip_reg.h> /* IP 対応レジスタ定義 */
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*********************************************
|
||||
ターゲットOS
|
||||
*********************************************/
|
||||
#define TARGET_OS_CTR (0)
|
||||
#define TARGET_OS_NITRO (TARGET_OS_CTR ^ 1)
|
||||
|
||||
|
||||
/*********************************************
|
||||
SDドライバ コンフィグレーション
|
||||
*********************************************/
|
||||
#define SD_DEBUG_PRINT_ON 0 /* デバッグ表示 */
|
||||
|
||||
#define WP_ena 1 /* ライトプロテクトのチェック有効 */
|
||||
#define TIMEOUT 1 /* FPGA Timeout none = FALSE */
|
||||
#define SCR 1 /* Send SCR Command = TRUE */
|
||||
#define RESID 1 /* Write Error Resid enable = TRUE */
|
||||
#define ATC_ON 0 /* ATC転送 使用/未使用 */
|
||||
|
||||
#define SecEnable 1 /* SD_SECCNTレジスタ Enable */
|
||||
#define SecDisenable 0 /* SD_SECCNTレジスタ Disable */
|
||||
//#define STANDBYMODE 0x04 /*** 5772 standby control bit ***/
|
||||
|
||||
|
||||
/*********************************************
|
||||
タイムアウト設定値(ms単位)
|
||||
*********************************************/
|
||||
#define SDCARD_RW_TIMEOUT (4000)
|
||||
#define SDCARD_STDBY_TIMEOUT (50)
|
||||
#define SDCARD_CLOCK_WAIT (500)
|
||||
#define SDCARD_SDCLK_WAIT (10)
|
||||
#define SDCARD_INITIAL_TIMEOUT (800)
|
||||
#define SDCARD_RESET_TIMEOUT (1500)
|
||||
#define SDCARD_ERASE_TIMEOUT (1)
|
||||
#define SDCARD_ERRPROC_TIMEOUT (2000)
|
||||
|
||||
|
||||
/*********************************************
|
||||
リトライ回数(Multiple Block R/W のとき)
|
||||
*********************************************/
|
||||
#define SDCARD_RETRY_COUNT (3)
|
||||
|
||||
/*********************************************
|
||||
その他
|
||||
*********************************************/
|
||||
#define SECTOR_SIZE (512) /* 1セクタのバイト数 */
|
||||
#define SECTOR_MAX (255) /* SYSFPGA アクセス最大セクタ数 */
|
||||
|
||||
/*--- 上位レイヤに返すステータス値(SDCARD_Getstatus参照)用 ---*/
|
||||
#define SDCARD_FLAG_CLR (0x3FFF) /* カード判定部分クリア用 */
|
||||
#define SDCARD_FLAG_SD (0x8000) /* カード判定部分SDカード */
|
||||
#define SDCARD_FLAG_MMC (0x4000) /* カード判定部分MMCカード */
|
||||
#define SDCARD_PORT1_CLR (0x0007) /* カードポート1判定部分クリア用 */
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /*__SDMC_CONFIG_H__*/
|
||||
34
build/libraries/devices/rom_sdmc/Makefile
Normal file
34
build/libraries/devices/rom_sdmc/Makefile
Normal file
@ -0,0 +1,34 @@
|
||||
#! make -f
|
||||
#----------------------------------------------------------------------------
|
||||
# Project: TwlSDK - libraries - spi
|
||||
# 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 = ARM9
|
||||
|
||||
ifdef TWL_WITH_ARM7
|
||||
SUBDIRS += ARM7
|
||||
endif
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
include $(TWLSDK_ROOT)/build/buildtools/modulerules
|
||||
|
||||
|
||||
#===== End of Makefile =====
|
||||
@ -20,11 +20,12 @@
|
||||
(R/W) : readable and writable
|
||||
(RO) : read only
|
||||
*********************************************/
|
||||
#if (CTR_DEF_ENVIRONMENT_DSEMU == 1)
|
||||
/*#if (CTR_DEF_ENVIRONMENT_DSEMU == 1)
|
||||
#define SD_IP_BASE (0x08030000) // NTR用ブレッドボード設定
|
||||
#else
|
||||
#define SD_IP_BASE (0x400B0000) // IOP実機設定
|
||||
#endif
|
||||
#endif*/
|
||||
#define SD_IP_BASE (0x04004800) // TWL ARM7設定
|
||||
|
||||
|
||||
#define SD_CMD (*(vu16 *)(SD_IP_BASE + 0x00)) /* CMD発行レジスタ(R/W) */
|
||||
@ -65,11 +66,12 @@
|
||||
/*********************************************
|
||||
SD I/F(ラッパー)レジスタ
|
||||
*********************************************/
|
||||
#if (CTR_DEF_ENVIRONMENT_DSEMU == 1)
|
||||
/*#if (CTR_DEF_ENVIRONMENT_DSEMU == 1)
|
||||
#define SD_IF_BASE (0x08030100) // NTR用ブレッドボード設定
|
||||
#else
|
||||
#define SD_IF_BASE (0x400B0100) // IOP実機設定
|
||||
#endif
|
||||
#endif*/
|
||||
#define SD_IF_BASE (0x04004900) // IOP実機設定
|
||||
|
||||
|
||||
#define SDIF_CNT ((vu32 *)(SD_IF_BASE+0x00)) /* コントロール */
|
||||
@ -91,7 +93,7 @@
|
||||
/*********************************************
|
||||
INTCレジスタ
|
||||
*********************************************/
|
||||
#if (CTR_DEF_ENVIRONMENT_DSEMU == 1)
|
||||
/*#if (CTR_DEF_ENVIRONMENT_DSEMU == 1)
|
||||
#define CTR_INT_BASE (0x08000000)
|
||||
#else
|
||||
#define CTR_INT_BASE (0x40010000)
|
||||
@ -103,7 +105,14 @@
|
||||
#define CTR_INT_IF (CTR_INT_BASE + 0x08) //IF
|
||||
|
||||
#define CTR_IE_SD_MASK (1<<13) //SD割り込みフラグ
|
||||
*/
|
||||
#define CTR_INT_BASE (0x04000000)
|
||||
|
||||
#define CTR_INT_SE (CTR_INT_BASE + 0x208) //割り込み要求選択レジスタ
|
||||
#define CTR_INT_IE (CTR_INT_BASE + 0x218) //IE
|
||||
#define CTR_INT_IF (CTR_INT_BASE + 0x21C) //IF
|
||||
|
||||
#define CTR_IE_SD_MASK (1<<8) //SD割り込みフラグ
|
||||
|
||||
|
||||
#endif /* __SD_IP_REG_H__ */
|
||||
|
||||
@ -12,7 +12,7 @@
|
||||
#include "sdmc.h"
|
||||
#include "sdif_ip.h" /* IP 対応フラグ定義 */
|
||||
|
||||
#if (SD_DEBUG_PRINT_ON == 1)
|
||||
/*#if (SD_DEBUG_PRINT_ON == 1)
|
||||
#if (CTR_DEF_ENVIRONMENT_DSEMU == 1)
|
||||
#define PRINTDEBUG osTPrintf
|
||||
#else
|
||||
@ -21,13 +21,14 @@
|
||||
#endif
|
||||
#else
|
||||
#define PRINTDEBUG( ...) ((void)0)
|
||||
#endif
|
||||
#endif*/
|
||||
#define PRINTDEBUG OS_TPrintf
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
定数
|
||||
***********************************************************************/
|
||||
#define SD_STACK_SIZE (4096)
|
||||
#define SD_STACK_SIZE (4096*2)
|
||||
#define SD_THREAD_PRIO (10)
|
||||
#define SD_INTR_THREAD_PRIO (SD_THREAD_PRIO - 1)
|
||||
|
||||
@ -64,6 +65,7 @@ OSMessageQueue sdmc_result_dtq;
|
||||
OSMessage sdmc_result_dtq_array[1];
|
||||
OSAlarm sdmc_alm;
|
||||
OSThread sdmc_intr_tsk;
|
||||
OSThreadQueue sdmc_tsk_q;
|
||||
#endif
|
||||
|
||||
#if (TARGET_OS_CTR == 1)
|
||||
@ -106,9 +108,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); /* 書きこみ完了セクタ数の取得 */
|
||||
@ -341,6 +343,8 @@ static void i_sdmcEnable( void)
|
||||
// osEnableInterrupts();
|
||||
// *(vu16*)0x04000208 = 1;
|
||||
#else
|
||||
/*SD割り込みのIF解除*/
|
||||
*(vu16*)CTR_INT_IF = CTR_IE_SD_MASK;
|
||||
OS_SetIrqFunction( OS_IE_SD, SDCARD_irq_Handler);
|
||||
OS_EnableIrqMask( OS_IE_SD);
|
||||
#endif
|
||||
@ -376,7 +380,9 @@ void SDCARD_irq_Handler( void)
|
||||
#if (TARGET_OS_CTR == 1)
|
||||
iwup_tsk( sdmc_intr_tsk_id);
|
||||
#else
|
||||
OS_WakeupThreadDirect( &sdmc_intr_tsk);
|
||||
PRINTDEBUG( "SD irq!\n");
|
||||
OS_SetIrqCheckFlag( OS_IE_SD);
|
||||
//TODO! OS_WakeupThreadDirect( &sdmc_intr_tsk);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -493,29 +499,35 @@ SDMC_ERR_CODE sdmcInit(void (*func1)(),void (*func2)())
|
||||
}
|
||||
|
||||
#else //(TARGET_OS_NITRO = 1)
|
||||
/*---------- OS準備 ----------*/
|
||||
if( !OS_IsAlarmAvailable()) { /* アラームチェック(OS_InitAlarm済みか?) */
|
||||
SDCARD_ErrStatus |= SDMC_ERR_END;
|
||||
}else{
|
||||
OS_CreateAlarm( &sdmc_alm); //使用可能であれば初期化
|
||||
}
|
||||
/*---------- OS準備 ----------*/
|
||||
if( !OS_IsAlarmAvailable()) { /* アラームチェック(OS_InitAlarm済みか?) */
|
||||
SDCARD_ErrStatus |= SDMC_ERR_END;
|
||||
}else{
|
||||
OS_CreateAlarm( &sdmc_alm); //使用可能であれば初期化
|
||||
}
|
||||
|
||||
/* メッセージ初期化 */
|
||||
OS_InitMessageQueue( &sdmc_dtq, &sdmc_dtq_array[0], 1);
|
||||
OS_InitMessageQueue( &sdmc_result_dtq, &sdmc_result_dtq_array[0], 1);
|
||||
/* メッセージ初期化 */
|
||||
OS_InitMessageQueue( &sdmc_dtq, &sdmc_dtq_array[0], 1);
|
||||
OS_InitMessageQueue( &sdmc_result_dtq, &sdmc_result_dtq_array[0], 1);
|
||||
|
||||
OS_InitThread(); //自分の優先度が16になる
|
||||
// OS_InitThread(); //自分の優先度が16になる
|
||||
|
||||
/* SDスレッドの立ち上げ */
|
||||
OS_CreateThread( &sdmc_tsk, SDCARD_Thread, NULL,
|
||||
(sd_stack+SD_STACK_SIZE / sizeof(u64)), SD_STACK_SIZE, SD_THREAD_PRIO);
|
||||
OS_WakeupThreadDirect( &sdmc_tsk);
|
||||
/* SDスレッドの立ち上げ */
|
||||
OS_CreateThread( &sdmc_tsk, SDCARD_Thread, NULL,
|
||||
(sd_stack+SD_STACK_SIZE / sizeof(u64)), SD_STACK_SIZE, SD_THREAD_PRIO);
|
||||
OS_WakeupThreadDirect( &sdmc_tsk);
|
||||
PRINTDEBUG( "sdmc_tsk:0x%x\n", &sdmc_tsk);
|
||||
|
||||
|
||||
/* SD割り込み処理スレッドの立ち上げ */
|
||||
OS_CreateThread( &sdmc_intr_tsk, SDCARD_Intr_Thread, NULL,
|
||||
(sd_intr_stack+SD_STACK_SIZE / sizeof(u64)), SD_STACK_SIZE, SD_INTR_THREAD_PRIO);
|
||||
OS_WakeupThreadDirect( &sdmc_intr_tsk);
|
||||
/*----------------------------*/
|
||||
/* SD割り込み処理スレッドの立ち上げ */
|
||||
OS_CreateThread( &sdmc_intr_tsk, SDCARD_Intr_Thread, NULL,
|
||||
(sd_intr_stack+SD_STACK_SIZE / sizeof(u64)), SD_STACK_SIZE, SD_INTR_THREAD_PRIO);
|
||||
OS_WakeupThreadDirect( &sdmc_intr_tsk);
|
||||
PRINTDEBUG( "sdmc_intr_tsk:0x%x\n", &sdmc_intr_tsk);
|
||||
|
||||
/* スレッドキューの初期化 */
|
||||
OS_InitThreadQueue( &sdmc_tsk_q);
|
||||
/*----------------------------*/
|
||||
#endif
|
||||
/**/
|
||||
sdmc_tsk_created = TRUE;
|
||||
@ -582,7 +594,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();
|
||||
|
||||
@ -665,7 +677,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;
|
||||
@ -692,7 +704,8 @@ static SDMC_ERR_CODE SDCARD_Layer_Init(void)
|
||||
#if (TARGET_OS_CTR == 1)
|
||||
dly_tsk( 1);
|
||||
#else
|
||||
OS_Sleep( 1);
|
||||
// OS_Sleep( 1);
|
||||
SVC_WaitByLoop( 17900); //179*4サイクル=716サイクル=10024ns=10us
|
||||
#endif
|
||||
|
||||
SDCARD_ErrStatus = SDMC_NORMAL; /* エラーステータスをクリア */
|
||||
@ -746,17 +759,17 @@ static SDMC_ERR_CODE SDCARD_Layer_Init(void)
|
||||
SDCARD_TimerStart(SDCARD_RESET_TIMEOUT); /* タイムアウト判定用タイマスタート */
|
||||
#endif
|
||||
|
||||
PRINTDEBUG( " CMD0 (GO_IDLE_STATE)\n");
|
||||
PRINTDEBUG( " CMD0(GO_IDLE_STATE)\n");
|
||||
SD_ClrErr((u16)(~SDMC_ERR_FPGA_TIMEOUT)); /* タイムアウト以外のエラーをクリア */
|
||||
{
|
||||
PRINTDEBUG( "SD_INFO1 : 0x%x\n", SD_INFO1);
|
||||
/*PRINTDEBUG( "SD_INFO1 : 0x%x\n", SD_INFO1);
|
||||
PRINTDEBUG( "SD_INFO2 : 0x%x\n", SD_INFO2);
|
||||
PRINTDEBUG( "SD_INFO1_MASK : 0x%x\n", SD_INFO1_MASK);
|
||||
PRINTDEBUG( "SD_INFO2_MASK : 0x%x\n", SD_INFO2_MASK);
|
||||
PRINTDEBUG( "SD_CLK_CTRL : 0x%x\n", SD_CLK_CTRL);
|
||||
PRINTDEBUG( "SD_SIZE : 0x%x\n", SD_SIZE);
|
||||
|
||||
PRINTDEBUG( "SD_INFO1_MASK : 0x%x\n", (*(vu32 *)(SD_IP_BASE + 0x20)));
|
||||
PRINTDEBUG( "SD_INFO1_MASK : 0x%x\n", (*(vu32 *)(SD_IP_BASE + 0x20)));*/
|
||||
}
|
||||
SD_Command(SD_CMD_CMD | GO_IDLE_STATE); /* CMD0発行、レスポンス確認 */
|
||||
if(SDCARD_ErrStatus){ /* エラーステータスの確認(エラー有り?) */
|
||||
@ -767,7 +780,8 @@ PRINTDEBUG( "SD_INFO1_MASK : 0x%x\n", (*(vu32 *)(SD_IP_BASE + 0x20)));
|
||||
#if (TARGET_OS_CTR == 1)
|
||||
dly_tsk( 1); /* 1ms待ち */
|
||||
#else
|
||||
OS_Sleep( 1);
|
||||
// OS_Sleep( 1);
|
||||
SVC_WaitByLoop( 17900); //179*4サイクル=716サイクル=10024ns=10us
|
||||
#endif
|
||||
SD_SendIfCond(); /* CMD8発行、レスポンス確認 */
|
||||
if( !SDCARD_SDHCFlag) { /* SDHC以外は失敗してるはずなので */
|
||||
@ -818,6 +832,7 @@ PRINTDEBUG( "SD_INFO1_MASK : 0x%x\n", (*(vu32 *)(SD_IP_BASE + 0x20)));
|
||||
#if TIMEOUT
|
||||
SDCARD_TimerStart(SDCARD_INITIAL_TIMEOUT); /* タイムアウト判定用タイマスタート */
|
||||
#endif
|
||||
PRINTDEBUG( "%d\n", __LINE__);
|
||||
|
||||
SD_SendCID(); /* CMD2発行 レスポンス確認 */
|
||||
if(SDCARD_ErrStatus){ /* エラーステータスの確認(エラー有り?) */
|
||||
@ -835,7 +850,7 @@ PRINTDEBUG( "SD_INFO1_MASK : 0x%x\n", (*(vu32 *)(SD_IP_BASE + 0x20)));
|
||||
}
|
||||
|
||||
/*------- standby state -------*/
|
||||
|
||||
PRINTDEBUG( "%d\n", __LINE__);
|
||||
SD_SendCSD(); /* CMD9発行 レスポンス確認 */
|
||||
if(SDCARD_ErrStatus){ /* エラーステータスの確認(エラー有り?) */
|
||||
return SDCARD_ErrStatus;
|
||||
@ -865,6 +880,7 @@ PRINTDEBUG( "SD_INFO1_MASK : 0x%x\n", (*(vu32 *)(SD_IP_BASE + 0x20)));
|
||||
|
||||
#if SCR
|
||||
SD_SelectBitWidth(FALSE); /* CMD55->ACMD6 ビット幅の選択 1bit */
|
||||
PRINTDEBUG( "%d\n", __LINE__);
|
||||
|
||||
/* ACMD51 発行 SD configuration register (SCR) */
|
||||
if(SDCARD_SDFlag){ /* SDカードフラグ ON かチェック */
|
||||
@ -962,7 +978,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))) ||
|
||||
@ -1257,12 +1273,13 @@ static SDMC_ERR_CODE SDCARDi_Read(void* buf,u32 bufsize,u32 offset,void(*func)(v
|
||||
/*--------------------------*/
|
||||
|
||||
/**/
|
||||
PRINTDEBUG( "----- Sleep Thread -----\n");
|
||||
//can_wup( 0);
|
||||
PRINTDEBUG( "--Slp Tsk--\n");
|
||||
#if (TARGET_OS_CTR == 1)
|
||||
//can_wup( 0);
|
||||
slp_tsk();
|
||||
#else
|
||||
OS_SleepThread( NULL);
|
||||
// OS_SleepThread( NULL);
|
||||
OS_SleepThread( &sdmc_tsk_q);
|
||||
#endif
|
||||
PRINTDEBUG( "waked\n");
|
||||
|
||||
@ -1556,7 +1573,7 @@ static void SDCARD_TimerStart(u32 tim)
|
||||
#else
|
||||
OSTick tim_tick;
|
||||
|
||||
tim_tick = OS_MicroSecondsToTicks( tim); //us単位からTick単位へ
|
||||
tim_tick = OS_MilliSecondsToTicks( tim); //us単位からTick単位へ
|
||||
|
||||
OS_CancelAlarm( &sdmc_alm); //アラーム破棄
|
||||
OS_SetAlarm( &sdmc_alm, tim_tick, SDCARD_Timer_irq, NULL); //アラームセット
|
||||
@ -1602,7 +1619,7 @@ static void SDCARD_Timer_irq(void* arg)
|
||||
#if (SD_DEBUG_PRINT_ON == 1)
|
||||
u16 tmp;
|
||||
|
||||
PRINTDEBUG( ">>>>> Timer interrupt (Timeout)\n");
|
||||
PRINTDEBUG( ">>>Timer intr(Timeout)\n");
|
||||
|
||||
SDCARD_ErrStatus |= SDMC_ERR_FPGA_TIMEOUT; /* タイムアウトエラービットの設定 */
|
||||
|
||||
@ -1644,12 +1661,13 @@ static void SDCARD_Timer_irq(void* arg)
|
||||
}
|
||||
|
||||
/**/
|
||||
PRINTDEBUG( "----- Wakeup Thread -----\n");
|
||||
PRINTDEBUG( "--Wup sdTsk(Time)--\n");
|
||||
#if (TARGET_OS_CTR == 1)
|
||||
iwup_tsk( sdmc_tsk_id);
|
||||
PRINTDEBUG( "id : 0x%x\n", sdmc_tsk_id);
|
||||
#else
|
||||
OS_WakeupThreadDirect( &sdmc_tsk);
|
||||
// OS_WakeupThreadDirect( &sdmc_tsk);
|
||||
OS_WakeupThread( &sdmc_tsk_q);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -1707,12 +1725,13 @@ static u16 i_sdmcSendSCR(void)
|
||||
#if SCR
|
||||
thread_flag = TRUE;
|
||||
SD_SendSCR(); /* SCRの取得コマンド発行 */
|
||||
PRINTDEBUG( "----- Sleep Thread -----\n");
|
||||
//can_wup( 0);
|
||||
PRINTDEBUG( "--Slp Tsk--\n");
|
||||
#if (TARGET_OS_CTR == 1)
|
||||
//can_wup( 0);
|
||||
slp_tsk();
|
||||
#else
|
||||
OS_SleepThread( NULL);
|
||||
// OS_SleepThread( NULL);
|
||||
OS_SleepThread( &sdmc_tsk_q);
|
||||
#endif
|
||||
PRINTDEBUG( "waked\n");
|
||||
thread_flag = FALSE;
|
||||
@ -1863,12 +1882,13 @@ static u16 SDCARD_SD_Status(void)
|
||||
|
||||
thread_flag = TRUE;
|
||||
SD_SDStatus(); /* ACMD13 SD_STATUSの取得コマンド発行処理 */
|
||||
PRINTDEBUG( "----- Sleep Thread -----\n");
|
||||
PRINTDEBUG( "--Slp Tsk--\n");
|
||||
#if (TARGET_OS_CTR == 1)
|
||||
//can_wup( 0);
|
||||
slp_tsk();
|
||||
#else
|
||||
OS_SleepThread( NULL);
|
||||
// OS_SleepThread( NULL);
|
||||
OS_SleepThread( &sdmc_tsk_q);
|
||||
#endif
|
||||
PRINTDEBUG( "waked\n");
|
||||
thread_flag = FALSE;
|
||||
@ -2332,12 +2352,13 @@ static u16 i_sdmcGetResid(u32 *pResid)
|
||||
/*--- ACMD22 ライト済みセクタ数取得コマンド発行 ---*/
|
||||
SD_SendNumWRSectors();
|
||||
/*-------------------------------------------------*/
|
||||
PRINTDEBUG( "----- Sleep Thread -----\n");
|
||||
PRINTDEBUG( "--Slp Tsk--\n");
|
||||
#if (TARGET_OS_CTR == 1)
|
||||
// can_wup( 0);
|
||||
slp_tsk();
|
||||
#else
|
||||
OS_SleepThread( NULL);
|
||||
// OS_SleepThread( NULL);
|
||||
OS_SleepThread( &sdmc_tsk_q);
|
||||
#endif
|
||||
PRINTDEBUG( "waked\n");
|
||||
thread_flag = FALSE;
|
||||
@ -2544,6 +2565,7 @@ static void SDCARD_Thread( void* arg)
|
||||
|
||||
while( TRUE) {
|
||||
/* メッセージ待ち */
|
||||
PRINTDEBUG( "rcv mes sdThread\n");
|
||||
#if (TARGET_OS_CTR == 1)
|
||||
rcv_dtq( sdmc_dtq_id, (VP_INT*)¤t_dat);
|
||||
#else
|
||||
@ -2609,18 +2631,25 @@ static void SDCARD_Thread( void* arg)
|
||||
*---------------------------------------------------------------------------*/
|
||||
static void SDCARD_Intr_Thread( void* arg)
|
||||
{
|
||||
u16 sd_info1;//, sd_info2;
|
||||
u16 sd_info1;//, sd_info2;
|
||||
OSIntrMode enabled;
|
||||
|
||||
while( 1) {
|
||||
PRINTDEBUG( "next_tsk:0x%x\n", OS_SelectThread());
|
||||
PRINTDEBUG( "Slp sdIntr\n");
|
||||
#if (TARGET_OS_CTR == 1)
|
||||
slp_tsk();
|
||||
#else
|
||||
OS_SleepThread( NULL);
|
||||
OS_WaitIrq( FALSE, OS_IE_SD);
|
||||
enabled = OS_DisableInterrupts();
|
||||
(void)OS_ClearIrqCheckFlag( OS_IE_SD);
|
||||
(void)OS_RestoreInterrupts( enabled);
|
||||
//TODO! OS_SleepThread( NULL);
|
||||
#endif
|
||||
|
||||
PRINTDEBUG( "sdmc interrupt handler : \n");
|
||||
PRINTDEBUG( "sdIntr waked\n");
|
||||
/*SD割り込みのIF解除*/
|
||||
*(vu32*)CTR_INT_IF = CTR_IE_SD_MASK;
|
||||
*(vu16*)CTR_INT_IF = CTR_IE_SD_MASK;
|
||||
|
||||
/*--- FIFOを使うとき ---*/
|
||||
if( SDCARD_UseFifoFlag) {
|
||||
@ -2628,7 +2657,7 @@ static void SDCARD_Intr_Thread( void* arg)
|
||||
if( ((*SDIF_CNT & SDIF_CNT_FULL)&&(*SDIF_CNT & SDIF_CNT_FFIE)) ||
|
||||
((!(*SDIF_CNT & SDIF_CNT_NEMP))&&(*SDIF_CNT & SDIF_CNT_FEIE))) {
|
||||
|
||||
PRINTDEBUG( ">>>>> SD Interrupt (FIFO Full or Empty)\n");
|
||||
PRINTDEBUG( ">>>SD Intr(FIFO)\n");// Full or Empty)\n");
|
||||
#if (TARGET_OS_CTR == 1)
|
||||
osDisableInterruptID( OS_INTR_ID_SD);
|
||||
#else
|
||||
@ -2654,18 +2683,19 @@ static void SDCARD_Intr_Thread( void* arg)
|
||||
OS_EnableIrqMask( OS_IE_SD);
|
||||
#endif
|
||||
if( thread_flag) {
|
||||
PRINTDEBUG( "----- Wakeup Thread! -----\n");
|
||||
PRINTDEBUG( "--Wup sdThread!--\n");
|
||||
#if (TARGET_OS_CTR == 1)
|
||||
wup_tsk( sdmc_tsk_id);
|
||||
PRINTDEBUG( "id : 0x%x\n", sdmc_tsk_id);
|
||||
#else
|
||||
OS_WakeupThreadDirect( &sdmc_tsk);
|
||||
// OS_WakeupThreadDirect( &sdmc_tsk);
|
||||
OS_WakeupThread( &sdmc_tsk_q);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}else{
|
||||
if( SD_CheckFPGAReg( SD_INFO2, (SD_INFO2_MASK_BRE | SD_INFO2_MASK_BWE))) {
|
||||
PRINTDEBUG( ">>>>> SD Interrupt (R/W Request from CARD)\n");
|
||||
PRINTDEBUG( ">>>SD Intr(R/W Req)\n");
|
||||
//ここで自動的にラッパーのFIFO<->SD_BUF0間で通信が行われる
|
||||
// if((!(*SDIF_CNT & SDIF_CNT_NEMP))&&(*SDIF_CNT & SDIF_CNT_FEIE)) {
|
||||
#if (TARGET_OS_CTR == 1)
|
||||
@ -2673,14 +2703,16 @@ static void SDCARD_Intr_Thread( void* arg)
|
||||
#else
|
||||
OS_DisableIrqMask( OS_IE_SD);
|
||||
#endif
|
||||
PRINTDEBUG( "begin\n");
|
||||
SDCARD_FPGA_irq();
|
||||
PRINTDEBUG( "end\n");
|
||||
#if (TARGET_OS_CTR == 1)
|
||||
osEnableInterruptID( OS_INTR_ID_SD);
|
||||
#else
|
||||
OS_EnableIrqMask( OS_IE_SD);
|
||||
#endif
|
||||
}else{
|
||||
PRINTDEBUG( ">>>>> SD Interrupt (End or Err)\n");
|
||||
PRINTDEBUG( ">>>SD Intr(End or Err)\n");
|
||||
#if (TARGET_OS_CTR == 1)
|
||||
osDisableInterruptID( OS_INTR_ID_SD);
|
||||
#else
|
||||
@ -2694,12 +2726,13 @@ static void SDCARD_Intr_Thread( void* arg)
|
||||
#endif
|
||||
/**/
|
||||
if( thread_flag) {
|
||||
PRINTDEBUG( "----- Wakeup Thread -----\n");
|
||||
PRINTDEBUG( "--Wup sdThread!--\n");
|
||||
#if (TARGET_OS_CTR == 1)
|
||||
wup_tsk( sdmc_tsk_id);
|
||||
PRINTDEBUG( "id : 0x%x\n", sdmc_tsk_id);
|
||||
#else
|
||||
OS_WakeupThreadDirect( &sdmc_tsk);
|
||||
// OS_WakeupThreadDirect( &sdmc_tsk);
|
||||
OS_WakeupThread( &sdmc_tsk_q);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@ -2707,20 +2740,22 @@ static void SDCARD_Intr_Thread( void* arg)
|
||||
/*--- FIFOを使わないとき ---*/
|
||||
}else{
|
||||
if( SD_CheckFPGAReg( SD_INFO2, (SD_INFO2_MASK_BRE | SD_INFO2_MASK_BWE))) {
|
||||
PRINTDEBUG( ">>>>> SD Interrupt (R/W Request from CARD)\n");
|
||||
PRINTDEBUG( ">>>SD Intr(R/W Req)\n");
|
||||
#if (TARGET_OS_CTR == 1)
|
||||
osDisableInterruptID( OS_INTR_ID_SD);
|
||||
#else
|
||||
OS_DisableIrqMask( OS_IE_SD);
|
||||
#endif
|
||||
PRINTDEBUG( "begin\n");
|
||||
SDCARD_FPGA_irq(); /*カードからのリードライト要求割り込み*/
|
||||
PRINTDEBUG( "end\n");
|
||||
#if (TARGET_OS_CTR == 1)
|
||||
osEnableInterruptID( OS_INTR_ID_SD);
|
||||
#else
|
||||
OS_EnableIrqMask( OS_IE_SD);
|
||||
#endif
|
||||
}else{
|
||||
PRINTDEBUG( ">>>>> SD Interrupt (End or Err)\n");
|
||||
PRINTDEBUG( ">>>SD Intr(End or Err)\n");
|
||||
#if (TARGET_OS_CTR == 1)
|
||||
osDisableInterruptID( OS_INTR_ID_SD);
|
||||
#else
|
||||
@ -2734,12 +2769,13 @@ static void SDCARD_Intr_Thread( void* arg)
|
||||
#endif
|
||||
/**/
|
||||
if( thread_flag) {
|
||||
PRINTDEBUG( "----- Wakeup Thread -----\n");
|
||||
PRINTDEBUG( "--Wup sdThread!--\n");
|
||||
#if (TARGET_OS_CTR == 1)
|
||||
wup_tsk( sdmc_tsk_id);
|
||||
PRINTDEBUG( "id : 0x%x\n", sdmc_tsk_id);
|
||||
#else
|
||||
OS_WakeupThreadDirect( &sdmc_tsk);
|
||||
// OS_WakeupThreadDirect( &sdmc_tsk);
|
||||
OS_WakeupThread( &sdmc_tsk_q);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@ -30,7 +30,6 @@ SRCDIR = ../common/src src
|
||||
|
||||
INCDIR = ../common
|
||||
INCDIR += . \
|
||||
$(TWLSDK_ROOT)/include/twl/ARM7 \
|
||||
$(TWLSDK_ROOT)/include/twl/fatfs/ARM7 \
|
||||
|
||||
SRCS = apistat.c prfsapi.c rtlowl.c apickdsk.c apiwrite.c \
|
||||
|
||||
31
build/tests/fatfs/Makefile
Normal file
31
build/tests/fatfs/Makefile
Normal file
@ -0,0 +1,31 @@
|
||||
#! make -f
|
||||
#----------------------------------------------------------------------------
|
||||
# Project: TwlSDK - tests - camera
|
||||
# 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 = fatfs_sd
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
include $(TWLSDK_ROOT)/build/buildtools/modulerules
|
||||
|
||||
|
||||
#===== End of Makefile =====
|
||||
53
build/tests/fatfs/fatfs_sd/ARM7/Makefile
Normal file
53
build/tests/fatfs/fatfs_sd/ARM7/Makefile
Normal file
@ -0,0 +1,53 @@
|
||||
#! make -f
|
||||
#----------------------------------------------------------------------------
|
||||
# Project: TwlSDK - CAMERA - demos - camera-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 =
|
||||
|
||||
LCFILE_SPEC = main.lsf
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
#TWL_CODEGEN = THUMB
|
||||
TWL_PROC = ARM7
|
||||
|
||||
TARGET_BIN = main.axf
|
||||
|
||||
SRCS = main.c
|
||||
|
||||
INCDIR += $(TWLSDK_ROOT)/include/twl \
|
||||
$(TWLSDK_ROOT)/include/twl/devices/sdmc/ARM7 \
|
||||
$(TWLSDK_ROOT)/include/twl/fatfs/ARM7 \
|
||||
|
||||
LLIBRARY_DIRS = $(TWLSDK_ROOT)/lib/ARM-BB/Release
|
||||
LLIBRARIES = libfatfs_sp.twl.a \
|
||||
libromsd_sp.twl.a \
|
||||
|
||||
#SRCDIR = # using default
|
||||
#LCFILE = # using default
|
||||
|
||||
include $(TWLSDK_ROOT)/build/buildtools/commondefs
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
do-build: $(TARGETS)
|
||||
|
||||
|
||||
include $(TWLSDK_ROOT)/build/buildtools/modulerules
|
||||
|
||||
|
||||
#===== End of Makefile =====
|
||||
40
build/tests/fatfs/fatfs_sd/ARM7/main.lsf
Normal file
40
build/tests/fatfs/fatfs_sd/ARM7/main.lsf
Normal file
@ -0,0 +1,40 @@
|
||||
#----------------------------------------------------------------------------
|
||||
# Project: TwlSDK - include
|
||||
# File: ARM7-BB.lsf
|
||||
#
|
||||
# Copyright 2007 Nintendo. All rights reserved.
|
||||
#
|
||||
# These coded insructions, 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: $
|
||||
#----------------------------------------------------------------------------
|
||||
#
|
||||
# Nitro LCF SPEC FILE
|
||||
#
|
||||
|
||||
Static $(TARGET_NAME)
|
||||
{
|
||||
Address 0x02004000
|
||||
Library crt0.o
|
||||
StackSize 1024 512
|
||||
}
|
||||
|
||||
#Objects on MAIN RAM # nothing for elf2bin
|
||||
#Autoload MAIN
|
||||
#{
|
||||
# Address 0x027e0000
|
||||
# Library
|
||||
#}
|
||||
|
||||
Autoload MAIN
|
||||
{
|
||||
Address 0x02020000
|
||||
Object $(OBJS_STATIC)
|
||||
Library $(LLIBS) $(GLIBS) $(CW_LIBS)
|
||||
Object * (.wram)
|
||||
}
|
||||
239
build/tests/fatfs/fatfs_sd/ARM7/src/main.c
Normal file
239
build/tests/fatfs/fatfs_sd/ARM7/src/main.c
Normal file
@ -0,0 +1,239 @@
|
||||
/*---------------------------------------------------------------------------*
|
||||
Project: TwlSDK - tests - snd - channel
|
||||
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_sp.h>
|
||||
#include <twl/fatfs/ARM7/rtfs.h>
|
||||
#include <twl/devices/sdmc/ARM7/sdmc.h>
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
定数定義
|
||||
*---------------------------------------------------------------------------*/
|
||||
#define PRINTDEBUG OS_TPrintf
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
内部関数定義
|
||||
*---------------------------------------------------------------------------*/
|
||||
static OSHeapHandle InitializeAllocateSystem(void);
|
||||
static void VBlankIntr(void);
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
|
||||
*---------------------------------------------------------------------------*/
|
||||
u32 BlockBuf[512/4];
|
||||
u32 BlockBuf2[512/4];
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: TwlSpMain
|
||||
|
||||
Description: Initialize and do main
|
||||
|
||||
Arguments: None.
|
||||
|
||||
Returns: None.
|
||||
*---------------------------------------------------------------------------*/
|
||||
void TwlSpMain(void)
|
||||
{
|
||||
OSHeapHandle heapHandle;
|
||||
SDMC_ERR_CODE result;
|
||||
SdmcResultInfo SdResult;
|
||||
|
||||
// OS初期化
|
||||
OS_Init();
|
||||
|
||||
OS_InitTick();
|
||||
OS_InitAlarm();
|
||||
|
||||
OS_InitThread();
|
||||
|
||||
// PXI初期化、ARM9と同期
|
||||
PXI_Init();
|
||||
|
||||
// ヒープ領域設定
|
||||
heapHandle = InitializeAllocateSystem();
|
||||
|
||||
|
||||
// ボタン入力サーチ初期化
|
||||
(void)PAD_InitXYButton();
|
||||
|
||||
// 割込み許可
|
||||
(void)OS_SetIrqFunction(OS_IE_V_BLANK, VBlankIntr);
|
||||
(void)OS_EnableIrqMask(OS_IE_V_BLANK);
|
||||
(void)GX_VBlankIntr(TRUE);
|
||||
(void)OS_EnableIrq();
|
||||
(void)OS_EnableInterrupts();
|
||||
|
||||
|
||||
/**/
|
||||
PRINTDEBUG("Sample program starts.\n");
|
||||
// rtfs_init();
|
||||
|
||||
/*SDドライバ初期化*/
|
||||
result = sdmcInit( NULL, NULL);
|
||||
if( result != 0) {
|
||||
PRINTDEBUG( "sdmcInit : failed\n");
|
||||
while( 1) {};
|
||||
}else{
|
||||
PRINTDEBUG( "sdmcInit : success\n");
|
||||
}
|
||||
|
||||
/*SDからブロックリード*/
|
||||
result = sdmcReadFifo( BlockBuf, 1, 0, NULL, &SdResult);
|
||||
if( result != 0) {
|
||||
PRINTDEBUG( "sdmcReadFifo failed.\n");
|
||||
}
|
||||
PRINTDEBUG( "sdmcReadFifo success.\n");
|
||||
|
||||
|
||||
/*SDへブロックライト*/
|
||||
MI_CpuFill8( BlockBuf2, 0xA5, 512);
|
||||
result = sdmcWriteFifo( BlockBuf2, 1, 0, NULL, &SdResult);
|
||||
if( result != 0) {
|
||||
PRINTDEBUG( "sdmcWriteFifo failed.\n");
|
||||
}
|
||||
PRINTDEBUG( "sdmcWriteFifo success.\n");
|
||||
|
||||
|
||||
/*SDからブロックリード*/
|
||||
result = sdmcReadFifo( BlockBuf2, 1, 0, NULL, &SdResult);
|
||||
if( result != 0) {
|
||||
PRINTDEBUG( "sdmcReadFifo failed.\n");
|
||||
}
|
||||
PRINTDEBUG( "sdmcReadFifo success.\n");
|
||||
|
||||
|
||||
/*SDへブロックライト*/
|
||||
result = sdmcWriteFifo( BlockBuf, 1, 0, NULL, &SdResult);
|
||||
if( result != 0) {
|
||||
PRINTDEBUG( "sdmcWriteFifo failed.\n");
|
||||
}
|
||||
PRINTDEBUG( "sdmcWriteFifo success.\n");
|
||||
|
||||
/*デバイスドライバの登録*/
|
||||
/* if( sdmcRtfsAttach( 4) == FALSE) { //sdmcをEドライブにする
|
||||
PRINTDEBUG( "sdmcRtfsAttach failed.\n");
|
||||
}else{
|
||||
if( sdmcRtfsAttach( 4) == FALSE) {
|
||||
PRINTDEBUG( "sdmcRtfsAttach success.\n");
|
||||
}else{
|
||||
PRINTDEBUG( "sdmcRtfsAttach error!.\n");
|
||||
}
|
||||
}
|
||||
|
||||
if( !rtfs_pc_set_default_drive( (unsigned char*)"E:")) {
|
||||
PRINTDEBUG( "pc_set_default_drive failed\n");
|
||||
while( 1){};
|
||||
}
|
||||
PRINTDEBUG( "pc_set_default_drive success\n");*/
|
||||
|
||||
PRINTDEBUG( "Sample program ends.\n");
|
||||
|
||||
|
||||
while (TRUE)
|
||||
{
|
||||
OS_Halt();
|
||||
|
||||
//---- check reset
|
||||
if (OS_IsResetOccurred())
|
||||
{
|
||||
OS_ResetSystem();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: InitializeAllocateSystem
|
||||
|
||||
Description: メモリ割当てシステムを初期化する。
|
||||
|
||||
Arguments: None.
|
||||
|
||||
Returns: None.
|
||||
*---------------------------------------------------------------------------*/
|
||||
static OSHeapHandle InitializeAllocateSystem(void)
|
||||
{
|
||||
void *tempLo;
|
||||
OSHeapHandle hh;
|
||||
|
||||
OS_TPrintf("OS_GetWramSubPrivArenaLo() = %p\n", OS_GetWramSubPrivArenaLo());
|
||||
OS_TPrintf("OS_GetWramSubPrivArenaHi() = %p\n", OS_GetWramSubPrivArenaHi());
|
||||
OS_TPrintf("OS_GetWramSubArenaLo() = %p\n", OS_GetWramSubArenaLo());
|
||||
OS_TPrintf("OS_GetWramSubArenaHi() = %p\n", OS_GetWramSubArenaHi());
|
||||
OS_TPrintf("OS_GetSubPrivArenaLo() = %p\n", OS_GetSubPrivArenaLo());
|
||||
OS_TPrintf("OS_GetSubPrivArenaHi() = %p\n", OS_GetSubPrivArenaHi());
|
||||
|
||||
OS_TPrintf("call OS_SetWramSubPrivArenaHi(0x0380f980); to fix arena.\n");
|
||||
OS_SetWramSubPrivArenaHi((void*)0x0380f980);
|
||||
|
||||
// メモリ割当て初期化
|
||||
tempLo = OS_InitAlloc(OS_ARENA_WRAM_SUBPRIV,
|
||||
OS_GetWramSubPrivArenaLo(), OS_GetWramSubPrivArenaHi(), 1);
|
||||
|
||||
// アリーナを0クリア
|
||||
MI_CpuClear8(tempLo, (u32)OS_GetWramSubPrivArenaHi() - (u32)tempLo);
|
||||
|
||||
// アリーナ下位アドレスを設定
|
||||
OS_SetArenaLo(OS_ARENA_WRAM_SUBPRIV, tempLo);
|
||||
|
||||
// ヒープ作成
|
||||
hh = OS_CreateHeap(OS_ARENA_WRAM_SUBPRIV,
|
||||
OS_GetWramSubPrivArenaLo(), OS_GetWramSubPrivArenaHi());
|
||||
|
||||
if (hh < 0)
|
||||
{
|
||||
OS_Panic("ARM7: Fail to create heap.\n");
|
||||
}
|
||||
|
||||
// カレントヒープに設定
|
||||
(void)OS_SetCurrentHeap(OS_ARENA_WRAM_SUBPRIV, hh);
|
||||
|
||||
return hh;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: VBlankIntr
|
||||
|
||||
Description: VBlank interrupt handler
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
#ifndef SDK_TEG
|
||||
|
||||
extern BOOL PMi_Initialized;
|
||||
void PM_SelfBlinkProc(void);
|
||||
|
||||
static void VBlankIntr(void)
|
||||
{
|
||||
//---- LED blink system
|
||||
if (PMi_Initialized)
|
||||
{
|
||||
PM_SelfBlinkProc();
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static void VBlankIntr(void)
|
||||
{
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
End of file
|
||||
*---------------------------------------------------------------------------*/
|
||||
32
build/tests/fatfs/fatfs_sd/Makefile
Normal file
32
build/tests/fatfs/fatfs_sd/Makefile
Normal file
@ -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 =====
|
||||
Loading…
Reference in New Issue
Block a user