设备驱动实现步骤:

1. 按照RT-Thread对象模型,扩展一对象有两种方式:

1)定义自己的私有数据结构,然后赋值到RT-Thread设备控制空的user_data指针上;

2)从struct rt_device结构中派生。(推荐)

2. 实现I/O设备模块中定义的6个公共设备接口,开始可以为空函数(返回rt_err_t的可默认返回RT_EOK)。

3. 根据自己的设备类型定义自己的私有数据域。

特别是可能有多个类似设备的情况下(例如串口1,2),

设备接口可以共用一套接口,不同的只是各自的数据域(寄存器基地址)。

4. 根据设备的类型,注册到RT-Thread设备框架中。

现以串口驱动为例:

/*stm32f10x.h
*This file contains all the peripheral register's definitions, bits
* definitions and memory mapping for STM32F10x Connectivity line,
* High density, High density value line, Medium density,
* Medium density Value line, Low density, Low density Value line
* and XL-density devices. */
typedef struct
{
__IO uint16_t SR;
uint16_t RESERVED0;
__IO uint16_t DR;
uint16_t RESERVED1;
__IO uint16_t BRR;
uint16_t RESERVED2;
__IO uint16_t CR1;
uint16_t RESERVED3;
__IO uint16_t CR2;
uint16_t RESERVED4;
__IO uint16_t CR3;
uint16_t RESERVED5;
__IO uint16_t GTPR;
uint16_t RESERVED6;
} USART_TypeDef;
struct stm32_uart
{
USART_TypeDef* uart_device;
IRQn_Type irq;
};
struct rt_serial_device
{
struct rt_device parent; const struct rt_uart_ops *ops;
struct serial_configure config; void *serial_rx;
void *serial_tx;
};
typedef struct rt_serial_device rt_serial_t;
/*
* serial register
*/
rt_err_t rt_hw_serial_register(struct rt_serial_device *serial,
const char *name,
rt_uint32_t flag,
void *data)
{
struct rt_device *device;
RT_ASSERT(serial != RT_NULL); device = &(serial->parent); device->type = RT_Device_Class_Char;
device->rx_indicate = RT_NULL;
device->tx_complete = RT_NULL; device->init = rt_serial_init;
device->open = rt_serial_open;
device->close = rt_serial_close;
device->read = rt_serial_read;
device->write = rt_serial_write;
device->control = rt_serial_control;
device->user_data = data; /* register a character device */
return rt_device_register(device, name, flag);
}
    struct stm32_uart* uart;
rt_hw_serial_register(&serial1, "uart1",
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX ,
uart);

rt_serial_device设备驱动采用派生rt_device实现驱动,实现一套共用的驱动函数-------linux中相当于platform_driver;

rt_serial_device的私有数据保存具体设备相关参数(与硬件密切相关)------linux中相当于platform_device。

最后通过rt_hw_serial_register()/rt_device_register()将uart(硬件device)和rt_serial_device(驱动)注册到系统驱动框架中(rt_device)。

上述采用派生和私有数据相结合的方法可使具体硬件与驱动分开,便于单独修改硬件;

原来(旧版本)将具体硬件与驱动都通过私有数据注册到系统驱动框架中。------自己理解。

私有数据方式实现驱动可节省空间,效率可能更高。

当为了实现硬件与业务分开,故可约定俗成:业务用派生实现,硬件用私有数据实现。

