diff --git a/jtag/ChangeLog b/jtag/ChangeLog index 39142189..df2f8cc5 100644 --- a/jtag/ChangeLog +++ b/jtag/ChangeLog @@ -1,5 +1,7 @@ 2008-09-06 Arnim Laeuger + * src/tap/cable/generic.c: fixed calibration loop + * src/svf/svf.c: require frequency setting from cable for RUNTEST MIN SEC command, fixes [ 2090432 ] SVF programming problem with "x SEC" arg to runtest diff --git a/jtag/src/tap/cable/generic.c b/jtag/src/tap/cable/generic.c index d178bfdf..6008b920 100644 --- a/jtag/src/tap/cable/generic.c +++ b/jtag/src/tap/cable/generic.c @@ -357,26 +357,24 @@ generic_set_frequency( cable_t *cable, uint32_t new_frequency ) { if (new_frequency == 0) { cable->delay = 0; - cable-> frequency = 0; + cable->frequency = 0; } else { const double tolerance = 0.1; - uint32_t loops; + const uint32_t loops = 2000; uint32_t delay = cable->delay; uint32_t frequency = cable->frequency; - printf("requested frequency %u, now calibrating delay loop\n", new_frequency); + if (new_frequency > (1.0 - tolerance) * frequency && + new_frequency < (1.0 + tolerance) * frequency) + return; - if (delay == 0) { - delay = 1000; - loops = 10000; - } else { - loops = 3 * frequency; - } + printf("requested frequency %u, now calibrating delay loop\n", new_frequency); while (1) { uint32_t i, new_delay; long double start, end, real_frequency; + cable->delay = delay; start = frealtime(); for (i = 0; i < loops; ++i) { cable->driver->clock(cable, 0, 0, 1); @@ -388,11 +386,11 @@ generic_set_frequency( cable_t *cable, uint32_t new_frequency ) printf("new real frequency %Lg, delay %u\n", real_frequency, delay); - loops = 3 * fmax(real_frequency, new_frequency); new_delay = (long double)delay * real_frequency / new_frequency; if (real_frequency >= (1.0 - tolerance)*new_frequency) { if (real_frequency <= (1.0 + tolerance)*new_frequency) { + frequency = real_frequency; break; } if (new_delay > delay) { @@ -400,16 +398,20 @@ generic_set_frequency( cable_t *cable, uint32_t new_frequency ) } else { delay++; } + } else { - if (new_delay < delay) { - delay = new_delay; - } else { - delay--; - } if (delay == 0) { printf("operating without delay\n"); + frequency = real_frequency; break; } + + if (new_delay < delay) { + delay = new_delay; + } else { + if (delay > 0) + delay--; + } } }