-
Notifications
You must be signed in to change notification settings - Fork 3
/
reset.sh
65 lines (53 loc) · 1.58 KB
/
reset.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/sh
# This script is intended to be used on IoT Starter Kit platform, it performs
# the following actions:
# - export/unpexort GPIO7 used to reset the SX1301 chip
#
# Usage examples:
# ./reset_lgw.sh stop
# ./reset_lgw.sh start
# The reset pin of SX1301 is wired with RPi GPIO7
# If used on another platform, the GPIO number can be given as parameter.
IOT_SK_SX1301_RESET_PIN=4
echo "Accessing concentrator reset pin through GPIO$IOT_SK_SX1301_RESET_PIN..."
WAIT_GPIO() {
sleep 1
}
iot_sk_init() {
# setup GPIO 4
echo "$IOT_SK_SX1301_RESET_PIN" > /sys/class/gpio/export; WAIT_GPIO
# set GPIO 4 as output
echo "out" > /sys/class/gpio/gpio$IOT_SK_SX1301_RESET_PIN/direction; WAIT_GPIO
# write output for SX1301 reset
echo "1" > /sys/class/gpio/gpio$IOT_SK_SX1301_RESET_PIN/value; WAIT_GPIO
echo "0" > /sys/class/gpio/gpio$IOT_SK_SX1301_RESET_PIN/value; WAIT_GPIO
#Use a second method to make suere SX1301 had been reset correctly
echo "4" > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio4/direction
echo "1" > /sys/class/gpio/gpio4/value
sleep 2
echo "0" > /sys/class/gpio/gpio4/value
sleep 1
echo "0" > /sys/class/gpio/gpio4/value
}
iot_sk_term() {
# cleanup GPIO 4
if [ -d /sys/class/gpio/gpio$IOT_SK_SX1301_RESET_PIN ]
then
echo "$IOT_SK_SX1301_RESET_PIN" > /sys/class/gpio/unexport; WAIT_GPIO
fi
}
case "$1" in
start)
iot_sk_term
iot_sk_init
;;
stop)
iot_sk_term
;;
*)
echo "Usage: $0 {start|stop} [<gpio number>]"
exit 1
;;
esac
exit 0