#!/bin/sh

# Script read wrs_auxclk parameters from dot-config, then start wrs_auxclk.

# First, read dot-config to get wrs_auxclk parameters
dotconfig=/wr/etc/dot-config

if [ -f $dotconfig ]; then
    . $dotconfig
else
    # exit
    echo "dot-config not found! Don't setup wrs_auxclk"
    exit 1
fi

if [ ! -z "$CONFIG_WRSAUXCLK_FREQ" ]; then
	p_freq="--freq "$CONFIG_WRSAUXCLK_FREQ;
fi

if [ ! -z "$CONFIG_WRSAUXCLK_DUTY" ]; then
	p_duty="--duty "$CONFIG_WRSAUXCLK_DUTY;
fi

if [ ! -z "$CONFIG_WRSAUXCLK_CSHIFT" ]; then
	p_cshift="--cshift "$CONFIG_WRSAUXCLK_CSHIFT;
fi

if [ ! -z "$CONFIG_WRSAUXCLK_SIGDEL" ]; then
	p_sigdel="--sigdel "$CONFIG_WRSAUXCLK_SIGDEL;
fi

if [ ! -z "$CONFIG_WRSAUXCLK_PPSHIFT" ]; then
	p_ppshift="--ppshift "$CONFIG_WRSAUXCLK_PPSHIFT;
fi

# execute wrs_auxclk
echo -n "Configuring external clock clk2: "
/wr/bin/wrs_auxclk $p_freq $p_duty $p_cshift $p_sigdel $p_ppshift > /dev/null 2>&1
if [ $? == 0 ]; then
	echo "OK"
else
	echo "Failed"
fi
