[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;
UINT written;
if (!sd_card_mounted()) {
return STR_NO_SDCARD;
}
// check and create folder here
strcpy(buf, STR_MODELS_PATH);
FRESULT result = f_opendir(&archiveFolder, buf);
@@ -992,6 +996,10 @@ const pm_char * eeRestoreModel(uint8_t i_fileDst, char *model_name)
FIL restoreFile;
UINT read;
if (!sd_card_mounted()) {
return STR_NO_SDCARD;
}
strcpy(buf, STR_MODELS_PATH);
buf[sizeof(MODELS_PATH)-1] = '/';
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);
#endif
if (!sd_card_mounted())
return;
CoEnterMutexSection(audioMutex);
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)
// States for initialising card
#define SD_ST_ERR -1
#define SD_ST_EMPTY 0
#define SD_ST_INIT1 1
#define SD_ST_INIT2 2
@@ -76,12 +77,12 @@
#define SD_ST_STBY 6
#define SD_ST_TRAN 7
#define SD_ST_DATA 8
#define SD_ST_ERR 9
#define SD_ST_MOUNTED 9
uint32_t Card_ID[4] ;
uint32_t Card_SCR[2] ;
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_rca ;
uint32_t Cmd_8_resp ;
@@ -857,11 +858,15 @@ void sdPoll10mS()
case SD_ST_TRAN:
sdAcmd51();
Card_state = SD_ST_DATA;
sdAcmd6(); // Set bus width to 4 bits, and speed to 9 MHz
// Should check the card can do this ****
Card_state = SD_ST_DATA;
break;
case SD_ST_DATA:
f_mount(0, &g_FATFS_Obj);
retrieveAvailableAudioFiles();
Card_state = SD_ST_MOUNTED;
break;
case SD_ST_ERR:
@@ -873,14 +878,12 @@ void sdPoll10mS()
// returns 1 for YES, 0 for NO
uint32_t sd_card_ready( void )
{
if ( CardIsConnected() )
{
if ( Card_state == SD_ST_DATA )
{
return 1 ;
}
}
return 0 ;
return CardIsConnected() && Card_state >= SD_ST_DATA;
}
uint32_t sd_card_mounted( void )
{
return CardIsConnected() && Card_state == SD_ST_MOUNTED;
}
uint32_t sd_cmd16()
@@ -917,8 +920,7 @@ uint32_t sd_read_block(uint32_t block_no, uint32_t *data)
CoEnterMutexSection(sdMutex);
if (Card_state == SD_ST_DATA) {
if (CardIsConnected()) {
if (sd_card_ready()) {
sd_cmd16();
// Block size = 512, nblocks = 1
phsmci->HSMCI_BLKR = ((512) << 16) | 1;
@@ -937,8 +939,6 @@ uint32_t sd_read_block(uint32_t block_no, uint32_t *data)
break;
}
}
}
}
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);
if (Card_state == SD_ST_DATA) {
if (CardIsConnected()) {
if (sd_card_ready()) {
sd_cmd16();
// Block size = 512, nblocks = 1
phsmci->HSMCI_BLKR = ((512) << 16) | 1;
@@ -974,8 +973,6 @@ uint32_t sd_write_block( uint32_t block_no, uint32_t *data )
break;
}
}
}
}
phsmci->HSMCI_MR &= ~(uint32_t)HSMCI_MR_PDCMODE;
+1 -1
View File
@@ -133,7 +133,7 @@ void writeLogs()
lastLogTime = tmr10ms;
if (!g_oLogFile.fs) {
if (openLogs())
if (!sd_card_mounted() || openLogs())
return;
}
+11
View File
@@ -70,5 +70,16 @@ inline const pm_char *SDCARD_ERROR(FRESULT result)
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