mirror of
https://github.com/rvtr/twl_wrapsdk.git
synced 2025-10-31 06:11:10 -04:00
delete rom_sdmc
git-svn-id: file:///Users/lillianskinner/Downloads/platinum/twl/twl_wrapsdk/trunk@128 4ee2a332-4b2b-5046-8439-1ba90f034370
This commit is contained in:
parent
c40d0becca
commit
1f0e0b2245
@ -22,7 +22,6 @@ include $(TWLSDK_ROOT)/build/buildtools/commondefs
|
||||
|
||||
SUBDIRS = \
|
||||
sdmc \
|
||||
rom_sdmc \
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
export NITRO_BLXCHECKED = yes
|
||||
|
||||
@ -1,66 +0,0 @@
|
||||
#! 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 =====
|
||||
@ -1,686 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*
|
||||
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)*/
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,349 +0,0 @@
|
||||
/*
|
||||
** 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);
|
||||
|
||||
|
||||
BOOL 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__ */
|
||||
@ -1,118 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*
|
||||
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__ */
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,85 +0,0 @@
|
||||
/*
|
||||
** 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_ON 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__*/
|
||||
@ -1,34 +0,0 @@
|
||||
#! 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 =====
|
||||
@ -1,146 +0,0 @@
|
||||
#ifndef __SDMC_H__
|
||||
#define __SDMC_H__
|
||||
|
||||
#include <twl.h>
|
||||
#include <rtfs.h>
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/*********************************************
|
||||
ポート番号
|
||||
*********************************************/
|
||||
typedef enum {
|
||||
SDMC_PORT_CARD = 0x400,
|
||||
SDMC_PORT_NAND = 0x401
|
||||
}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に対して
|
||||
*********************************************/
|
||||
typedef enum {
|
||||
SDMC_NORMAL = 0, /* 正常終了 */
|
||||
SDMC_ERR_COMMAND = 0x0001, /* CMDエラー */
|
||||
SDMC_ERR_CRC = 0x0002, /* CRCエラー */
|
||||
SDMC_ERR_END = 0x0004, /* 実行エラー */
|
||||
SDMC_ERR_TIMEOUT = 0x0008, /* コマンドタイムアウト */
|
||||
SDMC_ERR_FIFO_OVF = 0x0010, /* FIFO オーバーフローエラー(INFO2のIllegal write access to buffer) */
|
||||
SDMC_ERR_FIFO_UDF = 0x0020, /* FIFO アンダーフローエラー(INFO2のIllegal read access to buffer) */
|
||||
SDMC_ERR_WP = 0x0040, /* WriteProtectによる書き込みエラー */
|
||||
SDMC_ERR_FPGA_TIMEOUT = 0x0100, /* FPGA アクセスタイムアウト */
|
||||
SDMC_ERR_PARAM = 0x0200, /* コマンドパラメータエラー */
|
||||
SDMC_ERR_R1_STATUS = 0x0800, /* Normal response command カードステータス エラー */
|
||||
SDMC_ERR_NUM_WR_SECTORS = 0x1000, /* 書き込み完了セクタ数 エラー */
|
||||
SDMC_ERR_RESET = 0x2000, /* 初期化カードリセットコマンド時1.5秒タイムアウトエラー */
|
||||
SDMC_ERR_ILA = 0x4000, /* イリーガルアクセスエラー */
|
||||
SDMC_ERR_INFO_DETECT = 0x8000 /* カード排出時判別エラービット(IO3) */
|
||||
}SDMC_ERR_CODE;
|
||||
|
||||
|
||||
/*********************************************
|
||||
SDドライバ処理結果通知情報構造体
|
||||
*********************************************/
|
||||
typedef struct {
|
||||
u16 b_flags; /* 処理内容 */
|
||||
u16 result; /* 実行結果 */
|
||||
u32 resid; /* 読み(書き)サイズ */
|
||||
} SdmcResultInfo;
|
||||
|
||||
|
||||
/*********************************************
|
||||
SDスペック構造体
|
||||
*********************************************/
|
||||
typedef struct {
|
||||
u32 csd_ver2_flag; //CSDフォーマットバージョン(SDHCのときは1)
|
||||
u32 memory_capacity; //data areaのサイズ(512Byte単位)
|
||||
u32 protected_capacity; //protected areaのサイズ(512Byte単位)
|
||||
u32 card_capacity; //カード全体のサイズ(512Byte単位)
|
||||
|
||||
u32 adjusted_memory_capacity; //memory_capacityをシリンダ(heads*secptrack)の倍数に調整したサイズ(cylinders*heads*secptrackになる)
|
||||
|
||||
u16 heads;
|
||||
u16 secptrack;
|
||||
u16 cylinders;
|
||||
u16 SC; //sectors per cluster
|
||||
u16 BU;
|
||||
u16 RDE; //number of root dir entries(512 fix)
|
||||
u32 SS; //sector size(512 fix)
|
||||
u32 RSC; //reserved sector count(1 fix)
|
||||
// u32 TS; //total sectors
|
||||
u16 FATBITS; //16 or 32
|
||||
u16 SF; //sectors per FAT
|
||||
u32 SSA; //sectors in system area
|
||||
u32 NOM; //sectors in master boot record
|
||||
} SdmcSpec;
|
||||
|
||||
|
||||
/*********************************************
|
||||
RTFS用ドライバインタフェース
|
||||
*********************************************/
|
||||
BOOL sdmcRtfsIo( int driveno, dword block, void* buffer, word count, BOOLEAN reading);
|
||||
int sdmcRtfsCtrl( int driveno, int opcode, void* pargs);
|
||||
BOOL sdmcRtfsAttach( int driveno);
|
||||
|
||||
BOOL sdmcCheckMedia( void);
|
||||
|
||||
|
||||
/*********************************************
|
||||
データ転送関数の登録関連
|
||||
*********************************************/
|
||||
typedef void (*sdmcTransferFunction)( void* sd_adr, u32 size, BOOL read_flag);
|
||||
|
||||
//void sdmcSetTransferFunction( sdmcTransferFunction usr_func);
|
||||
|
||||
|
||||
/*********************************************
|
||||
基本API
|
||||
*********************************************/
|
||||
SDMC_ERR_CODE sdmcInit( SDMC_DMA_NO dma_no, void (*func1)(),void (*func2)());/* カードドライバ初期化 */
|
||||
SDMC_ERR_CODE sdmcReset( void); /* カードリセット */
|
||||
|
||||
SDMC_ERR_CODE sdmcGetStatus(u16 *status); /* カードドライバの現在の状態を取得する */
|
||||
u32 sdmcGetCardSize(void); /* カード全サイズの取得 */
|
||||
|
||||
/*SD I/FのFIFOを使ってリードする(高速)*/
|
||||
SDMC_ERR_CODE sdmcReadFifo(void* buf,u32 bufsize,u32 offset,void(*func)(void),SdmcResultInfo *info);
|
||||
SDMC_ERR_CODE sdmcReadFifoDirect( sdmcTransferFunction usr_func,
|
||||
u32 bufsize,u32 offset,void(*func)(void),SdmcResultInfo *info);
|
||||
|
||||
|
||||
/*リードする*/
|
||||
//SDMC_ERR_CODE sdmcRead(void* buf,u32 bufsize,u32 offset,void(*func)(void),SdmcResultInfo *info);
|
||||
|
||||
/*SD I/FのFIFOを使ってライトする(高速)*/
|
||||
SDMC_ERR_CODE sdmcWriteFifo(void* buf,u32 bufsize,u32 offset,void(*func)(void),SdmcResultInfo *info);
|
||||
SDMC_ERR_CODE sdmcWriteFifoDirect(sdmcTransferFunction usr_func,
|
||||
u32 bufsize,u32 offset,void(*func)(void),SdmcResultInfo *info);
|
||||
/*ライトする*/
|
||||
//SDMC_ERR_CODE sdmcWrite(void* buf,u32 bufsize,u32 offset,void(*func)(void),SdmcResultInfo *info);
|
||||
|
||||
/*ポート選択*/
|
||||
u16 sdmcSelectedNo(void);
|
||||
SDMC_ERR_CODE sdmcSelect(u16 select);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
|
||||
#endif /*__SDMC_H__*/
|
||||
Loading…
Reference in New Issue
Block a user