Skip to content

Commit 6645e47

Browse files
committed
Cleanup
Signed-off-by: Lesley Rossouw <lesley.rossouw@unsw.edu.au>
1 parent 78749ad commit 6645e47

2 files changed

Lines changed: 7 additions & 24 deletions

File tree

drivers/timer/time_conv.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
sddf_timer_freq_hz_t find_true_freq(sddf_timer_freq_hz_t f, uint64_t prescaler)
1111
{
1212
sddf_timer_freq_hz_t true_frequency = f / (1 << (sddf_timer_freq_hz_t)prescaler);
13-
// LOG_TIMER_DRIVER("Prescaler %zu maps %u MHz to equivalent freq of %u\n", prescaler,
14-
// f, true_frequency / MEGA);
1513
return true_frequency;
1614
}
1715

@@ -36,17 +34,15 @@ void find_mult_shift(sddf_timer_freq_hz_t f_a, sddf_timer_freq_hz_t f_b, uint64_
3634
shift_acc--;
3735
}
3836

39-
// Find mult and shift pair with best accuracy that fits range. Given our range
40-
// is very large, we basically always want a minimal shift.
37+
// Find mult and shift pair with best accuracy that fits range.
4138
// We try increasingly small shifts until we find one that doesn't destroy information.
4239
uint64_t shift;
4340
for (shift = 32; shift > 0; shift--) {
4441
tmp = (uint64_t)f_b << shift;
45-
tmp += f_a / 2;
46-
do_div(tmp, f_a);
42+
tmp += (uint64_t)f_a / 2ULL;
43+
tmp /= (uint64_t)f_a;
4744
if ((tmp >> shift_acc) == 0) {
48-
// Found it!
49-
break;
45+
break; // Found it!
5046
}
5147
}
5248
LOG_TIMER_DRIVER("M=%zu, S=%zu for f_a=%uMHz\n", tmp, shift, f_a / (MEGA));

drivers/timer/timer_common.c

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,11 @@
77
#include <sddf/timer/timer_driver.h>
88
#include <sddf/timer/protocol.h>
99
#include <sddf/util/util.h>
10-
#include <sddf/util/div64.h>
1110

1211
// This file implements cached time conversion which is suitable for almost
1312
// all timer drivers. Omit this file and use your own time conversion in your driver
14-
// if you do not want the caching behaviour. All non-caching common code is
15-
// contained in timer_driver_virt.c and time_conv.c.
16-
// NOTE: this file depends on time_conv.c!
13+
// if you do not want the caching behaviour.
1714

18-
19-
// Mult-shift cache. It's relatively expensive to calculate this every time, so we just
20-
// don't. Usually we will just be reusing the last result, so we just remember the last
21-
// one. We keep a separate entry for tick->ns and ns->tick.
2215
ms_cache_entry_t tick_to_ns_cache = {0};
2316
ms_cache_entry_t ns_to_tick_cache = {0};
2417

@@ -54,11 +47,8 @@ static inline uint64_t do_cached_period_freq_shift(uint64_t t_a, sddf_timer_freq
5447
* This function internally caches magic values for the calculation, these are recalculated
5548
* each time the frequency pair changes. Use do_freq_shift() to avoid caching.
5649
*
57-
* Prescaler should be given as an exponent, i.e. prescaler counter counts to 2^N,
58-
* provide N.
59-
*
6050
* @param uint64_t ticks to convert
61-
* @param uint64_t prescaler exponent
51+
* @param uint64_t prescaler exponent - i.e. if scaling to 2^N give N.
6252
* @returns non-zero on failure.
6353
*/
6454
uint64_t tick_to_ns_cached(uint64_t ticks, uint64_t prescaler, sddf_timer_freq_hz_t base_freq)
@@ -78,11 +68,8 @@ uint64_t tick_to_ns_cached(uint64_t ticks, uint64_t prescaler, sddf_timer_freq_h
7868
* This function internally caches magic values for the calculation, these are recalculated
7969
* each time the frequency pair changes. Use do_freq_shift() to avoid caching.
8070
*
81-
* Prescaler should be given as an exponent, i.e. prescaler counter counts to 2^N,
82-
* provide N.
83-
*
8471
* @param uint64_t ticks to convert
85-
* @param uint64_t prescaler exponent
72+
* @param uint64_t prescaler exponent - i.e. if scaling to 2^N give N.
8673
* @returns non-zero on failure.
8774
*/
8875
uint64_t ns_to_tick_cached(uint64_t ns, uint64_t prescaler, sddf_timer_freq_hz_t base_freq) {

0 commit comments

Comments
 (0)