fix SD driver

git-svn-id: file:///Users/lillianskinner/Downloads/platinum/twl/twl_wrapsdk/trunk@123 4ee2a332-4b2b-5046-8439-1ba90f034370
This commit is contained in:
shirait 2007-06-18 05:55:12 +00:00
parent c187ba2396
commit 4302bb8d5b
4 changed files with 73 additions and 35 deletions

View File

@ -1,8 +1,8 @@
/*
Project: CTR SD port driver
File: Carddrv.c
File: sdmc.c
2006, Research and Development Department, Nintendo.
2006-2007, Research and Development Department, Nintendo.
*/
#include <twl.h>
@ -22,7 +22,9 @@
#else
#define PRINTDEBUG( ...) ((void)0)
#endif*/
#define PRINTDEBUG OS_TPrintf
// #define PRINTDEBUG OS_TPrintf
#define PRINTDEBUG( ...) ((void)0)
/***********************************************************************
@ -30,7 +32,7 @@
***********************************************************************/
#define SD_STACK_SIZE (4096*2)
#define SD_THREAD_PRIO (10)
#define SD_INTR_THREAD_PRIO (SD_THREAD_PRIO + 1)
#define SD_INTR_THREAD_PRIO (SD_THREAD_PRIO - 1)
#define SD_OPERATION_INIT (0)
#define SD_OPERATION_READ (1)
@ -65,9 +67,10 @@ OSMessageQueue sdmc_result_dtq;
OSMessage sdmc_result_dtq_array[1];
OSAlarm sdmc_alm;
OSThread sdmc_intr_tsk;
OSThreadQueue sdmc_tsk_q;
#endif
u16 sdmc_wakeup_count = 0; //OS_WakeupThreadのキューイング代わり
#if (TARGET_OS_CTR == 1)
#else
u64 sd_stack[SD_STACK_SIZE / sizeof(u64)];
@ -382,7 +385,7 @@ void SDCARD_irq_Handler( void)
#else
PRINTDEBUG( "SD irq!\n");
OS_SetIrqCheckFlag( OS_IE_SD);
//TODO! OS_WakeupThreadDirect( &sdmc_intr_tsk);
// OS_WakeupThreadDirect( &sdmc_intr_tsk);
#endif
}
@ -525,9 +528,6 @@ SDMC_ERR_CODE sdmcInit(void (*func1)(),void (*func2)())
(sd_intr_stack+SD_STACK_SIZE / sizeof(u64)), SD_STACK_SIZE, SD_INTR_THREAD_PRIO);
OS_WakeupThreadDirect( &sdmc_intr_tsk);
PRINTDEBUG( "sdmc_intr_tsk:0x%x\n", &sdmc_intr_tsk);
/* スレッドキューの初期化 */
OS_InitThreadQueue( &sdmc_tsk_q);
/*----------------------------*/
#endif
/**/
@ -1276,8 +1276,15 @@ static SDMC_ERR_CODE SDCARDi_Read(void* buf,u32 bufsize,u32 offset,void(*func)(v
//can_wup( 0);
slp_tsk();
#else
// OS_SleepThread( NULL);
OS_SleepThread( &sdmc_tsk_q);
/*--------------------*/
OS_DisableInterrupts();
if( sdmc_wakeup_count == 0) {
OS_SleepThread( NULL);
}else{
sdmc_wakeup_count--;
}
OS_EnableInterrupts();
/*--------------------*/
#endif
PRINTDEBUG( "waked\n");
@ -1664,8 +1671,8 @@ static void SDCARD_Timer_irq(void* arg)
iwup_tsk( sdmc_tsk_id);
PRINTDEBUG( "id : 0x%x\n", sdmc_tsk_id);
#else
// OS_WakeupThreadDirect( &sdmc_tsk);
OS_WakeupThread( &sdmc_tsk_q);
sdmc_wakeup_count++;
OS_WakeupThreadDirect( &sdmc_tsk);
#endif
}
@ -1728,8 +1735,15 @@ static u16 i_sdmcSendSCR(void)
//can_wup( 0);
slp_tsk();
#else
// OS_SleepThread( NULL);
OS_SleepThread( &sdmc_tsk_q);
/*--------------------*/
OS_DisableInterrupts();
if( sdmc_wakeup_count == 0) {
OS_SleepThread( NULL);
}else{
sdmc_wakeup_count--;
}
OS_EnableInterrupts();
/*--------------------*/
#endif
PRINTDEBUG( "waked\n");
thread_flag = FALSE;
@ -1886,8 +1900,15 @@ static u16 SDCARD_SD_Status(void)
//can_wup( 0);
slp_tsk();
#else
// OS_SleepThread( NULL);
OS_SleepThread( &sdmc_tsk_q);
/*--------------------*/
OS_DisableInterrupts();
if( sdmc_wakeup_count == 0) {
OS_SleepThread( NULL);
}else{
sdmc_wakeup_count--;
}
OS_EnableInterrupts();
/*--------------------*/
#endif
PRINTDEBUG( "waked\n");
thread_flag = FALSE;
@ -2356,8 +2377,15 @@ static u16 i_sdmcGetResid(u32 *pResid)
// can_wup( 0);
slp_tsk();
#else
// OS_SleepThread( NULL);
OS_SleepThread( &sdmc_tsk_q);
/*--------------------*/
OS_DisableInterrupts();
if( sdmc_wakeup_count == 0) {
OS_SleepThread( NULL);
}else{
sdmc_wakeup_count--;
}
OS_EnableInterrupts();
/*--------------------*/
#endif
PRINTDEBUG( "waked\n");
thread_flag = FALSE;
@ -2636,19 +2664,19 @@ static void SDCARD_Intr_Thread( void* arg)
while( 1) {
PRINTDEBUG( "next_tsk:0x%x\n", OS_SelectThread());
PRINTDEBUG( "Slp sdIntr\n");
#if (TARGET_OS_CTR == 1)
slp_tsk();
#else
OS_WaitIrq( FALSE, OS_IE_SD);
enabled = OS_DisableInterrupts();
(void)OS_ClearIrqCheckFlag( OS_IE_SD);
/*SD割り込みのIF解除*/
*(vu16*)CTR_INT_IF = CTR_IE_SD_MASK;
(void)OS_RestoreInterrupts( enabled);
//TODO! OS_SleepThread( NULL);
#endif
PRINTDEBUG( "sdIntr waked\n");
/*SD割り込みのIF解除*/
*(vu16*)CTR_INT_IF = CTR_IE_SD_MASK;
/*--- FIFOðŽg¤Æ« ---*/
if( SDCARD_UseFifoFlag) {
@ -2687,8 +2715,8 @@ static void SDCARD_Intr_Thread( void* arg)
wup_tsk( sdmc_tsk_id);
PRINTDEBUG( "id : 0x%x\n", sdmc_tsk_id);
#else
// OS_WakeupThreadDirect( &sdmc_tsk);
OS_WakeupThread( &sdmc_tsk_q);
sdmc_wakeup_count++;
OS_WakeupThreadDirect( &sdmc_tsk);
#endif
}
}
@ -2730,8 +2758,8 @@ static void SDCARD_Intr_Thread( void* arg)
wup_tsk( sdmc_tsk_id);
PRINTDEBUG( "id : 0x%x\n", sdmc_tsk_id);
#else
// OS_WakeupThreadDirect( &sdmc_tsk);
OS_WakeupThread( &sdmc_tsk_q);
sdmc_wakeup_count++;
OS_WakeupThreadDirect( &sdmc_tsk);
#endif
}
}
@ -2773,8 +2801,8 @@ static void SDCARD_Intr_Thread( void* arg)
wup_tsk( sdmc_tsk_id);
PRINTDEBUG( "id : 0x%x\n", sdmc_tsk_id);
#else
// OS_WakeupThreadDirect( &sdmc_tsk);
OS_WakeupThread( &sdmc_tsk_q);
sdmc_wakeup_count++;
OS_WakeupThreadDirect( &sdmc_tsk);
#endif
}
}

