diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2010-06-22 08:41:08 +0000 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2010-06-22 08:41:08 +0000 |
commit | 5e649e5186ad50f9ecba4c5f5104d05bacd4e8e0 (patch) | |
tree | f743adf963c45c4eb52215ebf4f7c103a42c2caa /c | |
parent | 2010-06-22 Arnout Vandecappelle <arnout@mind.be> (diff) | |
download | rtems-5e649e5186ad50f9ecba4c5f5104d05bacd4e8e0.tar.bz2 |
2010-06-22 Arnout Vandecappelle <arnout@mind.be>
PR 1579/misc
* libchip/i2c/spi-sd-card.c: Gradually increasing sleep times when
waiting for write to finish.
Diffstat (limited to 'c')
-rw-r--r-- | c/src/ChangeLog | 6 | ||||
-rw-r--r-- | c/src/libchip/i2c/spi-sd-card.c | 15 |
2 files changed, 18 insertions, 3 deletions
diff --git a/c/src/ChangeLog b/c/src/ChangeLog index fe1f6677d8..61f5669538 100644 --- a/c/src/ChangeLog +++ b/c/src/ChangeLog @@ -1,5 +1,11 @@ 2010-06-22 Arnout Vandecappelle <arnout@mind.be> + PR 1579/misc + * libchip/i2c/spi-sd-card.c: Gradually increasing sleep times when + waiting for write to finish. + +2010-06-22 Arnout Vandecappelle <arnout@mind.be> + PR 1567/misc * libchip/i2c/spi-sd-card.h, libchip/i2c/spi-sd-card.c: Fixed timeouts. diff --git a/c/src/libchip/i2c/spi-sd-card.c b/c/src/libchip/i2c/spi-sd-card.c index ac395304dc..3370fa3dd7 100644 --- a/c/src/libchip/i2c/spi-sd-card.c +++ b/c/src/libchip/i2c/spi-sd-card.c @@ -373,6 +373,10 @@ static int sd_card_wait( sd_card_driver_entry *e) don't know if it is a write or read, assume write. FIXME should actually look at R2W_FACTOR for non-HC cards. */ int retries = e->n_ac_max * 25 / 10; + /* n_ac_max/100 is supposed to be the average waiting time. To + approximate this, we start with waiting n_ac_max/250 and + gradually increase the waiting time. */ + int wait_time_bytes = (retries + 149) / 150; while (e->busy) { /* Query busy tokens */ rv = sd_card_query( e, e->response, n); @@ -389,11 +393,16 @@ static int sd_card_wait( sd_card_driver_entry *e) if (retries <= 0) { return -RTEMS_TIMEOUT; } - n = SD_CARD_COMMAND_SIZE; if (e->schedule_if_busy) { - /* Invoke the scheduler */ - rtems_task_wake_after( RTEMS_YIELD_PROCESSOR); + uint64_t wait_time_us = wait_time_bytes; + wait_time_us *= 8000000; + wait_time_us /= e->transfer_mode.baudrate; + rtems_task_wake_after( RTEMS_MICROSECONDS_TO_TICKS(wait_time_us)); + retries -= wait_time_bytes; + wait_time_bytes = wait_time_bytes * 15 / 10; + } else { + n = SD_CARD_COMMAND_SIZE; } } return 0; |