Merge pull request #1235 from jwerner-chromium/JW_udelay

Fix udelay issues that can make duration slightly too short
This commit is contained in:
davidcunado-arm 2018-01-30 08:59:35 +00:00 committed by GitHub
commit eefd04b69c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 6 deletions

View File

@ -7,6 +7,7 @@
#include <assert.h>
#include <delay_timer.h>
#include <platform_def.h>
#include <utils_def.h>
/***********************************************************
* The delay timer implementation
@ -30,7 +31,8 @@ void udelay(uint32_t usec)
start = ops->get_timer_value();
total_delta = (usec * ops->clk_div) / ops->clk_mult;
/* Add an extra tick to avoid delaying less than requested. */
total_delta = div_round_up(usec * ops->clk_div, ops->clk_mult) + 1;
do {
/*

View File

@ -24,6 +24,11 @@
*/
#define DIV_ROUND_UP_2EVAL(n, d) (((n) + (d) - 1) / (d))
#define div_round_up(val, div) __extension__ ({ \
__typeof__(div) _div = (div); \
((val) + _div - 1) / _div; \
})
#define MIN(x, y) __extension__ ({ \
__typeof__(x) _x = (x); \
__typeof__(y) _y = (y); \
@ -55,11 +60,6 @@
#define round_down(value, boundary) \
((value) & ~round_boundary(value, boundary))
#define div_round_up(val, div) __extension__ ({ \
__typeof__(div) _div = (div); \
round_up((val), _div)/_div; \
})
/*
* Evaluates to 1 if (ptr + inc) overflows, 0 otherwise.
* Both arguments must be unsigned pointer values (i.e. uintptr_t).