X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fdrivers%2Fao_sdcard.c;h=7806bc194a6b910d946498d5a95c66bd258933ed;hb=fb0fb6f4beab484e7fe55b39d18c1f19778f1211;hp=6314a30c95f876ce4a196208693b59261cc1b25f;hpb=96c32125a780ad6b39c015f4abbae07fead68582;p=fw%2Faltos diff --git a/src/drivers/ao_sdcard.c b/src/drivers/ao_sdcard.c index 6314a30c..7806bc19 100644 --- a/src/drivers/ao_sdcard.c +++ b/src/drivers/ao_sdcard.c @@ -18,11 +18,18 @@ #include "ao.h" #include "ao_sdcard.h" +#if HAS_RADIO extern uint8_t ao_radio_mutex; +#define get_radio() ao_mutex_get(&ao_radio_mutex) +#define put_radio() ao_mutex_put(&ao_radio_mutex) +#else +#define get_radio() +#define put_radio() +#endif -#define ao_sdcard_get_slow() do { ao_mutex_get(&ao_radio_mutex); ao_spi_get(AO_SDCARD_SPI_BUS, AO_SPI_SPEED_250kHz); } while (0) -#define ao_sdcard_get() do { ao_mutex_get(&ao_radio_mutex); ao_spi_get(AO_SDCARD_SPI_BUS, AO_SPI_SPEED_FAST); } while (0) -#define ao_sdcard_put() do { ao_spi_put(AO_SDCARD_SPI_BUS); ao_mutex_put(&ao_radio_mutex); } while (0) +#define ao_sdcard_get_slow() do { get_radio(); ao_spi_get(AO_SDCARD_SPI_BUS, AO_SPI_SPEED_250kHz); } while (0) +#define ao_sdcard_get() do { get_radio(); ao_spi_get(AO_SDCARD_SPI_BUS, AO_SPI_SPEED_FAST); } while (0) +#define ao_sdcard_put() do { ao_spi_put(AO_SDCARD_SPI_BUS); put_radio(); } while (0) #define ao_sdcard_send_fixed(d,l) ao_spi_send_fixed((d), (l), AO_SDCARD_SPI_BUS) #define ao_sdcard_send(d,l) ao_spi_send((d), (l), AO_SDCARD_SPI_BUS) #define ao_sdcard_recv(d,l) ao_spi_recv((d), (l), AO_SDCARD_SPI_BUS) @@ -346,14 +353,16 @@ ao_sdcard_setup(void) sdver2 = 1; } - for (i = 0; i < SDCARD_IDLE_RETRY; i++) { + for (i = 0; i < SDCARD_OP_COND_RETRY; i++) { + ao_delay(AO_MS_TO_TICKS(10)); ret = ao_sdcard_app_send_op_cond(arg); if (ret != SDCARD_STATUS_IDLE_STATE) break; } if (ret != SDCARD_STATUS_READY_STATE) { /* MMC */ - for (i = 0; i < SDCARD_IDLE_RETRY; i++) { + for (i = 0; i < SDCARD_OP_COND_RETRY; i++) { + ao_delay(AO_MS_TO_TICKS(10)); ret = ao_sdcard_send_op_cond(); if (ret != SDCARD_STATUS_IDLE_STATE) break;