]>
Commit | Line | Data |
---|---|---|
697fb85f RG |
1 | /* |
2 | * pps-ktimer.c -- kernel timer test client | |
3 | * | |
4 | * | |
5 | * Copyright (C) 2005-2006 Rodolfo Giometti <[email protected]> | |
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 | ||
7f7cce74 | 22 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
697fb85f RG |
23 | |
24 | #include <linux/kernel.h> | |
25 | #include <linux/module.h> | |
26 | #include <linux/init.h> | |
27 | #include <linux/time.h> | |
28 | #include <linux/timer.h> | |
29 | #include <linux/pps_kernel.h> | |
30 | ||
31 | /* | |
32 | * Global variables | |
33 | */ | |
34 | ||
5e196d34 | 35 | static struct pps_device *pps; |
697fb85f RG |
36 | static struct timer_list ktimer; |
37 | ||
38 | /* | |
39 | * The kernel timer | |
40 | */ | |
41 | ||
e99e88a9 | 42 | static void pps_ktimer_event(struct timer_list *unused) |
697fb85f | 43 | { |
6f4229b5 | 44 | struct pps_event_time ts; |
697fb85f RG |
45 | |
46 | /* First of all we get the time stamp... */ | |
6f4229b5 | 47 | pps_get_ts(&ts); |
697fb85f | 48 | |
5e196d34 | 49 | pps_event(pps, &ts, PPS_CAPTUREASSERT, NULL); |
697fb85f RG |
50 | |
51 | mod_timer(&ktimer, jiffies + HZ); | |
52 | } | |
53 | ||
697fb85f RG |
54 | /* |
55 | * The PPS info struct | |
56 | */ | |
57 | ||
58 | static struct pps_source_info pps_ktimer_info = { | |
59 | .name = "ktimer", | |
60 | .path = "", | |
61 | .mode = PPS_CAPTUREASSERT | PPS_OFFSETASSERT | | |
62 | PPS_ECHOASSERT | | |
63 | PPS_CANWAIT | PPS_TSFMT_TSPEC, | |
697fb85f RG |
64 | .owner = THIS_MODULE, |
65 | }; | |
66 | ||
67 | /* | |
68 | * Module staff | |
69 | */ | |
70 | ||
71 | static void __exit pps_ktimer_exit(void) | |
72 | { | |
5e196d34 | 73 | dev_info(pps->dev, "ktimer PPS source unregistered\n"); |
697fb85f | 74 | |
5e196d34 AG |
75 | del_timer_sync(&ktimer); |
76 | pps_unregister_source(pps); | |
697fb85f RG |
77 | } |
78 | ||
79 | static int __init pps_ktimer_init(void) | |
80 | { | |
5e196d34 | 81 | pps = pps_register_source(&pps_ktimer_info, |
697fb85f | 82 | PPS_CAPTUREASSERT | PPS_OFFSETASSERT); |
5e196d34 | 83 | if (pps == NULL) { |
7f7cce74 | 84 | pr_err("cannot register PPS source\n"); |
5e196d34 | 85 | return -ENOMEM; |
697fb85f | 86 | } |
697fb85f | 87 | |
e99e88a9 | 88 | timer_setup(&ktimer, pps_ktimer_event, 0); |
697fb85f RG |
89 | mod_timer(&ktimer, jiffies + HZ); |
90 | ||
5e196d34 | 91 | dev_info(pps->dev, "ktimer PPS source registered\n"); |
697fb85f | 92 | |
5e196d34 | 93 | return 0; |
697fb85f RG |
94 | } |
95 | ||
96 | module_init(pps_ktimer_init); | |
97 | module_exit(pps_ktimer_exit); | |
98 | ||
99 | MODULE_AUTHOR("Rodolfo Giometti <[email protected]>"); | |
100 | MODULE_DESCRIPTION("dummy PPS source by using a kernel timer (just for debug)"); | |
101 | MODULE_LICENSE("GPL"); |