OpenCores
URL https://opencores.org/ocsvn/radiohdl/radiohdl/trunk

Subversion Repositories radiohdl

[/] [radiohdl/] [trunk/] [quartus/] [run_mif] - Rev 7

Go to most recent revision | Compare with Previous | Blame | View Log

#!/bin/bash -eu
# -------------------------------------------------------------------------- #
#
# Copyright (C) 2012                                                        
# ASTRON (Netherlands Institute for Radio Astronomy) <http://www.astron.nl/>
# JIVE (Joint Institute for VLBI in Europe) <http://www.jive.nl/>           
# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands                             
#                                                                           
# This program is free software: you can redistribute it and/or modify      
# it under the terms of the GNU General Public License as published by      
# the Free Software Foundation, either version 3 of the License, or         
# (at your option) any later version.                                       
#                                                                           
# This program is distributed in the hope that it will be useful,           
# but WITHOUT ANY WARRANTY; without even the implied warranty of            
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             
# GNU General Public License for more details.                              
#                                                                           
# You should have received a copy of the GNU General Public License         
# along with this program.  If not, see <http://www.gnu.org/licenses/>.     
#
# -------------------------------------------------------------------------- #

# Run this tool with at least the commandline arguments:
#   run_mif buildset design_name
# example:
#   run_mif unb2 unb2_minimal
#

# Convert character to ascii decimal value, print as hex
ord ()
{
    printf "%02x" $(( ( 256 + $(printf '%d' "'$1"))%256 ))
}

# read generic functions/definitions
. ${RADIOHDL_GEAR}/generic.sh

# helper function for command parsing
exit_with_error() {
    hdl_error_noexit $0 "$@"
    cat <<@EndOfHelp@
Usage: $(basename $0) buildset project [options]
Arguments: buildset     Name of the buildset to create the registermap for.
           project      Project file to use.

Options: --rev=*        which revision to use.
--> Note: It does not matter where the options are placed: before, in between or after the arguments.
@EndOfHelp@
    exit 1
}

# parse cmdline
POSITIONAL=()
rev=
while [[ $# -gt 0 ]]
do
    case $1 in
        --rev=*)
            rev=${1#*=}
            ;;
        -*|--*)
            exit_with_error "Unknown option: "$1
            ;;
        *)  POSITIONAL+=("$1")
            ;;
    esac
    shift
done
if [ ${#POSITIONAL[@]} -gt 0 ]; then
    set -- "${POSITIONAL[@]}"
fi

# check the positional parameters
if [ $# -ne 2 ]; then
    exit_with_error "Wrong number of arguments specified."
fi
buildset=$1
project=$2
# read in the configuration based on the user arguments
. ${RADIOHDL_GEAR}/quartus/set_quartus ${buildset}

# check projectfile
PRJS="${RADIOHDL_BUILD_DIR}"
PRJ=
for prj in ${PRJS}
    do
        if [ -d "${prj}/${buildset}/quartus/${project}" ]; then
            PRJ=${prj}
        fi  
    done  
if [ -z "${project}" -o -z "${PRJ}" ]; then
    hdl_error $0 "Please enter a valid project name"
fi

quartusdir="${PRJ}/${buildset}/quartus/${project}"
builddir="${quartusdir}/software"
bspdstdir="${builddir}/bsp"

if [ -z "${rev}" ]; then
    project_rev="${project}"
     hdl_info $0 "No project revision passed, defaulting to ${project_rev}"
else
    if [ -f "${quartusdir}/${rev}.qsf" ]; then
       project_rev="${rev}"
       hdl_info $0 "Selecting project revision ${project_rev}"
    else
       hdl_error $0 "Invalid project revision"
    fi
fi

reg_file=${quartusdir}/${project_rev}.reg
if [ ! -f "${reg_file}" ]; then
    hdl_error $0 "${project_rev}.reg file not found in [${quartusdir}]."
fi

# TODO: make a template
echo "DEPTH = 1024;"         > ${quartusdir}/${project_rev}.mif
echo "WIDTH = 32;"          >> ${quartusdir}/${project_rev}.mif
echo "ADDRESS_RADIX = DEC;" >> ${quartusdir}/${project_rev}.mif
echo "DATA_RADIX = HEX;"    >> ${quartusdir}/${project_rev}.mif
echo "CONTENT BEGIN"        >> ${quartusdir}/${project_rev}.mif

hdl_info $0 "Writing ${quartusdir}/${project_rev}.reg contents to ${quartusdir}/${project_rev}.mif"

tr '\n' '\0' < ${quartusdir}/${project_rev}.reg > ${quartusdir}/${project_rev}.reg_tmp
cat ${quartusdir}/${project_rev}.reg_tmp > ${quartusdir}/${project_rev}.reg
rm -f ${quartusdir}/${project_rev}.reg_tmp

address=0
charcnt=0
while IFS= read -r -d $'\0' -n1 char
do
    # 4 bytes per word address: print one address per 4 chars
    if [ $charcnt -eq 0 ] ; then
        printf "%s" "$address" >> ${quartusdir}/${project_rev}.mif
        printf " : " >> ${quartusdir}/${project_rev}.mif
    fi
 
    ord "${char}" >> ${quartusdir}/${project_rev}.mif
    charcnt=`expr $charcnt + 1`

    # last char of word, print semicolon and newline, increment word address
    if [ $(( $charcnt % 4 )) -eq 0 ] ; then
        printf ";\n" >> ${quartusdir}/${project_rev}.mif
        address=`expr $address + 1`
        charcnt=0
    fi
done < "${reg_file}"

printf "\n" >> ${quartusdir}/${project_rev}.mif
echo "END;" >> ${quartusdir}/${project_rev}.mif

hdl_info $0 "Done"

Go to most recent revision | Compare with Previous | Blame | View Log

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.