RTT驱动实现步骤的更多相关文章

  1. 【OpenWRT】【RT5350】【三】MakeFile文件编写规则和OpenWRT驱动开发步骤

    一.Makefile文件编写 http://www.cnblogs.com/majiangjiang/articles/3218002.html 可以看下上面的博客,总结的比较全了,在此不再复述 二. ...

  2. 基于MT6752/32平台 Android L版本驱动移植步骤

    基于MT6752/32平台 Android L版本驱动移植步骤 根据MK官网所述,在Android L 版本上Turnkey ABS 架构将会phase out,而Mediatek Turnkey架构 ...

  3. (原)使用1080Ti显卡时安装ubuntu16.04.1及驱动的步骤

    转载请注明出处: http://www.cnblogs.com/darkknightzh/p/6811328.html 参考网址: http://www.cnblogs.com/darkknightz ...

  4. Linux驱动学习步骤(转载)

    1. 学会写简单的makefile 2. 编一应用程序,可以用makefile跑起来 3. 学会写驱动的makefile 4. 写一简单char驱动,makefile编译通过,可以insmod, ls ...

  5. S3C2440上RTC时钟驱动开发实例讲解(转载)

    嵌入式Linux之我行,主要讲述和总结了本人在学习嵌入式linux中的每个步骤.一为总结经验,二希望能给想入门嵌入式Linux的朋友提供方便.如有错误之处,谢请指正. 共享资源,欢迎转载:http:/ ...

  6. 在CentOS 6.7中安装NVIDIA GT730显卡驱动的手记

    主机: Dell OptiPlex 390 MT (i5) 系列: 主机原配独显,型号未知,运转三年半,常有异响,关机之后过一阵再开机,可以解决.最近,风扇的声音实在不正常,重启也无解,判定它挂了.风 ...

  7. 使用linux mint 安装无线网卡驱动

    新买了个笔记本Thinkpad E440,用了两天发现无线网非常不稳定,有时候能搜到wifi却连不上,有时候连上了却连不上互联网,于是决定重新安装个网卡驱动. 首先看看自己显卡的型号: lspci : ...

  8. Win7-64bit系统下安装mysql的ODBC驱动

    安装过mysql数据库后,有些软件在调用mysql数据库时不会直接调用,需要安装mysql数据库的ODBC驱动,再来调用.这里就介绍下,如何在win7系统下安装mysql的ODBC驱动. Win7系统 ...

  9. linux设备驱动归纳总结(十一):写个简单的看门狗驱动【转】

    本文转载自:http://blog.chinaunix.net/uid-25014876-id-112879.html linux设备驱动归纳总结(十一):写个简单的看门狗驱动 xxxxxxxxxxx ...

随机推荐

  1. 使用Maven下载jar包

    有些开源项目不直接提供jar包的下载,而是建议使用Maven下载,以开源库hipster(https://github.com/citiususc/hipster,http://www.hipster ...

  2. 再谈EditText只能输入金额

    上次写了一篇EditText只能输入金额的博客,后来发现一个bug,当还未输入数字的情况下输入小数点程序就崩了,我去测了一下支付宝,看看会怎么样,我先输入小数点,程序正常,我再输入数字,可以正常输入, ...

  3. 【tomcat】FileNotFoundException: C:\Program Files\Java\apache-tomcat-8.5.11-geneshop3\webapps\ROOT\index.html (拒绝访问。)

    新装系统后,tomcat启动起来 提示如下错误: Caused by: java.io.FileNotFoundException: C:\Program Files\Java\apache-tomc ...

  4. String的解析

    String作为Java中最常用的引用类型,相对来说基本上都比较熟悉,无论在平时的编码过程中还是在笔试面试中,String都很受到青睐,然而,在使用String过程中,又有较多需要注意的细节之处. 1 ...

  5. C#中的访问修饰符

    1. 简述 private. protected. public. internal 修饰符的访问权限.private : 私有成员, 在类的内部才可以访问.protected : 保护成员,该类内部 ...

  6. stat,查看文件属性

    shell命令,查看文件详细属性 别再跟我回答ls -l了

  7. Android SlidingMenu 使用具体解释

    转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/36677279 非常多APP都有側滑菜单的功能.部分APP左右都是側滑菜单~Sli ...

  8. [Android] 给图像加入相框、圆形圆角显示图片、图像合成知识

        前一篇文章讲述了Android触屏setOnTouchListener实现突破缩放.移动.绘制和加入水印,继续我的"随手拍"项目完毕给图片加入相框.圆形圆角显示图片和图像合 ...

  9. 各大网站css初始化代码【转】

    文章来源:http://blog.sina.com.cn/s/blog_71ed1b870101a52w.html 腾讯QQ官网(http://www.qq.com)样式初始化 body,ol,ul, ...

  10. Mybatis学习记录(二)----mybatis开发dao的方法

    1  SqlSession使用范围 1.1 SqlSessionFactoryBuilder 通过SqlSessionFactoryBuilder创建会话工厂SqlSessionFactory 将Sq ...