[ersky9x] Radio blocked on start when playing a sound before SD card initialization end.

This commit is contained in:
bsongis
2012-07-27 17:52:03 +00:00
parent d2fabe2b2e
commit 174a7b29d9
5 changed files with 39 additions and 20 deletions
+8
View File
@@ -921,6 +921,10 @@ const pm_char * eeBackupModel(uint8_t i_fileSrc)
DIR archiveFolder; DIR archiveFolder;
UINT written; UINT written;
if (!sd_card_mounted()) {
return STR_NO_SDCARD;
}
// check and create folder here // check and create folder here
strcpy(buf, STR_MODELS_PATH); strcpy(buf, STR_MODELS_PATH);
FRESULT result = f_opendir(&archiveFolder, buf); FRESULT result = f_opendir(&archiveFolder, buf);
@@ -992,6 +996,10 @@ const pm_char * eeRestoreModel(uint8_t i_fileDst, char *model_name)
FIL restoreFile; FIL restoreFile;
UINT read; UINT read;
if (!sd_card_mounted()) {
return STR_NO_SDCARD;
}
strcpy(buf, STR_MODELS_PATH); strcpy(buf, STR_MODELS_PATH);
buf[sizeof(MODELS_PATH)-1] = '/'; buf[sizeof(MODELS_PATH)-1] = '/';
strcpy(&buf[sizeof(MODELS_PATH)], model_name); strcpy(&buf[sizeof(MODELS_PATH)], model_name);
+3
View File
@@ -462,6 +462,9 @@ void AudioQueue::playFile(const char *filename, uint8_t flags)
printf("playFile(\"%s\")\n", filename); fflush(stdout); printf("playFile(\"%s\")\n", filename); fflush(stdout);
#endif #endif
if (!sd_card_mounted())
return;
CoEnterMutexSection(audioMutex); CoEnterMutexSection(audioMutex);
uint8_t next_widx = (widx + 1) % AUDIO_QUEUE_LENGTH; uint8_t next_widx = (widx + 1) % AUDIO_QUEUE_LENGTH;
+16 -19
View File
@@ -67,6 +67,7 @@
#define CARD_SDHCCOMBO (CARD_TYPE_bmSDIO|CARD_SDHC) #define CARD_SDHCCOMBO (CARD_TYPE_bmSDIO|CARD_SDHC)
// States for initialising card // States for initialising card
#define SD_ST_ERR -1
#define SD_ST_EMPTY 0 #define SD_ST_EMPTY 0
#define SD_ST_INIT1 1 #define SD_ST_INIT1 1
#define SD_ST_INIT2 2 #define SD_ST_INIT2 2
@@ -76,12 +77,12 @@
#define SD_ST_STBY 6 #define SD_ST_STBY 6
#define SD_ST_TRAN 7 #define SD_ST_TRAN 7
#define SD_ST_DATA 8 #define SD_ST_DATA 8
#define SD_ST_ERR 9 #define SD_ST_MOUNTED 9
uint32_t Card_ID[4] ; uint32_t Card_ID[4] ;
uint32_t Card_SCR[2] ; uint32_t Card_SCR[2] ;
uint32_t Card_CSD[4] ; uint32_t Card_CSD[4] ;
uint32_t Card_state = SD_ST_EMPTY ; int32_t Card_state = SD_ST_EMPTY ;
uint32_t Sd_128_resp[4] ; uint32_t Sd_128_resp[4] ;
uint32_t Sd_rca ; uint32_t Sd_rca ;
uint32_t Cmd_8_resp ; uint32_t Cmd_8_resp ;
@@ -857,11 +858,15 @@ void sdPoll10mS()
case SD_ST_TRAN: case SD_ST_TRAN:
sdAcmd51(); sdAcmd51();
Card_state = SD_ST_DATA;
sdAcmd6(); // Set bus width to 4 bits, and speed to 9 MHz sdAcmd6(); // Set bus width to 4 bits, and speed to 9 MHz
// Should check the card can do this **** // Should check the card can do this ****
Card_state = SD_ST_DATA;
break;
case SD_ST_DATA:
f_mount(0, &g_FATFS_Obj); f_mount(0, &g_FATFS_Obj);
retrieveAvailableAudioFiles(); retrieveAvailableAudioFiles();
Card_state = SD_ST_MOUNTED;
break; break;
case SD_ST_ERR: case SD_ST_ERR:
@@ -873,14 +878,12 @@ void sdPoll10mS()
// returns 1 for YES, 0 for NO // returns 1 for YES, 0 for NO
uint32_t sd_card_ready( void ) uint32_t sd_card_ready( void )
{ {
if ( CardIsConnected() ) return CardIsConnected() && Card_state >= SD_ST_DATA;
{ }
if ( Card_state == SD_ST_DATA )
{ uint32_t sd_card_mounted( void )
return 1 ; {
} return CardIsConnected() && Card_state == SD_ST_MOUNTED;
}
return 0 ;
} }
uint32_t sd_cmd16() uint32_t sd_cmd16()
@@ -917,8 +920,7 @@ uint32_t sd_read_block(uint32_t block_no, uint32_t *data)
CoEnterMutexSection(sdMutex); CoEnterMutexSection(sdMutex);
if (Card_state == SD_ST_DATA) { if (sd_card_ready()) {
if (CardIsConnected()) {
sd_cmd16(); sd_cmd16();
// Block size = 512, nblocks = 1 // Block size = 512, nblocks = 1
phsmci->HSMCI_BLKR = ((512) << 16) | 1; phsmci->HSMCI_BLKR = ((512) << 16) | 1;
@@ -937,8 +939,6 @@ uint32_t sd_read_block(uint32_t block_no, uint32_t *data)
break; break;
} }
} }
}
} }
phsmci->HSMCI_MR &= ~(uint32_t)HSMCI_MR_PDCMODE; phsmci->HSMCI_MR &= ~(uint32_t)HSMCI_MR_PDCMODE;
@@ -954,8 +954,7 @@ uint32_t sd_write_block( uint32_t block_no, uint32_t *data )
CoEnterMutexSection(sdMutex); CoEnterMutexSection(sdMutex);
if (Card_state == SD_ST_DATA) { if (sd_card_ready()) {
if (CardIsConnected()) {
sd_cmd16(); sd_cmd16();
// Block size = 512, nblocks = 1 // Block size = 512, nblocks = 1
phsmci->HSMCI_BLKR = ((512) << 16) | 1; phsmci->HSMCI_BLKR = ((512) << 16) | 1;
@@ -974,8 +973,6 @@ uint32_t sd_write_block( uint32_t block_no, uint32_t *data )
break; break;
} }
} }
}
} }
phsmci->HSMCI_MR &= ~(uint32_t)HSMCI_MR_PDCMODE; phsmci->HSMCI_MR &= ~(uint32_t)HSMCI_MR_PDCMODE;
+1 -1
View File
@@ -133,7 +133,7 @@ void writeLogs()
lastLogTime = tmr10ms; lastLogTime = tmr10ms;
if (!g_oLogFile.fs) { if (!g_oLogFile.fs) {
if (openLogs()) if (!sd_card_mounted() || openLogs())
return; return;
} }
+11
View File
@@ -70,5 +70,16 @@ inline const pm_char *SDCARD_ERROR(FRESULT result)
extern void sdPoll10mS(); extern void sdPoll10mS();
#if defined(PCBARM)
extern "C" {
extern uint32_t sd_card_ready();
extern uint32_t sd_card_mounted();
}
#else
#define sd_card_ready() (true)
#define sd_card_mounted() (true)
#endif
#endif #endif