RTT驱动实现步骤
设备驱动实现步骤:
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驱动实现步骤的更多相关文章
- 【OpenWRT】【RT5350】【三】MakeFile文件编写规则和OpenWRT驱动开发步骤
一.Makefile文件编写 http://www.cnblogs.com/majiangjiang/articles/3218002.html 可以看下上面的博客,总结的比较全了,在此不再复述 二. ...
- 基于MT6752/32平台 Android L版本驱动移植步骤
基于MT6752/32平台 Android L版本驱动移植步骤 根据MK官网所述,在Android L 版本上Turnkey ABS 架构将会phase out,而Mediatek Turnkey架构 ...
- (原)使用1080Ti显卡时安装ubuntu16.04.1及驱动的步骤
转载请注明出处: http://www.cnblogs.com/darkknightzh/p/6811328.html 参考网址: http://www.cnblogs.com/darkknightz ...
- Linux驱动学习步骤(转载)
1. 学会写简单的makefile 2. 编一应用程序,可以用makefile跑起来 3. 学会写驱动的makefile 4. 写一简单char驱动,makefile编译通过,可以insmod, ls ...
- S3C2440上RTC时钟驱动开发实例讲解(转载)
嵌入式Linux之我行,主要讲述和总结了本人在学习嵌入式linux中的每个步骤.一为总结经验,二希望能给想入门嵌入式Linux的朋友提供方便.如有错误之处,谢请指正. 共享资源,欢迎转载:http:/ ...
- 在CentOS 6.7中安装NVIDIA GT730显卡驱动的手记
主机: Dell OptiPlex 390 MT (i5) 系列: 主机原配独显,型号未知,运转三年半,常有异响,关机之后过一阵再开机,可以解决.最近,风扇的声音实在不正常,重启也无解,判定它挂了.风 ...
- 使用linux mint 安装无线网卡驱动
新买了个笔记本Thinkpad E440,用了两天发现无线网非常不稳定,有时候能搜到wifi却连不上,有时候连上了却连不上互联网,于是决定重新安装个网卡驱动. 首先看看自己显卡的型号: lspci : ...
- Win7-64bit系统下安装mysql的ODBC驱动
安装过mysql数据库后,有些软件在调用mysql数据库时不会直接调用,需要安装mysql数据库的ODBC驱动,再来调用.这里就介绍下,如何在win7系统下安装mysql的ODBC驱动. Win7系统 ...
- linux设备驱动归纳总结(十一):写个简单的看门狗驱动【转】
本文转载自:http://blog.chinaunix.net/uid-25014876-id-112879.html linux设备驱动归纳总结(十一):写个简单的看门狗驱动 xxxxxxxxxxx ...
随机推荐
- Scala实战高手****第11课:Scala面向接口彻底实战和Spark源码鉴赏
第一点: scala的接口trait中所有方法可以都被实现!! 这种情况一般会是一种工具方法的集合,例如接口 Logging! scala 多种继承用extends ... with .... 在老 ...
- Delphi 自动检测U盘插入、拔出及获取U盘盘符!
http://qqhack8.blog.163.com/blog/static/1141479852012102133475/ Delphi 自动检测U盘插入.拔出及获取U盘盘符! u盘的 插 ...
- 使用Vue-cli创建project遇到的坑
环境: win10 / node( v10.2.1) /npm( v5.6.0) 准备: 1.安装node:上node官网下载node版本进行安装 2.安装vue-cli:npm install -- ...
- 【spring data jpa】jpa中使用in查询或删除 在@Query中怎么写 ,报错:org.springframework.expression.spel.SpelEvaluationException: EL1007E: Property or field 'goodsConfigUid' cannot be found on null 怎么处理
示例代码如下: @Modifying @Transactional @Query("delete from GoodsBindConfigMapping gbc " + " ...
- Oracle Service Bus中的线程
jib以前在给客户讲产品的时候经常提到Oracle Service Bus服务总线适合于短连接,高频率的交易,而不适合那些大报文,然后花费很长的调用时间的应用,前一阵在给客户培训完企业服务总线后,又对 ...
- VR开发者必看:4大最为值得关注的内容平台【转】
时间 2016-01-19 14:12:57 原文 http://www.sfw.cn/xinwen/478369.html 主题 虚拟现实 Oculus 对很多有意涉及VR行业的内 ...
- 虚拟机设置NAT上网
需要开启虚拟机网络相关服务, 安装虚拟网卡VMware虚拟机下实现NAT方式上网1. 把你的虚拟网卡VMnet8设置为自动获得IP.自动获得DNS服务器,启用.2. 把你虚拟机中操作系统的“本地连接” ...
- npm添加淘宝镜像
原文:http://cnodejs.org/topic/4f9904f9407edba21468f31e npm是一个很好用的工具,全场是Node Packet Manager,是一个nodejs的包 ...
- 文档对象模型-DOM(二)
从NodeList中选择元素 方法一:item()方法,用于返回其中的单一节点,需要在方法的参数中指定所需元素的索引编号. 当其中没有任何元素时,执行代码是对资源的浪费.因此程序员会在执行代码之前,先 ...
- ubuntu各版本代号(更新至15.04)及各版本下载地址等
版本号 代号 发布时间 15.04 Vivid Vervet 2015/04/22 14.10 Utopic Unicorn 2014/10/23 14.04 LTS Trusty Tahr 2014 ...