jtag/drivers/bcm2835gpio: use rounding in delay math
After setting adapter speed to some values, the driver shows the real speed little bit higher. Although it does not impose a problem from technical point of view because the difference is smaller than usual speed error, it looks at least strange to the user. The documentation reads that real frequency should be same or lower than requested. Use proper rounding in speed -> delay and delay -> speed conversions. Change-Id: I1831112cc58681875548d2aeb688391fb79fa37f Signed-off-by: Tomas Vanek <vanekt@fbl.cz> Reviewed-on: https://review.openocd.org/c/openocd/+/7261 Tested-by: jenkins Reviewed-by: Jonathan Bell <jonathan@raspberrypi.com> Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
This commit is contained in:
parent
148bc7e215
commit
b4dd8dbc37
|
@ -264,7 +264,8 @@ static int bcm2835gpio_khz(int khz, int *jtag_speed)
|
|||
LOG_DEBUG("BCM2835 GPIO: RCLK not supported");
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
*jtag_speed = speed_coeff/khz - speed_offset;
|
||||
*jtag_speed = DIV_ROUND_UP(speed_coeff, khz) - speed_offset;
|
||||
LOG_DEBUG("jtag_delay %d", *jtag_speed);
|
||||
if (*jtag_speed < 0)
|
||||
*jtag_speed = 0;
|
||||
return ERROR_OK;
|
||||
|
@ -272,7 +273,9 @@ static int bcm2835gpio_khz(int khz, int *jtag_speed)
|
|||
|
||||
static int bcm2835gpio_speed_div(int speed, int *khz)
|
||||
{
|
||||
*khz = speed_coeff/(speed + speed_offset);
|
||||
int divisor = speed + speed_offset;
|
||||
/* divide with roundig to the closest */
|
||||
*khz = (speed_coeff + divisor / 2) / divisor;
|
||||
return ERROR_OK;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue