Zephyr 设备树中的特殊节点

前言

在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
  • 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
  • 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 转换为设备指针:


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,也可以直接将其添加到该节点下。

#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);
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

qq_36115224

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值