028-86922220

建站动态

根据您的个性需求进行定制 先人一步 抢占小程序红利时代

如何进行RT-Thread中设备模型rt_device的理解

如何进行RT-Thread中设备模型rt_device的理解,针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。

创新互联公司服务项目包括胶州网站建设、胶州网站制作、胶州网页制作以及胶州网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,胶州网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到胶州省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!

前言

rt_device的结构

如何进行RT-Thread中设备模型rt_device的理解

rt_device_class_type.png

rt_device的使用

pin设备模型:结构如下:

/* pin device and operations for RT-Thread */
struct rt_device_pin
{
    struct rt_device parent; /* 派生于rt_device */
    const struct rt_pin_ops *ops; /* 设备特有的操作接口,还可以根据需要增加其他成员 */
};

如:

/* 使用时,需要把设备名称、操作接口等,传入 */
int rt_device_pin_register(const char *name, const struct rt_pin_ops *ops, void *user_data)
{
    _hw_pin.parent.type         = RT_Device_Class_Miscellaneous; /* 设备类型,为了区分设备种类 */
    _hw_pin.parent.rx_indicate  = RT_NULL; /* 接收回调,串口、CAN一般会有 */
    _hw_pin.parent.tx_complete  = RT_NULL; /* 发送回调,串口、CAN一般会有 */

#ifdef RT_USING_DEVICE_OPS
    _hw_pin.parent.ops          = &pin_ops;
#else
    _hw_pin.parent.init         = RT_NULL; /* 以下标准的rt_device设备操作接口,根据需要实现 */
    _hw_pin.parent.open         = RT_NULL;
    _hw_pin.parent.close        = RT_NULL;
    _hw_pin.parent.read         = _pin_read;
    _hw_pin.parent.write        = _pin_write;
    _hw_pin.parent.control      = _pin_control;
#endif

    _hw_pin.ops                 = ops;  /* 操作接口,设备的特有操作接口 */
    _hw_pin.parent.user_data    = user_data; /* 不是必要的用户数据 */

    /* register a character device */
    rt_device_register(&_hw_pin.parent, name, RT_DEVICE_FLAG_RDWR);  /* 设备注册接口:注册为具体设备 */

    return 0;
}
/* 具体设备的OPS 实现 */
const static struct rt_pin_ops _stm32_pin_ops =
{
    stm32_pin_mode,
    stm32_pin_write,
    stm32_pin_read,
    stm32_pin_attach_irq,
    stm32_pin_dettach_irq,
    stm32_pin_irq_enable,
};

/* 实际设备的注册方法 */
rt_device_pin_register("pin", &_stm32_pin_ops, RT_NULL);

其他

关于如何进行RT-Thread中设备模型rt_device的理解问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注创新互联行业资讯频道了解更多相关知识。


分享名称:如何进行RT-Thread中设备模型rt_device的理解
链接地址:http://www.tsicrk.com/article/ghheej.html

其他资讯

让你的专属顾问为你服务

4.5177s