Driver porting: the workqueue interface.
Posted Sep 15, 2004 7:05 UTC (Wed) by
Albert (guest, #24733)
In reply to:
Driver porting: the workqueue interface. by baisa
Parent article:
Driver porting: the workqueue interface.
I ran into the same problem. We ran a stepper motor from the timer interrupt. In 2.6 I used the RTC instead. Here is some code for a minimal module that uses RTC to generate IRQ8 at 1024 Hz and also registers an interrupt handler for IRQ8 (via the RTC module).
/*
* stepper.c - Stepper motor driver using RTC.
*/
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_ALERT */
#include <linux/init.h> /* Needed for the macros */
#include <linux/ioctl.h>
#if defined(CONFIG_RTC) || defined(CONFIG_RTC_MODULE)
#include <linux/rtc.h>
#define DRIVER_AUTHOR "John Doe <some@one>"
#define DRIVER_DESC "Stepper motor driver using RTC"
static rtc_task_t rtc_task;
static atomic_t rtc_inc = ATOMIC_INIT(0);
static int stepper_freq = 1024; /* Frequency Hz */
static void stepper_interrupt(void *private_data)
{
int ticks;
atomic_inc(&rtc_inc);
ticks = atomic_read(&rtc_inc);
/* Add some code here to drive the stepper motor */
if (ticks % stepper_freq == 0) {
printk(KERN_WARNING "stepper_interrupt: %d\n", ticks);
}
}
static int __init stepper_init(void)
{
int err;
printk(KERN_ALERT "stepper_init: registering task\n");
rtc_task.func = stepper_interrupt;
err = rtc_register(&rtc_task);
if (err < 0)
return err;
rtc_control(&rtc_task, RTC_IRQP_SET, stepper_freq);
rtc_control(&rtc_task, RTC_PIE_ON, 0);
atomic_set(&rtc_inc, 0);
return 0;
}
static void __exit stepper_exit(void)
{
rtc_control(&rtc_task, RTC_PIE_OFF, 0);
rtc_unregister(&rtc_task);
printk(KERN_ALERT "stepper_exit: rtc_task unregistered\n");
}
module_init(stepper_init);
module_exit(stepper_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR(DRIVER_AUTHOR);
MODULE_DESCRIPTION(DRIVER_DESC);
#endif /* CONFIG_RTC || CONFIG_RTC_MODULE */
(
Log in to post comments)