| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- /******************************************************************************
- 版权所有:
- 文件名称: gprs_vs_func.c
- 文件版本: 01.01
- 创建作者: xxxxxx
- 创建日期: 2014-06-10
- 功能说明: GPRS虚拟串口操作函数
- 其它说明:
- 修改记录:
- */
- #ifndef CPU_FUXI
- #include <linux/kernel.h>
- #include <linux/init.h>
- #include <linux/module.h>
- #include <linux/moduleparam.h>
- #include <linux/fs.h>
- #include <linux/sched.h>
- #include <linux/interrupt.h>
- #include <linux/kthread.h>
- #include <linux/delay.h>
- #include <linux/wait.h>
- #include <asm/uaccess.h>
- #include <asm/io.h>
- #include <asm/ioctls.h>
- //#include <asm/semaphore.h>
- #include <linux/if.h>
- #include <linux/tcp.h>
- #include <termios.h>
- #include <linux/syscalls.h>
- #include "gprs_vs_func.h"
- //虚拟串口设备
- #ifdef CPU_AM335X
- #define GPRS_VS_DEV "/dev/ttyS04"
- #else
- #define GPRS_VS_DEV "/dev/ttyS10"
- #endif
- int g_vsfd = -1; //虚拟串口句柄
- /******************************************************************************
- 函数名称: gprs_vs_open
- 函数版本: 01.01
- 创建作者: xxxxxx
- 创建日期: 2014-06-10
- 函数说明: 打开虚拟串口.
- 参数说明:
- 无
- 返回值: 打开成功返回0,失败返回负数。
- 修改记录:
- */
- int gprs_vs_open(void)
- {
- int fd = 0;
-
- #ifdef CPU_AM335X
- fd = sys_open(GPRS_VS_DEV, O_RDWR|O_NONBLOCK, 0);
- #else
- fd = sys_open(GPRS_VS_DEV, O_RDWR, 0);
- #endif
- if(fd < 0)
- {
- //printk("open %s error!\n", GPRS_VS_DEV);
- return -1;
- }
-
- g_vsfd = fd;
- return 0;
- }
- /******************************************************************************
- 函数名称: gprs_vs_write
- 函数版本: 01.01
- 创建作者: xxxxxx
- 创建日期: 2014-06-10
- 函数说明: 虚拟串口发送函数.
- 参数说明:
- 无
- 返回值: 成功返回发送的字节数,失败返回负数。
- 修改记录:
- */
- int gprs_vs_write(const unsigned char * buf, int count)
- {
- int ret = 0;
-
- if(g_vsfd >= 0)
- {
- ret= sys_write(g_vsfd, buf, count);
- }
- return ret;
- }
- /******************************************************************************
- 函数名称: gprs_vs_read
- 函数版本: 01.01
- 创建作者: xxxxxx
- 创建日期: 2014-06-10
- 函数说明: 虚拟串口接收函数.
- 参数说明:
- 无
- 返回值: 成功返回读取的字节数,失败返回负数。
- 修改记录:
- */
- int gprs_vs_read(unsigned char * buf, int count)
- {
- int ret = 0;
-
- if(g_vsfd >= 0)
- {
- ret= sys_read(g_vsfd, buf, count);
- }
- return ret;
- }
- /******************************************************************************
- 函数名称: gprs_vs_close
- 函数版本: 01.01
- 创建作者: xxxxxx
- 创建日期: 2014-06-10
- 函数说明: 关闭虚拟串口.
- 参数说明:
- 无
- 返回值: 无。
- 修改记录:
- */
- void gprs_vs_close(void)
- {
- if(g_vsfd >= 0)
- {
- sys_close(g_vsfd);
- g_vsfd = -1;
- }
-
- }
- #endif
|