|
HOWTO: Module usage |
APIC timer Module for Linux
Documentation HOWTO: Usage of the APIC timer module. Author: Vincent Oberle Purpose: This document shows how to use the APIC timer module. The test module from the distribution is an example. Content Preliminary Of course, include #include "uka_apic_timer.h" To programm a timer, you will need to give it a value of
the TSC register. To read the TSC register, include
unsigned long eax, edx; unsigned long long offset; rdtsc(eax, edx); offset = TO_ULL(edx, eax); Timer functions The function that is called by a timer when it is issued must have the following definition:
void timer_fn (unsigned long long exp, unsigned long data)
{
/* Body */
}
The Without pointers The first thing to do in order to create and program a timer
is to create a One solution is to use a structur directly, without pointer. static struct apic_timer_list timer; Note the use of the keyword The second step is to initialize the timer, first by calling
init_apic_timer(&timer); timer.function = (void*)a_fn; timer.expires = an_expires; And finally, call the add_apic_timer(&timer); With pointers The second solution is to create a dynamic Declar a pointer: struct apic_timer_list *timer; And initialize it with timer = (struct apic_timer_list *)kmalloc(sizeof(struct apic_timer_list), GFP_KERNEL); Then initialize the structur and add it. init_apic_timer(timer); timer->function = (void*)a_fn; timer->expires = an_expires; add_apic_timer(timer); |