您的位置:首页 > 其它

设备驱动和设备模型

2016-08-29 21:43 127 查看


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 the
include/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.声明设备对象
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: