1. #include <linux/init.h>
  2. #include <linux/module.h>
  3. #include <linux/types.h>
  4. #include <linux/fs.h>
  5. #include <linux/cdev.h>
  6. #include <linux/device.h>
  7. #include <linux/uaccess.h>
  8. #include <linux/kernel.h>
  9. #include <linux/errno.h>
  10. #include <linux/miscdevice.h>
  11. #include <linux/signal.h>
  12. #include <linux/timer.h>
  13. #include <linux/slab.h>
  14.  
  15. #define printw(fmt, ...) ({printk( KERN_ERR "[ksync] " fmt, ##__VA_ARGS__); 0; })
  16.  
  17. ;
  18. struct cdev testcdev;
  19. struct class *myclass;
  20. static struct fasync_struct *async;
  21. ][] = {};
  22.  
  23. int hexdump(unsigned char *name, unsigned char *data, unsigned short len)
  24. {
  25. unsigned char *buf;
  26. int i, p, ret;
  27. unsigned ] = {};
  28. unsigned ;
  29.  
  30. tmp_len = sprintf(tmp, "%s hex(len=%d): ", name, len);
  31. )
  32. len = ;
  33. buf = kmalloc( (len + ) * + tmp_len, GFP_KERNEL);
  34. memset(buf, ) * + tmp_len);
  35. memcpy(buf, tmp, tmp_len);
  36.  
  37. == len))
  38. {
  39. printw("%s\n", buf);
  40. kfree(buf);
  41. ;
  42. }
  43. , p = tmp_len; i < len; i++)
  44. {
  45. ret = sprintf((buf + p), "%02x ", *(data + i));
  46. p = p + ret;
  47. }
  48. printw("%s\n", buf);
  49. kfree(buf);
  50. ;
  51. }
  52.  
  53. void ksync_send(unsigned short cmd, unsigned char *buffer, short len)
  54. {
  55. unsigned ] = {};
  56. sprintf(string, "%s(0x%x, %d)", __func__, cmd, len);
  57.  
  58. memcpy(fsync_buffer[] + , ();
  59. memcpy(fsync_buffer[] + , ();
  60. memcpy(fsync_buffer[] + , buffer, len);
  61. hexdump(], len+);
  62. kill_fasync(&async, SIGIO, POLL_IN);
  63. }
  64.  
  65. void ksync_recv(unsigned short cmd, unsigned char *buffer, short len)
  66. {
  67. unsigned ] = {};
  68. sprintf(string, "%s(0x%x, %d)", __func__, cmd, len);
  69. hexdump(string, buffer, len);
  70. ksync_send(0x57, buffer, len);
  71. }
  72.  
  73. int char_open(struct inode *inode, struct file *filp)
  74. {
  75. printw("char_open ok...\n");
  76. ;
  77. }
  78.  
  79. static int char_fasync(int fd, struct file *filp, int mode)
  80. {
  81. return fasync_helper(fd, filp, mode, &async);
  82. }
  83.  
  84. int char_release(struct inode *inode,struct file *filp)
  85. {
  86. printw("char close\n");
  87. , filp, );;
  88. }
  89. int char_ioctl (struct inode *inode, struct file *filelp, unsigned int cmd, unsigned long args)
  90. {
  91.  
  92. ;
  93.  
  94. }
  95. ssize_t char_write(struct file *filp, const char __user *buffer, size_t count, loff_t *offset)
  96. {
  97. unsigned ];
  98. printw("%s\n", __func__);
  99. ], buffer, count))
  100. {
  101. return -EFAULT;
  102. }
  103. hexdump("char_write", buffer, count);
  104. memcpy((], );
  105. ksync_recv( info[], fsync_buffer[] + , info[] );
  106. printw("char_write ok...\n");
  107. return count;
  108. }
  109.  
  110. ssize_t char_read(struct file *filp, char __user *buffer, size_t count, loff_t *offset)
  111. {
  112. int ret;
  113. ret = copy_to_user( (unsigned ], count);
  114. != ret) {
  115. printw("[%s][%d][err]\n", __func__, __LINE__);
  116. return -EFAULT;
  117. }
  118. filp->f_pos += count;
  119. hexdump(], count);
  120. printw("char_read ok...\n");
  121. ;
  122. }
  123.  
  124. struct file_operations fop =
  125. {
  126. .open = char_open,
  127. .release = char_release,
  128. .compat_ioctl = char_ioctl,
  129. .write = char_write,
  130. .read = char_read,
  131. .fasync = char_fasync,
  132. };
  133.  
  134. int __init a_init(void)
  135. {
  136.  
  137. dev_t dev;
  138. int ret;
  139. dev = MKDEV(major,);
  140. ret = register_chrdev_region(dev,,"char");
  141. if(ret)
  142. {
  143. alloc_chrdev_region(&dev,,,"char");
  144. major = MAJOR(dev);
  145. }
  146.  
  147. testcdev.owner = THIS_MODULE;
  148. cdev_init(&testcdev, &fop);
  149. cdev_add(&testcdev, dev, );
  150.  
  151. myclass = class_create(THIS_MODULE, "char_class");
  152. device_create(myclass,NULL,dev,NULL, "ksync");
  153. printw("module init ok ...\n");
  154. ;
  155. }
  156.  
  157. void __exit a_exit(void)
  158. {
  159. dev_t dev;
  160. dev = MKDEV(major ,);
  161.  
  162. device_destroy(myclass, dev);
  163. class_destroy(myclass);
  164.  
  165. cdev_del(&testcdev);
  166. unregister_chrdev_region(dev,);
  167. printw("module exit ok....\n");
  168. }
  169.  
  170. module_init(a_init);
  171. module_exit(a_exit);
  172. MODULE_LICENSE("GPL");
  173. MODULE_AUTHOR("...");
  174. MODULE_DESCRIPTION("ksync");
  175. MODULE_VERSION("V1.0");
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <signal.h>
  4. #include <fcntl.h>
  5. int g_fd;
  6. unsigned ][] = {};
  7.  
  8. int hexdump(unsigned char *name, unsigned char *data, unsigned short len)
  9. {
  10. unsigned char *buf;
  11. int i, p, ret;
  12. unsigned ] = {};
  13. unsigned ;
  14.  
  15. tmp_len = sprintf(tmp, "%s hex(len=%d): ", name, len);
  16. )
  17. len = ;
  18. buf = ) * + tmp_len);
  19. memset(buf, ) * + tmp_len);
  20. memcpy(buf, tmp, tmp_len);
  21.  
  22. == len))
  23. {
  24. printf("%s\n", buf);
  25. free(buf);
  26. ;
  27. }
  28. , p = tmp_len; i < len; i++)
  29. {
  30. ret = sprintf((buf + p), "%02x ", *(data + i));
  31. p = p + ret;
  32. }
  33. printf("%s\n", buf);
  34. free(buf);
  35. ;
  36. }
  37.  
  38. void ksync_recv(unsigned short cmd, unsigned char *buffer, short len)
  39. {
  40.  
  41. }
  42.  
  43. void ksync_send(unsigned short cmd, unsigned char *buffer, short len)
  44. {
  45. unsigned ];
  46. int ret;
  47.  
  48. memcpy(s_buf + , ();
  49. memcpy(s_buf + , ();
  50. memcpy(s_buf + , buffer, len);
  51. hexdump();
  52. ret = write(g_fd, s_buf, len + );
  53. printf("write ret %d\n", ret);
  54. }
  55.  
  56. void sig_handler(int sig)
  57. {
  58. int ret;
  59. unsigned ];
  60. unsigned ];
  61. if(sig == SIGIO)
  62. {
  63. ret = read(g_fd, r_buf, );
  64. memcpy((], r_buf + , );
  65. memcpy((], r_buf + , );
  66. hexdump(]+);
  67. ksync_recv(info[], r_buf + , info[]);
  68. }
  69. return;
  70. }
  71.  
  72. int main(void)
  73. {
  74. unsigned ];
  75. signal(SIGIO, sig_handler);
  76. g_fd = open("/dev/ksync", O_RDWR);
  77. == g_fd)
  78. {
  79. printf("open err\n");
  80. ;
  81. }
  82. printf("open %d\n", g_fd);
  83. fcntl(g_fd, F_SETOWN, getpid());
  84. fcntl(g_fd, F_SETFL, fcntl(g_fd, F_GETFL) | FASYNC);
  85. )
  86. {
  87. memset(input, );
  88. gets(input);
  89. fflush(stdin);
  90. )
  91. continue;
  92. ksync_send(0x56, input, strlen(input) );
  93. }
  94. ;
  95. }
  1. # Makefile for PEDD
  2.  
  3. EXTRA_CFLAGS += -Wframe-larger-than=
  4.  
  5. ifneq ($(CROSS_COMPILE),)
  6. EXTRA_CFLAGS += -DARC_SDP
  7. endif
  8.  
  9. ifeq ($(KERNELRELEASE),)
  10.  
  11. ifeq ($(CROSS_COMPILE),)
  12. KERNELDIR ?= /lib/modules/$(shell uname -r)/build
  13. else
  14. KERNELDIR ?= /workspace/bpcie/output/build/linux-arc-axs101--3.13
  15. endif
  16.  
  17. PWD := $(shell pwd)
  18.  
  19. modules:
  20. $(MAKE) -C $(KERNELDIR) M=$(PWD) modules
  21.  
  22. modules_install:
  23. $(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install
  24.  
  25. clean:
  26. rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions *.symvers *.order *.out
  27.  
  28. .PHONY: modules modules_install clean
  29.  
  30. else
  31.  
  32. obj-m := ksync_drv.o
  33.  
  34. endif

ksync的更多相关文章

  1. 使用ksync 加速基于k8s 的应用开发

      ksync 实际上实现了类似 docker docker run -v /foo:/bar 的功能,可以加速我们应用的开发&&运行 安装 mac os curl https://v ...

随机推荐

  1. 解决 layui 弹出层(弹框)一闪而过就消失的问题 (转载)

    转载: 原文链接:https://blog.csdn.net/qq_20594019/article/details/83956532 本人遇到问题:使用layer.open()弹出页面层,出现弹框闪 ...

  2. 两种查看EFCore生成Sql语句的方法

    一.利用反射生成查询语句 该方法转载自:https://jhrs.com/2019/28488.html (略有修改) using Microsoft.EntityFrameworkCore.Quer ...

  3. Vue模板语法中数据绑定

    1.单项数据绑定 <div id="di"> <input type="text" :value="input_val"& ...

  4. ADB控制手机命令(adb命令)

    手机端配置tcp方式连接 su setprop service.adb.tcp.port 5555 stop adbd start adbd 首先使用管理员权限,然后打开监听5555端口 电脑端使用a ...

  5. 解决webservice(Java)中dao层注入为null问题

    首先在webservice指定发布的路径类中实现 ServletContextListener, 例如: import javax.servlet.ServletContextEvent; impor ...

  6. 论文学习-wlg-基于二维材料的肖特基异质结构的通用尺度定律

    目录 主要公式: 各个段落的内容 第一页 第二页 第三页 名词的含义 功函数: 电子亲和力 肖特基势垒 肖特基二极管的原理 非相对论性电子气:未知 Rashba自旋电子系统: 参考链接: 主要公式: ...

  7. [转]Spring Cloud在国内中小型公司能用起来吗?

    原文地址:http://www.cnblogs.com/ityouknow/p/7508306.html 原文地址:https://www.zhihu.com/question/61403505 今天 ...

  8. weblogic新增域并进行Jconsole监听

    一.创建域: 第一步,打开域配置界面: [bofm@UAT02-BIZ-ZJCG-AP-002 bin]$ cd /home/software/weblogic/Oracle/Middleware/w ...

  9. MySQL数据篇(五)--SQL对数据进行按月统计,或对数据进行按星期统计

    对于所有的需求,当你不知道怎么处理的时候,你就先用最简单的方法,或者说的明白一点,用最原始的方法,先实现业务需求再说. 一.对提现队列数据表“ims_checkout_task”进行汇总统计,按月汇总 ...

  10. python3+Scrapy爬虫使用pipeline数据保存到文本和数据库,数据少或者数据重复问题

    爬取的数据结果是没有错的,但是在保存数据的时候出错了,出现重复数据或者数据少问题.那为什么会造成这种结果呢? 其原因是由于Spider的速率比较快,而scapy操作数据库操作比较慢,导致pipelin ...