Skip to content

Commit 0e13ea9

Browse files
crafcat7xiaoxiang781216
authored andcommitted
mmcsd_sdio:Fix performing read and write in irq
In some usage scenarios, read and write tasks will be performed during interruptions. If sleep is used at this time, it will cause a timeout crash. Therefore, a macro is added to determine whether it is currently interrupted to select sleep/delay. Signed-off-by: chenrun1 <[email protected]>
1 parent 40ae660 commit 0e13ea9

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

drivers/mmcsd/mmcsd_sdio.c

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,19 @@
9898

9999
#define MMCSD_CAPACITY(b, s) ((s) >= 10 ? (b) << ((s) - 10) : (b) >> (10 - (s)))
100100

101+
#define MMCSD_USLEEP(usec) \
102+
do \
103+
{ \
104+
if (up_interrupt_context()) \
105+
{ \
106+
up_udelay(usec); \
107+
} \
108+
else \
109+
{ \
110+
nxsig_usleep(usec); \
111+
} \
112+
} while (0)
113+
101114
/****************************************************************************
102115
* Private Types
103116
****************************************************************************/
@@ -336,12 +349,12 @@ static inline int mmcsd_sendcmd4(FAR struct mmcsd_state_s *priv)
336349
*/
337350

338351
mmcsd_sendcmdpoll(priv, MMCSD_CMD4, CONFIG_MMCSD_DSR << 16);
339-
nxsig_usleep(MMCSD_DSR_DELAY);
352+
MMCSD_USLEEP(MMCSD_DSR_DELAY);
340353

341354
/* Send it again to have more confidence */
342355

343356
mmcsd_sendcmdpoll(priv, MMCSD_CMD4, CONFIG_MMCSD_DSR << 16);
344-
nxsig_usleep(MMCSD_DSR_DELAY);
357+
MMCSD_USLEEP(MMCSD_DSR_DELAY);
345358
}
346359
else
347360
{
@@ -1305,7 +1318,7 @@ static int mmcsd_transferready(FAR struct mmcsd_state_s *priv)
13051318

13061319
sched_yield();
13071320
#else
1308-
nxsig_usleep(1000);
1321+
MMCSD_USLEEP(1000);
13091322
#endif
13101323

13111324
/* We are still in the programming state. Calculate the elapsed
@@ -2595,7 +2608,7 @@ static int mmcsd_widebus(FAR struct mmcsd_state_s *priv)
25952608
SDIO_WIDEBUS(priv->dev, false);
25962609
priv->widebus = false;
25972610
SDIO_CLOCK(priv->dev, CLOCK_SDIO_DISABLED);
2598-
nxsig_usleep(MMCSD_CLK_DELAY);
2611+
MMCSD_USLEEP(MMCSD_CLK_DELAY);
25992612

26002613
return OK;
26012614
}
@@ -2656,7 +2669,7 @@ static int mmcsd_widebus(FAR struct mmcsd_state_s *priv)
26562669
}
26572670
#endif /* #ifdef CONFIG_MMCSD_MMCSUPPORT */
26582671

2659-
nxsig_usleep(MMCSD_CLK_DELAY);
2672+
MMCSD_USLEEP(MMCSD_CLK_DELAY);
26602673
return OK;
26612674
}
26622675

@@ -3450,7 +3463,7 @@ static int mmcsd_sdinitialize(FAR struct mmcsd_state_s *priv)
34503463
/* Select high speed SD clocking (which may depend on the DSR setting) */
34513464

34523465
SDIO_CLOCK(priv->dev, CLOCK_SD_TRANSFER_1BIT);
3453-
nxsig_usleep(MMCSD_CLK_DELAY);
3466+
MMCSD_USLEEP(MMCSD_CLK_DELAY);
34543467

34553468
/* If the hardware only supports 4-bit transfer mode then we forced to
34563469
* attempt to setup the card in this mode before checking the SCR register.
@@ -3547,7 +3560,7 @@ static int mmcsd_cardidentify(FAR struct mmcsd_state_s *priv)
35473560
*/
35483561

35493562
mmcsd_sendcmdpoll(priv, MMCSD_CMD0, 0xf0f0f0f0);
3550-
nxsig_usleep(MMCSD_IDLE_DELAY);
3563+
MMCSD_USLEEP(MMCSD_IDLE_DELAY);
35513564

35523565
/* After power up at least 74 clock cycles are required prior to starting
35533566
* bus communication
@@ -3558,7 +3571,7 @@ static int mmcsd_cardidentify(FAR struct mmcsd_state_s *priv)
35583571
/* Then send CMD0 just once is standard procedure */
35593572

35603573
mmcsd_sendcmdpoll(priv, MMCSD_CMD0, 0);
3561-
nxsig_usleep(MMCSD_IDLE_DELAY);
3574+
MMCSD_USLEEP(MMCSD_IDLE_DELAY);
35623575

35633576
#ifdef CONFIG_MMCSD_MMCSUPPORT
35643577
/* Send CMD1 which is supported only by MMC. if there is valid response
@@ -3580,7 +3593,7 @@ static int mmcsd_cardidentify(FAR struct mmcsd_state_s *priv)
35803593
*/
35813594

35823595
mmcsd_sendcmdpoll(priv, MMCSD_CMD0, 0);
3583-
nxsig_usleep(MMCSD_IDLE_DELAY);
3596+
MMCSD_USLEEP(MMCSD_IDLE_DELAY);
35843597
}
35853598
else
35863599
{

0 commit comments

Comments
 (0)