View File

@ -125,7 +125,6 @@ static void i_rtfsInit( DDRIVE* pdr)
{
byte drname[8]; /* Temp buffer for displaying drive letters as strings */
/* WARMSTART */
if( pdr->dev_table_drive_io) {
prtfs_cfg->drno_to_dr_map[pdr->driveno] = pdr; /* MAPS DRIVE structure to DRIVE: */

View File

@ -29,7 +29,7 @@ TARGET_BIN = main.axf
SRCS = main.c
INCDIR += $(TWLSDK_ROOT)/include/twl \
$(TWLSDK_ROOT)/include/twl/devices/rom_sdmc/ARM7 \
$(TWLSDK_ROOT)/include/twl/devices/sdmc/ARM7 \
$(TWLSDK_ROOT)/include/twl/fatfs/ARM7 \
LLIBRARY_DIRS = $(TWLSDK_ROOT)/lib/ARM-BB/Release

View File

@ -98,14 +98,24 @@ void TwlSpMain(void)
/**/
PRINTDEBUG("Sample program starts.\n");
// rtfs_init();
{
OSHeapHandle hh;
OS_SetSubPrivArenaLo( OS_InitAlloc( OS_ARENA_MAIN_SUBPRIV, OS_GetSubPrivArenaLo(), OS_GetSubPrivArenaHi(), 1));
hh = OS_CreateHeap( OS_ARENA_MAIN_SUBPRIV, OS_GetSubPrivArenaLo(), OS_GetSubPrivArenaHi());
OS_SetCurrentHeap( OS_ARENA_MAIN_SUBPRIV, hh);
if( rtfs_init() == FALSE) {
PRINTDEBUG( "rtfs_init failed.\n");
}else{
PRINTDEBUG( "rtfs_init success.\n");
}
}
MI_DmaFill32( 2, BlockBuf, 0x55AA55AA, 512*3);
MI_DmaFill32( 2, BlockBuf2, 0x00FF00FF, 512*3);
/*SDドライバ初期化*/
result = sdmcInit( SDMC_NOUSE_DMA, NULL, NULL);
if( result != 0) {
if( result != SDMC_NORMAL) {
PRINTDEBUG( "sdmcInit : failed\n");
while( 1) {};
}else{
@ -135,7 +145,7 @@ void TwlSpMain(void)
PRINTDEBUG( "sdmcReadFifo success.\n");
}
/*----------------------------*/
#else
//#else
/*NANDからブロックライトリード*/
result = sdmcSelect( (u16)SDMC_PORT_NAND);
if( result != 0) {
@ -163,7 +173,8 @@ void TwlSpMain(void)
#endif
/*デバイスドライバの登録*/
/* if( sdmcRtfsAttach( 4) == FALSE) { //sdmcをEドライブにする
PRINTDEBUG( "attach start\n");
if( sdmcRtfsAttach( 4) == FALSE) { //sdmcðEƒhƒ‰ƒCƒuÉ·é
PRINTDEBUG( "sdmcRtfsAttach failed.\n");
}else{
if( sdmcRtfsAttach( 4) == FALSE) {
@ -177,7 +188,7 @@ void TwlSpMain(void)
PRINTDEBUG( "pc_set_default_drive failed\n");
while( 1){};
}
PRINTDEBUG( "pc_set_default_drive success\n");*/
PRINTDEBUG( "pc_set_default_drive success\n");
PRINTDEBUG( "Sample program ends.\n");