From 8fc5602ac4ca60bb35f22c2e212479daa6266e13 Mon Sep 17 00:00:00 2001 From: Michael Gernoth Date: Sun, 2 Jun 2013 11:41:00 +0200 Subject: [PATCH] COC helper-scripts with RPi version detection --- COC/.gitignore | 1 + COC/coc-as-cuno | 13 ++++++++++ COC/coc-terminal | 3 +++ COC/init-coc | 65 ++++++++++++++++++++++++++++++++++++++++++++++++ COC/update-coc | 19 ++++++++++++++ 5 files changed, 101 insertions(+) create mode 100644 COC/.gitignore create mode 100755 COC/coc-as-cuno create mode 100755 COC/coc-terminal create mode 100755 COC/init-coc create mode 100755 COC/update-coc diff --git a/COC/.gitignore b/COC/.gitignore new file mode 100644 index 0000000..3e0efd8 --- /dev/null +++ b/COC/.gitignore @@ -0,0 +1 @@ +culfw diff --git a/COC/coc-as-cuno b/COC/coc-as-cuno new file mode 100755 index 0000000..46de8fd --- /dev/null +++ b/COC/coc-as-cuno @@ -0,0 +1,13 @@ +#!/bin/sh + +DEVICE=/dev/ttyAMA0,b38400 +PORT=2323 +#OPTIONS="-ly -lh" +#OPTIONS="-v -x" + +"`dirname "${0}"`"/init-coc + +while true; do + echo "Listening on port ${PORT} for new connection requests" + socat ${OPTIONS} "${DEVICE},raw,echo=0" "TCP-LISTEN:${PORT},reuseaddr" +done diff --git a/COC/coc-terminal b/COC/coc-terminal new file mode 100755 index 0000000..fc2ca52 --- /dev/null +++ b/COC/coc-terminal @@ -0,0 +1,3 @@ +#!/bin/sh -x + +socat /dev/ttyAMA0,b38400,raw,echo=0 - diff --git a/COC/init-coc b/COC/init-coc new file mode 100755 index 0000000..97166c5 --- /dev/null +++ b/COC/init-coc @@ -0,0 +1,65 @@ +#!/bin/sh + +#RPi v1: BUS=0 +#RPi v2: BUS=1 +#Auto: BUS=-1 +BUS=-1 + +#BATTERY=0: trickle charger for supercap enabled +#BATTERY=1: trickle charger for supercap disabled +BATTERY=0 + +if [ "`id -u`" != "0" ]; then + exec sudo "${0}" "${@}" +fi + +if [ "${BUS}" = "-1" ]; then + rev="0x`awk '{if ($1 == "Revision") {print $NF};}' /proc/cpuinfo`" + rev=$((rev & 0xffff)) + if [ "${rev}" -ge "4" ]; then + echo "RPi version 2 detected" + BUS=1 + else + echo "RPi version 1 detected" + BUS=0 + fi +fi + +if [ ! -e "/dev/i2c-${BUS}" ]; then + modprobe i2c-dev +fi + +if [ ! -e "/sys/bus/i2c/devices/${BUS}-0068" ]; then + echo "enabling RTC" + modprobe rtc-ds1307 + + tcharger="0xa5" + tchargertext="enabling" + if [ "${BATTERY}" = "1" ]; then + tcharger="0x00" + tchargertext="disabling" + fi + + if [ "`i2cget -y "${BUS}" 0x68 0x10`" != "${tcharger}" ]; then + echo "${tchargertext} trickle-charger for supercap" + i2cset -y "${BUS}" 0x68 0x10 "${tcharger}" + fi + echo "ds1339 0x68" >"/sys/class/i2c-adapter/i2c-${BUS}/new_device" +fi + +if [ ! -e "/sys/bus/i2c/devices/1-0018" ]; then + echo "enabling 1wire" + modprobe ds2482 + echo "ds2482 0x18" >"/sys/class/i2c-adapter/i2c-${BUS}/new_device" +fi + +echo "resetting 868MHz extension..." +if test ! -d /sys/class/gpio/gpio17; then echo 17 > /sys/class/gpio/export; fi +if test ! -d /sys/class/gpio/gpio18; then echo 18 > /sys/class/gpio/export; fi +echo out > /sys/class/gpio/gpio17/direction +echo out > /sys/class/gpio/gpio18/direction +echo 1 > /sys/class/gpio/gpio18/value +echo 0 > /sys/class/gpio/gpio17/value +sleep 1 +echo 1 > /sys/class/gpio/gpio17/value +sleep 1 diff --git a/COC/update-coc b/COC/update-coc new file mode 100755 index 0000000..7e50dfe --- /dev/null +++ b/COC/update-coc @@ -0,0 +1,19 @@ +#!/bin/sh + +if [ "`id -u`" != "0" ]; then + exec sudo "${0}" "${@}" +fi + +echo "calling COC bootloader..." +if test ! -d /sys/class/gpio/gpio17; then echo 17 > /sys/class/gpio/export; fi +if test ! -d /sys/class/gpio/gpio18; then echo 18 > /sys/class/gpio/export; fi +echo out > /sys/class/gpio/gpio17/direction +echo out > /sys/class/gpio/gpio18/direction +echo 0 > /sys/class/gpio/gpio18/value +echo 0 > /sys/class/gpio/gpio17/value +sleep 1 +echo 1 > /sys/class/gpio/gpio17/value +sleep 1 +echo 1 > /sys/class/gpio/gpio18/value + +avrdude -v -p atmega1284p -P /dev/ttyAMA0 -b 38400 -c avr109 -U flash:w:COC.hex -- 2.39.2