Linux 2.6.34-rc3
[pohmelfs.git] / drivers / pps / clients / pps-ktimer.c
blobe7ef5b8186d062284a92cd7f1347a94baddd2423
1 /*
2 * pps-ktimer.c -- kernel timer test client
5 * Copyright (C) 2005-2006 Rodolfo Giometti <giometti@linux.it>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include <linux/kernel.h>
24 #include <linux/module.h>
25 #include <linux/init.h>
26 #include <linux/time.h>
27 #include <linux/timer.h>
28 #include <linux/pps_kernel.h>
31 * Global variables
34 static int source;
35 static struct timer_list ktimer;
38 * The kernel timer
41 static void pps_ktimer_event(unsigned long ptr)
43 struct timespec __ts;
44 struct pps_ktime ts;
46 /* First of all we get the time stamp... */
47 getnstimeofday(&__ts);
49 pr_info("PPS event at %lu\n", jiffies);
51 /* ... and translate it to PPS time data struct */
52 ts.sec = __ts.tv_sec;
53 ts.nsec = __ts.tv_nsec;
55 pps_event(source, &ts, PPS_CAPTUREASSERT, NULL);
57 mod_timer(&ktimer, jiffies + HZ);
61 * The echo function
64 static void pps_ktimer_echo(int source, int event, void *data)
66 pr_info("echo %s %s for source %d\n",
67 event & PPS_CAPTUREASSERT ? "assert" : "",
68 event & PPS_CAPTURECLEAR ? "clear" : "",
69 source);
73 * The PPS info struct
76 static struct pps_source_info pps_ktimer_info = {
77 .name = "ktimer",
78 .path = "",
79 .mode = PPS_CAPTUREASSERT | PPS_OFFSETASSERT |
80 PPS_ECHOASSERT |
81 PPS_CANWAIT | PPS_TSFMT_TSPEC,
82 .echo = pps_ktimer_echo,
83 .owner = THIS_MODULE,
87 * Module staff
90 static void __exit pps_ktimer_exit(void)
92 del_timer_sync(&ktimer);
93 pps_unregister_source(source);
95 pr_info("ktimer PPS source unregistered\n");
98 static int __init pps_ktimer_init(void)
100 int ret;
102 ret = pps_register_source(&pps_ktimer_info,
103 PPS_CAPTUREASSERT | PPS_OFFSETASSERT);
104 if (ret < 0) {
105 printk(KERN_ERR "cannot register ktimer source\n");
106 return ret;
108 source = ret;
110 setup_timer(&ktimer, pps_ktimer_event, 0);
111 mod_timer(&ktimer, jiffies + HZ);
113 pr_info("ktimer PPS source registered at %d\n", source);
115 return 0;
118 module_init(pps_ktimer_init);
119 module_exit(pps_ktimer_exit);
121 MODULE_AUTHOR("Rodolfo Giometti <giometti@linux.it>");
122 MODULE_DESCRIPTION("dummy PPS source by using a kernel timer (just for debug)");
123 MODULE_LICENSE("GPL");