Issue 118 fixed
Another fix for SDcard setup on ersky9x board which should be quicker to initialize.
This commit is contained in:
+10
-4
@@ -76,7 +76,7 @@ const char * audioFilenames[] = {
|
|||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
uint32_t sdAvailableAudioFiles;
|
uint32_t sdAvailableAudioFiles = (1 << AU_TADA);
|
||||||
|
|
||||||
#if defined(SDCARD)
|
#if defined(SDCARD)
|
||||||
// TODO enable the assert when it's C++
|
// TODO enable the assert when it's C++
|
||||||
@@ -91,14 +91,16 @@ void retrieveAvailableAudioFiles()
|
|||||||
assert(sizeof(sdAvailableAudioFiles)*8 > AU_FRSKY_FIRST);
|
assert(sizeof(sdAvailableAudioFiles)*8 > AU_FRSKY_FIRST);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
sdAvailableAudioFiles = 0;
|
uint32_t availableAudioFiles = 0;
|
||||||
|
|
||||||
for (uint32_t i=0; i<AU_FRSKY_FIRST; i++) {
|
for (uint32_t i=0; i<AU_FRSKY_FIRST; i++) {
|
||||||
strcpy(filename+sizeof(SYSTEM_SOUNDS_PATH), audioFilenames[i]);
|
strcpy(filename+sizeof(SYSTEM_SOUNDS_PATH), audioFilenames[i]);
|
||||||
strcat(filename+sizeof(SYSTEM_SOUNDS_PATH), SOUNDS_EXT);
|
strcat(filename+sizeof(SYSTEM_SOUNDS_PATH), SOUNDS_EXT);
|
||||||
if (f_stat(filename, &info) == FR_OK)
|
if (f_stat(filename, &info) == FR_OK)
|
||||||
sdAvailableAudioFiles |= ((uint32_t)1 << i);
|
availableAudioFiles |= ((uint32_t)1 << i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sdAvailableAudioFiles = availableAudioFiles;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,8 +170,11 @@ extern uint16_t Sine_values[];
|
|||||||
uint8_t pcmCodec;
|
uint8_t pcmCodec;
|
||||||
uint32_t pcmFreq = 8000;
|
uint32_t pcmFreq = 8000;
|
||||||
|
|
||||||
|
#ifndef SIMU
|
||||||
void audioTask(void* pdata)
|
void audioTask(void* pdata)
|
||||||
{
|
{
|
||||||
|
sdInit();
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
|
||||||
CoWaitForSingleFlag(audioFlag, 0);
|
CoWaitForSingleFlag(audioFlag, 0);
|
||||||
@@ -178,6 +183,7 @@ void audioTask(void* pdata)
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#define WAV_BUFFER_SIZE 512
|
#define WAV_BUFFER_SIZE 512
|
||||||
uint16_t wavSamplesArray[3*WAV_BUFFER_SIZE];
|
uint16_t wavSamplesArray[3*WAV_BUFFER_SIZE];
|
||||||
@@ -474,7 +480,7 @@ void AudioQueue::playFile(const char *filename, uint8_t flags, uint8_t id)
|
|||||||
printf("playFile(\"%s\")\n", filename); fflush(stdout);
|
printf("playFile(\"%s\")\n", filename); fflush(stdout);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!sd_card_mounted())
|
if (!CardIsConnected() || (Card_state != SD_ST_MOUNTED && Card_state != SD_ST_STARTUP))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
CoEnterMutexSection(audioMutex);
|
CoEnterMutexSection(audioMutex);
|
||||||
|
|||||||
@@ -497,6 +497,22 @@
|
|||||||
|
|
||||||
#define CardIsConnected() ( (PIOB->PIO_PDSR & PIO_PB7) == 0 )
|
#define CardIsConnected() ( (PIOB->PIO_PDSR & PIO_PB7) == 0 )
|
||||||
|
|
||||||
|
// States for initialising card
|
||||||
|
#define SD_ST_ERR -1
|
||||||
|
#define SD_ST_STARTUP 0
|
||||||
|
#define SD_ST_EMPTY 1
|
||||||
|
#define SD_ST_INIT1 2
|
||||||
|
#define SD_ST_INIT2 3
|
||||||
|
#define SD_ST_IDLE 4
|
||||||
|
#define SD_ST_READY 5
|
||||||
|
#define SD_ST_IDENT 6
|
||||||
|
#define SD_ST_STBY 7
|
||||||
|
#define SD_ST_TRAN 8
|
||||||
|
#define SD_ST_DATA 9
|
||||||
|
#define SD_ST_MOUNTED 10
|
||||||
|
|
||||||
|
extern int32_t Card_state;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#define BOARD_PSRAM_PINS PIN_EBI_DATA_BUS, PIN_EBI_NCS0, PIN_EBI_NRD, PIN_EBI_NWE, \
|
#define BOARD_PSRAM_PINS PIN_EBI_DATA_BUS, PIN_EBI_NCS0, PIN_EBI_NRD, PIN_EBI_NWE, \
|
||||||
PIN_EBI_PSRAM_ADDR_BUS, PIN_EBI_PSRAM_NBS, PIN_EBI_A1
|
PIN_EBI_PSRAM_ADDR_BUS, PIN_EBI_PSRAM_NBS, PIN_EBI_A1
|
||||||
|
|||||||
+14
-31
@@ -66,23 +66,10 @@
|
|||||||
/** SDIO Combo, with SDHC embedded (0xB) */
|
/** SDIO Combo, with SDHC embedded (0xB) */
|
||||||
#define CARD_SDHCCOMBO (CARD_TYPE_bmSDIO|CARD_SDHC)
|
#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
|
|
||||||
#define SD_ST_IDLE 3
|
|
||||||
#define SD_ST_READY 4
|
|
||||||
#define SD_ST_IDENT 5
|
|
||||||
#define SD_ST_STBY 6
|
|
||||||
#define SD_ST_TRAN 7
|
|
||||||
#define SD_ST_DATA 8
|
|
||||||
#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] ;
|
||||||
int32_t Card_state = SD_ST_EMPTY ;
|
int32_t Card_state = SD_ST_STARTUP ;
|
||||||
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 ;
|
||||||
@@ -814,6 +801,9 @@ void retrieveAvailableAudioFiles();
|
|||||||
|
|
||||||
void sdPoll10mS()
|
void sdPoll10mS()
|
||||||
{
|
{
|
||||||
|
if (Card_state == SD_ST_STARTUP)
|
||||||
|
return;
|
||||||
|
|
||||||
if (!CardIsConnected()) {
|
if (!CardIsConnected()) {
|
||||||
Card_state = SD_ST_EMPTY;
|
Card_state = SD_ST_EMPTY;
|
||||||
Sd_rca = 0;
|
Sd_rca = 0;
|
||||||
@@ -879,52 +869,45 @@ void sdInit()
|
|||||||
Sd_rca = 0;
|
Sd_rca = 0;
|
||||||
sdErrorCount = 0;
|
sdErrorCount = 0;
|
||||||
|
|
||||||
Card_state = SD_ST_EMPTY;
|
if (!CardIsConnected()) {
|
||||||
if (!CardIsConnected())
|
Card_state = SD_ST_EMPTY;
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Card_state = SD_ST_INIT1;
|
|
||||||
sdCmd0();
|
sdCmd0();
|
||||||
|
|
||||||
Card_state = SD_ST_INIT2;
|
|
||||||
sdCmd8(1);
|
sdCmd8(1);
|
||||||
|
|
||||||
Card_state = SD_ST_IDLE;
|
|
||||||
sdMemInit(1, &Cmd_A41_resp);
|
sdMemInit(1, &Cmd_A41_resp);
|
||||||
|
|
||||||
Card_state = SD_ST_READY;
|
|
||||||
uint8_t retry;
|
uint8_t retry;
|
||||||
for (retry=0; retry<10; retry++) {
|
for (retry=0; retry<10; retry++) {
|
||||||
if (!sdCmd2()) break;
|
if (!sdCmd2()) break;
|
||||||
CoTickDelay(1); // 2ms
|
CoTickDelay(1); // 2ms
|
||||||
}
|
}
|
||||||
|
|
||||||
if (retry == 10)
|
if (retry == 10) {
|
||||||
|
Card_state = SD_ST_READY;
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
Card_state = SD_ST_IDENT;
|
|
||||||
|
|
||||||
for (retry=0; retry<10; retry++) {
|
for (retry=0; retry<10; retry++) {
|
||||||
if (!sdCmd3()) break;
|
if (!sdCmd3()) break;
|
||||||
CoTickDelay(1); // 2ms
|
CoTickDelay(1); // 2ms
|
||||||
}
|
}
|
||||||
|
|
||||||
if (retry == 10)
|
if (retry == 10) {
|
||||||
|
Card_state = SD_ST_IDENT;
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Card_state = SD_ST_STBY;
|
|
||||||
sdCmd9();
|
sdCmd9();
|
||||||
sdCmd7(); // Select Card
|
sdCmd7(); // Select Card
|
||||||
|
|
||||||
Card_state = SD_ST_TRAN;
|
|
||||||
sdAcmd51();
|
sdAcmd51();
|
||||||
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;
|
|
||||||
|
|
||||||
f_mount(0, &g_FATFS_Obj);
|
f_mount(0, &g_FATFS_Obj);
|
||||||
retrieveAvailableAudioFiles();
|
retrieveAvailableAudioFiles();
|
||||||
|
|
||||||
Card_state = SD_ST_MOUNTED;
|
Card_state = SD_ST_MOUNTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -745,7 +745,6 @@ void menuProcTrainer(uint8_t event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extern uint32_t Card_state;
|
|
||||||
void menuProcDiagVers(uint8_t event)
|
void menuProcDiagVers(uint8_t event)
|
||||||
{
|
{
|
||||||
SIMPLE_MENU(STR_MENUVERSION, menuTabDiag, e_Vers, 1);
|
SIMPLE_MENU(STR_MENUVERSION, menuTabDiag, e_Vers, 1);
|
||||||
|
|||||||
+15
-13
@@ -2234,7 +2234,7 @@ char userDataDisplayBuf[TELEM_SCREEN_BUFFER_SIZE];
|
|||||||
ACTIVE_MIXES_TYPE activeMixes;
|
ACTIVE_MIXES_TYPE activeMixes;
|
||||||
#endif
|
#endif
|
||||||
int32_t sum_chans512[NUM_CHNOUT] = {0};
|
int32_t sum_chans512[NUM_CHNOUT] = {0};
|
||||||
inline void doMixerCalculations(uint16_t tmr10ms, uint8_t tick10ms)
|
inline void doMixerCalculations(tmr10ms_t tmr10ms, uint8_t tick10ms)
|
||||||
{
|
{
|
||||||
#ifdef BOLD_FONT
|
#ifdef BOLD_FONT
|
||||||
activeMixes = 0;
|
activeMixes = 0;
|
||||||
@@ -2347,11 +2347,11 @@ inline void doMixerCalculations(uint16_t tmr10ms, uint8_t tick10ms)
|
|||||||
val += RESX;
|
val += RESX;
|
||||||
val /= (RESX/16); // calibrate it
|
val /= (RESX/16); // calibrate it
|
||||||
|
|
||||||
static uint16_t s_time_tot;
|
static tmr10ms_t s_time_tot;
|
||||||
static uint8_t s_cnt_1s;
|
static uint8_t s_cnt_1s;
|
||||||
static uint16_t s_sum_1s;
|
static uint16_t s_sum_1s;
|
||||||
#if defined(THRTRACE)
|
#if defined(THRTRACE)
|
||||||
static uint16_t s_time_trace;
|
static tmr10ms_t s_time_trace;
|
||||||
static uint16_t s_cnt_10s;
|
static uint16_t s_cnt_10s;
|
||||||
static uint16_t s_sum_10s;
|
static uint16_t s_sum_10s;
|
||||||
#endif
|
#endif
|
||||||
@@ -2359,7 +2359,7 @@ inline void doMixerCalculations(uint16_t tmr10ms, uint8_t tick10ms)
|
|||||||
s_cnt_1s++;
|
s_cnt_1s++;
|
||||||
s_sum_1s += val;
|
s_sum_1s += val;
|
||||||
|
|
||||||
if ((uint16_t)(tmr10ms - s_time_tot) >= 100) { // 1sec
|
if ((tmr10ms_t)(tmr10ms - s_time_tot) >= 100) { // 1sec
|
||||||
s_time_tot += 100;
|
s_time_tot += 100;
|
||||||
s_timeCumTot += 1;
|
s_timeCumTot += 1;
|
||||||
|
|
||||||
@@ -2371,7 +2371,7 @@ inline void doMixerCalculations(uint16_t tmr10ms, uint8_t tick10ms)
|
|||||||
s_cnt_10s += s_cnt_1s;
|
s_cnt_10s += s_cnt_1s;
|
||||||
s_sum_10s += s_sum_1s;
|
s_sum_10s += s_sum_1s;
|
||||||
|
|
||||||
if ((uint16_t)(tmr10ms - s_time_trace) >= 1000) {// 10sec
|
if ((tmr10ms_t)(tmr10ms - s_time_trace) >= 1000) {// 10sec
|
||||||
s_time_trace += 1000;
|
s_time_trace += 1000;
|
||||||
val = s_sum_10s / s_cnt_10s;
|
val = s_sum_10s / s_cnt_10s;
|
||||||
s_sum_10s = 0;
|
s_sum_10s = 0;
|
||||||
@@ -2531,7 +2531,7 @@ void perMain()
|
|||||||
{
|
{
|
||||||
static tmr10ms_t lastTMR;
|
static tmr10ms_t lastTMR;
|
||||||
tmr10ms_t tmr10ms = get_tmr10ms();
|
tmr10ms_t tmr10ms = get_tmr10ms();
|
||||||
uint8_t tick10ms = (tmr10ms > lastTMR ? tmr10ms - lastTMR : 1);
|
uint8_t tick10ms = (tmr10ms >= lastTMR ? tmr10ms - lastTMR : 1);
|
||||||
lastTMR = tmr10ms;
|
lastTMR = tmr10ms;
|
||||||
|
|
||||||
#if defined(PCBSTD) || defined(SIMU)
|
#if defined(PCBSTD) || defined(SIMU)
|
||||||
@@ -2747,7 +2747,7 @@ ISR(TIMER5_COMPA_vect, ISR_NOBLOCK) // mixer interrupt
|
|||||||
|
|
||||||
static tmr10ms_t lastTMR;
|
static tmr10ms_t lastTMR;
|
||||||
tmr10ms_t tmr10ms = get_tmr10ms();
|
tmr10ms_t tmr10ms = get_tmr10ms();
|
||||||
uint8_t tick10ms = (tmr10ms > lastTMR ? tmr10ms - lastTMR : 1);
|
uint8_t tick10ms = (tmr10ms >= lastTMR ? tmr10ms - lastTMR : 1);
|
||||||
lastTMR = tmr10ms;
|
lastTMR = tmr10ms;
|
||||||
|
|
||||||
if (s_current_protocol < PROTO_NONE) {
|
if (s_current_protocol < PROTO_NONE) {
|
||||||
@@ -3121,11 +3121,7 @@ inline void open9xInit(OPEN9X_INIT_ARGS)
|
|||||||
if (g_eeGeneral.backlightMode != e_backlight_mode_off) backlightOn(); // on Tx start turn the light on
|
if (g_eeGeneral.backlightMode != e_backlight_mode_off) backlightOn(); // on Tx start turn the light on
|
||||||
|
|
||||||
if (!UNEXPECTED_SHUTDOWN()) {
|
if (!UNEXPECTED_SHUTDOWN()) {
|
||||||
#if defined(PCBARM)
|
#if 0
|
||||||
lcd_clear();
|
|
||||||
refreshDisplay();
|
|
||||||
sdInit();
|
|
||||||
#elif 0
|
|
||||||
// defined(PCBSTD) && defined(VOICE) && !defined(SPLASH)
|
// defined(PCBSTD) && defined(VOICE) && !defined(SPLASH)
|
||||||
lcd_clear();
|
lcd_clear();
|
||||||
lcd_putsAtt(20, 28, PSTR("Open9x..."), DBLSIZE);
|
lcd_putsAtt(20, 28, PSTR("Open9x..."), DBLSIZE);
|
||||||
@@ -3136,6 +3132,12 @@ inline void open9xInit(OPEN9X_INIT_ARGS)
|
|||||||
|
|
||||||
doSplash();
|
doSplash();
|
||||||
|
|
||||||
|
#if defined(PCBARM)
|
||||||
|
while (Card_state == SD_ST_STARTUP) {
|
||||||
|
CoTickDelay(1); // 2ms
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#if !defined(PCBARM)
|
#if !defined(PCBARM)
|
||||||
checkLowEEPROM();
|
checkLowEEPROM();
|
||||||
#endif
|
#endif
|
||||||
@@ -3181,7 +3183,7 @@ void mixerTask(void * pdata)
|
|||||||
|
|
||||||
static tmr10ms_t lastTMR;
|
static tmr10ms_t lastTMR;
|
||||||
tmr10ms_t tmr10ms = get_tmr10ms();
|
tmr10ms_t tmr10ms = get_tmr10ms();
|
||||||
uint8_t tick10ms = (tmr10ms > lastTMR ? tmr10ms - lastTMR : 1);
|
uint8_t tick10ms = (tmr10ms >= lastTMR ? tmr10ms - lastTMR : 1);
|
||||||
lastTMR = tmr10ms;
|
lastTMR = tmr10ms;
|
||||||
|
|
||||||
if (s_current_protocol < PROTO_NONE) {
|
if (s_current_protocol < PROTO_NONE) {
|
||||||
|
|||||||
+1
-1
@@ -394,5 +394,5 @@ FRESULT f_getcwd (TCHAR *path, UINT sz_path)
|
|||||||
return FR_OK;
|
return FR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t Card_state = 8;
|
int32_t Card_state = SD_ST_MOUNTED;
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user