aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarti Bolivar <mbolivar@leaflabs.com>2012-06-02 22:01:29 -0400
committerMarti Bolivar <mbolivar@leaflabs.com>2012-06-03 00:04:01 -0400
commitc274dfafc202134e791de1468ba2cf0c9137621e (patch)
tree50c6c14c389b5d0956d084328c1006b949f7da57
parent98cc4bfcace01da7b467280f586bb6844916dea7 (diff)
downloadlibrambutan-c274dfafc202134e791de1468ba2cf0c9137621e.tar.gz
librambutan-c274dfafc202134e791de1468ba2cf0c9137621e.zip
HardwareTimer::setPeriod(): Don't use floating point.
I can't believe we've been shipping this for so long. Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
-rw-r--r--wirish/HardwareTimer.cpp6
1 files changed, 3 insertions, 3 deletions
diff --git a/wirish/HardwareTimer.cpp b/wirish/HardwareTimer.cpp
index c35804c..ef720ce 100644
--- a/wirish/HardwareTimer.cpp
+++ b/wirish/HardwareTimer.cpp
@@ -26,10 +26,10 @@
#include <wirish/HardwareTimer.h>
-#include <libmaple/rcc.h> // for rcc_clk_id
-#include <wirish/boards.h> // for CYCLES_PER_MICROSECOND
+#include <libmaple/rcc.h>
#include <wirish/ext_interrupts.h> // for noInterrupts(), interrupts()
#include <wirish/wirish_math.h>
+#include <board/board.h> // for CYCLES_PER_MICROSECOND
// TODO [0.1.0] Remove deprecated pieces
@@ -112,7 +112,7 @@ uint16 HardwareTimer::setPeriod(uint32 microseconds) {
uint32 period_cyc = microseconds * CYCLES_PER_MICROSECOND;
uint16 prescaler = (uint16)(period_cyc / MAX_RELOAD + 1);
- uint16 overflow = (uint16)round(period_cyc / prescaler);
+ uint16 overflow = (uint16)((period_cyc + (prescaler / 2)) / prescaler);
this->setPrescaleFactor(prescaler);
this->setOverflow(overflow);
return overflow;