#!/bin/bash

# The UrJTAG method sometimes messes up the FPGA, requiring a reset,
# so the Digilent way is probably safer on x86 (as well as a little
# faster).

# Find and use the latest version
BASEDIR=/space/Xilinx
VERSION=`ls $BASEDIR | grep "[0-9]" | tail -n1`
export PATH=$PATH:$BASEDIR/$VERSION/ISE_DS/ISE/bin/lin64

BITFILE=$1

function program() {
    # Digilent Adept tools for more boards
    yes Y | djtgcfg -d Nexys2 prog -i 0 -f $BITFILE
}

function program_urjtag() {
    #You may remove the -v (--verbose) switch for less verbose output.
    ~/sources/nexys2prog/trunk/nexys2prog -v $BITFILE
}

if [ -n "`echo $MACHTYPE | grep x86`" ]; then
    program
else
    program_urjtag
fi
