blob: 966ead188ee2320b58b0fc103591453a7915fb02 [file] [log] [blame]
Rodolfo Giometti697fb852010-03-10 15:23:45 -08001/*
2 * pps-ktimer.c -- kernel timer test client
3 *
4 *
5 * Copyright (C) 2005-2006 Rodolfo Giometti <giometti@linux.it>
6 *
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.
11 *
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.
16 *
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.
20 */
21
22
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>
29
30/*
31 * Global variables
32 */
33
Alexander Gordeev5e196d32011-01-12 17:00:51 -080034static struct pps_device *pps;
Rodolfo Giometti697fb852010-03-10 15:23:45 -080035static struct timer_list ktimer;
36
37/*
38 * The kernel timer
39 */
40
41static void pps_ktimer_event(unsigned long ptr)
42{
Alexander Gordeev6f4229b2011-01-12 17:00:50 -080043 struct pps_event_time ts;
Rodolfo Giometti697fb852010-03-10 15:23:45 -080044
45 /* First of all we get the time stamp... */
Alexander Gordeev6f4229b2011-01-12 17:00:50 -080046 pps_get_ts(&ts);
Rodolfo Giometti697fb852010-03-10 15:23:45 -080047
48 pr_info("PPS event at %lu\n", jiffies);
49
Alexander Gordeev5e196d32011-01-12 17:00:51 -080050 pps_event(pps, &ts, PPS_CAPTUREASSERT, NULL);
Rodolfo Giometti697fb852010-03-10 15:23:45 -080051
52 mod_timer(&ktimer, jiffies + HZ);
53}
54
55/*
56 * The echo function
57 */
58
Alexander Gordeev5e196d32011-01-12 17:00:51 -080059static void pps_ktimer_echo(struct pps_device *pps, int event, void *data)
Rodolfo Giometti697fb852010-03-10 15:23:45 -080060{
Alexander Gordeev5e196d32011-01-12 17:00:51 -080061 dev_info(pps->dev, "echo %s %s\n",
Rodolfo Giometti697fb852010-03-10 15:23:45 -080062 event & PPS_CAPTUREASSERT ? "assert" : "",
Alexander Gordeev5e196d32011-01-12 17:00:51 -080063 event & PPS_CAPTURECLEAR ? "clear" : "");
Rodolfo Giometti697fb852010-03-10 15:23:45 -080064}
65
66/*
67 * The PPS info struct
68 */
69
70static struct pps_source_info pps_ktimer_info = {
71 .name = "ktimer",
72 .path = "",
73 .mode = PPS_CAPTUREASSERT | PPS_OFFSETASSERT |
74 PPS_ECHOASSERT |
75 PPS_CANWAIT | PPS_TSFMT_TSPEC,
76 .echo = pps_ktimer_echo,
77 .owner = THIS_MODULE,
78};
79
80/*
81 * Module staff
82 */
83
84static void __exit pps_ktimer_exit(void)
85{
Alexander Gordeev5e196d32011-01-12 17:00:51 -080086 dev_info(pps->dev, "ktimer PPS source unregistered\n");
Rodolfo Giometti697fb852010-03-10 15:23:45 -080087
Alexander Gordeev5e196d32011-01-12 17:00:51 -080088 del_timer_sync(&ktimer);
89 pps_unregister_source(pps);
Rodolfo Giometti697fb852010-03-10 15:23:45 -080090}
91
92static int __init pps_ktimer_init(void)
93{
Alexander Gordeev5e196d32011-01-12 17:00:51 -080094 pps = pps_register_source(&pps_ktimer_info,
Rodolfo Giometti697fb852010-03-10 15:23:45 -080095 PPS_CAPTUREASSERT | PPS_OFFSETASSERT);
Alexander Gordeev5e196d32011-01-12 17:00:51 -080096 if (pps == NULL) {
Rodolfo Giometti697fb852010-03-10 15:23:45 -080097 printk(KERN_ERR "cannot register ktimer source\n");
Alexander Gordeev5e196d32011-01-12 17:00:51 -080098 return -ENOMEM;
Rodolfo Giometti697fb852010-03-10 15:23:45 -080099 }
Rodolfo Giometti697fb852010-03-10 15:23:45 -0800100
101 setup_timer(&ktimer, pps_ktimer_event, 0);
102 mod_timer(&ktimer, jiffies + HZ);
103
Alexander Gordeev5e196d32011-01-12 17:00:51 -0800104 dev_info(pps->dev, "ktimer PPS source registered\n");
Rodolfo Giometti697fb852010-03-10 15:23:45 -0800105
Alexander Gordeev5e196d32011-01-12 17:00:51 -0800106 return 0;
Rodolfo Giometti697fb852010-03-10 15:23:45 -0800107}
108
109module_init(pps_ktimer_init);
110module_exit(pps_ktimer_exit);
111
112MODULE_AUTHOR("Rodolfo Giometti <giometti@linux.it>");
113MODULE_DESCRIPTION("dummy PPS source by using a kernel timer (just for debug)");
114MODULE_LICENSE("GPL");