Changeset 1a21831 in rtems


Ignore:
Timestamp:
Oct 2, 2017, 11:28:22 AM (19 months ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11
Children:
c139a70
Parents:
8ca15e26
git-author:
Sebastian Huber <sebastian.huber@…> (10/02/17 11:28:22)
git-committer:
Sebastian Huber <sebastian.huber@…> (10/02/17 11:44:36)
Message:

i2c: Fix EEPROM driver program timeout handling

The RTEMS_MILLISECONDS_TO_TICKS() macro doesn't round up. Do not use it
to calculate the program timeout in ticks. Check program done condition
after the timeout check to account for pre-emptions.

Close #3162.

File:
1 edited

Legend:

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

    r8ca15e26 r1a21831  
    4040  uint16_t i2c_address_mask;
    4141  uint16_t i2c_address_shift;
    42   rtems_interval program_timeout;
     42  rtems_interval program_timeout_in_ticks;
    4343} eeprom;
    4444
     
    173173    ssize_t m;
    174174    rtems_interval timeout;
     175    bool before;
    175176
    176177    eeprom_set_addr(dev, off, addr);
     
    180181    }
    181182
    182     timeout = rtems_clock_tick_later(dev->program_timeout);
     183    timeout = rtems_clock_tick_later(dev->program_timeout_in_ticks);
    183184
    184185    do {
     186      before = rtems_clock_tick_before(timeout);
     187
    185188      m = eeprom_read(&dev->base, &in[0], cur, off);
    186     } while (m != cur && rtems_clock_tick_before(timeout));
     189      if (m == cur) {
     190        break;
     191      }
     192    } while (before);
    187193
    188194    if (m != cur) {
     
    227233{
    228234  uint32_t extra_address;
     235  uint32_t ms_per_tick;
    229236  eeprom *dev;
    230237
     
    262269  dev->page_size = page_size_in_bytes;
    263270  dev->size = size_in_bytes;
    264   dev->program_timeout = RTEMS_MILLISECONDS_TO_TICKS(program_timeout_in_ms);
     271  ms_per_tick = rtems_configuration_get_milliseconds_per_tick();
     272  dev->program_timeout_in_ticks = (program_timeout_in_ms + ms_per_tick - 1)
     273    / ms_per_tick + 1;
    265274
    266275  if (extra_address != 0) {
Note: See TracChangeset for help on using the changeset viewer.