设备驱动和设备模型

原创 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设备驱动之设备模型一--kobject

LINUX设备驱动驱动程序模型的核心数据结构是kobject,kobject数据结构在\linux\kobject.h中定义: struct kobject {        const char...

设备驱动基础0:设备模型之kobject,kset及其关系

设备驱动基础0:设备模型之kobject,kset及其关系 分类: linux驱动2015-01-10 22:18 2人阅读 评论(0) 收藏 举报 Linux2.6以后的设备...

LINUX设备驱动之设备模型一--kobject

LINUX设备驱动驱动程序模型的核心数据结构是kobject,kobject数据结构在\linux\kobject.h中定义: struct kobject {        const char...

设备驱动基础0:设备模型之kobject,kset及其关系

文章来自:http://www.cnblogs.com/image-eye/archive/2012/01/29/2330838.html Linux2.6以后的设备驱动,都是在设备模型的基础上...

linux设备驱动归纳总结(八):3设备模型的分层与面向对象

转自:http://blog.chinaunix.net/uid-25014876-id-110738.html linux设备驱动归纳总结(八):3.设备管理的分层与面向对象思想 xxxx...

LINUX设备驱动之设备模型二--kset

本站分析linux内核源码,版本号为2.6.32.3 转载请注明出处:http://ericfang.cublog.cn/   接着上一篇文章,分析kset, 我们已经知道了kset内...

LINUX设备驱动之设备模型二--kset

我们已经知道了kset内嵌了kobject来表示自身的节点,创建kset就要完成其内嵌kobject,注册kset时会产生一个事件,事件而最终会调用uevent_ops字段指向结构中的函数,这个事件是...

linux设备驱动学习(11) linux设备模型1

引自http://blog.chinaunix.net/space.php?uid=20543672&do=blog&id=94312    以《LDD3》的说法:Linux设备模型这部分内容可以...

LINUX设备驱动之设备模型四--device&driver&bus

----------------------------------------------------------------- 本站分析linux内核源码,版本号为2.6.32.3 转载请注明...

linux设备驱动学习(11) linux设备模型3

3. 内核对象机制主要相关函数 针对内核对象不同层次的数据结构,linux 2.6内核定义了一系列操作函数,定义于lib/kobject.c文件中。 3.1 kobject相关函数 void k...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

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