From 69013378972c07c9a1e46fa6ec274070cad1a532 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Sat, 20 Jul 2013 12:08:48 -0400 Subject: [PATCH] Add helper functions to convert timer irqs to milliseconds. Add ticks_to_ms() and ticks_from_ms() helpers. Signed-off-by: Kevin O'Connor --- src/clock.c | 3 +-- src/timer.c | 19 ++++++++++++++++--- src/usb-ehci.c | 3 +-- src/usb-ohci.c | 3 +-- src/usb-uhci.c | 3 +-- src/util.h | 2 ++ 6 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/clock.c b/src/clock.c index b9a708b..2f2ca07 100644 --- a/src/clock.c +++ b/src/clock.c @@ -94,8 +94,7 @@ clock_setup(void) u32 seconds = bcd2bin(inb_cmos(CMOS_RTC_SECONDS)); u32 minutes = bcd2bin(inb_cmos(CMOS_RTC_MINUTES)); u32 hours = bcd2bin(inb_cmos(CMOS_RTC_HOURS)); - u32 ticks = (hours * 60 + minutes) * 60 + seconds; - ticks = ((u64)ticks * PIT_TICK_RATE) / PIT_TICK_INTERVAL; + u32 ticks = ticks_from_ms(((hours * 60 + minutes) * 60 + seconds) * 1000); SET_BDA(timer_counter, ticks); // Setup Century storage diff --git a/src/timer.c b/src/timer.c index 87df97b..0fd0194 100644 --- a/src/timer.c +++ b/src/timer.c @@ -198,6 +198,21 @@ calc_future_tsc_usec(u32 usecs) * IRQ based timer ****************************************************************/ +// Return the number of milliseconds in 'ticks' number of timer irqs. +u32 +ticks_to_ms(u32 ticks) +{ + return DIV_ROUND_UP(PIT_TICK_INTERVAL * 1000 * ticks, PIT_TICK_RATE); +} + +// Return the number of timer irqs in 'ms' number of milliseconds. +u32 +ticks_from_ms(u32 ms) +{ + u32 kticks = DIV_ROUND_UP((u64)ms * PIT_TICK_RATE, PIT_TICK_INTERVAL); + return DIV_ROUND_UP(kticks, 1000); +} + // Calculate the timer value at 'count' number of full timer ticks in // the future. u32 @@ -212,9 +227,7 @@ calc_future_timer(u32 msecs) { if (!msecs) return GET_BDA(timer_counter); - u32 kticks = DIV_ROUND_UP((u64)msecs * PIT_TICK_RATE, PIT_TICK_INTERVAL); - u32 ticks = DIV_ROUND_UP(kticks, 1000); - return calc_future_timer_ticks(ticks); + return calc_future_timer_ticks(ticks_from_ms(msecs)); } // Check if the given timer value has passed. diff --git a/src/usb-ehci.c b/src/usb-ehci.c index e1e659b..c1638e4 100644 --- a/src/usb-ehci.c +++ b/src/usb-ehci.c @@ -15,7 +15,6 @@ #include "biosvar.h" // GET_LOWFLAT #include "usb-uhci.h" // uhci_setup #include "usb-ohci.h" // ohci_setup -#include "pit.h" // PIT_TICK_RATE struct usb_ehci_s { struct usb_s usb; @@ -427,7 +426,7 @@ ehci_alloc_intr_pipe(struct usbdevice_s *usbdev int maxpacket = epdesc->wMaxPacketSize; // Determine number of entries needed for 2 timer ticks. int ms = 1<wMaxPacketSize; // Determine number of entries needed for 2 timer ticks. int ms = 1<wMaxPacketSize; // Determine number of entries needed for 2 timer ticks. int ms = 1<