gprs_vs_func.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /******************************************************************************
  2. 版权所有:
  3. 文件名称: gprs_vs_func.c
  4. 文件版本: 01.01
  5. 创建作者: xxxxxx
  6. 创建日期: 2014-06-10
  7. 功能说明: GPRS虚拟串口操作函数
  8. 其它说明:
  9. 修改记录:
  10. */
  11. #ifndef CPU_FUXI
  12. #include <linux/kernel.h>
  13. #include <linux/init.h>
  14. #include <linux/module.h>
  15. #include <linux/moduleparam.h>
  16. #include <linux/fs.h>
  17. #include <linux/sched.h>
  18. #include <linux/interrupt.h>
  19. #include <linux/kthread.h>
  20. #include <linux/delay.h>
  21. #include <linux/wait.h>
  22. #include <asm/uaccess.h>
  23. #include <asm/io.h>
  24. #include <asm/ioctls.h>
  25. //#include <asm/semaphore.h>
  26. #include <linux/if.h>
  27. #include <linux/tcp.h>
  28. #include <termios.h>
  29. #include <linux/syscalls.h>
  30. #include "gprs_vs_func.h"
  31. //虚拟串口设备
  32. #ifdef CPU_AM335X
  33. #define GPRS_VS_DEV "/dev/ttyS04"
  34. #else
  35. #define GPRS_VS_DEV "/dev/ttyS10"
  36. #endif
  37. int g_vsfd = -1; //虚拟串口句柄
  38. /******************************************************************************
  39. 函数名称: gprs_vs_open
  40. 函数版本: 01.01
  41. 创建作者: xxxxxx
  42. 创建日期: 2014-06-10
  43. 函数说明: 打开虚拟串口.
  44. 参数说明:
  45. 无
  46. 返回值: 打开成功返回0,失败返回负数。
  47. 修改记录:
  48. */
  49. int gprs_vs_open(void)
  50. {
  51. int fd = 0;
  52. #ifdef CPU_AM335X
  53. fd = sys_open(GPRS_VS_DEV, O_RDWR|O_NONBLOCK, 0);
  54. #else
  55. fd = sys_open(GPRS_VS_DEV, O_RDWR, 0);
  56. #endif
  57. if(fd < 0)
  58. {
  59. //printk("open %s error!\n", GPRS_VS_DEV);
  60. return -1;
  61. }
  62. g_vsfd = fd;
  63. return 0;
  64. }
  65. /******************************************************************************
  66. 函数名称: gprs_vs_write
  67. 函数版本: 01.01
  68. 创建作者: xxxxxx
  69. 创建日期: 2014-06-10
  70. 函数说明: 虚拟串口发送函数.
  71. 参数说明:
  72. 无
  73. 返回值: 成功返回发送的字节数,失败返回负数。
  74. 修改记录:
  75. */
  76. int gprs_vs_write(const unsigned char * buf, int count)
  77. {
  78. int ret = 0;
  79. if(g_vsfd >= 0)
  80. {
  81. ret= sys_write(g_vsfd, buf, count);
  82. }
  83. return ret;
  84. }
  85. /******************************************************************************
  86. 函数名称: gprs_vs_read
  87. 函数版本: 01.01
  88. 创建作者: xxxxxx
  89. 创建日期: 2014-06-10
  90. 函数说明: 虚拟串口接收函数.
  91. 参数说明:
  92. 无
  93. 返回值: 成功返回读取的字节数,失败返回负数。
  94. 修改记录:
  95. */
  96. int gprs_vs_read(unsigned char * buf, int count)
  97. {
  98. int ret = 0;
  99. if(g_vsfd >= 0)
  100. {
  101. ret= sys_read(g_vsfd, buf, count);
  102. }
  103. return ret;
  104. }
  105. /******************************************************************************
  106. 函数名称: gprs_vs_close
  107. 函数版本: 01.01
  108. 创建作者: xxxxxx
  109. 创建日期: 2014-06-10
  110. 函数说明: 关闭虚拟串口.
  111. 参数说明:
  112. 无
  113. 返回值: 无。
  114. 修改记录:
  115. */
  116. void gprs_vs_close(void)
  117. {
  118. if(g_vsfd >= 0)
  119. {
  120. sys_close(g_vsfd);
  121. g_vsfd = -1;
  122. }
  123. }
  124. #endif