Damien Zammit, le mar. 06 févr. 2024 03:06:20 +0000, a ecrit:
> + us = (us * NSEC_PER_USEC) / hpet_period_nsec;
> +
> + start = HPET32(HPET_COUNTER);
> +
> + while (1) {
> + now = HPET32(HPET_COUNTER);
> +
> + if (now < start) {
> + /* handle timer overflow within 32 bits */
You don't need to do anything fancy. Even when now < start, thanks to
unsigned 32bit wrap-around, now - start will still be correct. In this:
> + if ((0xffffffff - start) + now + 1 > us)
> + break;
The 0xffffffff + 1 piece just wraps-around.
So *all* you need really is
> + if (now - start > us)
> + break;
Samuel