From 2778713ef804a011ebfeeaf745a67063e3b7e027 Mon Sep 17 00:00:00 2001 From: Hector Palacios Date: Wed, 10 Apr 2019 17:21:10 +0200 Subject: [PATCH] xbee: added new recipe for XBee hardware initialization This recipe adds a script and a related systemd service that configures two GPIOs (user defined, or else platform-defaults) as output and sets them to the appropriate value for initializing the XBee socket: - XBEE_SLEEP_RQ: is set low, for running the XBee - XBEE_RESET_N: is set low and then high, to reset the XBee The service triggers on the condition that the UART TTY device node pointed to by variable XBEE_UART exists. Signed-off-by: Hector Palacios https://jira.digi.com/browse/DEL-6366 --- .../conf/machine/ccimx8x-sbc-express.conf | 4 ++ .../conf/machine/ccimx8x-sbc-pro.conf | 4 ++ .../conf/machine/include/ccimx8x.inc | 1 + .../recipes-connectivity/xbee/xbee.bb | 40 +++++++++++ .../recipes-connectivity/xbee/xbee/xbee-init | 70 +++++++++++++++++++ .../xbee/xbee/xbee-init.service | 12 ++++ 6 files changed, 131 insertions(+) create mode 100644 meta-digi-dey/recipes-connectivity/xbee/xbee.bb create mode 100644 meta-digi-dey/recipes-connectivity/xbee/xbee/xbee-init create mode 100644 meta-digi-dey/recipes-connectivity/xbee/xbee/xbee-init.service diff --git a/meta-digi-arm/conf/machine/ccimx8x-sbc-express.conf b/meta-digi-arm/conf/machine/ccimx8x-sbc-express.conf index b480f3e32..e15fd9bd2 100644 --- a/meta-digi-arm/conf/machine/ccimx8x-sbc-express.conf +++ b/meta-digi-arm/conf/machine/ccimx8x-sbc-express.conf @@ -32,6 +32,10 @@ SERIAL_CONSOLES ?= "115200;ttyLP2" # Bluetooth tty BT_TTY ?= "ttyLP1" +# XBee +XBEE_RESET_N_GPIO ?= "397" +XBEE_SLEEP_RQ_GPIO ?= "400" + # U-Boot script to be copied to the boot image BOOT_SCRIPTS = "boot.scr:boot.scr" diff --git a/meta-digi-arm/conf/machine/ccimx8x-sbc-pro.conf b/meta-digi-arm/conf/machine/ccimx8x-sbc-pro.conf index 77422889e..60d23fa3f 100644 --- a/meta-digi-arm/conf/machine/ccimx8x-sbc-pro.conf +++ b/meta-digi-arm/conf/machine/ccimx8x-sbc-pro.conf @@ -32,6 +32,10 @@ SERIAL_CONSOLES ?= "115200;ttyLP2" # Bluetooth tty BT_TTY ?= "ttyLP1" +# XBee +XBEE_RESET_N_GPIO ?= "220" +XBEE_SLEEP_RQ_GPIO ?= "216" + # U-Boot script to be copied to the boot image BOOT_SCRIPTS = "boot.scr:boot.scr" diff --git a/meta-digi-arm/conf/machine/include/ccimx8x.inc b/meta-digi-arm/conf/machine/include/ccimx8x.inc index be801a056..045fe8b10 100644 --- a/meta-digi-arm/conf/machine/include/ccimx8x.inc +++ b/meta-digi-arm/conf/machine/include/ccimx8x.inc @@ -34,6 +34,7 @@ MACHINE_EXTRA_RDEPENDS += " \ mca-tool \ parted \ u-boot-fw-utils \ + xbee-init \ " MACHINE_EXTRA_RRECOMMENDS += " \ diff --git a/meta-digi-dey/recipes-connectivity/xbee/xbee.bb b/meta-digi-dey/recipes-connectivity/xbee/xbee.bb new file mode 100644 index 000000000..8bf090b99 --- /dev/null +++ b/meta-digi-dey/recipes-connectivity/xbee/xbee.bb @@ -0,0 +1,40 @@ +# Copyright (C) 2019 Digi International Inc. + +SUMMARY = "Digi XBee initialization" +DESCRIPTION = "Initialization scripts for XBee hardware of Digi boards" +SECTION = "base" +LICENSE = "GPL-2.0" +LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/GPL-2.0;md5=801f80980d171dd6425610833a22dbe6" + +SRC_URI = " \ + file://xbee-init \ + file://xbee-init.service \ +" +S = "${WORKDIR}" + +do_install() { + install -d ${D}${sysconfdir}/init.d/ + install -m 0755 ${WORKDIR}/xbee-init ${D}${sysconfdir}/ + ln -sf /etc/xbee-init ${D}${sysconfdir}/init.d/xbee-init + sed -i -e "s,##XBEE_RESET_N_GPIO##,${XBEE_RESET_N_GPIO},g" \ + -e "s,##XBEE_SLEEP_RQ_GPIO##,${XBEE_SLEEP_RQ_GPIO},g" \ + ${D}${sysconfdir}/xbee-init + + install -d ${D}${systemd_unitdir}/system/ + install -m 0644 ${WORKDIR}/xbee-init.service ${D}${systemd_unitdir}/system/ +} + +PACKAGES =+ "${PN}-init" +FILES_${PN}-init = " \ + ${sysconfdir}/xbee-init \ + ${sysconfdir}/init.d/xbee-init \ + ${systemd_unitdir}/system/xbee-init.service \ +" +INITSCRIPT_PACKAGES += "${PN}-init" +INITSCRIPT_NAME_${PN}-init = "xbee-init" +INITSCRIPT_PARAMS_${PN}-init = "start 19 2 3 4 5 . stop 21 0 1 6 ." + +SYSTEMD_SERVICE_${PN}-init = "xbee-init.service" + +PACKAGE_ARCH = "${MACHINE_ARCH}" +COMPATIBLE_MACHINE = "(ccimx8x)" diff --git a/meta-digi-dey/recipes-connectivity/xbee/xbee/xbee-init b/meta-digi-dey/recipes-connectivity/xbee/xbee/xbee-init new file mode 100644 index 000000000..9236a2dc6 --- /dev/null +++ b/meta-digi-dey/recipes-connectivity/xbee/xbee/xbee-init @@ -0,0 +1,70 @@ +#!/bin/sh + +# Linux GPIOs on XBee lines +XBEE_RESET_N_GPIO="##XBEE_RESET_N_GPIO##" +XBEE_SLEEP_RQ_GPIO="##XBEE_SLEEP_RQ_GPIO##" + +# request_gpio +request_gpio_out() { + local SG_GPIONR="${1}" + local SG_GPIOPATH="/sys/class/gpio/gpio${SG_GPIONR}" + + [ -d "${SG_GPIOPATH}" ] || printf "%s" "${SG_GPIONR}" > /sys/class/gpio/export + printf out > "${SG_GPIOPATH}/direction" && sleep .2 +} + +# free_gpio +free_gpio() { + local SG_GPIONR="${1}" + local SG_GPIOPATH="/sys/class/gpio/gpio${SG_GPIONR}" + + [ -d "${SG_GPIOPATH}" ] && printf "%s" "${SG_GPIONR}" > /sys/class/gpio/unexport +} + +# set_gpio_value +set_gpio_value() { + local SG_GPIONR="${1}" + local SG_GPIOVAL="${2}" + local SG_GPIOPATH="/sys/class/gpio/gpio${SG_GPIONR}" + + printf out > "${SG_GPIOPATH}/direction" && sleep .2 + printf "${SG_GPIOVAL}" > "${SG_GPIOPATH}/value" && sleep .2 +} + +xbee_init() { + # Power cycle XBEE_RESET_N + request_gpio_out ${XBEE_RESET_N_GPIO} + set_gpio_value ${XBEE_RESET_N_GPIO} 0 + set_gpio_value ${XBEE_RESET_N_GPIO} 1 + + # Set low XBEE_SLEEP_RQ + request_gpio_out ${XBEE_SLEEP_RQ_GPIO} + set_gpio_value ${XBEE_SLEEP_RQ_GPIO} 0 +} + +xbee_stop() { + free_gpio ${XBEE_RESET_N_GPIO} + free_gpio ${XBEE_SLEEP_RQ_GPIO} +} + +case "$1" in + start) + echo -n "Starting XBee hardware: " + xbee_init + echo "done." + ;; + stop) + echo -n "Stopping XBee hardware: " + xbee_stop + echo "done." + ;; + restart) + $0 stop + sleep 1 + $0 start + ;; + *) + echo "Usage: $0 {start|stop|restart}" + exit 1 + ;; +esac diff --git a/meta-digi-dey/recipes-connectivity/xbee/xbee/xbee-init.service b/meta-digi-dey/recipes-connectivity/xbee/xbee/xbee-init.service new file mode 100644 index 000000000..f56cc5580 --- /dev/null +++ b/meta-digi-dey/recipes-connectivity/xbee/xbee/xbee-init.service @@ -0,0 +1,12 @@ +[Unit] +Description=XBee GPIOs initialization +Before=ModemManager.service + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/etc/xbee-init start +ExecStop=/etc/xbee-init stop + +[Install] +WantedBy=multi-user.target