* Graeme Russ, <graeme.russ@gmail.com>
*
* (C) Copyright 2002
- * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se>
+ * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se>
*
* See file CREDITS for list of people who contributed to this
* project.
timer_fnc_t *isr_func;
};
-static struct timer_isr_function *first_timer_isr = NULL;
-static volatile unsigned long system_ticks = 0;
+static struct timer_isr_function *first_timer_isr;
+static unsigned long system_ticks;
+static uint64_t base_value;
/*
* register_timer_isr() allows multiple architecture and board specific
* functions to be called every millisecond. Keep the execution time of
* each function as low as possible
*/
-int register_timer_isr (timer_fnc_t *isr_func)
+int register_timer_isr(timer_fnc_t *isr_func)
{
struct timer_isr_function *new_func;
struct timer_isr_function *temp;
* Don't allow timer interrupts while the
* linked list is being modified
*/
- flag = disable_interrupts ();
+ flag = disable_interrupts();
if (first_timer_isr == NULL) {
first_timer_isr = new_func;
}
if (flag)
- enable_interrupts ();
+ enable_interrupts();
return 0;
}
/* Execute each registered function */
while (temp != NULL) {
- temp->isr_func ();
+ temp->isr_func();
temp = temp->next;
}
}
-void reset_timer (void)
+ulong get_timer(ulong base)
{
- system_ticks = 0;
+ return system_ticks - base;
}
-ulong get_timer (ulong base)
+void timer_set_tsc_base(uint64_t new_base)
{
- return (system_ticks - base);
+ base_value = new_base;
}
-void set_timer (ulong t)
+uint64_t timer_get_tsc(void)
{
- system_ticks = t;
+ uint64_t time_now;
+
+ time_now = rdtsc();
+ if (!base_value)
+ base_value = time_now;
+
+ return time_now - base_value;
}