summaryrefslogtreecommitdiff
path: root/recipes-bsp/multitech/mts-io/mts-io.mtcap.init
diff options
context:
space:
mode:
authorJohn Klug <john.klug@multitech.com>2021-02-15 16:02:33 -0600
committerJohn Klug <john.klug@multitech.com>2021-02-15 16:03:08 -0600
commitbe076b2153af894ce1c625a56101b976f95dea9b (patch)
tree5f7e79c2d3dcd937a6330fbc79f90dbf906b1af5 /recipes-bsp/multitech/mts-io/mts-io.mtcap.init
parent0b4a7982a56cdf145502231c6e6003338817e7cd (diff)
downloadmeta-multitech-be076b2153af894ce1c625a56101b976f95dea9b.tar.gz
meta-multitech-be076b2153af894ce1c625a56101b976f95dea9b.tar.bz2
meta-multitech-be076b2153af894ce1c625a56101b976f95dea9b.zip
Wait for supercap charge up to 3 minutes. Poweroff if no power
Diffstat (limited to 'recipes-bsp/multitech/mts-io/mts-io.mtcap.init')
-rw-r--r--recipes-bsp/multitech/mts-io/mts-io.mtcap.init38
1 files changed, 38 insertions, 0 deletions
diff --git a/recipes-bsp/multitech/mts-io/mts-io.mtcap.init b/recipes-bsp/multitech/mts-io/mts-io.mtcap.init
index 19bfa4a..ff0e947 100644
--- a/recipes-bsp/multitech/mts-io/mts-io.mtcap.init
+++ b/recipes-bsp/multitech/mts-io/mts-io.mtcap.init
@@ -103,6 +103,42 @@ cell_init() {
start_lora_led_updater() {
lora-led-updater &
}
+gettime() {
+ [[ $(cat /proc/uptime) =~ ([^[:space:]]+) ]]
+ echo ${BASH_REMATCH[1]}
+}
+wait_for_supercap() {
+ supercap=$(mts-io-sysfs show capability/supercap 2>/dev/null)
+ if ((supercap != 1)) ; then
+ return
+ fi
+ if ((SUPERCAPFULL != 1)) ; then
+ break
+ fi
+ t0=$(gettime)
+ maxwait=$(awk "BEGIN {print ${t0}+${SUPERCAPFULL_MAXWAIT}}")
+ while : ; do
+ if (($(mts-io-sysfs show power-fail) == 1)) ; then
+ # If we are booting, then go down.
+ # This will not work with systemd.
+ if [[ $(ps -h -o cmd -p $PPID) =~ /bin/sh[[:space:]]/etc/init.d/rc[[:space:]]S$ ]] ; then
+ logger -s -t 'mts-io' -p daemon.err "No power during boot, so power off"
+ exec /sbin/poweroff
+ # NOT REACHED
+ fi
+ fi
+ if (($(mts-io-sysfs show supercap-full) == 1)) ; then
+ logger -s -t 'mts-io' -p daemon.err 'Supercap Charged'
+ return
+ fi
+ t1=$(gettime)
+ if awk "BEGIN { if($t1<$maxwait)exit 1 }" ; then
+ break
+ fi
+ sleep 1
+ done
+ logger -s -t 'mts-io' -p daemon.err 'Supercap not full but timer expired -- continuing boot'
+}
case $1 in
start)
@@ -129,6 +165,8 @@ case $1 in
(($WIFICAP)) && modprobe wilc1000-sdio
set_hw_name
set_gpslink
+ wait_for_supercap
+
;;
stop)