fix FATFS, SD driver and Sample

git-svn-id: file:///Users/lillianskinner/Downloads/platinum/twl/twl_wrapsdk/trunk@124 4ee2a332-4b2b-5046-8439-1ba90f034370
This commit is contained in:
shirait 2007-06-19 06:28:03 +00:00
parent 4302bb8d5b
commit dc822607ed
3 changed files with 81 additions and 125 deletions

View File

@ -40,6 +40,14 @@
#define SD_OPERATION_WRITE (3)
#define SD_OPERATION_WRITE_WITH_FIFO (4)
/*
TODO:
SD_INTR_THREAD_PRIOを高くしてSleepをなくせば動く
Sleepを使うにはWakeupの前にSleepさせるためSD_INTR_THREAD_PRIOを低く
Sleepの前にSD割り込みが入らなかった場合なぜかずっと
Sleepの前に割り込みが入れば動く
*/
/***********************************************************************
extern変数
@ -70,6 +78,7 @@ OSThread sdmc_intr_tsk;
#endif
u16 sdmc_wakeup_count = 0; //OS_WakeupThreadのキューイング代わり
u16 sdmc_intr_wakeup_count = 0;
#if (TARGET_OS_CTR == 1)
#else
@ -384,7 +393,9 @@ void SDCARD_irq_Handler( void)
iwup_tsk( sdmc_intr_tsk_id);
#else
PRINTDEBUG( "SD irq!\n");
// OS_DumpThreadList();
OS_SetIrqCheckFlag( OS_IE_SD);
// sdmc_intr_wakeup_count++;
// OS_WakeupThreadDirect( &sdmc_intr_tsk);
#endif
}
@ -787,8 +798,8 @@ PRINTDEBUG( "SD_INFO1_MASK : 0x%x\n", (*(vu32 *)(SD_IP_BASE + 0x20)));*/
SD_SendIfCond(); /* CMD8発行、レスポンス確認 */
if( !SDCARD_SDHCFlag) { /* SDHC以外は失敗してるはずなので */
SDCARD_ErrStatus = SDMC_NORMAL; /* エラーフラグをクリアしておく */
}
} //注:CMD8によりここで割り込みが入る
while(!(SDCARD_ErrStatus & SDMC_ERR_FPGA_TIMEOUT)){ /* タイムアウトになったら抜ける */
SD_ClrErr((u16)(~SDMC_ERR_FPGA_TIMEOUT));
@ -833,12 +844,10 @@ PRINTDEBUG( "SD_INFO1_MASK : 0x%x\n", (*(vu32 *)(SD_IP_BASE + 0x20)));*/
#if TIMEOUT
SDCARD_TimerStart(SDCARD_INITIAL_TIMEOUT); /* タイムアウト判定用タイマスタート */
#endif
SD_SendCID(); /* CMD2発行 レスポンス確認 */
if(SDCARD_ErrStatus){ /* エラーステータスの確認(エラー有り?) */
return SDCARD_ErrStatus;
}
while(1){
SD_SendRelativeAddr(); /* CMD3発行 レスポンス確認 正常終了時 RCA<-ResのRCA */
if(SDCARD_ErrStatus){ /* エラーステータスの確認(エラー有り?) */
@ -848,7 +857,6 @@ PRINTDEBUG( "SD_INFO1_MASK : 0x%x\n", (*(vu32 *)(SD_IP_BASE + 0x20)));*/
break;
}
}
/*------- standby state -------*/
SD_SendCSD(); /* CMD9発行 レスポンス確認 */
if(SDCARD_ErrStatus){ /* エラーステータスの確認(エラー有り?) */
@ -862,7 +870,6 @@ PRINTDEBUG( "SD_INFO1_MASK : 0x%x\n", (*(vu32 *)(SD_IP_BASE + 0x20)));*/
if(SDCARD_ErrStatus){ /* エラーステータスの確認(エラー有り?) */
return SDCARD_ErrStatus;
}
/* Command toggles acard between the Stand-by and Transfer states */
SD_SelectCard(); /* CMD7発行 レスポンス確認 */
if(SDCARD_ErrStatus){ /* エラーステータスの確認(エラー有り?) */
@ -1271,19 +1278,14 @@ static SDMC_ERR_CODE SDCARDi_Read(void* buf,u32 bufsize,u32 offset,void(*func)(v
/*--------------------------*/
/**/
PRINTDEBUG( "--Slp Tsk--\n");
PRINTDEBUG( "==Slp Tsk==\n");
#if (TARGET_OS_CTR == 1)
//can_wup( 0);
slp_tsk();
#else
/*--------------------*/
OS_DisableInterrupts();
if( sdmc_wakeup_count == 0) {
OS_SleepThread( NULL);
}else{
sdmc_wakeup_count--;
}
OS_EnableInterrupts();
// OS_TPrintf( "sleep %d\n", __LINE__);
// OS_SleepThread( NULL);
/*--------------------*/
#endif
PRINTDEBUG( "waked\n");
@ -1672,6 +1674,7 @@ static void SDCARD_Timer_irq(void* arg)
PRINTDEBUG( "id : 0x%x\n", sdmc_tsk_id);
#else
sdmc_wakeup_count++;
PRINTDEBUG( "wakeup\n");
OS_WakeupThreadDirect( &sdmc_tsk);
#endif
}
@ -1730,19 +1733,14 @@ static u16 i_sdmcSendSCR(void)
#if SCR
thread_flag = TRUE;
SD_SendSCR(); /* SCRの取得コマンド発行 */
PRINTDEBUG( "--Slp Tsk--\n");
PRINTDEBUG( "==Slp Tsk==\n");
#if (TARGET_OS_CTR == 1)
//can_wup( 0);
slp_tsk();
#else
/*--------------------*/
OS_DisableInterrupts();
if( sdmc_wakeup_count == 0) {
OS_SleepThread( NULL);
}else{
sdmc_wakeup_count--;
}
OS_EnableInterrupts();
// OS_TPrintf( "sleep %d\n", __LINE__);
// OS_SleepThread( NULL);
/*--------------------*/
#endif
PRINTDEBUG( "waked\n");
@ -1895,19 +1893,14 @@ static u16 SDCARD_SD_Status(void)
thread_flag = TRUE;
SD_SDStatus(); /* ACMD13 SD_STATUSの取得コマンド発行処理 */
PRINTDEBUG( "--Slp Tsk--\n");
PRINTDEBUG( "==Slp Tsk==\n");
#if (TARGET_OS_CTR == 1)
//can_wup( 0);
slp_tsk();
#else
/*--------------------*/
OS_DisableInterrupts();
if( sdmc_wakeup_count == 0) {
OS_SleepThread( NULL);
}else{
sdmc_wakeup_count--;
}
OS_EnableInterrupts();
// OS_TPrintf( "sleep %d\n", __LINE__);
// OS_SleepThread( NULL);
/*--------------------*/
#endif
PRINTDEBUG( "waked\n");
@ -2372,19 +2365,14 @@ static u16 i_sdmcGetResid(u32 *pResid)
/*--- ACMD22 ライト済みセクタ数取得コマンド発行 ---*/
SD_SendNumWRSectors();
/*-------------------------------------------------*/
PRINTDEBUG( "--Slp Tsk--\n");
PRINTDEBUG( "==Slp Tsk==\n");
#if (TARGET_OS_CTR == 1)
// can_wup( 0);
slp_tsk();
#else
/*--------------------*/
OS_DisableInterrupts();
if( sdmc_wakeup_count == 0) {
OS_SleepThread( NULL);
}else{
sdmc_wakeup_count--;
}
OS_EnableInterrupts();
// OS_TPrintf( "sleep %d\n", __LINE__);
// OS_SleepThread( NULL);
/*--------------------*/
#endif
PRINTDEBUG( "waked\n");
@ -2665,17 +2653,18 @@ static void SDCARD_Intr_Thread( void* arg)
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();
// OS_DisableIrqMask( OS_IE_SD);
// if( sdmc_intr_wakeup_count == 0) {
// OS_SleepThread( NULL);
// }
// sdmc_intr_wakeup_count--;
// OS_EnableIrqMask( 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);
#endif
// (void)OS_RestoreInterrupts( enabled);
PRINTDEBUG( "sdIntr waked\n");
/*--- FIFOを使うとき ---*/
@ -2685,82 +2674,42 @@ static void SDCARD_Intr_Thread( void* arg)
((!(*SDIF_CNT & SDIF_CNT_NEMP))&&(*SDIF_CNT & SDIF_CNT_FEIE))) {
PRINTDEBUG( ">>>SD Intr(FIFO)\n");// Full or Empty)\n");
#if (TARGET_OS_CTR == 1)
osDisableInterruptID( OS_INTR_ID_SD);
#else
OS_DisableIrqMask( OS_IE_SD);
#endif
SDCARD_FPGA_irq(); /*カードからのリードライト要求割り込み*/
#if (TARGET_OS_CTR == 1)
osEnableInterruptID( OS_INTR_ID_SD);
#else
OS_EnableIrqMask( OS_IE_SD);
#endif
/* FIFO割り込みとALLEND割り込みがほぼ同時の場合に対応 */
if( SD_CheckFPGAReg( sd_info1, SD_INFO1_ALL_END)) {
#if (TARGET_OS_CTR == 1)
osDisableInterruptID( OS_INTR_ID_SD);
#else
(void)OS_ClearIrqCheckFlag( OS_IE_SD);
/*SD割り込みのIF解除*/
*(vu16*)CTR_INT_IF = CTR_IE_SD_MASK;
OS_DisableIrqMask( OS_IE_SD);
#endif
SYSFPGA_irq();
#if (TARGET_OS_CTR == 1)
osEnableInterruptID( OS_INTR_ID_SD);
#else
OS_EnableIrqMask( OS_IE_SD);
#endif
if( thread_flag) {
PRINTDEBUG( "--Wup sdThread!--\n");
#if (TARGET_OS_CTR == 1)
wup_tsk( sdmc_tsk_id);
PRINTDEBUG( "id : 0x%x\n", sdmc_tsk_id);
#else
sdmc_wakeup_count++;
PRINTDEBUG( "wakeup\n");
OS_WakeupThreadDirect( &sdmc_tsk);
#endif
}
}
}else{
if( SD_CheckFPGAReg( SD_INFO2, (SD_INFO2_MASK_BRE | SD_INFO2_MASK_BWE))) {
PRINTDEBUG( ">>>SD Intr(R/W Req)\n");
PRINTDEBUG ( ">>>SD Intr(R/W Req)\n");
//ここで自動的にラッパーのFIFO<->SD_BUF0間で通信が行われる
// if((!(*SDIF_CNT & SDIF_CNT_NEMP))&&(*SDIF_CNT & SDIF_CNT_FEIE)) {
#if (TARGET_OS_CTR == 1)
osDisableInterruptID( OS_INTR_ID_SD);
#else
OS_DisableIrqMask( OS_IE_SD);
#endif
PRINTDEBUG( "begin\n");
SDCARD_FPGA_irq();
PRINTDEBUG( "end\n");
#if (TARGET_OS_CTR == 1)
osEnableInterruptID( OS_INTR_ID_SD);
#else
OS_EnableIrqMask( OS_IE_SD);
#endif
}else{
PRINTDEBUG( ">>>SD Intr(End or Err)\n");
#if (TARGET_OS_CTR == 1)
osDisableInterruptID( OS_INTR_ID_SD);
#else
OS_DisableIrqMask( OS_IE_SD);
#endif
SYSFPGA_irq(); /*完了またはエラー割り込み*/
#if (TARGET_OS_CTR == 1)
osEnableInterruptID( OS_INTR_ID_SD);
#else
OS_EnableIrqMask( OS_IE_SD);
#endif
/**/
if( thread_flag) {
PRINTDEBUG( "--Wup sdThread!--\n");
#if (TARGET_OS_CTR == 1)
wup_tsk( sdmc_tsk_id);
PRINTDEBUG( "id : 0x%x\n", sdmc_tsk_id);
#else
sdmc_wakeup_count++;
OS_WakeupThreadDirect( &sdmc_tsk);
#endif
}
}
}
@ -2768,42 +2717,19 @@ static void SDCARD_Intr_Thread( void* arg)
}else{
if( SD_CheckFPGAReg( SD_INFO2, (SD_INFO2_MASK_BRE | SD_INFO2_MASK_BWE))) {
PRINTDEBUG( ">>>SD Intr(R/W Req)\n");
#if (TARGET_OS_CTR == 1)
osDisableInterruptID( OS_INTR_ID_SD);
#else
OS_DisableIrqMask( OS_IE_SD);
#endif
PRINTDEBUG( "begin\n");
SDCARD_FPGA_irq(); /*カードからのリードライト要求割り込み*/
PRINTDEBUG( "end\n");
#if (TARGET_OS_CTR == 1)
osEnableInterruptID( OS_INTR_ID_SD);
#else
OS_EnableIrqMask( OS_IE_SD);
#endif
}else{
PRINTDEBUG( ">>>SD Intr(End or Err)\n");
#if (TARGET_OS_CTR == 1)
osDisableInterruptID( OS_INTR_ID_SD);
#else
PRINTDEBUG( ">>SD Intr(End or Err)\n");
OS_DisableIrqMask( OS_IE_SD);
#endif
SYSFPGA_irq(); /*完了またはエラー割り込み*/
#if (TARGET_OS_CTR == 1)
osEnableInterruptID( OS_INTR_ID_SD);
#else
OS_EnableIrqMask( OS_IE_SD);
#endif
/**/
if( thread_flag) {
PRINTDEBUG( "--Wup sdThread!--\n");
#if (TARGET_OS_CTR == 1)
wup_tsk( sdmc_tsk_id);
PRINTDEBUG( "id : 0x%x\n", sdmc_tsk_id);
#else
sdmc_wakeup_count++;
OS_WakeupThreadDirect( &sdmc_tsk);
#endif
}
}
}

View File

@ -52,10 +52,9 @@
#define PRINTDEBUG vlink_dos_printf
#endif
#else
#define PRINTDEBUG i_sdmc_no_print
static void i_sdmc_no_print( const char *fmt, ... );
static void i_sdmc_no_print( const char *fmt, ... ){ return; }
#endif
//#define PRINTDEBUG OS_TPrintf
#define PRINTDEBUG( ...) ((void)0)
/*--------------------*/
/* This routine takes no arguments and returns an unsigned long. The routine
@ -123,9 +122,11 @@ dword rtfs_port_alloc_mutex(void)
OSMutex* my_mtx;
my_mtx = (OSMutex*)OS_Alloc( sizeof( OSMutex));
if( my_mtx == NULL) {
PRINTDEBUG("fatfs : ERROR! Cannot create new mutex.\n");
return 0;
}
OS_InitMutex( my_mtx);
PRINTDEBUG( "CreateMutex:0x%x\n", my_mtx);
return( (dword)my_mtx);
#endif
}
@ -149,6 +150,7 @@ void rtfs_port_claim_mutex(dword handle)
// PRINTDEBUG( "fatfs : task[%d] lock mutex(%d).\n", mytskid, handle);
}
#else
PRINTDEBUG( "LockMutex:0x%x\n", handle);
OS_LockMutex( (OSMutex*)handle);
#endif
}
@ -173,8 +175,9 @@ void rtfs_port_release_mutex(dword handle)
// PRINTDEBUG( "fatfs : task[%d] release mutex(%d).\n", mytskid, handle);
}
#else
PRINTDEBUG( "ReleaseMutex:0x%x\n", handle);
OS_UnlockMutex( (OSMutex*)handle);
OS_Free( (OSMutex*)handle);
// OS_Free( (OSMutex*)handle);
#endif
}

View File

@ -66,9 +66,10 @@ void MY_SdTransferRewind( void)
*---------------------------------------------------------------------------*/
void TwlSpMain(void)
{
OSHeapHandle heapHandle;
SDMC_ERR_CODE result;
OSHeapHandle heapHandle;
SDMC_ERR_CODE result;
SdmcResultInfo SdResult;
PCFD fd;
// OS初期化
OS_Init();
@ -76,8 +77,6 @@ void TwlSpMain(void)
OS_InitTick();
OS_InitAlarm();
OS_InitThread();
// PXI初期化、ARM9と同期
PXI_Init();
@ -95,6 +94,8 @@ void TwlSpMain(void)
(void)OS_EnableIrq();
(void)OS_EnableInterrupts();
OS_InitThread();
/**/
PRINTDEBUG("Sample program starts.\n");
@ -124,7 +125,7 @@ void TwlSpMain(void)
#if 0
/*--- SDへブロックライトリード ---*/
result = sdmcSelect( (u16)SDMC_PORT_CARD);
// result = sdmcSelect( (u16)SDMC_PORT_CARD);
if( result != 0) {
PRINTDEBUG( "sdmcSelect failed.\n");
}else{
@ -145,7 +146,7 @@ void TwlSpMain(void)
PRINTDEBUG( "sdmcReadFifo success.\n");
}
/*----------------------------*/
//#else
#if 0
/*NANDからブロックライトリード*/
result = sdmcSelect( (u16)SDMC_PORT_NAND);
if( result != 0) {
@ -169,9 +170,10 @@ void TwlSpMain(void)
}else{
PRINTDEBUG( "sdmcReadFifoDirect success.\n");
}
#endif
/*----------------------------*/
#endif
#else
/*デバイスドライバの登録*/
PRINTDEBUG( "attach start\n");
if( sdmcRtfsAttach( 4) == FALSE) { //sdmcをEドライブにする
@ -190,6 +192,31 @@ void TwlSpMain(void)
}
PRINTDEBUG( "pc_set_default_drive success\n");
/**/
{
CHKDISK_STATS dstat;
pc_check_disk( (byte*)"E:", &dstat, 0, 1, 1);
PRINTDEBUG( "pc_check_disk end.\n");
}
/*----------*/
fd = po_open( (byte*)"\\sdmc_twl_test.bin", (PO_CREAT|PO_BINARY|PO_WRONLY), PS_IWRITE);
if( fd < 0) {
PRINTDEBUG( "po_open failed.\n");
while( 1) {};
}
PRINTDEBUG( "po_open success.\n");
/*----------*/
/*----------*/
if( po_close( fd) < 0) {
PRINTDEBUG( "po_close failed.\n");
while( 1) {};
}
PRINTDEBUG( "po_close success.\n");
/*----------*/
#endif
PRINTDEBUG( "Sample program ends.\n");