From d12cc995d567ff3c43af6e33a9eee5259c95e287 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 7 May 2011 19:33:47 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2925 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/platforms/STM32/sdc_lld.c | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/os/hal/platforms/STM32/sdc_lld.c b/os/hal/platforms/STM32/sdc_lld.c index cb6eb2099..1697c2964 100644 --- a/os/hal/platforms/STM32/sdc_lld.c +++ b/os/hal/platforms/STM32/sdc_lld.c @@ -59,6 +59,16 @@ CH_IRQ_HANDLER(SDIO_IRQHandler) { CH_IRQ_PROLOGUE(); + chSysLockFromIsr(); + if (SDCD1.thread != NULL) { + if ((SDIO->STA & SDIO_STA_DATAEND) != 0) + SDCD1.thread->p_u.rdymsg = RDY_OK; + else + SDCD1.thread->p_u.rdymsg = RDY_RESET; + chSchReadyI(SDCD1.thread); + SDCD1.thread = NULL; + } + chSysUnlockFromIsr(); CH_IRQ_EPILOGUE(); } @@ -320,8 +330,7 @@ bool_t sdc_lld_send_cmd_long_crc(SDCDriver *sdcp, uint8_t cmd, uint32_t arg, */ bool_t sdc_lld_read(SDCDriver *sdcp, uint32_t startblk, uint8_t *buf, uint32_t n) { - msg_t msg; - uint32_t sts, resp[1]; + uint32_t sta, resp[1]; /* Prepares the DMA channel for reading.*/ dmaChannelSetup(&STM32_DMA2->channels[STM32_DMA_CHANNEL_4], @@ -349,11 +358,24 @@ bool_t sdc_lld_read(SDCDriver *sdcp, uint32_t startblk, goto error; chSysLock(); - chDbgAssert(sdcp->thread == NULL, "sdc_lld_read_blocks(), #1", "not NULL"); - sdcp->thread = chThdSelf(); - chSchGoSleepS(THD_STATE_SUSPENDED); - chDbgAssert(sdcp->thread == NULL, "sdc_lld_read_blocks(), #2", "not NULL"); - msg = chThdSelf()->p_u.rdymsg; + sta = SDIO->STA; + if ((sta & SDIO_STA_DCRCFAIL | SDIO_STA_DTIMEOUT | + SDIO_STA_DATAEND | SDIO_STA_STBITERR) == 0) { + chDbgAssert(sdcp->thread == NULL, "sdc_lld_read_blocks(), #1", "not NULL"); + sdcp->thread = chThdSelf(); + chSchGoSleepS(THD_STATE_SUSPENDED); + chDbgAssert(sdcp->thread == NULL, "sdc_lld_read_blocks(), #2", "not NULL"); + if (chThdSelf()->p_u.rdymsg != RDY_OK) { + chSysUnlock(); + goto error; + } + } + else { + if ((sta & SDIO_STA_DATAEND) == 0) { + chSysUnlock(); + goto error; + } + } chSysUnlock(); if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_STOP_TRANSMISSION, 0, resp)) -- cgit v1.2.3