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 <hector.palacios@digi.com> https://jira.digi.com/browse/DEL-6366
This commit is contained in:
parent
f4dd886ba3
commit
2778713ef8
|
|
@ -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"
|
||||
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ MACHINE_EXTRA_RDEPENDS += " \
|
|||
mca-tool \
|
||||
parted \
|
||||
u-boot-fw-utils \
|
||||
xbee-init \
|
||||
"
|
||||
|
||||
MACHINE_EXTRA_RRECOMMENDS += " \
|
||||
|
|
|
|||
|
|
@ -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)"
|
||||
|
|
@ -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 <gpio_nr>
|
||||
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 <gpio_nr>
|
||||
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 <gpio_nr> <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
|
||||
|
|
@ -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
|
||||
Loading…
Reference in New Issue