Add ticks_to_ms() and ticks_from_ms() helpers.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
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
* 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
{
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.
#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;
int maxpacket = epdesc->wMaxPacketSize;
// Determine number of entries needed for 2 timer ticks.
int ms = 1<<frameexp;
- int count = DIV_ROUND_UP(PIT_TICK_INTERVAL * 1000 * 2, PIT_TICK_RATE * ms);
+ int count = DIV_ROUND_UP(ticks_to_ms(2), ms);
struct ehci_pipe *pipe = memalign_low(EHCI_QH_ALIGN, sizeof(*pipe));
struct ehci_qtd *tds = memalign_low(EHCI_QTD_ALIGN, sizeof(*tds) * count);
void *data = malloc_low(maxpacket * count);
#include "pci_regs.h" // PCI_BASE_ADDRESS_0
#include "usb.h" // struct usb_s
#include "biosvar.h" // GET_LOWFLAT
-#include "pit.h" // PIT_TICK_RATE
#define FIT (1 << 31)
int maxpacket = epdesc->wMaxPacketSize;
// Determine number of entries needed for 2 timer ticks.
int ms = 1<<frameexp;
- int count = DIV_ROUND_UP(PIT_TICK_INTERVAL * 1000 * 2, PIT_TICK_RATE * ms)+1;
+ int count = DIV_ROUND_UP(ticks_to_ms(2), ms) + 1;
struct ohci_pipe *pipe = malloc_low(sizeof(*pipe));
struct ohci_td *tds = malloc_low(sizeof(*tds) * count);
void *data = malloc_low(maxpacket * count);
#include "pci_regs.h" // PCI_BASE_ADDRESS_4
#include "usb.h" // struct usb_s
#include "biosvar.h" // GET_LOWFLAT
-#include "pit.h" // PIT_TICK_RATE
struct usb_uhci_s {
struct usb_s usb;
int maxpacket = epdesc->wMaxPacketSize;
// Determine number of entries needed for 2 timer ticks.
int ms = 1<<frameexp;
- int count = DIV_ROUND_UP(PIT_TICK_INTERVAL * 1000 * 2, PIT_TICK_RATE * ms);
+ int count = DIV_ROUND_UP(ticks_to_ms(2), ms);
count = ALIGN(count, 2);
struct uhci_pipe *pipe = malloc_low(sizeof(*pipe));
struct uhci_td *tds = malloc_low(sizeof(*tds) * count);
void releaseRTC(void);
// timer.c
+u32 ticks_to_ms(u32 ticks);
+u32 ticks_from_ms(u32 ms);
void pmtimer_setup(u16 ioport);
int check_tsc(u64 end);
void timer_setup(void);