#!/bin/bash

# There is an externally placed smart reset IC (STM6522AAAADG6F on U3100) that must be fed with an logical high input
# signal in order to keep the board running. If the device has a logical low input signal, the board will be reset
# after ~60 seconds.

# Check if pin needs to be exported as GPIO
HW_RESET_GPIO="/sys/class/gpio/gpio0"
if [ -f "$HW_RESET_GPIO" ] ; then
    print "GPIO0 is already exported. No manual setup for GPIO required."
else
	echo 0 > "/sys/class/gpio/export"
	print "GPIO0 set up as GPIO."
fi

echo "Setting GPIO0 to output"
echo "out" > /sys/class/gpio/gpio0/direction

echo "Setting output of GPIO0 to logical high (1)"
echo 1 > /sys/class/gpio/gpio0/value

echo "Done"