-
Notifications
You must be signed in to change notification settings - Fork 2.1k
drivers/sdmmc_sdhc: add timeout to wait for ISR mutex unlock #21432
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
fabian18
wants to merge
1
commit into
RIOT-OS:master
Choose a base branch
from
fabian18:fix/sdmmc_sdhc_irq_timeout
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+20
−11
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -79,24 +79,29 @@ | |||||||||
|
||||||||||
/* millisecond timer definitions dependent on active ztimer backend */ | ||||||||||
#if IS_USED(MODULE_ZTIMER_MSEC) | ||||||||||
#define _ZTIMER_ACQUIRE() ztimer_acquire(ZTIMER_MSEC) | ||||||||||
#define _ZTIMER_RELEASE() ztimer_release(ZTIMER_MSEC) | ||||||||||
#define _ZTIMER_NOW() ztimer_now(ZTIMER_MSEC) | ||||||||||
#define _ZTIMER_SLEEP_MS(n) ztimer_sleep(ZTIMER_MSEC, n) | ||||||||||
#define _ZTIMER_CLOCK ZTIMER_MSEC | ||||||||||
#define _ZTIMER_TICKS_PER_MS 1 | ||||||||||
|
||||||||||
#elif IS_USED(MODULE_ZTIMER_USEC) | ||||||||||
#define _ZTIMER_ACQUIRE() ztimer_acquire(ZTIMER_USEC) | ||||||||||
#define _ZTIMER_RELEASE() ztimer_release(ZTIMER_USEC) | ||||||||||
#define _ZTIMER_NOW() ztimer_now(ZTIMER_USEC) / US_PER_MS | ||||||||||
#define _ZTIMER_SLEEP_MS(n) ztimer_sleep(ZTIMER_USEC, n * US_PER_MS) | ||||||||||
#define _ZTIMER_CLOCK ZTIMER_USEC | ||||||||||
#define _ZTIMER_TICKS_PER_MS US_PER_MS | ||||||||||
Comment on lines
+86
to
+87
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I'm not sure if it makes sense to partially apply the indentation style now? Ping @maribu? |
||||||||||
#else | ||||||||||
#error "Either module ztimer_msec or ztimer_usec is needed" | ||||||||||
#endif | ||||||||||
|
||||||||||
#define _ZTIMER_ACQUIRE() ztimer_acquire(_ZTIMER_CLOCK) | ||||||||||
#define _ZTIMER_RELEASE() ztimer_release(_ZTIMER_CLOCK) | ||||||||||
#define _ZTIMER_NOW() (ztimer_now(_ZTIMER_CLOCK) / _ZTIMER_TICKS_PER_MS) | ||||||||||
#define _ZTIMER_SLEEP_MS(n) ztimer_sleep(_ZTIMER_CLOCK, n * _ZTIMER_TICKS_PER_MS) | ||||||||||
|
||||||||||
/* Monitor card insertion and removal */ | ||||||||||
#define SDHC_NISTR_CARD_DETECT (SDHC_NISTR_CREM | SDHC_NISTR_CINS) | ||||||||||
#define SDHC_NISTER_CARD_DETECT (SDHC_NISTER_CREM | SDHC_NISTER_CINS) | ||||||||||
#define SDHC_NISIER_CARD_DETECT (SDHC_NISIER_CREM | SDHC_NISIER_CINS) | ||||||||||
|
||||||||||
/* 2s timeout for IRQ wait */ | ||||||||||
#define SDHC_IRQ_TIMEOUT_MS (2000 * _ZTIMER_TICKS_PER_MS) | ||||||||||
|
||||||||||
#include "board.h" | ||||||||||
|
||||||||||
/* forward declaration of _driver */ | ||||||||||
|
@@ -743,16 +748,20 @@ static bool _wait_for_event(sdhc_dev_t *sdhc_dev, | |||||||||
#if defined(CPU_SAMD5X) || defined(CPU_SAME5X) | ||||||||||
pm_block(SAM0_PM_IDLE); | ||||||||||
#endif | ||||||||||
mutex_lock(&sdhc_dev->irq_wait); | ||||||||||
bool timeout = ztimer_mutex_lock_timeout(_ZTIMER_CLOCK, &sdhc_dev->irq_wait, | ||||||||||
SDHC_IRQ_TIMEOUT_MS) < 0; | ||||||||||
#if defined(CPU_SAMD5X) || defined(CPU_SAME5X) | ||||||||||
pm_unblock(SAM0_PM_IDLE); | ||||||||||
#endif | ||||||||||
|
||||||||||
sdhc->NISIER.reg &= ~event; | ||||||||||
sdhc->EISIER.reg &= ~error_mask; | ||||||||||
|
||||||||||
if (sdhc_dev->error & error_mask) { | ||||||||||
if (timeout || (sdhc_dev->error & error_mask)) { | ||||||||||
if (IS_USED(ENABLE_DEBUG)) { | ||||||||||
if (timeout) { | ||||||||||
DEBUG("[sdmmc] IRQ wait timeout\n"); | ||||||||||
} | ||||||||||
DEBUG("[sdmmc] SDHC error: EISTR=%04x, ", sdhc_dev->error); | ||||||||||
switch (reset) { | ||||||||||
case SDHC_SRR_SWRSTCMD: | ||||||||||
|
@@ -832,7 +841,7 @@ static int _sdhc_to_sdmmc_err_code(uint16_t code) | |||||||||
static void _isr(sdhc_dev_t *sdhc_dev) | ||||||||||
{ | ||||||||||
sdhc_t *sdhc = sdhc_dev->conf->sdhc; | ||||||||||
|
||||||||||
DEBUG_PUTS("[sdmmc] IRQ"); | ||||||||||
if (sdhc->NISTR.reg & SDHC_NISTR_CARD_DETECT) { | ||||||||||
DEBUG_PUTS("[sdmmc] card presence changed"); | ||||||||||
|
||||||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.