xbee-init: script updated to use libgpiod tools

Additionally:
   - The handling of gpios has been swapped so 'Set low XBEE_SLEEP_RQ' is done
 before 'Power cycle XBEE_RESET_N' to assure the device doesn't enter sleep mode.
   - Removed ExecStop entry from systemd service since it's doing nothing.

https://jira.digi.com/browse/DEL-6424
https://jira.digi.com/browse/DEL-6423

Signed-off-by: Hector Bujanda <hector.bujanda@digi.com>
This commit is contained in:
Hector Bujanda 2020-03-04 09:57:30 +01:00
parent baa4a6f57e
commit f14d79f5a6
5 changed files with 11 additions and 51 deletions

View File

@ -25,8 +25,8 @@ SERIAL_CONSOLES ?= "115200;ttymxc0"
BT_TTY ?= "ttymxc1"
# XBees
XBEE_RESET_N_GPIO ?= "508,8"
XBEE_SLEEP_RQ_GPIO ?= "504,7"
XBEE_RESET_N_GPIO ?= "mca-gpio@15,gpio1@8"
XBEE_SLEEP_RQ_GPIO ?= "mca-gpio@11,gpio1@7"
XBEE_TTY ?= "ttymxc3"
# U-Boot script to be copied to the boot image

View File

@ -23,8 +23,8 @@ SERIAL_CONSOLES ?= "115200;ttyLP2"
BT_TTY ?= "ttyLP1"
# XBee
XBEE_RESET_N_GPIO ?= "397"
XBEE_SLEEP_RQ_GPIO ?= "400"
XBEE_RESET_N_GPIO ?= "gpio3@13"
XBEE_SLEEP_RQ_GPIO ?= "gpio3@16"
XBEE_TTY ?= "ttyLP0"
# U-Boot script to be copied to the boot image

View File

@ -26,8 +26,8 @@ SERIAL_CONSOLES ?= "115200;ttyLP2"
BT_TTY ?= "ttyLP1"
# XBee
XBEE_RESET_N_GPIO ?= "220"
XBEE_SLEEP_RQ_GPIO ?= "216"
XBEE_RESET_N_GPIO ?= "mca-gpio@15"
XBEE_SLEEP_RQ_GPIO ?= "mca-gpio@11"
XBEE_TTY ?= "ttyMCA0"
# U-Boot script to be copied to the boot image

View File

@ -4,47 +4,13 @@
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 ${1}
set_gpio_value ${1} 0
set_gpio_value ${1} 1
# Set low XBEE_SLEEP_RQ
request_gpio_out ${2}
set_gpio_value ${2} 0
}
gpioset ${3} ${4}=0
xbee_stop() {
free_gpio ${1}
free_gpio ${2}
# Power cycle XBEE_RESET_N
gpioset ${1} ${2}=0
gpioset ${1} ${2}=1
}
xbee_iterate_list() {
@ -54,9 +20,7 @@ xbee_iterate_list() {
for SLEEP in $(echo ${XBEE_SLEEP_RQ_GPIO} | sed "s/,/ /g"); do
if [ "${i}" = "${j}" ]; then
if [ "${1}" = "start" ]; then
xbee_init ${RESET} ${SLEEP}
elif [ "${1}" = "stop" ]; then
xbee_stop ${RESET} ${SLEEP}
xbee_init $(echo ${RESET} | sed "s/@/ /g") $(echo ${SLEEP} | sed "s/@/ /g")
fi
fi
j="$((j + 1))"
@ -72,9 +36,6 @@ case "$1" in
echo "done."
;;
stop)
echo -n "Stopping XBee hardware: "
xbee_iterate_list stop
echo "done."
;;
restart)
$0 stop

View File

@ -6,7 +6,6 @@ Before=ModemManager.service
Type=oneshot
RemainAfterExit=yes
ExecStart=/etc/xbee-init start
ExecStop=/etc/xbee-init stop
[Install]
WantedBy=multi-user.target