Skip to content

Commit

Permalink
Make best effort with timer prescales, rather than bailing out
Browse files Browse the repository at this point in the history
TC16, for example, is not quite obtainable with standard prescales.
  • Loading branch information
frno7 committed Jan 14, 2025
1 parent c4f1231 commit 374109f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/tos/sndh.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <tos/cookie.h>
#include <tos/system-variable.h>

#include "internal/compare.h"
#include "internal/macro.h"
#include "internal/build-assert.h"
#include "internal/check-compiler.h"
Expand Down Expand Up @@ -83,11 +84,10 @@ MFP_CTRL_DIV(MFP_CTRL_DIV_PRESCALE)
if (frequency > U32_MAX / prescale_div[i])
continue;

const u32 count = DIV_ROUND_CLOSEST_U32(
MFP_TIMER_FREQUENCY, prescale_div[i] * (u32)frequency);

if (count < 1 || 256 < count)
continue;
/* FIXME: Report unobtainable frequencies. */
const u32 count = clamp_t(u32,
DIV_ROUND_CLOSEST_U32(MFP_TIMER_FREQUENCY,
prescale_div[i] * (u32)frequency), 1, 256);

const u32 f = DIV_ROUND_CLOSEST_U32(
MFP_TIMER_FREQUENCY, prescale_div[i] * count);
Expand Down
Binary file modified lib/tos/tos
Binary file not shown.

0 comments on commit 374109f

Please sign in to comment.