Changeset 58eccd0 in rtems


Ignore:
Timestamp:
Jun 22, 2010, 8:37:26 AM (9 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, master
Children:
5e649e5
Parents:
6dfaeb4
Message:

2010-06-22 Arnout Vandecappelle <arnout@…>

PR 1567/misc

  • libchip/i2c/spi-sd-card.h, libchip/i2c/spi-sd-card.c: Fixed timeouts.
Location:
c/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • c/src/ChangeLog

    r6dfaeb4 r58eccd0  
     12010-06-22      Arnout Vandecappelle <arnout@mind.be>
     2
     3        PR 1567/misc
     4        * libchip/i2c/spi-sd-card.h, libchip/i2c/spi-sd-card.c: Fixed
     5        timeouts.
     6
    172010-06-21      Arnout Vandecappelle <arnout@mind.be>
    28
  • c/src/libchip/i2c/spi-sd-card.c

    r6dfaeb4 r58eccd0  
    302302{
    303303        uint64_t ac = sd_card_access_time( csd);
     304        uint32_t ac_100ms = transfer_speed / 80;
    304305        uint32_t n = SD_CARD_CSD_GET_NSAC( csd) * 100;
    305         ac = (ac * transfer_speed) / 8000000000ULL;
    306         return n + (uint32_t) ac;
     306        /* ac is in ns, transfer_speed in bps, max_access_time in bytes.
     307           max_access_time is 100 times typical access time (taac+nsac) */
     308        ac = ac * transfer_speed / 80000000;
     309        ac = ac + 100*n;
     310        if ((uint32_t)ac > ac_100ms)
     311                return ac_100ms;
     312        else
     313                return (uint32_t)ac;
    307314}
    308315
     
    363370        int r = 0;
    364371        int n = 2;
     372        /* For writes, the timeout is 2.5 times that of reads; since we
     373           don't know if it is a write or read, assume write.
     374           FIXME should actually look at R2W_FACTOR for non-HC cards. */
     375        int retries = e->n_ac_max * 25 / 10;
    365376        while (e->busy) {
    366377                /* Query busy tokens */
     
    374385                                return 0;
    375386                        }
     387                }
     388                retries -= n;
     389                if (retries <= 0) {
     390                        return -RTEMS_TIMEOUT;
    376391                }
    377392                n = SD_CARD_COMMAND_SIZE;
     
    958973                read_block_size = 512;
    959974                write_block_size = 512;
     975
     976                /* Timeout is fixed at 100ms in CSD Version 2.0 */
     977                e->n_ac_max = transfer_speed / 80;
    960978        } else {
    961979                RTEMS_DO_CLEANUP_SC( RTEMS_IO_ERROR, sc, sd_card_driver_init_cleanup, "Unexpected CSD Structure number");
     
    968986                RTEMS_SYSLOG( "Spec version             : %" PRIu8 "\n", SD_CARD_CSD_GET_SPEC_VERS( block));
    969987                RTEMS_SYSLOG( "Access time [ns]         : %" PRIu32 "\n", sd_card_access_time( block));
     988                RTEMS_SYSLOG( "Access time [N]          : %" PRIu32 "\n", SD_CARD_CSD_GET_NSAC( block)*100);
    970989                RTEMS_SYSLOG( "Max access time [N]      : %" PRIu32 "\n", e->n_ac_max);
    971990                RTEMS_SYSLOG( "Max read block size [B]  : %" PRIu32 "\n", read_block_size);
     
    12071226                                return sd_card_disk_block_write( e, r);
    12081227                        default:
    1209                                 errno = EINVAL;
     1228                                errno = EINVAL;
    12101229                                return -1;
    12111230                }
     
    12141233                return 0;
    12151234        } else {
    1216                 errno = EINVAL;
     1235                errno = EINVAL;
    12171236                return -1;
    12181237        }
  • c/src/libchip/i2c/spi-sd-card.h

    r6dfaeb4 r58eccd0  
    5353}
    5454
    55 #define SD_CARD_N_AC_MAX_DEFAULT 8
     55/* Default speed = 400kbps, default timeout = 100ms, n_ac_max is in bytes */
     56#define SD_CARD_N_AC_MAX_DEFAULT 5000
    5657
    5758typedef struct {
Note: See TracChangeset for help on using the changeset viewer.