You are on page 1of 2

[TUTORIAL]

How to create a Timer in ath5k driver


Definition To create a timer in ath5k driver, you need first to define it. Open the ath5k.h library file of the driver and define the timer in ath5k_hw struct with the following form: struct timer_list timer's_name; Initialization After the definition of the timer you need to initialize it. Open the base.c file and find the ath5k_init function which initializes the ath5k. After the first definitions you can initialize your timer by editing the following code lines: init_timer(&ah->timer's_name); ah->timer's_name.function = my_timer's_function; ah->timer's_name.data = (struct ath5k_hw *) ah; mod_timer(&ah->timer's_name, jiffies + msecs_to_jiffies(1000 * n)); The first line initializes the timer that you have define in the previous struct. In the second line you define the function that will use the timer (see the third step). The next line defines the parameters of your timer s function. In our case we give as parameter the ath5k_hw struct. Finally with the mod_timer function we call the timer for first time. It takes as parameters the timer to be modified and the timer's timeout in jiffies. In computing a jiffy is the duration of one tick of the system timer interrupt. It is not an absolute time interval unit, since its duration depends on the clock interrupt frequency of the particular hardware platform. Timer's function In this step you must write the my_timer's_function that defined in the previous step somewhere in the driver. Your function must take as parameter the variable you have define in your timer's_name.data. Finally, you must call again your timer recursively: mod_timer(&data->timer's_name, jiffies + msecs_to_jiffies(n)); Delete the timer If you don't delete the timer, it will continue to run until you close your computer. So you need

to delete your timer while you close the ath5k module. Find the ath5k_stop function in the base.c file and delete your timer with the following code line: del_timer(&ah->gpio_timer);

You might also like