#!/bin/sh # Automatically generates a PLL parameterized by output freq # (instead of cryptic parameters) if [ "$#" -ne 2 ]; then echo "Usage: $0 FPGA_KIND INPUTFREQ" >&2 exit 1 fi FPGA_KIND=$1 INPUTFREQ=$2 echo "/* " echo " * Do not edit this file, it was generated by gen_pll.sh" echo " * " echo " * FPGA kind : $1" echo " * Input frequency: $2 MHz" echo " */" case $FPGA_KIND in "ICE40") cat << EOF module femtoPLL #( parameter freq = 40 ) ( input wire pclk, output wire clk ); SB_PLL40_CORE pll ( .REFERENCECLK(pclk), .PLLOUTCORE(clk), .RESETB(1'b1), .BYPASS(1'b0) ); defparam pll.FEEDBACK_PATH="SIMPLE"; defparam pll.PLLOUT_SELECT="GENCLK"; generate case(freq) EOF for OUTPUTFREQ in `cat frequencies.txt` do echo " $OUTPUTFREQ: begin" icepll -i $INPUTFREQ -o $OUTPUTFREQ \ | egrep "DIVR|DIVF|DIVQ|FILTER_RANGE" \ | sed -e 's|[:()]||g' \ | awk '{printf(" defparam pll.%s = %s;\n",$1,$3);}' echo " end" done cat < tmp.txt cat tmp.v \ | egrep "CLKI_DIV|CLKOP_DIV|CLKOP_CPHASE|CLKFB_DIV" \ | sed -e 's|[),.]| |g' -e 's|(|=|g' \ | awk '{printf(" defparam pll_i.%s;\n",$1);}' rm -f tmp.v tmp.txt echo " end" done cat < tmp.txt cat tmp.v \ | egrep "IDIV_SEL|FBDIV_SEL|ODIV_SEL" \ | sed -e 's|[),.]| |g' -e 's|(|=|g' \ | awk '{printf(" defparam pll_i.%s;\n",$1);}' rm -f tmp.v tmp.txt echo " end" done cat <