pps-ktimer.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  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. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  22. #include <linux/kernel.h>
  23. #include <linux/module.h>
  24. #include <linux/init.h>
  25. #include <linux/time.h>
  26. #include <linux/timer.h>
  27. #include <linux/pps_kernel.h>
  28. /*
  29. * Global variables
  30. */
  31. static struct pps_device *pps;
  32. static struct timer_list ktimer;
  33. /*
  34. * The kernel timer
  35. */
  36. static void pps_ktimer_event(unsigned long ptr)
  37. {
  38. struct pps_event_time ts;
  39. /* First of all we get the time stamp... */
  40. pps_get_ts(&ts);
  41. dev_info(pps->dev, "PPS event at %lu\n", jiffies);
  42. pps_event(pps, &ts, PPS_CAPTUREASSERT, NULL);
  43. mod_timer(&ktimer, jiffies + HZ);
  44. }
  45. /*
  46. * The echo function
  47. */
  48. static void pps_ktimer_echo(struct pps_device *pps, int event, void *data)
  49. {
  50. dev_info(pps->dev, "echo %s %s\n",
  51. event & PPS_CAPTUREASSERT ? "assert" : "",
  52. event & PPS_CAPTURECLEAR ? "clear" : "");
  53. }
  54. /*
  55. * The PPS info struct
  56. */
  57. static struct pps_source_info pps_ktimer_info = {
  58. .name = "ktimer",
  59. .path = "",
  60. .mode = PPS_CAPTUREASSERT | PPS_OFFSETASSERT |
  61. PPS_ECHOASSERT |
  62. PPS_CANWAIT | PPS_TSFMT_TSPEC,
  63. .echo = pps_ktimer_echo,
  64. .owner = THIS_MODULE,
  65. };
  66. /*
  67. * Module staff
  68. */
  69. static void __exit pps_ktimer_exit(void)
  70. {
  71. dev_info(pps->dev, "ktimer PPS source unregistered\n");
  72. del_timer_sync(&ktimer);
  73. pps_unregister_source(pps);
  74. }
  75. static int __init pps_ktimer_init(void)
  76. {
  77. pps = pps_register_source(&pps_ktimer_info,
  78. PPS_CAPTUREASSERT | PPS_OFFSETASSERT);
  79. if (pps == NULL) {
  80. pr_err("cannot register PPS source\n");
  81. return -ENOMEM;
  82. }
  83. setup_timer(&ktimer, pps_ktimer_event, 0);
  84. mod_timer(&ktimer, jiffies + HZ);
  85. dev_info(pps->dev, "ktimer PPS source registered\n");
  86. return 0;
  87. }
  88. module_init(pps_ktimer_init);
  89. module_exit(pps_ktimer_exit);
  90. MODULE_AUTHOR("Rodolfo Giometti <giometti@linux.it>");
  91. MODULE_DESCRIPTION("dummy PPS source by using a kernel timer (just for debug)");
  92. MODULE_LICENSE("GPL");