#!/bin/sh
#
# FPGA driver module and RBF load
# Install in /etc/init.d/S##fpga
#
# J. Kelley 
# 28 July 2009
# j.kelley@astro.ru.nl
#

kernel=`uname -r`
dev="/dev/fpga"
module="/root/auger2/modules/$kernel/fpga.ko"
design="/root/auger2/auger.rbf"

if [ ! -f $module ] ; then
    echo Module file $module not found!
    exit 1
fi

if [ ! -f $design ] ; then
    echo FPGA design $design not found!
    exit 1
fi

if [ ! -c $dev ] ; then
    echo Device file $dev does not exist!
    exit 1
fi

start() {
    echo -n "Loading FPGA: "
    insmod $module
    cat $design > $dev
    echo "OK"
}
stop() {
    echo -n "Unloading FPGA: "
    echo 0 > /dev/fpga
    rmmod $module
    echo "OK"
}
restart() {
	stop
	start
}

case "$1" in
  start)
      start
      ;;
  stop)
      stop
      ;;
  restart|reload)
      restart
      ;;
  *)
      echo "Usage: $0 {start|stop|restart}"
      exit 1
esac

exit $?

