Changeset 8ca15e26 in rtems


Ignore:
Timestamp:
Oct 2, 2017, 11:06:59 AM (20 months ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11
Children:
1a21831
Parents:
a3199d91
git-author:
Sebastian Huber <sebastian.huber@…> (10/02/17 11:06:59)
git-committer:
Sebastian Huber <sebastian.huber@…> (10/02/17 11:44:32)
Message:

i2c: Send MSB of address first for EEPROMs

Close #3161.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpukit/dev/i2c/eeprom.c

    ra3199d91 r8ca15e26  
    4949}
    5050
     51static void eeprom_set_addr(
     52  const eeprom *dev,
     53  uint32_t off,
     54  uint8_t addr[EEPROM_MAX_ADDRESS_BYTES]
     55)
     56{
     57  int shift = 24 - (4 - dev->address_bytes) * 8;
     58
     59  addr[0] = (uint8_t) (off >> shift);
     60  shift -= 8;
     61  addr[1] = (uint8_t) (off >> shift);
     62  shift -= 8;
     63  addr[2] = (uint8_t) (off >> shift);
     64  shift -= 8;
     65  addr[3] = (uint8_t) (off >> shift);
     66}
     67
    5168static ssize_t eeprom_read(
    5269  i2c_dev *base,
     
    8198    uint16_t cur = (uint16_t) (todo < 255 ?  todo : 255);
    8299
    83     uint8_t addr[EEPROM_MAX_ADDRESS_BYTES] = {
    84       (uint8_t) off,
    85       (uint8_t) (off >> 8),
    86       (uint8_t) (off >> 16),
    87       (uint8_t) (off >> 24)
    88     };
     100    uint8_t addr[EEPROM_MAX_ADDRESS_BYTES];
    89101    i2c_msg msgs[2] = {
    90102      {
     
    102114    int err;
    103115
     116    eeprom_set_addr(dev, off, addr);
    104117    err = i2c_bus_transfer(dev->base.bus, &msgs[0], RTEMS_ARRAY_SIZE(msgs));
    105118    if (err != 0) {
     
    142155    uint16_t rem = dev->page_size - (off & (dev->page_size - 1));
    143156    uint16_t cur = (uint16_t) (todo < rem ? todo : rem);
    144     uint8_t addr[EEPROM_MAX_ADDRESS_BYTES] = {
    145       (uint8_t) off,
    146       (uint8_t) (off >> 8),
    147       (uint8_t) (off >> 16),
    148       (uint8_t) (off >> 24)
    149     };
     157    uint8_t addr[EEPROM_MAX_ADDRESS_BYTES];
    150158    i2c_msg msgs[2] = {
    151159      {
     
    166174    rtems_interval timeout;
    167175
     176    eeprom_set_addr(dev, off, addr);
    168177    err = i2c_bus_transfer(dev->base.bus, &msgs[0], RTEMS_ARRAY_SIZE(msgs));
    169178    if (err != 0) {
Note: See TracChangeset for help on using the changeset viewer.