mirror of
https://github.com/rvtr/TwlIPL.git
synced 2025-10-31 06:01:12 -04:00
add prototype of nandfirm and relational libraries
git-svn-id: file:///Users/lillianskinner/Downloads/platinum/twl/TwlIPL/trunk@25 b08762b0-b915-fc4b-9d8c-17b2551a87ff
This commit is contained in:
parent
41c9d02985
commit
451c6d9242
@ -26,7 +26,7 @@ endif
|
||||
TWL_KEYSDIR ?= $(FIRM_ROOT)/keys/dummy
|
||||
|
||||
|
||||
ifneq ($(filter NORFIRM NANDFIRM GCDFIRM,$(FIRM_TARGET)),)
|
||||
ifneq ($(filter FIRM GCDFIRM,$(FIRM_TARGET)),)
|
||||
TARGET_BIN ?= $(subst .,$(DUMMY_KEYS_SUFFIX).,$(TARGET_FIRM_BIN))
|
||||
endif
|
||||
|
||||
@ -41,10 +41,10 @@ SPACE ?= $(EMPTY) $(EMPTY)
|
||||
# FIRM_CODEGEN = [ARM/THUMB]
|
||||
# FIRM_PROC = [ARM9/ARM7]
|
||||
#
|
||||
# FIRM_TARGET = [NORFIRM/NANDFIRM/GCDFIRM/APP]
|
||||
# FIRM_TARGET = [FIRM/GCDFIRM/APP]
|
||||
#
|
||||
|
||||
FIRM_PLATFORM ?= BB
|
||||
FIRM_PLATFORM ?= TS
|
||||
FIRM_MEMSIZE ?= 32M
|
||||
FIRM_CODEGEN ?= ARM
|
||||
FIRM_PROC ?= ARM9
|
||||
@ -164,6 +164,7 @@ ifeq ($(CODEGEN_PROC),ARM9)
|
||||
FIRM_LIBS_BASE ?= \
|
||||
libos \
|
||||
libmi \
|
||||
libpxi \
|
||||
# libgcd \
|
||||
# libacsign \
|
||||
|
||||
@ -173,9 +174,12 @@ else # ($(CODEGEN_PROC),ARM7)
|
||||
|
||||
FIRM_LIBS_BASE ?= \
|
||||
libos_sp \
|
||||
libfatfs_sp \
|
||||
libpxi_sp \
|
||||
libaes_sp \
|
||||
libpm_sp \
|
||||
# libnvram_sp \
|
||||
# libgcd_sp \
|
||||
# libaes_sp \
|
||||
# libacsign_sp \
|
||||
# libfirmsd_sp \
|
||||
|
||||
|
||||
@ -25,10 +25,13 @@ SUBDIRS = \
|
||||
os \
|
||||
mi \
|
||||
init \
|
||||
pxi \
|
||||
fatfs \
|
||||
aes \
|
||||
pm \
|
||||
# syscall \
|
||||
# nvram \
|
||||
# gcd \
|
||||
# aes \
|
||||
# acsign \
|
||||
# acsign_ecc \
|
||||
# devices \
|
||||
|
||||
59
build/libraries/aes/ARM7/Makefile
Normal file
59
build/libraries/aes/ARM7/Makefile
Normal file
@ -0,0 +1,59 @@
|
||||
#! make -f
|
||||
#----------------------------------------------------------------------------
|
||||
# Project: TwlFirm - libraries - aes
|
||||
# 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.
|
||||
#
|
||||
# $Date:: $
|
||||
# $Rev:$
|
||||
# $Author:$
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
SUBDIRS =
|
||||
SUBMAKES =
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
# build ARM & THUMB libraries
|
||||
FIRM_CODEGEN_ALL ?= TRUE
|
||||
|
||||
# Codegen for sub processer
|
||||
FIRM_PROC = ARM7
|
||||
|
||||
SRCDIR = .
|
||||
|
||||
SRCS = \
|
||||
aes_init.c \
|
||||
|
||||
TARGET_LIB = libaes_sp$(FIRM_LIBSUFFIX).a
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
# DEBUG版ビルドの場合、RELEASE版でビルドして
|
||||
# DEBUG版のライブラリを装います。
|
||||
|
||||
ifdef NITRO_DEBUG
|
||||
NITRO_BUILD_TYPE = RELEASE
|
||||
endif
|
||||
|
||||
include $(TWLFIRM_ROOT)/build/buildtools/commondefs
|
||||
|
||||
INSTALL_TARGETS = $(TARGETS)
|
||||
INSTALL_DIR = $(FIRM_INSTALL_LIBDIR)
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
do-build: $(TARGETS)
|
||||
|
||||
include $(TWLFIRM_ROOT)/build/buildtools/modulerules
|
||||
|
||||
#===== End of Makefile =====
|
||||
72
build/libraries/aes/ARM7/aes_init.c
Normal file
72
build/libraries/aes/ARM7/aes_init.c
Normal file
@ -0,0 +1,72 @@
|
||||
/*---------------------------------------------------------------------------*
|
||||
Project: TwlIPL - libraries - aes
|
||||
File: aes_init.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.
|
||||
|
||||
$Date:: $
|
||||
$Rev$
|
||||
$Author$
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#include <firm/aes.h>
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: AESi_InitGameKeys
|
||||
|
||||
Description: set IDs depending on the application.
|
||||
you SHOULD NOT touch any ID registers after this call.
|
||||
|
||||
Arguments: u8[4] game code
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void AESi_InitGameKeys( u8 game_code[4] )
|
||||
{
|
||||
while (reg_AES_AES_CNT & REG_AES_AES_CNT_E_MASK)
|
||||
{
|
||||
}
|
||||
|
||||
reg_AES_AES_ID_B2 = AES_IDS_ID0_C(game_code);
|
||||
reg_AES_AES_ID_B3 = AES_IDS_ID0_D(game_code);
|
||||
|
||||
reg_AES_AES_ID_C0 = AES_IDS_ID1_A(game_code);
|
||||
reg_AES_AES_ID_C1 = AES_IDS_ID1_B(game_code);
|
||||
|
||||
// set dummy without seed[3]
|
||||
reg_AES_AES_SEED_A0 = 1;
|
||||
reg_AES_AES_SEED_A1 = 2;
|
||||
reg_AES_AES_SEED_A2 = 3;
|
||||
reg_AES_AES_SEED_B0 = 4;
|
||||
reg_AES_AES_SEED_B1 = 5;
|
||||
reg_AES_AES_SEED_B2 = 6;
|
||||
reg_AES_AES_SEED_C0 = 7;
|
||||
reg_AES_AES_SEED_C1 = 8;
|
||||
reg_AES_AES_SEED_C2 = 9;
|
||||
reg_AES_AES_SEED_D0 = 10;
|
||||
reg_AES_AES_SEED_D1 = 11;
|
||||
reg_AES_AES_SEED_D2 = 12;
|
||||
|
||||
reg_AES_AES_KEY_A0 = 1;
|
||||
reg_AES_AES_KEY_A1 = 2;
|
||||
reg_AES_AES_KEY_A2 = 3;
|
||||
reg_AES_AES_KEY_A3 = 3;
|
||||
reg_AES_AES_KEY_B0 = 4;
|
||||
reg_AES_AES_KEY_B1 = 5;
|
||||
reg_AES_AES_KEY_B2 = 6;
|
||||
reg_AES_AES_KEY_B3 = 6;
|
||||
reg_AES_AES_KEY_C0 = 7;
|
||||
reg_AES_AES_KEY_C1 = 8;
|
||||
reg_AES_AES_KEY_C2 = 9;
|
||||
reg_AES_AES_KEY_C3 = 9;
|
||||
reg_AES_AES_KEY_D0 = 10;
|
||||
reg_AES_AES_KEY_D1 = 11;
|
||||
reg_AES_AES_KEY_D2 = 12;
|
||||
reg_AES_AES_KEY_D3 = 12;
|
||||
}
|
||||
31
build/libraries/aes/Makefile
Normal file
31
build/libraries/aes/Makefile
Normal file
@ -0,0 +1,31 @@
|
||||
#! make -f
|
||||
#----------------------------------------------------------------------------
|
||||
# Project: TwlIPL - libraries - aes
|
||||
# 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.
|
||||
#
|
||||
# $Date:: $
|
||||
# $Rev:$
|
||||
# $Author:$
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
include $(TWLFIRM_ROOT)/build/buildtools/commondefs
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
SUBDIRS = ARM7
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
include $(TWLFIRM_ROOT)/build/buildtools/modulerules
|
||||
|
||||
|
||||
#===== End of Makefile =====
|
||||
68
build/libraries/fatfs/ARM7/Makefile
Normal file
68
build/libraries/fatfs/ARM7/Makefile
Normal file
@ -0,0 +1,68 @@
|
||||
#! make -f
|
||||
#----------------------------------------------------------------------------
|
||||
# Project: TwlFirm - libraries - fatfs
|
||||
# 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.
|
||||
#
|
||||
# $Date:: $
|
||||
# $Rev:$
|
||||
# $Author:$
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
SUBDIRS =
|
||||
SUBMAKES =
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
# build ARM & THUMB libraries
|
||||
FIRM_CODEGEN_ALL ?= TRUE
|
||||
|
||||
# Codegen for sub processer
|
||||
FIRM_PROC = ARM7
|
||||
|
||||
INCDIR = rom_sdmc \
|
||||
$(TWLSDK_ROOT)/build/libraries/fatfs/ARM7.TWL/include \
|
||||
$(TWLSDK_ROOT)/build/libraries/fatfs/ARM7.TWL/include/twl/fatfs/ARM7
|
||||
|
||||
SRCDIR = src rom_sdmc
|
||||
|
||||
SRCS = \
|
||||
fatfs_loader.c \
|
||||
fatfs_firm.c \
|
||||
sdmc.c \
|
||||
sdmc_nandinit.c \
|
||||
drsdmc.c \
|
||||
|
||||
|
||||
TARGET_LIB = libfatfs_sp$(FIRM_LIBSUFFIX).a
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
# DEBUG版ビルドの場合、RELEASE版でビルドして
|
||||
# DEBUG版のライブラリを装います。
|
||||
|
||||
ifdef NITRO_DEBUG
|
||||
NITRO_BUILD_TYPE = RELEASE
|
||||
endif
|
||||
|
||||
include $(TWLFIRM_ROOT)/build/buildtools/commondefs
|
||||
|
||||
INSTALL_TARGETS = $(TARGETS)
|
||||
INSTALL_DIR = $(FIRM_INSTALL_LIBDIR)
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
do-build: $(TARGETS)
|
||||
|
||||
include $(TWLFIRM_ROOT)/build/buildtools/modulerules
|
||||
|
||||
#===== End of Makefile =====
|
||||
687
build/libraries/fatfs/ARM7/firm_sdmc/drsdmc.c
Normal file
687
build/libraries/fatfs/ARM7/firm_sdmc/drsdmc.c
Normal file
@ -0,0 +1,687 @@
|
||||
/*---------------------------------------------------------------------------*
|
||||
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"
|
||||
#include <firm/sdmc.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/fatfs/ARM7/firm_sdmc/sdif.c
Normal file
1188
build/libraries/fatfs/ARM7/firm_sdmc/sdif.c
Normal file
File diff suppressed because it is too large
Load Diff
2683
build/libraries/fatfs/ARM7/firm_sdmc/sdmc.c
Normal file
2683
build/libraries/fatfs/ARM7/firm_sdmc/sdmc.c
Normal file
File diff suppressed because it is too large
Load Diff
246
build/libraries/fatfs/ARM7/firm_sdmc/sdmc_port.c
Normal file
246
build/libraries/fatfs/ARM7/firm_sdmc/sdmc_port.c
Normal file
@ -0,0 +1,246 @@
|
||||
/*---------------------------------------------------------------------------*
|
||||
Project:
|
||||
File: sdmc_port.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: sdmc_port.c,v $
|
||||
$NoKeywords: $
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#include <firm.h>
|
||||
#include "sdmc_config.h"
|
||||
#include "sdif_reg.h"
|
||||
#include <firm/devices/firm_sdmc/ARM7/sdmc.h>
|
||||
#include "sdif_ip.h"
|
||||
|
||||
|
||||
// #define PRINTDEBUG OS_TPrintf
|
||||
#define PRINTDEBUG( ...) ((void)0)
|
||||
|
||||
|
||||
|
||||
/*extern変数(sdmc.c)*/
|
||||
extern u32 SDCARD_SectorSize; /* セクタサイズ デフォルト 512bytes */
|
||||
extern SDMC_ERR_CODE SDCARD_ErrStatus; /* エラーステータス */
|
||||
extern volatile s16 SDCARD_OutFlag; /* カード排出発生判定フラグ */
|
||||
|
||||
|
||||
extern SDPortContext SDPort0Context;
|
||||
extern SDPortContext SDPort1Context;
|
||||
|
||||
|
||||
/*extern関数(sdmc.c)*/
|
||||
extern void i_sdmcCalcSize( void);
|
||||
extern void SDCARD_Backup_port1(void);
|
||||
extern void SDCARD_Restore_port1(void);
|
||||
extern SDMC_ERR_CODE SDCARD_Layer_Init(void);
|
||||
extern void SDCARD_TimerStop(void); /* タイムアウト計測停止 */
|
||||
|
||||
static SDMC_ERR_CODE i_sdmcSavePortContext( SDPortContext* buf_adr, u16 port_no);
|
||||
static SDMC_ERR_CODE i_sdmcLoadPortContext( SDPortContext* buf_adr, u16* port_no);
|
||||
|
||||
static void sdmcPrintContext( SDPortContext* targ);
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: sdmcClearPortContext
|
||||
|
||||
Description:
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void sdmcClearPortContext( SDPortContext* buf_adr)
|
||||
{
|
||||
MI_CpuFill8( buf_adr, 0x00, sizeof(SDPortContext));
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: sdmcCheckPortContext
|
||||
|
||||
Description:
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
SDMC_ERR_CODE sdmcCheckPortContext( SDPortContext* buf_adr)
|
||||
{
|
||||
if( (buf_adr->SD_CID[0] != 0)&&(buf_adr->port_no < 2)) {
|
||||
return( SDMC_NORMAL);
|
||||
}else{
|
||||
return( SDMC_ERR_PARAM);
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: sdmcSavePortContext
|
||||
|
||||
Description: ポート0のレジスタや変数をユーザバッファに退避する
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
static SDMC_ERR_CODE i_sdmcSavePortContext( SDPortContext* buf_adr, u16 port_no)
|
||||
{
|
||||
if( buf_adr == NULL) {
|
||||
return( SDMC_ERR_PARAM);
|
||||
}
|
||||
switch( port_no) {
|
||||
case 0:
|
||||
MI_CpuCopy8( &SDPort0Context, buf_adr, sizeof(SDPortContext));
|
||||
buf_adr->port_no = 0;
|
||||
break;
|
||||
case 1:
|
||||
MI_CpuCopy8( &SDPort1Context, buf_adr, sizeof(SDPortContext));
|
||||
buf_adr->port_no = 1;
|
||||
break;
|
||||
default: return( SDMC_ERR_PARAM);
|
||||
}
|
||||
return( SDMC_NORMAL);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: sdmcLoadPortContext
|
||||
|
||||
Description: ポート0のレジスタや変数をユーザバッファから復帰する
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
static SDMC_ERR_CODE i_sdmcLoadPortContext( SDPortContext* buf_adr, u16* port_no)
|
||||
{
|
||||
if( buf_adr == NULL) {
|
||||
return( SDMC_ERR_PARAM);
|
||||
}
|
||||
switch( buf_adr->port_no) {
|
||||
case 0:
|
||||
MI_CpuCopy8( buf_adr, &SDPort0Context, sizeof(SDPortContext));
|
||||
*port_no = 0;
|
||||
break;
|
||||
case 1:
|
||||
MI_CpuCopy8( buf_adr, &SDPort1Context, sizeof(SDPortContext));
|
||||
*port_no = 1;
|
||||
break;
|
||||
default: return( SDMC_ERR_PARAM);
|
||||
}
|
||||
return( SDMC_NORMAL);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: i_sdmcMPInitFirm
|
||||
|
||||
Description: initialize SD card in multi ports.
|
||||
マルチポートのSDカード初期化
|
||||
|
||||
Arguments:
|
||||
|
||||
Returns: 0 : success
|
||||
> 0 : error code
|
||||
*---------------------------------------------------------------------------*/
|
||||
SDMC_ERR_CODE i_sdmcMPInitFirm( void)
|
||||
{
|
||||
u16 load_port_no;
|
||||
SDPortContext* SDNandContext;
|
||||
|
||||
//予約領域のポートコンテキスト参照
|
||||
SDNandContext = (SDPortContext*)&(((OSFromBromBuf*)OSi_GetFromBromAddr())->SDNandContext);
|
||||
|
||||
#if 0
|
||||
sdmcPrintContext( SDNandContext);
|
||||
#endif
|
||||
|
||||
//NANDスロットの初期化
|
||||
SD_SetFPGA( SD_PORTSEL, SDMC_PORT_NAND); /* NANDポート選択 */
|
||||
|
||||
PRINTDEBUG( "SDNandContext : 0x%x\n", SDNandContext);
|
||||
//初期化済みでないときだけ初期化
|
||||
if( sdmcCheckPortContext( SDNandContext) != SDMC_NORMAL) {
|
||||
PRINTDEBUG( "sdmcCheckPortContext : ERR!\n");
|
||||
SDCARD_ErrStatus = SDCARD_Layer_Init();
|
||||
|
||||
SDCARD_Backup_port1(); //TODO:ポート番号
|
||||
//ポートコンテキストの保存
|
||||
if( i_sdmcSavePortContext( SDNandContext, 1) != SDMC_NORMAL) {
|
||||
PRINTDEBUG( "i_sdmcSavePortContext failed\n");
|
||||
return( SDMC_ERR_PARAM);
|
||||
}
|
||||
}else{ //ポートコンテキストの復帰
|
||||
PRINTDEBUG( "sdmcCheckPortContext : NORMAL\n");
|
||||
|
||||
/*SDCARD_Layer_Init()の代わり*/
|
||||
SDCARD_SectorSize = SECTOR_SIZE; /* セクタサイズ デフォルト 512bytes */
|
||||
// SD_SetFPGA(SD_CLK_CTRL,(SD_CLK_CTRL_128)); /* SDクロックの周波数 261KHz(初期化時は100~400khz) */
|
||||
|
||||
if( i_sdmcLoadPortContext( SDNandContext, &load_port_no) != SDMC_NORMAL) {
|
||||
PRINTDEBUG( "i_sdmcLoadPortContext failed\n");
|
||||
return( SDMC_ERR_PARAM);
|
||||
}
|
||||
SDCARD_Restore_port1(); //TODO:load_port_no値判定
|
||||
}
|
||||
|
||||
SDCARD_OutFlag = FALSE; /* 排出フラグをリセット */
|
||||
|
||||
SDCARD_TimerStop(); /* タイムアウト判定用タイマストップ */
|
||||
SD_DisableClock(); /* SD-CLK Disable */
|
||||
SD_EnableInfo(); /* SD Card 挿抜 割り込み許可 */
|
||||
|
||||
return SDCARD_ErrStatus;
|
||||
}
|
||||
|
||||
|
||||
/*デバッグ用*/
|
||||
static void sdmcPrintContext( SDPortContext* targ)
|
||||
{
|
||||
OS_TPrintf( "CID[0]:0x%x\n", targ->SD_CID[0]);
|
||||
OS_TPrintf( "CID[1]:0x%x\n", targ->SD_CID[1]);
|
||||
OS_TPrintf( "CID[2]:0x%x\n", targ->SD_CID[2]);
|
||||
OS_TPrintf( "CID[3]:0x%x\n", targ->SD_CID[3]);
|
||||
OS_TPrintf( "CID[4]:0x%x\n", targ->SD_CID[4]);
|
||||
OS_TPrintf( "CID[5]:0x%x\n", targ->SD_CID[5]);
|
||||
OS_TPrintf( "CID[6]:0x%x\n", targ->SD_CID[6]);
|
||||
OS_TPrintf( "CID[7]:0x%x\n\n", targ->SD_CID[7]);
|
||||
|
||||
OS_TPrintf( "CSD[0]:0x%x\n", targ->SD_CSD[0]);
|
||||
OS_TPrintf( "CSD[1]:0x%x\n", targ->SD_CSD[1]);
|
||||
OS_TPrintf( "CSD[2]:0x%x\n", targ->SD_CSD[2]);
|
||||
OS_TPrintf( "CSD[3]:0x%x\n", targ->SD_CSD[3]);
|
||||
OS_TPrintf( "CSD[4]:0x%x\n", targ->SD_CSD[4]);
|
||||
OS_TPrintf( "CSD[5]:0x%x\n", targ->SD_CSD[5]);
|
||||
OS_TPrintf( "CSD[6]:0x%x\n", targ->SD_CSD[6]);
|
||||
OS_TPrintf( "CSD[7]:0x%x\n\n", targ->SD_CSD[7]);
|
||||
|
||||
OS_TPrintf( "OCR[0]:0x%x\n", targ->SD_OCR[0]);
|
||||
OS_TPrintf( "OCR[1]:0x%x\n\n", targ->SD_OCR[1]);
|
||||
|
||||
OS_TPrintf( "SCR[0]:0x%x\n", targ->SD_SCR[0]);
|
||||
OS_TPrintf( "SCR[1]:0x%x\n\n", targ->SD_SCR[1]);
|
||||
|
||||
OS_TPrintf( "RCA:0x%x\n\n", targ->SD_RCA);
|
||||
|
||||
OS_TPrintf( "MMCFlag :0x%x\n", targ->MMCFlag);
|
||||
OS_TPrintf( "SDHCFlag:0x%x\n", targ->SDHCFlag);
|
||||
OS_TPrintf( "SDFlag :0x%x\n\n", targ->SDFlag);
|
||||
|
||||
OS_TPrintf( "ErrStatus:0x%x\n", targ->ErrStatus);
|
||||
OS_TPrintf( "Status:0x%x\n\n", targ->Status);
|
||||
|
||||
OS_TPrintf( "SD_CLK_CTRL_VALUE:0x%x\n", targ->SD_CLK_CTRL_VALUE);
|
||||
OS_TPrintf( "SD_OPTION_VALUE :0x%x\n\n", targ->SD_OPTION_VALUE);
|
||||
|
||||
OS_TPrintf( "OutFlag:0x%x\n\n", targ->OutFlag);
|
||||
|
||||
OS_TPrintf( "port_no:0x%x\n", targ->port_no);
|
||||
}
|
||||
686
build/libraries/fatfs/ARM7/rom_sdmc/drsdmc.c
Normal file
686
build/libraries/fatfs/ARM7/rom_sdmc/drsdmc.c
Normal file
@ -0,0 +1,686 @@
|
||||
/*---------------------------------------------------------------------------*
|
||||
Project: TwlBrom - rtfs interface for SD Memory Card
|
||||
File: drsdmc.h
|
||||
|
||||
Copyright 2007 Nintendo. All rights reserved.
|
||||
|
||||
These coded instructions, statements, and computer programs contain
|
||||
proprietary information of Nintendo of America Inc. and/or Nintendo
|
||||
Company Ltd., and are protected by Federal copyright law. They may
|
||||
not be disclosed to third parties or copied or duplicated in any form,
|
||||
in whole or in part, without the prior written consent of Nintendo.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#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)*/
|
||||
1236
build/libraries/fatfs/ARM7/rom_sdmc/sdif.c
Normal file
1236
build/libraries/fatfs/ARM7/rom_sdmc/sdif.c
Normal file
File diff suppressed because it is too large
Load Diff
349
build/libraries/fatfs/ARM7/rom_sdmc/sdif_ip.h
Normal file
349
build/libraries/fatfs/ARM7/rom_sdmc/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);
|
||||
|
||||
|
||||
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__ */
|
||||
118
build/libraries/fatfs/ARM7/rom_sdmc/sdif_reg.h
Normal file
118
build/libraries/fatfs/ARM7/rom_sdmc/sdif_reg.h
Normal file
@ -0,0 +1,118 @@
|
||||
/*---------------------------------------------------------------------------*
|
||||
Project: TwlBrom - 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__ */
|
||||
2861
build/libraries/fatfs/ARM7/rom_sdmc/sdmc.c
Normal file
2861
build/libraries/fatfs/ARM7/rom_sdmc/sdmc.c
Normal file
File diff suppressed because it is too large
Load Diff
77
build/libraries/fatfs/ARM7/rom_sdmc/sdmc.h
Normal file
77
build/libraries/fatfs/ARM7/rom_sdmc/sdmc.h
Normal file
@ -0,0 +1,77 @@
|
||||
|
||||
#ifndef __SDMC_H__
|
||||
#define __SDMC_H__
|
||||
|
||||
//#include <brom.h>
|
||||
//#include <rtfs.h>
|
||||
|
||||
#include <firm/devices/firm_sdmc/ARM7/sdmc_types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/*********************************************
|
||||
RTFS用ドライバインタフェース
|
||||
*********************************************/
|
||||
#if 0
|
||||
BOOL sdmcRtfsIo( int driveno, dword block, void* buffer, word count, BOOLEAN reading);
|
||||
int sdmcRtfsCtrl( int driveno, int opcode, void* pargs);
|
||||
BOOL sdmcRtfsAttach( int driveno);
|
||||
#endif
|
||||
|
||||
BOOL sdmcCheckMedia( void);
|
||||
|
||||
|
||||
/*********************************************
|
||||
データ転送関数の登録関連
|
||||
*********************************************/
|
||||
typedef void (*sdmcTransferFunction)( void* sd_adr, u32 size, BOOL read_flag);
|
||||
|
||||
//void sdmcSetTransferFunction( sdmcTransferFunction usr_func);
|
||||
|
||||
|
||||
/*********************************************
|
||||
基本API
|
||||
*********************************************/
|
||||
void sdmcClearPortContext( SDPortContext* buf_adr);
|
||||
SDMC_ERR_CODE sdmcCheckPortContext( SDPortContext* buf_adr);
|
||||
|
||||
|
||||
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 sdmcReadStreamBegin( u32 offset, SdmcResultInfo *info);
|
||||
SDMC_ERR_CODE sdmcReadStreamEnd( 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__*/
|
||||
87
build/libraries/fatfs/ARM7/rom_sdmc/sdmc_config.h
Normal file
87
build/libraries/fatfs/ARM7/rom_sdmc/sdmc_config.h
Normal file
@ -0,0 +1,87 @@
|
||||
/*
|
||||
** 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 <firm.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 ***/
|
||||
|
||||
#define SDCARD_TIMER_ID (OS_TIMER_3)
|
||||
|
||||
|
||||
/*********************************************
|
||||
タイムアウト設定値(ms単位)
|
||||
*********************************************/
|
||||
#define SDCARD_RW_TIMEOUT (2000)
|
||||
#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__*/
|
||||
637
build/libraries/fatfs/ARM7/rom_sdmc/sdmc_nandinit.c
Normal file
637
build/libraries/fatfs/ARM7/rom_sdmc/sdmc_nandinit.c
Normal file
@ -0,0 +1,637 @@
|
||||
/*
|
||||
Project: TwlBrom SD port driver
|
||||
File: Carddrv.c
|
||||
|
||||
2006, Research and Development Department, Nintendo.
|
||||
*/
|
||||
|
||||
#include "sdmc_config.h"
|
||||
#include "sdmc.h"
|
||||
#include "sdif_reg.h"
|
||||
#include "sdif_ip.h"
|
||||
#include <firm.h>
|
||||
//#include <twl/hw/ARM7/ioreg_MI.h>
|
||||
//#include "sdmc_config.h"
|
||||
//#include "sdif_reg.h" /* IP 対応レジスタ定義 */
|
||||
//#include <brom/rom_sdmc.h>
|
||||
//#include "sdif_ip.h" /* IP 対応フラグ定義 */
|
||||
|
||||
// #define PRINTDEBUG OS_TPrintf
|
||||
#define PRINTDEBUG( ...) ((void)0)
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
定数
|
||||
***********************************************************************/
|
||||
static BOOL sdmcGetErrStat( void);
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
static関数の宣言
|
||||
***********************************************************************/
|
||||
static void SDCARD_Backup_port1(void);
|
||||
static void SDCARD_Restore_port1(void);
|
||||
|
||||
static int MMCP_SetBusWidth( BOOL b4bit); /* ビット幅の選択(MMCplus, eMMC, moviNAND) */
|
||||
|
||||
static SDMC_ERR_CODE SDCARD_Layer_Init(void);
|
||||
static SDMC_ERR_CODE i_sdmcMPInit( void); /* カードドライバ初期化(マルチポート対応) */
|
||||
|
||||
/***********************************************************************
|
||||
外部参照変数
|
||||
***********************************************************************/
|
||||
extern void SDCARD_Timer_irq(void* arg); /* タイムアウト割り込みハンドラ */
|
||||
extern void SDCARD_TimerCheck( void);
|
||||
extern void SDCARD_TimerStart(u32 tim); /* タイムアウト計測スタート */
|
||||
extern void SDCARD_TimerStop(void); /* タイムアウト計測停止 */
|
||||
|
||||
|
||||
extern u16 SD_CID[8]; /* CID値保存用 */
|
||||
extern u16 SD_CSD[8]; /* CSD値保存用 */
|
||||
extern u16 SD_OCR[2]; /* OCR値保存用 */
|
||||
extern u16 SD_SCR[4]; /* SCR値保存用 */
|
||||
extern u16 SD_RCA; /* RCA値保存用 */
|
||||
|
||||
extern s16 SDCARD_MMCFlag; /* MMCカードフラグ */
|
||||
extern s16 SDCARD_SDHCFlag; /* SDHCカードフラグ */
|
||||
extern u16 SD_port_number; /* 現在ポート番号 */
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
グローバル
|
||||
***********************************************************************/
|
||||
static u16 SD_SDSTATUS[32]; /* SD_STATUSレジスタ保存用 */
|
||||
static u16 SDCARD_WP_FLAG0; /* カードライトプロテクトフラグ。0=なし、1=有り */
|
||||
static u16 SDCARD_WP_FLAG1; /* カードライトプロテクトフラグ。0=なし、1=有り */
|
||||
static u16 SDCARD_WP_PERMANENT; /* カードライトプロテクト永久フラグ。0=なし、1=有り */
|
||||
static u16 SDCARD_WP_TEMPORARY; /* カードライトプロテクト一時フラグ。0=なし、1=有り */
|
||||
|
||||
static u32 SDCARD_SectorSize; /* セクタサイズ デフォルト 512bytes */
|
||||
|
||||
static u16 SD_INFO1_VALUE; /* SD_INFO1レジスタ取得用変数 */
|
||||
static u16 SD_INFO1_MASK_VALUE; /* SD_INFO1割込みマスク用変数(0で許可, 1で禁止) */
|
||||
static u16 SD_INFO2_VALUE; /* SD_INFO2レジスタ取得用変数 */
|
||||
static u16 SD_INFO2_MASK_VALUE; /* SD_INFO2割り込みマスク用変数(0で許可, 1で禁止) */
|
||||
static u16 SD_INFO_ERROR_VALUE; /* SD_INFO2, SD_INFO1のエラービット確認用変数 */
|
||||
|
||||
|
||||
/*ポート状態保存*/
|
||||
static SDPortContext SDPort0Context;
|
||||
static SDPortContext SDPort1Context;
|
||||
//SDPortContext *SDPortCurrentContext = &SDPort0Context; /*TODO*/
|
||||
|
||||
|
||||
|
||||
extern volatile SDMC_ERR_CODE SDCARD_ErrStatus; /* エラーステータス */
|
||||
extern volatile u32 SDCARD_Status; /* カードステータス */
|
||||
|
||||
static s16 SDCARD_SDFlag; /* SDカードフラグ */
|
||||
|
||||
static volatile s16 SDCARD_OutFlag = 0; /* カード排出発生判定フラグ */
|
||||
static SdmcResultInfo *pSDCARD_info = NULL; /* 保存用実行結果構造体ポインタ */
|
||||
|
||||
|
||||
static SDMC_ERR_CODE i_sdmcSavePortContext( SDPortContext* buf_adr, u16 port_no);
|
||||
static SDMC_ERR_CODE i_sdmcLoadPortContext( SDPortContext* buf_adr, u16* port_no);
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: sdmcSavePortContext
|
||||
|
||||
Description: ポート0のレジスタや変数をユーザバッファに退避する
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
static SDMC_ERR_CODE i_sdmcSavePortContext( SDPortContext* buf_adr, u16 port_no)
|
||||
{
|
||||
if( buf_adr == NULL) {
|
||||
return( SDMC_ERR_PARAM);
|
||||
}
|
||||
switch( port_no) {
|
||||
case 0:
|
||||
MI_CpuCopy8( &SDPort0Context, buf_adr, sizeof(SDPortContext));
|
||||
buf_adr->port_no = 0;
|
||||
break;
|
||||
case 1:
|
||||
MI_CpuCopy8( &SDPort1Context, buf_adr, sizeof(SDPortContext));
|
||||
buf_adr->port_no = 1;
|
||||
break;
|
||||
default: return( SDMC_ERR_PARAM);
|
||||
}
|
||||
return( SDMC_NORMAL);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: sdmcLoadPortContext
|
||||
|
||||
Description: ポート0のレジスタや変数をユーザバッファから復帰する
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
static SDMC_ERR_CODE i_sdmcLoadPortContext( SDPortContext* buf_adr, u16* port_no)
|
||||
{
|
||||
if( buf_adr == NULL) {
|
||||
return( SDMC_ERR_PARAM);
|
||||
}
|
||||
switch( buf_adr->port_no) {
|
||||
case 0:
|
||||
MI_CpuCopy8( buf_adr, &SDPort0Context, sizeof(SDPortContext));
|
||||
*port_no = 0;
|
||||
break;
|
||||
case 1:
|
||||
MI_CpuCopy8( buf_adr, &SDPort1Context, sizeof(SDPortContext));
|
||||
*port_no = 1;
|
||||
break;
|
||||
default: return( SDMC_ERR_PARAM);
|
||||
}
|
||||
return( SDMC_NORMAL);
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: SDCARD_Backup_port1
|
||||
|
||||
Description: backup registers and variables of port1.
|
||||
ポート1のレジスタや変数をバックアップする
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
static void SDCARD_Backup_port1(void)
|
||||
{
|
||||
/* registers */
|
||||
SD_GetFPGA(SDPort1Context.SD_CLK_CTRL_VALUE,SD_CLK_CTRL);
|
||||
SD_GetFPGA(SDPort1Context.SD_OPTION_VALUE, SD_OPTION);
|
||||
|
||||
/* variables */
|
||||
SDPort1Context.SD_RCA = SD_RCA;
|
||||
SDPort1Context.ErrStatus = SDCARD_ErrStatus;
|
||||
SDPort1Context.Status = SDCARD_Status;
|
||||
SDPort1Context.MMCFlag = SDCARD_MMCFlag;
|
||||
SDPort1Context.SDHCFlag = SDCARD_SDHCFlag;
|
||||
SDPort1Context.SDFlag = SDCARD_SDFlag;
|
||||
|
||||
SDPort1Context.OutFlag = SDCARD_OutFlag;
|
||||
|
||||
/*media registers*/
|
||||
MI_CpuCopy8( SD_CID, SDPort1Context.SD_CID, 16);
|
||||
MI_CpuCopy8( SD_CSD, SDPort1Context.SD_CSD, 16);
|
||||
MI_CpuCopy8( SD_OCR, SDPort1Context.SD_OCR, 4);
|
||||
MI_CpuCopy8( SD_SCR, SDPort1Context.SD_SCR, 8);
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: SDCARD_Restore_port1
|
||||
|
||||
Description: restore registers and variables of port0.
|
||||
ポート1のレジスタや変数を復帰する。
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
static void SDCARD_Restore_port1(void)
|
||||
{
|
||||
/* registers */
|
||||
SD_SetFPGA( SD_CLK_CTRL, SDPort1Context.SD_CLK_CTRL_VALUE);
|
||||
SD_SetFPGA( SD_OPTION, SDPort1Context.SD_OPTION_VALUE);
|
||||
|
||||
/* variables */
|
||||
SD_RCA = SDPort1Context.SD_RCA;
|
||||
SDCARD_ErrStatus = SDPort1Context.ErrStatus;
|
||||
SDCARD_Status = SDPort1Context.Status;
|
||||
SDCARD_MMCFlag = SDPort1Context.MMCFlag;
|
||||
SDCARD_SDHCFlag = SDPort1Context.SDHCFlag;
|
||||
SDCARD_SDFlag = SDPort1Context.SDFlag;
|
||||
|
||||
SDCARD_OutFlag = SDPort1Context.OutFlag;
|
||||
pSDCARD_info = NULL;
|
||||
|
||||
/*media registers*/
|
||||
MI_CpuCopy8( SDPort1Context.SD_CID, SD_CID, 16);
|
||||
MI_CpuCopy8( SDPort1Context.SD_CSD, SD_CSD, 16);
|
||||
MI_CpuCopy8( SDPort1Context.SD_OCR, SD_OCR, 4);
|
||||
MI_CpuCopy8( SDPort1Context.SD_SCR, SD_SCR, 8);
|
||||
|
||||
/*recalc*/
|
||||
SDCARD_WP_PERMANENT = (u16)(SD_CSD[0] & (u16)(SDCARD_WP_PERMANENT_BIT));
|
||||
SDCARD_WP_TEMPORARY = (u16)(SD_CSD[0] & (u16)(SDCARD_WP_TEMPORARY_BIT));
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: sdmcNandInit
|
||||
|
||||
Description: Initialize SD interface and SD card.
|
||||
初期化
|
||||
|
||||
Arguments: dma_no : 使用するDMA番号
|
||||
func1 : カード挿入時コールバック関数
|
||||
func2 : カード排出時コールバック関数
|
||||
|
||||
Returns: 0 : success
|
||||
> 0 : error code
|
||||
*---------------------------------------------------------------------------*/
|
||||
SDMC_ERR_CODE sdmcNandInit( void)
|
||||
{
|
||||
/* SD初期化 */
|
||||
SDCARD_ErrStatus = sdmcReset();
|
||||
|
||||
if(!SDCARD_ErrStatus) {
|
||||
SDCARD_ErrStatus = i_sdmcMPInit();
|
||||
}
|
||||
|
||||
return SDCARD_ErrStatus;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: sdmcReset
|
||||
|
||||
Description: reset SD card.
|
||||
リセット
|
||||
|
||||
Arguments:
|
||||
|
||||
Returns: 0 : success
|
||||
> 0 : error code
|
||||
*---------------------------------------------------------------------------*/
|
||||
static SDMC_ERR_CODE sdmcReset( void)
|
||||
{
|
||||
OSIntrMode irq_core_flag;
|
||||
SDCARD_MMCFlag = FALSE; /* MMCカード判定フラグクリア */
|
||||
SDCARD_SDHCFlag = FALSE;
|
||||
SDCARD_SDFlag = FALSE; /* SDカード判定フラグクリア */
|
||||
|
||||
/*** カードステータスをクリア ***/
|
||||
SDCARD_ErrStatus = SDMC_NORMAL;
|
||||
SDCARD_Status = SDMC_NORMAL;
|
||||
|
||||
/*** カードCSD WPビットをクリア ***/
|
||||
SDCARD_WP_FLAG0 = 0;
|
||||
SDCARD_WP_FLAG1 = 0;
|
||||
SDCARD_WP_PERMANENT = 0;
|
||||
SDCARD_WP_TEMPORARY = 0;
|
||||
|
||||
irq_core_flag = OS_DisableInterrupts(); /* 割込み禁止 */
|
||||
|
||||
*SDIF_CNT_L = 0x0402; //ラッパーレジスタ
|
||||
*SDIF_CNT_L = 0x0000; //ラッパーレジスタ
|
||||
*SDIF_FDS_L = 0;
|
||||
*SDIF_FSC_L = 1;
|
||||
SD_Init(); /* SD Card I/F 初期化処理 */
|
||||
SD_AndFPGA( SD_OPTION, SD_CD_DETECT_TIME); /* CD 検出タイムをゼロクリア */
|
||||
|
||||
SD_port_number = SDCARD_PORT1; /*** 現在のポート番号をデフォルトに設定 ***/
|
||||
|
||||
// SDCARD_Backup_port1(); /* port1 backup */
|
||||
|
||||
OS_RestoreInterrupts( irq_core_flag); /* 割り込み設定を元に戻す */
|
||||
|
||||
return SDCARD_ErrStatus;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: SDCARD_Layer_Init
|
||||
|
||||
Description: initialize sequence for SD card.
|
||||
SDカード規定の初期化手順
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
static SDMC_ERR_CODE SDCARD_Layer_Init(void)
|
||||
{
|
||||
u32 ulCSize;
|
||||
u16 read_block_len_val, mult_val;
|
||||
|
||||
// u16 memory_exist, function_number;
|
||||
SDCARD_Status = SDMC_NORMAL; /* カードステータスをクリア */
|
||||
SDCARD_MMCFlag = FALSE; /* MMCカード判定フラグクリア */
|
||||
SDCARD_SDHCFlag = FALSE;
|
||||
SDCARD_SDFlag = FALSE; /* SDカード判定フラグクリア */
|
||||
|
||||
SD_SetFPGA(SD_CLK_CTRL,(SD_CLK_CTRL_128)); /* SDクロックの周波数 261KHz(初期化時は100~400khz) */
|
||||
SD_EnableClock(); /* SDカードのクロックをイネーブルにする */
|
||||
|
||||
/* SD I/F部ダミー80クロック(1mSec)転送待ち(タイマーで待ちを実装しても良い) */
|
||||
SVC_WaitByLoop( 17900); //179*4サイクル=716サイクル=10024ns=10us
|
||||
|
||||
SDCARD_ErrStatus = SDMC_NORMAL; /* エラーステータスをクリア */
|
||||
|
||||
SDCARD_TimerStop(); /* タイムアウト判定用タイマストップ */
|
||||
|
||||
#if TIMEOUT
|
||||
SDCARD_TimerStart(SDCARD_RESET_TIMEOUT); /* タイムアウト判定用タイマスタート */
|
||||
#endif
|
||||
|
||||
PRINTDEBUG( " CMD0(GO_IDLE_STATE)\n");
|
||||
SD_ClrErr((u16)(~SDMC_ERR_FPGA_TIMEOUT)); /* タイムアウト以外のエラーをクリア */
|
||||
SD_Command(SD_CMD_CMD | GO_IDLE_STATE); /* CMD0発行、レスポンス確認 */
|
||||
if(SDCARD_ErrStatus){ /* エラーステータスの確認(エラー有り?) */
|
||||
return SDCARD_ErrStatus;
|
||||
}
|
||||
|
||||
/*------- idle state -------*/
|
||||
SVC_WaitByLoop( 17900); //179*4サイクル=716サイクル=10024ns=10us
|
||||
|
||||
while(!(SDCARD_ErrStatus & SDMC_ERR_FPGA_TIMEOUT)){ /* タイムアウトになったら抜ける */
|
||||
/******************/
|
||||
SDCARD_TimerCheck();
|
||||
/******************/
|
||||
SD_ClrErr((u16)(~SDMC_ERR_FPGA_TIMEOUT));
|
||||
|
||||
SD_RCA = 0; /* RCA = 0をセット */
|
||||
|
||||
if(!SDCARD_MMCFlag){ /* MMCカードフラグが 0(OFF) か? */
|
||||
|
||||
if( SD_AppCommand() == SDMC_NORMAL) { /* CMD55 発行処理が正常か? */
|
||||
|
||||
SDCARD_MMCFlag = FALSE; /* MMCカードフラグクリア */
|
||||
if(!SD_AppOpCond()){ /* ACMD41発行処理が正常か?(OCR31bit = L の時 No Response) */
|
||||
|
||||
SDCARD_SDFlag = TRUE; /* SDカードフラグセット */
|
||||
break;
|
||||
}
|
||||
}else{ /* CMD55 が正常終了しない */
|
||||
if(SDCARD_ErrStatus == SDMC_ERR_TIMEOUT){ /* タイムアウト(==No Response)か? */
|
||||
SDCARD_MMCFlag = TRUE; /* MMCカードフラグセット */
|
||||
}else{
|
||||
// break; //コメントアウトしないとSDカードの初期化に失敗する
|
||||
}
|
||||
}
|
||||
}
|
||||
if(SDCARD_MMCFlag){ /* MMCカードフラグが 1(ON) のとき */
|
||||
SD_RCA = 1; /* RCA = 1をセット */
|
||||
if(!SD_SendOpCond()){ /* CMD1発行処理が正常か? */
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SDCARD_TimerStop(); /* タイムアウト判定用タイマストップ */
|
||||
if(SDCARD_ErrStatus){ /* エラーステータスの確認(エラー有り?)*/
|
||||
if(SDCARD_ErrStatus & SDMC_ERR_FPGA_TIMEOUT){ /* タイムアウトエラーかチェック */
|
||||
SD_ClrErr(SDMC_ERR_FPGA_TIMEOUT); /* タイムアウトエラーの設定クリア */
|
||||
SD_SetErr(SDMC_ERR_RESET); /* 初期化カードリセットコマンド時1.5秒タイムアウトエラーの設定 */
|
||||
}
|
||||
SDCARD_MMCFlag = FALSE; /* MMCカードフラグクリア */
|
||||
return SDCARD_ErrStatus;
|
||||
}
|
||||
|
||||
#if TIMEOUT
|
||||
SDCARD_TimerStart(SDCARD_INITIAL_TIMEOUT); /* タイムアウト判定用タイマスタート */
|
||||
#endif
|
||||
|
||||
SD_SendCID(); /* CMD2発行 レスポンス確認 */
|
||||
if(SDCARD_ErrStatus){ /* エラーステータスの確認(エラー有り?) */
|
||||
return SDCARD_ErrStatus;
|
||||
}
|
||||
|
||||
while(1){
|
||||
/******************/
|
||||
SDCARD_TimerCheck();
|
||||
/******************/
|
||||
SD_SendRelativeAddr(); /* CMD3発行 レスポンス確認 正常終了時 RCA<-ResのRCA */
|
||||
if(SDCARD_ErrStatus){ /* エラーステータスの確認(エラー有り?) */
|
||||
return SDCARD_ErrStatus;
|
||||
}
|
||||
if(SD_RCA != 0){
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*------- standby state -------*/
|
||||
SD_SendCSD(); /* CMD9発行 レスポンス確認 */
|
||||
if(SDCARD_ErrStatus){ /* エラーステータスの確認(エラー有り?) */
|
||||
return SDCARD_ErrStatus;
|
||||
}
|
||||
SDCARD_WP_PERMANENT = (u16)(SD_CSD[0] & (u16)(SDCARD_WP_PERMANENT_BIT));
|
||||
SDCARD_WP_TEMPORARY = (u16)(SD_CSD[0] & (u16)(SDCARD_WP_TEMPORARY_BIT));
|
||||
|
||||
/* 転送速度設定 */
|
||||
SD_ClockDivSet(SD_RSP5); /* SDカードの動作クロック設定 (CSD[5]) */
|
||||
if(SDCARD_ErrStatus){ /* エラーステータスの確認(エラー有り?) */
|
||||
return SDCARD_ErrStatus;
|
||||
}
|
||||
|
||||
/* Command toggles acard between the Stand-by and Transfer states */
|
||||
SD_SelectCard(); /* CMD7発行 レスポンス確認 */
|
||||
if(SDCARD_ErrStatus){ /* エラーステータスの確認(エラー有り?) */
|
||||
return SDCARD_ErrStatus;
|
||||
}
|
||||
|
||||
/*------- translate state -------*/
|
||||
|
||||
SDCARD_SectorSize = SECTOR_SIZE; /* セクタサイズ デフォルト 512bytes */
|
||||
SD_SetBlockLength(SDCARD_SectorSize); /* CMD16 ブロックサイズの設定 */
|
||||
if(SDCARD_ErrStatus){ /* エラーステータスの確認(エラー有り?) */
|
||||
return SDCARD_ErrStatus;
|
||||
}
|
||||
|
||||
SD_SCR[0] |= SCR_DAT_BUS_WIDTH_4BIT; //SCRの必要な部分のみ
|
||||
|
||||
SD_EnableClock(); /* SD-CLK Enable */
|
||||
|
||||
if(SDCARD_MMCFlag){ /* MMCカード ON かチェック */
|
||||
if( ((SD_CSD[7] & 0x3C)>>2) >= 4) {
|
||||
MMCP_SetBusWidth( TRUE);
|
||||
}
|
||||
// SD_SelectBitWidth(FALSE); /* CMD55->ACMD6 ビット幅の選択 1bit */
|
||||
}else{
|
||||
SD_SelectBitWidth(TRUE); /* CMD55->ACMD6 ビット幅の選択 4bit */
|
||||
}
|
||||
|
||||
SDCARD_TimerStop(); /* タイムアウト判定用タイマストップ */
|
||||
return SDCARD_ErrStatus;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: i_sdmcMPInit
|
||||
|
||||
Description: initialize SD card in multi ports.
|
||||
マルチポートのSDカード初期化
|
||||
|
||||
Arguments:
|
||||
|
||||
Returns: 0 : success
|
||||
> 0 : error code
|
||||
*---------------------------------------------------------------------------*/
|
||||
static SDMC_ERR_CODE i_sdmcMPInit( void)
|
||||
{
|
||||
u16 load_port_no;
|
||||
SDPortContext* SDNandContext;
|
||||
|
||||
//予約領域のポートコンテキスト参照
|
||||
SDNandContext = (SDPortContext*)&(((OSFromBromBuf*)OSi_GetFromBromAddr())->SDNandContext);
|
||||
|
||||
//NANDスロットの初期化
|
||||
SD_SetFPGA( SD_PORTSEL, SDMC_PORT_NAND); /* NANDポート選択 */
|
||||
|
||||
// OS_TPrintf( "SDNandContext : 0x%x\n", SDNandContext);
|
||||
//初期化済みでないときだけ初期化
|
||||
if( sdmcCheckPortContext( SDNandContext) != SDMC_NORMAL) {
|
||||
// OS_TPrintf( "sdmcCheckPortContext : ERR!\n");
|
||||
SDCARD_ErrStatus = SDCARD_Layer_Init();
|
||||
|
||||
SDCARD_Backup_port1();
|
||||
//ポートコンテキストの保存
|
||||
if( i_sdmcSavePortContext( SDNandContext, 1) != SDMC_NORMAL) {
|
||||
// OS_TPrintf( "i_sdmcSavePortContext failed\n");
|
||||
return( SDMC_ERR_PARAM);
|
||||
}
|
||||
}else{ //ポートコンテキストの復帰
|
||||
// OS_TPrintf( "sdmcCheckPortContext : NORMAL\n");
|
||||
|
||||
/*SDCARD_Layer_Init()の代わり*/
|
||||
SDCARD_SectorSize = SECTOR_SIZE; /* セクタサイズ デフォルト 512bytes */
|
||||
|
||||
if( i_sdmcLoadPortContext( SDNandContext, &load_port_no) != SDMC_NORMAL) {
|
||||
// OS_TPrintf( "i_sdmcLoadPortContext failed\n");
|
||||
return( SDMC_ERR_PARAM);
|
||||
}
|
||||
SDCARD_Restore_port1(); //TODO:load_port_no値判定
|
||||
}
|
||||
|
||||
SDCARD_OutFlag = FALSE; /* 排出フラグをリセット */
|
||||
|
||||
SDCARD_TimerStop(); /* タイムアウト判定用タイマストップ */
|
||||
SD_DisableClock(); /* SD-CLK Disable */
|
||||
SD_EnableInfo(); /* SD Card 挿抜 割り込み許可 */
|
||||
|
||||
return SDCARD_ErrStatus;
|
||||
}
|
||||
|
||||
#if 0
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: sdmcGetStatus
|
||||
|
||||
Description: get card status
|
||||
カードの状態を取得する
|
||||
bit15 SDカード判別ビット(検出したら1)
|
||||
bit14 MMCカード判別ビット(検出したら1)
|
||||
bit10 IO3 card detect(検出したら1) ※CTRではプルアップのため使えない
|
||||
bit9 IO3 card inserted(挿入動作で1) ※CTRではプルアップのため使えない
|
||||
bit8 IO3 card removed(脱動作で1) ※CTRではプルアップのため使えない
|
||||
bit7 write protect(書き込み禁止の場合1)
|
||||
bit5 card detect(検出したら1)
|
||||
bit4 card inserted(挿入動作で1)
|
||||
bit3 card removed(脱動作で1)
|
||||
bit2 R/W access all end
|
||||
bit0 Response end
|
||||
|
||||
Arguments: *status : カードの状態を格納する変数へのポインタ
|
||||
|
||||
Returns: 0 : success
|
||||
> 0 : error code
|
||||
*---------------------------------------------------------------------------*/
|
||||
/*-----------------------------------------------
|
||||
SD_INFO1レジスタ
|
||||
bit[10,9,8,7] = DAT3CD, DAT3IN, DAT3OUT, WP
|
||||
bit[5, 4, 3, 2] = CD, INS, REM, ALLEND
|
||||
bit0 = RESEND
|
||||
-------------------------------------------------
|
||||
EXT_CDレジスタ
|
||||
bit[2,1,0] = P1CD, P1INS, P1REM
|
||||
-------------------------------------------------
|
||||
EXT_CD_DAT3レジスタ
|
||||
bit[2, 1, 0] = P1DCD, P1DINS, P1DREM
|
||||
-------------------------------------------------
|
||||
EXT_WPレジスタ
|
||||
bit0 = P1WP
|
||||
-----------------------------------------------*/
|
||||
SDMC_ERR_CODE sdmcGetStatus(u16 *status)
|
||||
{
|
||||
u16 SD_INFO1_STATUS;
|
||||
|
||||
SD_INFO1_STATUS = SD_INFO1; /* SD_INFO1レジスタ読み出し */
|
||||
*status = SD_INFO1_STATUS; /* 論理反転 */
|
||||
|
||||
/*--- ポート0のとき ---*/
|
||||
if(SD_port_number == SDCARD_PORT0)
|
||||
{
|
||||
*status &= SDCARD_FLAG_CLR; /* SD/MMCフラグクリア */
|
||||
}
|
||||
/*--- ポート1のとき ---*/
|
||||
else if (SD_port_number == SDCARD_PORT1)
|
||||
{
|
||||
*status &= SDCARD_PORT1_CLR; /* port1に関係ない部分をクリア */
|
||||
SD_INFO1_STATUS = (u16)((EXT_CD & 0x0007) << 3);
|
||||
SD_INFO1_STATUS |= ((EXT_CD_DAT3 & 0x0007) << 8);
|
||||
SD_INFO1_STATUS |= ((EXT_WP & 0x0001) << 7);
|
||||
*status |= SD_INFO1_STATUS; /* カードport1フラグ設定 */
|
||||
}
|
||||
/*--- SD/MMCフラグをセット ---*/
|
||||
if( SDCARD_MMCFlag) { /* 検出したカードがMMCカードの時 */
|
||||
*status |= SDCARD_FLAG_MMC; /* カード判定部分MMCカード */
|
||||
}
|
||||
if( SDCARD_SDFlag) { /* 検出したカードがSDカードの時 */
|
||||
*status |= SDCARD_FLAG_SD; /* カード判定部分SDカード */
|
||||
}
|
||||
|
||||
return SDMC_NORMAL;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*******************************************************************************/
|
||||
static int MMCP_SetBusWidth( BOOL b4bit)
|
||||
{
|
||||
SD_EnableClock(); /* SD-CLK Enable */
|
||||
|
||||
/*コマンド6発行*/
|
||||
MMCP_WriteBusWidth( b4bit);
|
||||
SD_AndFPGA(SD_OPTION,(~SD_OPTION_WIDTH_1BIT)); /* IPにビット幅の設定(4bit幅) */
|
||||
|
||||
return( 0);
|
||||
}
|
||||
/*******************************************************************************/
|
||||
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: sdmcGetErrStat
|
||||
|
||||
Description: エラー取得
|
||||
|
||||
Arguments:
|
||||
|
||||
Returns: TRUE : success
|
||||
FALSE : error
|
||||
*---------------------------------------------------------------------------*/
|
||||
static BOOL sdmcGetErrStat( void)
|
||||
{
|
||||
PRINTDEBUG( "SD_INFO2:0x%x\n", SD_INFO2);
|
||||
|
||||
/*--- 取得 ---*/
|
||||
SD_GetFPGA( SD_INFO2_VALUE, SD_INFO2);
|
||||
/*------------------------------------------*/
|
||||
|
||||
/*--- SD_INFO2のエラーフラグ作成 ---*/
|
||||
SD_INFO_ERROR_VALUE = (u16)(SD_INFO2_VALUE & 0x807F);//
|
||||
/*--- エラーステータス作成 (RESTIMEOUTとILAエラーのフラグは反映しない) ---*/
|
||||
SDCARD_ErrStatus |= SD_INFO_ERROR_VALUE & (~(SD_INFO2_ERR_RESTIMEOUT)) &
|
||||
(~(SD_INFO2_ERR_ILA)) & SD_INFO2_MASK_ERRSET;
|
||||
|
||||
/*--- RESTIMEOUTとILAエラーはフラグの位置をずらして反映する ---*/
|
||||
if( SD_INFO_ERROR_VALUE & SD_INFO2_ERR_ILA) {
|
||||
SDCARD_ErrStatus |= SDMC_ERR_ILA; /* イリーガルアクセスエラー発生 */
|
||||
}
|
||||
if( SD_INFO_ERROR_VALUE & SD_INFO2_ERR_RESTIMEOUT) {
|
||||
SDCARD_ErrStatus |= SDMC_ERR_TIMEOUT; /* Response Time out エラー発生 */
|
||||
}/*------------------------------------------------------------*/
|
||||
|
||||
SD_AndFPGA( SD_INFO2,(~(SD_INFO2_ERROR_SET))); /* SD_INFO2のエラーフラグを全て落とす */
|
||||
|
||||
if( (SD_INFO_ERROR_VALUE) != 0) {
|
||||
return( FALSE);
|
||||
}else{
|
||||
return( TRUE);
|
||||
}
|
||||
}
|
||||
421
build/libraries/fatfs/ARM7/src/fatfs_firm.c
Normal file
421
build/libraries/fatfs/ARM7/src/fatfs_firm.c
Normal file
@ -0,0 +1,421 @@
|
||||
/*---------------------------------------------------------------------------*
|
||||
Project: TwlIPL - libraries - fatfs
|
||||
File: fatfs_firm.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.
|
||||
|
||||
$Date:: $
|
||||
$Rev$
|
||||
$Author$
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#include <symbols.h>
|
||||
|
||||
#include <firm/fatfs.h>
|
||||
#include <firm/sdmc.h>
|
||||
#include <firm/format/format_rom.h>
|
||||
#include <twl/aes.h>
|
||||
#include <twl/aes/ARM7/lo.h>
|
||||
#include <rtfs.h>
|
||||
|
||||
extern u32 NAND_FAT_PARTITION_COUNT;
|
||||
|
||||
#define DMA_PIPE 2
|
||||
#define DMA_RECV 3
|
||||
|
||||
/*
|
||||
専用DMA関数
|
||||
*/
|
||||
#define MIi_SRC_INC (MI_NDMA_SRC_INC | MI_NDMA_SRC_RELOAD_DISABLE)
|
||||
#define MIi_SRC_DEC (MI_NDMA_SRC_DEC | MI_NDMA_SRC_RELOAD_DISABLE)
|
||||
#define MIi_SRC_FIX (MI_NDMA_SRC_FIX | MI_NDMA_SRC_RELOAD_DISABLE)
|
||||
#define MIi_SRC_FILLDATA (MI_NDMA_SRC_FILLDATA | MI_NDMA_SRC_RELOAD_DISABLE)
|
||||
|
||||
#define MIi_DEST_INC (MI_NDMA_DEST_INC | MI_NDMA_DEST_RELOAD_DISABLE)
|
||||
#define MIi_DEST_DEC (MI_NDMA_DEST_DEC | MI_NDMA_DEST_RELOAD_DISABLE)
|
||||
#define MIi_DEST_FIX (MI_NDMA_DEST_FIX | MI_NDMA_DEST_RELOAD_DISABLE)
|
||||
#define MIi_DEST_INC_RELOAD (MI_NDMA_SRC_INC | MI_NDMA_DEST_RELOAD_ENABLE)
|
||||
|
||||
#define MIi_IMM (MI_NDMA_IMM_MODE_ON)
|
||||
|
||||
#define MIi_CONT (MI_NDMA_CONTINUOUS_ON)
|
||||
//---------------- register setting
|
||||
static inline void MIi_SetSrc( u32 ndmaNo, u32 src )
|
||||
{
|
||||
MI_NDMA_REG( ndmaNo, MI_NDMA_REG_SAD_WOFFSET ) = src;
|
||||
}
|
||||
static inline void MIi_SetDest( u32 ndmaNo, u32 dest )
|
||||
{
|
||||
MI_NDMA_REG( ndmaNo, MI_NDMA_REG_DAD_WOFFSET ) = dest;
|
||||
}
|
||||
static inline void MIi_SetTotalWordCount( u32 ndmaNo, u32 size )
|
||||
{
|
||||
MI_NDMA_REG( ndmaNo, MI_NDMA_REG_TCNT_WOFFSET ) = size;
|
||||
}
|
||||
static inline void MIi_SetWordCount( u32 ndmaNo, u32 size )
|
||||
{
|
||||
MI_NDMA_REG( ndmaNo, MI_NDMA_REG_WCNT_WOFFSET ) = size;
|
||||
}
|
||||
static inline void MIi_SetInterval( u32 ndmaNo, u32 intervalTimer, u32 prescaler )
|
||||
{
|
||||
#ifdef SDK_ARM7
|
||||
//---- In case of ARM7, intervalTimer==1 is nonsense
|
||||
SDK_ASSERT(intervalTimer != 1);
|
||||
#endif
|
||||
MI_NDMA_REG( ndmaNo, MI_NDMA_REG_BCNT_WOFFSET ) = intervalTimer | prescaler;
|
||||
}
|
||||
static inline void MIi_SetFillData( u32 ndmaNo, u32 data )
|
||||
{
|
||||
MI_NDMA_REG( ndmaNo, MI_NDMA_REG_FDATA_WOFFSET ) = data;
|
||||
}
|
||||
static inline void MIi_SetControl( u32 ndmaNo, u32 contData )
|
||||
{
|
||||
MI_NDMA_REG( ndmaNo, MI_NDMA_REG_CNT_WOFFSET ) = contData;
|
||||
}
|
||||
static inline void MIi_NDmaRecv(u32 ndmaNo, const void *src, void *dest, u32 size)
|
||||
{
|
||||
MIi_SetSrc( ndmaNo, (u32)src );
|
||||
MIi_SetDest( ndmaNo, (u32)dest );
|
||||
MIi_SetInterval( ndmaNo, MI_NDMA_NO_INTERVAL, MI_NDMA_INTERVAL_PS_1 );
|
||||
MIi_SetTotalWordCount( ndmaNo, size/4 );
|
||||
MIi_SetWordCount( ndmaNo, size/4 );
|
||||
MIi_SetControl( ndmaNo, MI_NDMA_BWORD_16 | MI_NDMA_SRC_FIX | MIi_DEST_INC | MIi_IMM | MI_NDMA_ENABLE );
|
||||
}
|
||||
|
||||
static inline void MIi_NDmaPipeSetup(u32 ndmaNo, const void *src, void *dest, u32 size)
|
||||
{
|
||||
MIi_SetSrc( ndmaNo, (u32)src );
|
||||
MIi_SetDest( ndmaNo, (u32)dest );
|
||||
MIi_SetInterval( ndmaNo, MI_NDMA_NO_INTERVAL, MI_NDMA_INTERVAL_PS_1 );
|
||||
MIi_SetTotalWordCount( ndmaNo, size/4 );
|
||||
MIi_SetWordCount( ndmaNo, size/4 );
|
||||
MIi_SetControl( ndmaNo, MI_NDMA_BWORD_16 | MI_NDMA_SRC_FIX | MIi_DEST_FIX | MIi_IMM );
|
||||
}
|
||||
|
||||
static inline void MIi_NDmaRestart(u32 ndmaNo)
|
||||
{
|
||||
MI_WaitNDma( ndmaNo );
|
||||
MI_NDMA_REG( ndmaNo, MI_NDMA_REG_CNT_WOFFSET ) |= MI_NDMA_ENABLE;
|
||||
}
|
||||
|
||||
/*
|
||||
専用NAND関数
|
||||
*/
|
||||
#define NAND_SECTOR_SIZE 512
|
||||
extern void SDCARD_TimerStart(u32 tim); /* タイムアウト計測スタート */
|
||||
extern volatile SDMC_ERR_CODE SDCARD_ErrStatus;
|
||||
|
||||
static inline void nandClearFifo( void )
|
||||
{
|
||||
*SDIF_CNT |= SDIF_CNT_FCLR;
|
||||
}
|
||||
|
||||
static inline void nandWaitFifoFull( void )
|
||||
{
|
||||
SDCARD_TimerStart(SDCARD_RW_TIMEOUT); /* タイムアウト判定用タイマスタート(2000msec) */
|
||||
while( (*SDIF_CNT & SDIF_CNT_FULL) == 0)
|
||||
{
|
||||
if ( SDCARD_ErrStatus != SDMC_NORMAL ) // an error was occurred
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void nandStartToRead(u32 block, u32 count)
|
||||
{
|
||||
SD_EnableClock();
|
||||
SD_EnableSeccnt(count);
|
||||
*SDIF_FSC = count;
|
||||
*SDIF_FDS = NAND_SECTOR_SIZE;
|
||||
*SDIF_CNT = (*SDIF_CNT & ~SDIF_CNT_FEIE) | SDIF_CNT_FFIE | SDIF_CNT_USEFIFO;
|
||||
CC_EXT_MODE = CC_EXT_MODE_DMA;
|
||||
nandClearFifo();
|
||||
|
||||
SDCARD_ErrStatus = SDMC_NORMAL;
|
||||
SDCARD_TimerStart(SDCARD_RW_TIMEOUT); /* タイムアウト判定用タイマスタート(2000msec) */
|
||||
SD_MultiReadBlock(block * NAND_SECTOR_SIZE);
|
||||
}
|
||||
|
||||
static void nandStopToRead( void )
|
||||
{
|
||||
if( !SD_CheckFPGAReg(SD_STOP,SD_STOP_SEC_ENABLE) ){
|
||||
SD_StopTransmission(); /* カード転送終了をFPGAに通知(CMD12発行) */
|
||||
}
|
||||
SD_TransEndFPGA(); /* 転送終了処理(割り込みマスクを禁止に戻す) */
|
||||
SD_DisableClock(); /* クロック供給停止 */
|
||||
|
||||
nandClearFifo();
|
||||
*SDIF_CNT &= ~SDIF_CNT_USEFIFO; /* FIFO使用フラグOFF */
|
||||
CC_EXT_MODE = CC_EXT_MODE_PIO; /* PIOモード(DMAモードOFF) */
|
||||
}
|
||||
|
||||
#define AES_GET_CNT_BITS(regValue, name) \
|
||||
((regValue) & (REG_AES_AES_CNT_##name##_MASK))
|
||||
|
||||
static BOOL useAES = FALSE;
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: FATFS_EnableAES
|
||||
|
||||
Description: enable AES data path
|
||||
|
||||
Arguments: slot aes key slot number
|
||||
counter initial counter value
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void FATFS_EnableAES( AESKeySlot slot, const AESCounter* pCounter )
|
||||
{
|
||||
useAES = TRUE;
|
||||
AESi_WaitKey();
|
||||
AESi_LoadKey( slot );
|
||||
AESi_SetCounter( pCounter );
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: FATFS_DisableAES
|
||||
|
||||
Description: bypass AES
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void FATFS_DisableAES( void )
|
||||
{
|
||||
useAES = FALSE;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: nandRead
|
||||
|
||||
Description: normal read
|
||||
|
||||
Arguments: block: source sector number in NAND
|
||||
dest: dest address (4 bytes alignment)
|
||||
count: sectors to transfer
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void nandRead(u32 block, void *dest, u16 count)
|
||||
{
|
||||
//MI_StopNDma( DMA_PIPE ); // already stopped
|
||||
//MI_StopNDma( DMA_RECV ); // already stopped
|
||||
|
||||
nandStartToRead( block, count );
|
||||
if ( SDCARD_ErrStatus != SDMC_NORMAL )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
while ( count-- )
|
||||
{
|
||||
nandWaitFifoFull();
|
||||
MIi_NDmaRecv( DMA_PIPE, (void*)SDIF_FI, dest, NAND_SECTOR_SIZE );
|
||||
MI_WaitNDma( DMA_PIPE );
|
||||
dest = (void*)((u32)dest + NAND_SECTOR_SIZE);
|
||||
}
|
||||
nandStopToRead();
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: nandReadAES
|
||||
|
||||
Description: AES read
|
||||
|
||||
Arguments: block: source sector number in NAND
|
||||
dest: dest address (4 bytes alignment)
|
||||
count: sectors to transfer
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
#define PIPE_SIZE 64
|
||||
void nandReadAES(u32 block, void *dest, u16 count)
|
||||
{
|
||||
u32 offset = 0; // in bytes
|
||||
|
||||
//MI_StopNDma( DMA_PIPE ); // already stopped
|
||||
//MI_StopNDma( DMA_RECV ); // already stopped
|
||||
|
||||
MIi_NDmaPipeSetup( DMA_PIPE, (void*)SDIF_FI, (void*)REG_AES_IFIFO_ADDR, PIPE_SIZE );
|
||||
|
||||
/*
|
||||
AESのセットアップ&出力DMA設定
|
||||
*/
|
||||
AESi_Reset();
|
||||
AESi_Reset();
|
||||
AESi_DmaRecv( DMA_RECV, dest, (u32)(count * NAND_SECTOR_SIZE), NULL, NULL );
|
||||
// AESi_SetCounter( &aesCounter ); // remain???
|
||||
// FATFSi_AddCounter( count * NAND_SECTOR_SIZE ); // update for next read
|
||||
AESi_Run( AES_MODE_CTR, 0, (u32)(count * NAND_SECTOR_SIZE / AES_BLOCK_SIZE), NULL, NULL );
|
||||
|
||||
nandStartToRead( block, count );
|
||||
if ( SDCARD_ErrStatus != SDMC_NORMAL )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
while ( block * NAND_SECTOR_SIZE > offset )
|
||||
{
|
||||
while ( AES_GET_CNT_BITS( reg_AES_AES_CNT, IFIFO_CNT ) )
|
||||
{
|
||||
}
|
||||
if ( (offset & NAND_SECTOR_SIZE) == 0 )
|
||||
{
|
||||
nandWaitFifoFull();
|
||||
}
|
||||
MIi_NDmaRestart( DMA_PIPE );
|
||||
offset += PIPE_SIZE;
|
||||
}
|
||||
MI_WaitNDma( DMA_PIPE );
|
||||
nandStopToRead();
|
||||
MI_WaitNDma( DMA_RECV );
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: nandRtfsIoFirm
|
||||
|
||||
Description: 上位層からのセクタリード/ライト要求を受ける
|
||||
|
||||
Arguments: driveno : ドライブ番号
|
||||
block : 開始ブロック番号
|
||||
buffer :
|
||||
count : ブロック数
|
||||
reading : リード要求時にTRUE
|
||||
|
||||
Returns: TRUE/FALSE
|
||||
*---------------------------------------------------------------------------*/
|
||||
static BOOL nandRtfsIoFirm( int driveno, u32 block, void* buffer, u16 count, BOOL reading)
|
||||
{
|
||||
u16 result;
|
||||
SdmcResultInfo SdResult;
|
||||
#pragma unused( driveno)
|
||||
|
||||
/**/
|
||||
sdmcSelect( (u16)SDMC_PORT_NAND);
|
||||
|
||||
if( reading) {
|
||||
if (useAES)
|
||||
{
|
||||
nandReadAES(block, buffer, count);
|
||||
}
|
||||
else
|
||||
{
|
||||
nandRead(block, buffer, count);
|
||||
}
|
||||
result = sdmcReadFifo( buffer, count, block, NULL, &SdResult);
|
||||
// result = sdmcRead( buffer, count, block, NULL, &SdResult);
|
||||
}else{
|
||||
result = sdmcWriteFifo( buffer, count, block, NULL, &SdResult);
|
||||
// result = sdmcWrite( buffer, count, block, NULL, &SdResult);
|
||||
}
|
||||
if( result) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: nandRtfsAttachFirm
|
||||
|
||||
Description: sdmcドライバをドライブに割り当てる
|
||||
|
||||
Arguments: driveno : ドライブ番号
|
||||
|
||||
Returns:
|
||||
*---------------------------------------------------------------------------*/
|
||||
#define nandRtfsCtrl FATFSi_nandRtfsCtrl
|
||||
extern int nandRtfsCtrl( int driveno, int opcode, void* pargs);
|
||||
static BOOL nandRtfsAttachFirm( int driveno, int partition_no)
|
||||
{
|
||||
BOOLEAN result;
|
||||
DDRIVE pdr;
|
||||
|
||||
if( partition_no >= NAND_FAT_PARTITION_COUNT) {
|
||||
return( FALSE);
|
||||
}
|
||||
|
||||
pdr.dev_table_drive_io = nandRtfsIoFirm;
|
||||
pdr.dev_table_perform_device_ioctl = nandRtfsCtrl;
|
||||
pdr.register_file_address = (dword) 0; /* Not used */
|
||||
pdr.interrupt_number = 0; /* Not used */
|
||||
pdr.drive_flags = (DRIVE_FLAGS_VALID | DRIVE_FLAGS_PARTITIONED);//DRIVE_FLAGS_FAILSAFE;
|
||||
pdr.partition_number = partition_no; /* Not used */
|
||||
pdr.pcmcia_slot_number = 0; /* Not used */
|
||||
pdr.controller_number = 0;
|
||||
pdr.logical_unit_number = 0;
|
||||
|
||||
switch( partition_no) {
|
||||
case 0:
|
||||
result = rtfs_attach( driveno, &pdr, "SD1p0"); //構造体がFSライブラリ側にコピーされる
|
||||
break;
|
||||
case 1:
|
||||
result = rtfs_attach( driveno, &pdr, "SD1p1"); //構造体がFSライブラリ側にコピーされる
|
||||
break;
|
||||
case 2:
|
||||
result = rtfs_attach( driveno, &pdr, "SD1p2"); //構造体がFSライブラリ側にコピーされる
|
||||
break;
|
||||
case 3:
|
||||
result = rtfs_attach( driveno, &pdr, "SD1p3"); //構造体がFSライブラリ側にコピーされる
|
||||
break;
|
||||
default:
|
||||
result = FALSE;
|
||||
break;
|
||||
}
|
||||
|
||||
return( result);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: FATFS_InitFIRM
|
||||
|
||||
Description: init file system
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
extern SDMC_ERR_CODE sdmcNandInit( void (*func1)(),void (*func2)());
|
||||
BOOL FATFS_InitFIRM( void )
|
||||
{
|
||||
/* RTFSライブラリを初期化 */
|
||||
if(!rtfs_init())
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* SDドライバ初期化 */
|
||||
// if (sdmcInit(SDMC_NOUSE_DMA, NULL, NULL) != SDMC_NORMAL) // firm_sdmc
|
||||
if (sdmcNandInit(NULL, NULL) != SDMC_NORMAL) // rom_sdmc
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: FATFS_MountNandFirm
|
||||
|
||||
Description: mount nand partition
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
BOOL FATFS_MountNandFirm( int driveno, int partition_no )
|
||||
{
|
||||
// CAUTION!: 同じ関数を2回呼び出す理由について要確認。
|
||||
if ( !nandRtfsAttachFirm(driveno, partition_no) || nandRtfsAttachFirm(driveno, partition_no))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
242
build/libraries/fatfs/ARM7/src/fatfs_loader.c
Normal file
242
build/libraries/fatfs/ARM7/src/fatfs_loader.c
Normal file
@ -0,0 +1,242 @@
|
||||
/*---------------------------------------------------------------------------*
|
||||
Project: TwlIPL - libraries - fatfs
|
||||
File: fatfs_loader.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.
|
||||
|
||||
$Date:: $
|
||||
$Rev$
|
||||
$Author$
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#include <symbols.h>
|
||||
|
||||
#include <firm/fatfs.h>
|
||||
#include <firm/sdmc.h>
|
||||
#include <firm/format/format_rom.h>
|
||||
#include <twl/aes.h>
|
||||
#include <twl/aes/ARM7/lo.h>
|
||||
#include <rtfs.h>
|
||||
|
||||
#define PXI_FIFO_TAG_DATA PXI_FIFO_TAG_USER_0
|
||||
|
||||
static ROM_Header* const rh= (ROM_Header*)(HW_MAIN_MEM_SYSTEM_END - 0x2000);
|
||||
static int menu_fd = 0;
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: FATFS_OpenRecentMenu
|
||||
|
||||
Description: open recent menu file
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
BOOL FATFS_OpenRecentMenu( int driveno )
|
||||
{
|
||||
char menufile[] = "A:\\ipl\\menu.srl";
|
||||
if (driveno < 0 || driveno >= 26)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
menufile[0] = (char)('A' + driveno);
|
||||
menu_fd = po_open((u8*)menufile, PO_BINARY, 0);
|
||||
if (menu_fd <= 0)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#define HEADER_SIZE 0x1000
|
||||
|
||||
#define SLOT_SIZE 0x2000
|
||||
|
||||
static BOOL FATFS_LoadBuffer(u32 offset, u32 size)
|
||||
{
|
||||
u8* base = (u8*)MI_GetWramMapStart_B();
|
||||
u8* curr = base;
|
||||
static int count = 0;
|
||||
|
||||
// seek first
|
||||
if (!po_lseek(menu_fd, (s32)offset, PSEEK_SET))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
// loading loop
|
||||
while (size > 0)
|
||||
{
|
||||
u8* dest = curr + count * SLOT_SIZE; // target buffer address
|
||||
u32 unit = size < SLOT_SIZE ? size : SLOT_SIZE; // size
|
||||
while (MI_GetWramBankMaster_B(count) != MI_WRAM_ARM7) // waiting to be master
|
||||
{
|
||||
}
|
||||
if (!po_read(menu_fd, (u8*)dest, (int)unit)) // reading
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
PXI_NotifyID( FIRM_PXI_ID_LOAD_PIRIOD );
|
||||
count = (count + 1) & 0x7;
|
||||
size -= unit;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: FATFS_LoadHeader
|
||||
|
||||
Description: load menu header
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: TRUE if success
|
||||
*---------------------------------------------------------------------------*/
|
||||
BOOL FATFS_LoadHeader( void )
|
||||
{
|
||||
// open the file in FATFS_InitFIRM()
|
||||
if (menu_fd <= 0)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// load header without AES
|
||||
PXI_NotifyID( FIRM_PXI_ID_LOAD_HEADER );
|
||||
FATFS_DisableAES();
|
||||
if (!FATFS_LoadBuffer(0, HEADER_SIZE) ||
|
||||
PXI_RecvID() != FIRM_PXI_ID_AUTH_HEADER )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// set id depends on game_code and seed to use (or all?)
|
||||
{
|
||||
AESKeySeed seed;
|
||||
AESi_InitGameKeys((u8*)rh->s.game_code);
|
||||
PXI_RecvDataByFifo( PXI_FIFO_TAG_DATA, &seed, AES_BLOCK_SIZE );
|
||||
AESi_SetKeySeedA(&seed); // APP
|
||||
//AESi_SetKeySeedB(&seed); // APP & HARD
|
||||
//AESi_SetKeySeedC(&seed); //
|
||||
//AESi_SetKeySeedD(&seed); // HARD
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void FATFSi_AddCounter(AESCounter* pCounter, u32 nums)
|
||||
{
|
||||
u32 data = 0;
|
||||
int i;
|
||||
for (i = 15; i >= 0; i--)
|
||||
{
|
||||
data += pCounter->bytes[i] + (nums & 0xFF);
|
||||
pCounter->bytes[i] = (u8)(data & 0xFF);
|
||||
data >>= 8;
|
||||
nums >>= 8;
|
||||
if ( !data && !nums )
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static AESCounter* FATFSi_GetCounter( u32 offset )
|
||||
{
|
||||
static AESCounter counter;
|
||||
MI_CpuCopy8(rh->s.main_static_digest, &counter, 12);
|
||||
counter.words[3] = 0;
|
||||
FATFSi_AddCounter(&counter, offset - SECURE_AREA_START);
|
||||
return &counter;
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: FATFS_LoadMenu
|
||||
|
||||
Description: load menu binary
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: TRUE if success
|
||||
*---------------------------------------------------------------------------*/
|
||||
BOOL FATFS_LoadMenu( void )
|
||||
{
|
||||
// load ARM9 static region without AES
|
||||
if ( rh->s.main_size > 0 )
|
||||
{
|
||||
PXI_NotifyID( FIRM_PXI_ID_LOAD_ARM9_STATIC );
|
||||
FATFS_DisableAES();
|
||||
if ( !FATFS_LoadBuffer( rh->s.main_rom_offset, rh->s.main_size ) ||
|
||||
PXI_RecvID() != FIRM_PXI_ID_AUTH_ARM9_STATIC )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
// load ARM7 static region without AES
|
||||
if ( rh->s.sub_size > 0 )
|
||||
{
|
||||
PXI_NotifyID( FIRM_PXI_ID_LOAD_ARM7_STATIC );
|
||||
FATFS_DisableAES();
|
||||
if ( !FATFS_LoadBuffer( rh->s.sub_rom_offset, rh->s.sub_size ) ||
|
||||
PXI_RecvID() != FIRM_PXI_ID_AUTH_ARM7_STATIC )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
// load ARM9 extended static region with AES
|
||||
if ( rh->s.main_ex_size > 0 )
|
||||
{
|
||||
PXI_NotifyID( FIRM_PXI_ID_LOAD_ARM9_STATIC_EX );
|
||||
if ( !rh->s.enable_aes || !rh->s.enable_signature )
|
||||
{
|
||||
FATFS_DisableAES();
|
||||
}
|
||||
else
|
||||
{
|
||||
FATFS_EnableAES( AES_KEY_SLOT_A, FATFSi_GetCounter( rh->s.main_ex_rom_offset ) );
|
||||
}
|
||||
if ( !FATFS_LoadBuffer( rh->s.main_ex_rom_offset, rh->s.main_ex_size ) ||
|
||||
PXI_RecvID() != FIRM_PXI_ID_AUTH_ARM9_STATIC_EX )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
// load ARM7 extended static region with AES
|
||||
if ( rh->s.sub_ex_size > 0 )
|
||||
{
|
||||
PXI_NotifyID( FIRM_PXI_ID_LOAD_ARM7_STATIC_EX );
|
||||
if ( !rh->s.enable_aes || !rh->s.enable_signature )
|
||||
{
|
||||
FATFS_DisableAES();
|
||||
}
|
||||
else
|
||||
{
|
||||
FATFS_EnableAES( AES_KEY_SLOT_A, FATFSi_GetCounter( rh->s.sub_ex_rom_offset ) );
|
||||
}
|
||||
if ( !FATFS_LoadBuffer( rh->s.sub_ex_rom_offset, rh->s.sub_ex_size ) ||
|
||||
PXI_RecvID() != FIRM_PXI_ID_AUTH_ARM7_STATIC_EX )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: FATFS_BootMenu
|
||||
|
||||
Description: boot menu
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void FATFS_BootMenu( void )
|
||||
{
|
||||
OSi_Boot( rh->s.sub_entry_address, (MIHeader_WramRegs*)rh->s.main_wram_config_data );
|
||||
}
|
||||
31
build/libraries/fatfs/Makefile
Normal file
31
build/libraries/fatfs/Makefile
Normal file
@ -0,0 +1,31 @@
|
||||
#! make -f
|
||||
#----------------------------------------------------------------------------
|
||||
# Project: TwlIPL - libraries - fatfs
|
||||
# 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.
|
||||
#
|
||||
# $Date:: $
|
||||
# $Rev:$
|
||||
# $Author:$
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
include $(TWLFIRM_ROOT)/build/buildtools/commondefs
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
SUBDIRS = ARM7
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
include $(TWLFIRM_ROOT)/build/buildtools/modulerules
|
||||
|
||||
|
||||
#===== End of Makefile =====
|
||||
@ -29,6 +29,7 @@ SRCDIR = .
|
||||
|
||||
SRCS = \
|
||||
mi_init_mainMemory.c \
|
||||
mi_loader.c \
|
||||
|
||||
TARGET_LIB = libmi$(FIRM_LIBSUFFIX).a
|
||||
|
||||
|
||||
@ -16,10 +16,58 @@
|
||||
*---------------------------------------------------------------------------*/
|
||||
#include <firm/os.h>
|
||||
#include <firm/mi.h>
|
||||
#include <firm/pxi.h>
|
||||
#ifdef SDK_ARM9
|
||||
#include <twl/os/ARM9/os_cache_tag.h>
|
||||
#else
|
||||
#include <twl/aes/ARM7/lo.h>
|
||||
#endif
|
||||
|
||||
void OSi_BootCore( OSEntryPoint p );
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: OSi_Boot
|
||||
|
||||
Description: boot firm
|
||||
|
||||
Arguments: entry : entry point
|
||||
w : wram settings
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void OSi_Boot( void* entry, MIHeader_WramRegs* w )
|
||||
{
|
||||
OSEntryPoint p = (OSEntryPoint)entry;
|
||||
|
||||
(void)OS_DisableInterrupts();
|
||||
OSi_Finalize();
|
||||
|
||||
#ifdef SDK_ARM9
|
||||
|
||||
MI_CpuCopy8( w, (void*)REG_MBK1_ADDR, 32 ); // set MBK1 - 8
|
||||
//reg_RBKCNT1_H_ADDR = w->sub_wramlock[4]; // set RBKCNT01
|
||||
|
||||
// request hiding secure rom
|
||||
PXI_NotifyID( FIRM_PXI_ID_DONE_WRAM_SETTING );
|
||||
|
||||
OSi_ClearWorkArea();
|
||||
|
||||
#else // SDK_ARM7
|
||||
|
||||
// wait request of hiding secure rom
|
||||
PXI_WaitID( FIRM_PXI_ID_DONE_WRAM_SETTING );
|
||||
|
||||
MI_CpuCopy8( &w->sub_wrammap_a, (void*)REG_MBK6_ADDR, 13 ); // set MBK6 - MBK_C_LOCK
|
||||
|
||||
AESi_SetKeySeedA( (AESKeySeed*)OSi_GetFromBromAddr()->aes_key[2] ); // erase
|
||||
|
||||
OSi_ClearWorkArea();
|
||||
|
||||
#endif // SDK_ARM7
|
||||
|
||||
OSi_BootCore( p );
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: OSi_Finalize
|
||||
|
||||
@ -55,3 +103,52 @@ void OSi_Finalize(void)
|
||||
#endif // SDK_ARM9
|
||||
}
|
||||
|
||||
extern void SDK_STATIC_DATA_START(void); // static data start address
|
||||
extern void SDK_STATIC_BSS_END(void); // static bss end address
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: OSi_ClearWorkArea
|
||||
|
||||
Description: clear work area
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
#include <nitro/code32.h>
|
||||
asm void OSi_ClearWorkArea( void )
|
||||
{
|
||||
mov r11, lr
|
||||
|
||||
// clear stack with r4-r9
|
||||
mov r0, #0
|
||||
ldr r1, =SDK_STATIC_DATA_START
|
||||
ldr r2, =SDK_STATIC_BSS_END
|
||||
sub r2, r2, r1
|
||||
bl MIi_CpuClearFast
|
||||
|
||||
bx r11
|
||||
}
|
||||
|
||||
asm void OSi_BootCore( OSEntryPoint p )
|
||||
{
|
||||
mov r11, r0
|
||||
|
||||
// clear stack with r4-r9
|
||||
mov r0, #0
|
||||
#if 0
|
||||
ldr r1, =HW_FIRM_STACK
|
||||
ldr r2, =HW_FIRM_STACK_SIZE
|
||||
#endif
|
||||
bl MIi_CpuClearFast
|
||||
|
||||
mov lr, r11
|
||||
|
||||
// clear registers
|
||||
#if 0
|
||||
ldr sp, =HW_FIRM_STACK
|
||||
#endif
|
||||
ldmia sp, {r0-r12,sp}
|
||||
|
||||
bx lr
|
||||
}
|
||||
|
||||
@ -40,14 +40,14 @@ void OS_InitFIRM(void)
|
||||
OS_InitPrintServer();
|
||||
#endif
|
||||
|
||||
//---- Init Arena (arenas except SUBPRIV-WRAM)
|
||||
OS_InitArena();
|
||||
|
||||
//---- Init interProcessor I/F
|
||||
// Sync with ARM7 to enable OS_GetConsoleType()
|
||||
// PXI_Init() must be called before OS_InitArenaEx()
|
||||
PXI_Init();
|
||||
|
||||
//---- Init Arena (arenas except SUBPRIV-WRAM)
|
||||
OS_InitArena();
|
||||
|
||||
//---- Init Spinlock
|
||||
OS_InitLock();
|
||||
|
||||
@ -103,12 +103,12 @@ void OS_InitFIRM(void)
|
||||
//----------------------------------------------------------------
|
||||
// for ARM7
|
||||
|
||||
//---- Init Arena (SUBPRIV-WRAM arena)
|
||||
OS_InitArena();
|
||||
|
||||
//---- Init interProcessor I/F
|
||||
PXI_Init();
|
||||
|
||||
//---- Init Arena (SUBPRIV-WRAM arena)
|
||||
OS_InitArena();
|
||||
|
||||
//---- Init Spinlock
|
||||
OS_InitLock();
|
||||
|
||||
|
||||
62
build/libraries/pm/ARM7/Makefile
Normal file
62
build/libraries/pm/ARM7/Makefile
Normal file
@ -0,0 +1,62 @@
|
||||
#! make -f
|
||||
#----------------------------------------------------------------------------
|
||||
# Project: TwlFirm - libraries - pm
|
||||
# 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.
|
||||
#
|
||||
# $Date:: $
|
||||
# $Rev:$
|
||||
# $Author:$
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
SUBDIRS =
|
||||
SUBMAKES =
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
# build ARM & THUMB libraries
|
||||
FIRM_CODEGEN_ALL ?= TRUE
|
||||
|
||||
# Codegen for sub processer
|
||||
FIRM_PROC = ARM7
|
||||
|
||||
INCDIR = $(TWLSDK_ROOT)/build/libraries/spi/ARM7/pm/include \
|
||||
|
||||
SRCDIR = .
|
||||
|
||||
SRCS = \
|
||||
pm_init.c \
|
||||
pm_pmic_ex.c \
|
||||
|
||||
TARGET_LIB = libpm_sp$(FIRM_LIBSUFFIX).a
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
# DEBUG版ビルドの場合、RELEASE版でビルドして
|
||||
# DEBUG版のライブラリを装います。
|
||||
|
||||
ifdef NITRO_DEBUG
|
||||
NITRO_BUILD_TYPE = RELEASE
|
||||
endif
|
||||
|
||||
include $(TWLFIRM_ROOT)/build/buildtools/commondefs
|
||||
|
||||
INSTALL_TARGETS = $(TARGETS)
|
||||
INSTALL_DIR = $(FIRM_INSTALL_LIBDIR)
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
do-build: $(TARGETS)
|
||||
|
||||
include $(TWLFIRM_ROOT)/build/buildtools/modulerules
|
||||
|
||||
#===== End of Makefile =====
|
||||
60
build/libraries/pm/ARM7/pm_init.c
Normal file
60
build/libraries/pm/ARM7/pm_init.c
Normal file
@ -0,0 +1,60 @@
|
||||
/*---------------------------------------------------------------------------*
|
||||
Project: TwlIPL - libraries - pm
|
||||
File: pm_init.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.
|
||||
|
||||
$Date:: $
|
||||
$Rev$
|
||||
$Author$
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#include <firm/pm.h>
|
||||
|
||||
#define OS_MSEC_TO_CPUCYC( msec ) ((u32)( ((HW_CPU_CLOCK/1000) * (u32)(msec)) ))
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: PM_InitFIRM
|
||||
|
||||
Description: power B/L on
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void PM_InitFIRM( void )
|
||||
{
|
||||
// LED
|
||||
PMi_ResetFlags( REG_PMIC_LED_CTL_ADDR, PMIC_LED_CTL_L12_AT_BLK | PMIC_LED_CTL_L12_BLK_BY_SLP );
|
||||
PMi_SetParams( REG_PMIC_LED12_B4_ADDR,
|
||||
PMIC_LED12_B4_L1_100 | PMIC_LED12_B4_L2_100,
|
||||
PMIC_LED12_B4_L1_MASK | PMIC_LED12_B4_L2_MASK
|
||||
);
|
||||
PMi_SetParams( REG_PMIC_LED12_B3_ADDR,
|
||||
PMIC_LED12_B3_L1_OFF | PMIC_LED12_B3_L2_100,
|
||||
PMIC_LED12_B3_L1_MASK | PMIC_LED12_B3_L2_MASK
|
||||
);
|
||||
PMi_SetParams( REG_PMIC_LED12_B2_ADDR,
|
||||
PMIC_LED12_B2_L1_100 | PMIC_LED12_B2_L2_OFF,
|
||||
PMIC_LED12_B2_L1_MASK | PMIC_LED12_B2_L2_MASK
|
||||
);
|
||||
PMi_SetParams( REG_PMIC_LED12_B1_ADDR,
|
||||
PMIC_LED12_B1_L1_OFF | PMIC_LED12_B1_L2_OFF,
|
||||
PMIC_LED12_B1_L1_MASK | PMIC_LED12_B1_L2_MASK
|
||||
);
|
||||
|
||||
// LCD ON
|
||||
PMi_SetFlags( REG_PMIC_CTL2_ADDR, PMIC_CTL2_LCD_PWR );
|
||||
|
||||
// back light ON
|
||||
PMi_SetParams( REG_PMIC_BL1_BRT_ADDR, PMIC_BL_BRT_MAX, PMIC_BL1_BRT_MASK );
|
||||
PMi_SetParams( REG_PMIC_BL2_BRT_ADDR, PMIC_BL_BRT_MAX, PMIC_BL2_BRT_MASK );
|
||||
OS_SpinWait( OS_MSEC_TO_CPUCYC( 17*2 ) );
|
||||
PMi_SetFlags( REG_PMIC_CTL2_ADDR, PMIC_CTL2_BKLT1 | PMIC_CTL2_BKLT2 );
|
||||
}
|
||||
72
build/libraries/pm/ARM7/pm_pmic_ex.c
Normal file
72
build/libraries/pm/ARM7/pm_pmic_ex.c
Normal file
@ -0,0 +1,72 @@
|
||||
/*---------------------------------------------------------------------------*
|
||||
Project: TwlIPL - libraries - pm
|
||||
File: pm_pmic_ex.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: $
|
||||
$NoKeywords: $
|
||||
*---------------------------------------------------------------------------*/
|
||||
#include <firm/pm.h>
|
||||
#include <pm_pmic.h>
|
||||
|
||||
//================================================================================
|
||||
// PMIC BIT CONTROL
|
||||
//================================================================================
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: PMi_SetParams
|
||||
|
||||
Description: set control bit to device register
|
||||
|
||||
Arguments: reg : device register
|
||||
setBits : bits to set
|
||||
maskBits : bits to mask
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void PMi_SetParams( u8 reg, u8 setBits, u8 maskBits )
|
||||
{
|
||||
u8 tmp;
|
||||
tmp = PMi_GetRegister( reg );
|
||||
tmp &= ~maskBits;
|
||||
setBits &= maskBits;
|
||||
tmp |= setBits;
|
||||
PMi_SetRegister( reg, tmp );
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: PMi_SetFlags
|
||||
|
||||
Description: set control bit to device register
|
||||
|
||||
Arguments: reg : device register
|
||||
setBits : bits to set
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void PMi_SetFlags( u8 reg, u8 setBits )
|
||||
{
|
||||
PMi_SetParams( reg, setBits, setBits );
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: PMi_ResetFlags
|
||||
|
||||
Description: clear control bit to device register
|
||||
|
||||
Arguments: reg : device register
|
||||
clrBits : bits to set
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void PMi_ResetFlags( u8 reg, u8 clrBits )
|
||||
{
|
||||
PMi_SetParams( reg, 0, clrBits );
|
||||
}
|
||||
|
||||
31
build/libraries/pm/Makefile
Normal file
31
build/libraries/pm/Makefile
Normal file
@ -0,0 +1,31 @@
|
||||
#! make -f
|
||||
#----------------------------------------------------------------------------
|
||||
# Project: TwlIPL - libraries - pm
|
||||
# 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.
|
||||
#
|
||||
# $Date:: $
|
||||
# $Rev:$
|
||||
# $Author:$
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
include $(TWLFIRM_ROOT)/build/buildtools/commondefs
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
SUBDIRS = ARM7
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
include $(TWLFIRM_ROOT)/build/buildtools/modulerules
|
||||
|
||||
|
||||
#===== End of Makefile =====
|
||||
61
build/libraries/pxi/ARM7/Makefile
Normal file
61
build/libraries/pxi/ARM7/Makefile
Normal file
@ -0,0 +1,61 @@
|
||||
#! make -f
|
||||
#----------------------------------------------------------------------------
|
||||
# Project: TwlFirm - libraries_sp - pxi
|
||||
# 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.
|
||||
#
|
||||
# $Date:: $
|
||||
# $Rev:$
|
||||
# $Author:$
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
SUBDIRS =
|
||||
#SUBMAKES = Makefile.CALLTRACE \
|
||||
# Makefile.FUNCTIONCOST
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
# build ARM & THUMB libraries
|
||||
FIRM_CODEGEN_ALL ?= TRUE
|
||||
|
||||
# Codegen for sub processer
|
||||
FIRM_PROC = ARM7
|
||||
|
||||
SRCDIR = ../common .
|
||||
|
||||
SRCS = \
|
||||
pxi_misc.c \
|
||||
|
||||
TARGET_LIB = libpxi_sp$(FIRM_LIBSUFFIX).a
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
# DEBUG版ビルドの場合、RELEASE版でビルドして
|
||||
# DEBUG版のライブラリを装います。
|
||||
|
||||
ifdef NITRO_DEBUG
|
||||
NITRO_BUILD_TYPE = RELEASE
|
||||
endif
|
||||
|
||||
include $(TWLFIRM_ROOT)/build/buildtools/commondefs
|
||||
|
||||
INSTALL_TARGETS = $(TARGETS)
|
||||
INSTALL_DIR = $(FIRM_INSTALL_LIBDIR)
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
do-build: $(TARGETS)
|
||||
|
||||
include $(TWLFIRM_ROOT)/build/buildtools/modulerules
|
||||
|
||||
|
||||
#===== End of Makefile =====
|
||||
58
build/libraries/pxi/ARM9/Makefile
Normal file
58
build/libraries/pxi/ARM9/Makefile
Normal file
@ -0,0 +1,58 @@
|
||||
#! make -f
|
||||
#----------------------------------------------------------------------------
|
||||
# Project: TwlFirm - libraries - pxi
|
||||
# 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.
|
||||
#
|
||||
# $Date:: $
|
||||
# $Rev:$
|
||||
# $Author:$
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
SUBDIRS =
|
||||
SUBMAKES =
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
# build ARM & THUMB libraries
|
||||
FIRM_CODEGEN_ALL ?= TRUE
|
||||
|
||||
SRCDIR = ../common .
|
||||
|
||||
SRCS = \
|
||||
pxi_misc.c \
|
||||
|
||||
TARGET_LIB = libpxi$(FIRM_LIBSUFFIX).a
|
||||
|
||||
include $(TWLFIRM_ROOT)/build/buildtools/commondefs
|
||||
|
||||
INSTALL_TARGETS = $(TARGETS)
|
||||
INSTALL_DIR = $(FIRM_INSTALL_LIBDIR)
|
||||
|
||||
ifdef NITRO_CALLTRACE
|
||||
CCFLAGS += -DOS_PROFILE_AVAILABLE -DOS_PROFILE_CALL_TRACE
|
||||
endif
|
||||
|
||||
ifdef NITRO_FUNCTIONCOST
|
||||
CCFLAGS += -DOS_PROFILE_AVAILABLE -DOS_PROFILE_FUNCTION_COST
|
||||
endif
|
||||
|
||||
ifdef NITRO_TCM_APPLY
|
||||
CCFLAGS += -DSDK_TCM_APPLY
|
||||
endif
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
do-build: $(TARGETS)
|
||||
|
||||
include $(TWLFIRM_ROOT)/build/buildtools/modulerules
|
||||
|
||||
#===== End of Makefile =====
|
||||
32
build/libraries/pxi/Makefile
Normal file
32
build/libraries/pxi/Makefile
Normal file
@ -0,0 +1,32 @@
|
||||
#! make -f
|
||||
#----------------------------------------------------------------------------
|
||||
# Project: TwlFirm - libraries - pxi
|
||||
# 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.
|
||||
#
|
||||
# $Date:: $
|
||||
# $Rev:$
|
||||
# $Author:$
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
include $(TWLFIRM_ROOT)/build/buildtools/commondefs
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
SUBDIRS = ARM9 \
|
||||
ARM7 \
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
include $(TWLFIRM_ROOT)/build/buildtools/modulerules
|
||||
|
||||
|
||||
#===== End of Makefile =====
|
||||
352
build/libraries/pxi/common/pxi_misc.c
Normal file
352
build/libraries/pxi/common/pxi_misc.c
Normal file
@ -0,0 +1,352 @@
|
||||
/*---------------------------------------------------------------------------*
|
||||
Project: TwlFirm - library - pxi
|
||||
File: pxi_misc.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: $
|
||||
$NoKeywords: $
|
||||
*---------------------------------------------------------------------------*/
|
||||
#include <firm/os.h>
|
||||
#include <twl/memorymap.h>
|
||||
#include <firm/pxi.h>
|
||||
|
||||
static u16 FifoCtrlInit = 0;
|
||||
|
||||
/*********** function prototypes ******************/
|
||||
static inline PXIFifoStatus PXIi_GetFromFifo(u32 *data_buf);
|
||||
static inline PXIFifoStatus PXIi_SetToFifo(u32 data);
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: PXI_InitFifoFIRM
|
||||
|
||||
Description: initialize FIFO system for firm
|
||||
|
||||
Arguments: None.
|
||||
|
||||
Returns: None.
|
||||
*---------------------------------------------------------------------------*/
|
||||
void PXI_InitFifoFIRM(void)
|
||||
{
|
||||
OSIntrMode enabled;
|
||||
|
||||
enabled = OS_DisableInterrupts();
|
||||
|
||||
if (!FifoCtrlInit)
|
||||
{
|
||||
FifoCtrlInit = TRUE;
|
||||
|
||||
reg_PXI_FIFO_CNT =
|
||||
(REG_PXI_FIFO_CNT_SEND_CL_MASK |
|
||||
REG_PXI_FIFO_CNT_E_MASK | REG_PXI_FIFO_CNT_ERR_MASK);
|
||||
|
||||
#ifdef SDK_ARM9
|
||||
PXI_SendIDByIntf( FIRM_PXI_ID_INIT_ARM9 );
|
||||
PXI_WaitIDByIntf( FIRM_PXI_ID_INIT_ARM7 );
|
||||
#else // SDK_ARM7
|
||||
PXI_SendIDByIntf( FIRM_PXI_ID_INIT_ARM7 );
|
||||
PXI_WaitIDByIntf( FIRM_PXI_ID_INIT_ARM9 );
|
||||
#endif // SDK_ARM7
|
||||
}
|
||||
(void)OS_RestoreInterrupts(enabled);
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: PXI_NotifyID
|
||||
|
||||
Description: Send 4bit id to other processor
|
||||
|
||||
Arguments: id notifying id
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void PXI_NotifyID( u32 id )
|
||||
{
|
||||
PXI_SendIDByFifo( PXI_FIFO_TAG_SYSTEM, id );
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: PXI_WaitID
|
||||
|
||||
Description: Wait 4bit id from the other processor
|
||||
|
||||
Arguments: id waiting id
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void PXI_WaitID( u32 id )
|
||||
{
|
||||
PXI_WaitIDByFifo( PXI_FIFO_TAG_SYSTEM, id );
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: PXI_RecvID
|
||||
|
||||
Description: Receive 4bit id from the other processor
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: id
|
||||
*---------------------------------------------------------------------------*/
|
||||
u8 PXI_RecvID( void )
|
||||
{
|
||||
u8 id;
|
||||
|
||||
while (PXI_RecvIDByFifo(PXI_FIFO_TAG_SYSTEM, &id) != PXI_FIFO_SUCCESS)
|
||||
{
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: PXI_SendIDByIntf
|
||||
|
||||
Description: Send 4bit id to the other processor
|
||||
|
||||
Arguments: id sending id
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void PXI_SendIDByIntf( u32 id )
|
||||
{
|
||||
reg_PXI_INTF = (u16)(id << REG_PXI_INTF_SEND_SHIFT);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: PXI_RecvIDByIntf
|
||||
|
||||
Description: Receive 4bit id from the other processor
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: received id
|
||||
*---------------------------------------------------------------------------*/
|
||||
u32 PXI_RecvIDByIntf( void )
|
||||
{
|
||||
return (u32)((reg_PXI_INTF & REG_PXI_INTF_RECV_MASK) >> REG_PXI_INTF_RECV_SHIFT);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: PXI_WaitIDByIntf
|
||||
|
||||
Description: Wait 4bit id from the other processor
|
||||
|
||||
Arguments: id waiting id
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void PXI_WaitIDByIntf( u32 id )
|
||||
{
|
||||
while (PXI_RecvIDByIntf() != id)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: PXI_SendIDByFifo
|
||||
|
||||
Description: Send 32bit-word to another CPU via FIFO
|
||||
|
||||
Arguments:
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void PXI_SendIDByFifo(PXIFifoTag tag, u32 id)
|
||||
{
|
||||
static PXIFifoMessage fifomsg;
|
||||
|
||||
fifomsg.e.tag = tag;
|
||||
fifomsg.e.data = id;
|
||||
|
||||
while ( PXIi_SetToFifo(fifomsg.raw) != PXI_FIFO_SUCCESS )
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: PXI_RecvIDByFifo
|
||||
|
||||
Description: Recv 32bit-word from another CPU via FIFO
|
||||
|
||||
Arguments:
|
||||
|
||||
Returns: if error occured, returns minus value
|
||||
*---------------------------------------------------------------------------*/
|
||||
PXIFifoStatus PXI_RecvIDByFifo(PXIFifoTag tag, void* buf)
|
||||
{
|
||||
static PXIFifoMessage fifomsg;
|
||||
u8* p = buf;
|
||||
|
||||
while ( PXIi_GetFromFifo(&fifomsg.raw) != PXI_FIFO_SUCCESS )
|
||||
{
|
||||
}
|
||||
|
||||
if (fifomsg.e.tag != tag)
|
||||
{
|
||||
return PXI_FIFO_FAIL_RECV_ERR;
|
||||
}
|
||||
|
||||
*p = (u8)fifomsg.e.data;
|
||||
|
||||
return PXI_FIFO_SUCCESS;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: PXI_WaitIDByFifo
|
||||
|
||||
Description: Wait 32bit-word from another CPU via FIFO
|
||||
|
||||
Arguments: id waiting id
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void PXI_WaitIDByFifo(PXIFifoTag tag, u32 id)
|
||||
{
|
||||
u8 buf = (u8)id;
|
||||
|
||||
do
|
||||
{
|
||||
while (PXI_RecvIDByFifo(tag, &buf) != PXI_FIFO_SUCCESS)
|
||||
{
|
||||
}
|
||||
}
|
||||
while ( buf != id );
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: PXI_SendDataByFifo
|
||||
|
||||
Description: Send data to another CPU via FIFO
|
||||
|
||||
Arguments:
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void PXI_SendDataByFifo(PXIFifoTag tag, void* buf, int size)
|
||||
{
|
||||
static PXIFifoMessage fifomsg;
|
||||
u32* p = buf;
|
||||
int len = size/4;
|
||||
int i;
|
||||
|
||||
fifomsg.e.tag = tag;
|
||||
fifomsg.e.data = len;
|
||||
|
||||
while ( PXIi_SetToFifo(fifomsg.raw) != PXI_FIFO_SUCCESS )
|
||||
{
|
||||
}
|
||||
|
||||
for ( i=0; i<len; i++ )
|
||||
{
|
||||
while ( PXIi_SetToFifo(p[i]) != PXI_FIFO_SUCCESS )
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: PXI_RecvDataByFifo
|
||||
|
||||
Description: Recv data to another CPU via FIFO
|
||||
|
||||
Arguments:
|
||||
|
||||
Returns: if error occured, returns minus value
|
||||
*---------------------------------------------------------------------------*/
|
||||
PXIFifoStatus PXI_RecvDataByFifo(PXIFifoTag tag, void* buf, int max_size )
|
||||
{
|
||||
static PXIFifoMessage fifomsg;
|
||||
u32* p = buf;
|
||||
u32 len;
|
||||
int i;
|
||||
|
||||
while ( PXIi_GetFromFifo(&fifomsg.raw) != PXI_FIFO_SUCCESS )
|
||||
{
|
||||
}
|
||||
|
||||
if (fifomsg.e.tag != tag)
|
||||
{
|
||||
return PXI_FIFO_FAIL_SEND_ERR;
|
||||
}
|
||||
|
||||
len = fifomsg.e.data;
|
||||
|
||||
if (len > max_size/4)
|
||||
{
|
||||
return PXI_FIFO_FAIL_SEND_ERR;
|
||||
}
|
||||
|
||||
for ( i=0; i<len; i++ )
|
||||
{
|
||||
while ( PXIi_GetFromFifo(&p[i]) != PXI_FIFO_SUCCESS )
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
return PXI_FIFO_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
//======================================================================
|
||||
// Write Send-FIFO reg.
|
||||
//======================================================================
|
||||
static inline PXIFifoStatus PXIi_SetToFifo(u32 data)
|
||||
{
|
||||
OSIntrMode enabled;
|
||||
|
||||
if (reg_PXI_FIFO_CNT & REG_PXI_FIFO_CNT_ERR_MASK)
|
||||
{
|
||||
reg_PXI_FIFO_CNT |= (REG_PXI_FIFO_CNT_E_MASK | REG_PXI_FIFO_CNT_ERR_MASK);
|
||||
return PXI_FIFO_FAIL_SEND_ERR;
|
||||
}
|
||||
|
||||
enabled = OS_DisableInterrupts();
|
||||
if (reg_PXI_FIFO_CNT & REG_PXI_FIFO_CNT_SEND_FULL_MASK)
|
||||
{
|
||||
(void)OS_RestoreInterrupts(enabled);
|
||||
return PXI_FIFO_FAIL_SEND_FULL;
|
||||
}
|
||||
|
||||
reg_PXI_SEND_FIFO = data;
|
||||
(void)OS_RestoreInterrupts(enabled);
|
||||
return PXI_FIFO_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
//======================================================================
|
||||
// Read Send-FIFO reg.
|
||||
//======================================================================
|
||||
static inline PXIFifoStatus PXIi_GetFromFifo(u32 *data_buf)
|
||||
{
|
||||
|
||||
OSIntrMode enabled;
|
||||
|
||||
if (reg_PXI_FIFO_CNT & REG_PXI_FIFO_CNT_ERR_MASK)
|
||||
{
|
||||
reg_PXI_FIFO_CNT |= (REG_PXI_FIFO_CNT_E_MASK | REG_PXI_FIFO_CNT_ERR_MASK);
|
||||
return PXI_FIFO_FAIL_RECV_ERR;
|
||||
}
|
||||
|
||||
enabled = OS_DisableInterrupts();
|
||||
if (reg_PXI_FIFO_CNT & REG_PXI_FIFO_CNT_RECV_EMP_MASK)
|
||||
{
|
||||
(void)OS_RestoreInterrupts(enabled);
|
||||
return PXI_FIFO_FAIL_RECV_EMPTY;
|
||||
}
|
||||
|
||||
*data_buf = reg_PXI_RECV_FIFO;
|
||||
(void)OS_RestoreInterrupts(enabled);
|
||||
|
||||
return PXI_FIFO_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@ -23,6 +23,7 @@ include $(TWLFIRM_ROOT)/build/buildtools/commondefs
|
||||
|
||||
SUBDIRS = \
|
||||
nandfirm-print \
|
||||
nandfirm-loader \
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
49
build/nandfirm/nandfirm-loader/ARM7/Makefile
Normal file
49
build/nandfirm/nandfirm-loader/ARM7/Makefile
Normal file
@ -0,0 +1,49 @@
|
||||
#! make -f
|
||||
#----------------------------------------------------------------------------
|
||||
# Project: TwlFirm - tools - nandfirm-loader
|
||||
# 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.
|
||||
#
|
||||
# $Date:: $
|
||||
# $Rev:$
|
||||
# $Author:$
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
FIRM_PROC = ARM7
|
||||
FIRM_TARGET = FIRM
|
||||
|
||||
SUBDIRS =
|
||||
|
||||
LINCLUDES = ../include
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
TARGET_BIN = twl_nandfirm7_loader.axf
|
||||
|
||||
SRCS = main.c
|
||||
|
||||
CRT0_O = crt0_firm.o
|
||||
|
||||
#SRCDIR = # using default
|
||||
#LCFILE = # using default
|
||||
|
||||
include $(TWLFIRM_ROOT)/build/buildtools/commondefs
|
||||
|
||||
LLIBRARIES = libaes_sp$(TWL_LIBSUFFIX).a
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
do-build: $(TARGETS)
|
||||
|
||||
|
||||
include $(TWLFIRM_ROOT)/build/buildtools/modulerules
|
||||
|
||||
|
||||
#===== End of Makefile =====
|
||||
75
build/nandfirm/nandfirm-loader/ARM7/main.c
Normal file
75
build/nandfirm/nandfirm-loader/ARM7/main.c
Normal file
@ -0,0 +1,75 @@
|
||||
/*---------------------------------------------------------------------------*
|
||||
Project: TwlFirm - nandfirm - nandrfirm-loader
|
||||
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.
|
||||
|
||||
$Date:: $
|
||||
$Rev$
|
||||
$Author$
|
||||
*---------------------------------------------------------------------------*/
|
||||
#include <firm.h>
|
||||
#include <firm/fatfs.h>
|
||||
#include <twl/os/ARM7/debugLED.h>
|
||||
|
||||
#define FIRM_ENABLE_JTAG
|
||||
|
||||
#define DRIVE_LETTER 'A' // マウント先ドライブ名
|
||||
#define DRIVE_NO (DRIVE_LETTER - 'A') // マウント先ドライブ番号
|
||||
#define PARTITION_NO 0 // 対象パーティション
|
||||
|
||||
void TwlSpMain( void )
|
||||
{
|
||||
OS_TPrintf( "\nNAND Boot time is %d msec.\n", OS_TicksToMilliSecondsBROM32(OS_GetTick()));
|
||||
|
||||
// for normal program
|
||||
// MIi_CpuClearFast( 0, (void*)OSi_GetFromBromAddr(), sizeof(OSFromBromBuf) );
|
||||
|
||||
// required here?
|
||||
// reg_GX_VRAMCNT_C = REG_GX_VRAMCNT_C_FIELD( TRUE, 0, 0x2);
|
||||
|
||||
OS_InitFIRM();
|
||||
|
||||
OS_InitDebugLED();
|
||||
OS_SetDebugLED(0x01);
|
||||
|
||||
#ifdef FIRM_ENABLE_JTAG
|
||||
reg_SCFG_JTAG = REG_SCFG_JTAG_CPUJE_MASK | REG_SCFG_JTAG_ARM7SEL_MASK;
|
||||
#endif // FIRM_ENABLE_JTAG
|
||||
|
||||
PM_InitFIRM();
|
||||
|
||||
OS_SetDebugLED(0x02);
|
||||
|
||||
// load menu
|
||||
if ( FATFS_InitFIRM() && // ARM7側のみ&NANDのみ
|
||||
FATFS_MountNandFirm(DRIVE_NO, PARTITION_NO) && // NAND[0]をX:ドライブにマウント
|
||||
FATFS_OpenRecentMenu(DRIVE_NO) ) // 目的のファイルをオープンしてしまう
|
||||
{
|
||||
|
||||
OS_SetDebugLED(0x04);
|
||||
|
||||
if ( FATFS_LoadHeader() && FATFS_LoadMenu() )
|
||||
{
|
||||
|
||||
OS_SetDebugLED(0x08);
|
||||
|
||||
FATFS_BootMenu();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
PXI_NotifyID( FIRM_PXI_ID_NULL );
|
||||
}
|
||||
|
||||
OS_SetDebugLED(0xF0);
|
||||
|
||||
OS_Terminate();
|
||||
}
|
||||
|
||||
48
build/nandfirm/nandfirm-loader/ARM9/Makefile
Normal file
48
build/nandfirm/nandfirm-loader/ARM9/Makefile
Normal file
@ -0,0 +1,48 @@
|
||||
#! make -f
|
||||
#----------------------------------------------------------------------------
|
||||
# Project: TwlFirm - tools - nandfirm-loader
|
||||
# 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.
|
||||
#
|
||||
# $Date:: $
|
||||
# $Rev:$
|
||||
# $Author:$
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
FIRM_TARGET = FIRM
|
||||
|
||||
SUBDIRS =
|
||||
|
||||
LINCLUDES = ../include
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
TARGET_BIN = twl_nandfirm9_loader.axf
|
||||
|
||||
SRCS = main.c
|
||||
|
||||
CRT0_O = crt0_firm.o
|
||||
|
||||
#SRCDIR = # using default
|
||||
#LCFILE = # using default
|
||||
|
||||
|
||||
include $(TWLFIRM_ROOT)/build/buildtools/commondefs
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
do-build: $(TARGETS)
|
||||
|
||||
|
||||
include $(TWLFIRM_ROOT)/build/buildtools/modulerules
|
||||
|
||||
|
||||
#===== End of Makefile =====
|
||||
41
build/nandfirm/nandfirm-loader/ARM9/main.c
Normal file
41
build/nandfirm/nandfirm-loader/ARM9/main.c
Normal file
@ -0,0 +1,41 @@
|
||||
/*---------------------------------------------------------------------------*
|
||||
Project: TwlFirm - nandfirm - nandrfirm-loader
|
||||
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.
|
||||
|
||||
$Date:: $
|
||||
$Rev$
|
||||
$Author$
|
||||
*---------------------------------------------------------------------------*/
|
||||
#include <firm.h>
|
||||
#include <firm/mi.h>
|
||||
|
||||
u8 acHeap[4*1024] __attribute__ ((aligned (32)));
|
||||
int acPool[3];
|
||||
int errID;
|
||||
|
||||
void TwlMain( void )
|
||||
{
|
||||
OS_TPrintf( "\nNAND Boot time is %d msec.\n", OS_TicksToMilliSecondsBROM32(OS_GetTick()));
|
||||
|
||||
OS_InitFIRM();
|
||||
|
||||
SVC_InitSignHeap( acPool, acHeap, sizeof(acHeap) );
|
||||
|
||||
// load menu
|
||||
if ( MI_LoadHeader( acPool ) && MI_LoadMenu() )
|
||||
{
|
||||
MI_BootMenu();
|
||||
}
|
||||
|
||||
OS_Terminate();
|
||||
|
||||
}
|
||||
|
||||
54
build/nandfirm/nandfirm-loader/Makefile
Normal file
54
build/nandfirm/nandfirm-loader/Makefile
Normal file
@ -0,0 +1,54 @@
|
||||
#! make -f
|
||||
#----------------------------------------------------------------------------
|
||||
# Project: TwlFirm - 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.
|
||||
#
|
||||
# $Date:: $
|
||||
# $Rev:$
|
||||
# $Author:$
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
|
||||
FIRM_TARGET = FIRM
|
||||
|
||||
|
||||
include $(TWLFIRM_ROOT)/build/buildtools/commondefs
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
SUBDIRS = \
|
||||
ARM7 \
|
||||
ARM9 \
|
||||
wram_regs \
|
||||
|
||||
TARGET_FIRM_BIN = nandfirm_loader.nand
|
||||
BINDIR = .
|
||||
MAKEFIRM_ARM9 = ARM9/bin/ARM9-$(FIRM_PLATFORM)$(CODEGEN_ARCH)/$(FIRM_BUILD_DIR)/twl_nandfirm9_loader.axf
|
||||
MAKEFIRM_ARM7 = ARM7/bin/ARM7-$(FIRM_PLATFORM)$(CODEGEN_ARCH)/$(FIRM_BUILD_DIR)/twl_nandfirm7_loader.axf
|
||||
MAKEFIRM_RSA_PRVKEY = $(TWL_KEYSDIR)/rsa/private_nand.der
|
||||
LDEPENDS_BIN += wram_regs/wram_regs.rbin
|
||||
|
||||
NITRO_MAKEROM = TRUE
|
||||
MAKEFIRM_FLAGS += -p
|
||||
FIRM_SPEC = nandfirm.nandsf
|
||||
|
||||
LDIRT_CLEAN += $(BINDIR)/$(TARGET_BIN) \
|
||||
rsa_public.sbin \
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
do-build: $(TARGET_BIN)
|
||||
|
||||
include $(TWLFIRM_ROOT)/build/buildtools/modulerules
|
||||
|
||||
|
||||
#===== End of Makefile =====
|
||||
24
build/nandfirm/nandfirm-loader/nandfirm.nandsf
Normal file
24
build/nandfirm/nandfirm-loader/nandfirm.nandsf
Normal file
@ -0,0 +1,24 @@
|
||||
#NANDSF --- Nandfirm Spec File
|
||||
|
||||
VERSION : GENERATE
|
||||
|
||||
RSA_KEY : $(MAKEFIRM_RSA_PRVKEY)
|
||||
OUT_KEY : rsa_public.sbin
|
||||
|
||||
WRAM_RBIN: ./wram_regs/wram_regs.rbin
|
||||
|
||||
MIRROR_OFS: 0x80000
|
||||
|
||||
DECOMP_PROC : ARM9 # ARM9 or ARM7
|
||||
|
||||
ARM9_COMP : FALSE # TRUE or FALSE, should be before ARM9_SBIN
|
||||
ARM9_SBIN : $(MAKEFIRM_ARM9).FLX.TWL.sbin
|
||||
ARM9_ELF : $(MAKEFIRM_ARM9).axf
|
||||
|
||||
ARM7_COMP : FALSE # TRUE or FALSE, should be before ARM7_SBIN
|
||||
ARM7_SBIN : $(MAKEFIRM_ARM7).FLX.TWL.sbin
|
||||
ARM7_ELF : $(MAKEFIRM_ARM7).axf
|
||||
|
||||
ARM9_X2 : TRUE # TRUE or FALSE
|
||||
|
||||
NCD_ROMOFS : 0x07fe00
|
||||
48
build/nandfirm/nandfirm-loader/wram_regs/Makefile
Normal file
48
build/nandfirm/nandfirm-loader/wram_regs/Makefile
Normal file
@ -0,0 +1,48 @@
|
||||
#! make -f
|
||||
#----------------------------------------------------------------------------
|
||||
# Project: TwlFirm - tools - norfirm-print
|
||||
# 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.
|
||||
#
|
||||
# $Date:: $
|
||||
# $Rev:$
|
||||
# $Author:$
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
SUBDIRS =
|
||||
|
||||
LINCLUDES = ../include
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
TARGET_BIN = wram_regs.rbin
|
||||
|
||||
SRCS = \
|
||||
wram_regs.c \
|
||||
|
||||
#SRCDIR = # using default
|
||||
#LCFILE = # using default
|
||||
|
||||
|
||||
include $(TWLFIRM_ROOT)/build/buildtools/commondefs
|
||||
|
||||
INSTALL_DIR = .
|
||||
INSTALL_TARGETS = $(BINDIR)/$(TARGET_BIN)
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
do-build: $(TARGETS)
|
||||
|
||||
|
||||
include $(TWLFIRM_ROOT)/build/buildtools/modulerules
|
||||
|
||||
|
||||
#===== End of Makefile =====
|
||||
91
build/nandfirm/nandfirm-loader/wram_regs/wram_regs.c
Normal file
91
build/nandfirm/nandfirm-loader/wram_regs/wram_regs.c
Normal file
@ -0,0 +1,91 @@
|
||||
/*---------------------------------------------------------------------------*
|
||||
Project: TwlFirm - tools - nandfirm
|
||||
File: wram_regs.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.
|
||||
|
||||
$Date:: $
|
||||
$Rev$
|
||||
$Author$
|
||||
*---------------------------------------------------------------------------*/
|
||||
#include <twl/mi.h>
|
||||
#include <firm/format/wram_regs.h>
|
||||
|
||||
MIHeader_WramRegs wram_regs_init =
|
||||
{
|
||||
// ARM9
|
||||
{
|
||||
REG_MI_MBK_A0_FIELD( 1, MI_WRAM_A_OFFSET_0KB , MI_WRAM_ARM7 ),
|
||||
REG_MI_MBK_A1_FIELD( 1, MI_WRAM_A_OFFSET_64KB , MI_WRAM_ARM7 ),
|
||||
REG_MI_MBK_A2_FIELD( 1, MI_WRAM_A_OFFSET_128KB, MI_WRAM_ARM7 ),
|
||||
REG_MI_MBK_A3_FIELD( 1, MI_WRAM_A_OFFSET_192KB, MI_WRAM_ARM7 ),
|
||||
},
|
||||
{
|
||||
REG_MI_MBK_B0_FIELD( 1, MI_WRAM_BC_OFFSET_0KB , MI_WRAM_ARM7 ),
|
||||
REG_MI_MBK_B1_FIELD( 1, MI_WRAM_BC_OFFSET_32KB , MI_WRAM_ARM7 ),
|
||||
REG_MI_MBK_B2_FIELD( 1, MI_WRAM_BC_OFFSET_64KB , MI_WRAM_ARM7 ),
|
||||
REG_MI_MBK_B3_FIELD( 1, MI_WRAM_BC_OFFSET_96KB , MI_WRAM_ARM7 ),
|
||||
REG_MI_MBK_B4_FIELD( 1, MI_WRAM_BC_OFFSET_128KB, MI_WRAM_ARM7 ),
|
||||
REG_MI_MBK_B5_FIELD( 1, MI_WRAM_BC_OFFSET_160KB, MI_WRAM_ARM7 ),
|
||||
REG_MI_MBK_B6_FIELD( 1, MI_WRAM_BC_OFFSET_192KB, MI_WRAM_ARM7 ),
|
||||
REG_MI_MBK_B7_FIELD( 1, MI_WRAM_BC_OFFSET_224KB, MI_WRAM_ARM7 ),
|
||||
},
|
||||
{
|
||||
REG_MI_MBK_C0_FIELD( 1, MI_WRAM_BC_OFFSET_0KB , MI_WRAM_ARM9 ),
|
||||
REG_MI_MBK_C1_FIELD( 1, MI_WRAM_BC_OFFSET_32KB , MI_WRAM_ARM9 ),
|
||||
REG_MI_MBK_C2_FIELD( 1, MI_WRAM_BC_OFFSET_64KB , MI_WRAM_ARM9 ),
|
||||
REG_MI_MBK_C3_FIELD( 1, MI_WRAM_BC_OFFSET_96KB , MI_WRAM_ARM9 ),
|
||||
REG_MI_MBK_C4_FIELD( 1, MI_WRAM_BC_OFFSET_128KB, MI_WRAM_ARM9 ),
|
||||
REG_MI_MBK_C5_FIELD( 1, MI_WRAM_BC_OFFSET_160KB, MI_WRAM_ARM9 ),
|
||||
REG_MI_MBK_C6_FIELD( 1, MI_WRAM_BC_OFFSET_192KB, MI_WRAM_ARM9 ),
|
||||
REG_MI_MBK_C7_FIELD( 1, MI_WRAM_BC_OFFSET_224KB, MI_WRAM_ARM9 ),
|
||||
},
|
||||
REG_MI_MBK6_FIELD( REG_WRAM_MAP_CONV_ADDR( 6, A, EADDR, MI_WRAM_MAP_NULL ),
|
||||
MI_WRAM_IMAGE_128KB,
|
||||
REG_WRAM_MAP_CONV_ADDR( 6, A, SADDR, MI_WRAM_MAP_NULL )
|
||||
),
|
||||
REG_MI_MBK7_FIELD( REG_WRAM_MAP_CONV_ADDR( 7, B, EADDR, HW_WRAM_AREA_HALF + 0x00080000 ),
|
||||
MI_WRAM_IMAGE_128KB,
|
||||
REG_WRAM_MAP_CONV_ADDR( 7, B, SADDR, HW_WRAM_AREA_HALF + 0x00040000 )
|
||||
),
|
||||
REG_MI_MBK8_FIELD( REG_WRAM_MAP_CONV_ADDR( 8, C, EADDR, HW_WRAM_AREA_HALF + 0x00040000 ),
|
||||
MI_WRAM_IMAGE_128KB,
|
||||
REG_WRAM_MAP_CONV_ADDR( 8, C, SADDR, HW_WRAM_AREA_HALF )
|
||||
),
|
||||
|
||||
// ARM7
|
||||
REG_MI_MBK6_FIELD( REG_WRAM_MAP_CONV_ADDR( 6, A, EADDR, HW_WRAM_AREA_HALF + 0x00040000 ),
|
||||
MI_WRAM_IMAGE_128KB,
|
||||
REG_WRAM_MAP_CONV_ADDR( 6, A, SADDR, HW_WRAM_AREA_HALF )
|
||||
),
|
||||
REG_MI_MBK7_FIELD( REG_WRAM_MAP_CONV_ADDR( 7, B, EADDR, HW_WRAM_AREA_HALF + 0x00080000 ),
|
||||
MI_WRAM_IMAGE_128KB,
|
||||
REG_WRAM_MAP_CONV_ADDR( 7, B, SADDR, HW_WRAM_AREA_HALF + 0x00040000 )
|
||||
),
|
||||
REG_MI_MBK8_FIELD( REG_WRAM_MAP_CONV_ADDR( 8, C, EADDR, MI_WRAM_MAP_NULL ),
|
||||
MI_WRAM_IMAGE_128KB,
|
||||
REG_WRAM_MAP_CONV_ADDR( 8, C, SADDR, MI_WRAM_MAP_NULL )
|
||||
),
|
||||
|
||||
// WRAM Lock
|
||||
{
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
},
|
||||
|
||||
// WRAM-0/1
|
||||
3,
|
||||
|
||||
// VRAM-C
|
||||
7,
|
||||
// VRAM-D
|
||||
7,
|
||||
};
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
|
||||
FIRM_TARGET = NORFIRM
|
||||
FIRM_TARGET = FIRM
|
||||
|
||||
|
||||
include $(TWLFIRM_ROOT)/build/buildtools/commondefs
|
||||
|
||||
@ -12,11 +12,11 @@ WRAM_RBIN: ./wram_regs/wram_regs.rbin
|
||||
DECOMP_PROC : ARM9 # ARM9 or ARM7
|
||||
|
||||
ARM9_COMP : TRUE # TRUE or FALSE, should be before ARM9_SBIN
|
||||
ARM9_SBIN : $(MAKEFIRM_ARM9).sbin
|
||||
ARM9_SBIN : $(MAKEFIRM_ARM9).FLX.TWL.sbin
|
||||
ARM9_ELF : $(MAKEFIRM_ARM9).axf
|
||||
|
||||
ARM7_COMP : TRUE # TRUE or FALSE, should be before ARM7_SBIN
|
||||
ARM7_SBIN : $(MAKEFIRM_ARM7).sbin
|
||||
ARM7_SBIN : $(MAKEFIRM_ARM7).FLX.TWL.sbin
|
||||
ARM7_ELF : $(MAKEFIRM_ARM7).axf
|
||||
|
||||
NCD_ROMOFS : 0x07fe00
|
||||
|
||||
@ -20,11 +20,13 @@
|
||||
#include <twl.h>
|
||||
|
||||
#include <firm/os.h>
|
||||
#include <firm/pxi.h>
|
||||
#include <firm/mi.h>
|
||||
#include <firm/pm.h>
|
||||
#include <firm/aes.h>
|
||||
/*
|
||||
#include <firm/memorymap.h>
|
||||
#include <firm/nvram.h>
|
||||
#include <firm/pm.h>
|
||||
#include <firm/gcd.h>
|
||||
*/
|
||||
|
||||
|
||||
@ -18,10 +18,9 @@
|
||||
#define FIRM_AES_H_
|
||||
|
||||
#ifdef SDK_ARM7
|
||||
#include <twl/aes/common/type.h>
|
||||
#include <firm/aes/ARM7/aes_init.h>
|
||||
#include <firm/aes/ARM7/aes_ids.h>
|
||||
#include <twl/aes/ARM7/instruction.h>
|
||||
#include <twl/aes/ARM7/transfer.h>
|
||||
#endif // SDK_ARM7
|
||||
|
||||
/* FIRM_AES_H_ */
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*---------------------------------------------------------------------------*
|
||||
Project: TwlFirm - AES - include
|
||||
Project: TwlIPL - AES - include
|
||||
File: aes_init.h
|
||||
|
||||
Copyright 2007 Nintendo. All rights reserved.
|
||||
@ -22,14 +22,14 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
ŠÖ<EFBFBD>”’è‹`
|
||||
*---------------------------------------------------------------------------*/
|
||||
void AESi_InitGameKeys( u8 game_code[4] );
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
/* TWL_AES_AES_INIT_H_ */
|
||||
#endif
|
||||
|
||||
349
include/firm/devices/firm_sdmc/ARM7/sdif_ip.h
Normal file
349
include/firm/devices/firm_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);
|
||||
|
||||
|
||||
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__ */
|
||||
118
include/firm/devices/firm_sdmc/ARM7/sdif_reg.h
Normal file
118
include/firm/devices/firm_sdmc/ARM7/sdif_reg.h
Normal file
@ -0,0 +1,118 @@
|
||||
/*---------------------------------------------------------------------------*
|
||||
Project: TwlBrom - 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__ */
|
||||
87
include/firm/devices/firm_sdmc/ARM7/sdmc_config.h
Normal file
87
include/firm/devices/firm_sdmc/ARM7/sdmc_config.h
Normal file
@ -0,0 +1,87 @@
|
||||
/*
|
||||
** 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 <firm.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 ***/
|
||||
|
||||
#define SDCARD_TIMER_ID (OS_TIMER_3)
|
||||
|
||||
|
||||
/*********************************************
|
||||
タイムアウト設定値(ms単位)
|
||||
*********************************************/
|
||||
#define SDCARD_RW_TIMEOUT (2000)
|
||||
#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__*/
|
||||
127
include/firm/devices/firm_sdmc/ARM7/sdmc_types.h
Normal file
127
include/firm/devices/firm_sdmc/ARM7/sdmc_types.h
Normal file
@ -0,0 +1,127 @@
|
||||
|
||||
#ifndef __SDMC_TYPES_H__
|
||||
#define __SDMC_TYPES_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
|
||||
{
|
||||
u16 SD_CID[8]; /* CID保存用 (Card IDentification register) : ID*/
|
||||
u16 SD_CSD[8]; /* CSD保存用 (Card Specific Data register) : spec*/
|
||||
u16 SD_OCR[2]; /* OCR保存用 (Operation Condition Register) : voltage and status*/
|
||||
u16 SD_SCR[4]; /* SCR保存用 (Sd card Configulation Register) : bus-width, card-ver, etc*/
|
||||
u16 SD_RCA; /* RCA保存用 (Relative Card Address register) : address*/
|
||||
s16 MMCFlag;
|
||||
s16 SDHCFlag;
|
||||
s16 SDFlag;
|
||||
SDMC_ERR_CODE ErrStatus; /* SDCARD_ErrStatus */
|
||||
u32 Status; /* SDCARD_Status */
|
||||
u16 SD_CLK_CTRL_VALUE;
|
||||
u16 SD_OPTION_VALUE;
|
||||
|
||||
s16 OutFlag;
|
||||
u16 port_no;
|
||||
}
|
||||
SDPortContext;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*********************************************
|
||||
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;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
|
||||
#endif /*__SDMC_TYPES_H__*/
|
||||
28
include/firm/fatfs.h
Normal file
28
include/firm/fatfs.h
Normal file
@ -0,0 +1,28 @@
|
||||
/*---------------------------------------------------------------------------*
|
||||
Project: TwlIPL - include - fatfs
|
||||
File: fatfs.h
|
||||
|
||||
Copyright 2007 Nintendo. All rights reserved.
|
||||
|
||||
These coded instructions, statements, and computer programs contain
|
||||
proprietary information of Nintendo of America Inc. and/or Nintendo
|
||||
Company Ltd., and are protected by Federal copyright law. They may
|
||||
not be disclosed to third parties or copied or duplicated in any form,
|
||||
in whole or in part, without the prior written consent of Nintendo.
|
||||
|
||||
$Date:: 2007-09-06$
|
||||
$Rev$
|
||||
$Author$
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef FIRM_FATFS_H_
|
||||
#define FIRM_FATFS_H_
|
||||
|
||||
#ifdef SDK_ARM7
|
||||
#include <firm/fatfs/ARM7/fatfs_loader.h>
|
||||
#include <firm/fatfs/ARM7/fatfs_firm.h>
|
||||
#endif // SDK_ARM7
|
||||
|
||||
|
||||
/* FIRM_FATFS_H_ */
|
||||
#endif
|
||||
105
include/firm/fatfs/ARM7/fatfs_firm.h
Normal file
105
include/firm/fatfs/ARM7/fatfs_firm.h
Normal file
@ -0,0 +1,105 @@
|
||||
/*---------------------------------------------------------------------------*
|
||||
Project: TwlIPL - include - fatfs
|
||||
File: fatfs.h
|
||||
|
||||
Copyright 2007 Nintendo. All rights reserved.
|
||||
|
||||
These coded instructions, statements, and computer programs contain
|
||||
proprietary information of Nintendo of America Inc. and/or Nintendo
|
||||
Company Ltd., and are protected by Federal copyright law. They may
|
||||
not be disclosed to third parties or copied or duplicated in any form,
|
||||
in whole or in part, without the prior written consent of Nintendo.
|
||||
|
||||
$Date:: 2007-09-06$
|
||||
$Rev$
|
||||
$Author$
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef FIRM_FATFS_FATFS_FIRM_H_
|
||||
#define FIRM_FATFS_FATFS_FIRM_H_
|
||||
|
||||
#include <twl/types.h>
|
||||
#include <twl/aes/ARM7/lo.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: FATFS_EnableAES
|
||||
|
||||
Description: enable AES data path
|
||||
|
||||
Arguments: slot aes key slot number
|
||||
counter initial counter value
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void FATFS_EnableAES( AESKeySlot slot, const AESCounter* pCounter );
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: FATFS_DisableAES
|
||||
|
||||
Description: bypass AES
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void FATFS_DisableAES( void );
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: nandRead
|
||||
|
||||
Description: normal read
|
||||
|
||||
Arguments: block: source sector number in NAND
|
||||
dest: dest address (4 bytes alignment)
|
||||
count: sectors to transfer
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void nandRead(u32 block, void *dest, u16 count);
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: nandReadAES
|
||||
|
||||
Description: AES read
|
||||
|
||||
Arguments: block: source sector number in NAND
|
||||
dest: dest address (4 bytes alignment)
|
||||
count: sectors to transfer
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void nandReadAES(u32 block, void *dest, u16 count);
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: FATFS_InitFIRM
|
||||
|
||||
Description: init file system
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
BOOL FATFS_InitFIRM( void );
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: FATFS_MountNandFirm
|
||||
|
||||
Description: mount nand partition
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
BOOL FATFS_MountNandFirm( int driveno, int partition_no );
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
|
||||
/* FIRM_FATFS_FATFS_FIRM_H_ */
|
||||
#endif
|
||||
78
include/firm/fatfs/ARM7/fatfs_loader.h
Normal file
78
include/firm/fatfs/ARM7/fatfs_loader.h
Normal file
@ -0,0 +1,78 @@
|
||||
/*---------------------------------------------------------------------------*
|
||||
Project: TwlIPL - include - fatfs
|
||||
File: fatfs_loader.h
|
||||
|
||||
Copyright 2007 Nintendo. All rights reserved.
|
||||
|
||||
These coded instructions, statements, and computer programs contain
|
||||
proprietary information of Nintendo of America Inc. and/or Nintendo
|
||||
Company Ltd., and are protected by Federal copyright law. They may
|
||||
not be disclosed to third parties or copied or duplicated in any form,
|
||||
in whole or in part, without the prior written consent of Nintendo.
|
||||
|
||||
$Date:: 2007-09-06$
|
||||
$Rev$
|
||||
$Author$
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef FIRM_FATFS_FATFS_LOADER_H_
|
||||
#define FIRM_FATFS_FATFS_LOADER_H_
|
||||
|
||||
#include <twl/types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: FATFS_OpenRecentMenu
|
||||
|
||||
Description: open recent menu file
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
BOOL FATFS_OpenRecentMenu( int driveno );
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: FATFS_LoadHeader
|
||||
|
||||
Description: load menu header
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: TRUE if success
|
||||
*---------------------------------------------------------------------------*/
|
||||
BOOL FATFS_LoadHeader( void );
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: FATFS_LoadMenu
|
||||
|
||||
Description: load menu binary
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: TRUE if success
|
||||
*---------------------------------------------------------------------------*/
|
||||
BOOL FATFS_LoadMenu( void );
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: FATFS_BootMenu
|
||||
|
||||
Description: boot menu
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void FATFS_BootMenu( void );
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
|
||||
/* FIRM_FATFS_FATFS_LOADER_H_ */
|
||||
#endif
|
||||
@ -36,6 +36,16 @@ extern "C" {
|
||||
#define HW_FIRM_FROM_BROM_BUF_END (HW_WRAM_AREA_END - 0x1000) // END - 4KB
|
||||
#define HW_FIRM_FROM_BROM_BUF_SIZE 0x3000 // 12KB
|
||||
|
||||
//------------------------------------- HW_FIRM_APP_BUF
|
||||
#define HW_FIRM_APP_BUF (HW_MAIN_MEM_HI_EX_END - HW_FIRM_APP_BUF_SIZE)
|
||||
#define HW_FIRM_APP_BUF_END (HW_FIRM_APP_BUF + HW_FIRM_APP_BUF_SIZE)
|
||||
#define HW_FIRM_APP_BUF_SIZE 0x00800000 // 8MB
|
||||
|
||||
//------------------------------------- HW_FIRM_BOOT_CORE
|
||||
#define HW_FIRM_BOOT_CORE HW_EXT_WRAM
|
||||
#define HW_FIRM_BOOT_CORE_END (HW_FIRM_BOOT_CORE + HW_FIRM_BOOT_CORE_SIZE)
|
||||
#define HW_FIRM_BOOT_CORE_SIZE 0x200 // 512B
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
|
||||
@ -36,6 +36,15 @@ extern "C" {
|
||||
#define HW_FIRM_FROM_BROM_BUF_END (HW_ITCM_END - 0x1000) // END - 4KB
|
||||
#define HW_FIRM_FROM_BROM_BUF_SIZE 0x3000 // 12KB
|
||||
|
||||
//------------------------------------- HW_FIRM_APP_BUF
|
||||
#define HW_FIRM_APP_BUF (HW_MAIN_MEM_HI_EX_END - HW_FIRM_APP_BUF_SIZE)
|
||||
#define HW_FIRM_APP_BUF_END (HW_FIRM_APP_BUF + HW_FIRM_APP_BUF_SIZE)
|
||||
#define HW_FIRM_APP_BUF_SIZE 0x00800000 // 8MB
|
||||
|
||||
//------------------------------------- HW_FIRM_BOOT_CORE
|
||||
#define HW_FIRM_BOOT_CORE HW_FIRM_FROM_BROM_BUF_END
|
||||
#define HW_FIRM_BOOT_CORE_END (HW_FIRM_BOOT_CORE + HW_FIRM_BOOT_CORE_SIZE)
|
||||
#define HW_FIRM_BOOT_CORE_SIZE 0x200 // 512B
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
|
||||
@ -21,6 +21,9 @@
|
||||
#include <twl/mi.h>
|
||||
|
||||
#include <firm/mi/mainMemory.h>
|
||||
#ifdef SDK_ARM9
|
||||
#include <firm/mi/ARM9/mi_loader.h>
|
||||
#endif
|
||||
|
||||
/* FIRM_MI_H_ */
|
||||
#endif
|
||||
|
||||
66
include/firm/mi/ARM9/mi_loader.h
Normal file
66
include/firm/mi/ARM9/mi_loader.h
Normal file
@ -0,0 +1,66 @@
|
||||
/*---------------------------------------------------------------------------*
|
||||
Project: TwlIPL - include - mi
|
||||
File: mi_loader.h
|
||||
|
||||
Copyright 2007 Nintendo. All rights reserved.
|
||||
|
||||
These coded instructions, statements, and computer programs contain
|
||||
proprietary information of Nintendo of America Inc. and/or Nintendo
|
||||
Company Ltd., and are protected by Federal copyright law. They may
|
||||
not be disclosed to third parties or copied or duplicated in any form,
|
||||
in whole or in part, without the prior written consent of Nintendo.
|
||||
|
||||
$Date:: 2007-09-06$
|
||||
$Rev$
|
||||
$Author$
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef FIRM_MI_LOADER_H_
|
||||
#define FIRM_MI_LOADER_H_
|
||||
|
||||
#include <twl/types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: MI_LoadHeader
|
||||
|
||||
Description: load header
|
||||
|
||||
Arguments: pool pointer to the pool info for SVC_DecryptoSign
|
||||
|
||||
Returns: TRUE if success
|
||||
*---------------------------------------------------------------------------*/
|
||||
BOOL MI_LoadHeader( int* pool );
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: MI_LoadMenu
|
||||
|
||||
Description: load menu program
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: TRUE if success
|
||||
*---------------------------------------------------------------------------*/
|
||||
BOOL MI_LoadMenu( void );
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: MI_BootMenu
|
||||
|
||||
Description: boot menu
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void MI_BootMenu( void );
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
|
||||
/* FIRM_MI_LOADER_H_ */
|
||||
#endif
|
||||
@ -29,6 +29,8 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//---- entry point type
|
||||
typedef void (*OSEntryPoint) (void);
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: OSi_Boot
|
||||
@ -36,10 +38,11 @@ extern "C" {
|
||||
Description: boot firm
|
||||
|
||||
Arguments: entry : entry point
|
||||
w : wram settings
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void OSi_Boot( void* entry, MIHeader_WramRegs* w, BOOL to_firm );
|
||||
void OSi_Boot( void* entry, MIHeader_WramRegs* w );
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: OSi_Finalize
|
||||
@ -52,6 +55,17 @@ void OSi_Boot( void* entry, MIHeader_WramRegs* w, BOOL to_firm );
|
||||
*---------------------------------------------------------------------------*/
|
||||
void OSi_Finalize(void);
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: OSi_ClearWorkArea
|
||||
|
||||
Description: clear work area
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void OSi_ClearWorkArea( void );
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: OSi_GetFromBromAddr
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*---------------------------------------------------------------------------*
|
||||
Project: TwlFirm - include - PM
|
||||
Project: TwlIPL - include - pm
|
||||
File: pm.h
|
||||
|
||||
Copyright 2007 Nintendo. All rights reserved.
|
||||
@ -18,13 +18,11 @@
|
||||
#ifndef FIRM_PM_H_
|
||||
#define FIRM_PM_H_
|
||||
|
||||
#include <twl/pm.h>
|
||||
|
||||
#ifdef SDK_ARM7
|
||||
#include <../build/libraries/spi/ARM7/pm/include/pm_pmic.h>
|
||||
#include <../build/libraries/spi/ARM7/pm/include/pm_pmic_ex.h>
|
||||
#include <firm/pm/ARM7/pm_reg_ex.h>
|
||||
#include <firm/pm/ARM7/pm_pmic_ex.h>
|
||||
#include <firm/pm/ARM7/pm_init.h>
|
||||
#endif // SDK_ARM7
|
||||
|
||||
|
||||
/* FIRM_PM_H_ */
|
||||
#endif
|
||||
|
||||
41
include/firm/pm/ARM7/pm_init.h
Normal file
41
include/firm/pm/ARM7/pm_init.h
Normal file
@ -0,0 +1,41 @@
|
||||
/*---------------------------------------------------------------------------*
|
||||
Project: TwlIPL - include - pm
|
||||
File: pm_init.h
|
||||
|
||||
Copyright 2007 Nintendo. All rights reserved.
|
||||
|
||||
These coded instructions, statements, and computer programs contain
|
||||
proprietary information of Nintendo of America Inc. and/or Nintendo
|
||||
Company Ltd., and are protected by Federal copyright law. They may
|
||||
not be disclosed to third parties or copied or duplicated in any form,
|
||||
in whole or in part, without the prior written consent of Nintendo.
|
||||
|
||||
$Date:: 2007-09-06$
|
||||
$Rev$
|
||||
$Author$
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef FIRM_PM_ARM7_PM_INIT_H_
|
||||
#define FIRM_PM_ARM7_PM_INIT_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: PM_InitFIRM
|
||||
|
||||
Description: power B/L on
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void PM_InitFIRM( void );
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
/* FIRM_PM_ARM7_PM_INIT_H_ */
|
||||
#endif
|
||||
73
include/firm/pm/ARM7/pm_pmic_ex.h
Normal file
73
include/firm/pm/ARM7/pm_pmic_ex.h
Normal file
@ -0,0 +1,73 @@
|
||||
/*---------------------------------------------------------------------------*
|
||||
Project: TwlIPL - include - pm
|
||||
File: pm_pmic_ex.h
|
||||
|
||||
Copyright 2007 Nintendo. All rights reserved.
|
||||
|
||||
These coded instructions, statements, and computer programs contain
|
||||
proprietary information of Nintendo of America Inc. and/or Nintendo
|
||||
Company Ltd., and are protected by Federal copyright law. They may
|
||||
not be disclosed to third parties or copied or duplicated in any form,
|
||||
in whole or in part, without the prior written consent of Nintendo.
|
||||
|
||||
$Date:: 2007-09-06$
|
||||
$Rev$
|
||||
$Author$
|
||||
*---------------------------------------------------------------------------*/
|
||||
#ifndef FIRM_PM_PMIC_EX_H_
|
||||
#define FIRM_PM_PMIC_EX_H_
|
||||
|
||||
#include <firm/misc.h>
|
||||
#include <twl/types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//================================================================================
|
||||
// PMIC ACCESS
|
||||
//================================================================================
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: PMi_SetParams
|
||||
|
||||
Description: set control bit to device register
|
||||
|
||||
Arguments: reg : device register
|
||||
setBits : bits to set
|
||||
maskBits : bits to mask
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void PMi_SetParams( u8 reg, u8 setBits, u8 maskBits );
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: PMi_SetFlags
|
||||
|
||||
Description: set control bit to device register
|
||||
|
||||
Arguments: reg : device register
|
||||
setBits : bits to set
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void PMi_SetFlags( u8 reg, u8 setBits );
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: PMi_ResetFlags
|
||||
|
||||
Description: clear control bit to device register
|
||||
|
||||
Arguments: reg : device register
|
||||
clrBits : bits to set
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void PMi_ResetFlags( u8 reg, u8 clrBits );
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
/* FIRM_PM_PMIC_EX_H_ */
|
||||
#endif
|
||||
538
include/firm/pm/ARM7/pm_reg_ex.h
Normal file
538
include/firm/pm/ARM7/pm_reg_ex.h
Normal file
@ -0,0 +1,538 @@
|
||||
/*---------------------------------------------------------------------------*
|
||||
Project: TwlIPL - include - pm
|
||||
File: pm_reg_ex.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.
|
||||
|
||||
$Date:: 2007-09-06$
|
||||
$Rev$
|
||||
$Author$
|
||||
*---------------------------------------------------------------------------*/
|
||||
#ifndef FIRM_PM_PM_REG_EX_H_
|
||||
#define FIRM_PM_PM_REG_EX_H_
|
||||
|
||||
#define SDK_PMIC_REV 100
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
//================================================================
|
||||
// PMIC extention register parameter
|
||||
//================================================================
|
||||
//---------------- address
|
||||
#define REG_PMIC_CTL2_ADDR 0x10 // R/W
|
||||
#if SDK_PMIC_REV!=0
|
||||
#define REG_PMIC_OUT_CTL_ADDR 0x11 // R/W
|
||||
#define REG_PMIC_TIME_CTL_ADDR 0x12 // R/W
|
||||
#define REG_PMIC_PM_INFO_ADDR 0x14 // R
|
||||
#define REG_PMIC_BT_INFO_ADDR 0x15 // R
|
||||
#define REG_PMIC_SW_FLAGS_ADDR 0x16 // R/W
|
||||
#define REG_PMIC_BT_CRCT_ADDR 0x17 // R/W
|
||||
#define REG_PMIC_BT_THL_ADDR 0x18 // R/W
|
||||
#define REG_PMIC_BT_THH_ADDR 0x19 // R/W
|
||||
#define REG_PMIC_LED_CTL_ADDR 0x1a // R/W
|
||||
#define REG_PMIC_LED12_BLK_ADDR 0x1a // R/W mirror
|
||||
#define REG_PMIC_LED12_B4_ADDR 0x1b // R/W
|
||||
#define REG_PMIC_LED12_B3_ADDR 0x1c // R/W
|
||||
#define REG_PMIC_LED12_B2_ADDR 0x1d // R/W
|
||||
#define REG_PMIC_LED12_B1_ADDR 0x1e // R/W
|
||||
#define REG_PMIC_BL1_BRT_ADDR 0x1f // R/W
|
||||
#define REG_PMIC_BL2_BRT_ADDR 0x20 // R/W
|
||||
#else // SDK_PMIC_REV==0
|
||||
#define REG_PMIC_BT_INFO_ADDR 0x11 // R
|
||||
#define REG_PMIC_SW_FLAGS_ADDR 0x12 // R/W
|
||||
#define REG_PMIC_TIME_CTL_ADDR 0x15 // R/W
|
||||
#define REG_PMIC_OUT_CTL_ADDR 0x16 // R/W
|
||||
#define REG_PMIC_BT_CRCT_ADDR 0x18 // R/W
|
||||
#define REG_PMIC_BT_THL_ADDR 0x19 // R/W
|
||||
#define REG_PMIC_BT_THH_ADDR 0x1a // R/W
|
||||
#define REG_PMIC_LED_CTL_ADDR 0x1c // R/W
|
||||
#define REG_PMIC_LED12_B4_ADDR 0x1d // R/W
|
||||
#define REG_PMIC_LED12_B3_ADDR 0x1e // R/W
|
||||
#define REG_PMIC_LED12_B2_ADDR 0x1f // R/W
|
||||
#define REG_PMIC_LED12_B1_ADDR 0x20 // R/W
|
||||
#define REG_PMIC_LED12_BLK_ADDR 0x22 // R/W
|
||||
#define REG_PMIC_BL1_BRT_ADDR 0x24 // R/W
|
||||
#define REG_PMIC_BL2_BRT_ADDR 0x24 // R/W
|
||||
#endif // SDK_PMIC_REV==0
|
||||
#define REG_PMIC_GPIO_CTL_ADDR 0x13 // R/W
|
||||
|
||||
|
||||
//---------------- each register spec
|
||||
//---- PMIC_CTL2
|
||||
#define PMIC_CTL2_RST (1<< 0)
|
||||
#define PMIC_CTL2_VCNT5_BLO (1<< 1)
|
||||
#define PMIC_CTL2_BKLT1 (1<< 2)
|
||||
#define PMIC_CTL2_BKLT2 (1<< 3)
|
||||
#define PMIC_CTL2_VLT42 (1<< 4) // ?
|
||||
#define PMIC_CTL2_LCD_PWR (1<< 5)
|
||||
#define PMIC_CTL2_PWR_OFF (1<< 6)
|
||||
|
||||
//---- PMIC_BT_INFO
|
||||
#define PMIC_BT_INFO_VLTLOW (1<< 0)
|
||||
#define PMIC_BT_INFO_VLT_SHIFT 1
|
||||
#define PMIC_BT_INFO_VLT_MASK (7<< PMIC_BT_INFO_VLT_SHIFT)
|
||||
#define PMIC_BT_INFO_MKR_SHIFT 5
|
||||
#define PMIC_BT_INFO_MKR_MASK (7<< PMIC_BT_INFO_MKR_SHIFT)
|
||||
|
||||
//---- PMIC_SW_FLAGS
|
||||
#define PMIC_SW_FLAGS_WARMBOOT (1 << 7)
|
||||
|
||||
//---- PMIC_GPIO_CTL
|
||||
#if SDK_PMIC_REV!=0
|
||||
#define PMIC_GPIO_CTL_O1 (1<< 0)
|
||||
#define PMIC_GPIO_CTL_O2 (1<< 1)
|
||||
#define PMIC_GPIO_CTL_O3 (1<< 2)
|
||||
#else // SDK_PMIC_REV==0
|
||||
#define PMIC_GPIO_CTL_O1 (1<< 1)
|
||||
#define PMIC_GPIO_CTL_O2 (1<< 2)
|
||||
#define PMIC_GPIO_CTL_O3 (1<< 3)
|
||||
#define PMIC_GPIO_CTL_AO_SHIFT 6
|
||||
#define PMIC_GPIO_CTL_AO_MASK (3<< PMIC_GPIO_CTL_SHIFT)
|
||||
#endif // SDK_PMIC_REV==0
|
||||
|
||||
//---- PMIC_TIME_CTL
|
||||
#if SDK_PMIC_REV!=0
|
||||
#define PMIC_TIME_CTL_OFF_SHIFT 0
|
||||
#define PMIC_TIME_CTL_OFF_MASK (0x7<< PMIC_TIME_CTL_OFF_SHIFT)
|
||||
#define PMIC_TIME_CTL_ACQ_SHIFT 4
|
||||
#define PMIC_TIME_CTL_ACQ_MASK (0x3<< PMIC_TIME_CTL_ACQ_SHIFT)
|
||||
#else // SDK_PMIC_REV==0
|
||||
#define PMIC_TIME_CTL_OFF_SHIFT 0
|
||||
#define PMIC_TIME_CTL_OFF_MASK (0xf<< PMIC_TIME_CTL_OFF_SHIFT)
|
||||
#endif // SDK_PMIC_REV==0
|
||||
|
||||
//---- PMIC_BT_CRCT
|
||||
#define PMIC_BT_CRCT_TEMP_ON (1<< 0)
|
||||
#define PMIC_BT_CRCT_AMPR_ON (1<< 1)
|
||||
#define PMIC_BT_CRCT_AK_SHIFT 4
|
||||
#define PMIC_BT_CRCT_AK_MASK (0x3<< PMIC_BT_CRCT_AK_SHIFT)
|
||||
#define PMIC_BT_CRCT_TK_SHIFT 6
|
||||
#define PMIC_BT_CRCT_TK_MASK (0x3<< PMIC_BT_CRCT_TK_SHIFT)
|
||||
|
||||
//---- PMIC_BT_THL
|
||||
#define PMIC_BT_THL_TH1_SHIFT 0
|
||||
#define PMIC_BT_THL_TH1_MASK (7<< PMIC_BT_THL_TH1_SHIFT)
|
||||
#define PMIC_BT_THL_TH2_SHIFT 4
|
||||
#define PMIC_BT_THL_TH2_MASK (7<< PMIC_BT_THL_TH2_SHIFT)
|
||||
|
||||
//---- PMIC_BT_THH
|
||||
#define PMIC_BT_THH_TH3_SHIFT 0
|
||||
#define PMIC_BT_THH_TH3_MASK (7<< PMIC_BT_THH_TH3_SHIFT)
|
||||
#define PMIC_BT_THH_TH4_SHIFT 4
|
||||
#define PMIC_BT_THH_TH4_MASK (7<< PMIC_BT_THH_TH4_SHIFT)
|
||||
|
||||
//---- PMIC_OUT_CTL
|
||||
#if SDK_PMIC_REV!=0
|
||||
#define PMIC_OUT_CTL_V12_SHIFT 0
|
||||
#define PMIC_OUT_CTL_V12_MASK (0x1<< PMIC_OUT_CTL_V12_SHIFT)
|
||||
#define PMIC_OUT_CTL_V18_SHIFT 1
|
||||
#define PMIC_OUT_CTL_V18_MASK (0x1<< PMIC_OUT_CTL_V18_SHIFT)
|
||||
#define PMIC_OUT_CTL_V33_SHIFT 2
|
||||
#define PMIC_OUT_CTL_V33_MASK (0x1<< PMIC_OUT_CTL_V33_SHIFT)
|
||||
#else // SDK_PMIC_REV==0
|
||||
#define PMIC_OUT_CTL_V18_SHIFT 0
|
||||
#define PMIC_OUT_CTL_V18_MASK (0x3<< PMIC_OUT_CTL_V18_SHIFT)
|
||||
#define PMIC_OUT_CTL_V12_SHIFT 2
|
||||
#define PMIC_OUT_CTL_V12_MASK (0x1<< PMIC_OUT_CTL_V12_SHIFT)
|
||||
#define PMIC_OUT_CTL_V33_SHIFT 3
|
||||
#define PMIC_OUT_CTL_V33_MASK (0x1<< PMIC_OUT_CTL_V33_SHIFT)
|
||||
#endif // SDK_PMIC_REV==0
|
||||
|
||||
//---- PMIC_LED_CTL
|
||||
#define PMIC_LED_CTL_L12_B4_ONLY (1<< 0)
|
||||
#define PMIC_LED_CTL_L12_AT_BLK (1<< 1)
|
||||
#if SDK_PMIC_REV!=0
|
||||
#define PMIC_LED_CTL_L12_BLK_BY_SLP (1<< 2)
|
||||
#define PMIC_LED_CTL_L12_BLKF_SHIFT 4
|
||||
#define PMIC_LED_CTL_L12_BLKF_MASK (0x3<< PMIC_LED_CTL_L12_BLKF_SHIFT)
|
||||
#define PMIC_LED_CTL_L12_BLKD_SHIFT 6
|
||||
#define PMIC_LED_CTL_L12_BLKD_MASK (0x3<< PMIC_LED_CTL_L12_BLKD_SHIFT)
|
||||
#endif // SDK_PMIC_REV!=0
|
||||
|
||||
//---- PMIC_LED12_BLK (mirror)
|
||||
#if SDK_PMIC_REV!=0
|
||||
#define PMIC_LED12_BLK_FQ_SHIFT 4
|
||||
#define PMIC_LED12_BLK_FQ_MASK (0x3<< PMIC_LED12_BLK_FQ_SHIFT)
|
||||
#define PMIC_LED12_BLK_DT_SHIFT 6
|
||||
#define PMIC_LED12_BLK_DT_MASK (0x3<< PMIC_LED12_BLK_DT_SHIFT)
|
||||
#else // SDK_PMIC_REV==0
|
||||
#define PMIC_LED12_BLK_FQ_SHIFT 0
|
||||
#define PMIC_LED12_BLK_FQ_MASK (0x7<< PMIC_LED12_BLK_FQ_SHIFT)
|
||||
#define PMIC_LED12_BLK_DT_SHIFT 4
|
||||
#define PMIC_LED12_BLK_DT_MASK (0x3<< PMIC_LED12_BLK_DT_SHIFT)
|
||||
#endif // SDK_PMIC_REV==0
|
||||
|
||||
//---- PMIC_LED12_B4
|
||||
#define PMIC_LED12_B4_L1_SHIFT 0
|
||||
#define PMIC_LED12_B4_L1_MASK (0x7<< PMIC_LED12_B4_L1_SHIFT)
|
||||
#define PMIC_LED12_B4_L2_SHIFT 4
|
||||
#define PMIC_LED12_B4_L2_MASK (0x7<< PMIC_LED12_B4_L2_SHIFT)
|
||||
|
||||
//---- PMIC_LED12_B3
|
||||
#define PMIC_LED12_B3_L1_SHIFT 0
|
||||
#define PMIC_LED12_B3_L1_MASK (0x7<< PMIC_LED12_B3_L1_SHIFT)
|
||||
#define PMIC_LED12_B3_L2_SHIFT 4
|
||||
#define PMIC_LED12_B3_L2_MASK (0x7<< PMIC_LED12_B3_L2_SHIFT)
|
||||
|
||||
//---- PMIC_LED12_B2
|
||||
#define PMIC_LED12_B2_L1_SHIFT 0
|
||||
#define PMIC_LED12_B2_L1_MASK (0x7<< PMIC_LED12_B2_L1_SHIFT)
|
||||
#define PMIC_LED12_B2_L2_SHIFT 4
|
||||
#define PMIC_LED12_B2_L2_MASK (0x7<< PMIC_LED12_B2_L2_SHIFT)
|
||||
|
||||
//---- PMIC_LED12_B1
|
||||
#define PMIC_LED12_B1_L1_SHIFT 0
|
||||
#define PMIC_LED12_B1_L1_MASK (0x7<< PMIC_LED12_B1_L1_SHIFT)
|
||||
#define PMIC_LED12_B1_L2_SHIFT 4
|
||||
#define PMIC_LED12_B1_L2_MASK (0x7<< PMIC_LED12_B1_L2_SHIFT)
|
||||
|
||||
//---- PMIC_BL1_BRT
|
||||
#define PMIC_BL1_BRT_SHIFT 0
|
||||
#define PMIC_BL1_BRT_MASK (0x1f<< PMIC_BL1_BRT_SHIFT)
|
||||
|
||||
//---- PMIC_BL2_BRT
|
||||
#define PMIC_BL2_BRT_SHIFT 0
|
||||
#define PMIC_BL2_BRT_MASK (0x1f<< PMIC_BL2_BRT_SHIFT)
|
||||
|
||||
|
||||
//---- PMIC_BT_INFO
|
||||
typedef enum
|
||||
{
|
||||
PMIC_BT_INFO_VLT_L1 = (0 << PMIC_BT_INFO_VLT_SHIFT),
|
||||
PMIC_BT_INFO_VLT_L2 = (1 << PMIC_BT_INFO_VLT_SHIFT),
|
||||
PMIC_BT_INFO_VLT_L3 = (2 << PMIC_BT_INFO_VLT_SHIFT),
|
||||
PMIC_BT_INFO_VLT_L4 = (3 << PMIC_BT_INFO_VLT_SHIFT),
|
||||
PMIC_BT_INFO_VLT_L5 = (4 << PMIC_BT_INFO_VLT_SHIFT)
|
||||
}
|
||||
PMBatteryLevel;
|
||||
|
||||
//---- PMIC_TIME_CTL
|
||||
typedef enum
|
||||
{
|
||||
#if SDK_PMIC_REV!=0
|
||||
PMIC_TIME_CTL_OFF_125MS = (0x0 << PMIC_TIME_CTL_OFF_SHIFT),
|
||||
PMIC_TIME_CTL_OFF_250MS = (0x1 << PMIC_TIME_CTL_OFF_SHIFT), // default
|
||||
PMIC_TIME_CTL_OFF_500MS = (0x2 << PMIC_TIME_CTL_OFF_SHIFT),
|
||||
PMIC_TIME_CTL_OFF_750MS = (0x3 << PMIC_TIME_CTL_OFF_SHIFT),
|
||||
PMIC_TIME_CTL_OFF_1S = (0x4 << PMIC_TIME_CTL_OFF_SHIFT),
|
||||
PMIC_TIME_CTL_OFF_2S = (0x5 << PMIC_TIME_CTL_OFF_SHIFT),
|
||||
PMIC_TIME_CTL_OFF_4S = (0x6 << PMIC_TIME_CTL_OFF_SHIFT),
|
||||
PMIC_TIME_CTL_OFF_8S = (0x7 << PMIC_TIME_CTL_OFF_SHIFT)
|
||||
#else // SDK_PMIC_REV==0
|
||||
PMIC_TIME_CTL_OFF_100MS = (0x0 << PMIC_TIME_CTL_OFF_SHIFT),
|
||||
PMIC_TIME_CTL_OFF_200MS = (0x1 << PMIC_TIME_CTL_OFF_SHIFT), // default
|
||||
PMIC_TIME_CTL_OFF_300MS = (0x2 << PMIC_TIME_CTL_OFF_SHIFT),
|
||||
PMIC_TIME_CTL_OFF_500MS = (0x3 << PMIC_TIME_CTL_OFF_SHIFT),
|
||||
PMIC_TIME_CTL_OFF_700MS = (0x4 << PMIC_TIME_CTL_OFF_SHIFT),
|
||||
PMIC_TIME_CTL_OFF_900MS = (0x5 << PMIC_TIME_CTL_OFF_SHIFT),
|
||||
PMIC_TIME_CTL_OFF_1S = (0x6 << PMIC_TIME_CTL_OFF_SHIFT),
|
||||
PMIC_TIME_CTL_OFF_1500MS = (0x7 << PMIC_TIME_CTL_OFF_SHIFT),
|
||||
PMIC_TIME_CTL_OFF_2S = (0x8 << PMIC_TIME_CTL_OFF_SHIFT),
|
||||
PMIC_TIME_CTL_OFF_2500MS = (0x9 << PMIC_TIME_CTL_OFF_SHIFT),
|
||||
PMIC_TIME_CTL_OFF_3S = (0xa << PMIC_TIME_CTL_OFF_SHIFT),
|
||||
PMIC_TIME_CTL_OFF_4S = (0xb << PMIC_TIME_CTL_OFF_SHIFT),
|
||||
PMIC_TIME_CTL_OFF_5S = (0xc << PMIC_TIME_CTL_OFF_SHIFT),
|
||||
PMIC_TIME_CTL_OFF_7S = (0xd << PMIC_TIME_CTL_OFF_SHIFT),
|
||||
PMIC_TIME_CTL_OFF_9S = (0xe << PMIC_TIME_CTL_OFF_SHIFT),
|
||||
PMIC_TIME_CTL_OFF_10S = (0xf << PMIC_TIME_CTL_OFF_SHIFT)
|
||||
#endif // SDK_PMIC_REV==0
|
||||
}
|
||||
PMOffTime;
|
||||
|
||||
//---- PMIC_BT_CRCT
|
||||
typedef enum
|
||||
{
|
||||
PMIC_BT_CRCT_AK_30_10 = (0 << PMIC_BT_CRCT_AK_SHIFT),
|
||||
PMIC_BT_CRCT_AK_50_10 = (1 << PMIC_BT_CRCT_AK_SHIFT), // default
|
||||
PMIC_BT_CRCT_AK_70_10 = (2 << PMIC_BT_CRCT_AK_SHIFT),
|
||||
PMIC_BT_CRCT_AK_90_10 = (3 << PMIC_BT_CRCT_AK_SHIFT)
|
||||
}
|
||||
PMAmprCoeff;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
PMIC_BT_CRCT_TK_10 = (0 << PMIC_BT_CRCT_TK_SHIFT),
|
||||
PMIC_BT_CRCT_TK_15 = (1 << PMIC_BT_CRCT_TK_SHIFT), // default
|
||||
PMIC_BT_CRCT_TK_20 = (2 << PMIC_BT_CRCT_TK_SHIFT),
|
||||
PMIC_BT_CRCT_TK_30 = (3 << PMIC_BT_CRCT_TK_SHIFT)
|
||||
}
|
||||
PMTempCoeff;
|
||||
|
||||
//---- PMIC_BT_THL / PMIC_BT_THH
|
||||
typedef enum
|
||||
{
|
||||
PMIC_BT_TH_D0 = 0,
|
||||
PMIC_BT_TH_D20 = 1,
|
||||
PMIC_BT_TH_D40 = 2,
|
||||
PMIC_BT_TH_D60 = 3,
|
||||
PMIC_BT_TH_D80 = 4,
|
||||
PMIC_BT_TH_D100 = 5,
|
||||
PMIC_BT_TH_D120 = 6,
|
||||
PMIC_BT_TH_D140 = 7
|
||||
}
|
||||
PMBatteryThresholdDownCommon;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
PMIC_BT_THL_TH1_D0 = (0 << PMIC_BT_THL_TH1_SHIFT),
|
||||
PMIC_BT_THL_TH1_D20 = (1 << PMIC_BT_THL_TH1_SHIFT),
|
||||
PMIC_BT_THL_TH1_D40 = (2 << PMIC_BT_THL_TH1_SHIFT),
|
||||
PMIC_BT_THL_TH1_D60 = (3 << PMIC_BT_THL_TH1_SHIFT),
|
||||
PMIC_BT_THL_TH1_D80 = (4 << PMIC_BT_THL_TH1_SHIFT),
|
||||
PMIC_BT_THL_TH1_D100 = (5 << PMIC_BT_THL_TH1_SHIFT),
|
||||
PMIC_BT_THL_TH1_D120 = (6 << PMIC_BT_THL_TH1_SHIFT),
|
||||
PMIC_BT_THL_TH1_D140 = (7 << PMIC_BT_THL_TH1_SHIFT)
|
||||
}
|
||||
PMBatteryThreshold1Down;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
PMIC_BT_THL_TH2_D0 = (0 << PMIC_BT_THL_TH2_SHIFT),
|
||||
PMIC_BT_THL_TH2_D20 = (1 << PMIC_BT_THL_TH2_SHIFT),
|
||||
PMIC_BT_THL_TH2_D40 = (2 << PMIC_BT_THL_TH2_SHIFT),
|
||||
PMIC_BT_THL_TH2_D60 = (3 << PMIC_BT_THL_TH2_SHIFT),
|
||||
PMIC_BT_THL_TH2_D80 = (4 << PMIC_BT_THL_TH2_SHIFT),
|
||||
PMIC_BT_THL_TH2_D100 = (5 << PMIC_BT_THL_TH2_SHIFT),
|
||||
PMIC_BT_THL_TH2_D120 = (6 << PMIC_BT_THL_TH2_SHIFT),
|
||||
PMIC_BT_THL_TH2_D140 = (7 << PMIC_BT_THL_TH2_SHIFT)
|
||||
}
|
||||
PMBatteryThreshold2Down;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
PMIC_BT_THH_TH3_D0 = (0 << PMIC_BT_THH_TH3_SHIFT),
|
||||
PMIC_BT_THH_TH3_D20 = (1 << PMIC_BT_THH_TH3_SHIFT),
|
||||
PMIC_BT_THH_TH3_D40 = (2 << PMIC_BT_THH_TH3_SHIFT),
|
||||
PMIC_BT_THH_TH3_D60 = (3 << PMIC_BT_THH_TH3_SHIFT),
|
||||
PMIC_BT_THH_TH3_D80 = (4 << PMIC_BT_THH_TH3_SHIFT),
|
||||
PMIC_BT_THH_TH3_D100 = (5 << PMIC_BT_THH_TH3_SHIFT),
|
||||
PMIC_BT_THH_TH3_D120 = (6 << PMIC_BT_THH_TH3_SHIFT),
|
||||
PMIC_BT_THH_TH3_D140 = (7 << PMIC_BT_THH_TH3_SHIFT)
|
||||
}
|
||||
PMBatteryThreshold3Down;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
PMIC_BT_THH_TH4_D0 = (0 << PMIC_BT_THH_TH4_SHIFT),
|
||||
PMIC_BT_THH_TH4_D20 = (1 << PMIC_BT_THH_TH4_SHIFT),
|
||||
PMIC_BT_THH_TH4_D40 = (2 << PMIC_BT_THH_TH4_SHIFT),
|
||||
PMIC_BT_THH_TH4_D60 = (3 << PMIC_BT_THH_TH4_SHIFT),
|
||||
PMIC_BT_THH_TH4_D80 = (4 << PMIC_BT_THH_TH4_SHIFT),
|
||||
PMIC_BT_THH_TH4_D100 = (5 << PMIC_BT_THH_TH4_SHIFT),
|
||||
PMIC_BT_THH_TH4_D120 = (6 << PMIC_BT_THH_TH4_SHIFT),
|
||||
PMIC_BT_THH_TH4_D140 = (7 << PMIC_BT_THH_TH4_SHIFT)
|
||||
}
|
||||
PMBatteryThreshold4Down;
|
||||
|
||||
//---- PMIC_OUT_CTL
|
||||
typedef enum
|
||||
{
|
||||
PMIC_OUT_CTL_V18_PWM = (0 << PMIC_OUT_CTL_V18_SHIFT), // default
|
||||
PMIC_OUT_CTL_V18_PFM = (1 << PMIC_OUT_CTL_V18_SHIFT)
|
||||
}
|
||||
PMPfmPwmV18;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
PMIC_OUT_CTL_V12_PWM = (0 << PMIC_OUT_CTL_V12_SHIFT), // default
|
||||
PMIC_OUT_CTL_V12_PFM = (1 << PMIC_OUT_CTL_V12_SHIFT)
|
||||
}
|
||||
PMPfmPwmV12;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
PMIC_OUT_CTL_V33_PWM = (0 << PMIC_OUT_CTL_V33_SHIFT), // default
|
||||
PMIC_OUT_CTL_V33_PFM = (1 << PMIC_OUT_CTL_V33_SHIFT)
|
||||
}
|
||||
PMPfmPwmV33;
|
||||
|
||||
//---- PMIC_LED12_B4 / PMIC_LED12_B3 / PMIC_LED12_B2 / PMIC_LED12_B1
|
||||
typedef enum
|
||||
{
|
||||
PMIC_LED_BRT_OFF = 0, // default
|
||||
PMIC_LED_BRT_14 = 1,
|
||||
PMIC_LED_BRT_28 = 2,
|
||||
PMIC_LED_BRT_43 = 3,
|
||||
PMIC_LED_BRT_57 = 4,
|
||||
PMIC_LED_BRT_71 = 5,
|
||||
PMIC_LED_BRT_85 = 6,
|
||||
PMIC_LED_BRT_100 = 7
|
||||
}
|
||||
PMLedBrightCommon;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
PMIC_LED12_B4_L1_OFF = (0 << PMIC_LED12_B4_L1_SHIFT), // default
|
||||
PMIC_LED12_B4_L1_14 = (1 << PMIC_LED12_B4_L1_SHIFT),
|
||||
PMIC_LED12_B4_L1_28 = (2 << PMIC_LED12_B4_L1_SHIFT),
|
||||
PMIC_LED12_B4_L1_43 = (3 << PMIC_LED12_B4_L1_SHIFT),
|
||||
PMIC_LED12_B4_L1_57 = (4 << PMIC_LED12_B4_L1_SHIFT),
|
||||
PMIC_LED12_B4_L1_71 = (5 << PMIC_LED12_B4_L1_SHIFT),
|
||||
PMIC_LED12_B4_L1_85 = (6 << PMIC_LED12_B4_L1_SHIFT),
|
||||
PMIC_LED12_B4_L1_100 = (7 << PMIC_LED12_B4_L1_SHIFT)
|
||||
}
|
||||
PMLed1Bright4;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
PMIC_LED12_B4_L2_OFF = (0 << PMIC_LED12_B4_L2_SHIFT), // default
|
||||
PMIC_LED12_B4_L2_14 = (1 << PMIC_LED12_B4_L2_SHIFT),
|
||||
PMIC_LED12_B4_L2_28 = (2 << PMIC_LED12_B4_L2_SHIFT),
|
||||
PMIC_LED12_B4_L2_43 = (3 << PMIC_LED12_B4_L2_SHIFT),
|
||||
PMIC_LED12_B4_L2_57 = (4 << PMIC_LED12_B4_L2_SHIFT),
|
||||
PMIC_LED12_B4_L2_71 = (5 << PMIC_LED12_B4_L2_SHIFT),
|
||||
PMIC_LED12_B4_L2_85 = (6 << PMIC_LED12_B4_L2_SHIFT),
|
||||
PMIC_LED12_B4_L2_100 = (7 << PMIC_LED12_B4_L2_SHIFT)
|
||||
}
|
||||
PMLed2Bright4;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
PMIC_LED12_B3_L1_OFF = (0 << PMIC_LED12_B3_L1_SHIFT), // default
|
||||
PMIC_LED12_B3_L1_14 = (1 << PMIC_LED12_B3_L1_SHIFT),
|
||||
PMIC_LED12_B3_L1_28 = (2 << PMIC_LED12_B3_L1_SHIFT),
|
||||
PMIC_LED12_B3_L1_43 = (3 << PMIC_LED12_B3_L1_SHIFT),
|
||||
PMIC_LED12_B3_L1_57 = (4 << PMIC_LED12_B3_L1_SHIFT),
|
||||
PMIC_LED12_B3_L1_71 = (5 << PMIC_LED12_B3_L1_SHIFT),
|
||||
PMIC_LED12_B3_L1_85 = (6 << PMIC_LED12_B3_L1_SHIFT),
|
||||
PMIC_LED12_B3_L1_100 = (7 << PMIC_LED12_B3_L1_SHIFT)
|
||||
}
|
||||
PMLed1Bright3;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
PMIC_LED12_B3_L2_OFF = (0 << PMIC_LED12_B3_L2_SHIFT), // default
|
||||
PMIC_LED12_B3_L2_14 = (1 << PMIC_LED12_B3_L2_SHIFT),
|
||||
PMIC_LED12_B3_L2_28 = (2 << PMIC_LED12_B3_L2_SHIFT),
|
||||
PMIC_LED12_B3_L2_43 = (3 << PMIC_LED12_B3_L2_SHIFT),
|
||||
PMIC_LED12_B3_L2_57 = (4 << PMIC_LED12_B3_L2_SHIFT),
|
||||
PMIC_LED12_B3_L2_71 = (5 << PMIC_LED12_B3_L2_SHIFT),
|
||||
PMIC_LED12_B3_L2_85 = (6 << PMIC_LED12_B3_L2_SHIFT),
|
||||
PMIC_LED12_B3_L2_100 = (7 << PMIC_LED12_B3_L2_SHIFT)
|
||||
}
|
||||
PMLed2Bright3;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
PMIC_LED12_B2_L1_OFF = (0 << PMIC_LED12_B2_L1_SHIFT), // default
|
||||
PMIC_LED12_B2_L1_14 = (1 << PMIC_LED12_B2_L1_SHIFT),
|
||||
PMIC_LED12_B2_L1_28 = (2 << PMIC_LED12_B2_L1_SHIFT),
|
||||
PMIC_LED12_B2_L1_43 = (3 << PMIC_LED12_B2_L1_SHIFT),
|
||||
PMIC_LED12_B2_L1_57 = (4 << PMIC_LED12_B2_L1_SHIFT),
|
||||
PMIC_LED12_B2_L1_71 = (5 << PMIC_LED12_B2_L1_SHIFT),
|
||||
PMIC_LED12_B2_L1_85 = (6 << PMIC_LED12_B2_L1_SHIFT),
|
||||
PMIC_LED12_B2_L1_100 = (7 << PMIC_LED12_B2_L1_SHIFT)
|
||||
}
|
||||
PMLed1Bright2;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
PMIC_LED12_B2_L2_OFF = (0 << PMIC_LED12_B2_L2_SHIFT), // default
|
||||
PMIC_LED12_B2_L2_14 = (1 << PMIC_LED12_B2_L2_SHIFT),
|
||||
PMIC_LED12_B2_L2_28 = (2 << PMIC_LED12_B2_L2_SHIFT),
|
||||
PMIC_LED12_B2_L2_43 = (3 << PMIC_LED12_B2_L2_SHIFT),
|
||||
PMIC_LED12_B2_L2_57 = (4 << PMIC_LED12_B2_L2_SHIFT),
|
||||
PMIC_LED12_B2_L2_71 = (5 << PMIC_LED12_B2_L2_SHIFT),
|
||||
PMIC_LED12_B2_L2_85 = (6 << PMIC_LED12_B2_L2_SHIFT),
|
||||
PMIC_LED12_B2_L2_100 = (7 << PMIC_LED12_B2_L2_SHIFT)
|
||||
}
|
||||
PMLed2Bright2;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
PMIC_LED12_B1_L1_OFF = (0 << PMIC_LED12_B1_L1_SHIFT), // default
|
||||
PMIC_LED12_B1_L1_14 = (1 << PMIC_LED12_B1_L1_SHIFT),
|
||||
PMIC_LED12_B1_L1_28 = (2 << PMIC_LED12_B1_L1_SHIFT),
|
||||
PMIC_LED12_B1_L1_43 = (3 << PMIC_LED12_B1_L1_SHIFT),
|
||||
PMIC_LED12_B1_L1_57 = (4 << PMIC_LED12_B1_L1_SHIFT),
|
||||
PMIC_LED12_B1_L1_71 = (5 << PMIC_LED12_B1_L1_SHIFT),
|
||||
PMIC_LED12_B1_L1_85 = (6 << PMIC_LED12_B1_L1_SHIFT),
|
||||
PMIC_LED12_B1_L1_100 = (7 << PMIC_LED12_B1_L1_SHIFT)
|
||||
}
|
||||
PMLed1Bright5;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
PMIC_LED12_B1_L2_OFF = (0 << PMIC_LED12_B1_L2_SHIFT), // default
|
||||
PMIC_LED12_B1_L2_14 = (1 << PMIC_LED12_B1_L2_SHIFT),
|
||||
PMIC_LED12_B1_L2_28 = (2 << PMIC_LED12_B1_L2_SHIFT),
|
||||
PMIC_LED12_B1_L2_43 = (3 << PMIC_LED12_B1_L2_SHIFT),
|
||||
PMIC_LED12_B1_L2_57 = (4 << PMIC_LED12_B1_L2_SHIFT),
|
||||
PMIC_LED12_B1_L2_71 = (5 << PMIC_LED12_B1_L2_SHIFT),
|
||||
PMIC_LED12_B1_L2_85 = (6 << PMIC_LED12_B1_L2_SHIFT),
|
||||
PMIC_LED12_B1_L2_100 = (7 << PMIC_LED12_B1_L2_SHIFT)
|
||||
}
|
||||
PMLed2Bright1;
|
||||
|
||||
//---- PMIC_LED_CTL ( PMIC_LED12_BLK )
|
||||
|
||||
typedef enum
|
||||
{
|
||||
PMIC_LED_BLK_FREQ_033HZ = 0, // default
|
||||
PMIC_LED_BLK_FREQ_050HZ = 1,
|
||||
PMIC_LED_BLK_FREQ_067HZ = 2,
|
||||
PMIC_LED_BLK_FREQ_1HZ = 3,
|
||||
PMIC_LED_BLK_FREQ_2HZ = 4,
|
||||
PMIC_LED_BLK_FREQ_4HZ = 5
|
||||
}
|
||||
PMLedBlinkFreqCommon;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
#if SDK_PMIC_REV!=0
|
||||
PMIC_LED12_BLK_FREQ_041HZ = (0 << PMIC_LED_CTL_L12_BLKF_SHIFT),
|
||||
PMIC_LED12_BLK_FREQ_082HZ = (1 << PMIC_LED_CTL_L12_BLKF_SHIFT),
|
||||
PMIC_LED12_BLK_FREQ_2Z = (2 << PMIC_LED_CTL_L12_BLKF_SHIFT), // default
|
||||
PMIC_LED12_BLK_FREQ_4HZ = (3 << PMIC_LED_CTL_L12_BLKF_SHIFT)
|
||||
#else // SDK_PMIC_REV==0
|
||||
PMIC_LED12_BLK_FREQ_033HZ = (0 << PMIC_LED12_BLK_FQ_SHIFT), // default
|
||||
PMIC_LED12_BLK_FREQ_050HZ = (1 << PMIC_LED12_BLK_FQ_SHIFT),
|
||||
PMIC_LED12_BLK_FREQ_067HZ = (2 << PMIC_LED12_BLK_FQ_SHIFT),
|
||||
PMIC_LED12_BLK_FREQ_1HZ = (3 << PMIC_LED12_BLK_FQ_SHIFT),
|
||||
PMIC_LED12_BLK_FREQ_2HZ = (4 << PMIC_LED12_BLK_FQ_SHIFT),
|
||||
PMIC_LED12_BLK_FREQ_4HZ = (5 << PMIC_LED12_BLK_FQ_SHIFT)
|
||||
#endif // SDK_PMIC_REV==0
|
||||
}
|
||||
PMLed12BlinkFreq;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
#if SDK_PMIC_REV!=0
|
||||
PMIC_LED12_BLK_DUTY_10 = (0 << PMIC_LED_CTL_L12_BLKD_SHIFT),
|
||||
PMIC_LED12_BLK_DUTY_25 = (1 << PMIC_LED_CTL_L12_BLKD_SHIFT),
|
||||
PMIC_LED12_BLK_DUTY_50 = (2 << PMIC_LED_CTL_L12_BLKD_SHIFT), // default
|
||||
PMIC_LED12_BLK_DUTY_75 = (3 << PMIC_LED_CTL_L12_BLKD_SHIFT)
|
||||
#else // SDK_PMIC_REV==0
|
||||
PMIC_LED12_BLK_DUTY_10 = (0 << PMIC_LED12_BLK_DT_SHIFT), // default
|
||||
PMIC_LED12_BLK_DUTY_25 = (1 << PMIC_LED12_BLK_DT_SHIFT),
|
||||
PMIC_LED12_BLK_DUTY_50 = (2 << PMIC_LED12_BLK_DT_SHIFT),
|
||||
PMIC_LED12_BLK_DUTY_75 = (3 << PMIC_LED12_BLK_DT_SHIFT)
|
||||
#endif // SDK_PMIC_REV==0
|
||||
}
|
||||
PMLed12BlinkDuty;
|
||||
|
||||
//---- PMIC_BL1_BRT / PMIC_BL2_BRT
|
||||
typedef enum
|
||||
{
|
||||
PMIC_BL_BRT_MIN = 0, // default
|
||||
PMIC_BL_BRT_MAX = 0x1f,
|
||||
PMIC_BL_BRT_DEFAULT = 0x08
|
||||
}
|
||||
PMBackLightBrightness;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
/* FIRM_PM_PM_REG_EX_H_ */
|
||||
#endif
|
||||
28
include/firm/pxi.h
Normal file
28
include/firm/pxi.h
Normal file
@ -0,0 +1,28 @@
|
||||
/*---------------------------------------------------------------------------*
|
||||
Project: TwlFirm - include - PXI
|
||||
File: pxi.h
|
||||
|
||||
Copyright 2007 Nintendo. All rights reserved.
|
||||
|
||||
These coded instructions, statements, and computer programs contain
|
||||
proprietary information of Nintendo of America Inc. and/or Nintendo
|
||||
Company Ltd., and are protected by Federal copyright law. They may
|
||||
not be disclosed to third parties or copied or duplicated in any form,
|
||||
in whole or in part, without the prior written consent of Nintendo.
|
||||
|
||||
$Date:: 2007-09-06$
|
||||
$Rev$
|
||||
$Author$
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef FIRM_PXI_H_
|
||||
#define FIRM_PXI_H_
|
||||
|
||||
#include <nitro/pxi.h>
|
||||
|
||||
#include <firm/pxi/common/regname_ex.h>
|
||||
#include <firm/pxi/common/misc.h>
|
||||
|
||||
|
||||
/* FIRM_PXI_H_ */
|
||||
#endif
|
||||
219
include/firm/pxi/common/misc.h
Normal file
219
include/firm/pxi/common/misc.h
Normal file
@ -0,0 +1,219 @@
|
||||
/*---------------------------------------------------------------------------*
|
||||
Project: TwlFirm - -include - PXI
|
||||
File: misc.h
|
||||
|
||||
Copyright 2007 Nintendo. All rights reserved.
|
||||
|
||||
These coded instructions, statements, and computer programs contain
|
||||
proprietary information of Nintendo of America Inc. and/or Nintendo
|
||||
Company Ltd., and are protected by Federal copyright law. They may
|
||||
not be disclosed to third parties or copied or duplicated in any form,
|
||||
in whole or in part, without the prior written consent of Nintendo.
|
||||
|
||||
$Log: $
|
||||
$NoKeywords: $
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef FIRM_PXI_COMMON_MISC_H_
|
||||
#define FIRM_PXI_COMMON_MISC_H_
|
||||
|
||||
#include <firm/pxi.h>
|
||||
#include <twl/memorymap.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// PXI sync ID for bootrom
|
||||
typedef enum
|
||||
{
|
||||
// from ARM7
|
||||
FIRM_PXI_ID_INIT_ARM7 = 7,
|
||||
FIRM_PXI_ID_LOAD_HEADER = 8,
|
||||
FIRM_PXI_ID_LOAD_ARM9_STATIC = 5,
|
||||
FIRM_PXI_ID_LOAD_ARM7_STATIC = 6,
|
||||
FIRM_PXI_ID_LOAD_ARM9_STATIC_EX = 9,
|
||||
FIRM_PXI_ID_LOAD_ARM7_STATIC_EX = 10,
|
||||
FIRM_PXI_ID_LOAD_PIRIOD = 11,
|
||||
|
||||
// from ARM9
|
||||
FIRM_PXI_ID_INIT_ARM9 = 9,
|
||||
FIRM_PXI_ID_AUTH_HEADER = 8,
|
||||
FIRM_PXI_ID_AUTH_ARM9_STATIC = 5,
|
||||
FIRM_PXI_ID_AUTH_ARM7_STATIC = 6,
|
||||
FIRM_PXI_ID_AUTH_ARM9_STATIC_EX = 9,
|
||||
FIRM_PXI_ID_AUTH_ARM7_STATIC_EX = 10,
|
||||
FIRM_PXI_ID_DONE_WRAM_SETTING = 4,
|
||||
|
||||
// from both of ARM9 and ARM7
|
||||
FIRM_PXI_ID_NULL = 0,
|
||||
FIRM_PXI_ID_ERR = 0xF
|
||||
}
|
||||
FIRMPxiID;
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: PXI_InitFifoFIRM
|
||||
|
||||
Description: initialize FIFO system for bootrom
|
||||
|
||||
Arguments: None.
|
||||
|
||||
Returns: None.
|
||||
*---------------------------------------------------------------------------*/
|
||||
void PXI_InitFifoFIRM(void);
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: PXI_NotifyID
|
||||
|
||||
Description: send 4bit id to other processor
|
||||
|
||||
Arguments: id notifying id
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void PXI_NotifyID( u32 id );
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: PXI_WaitID
|
||||
|
||||
Description: Wait 4bit id from the other processor
|
||||
|
||||
Arguments: id waiting id
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void PXI_WaitID( u32 id );
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: PXI_RecvID
|
||||
|
||||
Description: Receive 4bit id from the other processor
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: id
|
||||
*---------------------------------------------------------------------------*/
|
||||
u8 PXI_RecvID( void );
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: PXI_SendIDByIntf
|
||||
|
||||
Description: send 4bit id to other processor
|
||||
|
||||
Arguments: id notifying id
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void PXI_SendIDByIntf( u32 id );
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: PXI_RecvIDByIntf
|
||||
|
||||
Description: receive 4bit id from the other processor
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: received id
|
||||
*---------------------------------------------------------------------------*/
|
||||
u32 PXI_RecvIDByIntf( void );
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: PXI_WaitIDByIntf
|
||||
|
||||
Description: Wait 4bit id from the other processor
|
||||
|
||||
Arguments: id waiting id
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void PXI_WaitIDByIntf( u32 id );
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: PXI_SendIDByFifo
|
||||
|
||||
Description: Send 32bit-word to another CPU via FIFO
|
||||
|
||||
Arguments:
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void PXI_SendIDByFifo(PXIFifoTag tag, u32 id);
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: PXI_RecvIDByFifo
|
||||
|
||||
Description: Recv 32bit-word from another CPU via FIFO
|
||||
|
||||
Arguments:
|
||||
|
||||
Returns: if error occured, returns minus value
|
||||
*---------------------------------------------------------------------------*/
|
||||
PXIFifoStatus PXI_RecvIDByFifo(PXIFifoTag tag, void* buf);
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: PXI_WaitIDByFifo
|
||||
|
||||
Description: Wait 32bit-word from another CPU via FIFO
|
||||
|
||||
Arguments: id waiting id
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void PXI_WaitIDByFifo(PXIFifoTag tag, u32 id);
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: PXI_SendDataByFifo
|
||||
|
||||
Description: Send 32bit-word to another CPU via FIFO
|
||||
|
||||
Arguments:
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void PXI_SendDataByFifo(PXIFifoTag tag, void* buf, int size);
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: PXI_RecvDataByFifo
|
||||
|
||||
Description: Recv 32bit-word to another CPU via FIFO
|
||||
|
||||
Arguments:
|
||||
|
||||
Returns: if error occured, returns minus value
|
||||
*---------------------------------------------------------------------------*/
|
||||
PXIFifoStatus PXI_RecvDataByFifo(PXIFifoTag tag, void* buf, int max_size);
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: PXI_IsSendFifoFull
|
||||
|
||||
Description: Check if send fifo is full?
|
||||
|
||||
Arguments: None.
|
||||
|
||||
Returns: if send fifo is full
|
||||
*---------------------------------------------------------------------------*/
|
||||
static inline BOOL PXI_IsSendFifoFull(void)
|
||||
{
|
||||
return (reg_PXI_FIFO_CNT & REG_PXI_FIFO_CNT_SEND_FULL_MASK) >> REG_PXI_FIFO_CNT_SEND_FULL_SHIFT;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: PXI_IsRecvFifoEmpty
|
||||
|
||||
Description: Check if receive fifo is empty?
|
||||
|
||||
Arguments: None.
|
||||
|
||||
Returns: if receive fifo is empty
|
||||
*---------------------------------------------------------------------------*/
|
||||
static inline BOOL PXI_IsRecvFifoEmpty(void)
|
||||
{
|
||||
return (reg_PXI_FIFO_CNT & REG_PXI_FIFO_CNT_RECV_EMP_MASK) >> REG_PXI_FIFO_CNT_RECV_EMP_SHIFT;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* FIRM_PXI_COMMON_MISC_H_ */
|
||||
42
include/firm/pxi/common/regname_ex.h
Normal file
42
include/firm/pxi/common/regname_ex.h
Normal file
@ -0,0 +1,42 @@
|
||||
/*---------------------------------------------------------------------------*
|
||||
Project: TwlIPL - include - PXI
|
||||
File: regname.h
|
||||
|
||||
Copyright 2007 Nintendo. All rights reserved.
|
||||
|
||||
These coded instructions, statements, and computer programs contain
|
||||
proprietary information of Nintendo of America Inc. and/or Nintendo
|
||||
Company Ltd., and are protected by Federal copyright law. They may
|
||||
not be disclosed to third parties or copied or duplicated in any form,
|
||||
in whole or in part, without the prior written consent of Nintendo.
|
||||
|
||||
$Log: $
|
||||
$NoKeywords: $
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef FIRM_PXI_COMMON_REGNAME_EX_H_
|
||||
#define FIRM_PXI_COMMON_REGNAME_EX_H_
|
||||
|
||||
#include <twl/types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef SDK_ARM9
|
||||
|
||||
#define REG_PXI_FIFO_CNT_SEND_FULL_SHIFT REG_PXI_SUBP_FIFO_CNT_SEND_FULL_SHIFT
|
||||
#define REG_PXI_FIFO_CNT_RECV_EMP_SHIFT REG_PXI_SUBP_FIFO_CNT_RECV_EMP_SHIFT
|
||||
|
||||
#else // SDK_ARM7
|
||||
|
||||
#define REG_PXI_FIFO_CNT_SEND_FULL_SHIFT REG_PXI_MAINP_FIFO_CNT_SEND_FULL_SHIFT
|
||||
#define REG_PXI_FIFO_CNT_RECV_EMP_SHIFT REG_PXI_MAINP_FIFO_CNT_RECV_EMP_SHIFT
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
/* FIRM_PXI_COMMON_REGNAME_EX_H_ */
|
||||
#endif
|
||||
38
include/firm/sdmc.h
Normal file
38
include/firm/sdmc.h
Normal file
@ -0,0 +1,38 @@
|
||||
/*---------------------------------------------------------------------------*
|
||||
Project: TwlIPL - include - sdmc
|
||||
File: sdmc.h
|
||||
|
||||
Copyright 2007 Nintendo. All rights reserved.
|
||||
|
||||
These coded instructions, statements, and computer programs contain
|
||||
proprietary information of Nintendo of America Inc. and/or Nintendo
|
||||
Company Ltd., and are protected by Federal copyright law. They may
|
||||
not be disclosed to third parties or copied or duplicated in any form,
|
||||
in whole or in part, without the prior written consent of Nintendo.
|
||||
|
||||
$Date:: 2007-09-06$
|
||||
$Rev$
|
||||
$Author$
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef FIRM_SDMC_H_
|
||||
#define FIRM_SDMC_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef SDK_ARM9
|
||||
#else // SDK_ARM7
|
||||
#include <firm/devices/firm_sdmc/ARM7/sdif_ip.h>
|
||||
#include <firm/devices/firm_sdmc/ARM7/sdif_reg.h>
|
||||
#include <firm/devices/firm_sdmc/ARM7/sdmc.h>
|
||||
#include <firm/devices/firm_sdmc/ARM7/sdmc_config.h>
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
/* FIRM_SDMC_H_ */
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -40,3 +40,11 @@ Autoload DTCM
|
||||
Object $(OBJS_AUTOLOAD) (.bss)
|
||||
}
|
||||
|
||||
Ltdautoload LTDMAIN
|
||||
{
|
||||
# NITRO/TWL 共有のオーバーレイが在る場合は、さらにその後ろに配置する必要があります。
|
||||
After $(TARGET_NAME)
|
||||
Object * (.ltdmain)
|
||||
Object $(OBJS_LTDAUTOLOAD)
|
||||
Library $(GLTDLIBS)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user