请选择 进入手机版 | 继续访问电脑版
搜索

8

主题

21

帖子

199

积分

注册会员

Rank: 2

积分
199
发表于 2017-6-12 14:49:10 11105 浏览 2 回复

RS485 内核提供的驱动的使用

你们好!!!
       (1)RS485 模块使用内核提供的驱动,并在内核中配置好RS485模块选项,编译移植内核后,RS485模块能够正常通信吗?
       (2)内核中提供的 RS485 驱动程序 drivers/char/max485_ctl.c 没有 数据的发送和接收功能,若是要使用 RS485 模块通信,是要重新编写 RS485 的驱动程序吗,还是可以将串口的驱动程序修改为 RS485 的驱动程序呢??

内核提供的 RS485 驱动程序 drivers/char/max485_ctl.c 如下:
  1. #include <linux/init.h>
  2. #include <linux/module.h>

  3. #include <linux/kernel.h>
  4. #include <linux/fs.h>
  5. #include <mach/gpio.h>
  6. #include <plat/gpio-cfg.h>
  7. #include <linux/miscdevice.h>
  8. #include <linux/platform_device.h>
  9. //#include <mach/gpio-bank.h>
  10. #include <mach/regs-gpio.h>
  11. #include <asm/io.h>
  12. #include <linux/regulator/consumer.h>        //cwp, PMIC interafce
  13. //#include "gps.h"
  14. #include <linux/delay.h>

  15. #define GPS_DEBUG
  16. #ifdef GPS_DEBUG
  17. #define DPRINTK(x...) printk("MAX485_CTL DEBUG:" x)
  18. #else
  19. #define DPRINTK(x...)
  20. #endif

  21. #define DRIVER_NAME "max485_ctl"

  22. int max485_ctl_open(struct inode *inode,struct file *filp)
  23. {
  24.         DPRINTK("Device Opened Success!\n");
  25.         return nonseekable_open(inode,filp);
  26. }

  27. int max485_ctl_release(struct inode *inode,struct file *filp)
  28. {
  29.         DPRINTK("Device Closed Success!\n");
  30.         return 0;
  31. }

  32. int max485_ctl_pm(bool enable)
  33. {
  34.         int ret = 0;
  35.         printk("firecxx debug: GPS PM return %d\r\n" , ret);
  36.         return ret;
  37. };

  38. long max485_ctl_ioctl(struct file *filp,unsigned int cmd,unsigned long arg)
  39. {
  40.         printk("firecxx debug: max485_ctl_ioctl cmd is %d\n" , cmd);

  41.         switch(cmd)
  42.         {               
  43.                 case 1:
  44.                         if(gpio_request(EXYNOS4_GPA0(7) ,"GPA0_7"))
  45.                         {
  46.                                 DPRINTK("max485_ctl GPIO err!\r\n");
  47.                         }
  48.                         else
  49.                         {
  50.                                 gpio_direction_output(EXYNOS4_GPA0(7), 1);
  51.                                 DPRINTK("max485_ctl Set High!\n");
  52.                                 gpio_free(EXYNOS4_GPA0(7));

  53.                                 mdelay(100);
  54.                         }
  55.                                
  56.                         break;
  57.                 case 0:
  58.                         if(gpio_request(EXYNOS4_GPA0(7) ,"GPA0_7"))
  59.                         {
  60.                                 DPRINTK("max485_ctl GPIO err!\r\n");
  61.                         }
  62.                         else
  63.                         {                       
  64.                                 gpio_direction_output(EXYNOS4_GPA0(7),0);
  65.                                 DPRINTK("max485_ctl Set Low!\n");
  66.                                 gpio_free(EXYNOS4_GPA0(7));

  67.                                 mdelay(100);
  68.                         }
  69.                        
  70.                         break;
  71.                        
  72.                 default:
  73.                         DPRINTK("max485_ctl COMMAND ERROR!\n");
  74.                         return -ENOTTY;
  75.         }
  76.         return 0;
  77. }

  78. static struct file_operations max485_ctl_ops = {
  79.         .owner         = THIS_MODULE,
  80.         .open         = max485_ctl_open,
  81.         .release= max485_ctl_release,
  82.         .unlocked_ioctl         = max485_ctl_ioctl,
  83. };

  84. static struct miscdevice max485_ctl_dev = {
  85.         .minor        = MISC_DYNAMIC_MINOR,
  86.         .fops        = &max485_ctl_ops,
  87.         .name        = "max485_ctl_pin",
  88. };


  89. static int max485_ctl_probe(struct platform_device *pdev)
  90. {
  91.         int err = 0;
  92.        
  93.         int ret;
  94.         char *banner = "max485_ctl Initialize\n";

  95.         printk(banner);

  96.         err = gpio_request(EXYNOS4_GPA0(7), "GPA0_7");
  97.         if (err) {
  98.                 printk(KERN_ERR "failed to request GPA0_7 for "
  99.                         "max485_ctl control\n");
  100.                 return err;
  101.         }
  102.         gpio_direction_output(EXYNOS4_GPA0(7), 1);

  103.         s3c_gpio_cfgpin(EXYNOS4_GPA0(7), S3C_GPIO_OUTPUT);
  104.         gpio_free(EXYNOS4_GPA0(7));

  105.         ret = misc_register(&max485_ctl_dev);
  106.         if(ret<0)
  107.         {
  108.                 printk("max485_ctl:register device failed!\n");
  109.                 goto exit;
  110.         }

  111.         return 0;

  112. exit:
  113.         misc_deregister(&max485_ctl_dev);
  114.         return ret;
  115. }

  116. static int max485_ctl_remove (struct platform_device *pdev)
  117. {
  118.         misc_deregister(&max485_ctl_dev);       

  119.         return 0;
  120. }

  121. static int max485_ctl_suspend (struct platform_device *pdev, pm_message_t state)
  122. {
  123.         DPRINTK("max485_ctl suspend:power off!\n");
  124.         return 0;
  125. }

  126. static int max485_ctl_resume (struct platform_device *pdev)
  127. {
  128.         DPRINTK("max485_ctl resume:power on!\n");
  129.         return 0;
  130. }

  131. static struct platform_driver max485_ctl_driver = {
  132.         .probe = max485_ctl_probe,
  133.         .remove = max485_ctl_remove,
  134.         .suspend = max485_ctl_suspend,
  135.         .resume = max485_ctl_resume,
  136.         .driver = {
  137.                 .name = DRIVER_NAME,
  138.                 .owner = THIS_MODULE,
  139.         },
  140. };

  141. static void __exit max485_ctl_exit(void)
  142. {
  143.         platform_driver_unregister(&max485_ctl_driver);
  144. }

  145. static int __init max485_ctl_init(void)
  146. {
  147.         return platform_driver_register(&max485_ctl_driver);
  148. }

  149. module_init(max485_ctl_init);
  150. module_exit(max485_ctl_exit);

  151. MODULE_LICENSE("Dual BSD/GPL");
复制代码

回复

使用道具 举报

48

主题

604

帖子

1923

积分

版主

Rank: 7Rank: 7Rank: 7

积分
1923
发表于 2017-6-12 15:22:39
485的原理和驱动很简单的。
你可以看下网盘资料
\iTOP4412开发板资料汇总(不含光盘内容)\iTOP-4412开发板视频教程及其相关\08-Linux驱动实验视频教程
\视频27
这几个视频介绍的是485~
回复 点赞

使用道具 举报

8

主题

21

帖子

199

积分

注册会员

Rank: 2

积分
199
 楼主| 发表于 2017-6-12 15:30:40
TOPEET_moon 发表于 2017-6-12 15:22
485的原理和驱动很简单的。
你可以看下网盘资料
\iTOP4412开发板资料汇总(不含光盘内容)\iTOP-4412开发 ...

好的,谢你啦!!!
回复 点赞

使用道具 举报

返回列表
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

登录或注册

官方客服

QQ:2551456065

官方QQ群

195631883

扫一扫关注迅为公众号

群号652692981

 
快速回复 返回顶部 返回列表