Ticket #1756: pr1756.diff

File pr1756.diff, 2.5 KB (added by Joel Sherrill, on Mar 7, 2011 at 4:31:39 PM)

Adds retry logic

  • c/src/lib/libbsp/i386/pc386/timer/timer.c

    RCS file: /usr1/CVS/rtems/c/src/lib/libbsp/i386/pc386/timer/timer.c,v
    retrieving revision 1.32
    retrieving revision 1.33
    diff -u -r1.32 -r1.33
     
    2424 *  found in the file LICENSE in this distribution or at
    2525 *  http://www.rtems.com/license/LICENSE.
    2626 *
    27  *  $Id: timer.c,v 1.32 2011/02/09 08:22:58 ralf Exp $
     27 *  $Id: timer.c,v 1.33 2011/03/04 21:56:45 joel Exp $
    2828 */
    2929
    3030#include <stdlib.h>
     
    334334  unsigned int targetClockBits, currentClockBits;
    335335  unsigned int slowLoopGranularity, fastLoopGranularity;
    336336  rtems_interrupt_level  level;
     337  int retries = 0;
    337338
     339  rtems_interrupt_disable(level);
     340
     341retry:
     342  if ( ++retries >= 5 ) {
     343    printk( "Calibrate_loop_1ms: too many attempts. giving up!!\n" );
     344    while (1);
     345  }
    338346#ifdef DEBUG_CALIBRATE
    339347  printk("Calibrate_loop_1ms is starting,  please wait (but not too long.)\n");
    340348#endif
    341349  targetClockBits = US_TO_TICK(1000);
    342 
    343   rtems_interrupt_disable(level);
    344350  /*
    345351   * Fill up the cache to get a correct offset
    346352   */
     
    384390  fastLoop (10000);
    385391  res = readTimer0() - offset;
    386392  if (res < emptyCall) {
    387      printk("Problem #1 in offset computation in Calibrate_loop_1ms in file libbsp/i386/pc386/timer/timer.c\n");
    388     while (1);
     393    printk(
     394      "Problem #1 in offset computation in Calibrate_loop_1ms "
     395        " in file libbsp/i386/pc386/timer/timer.c\n"
     396    );
     397    goto retry;
    389398  }
    390399  fastLoopGranularity = (res - emptyCall) / 10000;
    391400  /*
     
    395404  slowLoop(10);
    396405  res = readTimer0();
    397406  if (res < offset + emptyCall) {
    398      printk("Problem #2 in offset computation in Calibrate_loop_1ms in file libbsp/i386/pc386/timer/timer.c\n");
    399     while (1);
     407    printk(
     408      "Problem #2 in offset computation in Calibrate_loop_1ms "
     409        " in file libbsp/i386/pc386/timer/timer.c\n"
     410    );
     411    goto retry;
    400412  }
    401413  slowLoopGranularity = (res - offset - emptyCall)/ 10;
    402414
    403415  if (slowLoopGranularity == 0) {
    404     printk("Problem #3 in Calibrate_loop_1ms in file libbsp/i386/pc386/timer/timer.c\n");
    405     while (1);
     416    printk(
     417      "Problem #3 in offset computation in Calibrate_loop_1ms "
     418        " in file libbsp/i386/pc386/timer/timer.c\n"
     419    );
     420    goto retry;
    406421  }
    407422
    408423  targetClockBits += offset;