【第22期】观点:IT 行业加班,到底有没有价值?

设备驱动和设备模型

原创 2016年08月29日 21:43:22

Device Drivers and Device Model

设备驱动和设备模型

Introduction - 简介

The Zephyr kernel supports a variety of device drivers. The specific set of device drivers available for an application’s board configuration varies according to the associated hardware components and device driver software.

Zephyr内核支持多种设备驱动。根据关联的硬件组件和设备驱动软件的不同,App使用的设备驱动集合通过单板配置来改变。

The Zephyr device model provides a consistent device model for configuring the drivers that are part of a system. The device model is responsible for initializing all the drivers configured into the system.

Zephyr设备模型提供设备模型来配置驱动。设备模型有责任完成所有配置的驱动的初始化。

Each type of driver (UART, SPI, I2C) is supported by a generic type API.

每种驱动都可以被通用API所支持。

In this model the driver fills in the pointer to the structure containing the function pointers to its API functions during driver initialization. These structures are placed into the RAM section in initialization level order.

在这个驱动模型填充的结构体指针中包含了执行API功能的函数指针。这些结构依照初始化级别顺序存放在RAM中。

Standard Drivers - 标准驱动

Device drivers which are present on all supported board configurations are listed below.

  • Interrupt controller: This device driver is used by the kernel’s interrupt management subsystem.

  • - 中断控制器。用于内核终端管理子程序。

  • Timer: This device driver is used by the kernel’s system clock and hardware clock subsystem.

  • - 定时器。用于内核系统时钟和硬件时钟子系统。

  • Serial communication: This device driver is used by the kernel’s system console subsystem.

  • - 串口通信。用于内核系统控制台子系统。

  • Random number generator: This device driver provides a source of random numbers.

    Important

    Certain implementations of this device driver do not generate sequences of values that are truly random.

  • - 随机数生成器。用于产生随机数。实际上并不是完全随机的。

Synchronous Calls - 同步调用

Zephyr provides a set of device drivers for multiple boards. Each driver should support an interrupt-based implementation, rather than polling, unless the specific hardware does not provide any interrupt.

除非某硬件不支持中断,否则,所有的中断都应该基于中断实现,而不是轮询。

High-level calls accessed through devices’s specific API, such as i2c.h or spi.h, are usually intended as synchronous. Thus, these calls should be blocking.

高层调用访问设备通过制定API,一般都是严格同步的。因此,这些调用是阻塞式的。

Due to the fact that Zephyr provides two types of execution contexts (task and fiber) on a microkernel, drivers need to act accordingly. For example, a nanokernel semaphore cannot be used when the context is a task, so theinclude/device.h exposes a helper API to handle this case transparently; no other means ought to be used instead.

在微内核中,Zephyr提供了两种上下文(task和fiber),因此,驱动需要分别实现两种。比如,微内核信号量不能用于task上下文,所以include/device.h文件提供了帮助API来显示处理这种情形;除此别无它法。

Zephyr API exposes 1 type and 3 inline functions to solve this issue. - Zephyr API使用1种类型和3个内联函数来解决这一问题。

device_sync_call_t

This type provides a nanokernel semaphore, always present in both nanokernel and microkernel use cases. It is meant to be used within a fiber context. Then, and only on a microkernel type, it will provide a kernel semaphore meant to be used within a task context. A boolean marker is used to remember the caller’s context when running a microkernel.
这个类型提供了nanokernel信号量,在超微内核和微内核使用中,可以在fiber上下文中使用。如果被用于task上下文,那么仅能用作微内核类型。当运行微内核时,使用布尔型标记来记住调用上下文。

device_sync_call_init()

This function initializes the device_sync_call_t type semaphores and the marker. This function should be used only once in the device driver’s instance lifetime. Thus, the driver’s initialization function is the best place for calling it.
初始化上述类型以及标识。在设备驱动实例化生命周期内,该函数仅能使用一次。因此,最好在驱动初始化函数中调用该函数。

device_sync_call_wait()

This function will block - that is, it will perform a “take wait” - on the relevant semaphore. The exposed driver’s API function can then be used as a blocking function until the relevant semaphore is released by a give. This is therefore used to start a synchronous call, and waits until being signaled for synchronization.
函数会被相关的信号量阻塞。该函数接口会被阻塞直到相关的信号量被give。可以被用于信号量同步。

device_sync_call_complete()

This function releases the relevant semaphore and thus will unlock the blocking function. Most frequently will it be called in the driver’s ISR handler. It is used to signal the completion of the synchronous call (error or success).
函数释放相关的信号量。解锁阻塞函数。通常在驱动中断处理函数中调用。

Driver APIs - 驱动APIs

The following APIs for device drivers are provided by device.h. The APIs are intended for use in device drivers only and should not be used in applications.

驱动API放在device.h中。这些API仅仅用于设备驱动,请不要用于APP之中。

DEVICE_INIT()
create device object and set it up for boot time initialization.
创建设备对象,并且在启动阶段初始化设备对象。
DEVICE_AND_API_INIT()
Create device object and set it up for boot time initialization. This also takes a pointer to driver API struct for link time pointer assignment.
创建设备对象,并且在启动阶段初始化设备对象。该API生成一个指向驱动API对象的指针。
DEVICE_NAME_GET()
Expands to the full name of a global device object.
获取全局设备对象的完整名称。
DEVICE_GET()
Obtain a pointer to a device object by name.
通过设备名称获取设备指针。
DEVICE_DECLARE()
Declare a device object.
声明设备对象
版权声明:本文为博主原创文章,未经博主允许不得转载。 举报

相关文章推荐

[快速上手Linux设备驱动]之我看Linux设备模型(总线篇)

上一篇,walfred讲述了一个简单的字符设备驱动,没有看的同学一定要好好的看哦[快速上手Linux设备驱动]之我看Linux字符设备驱动,从这篇文章起,OurUnix转了一篇很不错的描写Linux设...

Linux设备驱动模型

尽管LDD3中说对多数程序员掌握设备驱动模型不是必要的,但对于嵌入式Linux的底层程序员而言,对设备驱动模型的学习非常重要。

程序员升职加薪指南!还缺一个“证”!

CSDN出品,立即查看!

linux设备驱动--字符设备模型

linux设备驱动--字符设备模型 最近正在学习设备驱动开发,因此打算写一个系列博客,即是对自己学习的一个总结,也是对自己的一个督促,有不对,不足,需要改正的地方还望大家指出,而且希望结识志...

Linux设备驱动模型中的热插拔机制及mdev

热插拔(hotplug,打这个词的时候我常常想到热干面)不一定非要指类似U盘那样的插入拔出,此处的热插拔广义上讲,是指一个设备加入系统,内核如何通知用户空间。举个简单的例子,如果你的电脑中有块PCI网卡,针对该网卡的驱动程序以内核模块的形式被编译(obj-m),那么Linux系统在启动过程中是如何自...

linux设备驱动--字符设备模型

linux设备驱动--字符设备模型 最近正在学习设备驱动开发,因此打算写一个系列博客,即是对自己学习的一个总结,也是对自己的一个督促,有不对,不足,需要改正的地方还望大家指出,而且希望结...
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)