1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

tests/periph_ptp_clock: fix bug in debug print

The API doc of ptp_clock_adjust_speed says regarding the correction
parameter:

    1. A call with @p correction set to `0` restores the nominal clock speed.
    2. A call with a positive value for @p correction speeds the clock up
       by `correction / (1 << 32)` (so up to ~50% for `INT32_MAX`).
    3. A call with a negative value for @p correction slows the clock down by
       `-correction / (1 << 32)` (so up to 50% for `INT32_MIN`).

So we need to divide by 2^32, not 2^32 - 1 (or `UINT32_MAX`).
This commit is contained in:
Marian Buschsieweke 2021-03-12 20:34:30 +01:00
parent e768a85f62
commit 42df56ff08
No known key found for this signature in database
GPG Key ID: 61F64C6599B1539F

View File

@ -67,7 +67,8 @@ static int test_speed_adjustment(const int32_t speed)
print_str(" (~");
{
int64_t tmp = speed * 100000ULL;
tmp /= UINT32_MAX;
/* trusting compiler to use arithmetic right shift, when available instead of division */
tmp /= 1LL << 32;
tmp += 100000ULL;
char output[16];
print(output, fmt_s32_dfp(output, (int32_t)tmp, -3));