From 32474838c0c8fd193f6be8db9d3325421ab8f9f2 Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Thu, 17 Apr 2014 12:50:24 +0400 Subject: [PATCH] LPC11C24: Fixed undefined behavior in clock driver --- libuavcan_drivers/lpc11c24/driver/src/clock.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libuavcan_drivers/lpc11c24/driver/src/clock.cpp b/libuavcan_drivers/lpc11c24/driver/src/clock.cpp index 2f2ed414d3..c689154e54 100644 --- a/libuavcan_drivers/lpc11c24/driver/src/clock.cpp +++ b/libuavcan_drivers/lpc11c24/driver/src/clock.cpp @@ -68,7 +68,8 @@ static uint64_t sampleFromCriticalSection(const volatile uint64_t* const value) cycles = reload - SysTick->VAL; time += USecPerOverflow; } - return time + (cycles / (SystemCoreClock / 1000000)); + const uint32_t cycles_per_usec = SystemCoreClock / 1000000; + return time + (cycles / cycles_per_usec); } uint64_t getUtcUSecFromCanInterrupt()