前言
在zephyr中包含一部分特殊节点,他们的功能各不相同,节点如下:
- aliases
- chosen
- zephyr,user
aliases
aliases 是对设备树中其他节点起的别名,别名用于为节点提供较短的名称,该名称可用于设备树的其他部分以引用节点。
/{
aliases {
led0 = &led0;
};
leds {
compatible = "gpio-leds";
led0: led_0 {
gpios = <&gpio1 0 0>;
label = "LED 0";
};
}
chosen
在Zephyr中,chosen节点是一个特殊的设备树节点,用于指定一些系统级别的属性,这些属性可以在系统启动时被引导加载程序(bootloader)或内核使用,在这个特定的设备树文件中,chosen节点支持以下属性:
- zephyr,bt-c2h-uart
- Selects the UART used for host communication in the
- zephyr,bt-mon-uart
- Sets UART device used for the Bluetooth monitor logging
- zephyr,bt-uart
- Sets UART device used by Bluetooth
- zephyr,canbus
- Sets the default CAN controller
- zephyr,ccm
- Core-Coupled Memory node on some STM32 SoCs
- zephyr,code-partition
- Flash partition that the Zephyr image’s text section should be linked into
- zephyr,console
- Sets UART device used by console driver
- zephyr,display
- Sets the default display controller
- zephyr,keyboard-scan
- Sets the default keyboard scan controller
- zephyr,dtcm
- Data Tightly Coupled Memory node on some Arm SoCs
- zephyr,entropy
- A device which can be used as a system-wide entropy source
- zephyr,flash
- A node whose reg is sometimes used to set the defaults for CONFIG_FLASH_BASE_ADDRESS and CONFIG_FLASH_SIZE
- zephyr,flash-controller
- The node corresponding to the flash controller device for
the zephyr,flash node
- The node corresponding to the flash controller device for
- zephyr,gdbstub-uart
- Sets UART device used by the gdbstub subsystem
- zephyr,ieee802154
- Used by the networking subsystem to set the IEEE 802.15.4 device
- zephyr,ipc
- Used by the OpenAMP subsystem to specify the inter-process communication (IPC) device
- zephyr,ipc_shm
- A node whose reg is used by the OpenAMP subsystem to determine the base address and size of the shared memory (SHM) usable for interprocess-communication (IPC)
- zephyr,itcm
- Instruction Tightly Coupled Memory node on some Arm SoCs
- zephyr,ocm
- On-chip memory node on Xilinx Zynq-7000 and ZynqMP SoCs
- zephyr,osdp-uart
- Sets UART device used by OSDP subsystem
- zephyr,ot-uart
- Used by the OpenThread to specify UART device for Spinel protocol
- zephyr,pcie-controller
- The node corresponding to the PCIe Controller
- zephyr,ppp-uart
- Sets UART device used by PPP
- zephyr,settings-partition
- Fixed partition node. If defined this selects the partition used by the NVS and FCB settings backends.
- zephyr,shell-uart
- Sets UART device used by serial shell backend
- zephyr,sram
- A node whose reg sets the base address and size of SRAM memory
available to the Zephyr image, used during linking
- A node whose reg sets the base address and size of SRAM memory
- zephyr,tracing-uart
- Sets UART device used by tracing subsystem
- zephyr,uart-mcumgr
- UART used for device_mgmt
- zephyr,uart-pipe
- Sets UART device used by serial pipe driver
- zephyr,usb-device
- USB device node. If defined and has a vbus-gpios property, these will be used by the USB subsystem to enable/disable VBUS
zephyr,user
Zephyr 的 devicetree 脚本将/zephyr,user节点作为一种特殊情况进行处理:可以将任意的属性放入其中并检索它们的值,而无需编写绑定文件。当只需要几个简单的属性时,它是一个方便的容器.
简单属性
/ {
zephyr,user {
boolean;
bytes = [81 82 83];
number = <23>;
numbers = <1>, <2>, <3>;
string = "text";
strings = "a", "b", "c";
};
};
在上面的设备树中包含了一些基本的数据类型,如果需要获取他们的值,可以通过下面的方式:
#define ZEPHYR_USER_NODE DT_PATH(zephyr_user)
DT_PROP(ZEPHYR_USER_NODE, boolean) // 1
DT_PROP(ZEPHYR_USER_NODE, bytes) // {0x81, 0x82, 0x83}
DT_PROP(ZEPHYR_USER_NODE, number) // 23
DT_PROP(ZEPHYR_USER_NODE, numbers) // {1, 2, 3}
DT_PROP(ZEPHYR_USER_NODE, string) // "text"
DT_PROP(ZEPHYR_USER_NODE, strings) // {"a", "b", "c"}
设备节点
/ {
zephyr,user {
handle = <&gpio0>;
handles = <&gpio0>, <&gpio1>;
};
};
也可以将 phandle 和 phandles 转换为设备指针:文章来源:https://www.toymoban.com/news/detail-432549.html
const struct device *my_device =
DEVICE_DT_GET(DT_PROP(ZEPHYR_USER_NODE, handle));
#define PHANDLE_TO_DEVICE(node_id, prop, idx) \
DEVICE_DT_GET(DT_PHANDLE_BY_IDX(node_id, prop, idx)),
const struct device *my_devices[] = {
DT_FOREACH_PROP_ELEM(ZEPHYR_USER_NODE, handles, PHANDLE_TO_DEVICE)
};
GPIOs
#include <zephyr/dt-bindings/gpio/gpio.h>
/ {
zephyr,user {
signal-gpios = <&gpio0 1 GPIO_ACTIVE_HIGH>;
};
};
除此之外,如果你需要使用GPIO,也可以直接将其添加到该节点下。文章来源地址https://www.toymoban.com/news/detail-432549.html
#include <zephyr/drivers/gpio.h>
#define ZEPHYR_USER_NODE DT_PATH(zephyr_user)
const struct gpio_dt_spec signal =
GPIO_DT_SPEC_GET(ZEPHYR_USER_NODE, signal_gpios);
/* Configure the pin */
gpio_pin_configure_dt(&signal, GPIO_OUTPUT_INACTIVE);
/* Set the pin to its active level */
gpio_pin_set_dt(&signal, 1);
到了这里,关于Zephyr 设备树中的特殊节点的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!