mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-18 12:52:44 +01:00
driver/mtd_spi_nor: clearup sleep timming
This commit is contained in:
parent
cdffc8f0ca
commit
f8607ecc28
@ -342,7 +342,7 @@ static uint32_t mtd_spi_nor_get_size(const mtd_jedec_id_t *id)
|
|||||||
static inline void wait_for_write_complete(const mtd_spi_nor_t *dev, uint32_t us)
|
static inline void wait_for_write_complete(const mtd_spi_nor_t *dev, uint32_t us)
|
||||||
{
|
{
|
||||||
unsigned i = 0, j = 0;
|
unsigned i = 0, j = 0;
|
||||||
uint32_t div = 2;
|
uint32_t div = 1; /* first wait one full interval */
|
||||||
#if IS_ACTIVE(ENABLE_DEBUG)
|
#if IS_ACTIVE(ENABLE_DEBUG)
|
||||||
uint32_t diff = 0;
|
uint32_t diff = 0;
|
||||||
#endif
|
#endif
|
||||||
@ -362,13 +362,15 @@ static inline void wait_for_write_complete(const mtd_spi_nor_t *dev, uint32_t us
|
|||||||
i++;
|
i++;
|
||||||
#if IS_USED(MODULE_ZTIMER_USEC)
|
#if IS_USED(MODULE_ZTIMER_USEC)
|
||||||
if (us) {
|
if (us) {
|
||||||
ztimer_sleep(ZTIMER_USEC, us);
|
uint32_t wait_us = us / div;
|
||||||
|
uint32_t wait_min = 2;
|
||||||
|
|
||||||
|
wait_us = wait_us > wait_min ? wait_us : wait_min;
|
||||||
|
|
||||||
|
ztimer_sleep(ZTIMER_USEC, wait_us);
|
||||||
/* reduce the waiting time quickly if the estimate was too short,
|
/* reduce the waiting time quickly if the estimate was too short,
|
||||||
* but still avoid busy (yield) waiting */
|
* but still avoid busy (yield) waiting */
|
||||||
if (us > 2) {
|
div++;
|
||||||
us -= (us / div);
|
|
||||||
div++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
j++;
|
j++;
|
||||||
@ -376,16 +378,15 @@ static inline void wait_for_write_complete(const mtd_spi_nor_t *dev, uint32_t us
|
|||||||
}
|
}
|
||||||
#elif IS_USED(MODULE_XTIMER)
|
#elif IS_USED(MODULE_XTIMER)
|
||||||
if (us) {
|
if (us) {
|
||||||
xtimer_usleep(us);
|
uint32_t wait_us = us / div;
|
||||||
|
uint32_t wait_min = 2 * XTIMER_BACKOFF;
|
||||||
|
|
||||||
|
wait_us = wait_us > wait_min ? wait_us : wait_min;
|
||||||
|
|
||||||
|
xtimer_usleep(wait_us);
|
||||||
/* reduce the waiting time quickly if the estimate was too short,
|
/* reduce the waiting time quickly if the estimate was too short,
|
||||||
* but still avoid busy (yield) waiting */
|
* but still avoid busy (yield) waiting */
|
||||||
if (us > 2 * XTIMER_BACKOFF) {
|
div++;
|
||||||
us -= (us / div);
|
|
||||||
div++;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
us = 2 * XTIMER_BACKOFF;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
j++;
|
j++;
|
||||||
|
Loading…
Reference in New Issue
Block a user