miropcm20-rds.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:3k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /* MiroSOUND PCM20 radio rds interface driver
  2.  * (c) 2001 Robert Siemer <Robert.Siemer@gmx.de>
  3.  * Thanks to Fred Seidel. See miropcm20-rds-core.c for further information.
  4.  */
  5. /* Revision history:
  6.  *
  7.  *   2001-04-18  Robert Siemer <Robert.Siemer@gmx.de>
  8.  *        separate file for user interface driver
  9.  */
  10. #include <linux/module.h>
  11. #include <linux/init.h>
  12. #include <linux/slab.h>
  13. #include <asm/uaccess.h>
  14. #include <linux/devfs_fs_kernel.h>
  15. #include "miropcm20-rds-core.h"
  16. devfs_handle_t dfsh;
  17. char * text_buffer;
  18. static int rds_users = 0;
  19. static int rds_f_open(struct inode *in, struct file *fi)
  20. {
  21. if(rds_users)
  22. return -EBUSY;
  23. if ((text_buffer=kmalloc(66, GFP_KERNEL)) == 0) {
  24. printk(KERN_NOTICE "aci-rds: Out of memory by open()...n");
  25. return -ENOMEM;
  26. }
  27. rds_users++;
  28. MOD_INC_USE_COUNT;
  29. return 0;
  30. }
  31. static int rds_f_release(struct inode *in, struct file *fi)
  32. {
  33. kfree(text_buffer);
  34. rds_users--;
  35. MOD_DEC_USE_COUNT;
  36. return 0;
  37. }
  38. static void print_matrix(char *ch, char out[])
  39. {
  40.         int j;
  41. for (j=7; j>=0; j--) {
  42.  out[7-j] = ((*ch >> j) & 0x1) + '0';
  43. }
  44. }
  45. static ssize_t rds_f_read(struct file *file, char *buffer, size_t length, loff_t *offset)
  46. {
  47. // i = sprintf(text_buffer, "length: %d, offset: %dn", length, *offset);
  48. char c;
  49. char bits[8];
  50. current->state=TASK_UNINTERRUPTIBLE;
  51. schedule_timeout(2*HZ);
  52. aci_rds_cmd(RDS_STATUS, &c, 1);
  53. print_matrix(&c, bits);
  54. if (copy_to_user(buffer, bits, 8))
  55. return -EFAULT;
  56. /* if ((c >> 3) & 1) {
  57. aci_rds_cmd(RDS_STATIONNAME, text_buffer+1, 8);
  58. text_buffer[0]  = ' ' ;
  59. text_buffer[9]  = 'n';
  60. return copy_to_user(buffer+8, text_buffer, 10) ? -EFAULT: 18;
  61. }
  62. */
  63. /* if ((c >> 6) & 1) {
  64. aci_rds_cmd(RDS_PTYTATP, &c, 1);
  65. if ( c & 1)
  66. sprintf(text_buffer, " M");
  67. else
  68. sprintf(text_buffer, " S");
  69. if ((c >> 1) & 1)
  70. sprintf(text_buffer+2, " TA");
  71. else
  72. sprintf(text_buffer+2, " --");
  73. if ((c >> 7) & 1)
  74. sprintf(text_buffer+5, " TP");
  75. else
  76. sprintf(text_buffer+5, " --");
  77. sprintf(text_buffer+8, " %2dn", (c >> 2) & 0x1f);
  78. return copy_to_user(buffer+8, text_buffer, 12) ? -EFAULT: 20;
  79. }
  80. */
  81. if ((c >> 4) & 1) {
  82. aci_rds_cmd(RDS_TEXT, text_buffer, 65);
  83. text_buffer[0]  = ' ' ;
  84. text_buffer[65] = 'n';
  85. return copy_to_user(buffer+8, text_buffer,66) ? -EFAULT : 66+8;
  86. } else {
  87. put_user('n', buffer+8);
  88. return 9;
  89. }
  90. }
  91. static struct file_operations rds_f_ops = {
  92. read:    rds_f_read,
  93. open:    rds_f_open,
  94. release: rds_f_release
  95. };
  96. static int __init miropcm20_rds_init(void)
  97. {
  98. if ((dfsh = devfs_register(NULL, "v4l/rds/radiotext", 
  99.    DEVFS_FL_DEFAULT | DEVFS_FL_AUTO_DEVNUM,
  100.    0, 0, S_IRUGO | S_IFCHR, &rds_f_ops, NULL))
  101.     == NULL)
  102. goto devfs_register;
  103. printk("miropcm20-rds: userinterface driver loaded.n");
  104. #if DEBUG
  105. printk("v4l-name: %sn", devfs_get_name(pcm20_radio.devfs_handle, 0));
  106. #endif
  107. return 0;
  108.  devfs_register:
  109. return -EINVAL;
  110. }
  111. static void __exit miropcm20_rds_cleanup(void)
  112. {
  113. devfs_unregister(dfsh);
  114. }
  115. module_init(miropcm20_rds_init);
  116. module_exit(miropcm20_rds_cleanup);
  117. MODULE_LICENSE("GPL");