代码拉取完成,页面将自动刷新
#!/usr/bin/env bash
cd $(dirname $0)
export PATH=$PATH:$(pwd)/tools/bin/ #个人脚本路径添加到临时环境变量
export PATH=$PATH:$(pwd)/tools/kcpsm/ #kcpsm工具路径添加到临时环境变量
hexfile="tmp/$(ls tmp | grep "\.hex")"
file1="tmp/file1.txt"
file2="tmp/file2.txt"
incfile="head.v"
###############################################
# 脚本主函数
###############################################
function main(){
#没有输入参数,直接仿真并打开gtkwave显示
if [ $# -eq 0 ] ;then
msim
exit 0
fi
case $1 in
-r) msim -r;; #重新仿真,但不新打开gtkwave
-c) compile ; mkhd ;; #编译software一级目录下的汇编*.psm文件,并自动更新项目下的rom文件的内容
-g) compile ; mkhd; cp *.v step_fpga/ ; cd step_fpga ; ./run.tcl ;;
esac
}
#####################################
# 找出psm代码使用了哪些指令 ->指令编号
#####################################
function PreCutHexFile(){
i=0
cnt=0
intr_flag=0
if [ ! -f $1 ] ;then
echo "不存在$1文件"
exit
fi
while read line
do
line=$(echo ${line:0:2})
if [[ $line == "00" ]] ;then
if [ $cnt -eq 0 ] ;then
cnt=$[cnt+1]
else
break
fi
else
if [ $cnt -gt 0 ] ;then
cnt=0
fi
fi
echo "H$line"
if [[ ${line:0:2} == "28" ]] ;then
intr_flag=1 #检测到代码中有使用中断函数
fi
i=$[i+1]
done < $1
if [ $intr_flag -eq 1 ] ;then
fileT="/tmp/$(date +%Y%m%d%H%M%S).txt"
cat $hexfile | tail -n +1024 > $fileT
while read line
do
line=$(echo ${line:0:2})
if [[ $line == "00" ]] ;then
if [ $cnt -eq 0 ] ;then
cnt=$[cnt+1]
else
break
fi
else
if [ $cnt -gt 0 ] ;then
cnt=0
fi
fi
echo "H$line"
i=$[i+1]
done < $fileT
rm $fileT
fi
}
#####################################
# 指令和其对应的宏
#####################################
function EchoDirec(){
if [ ! -f $1 ] ; then
echo "文件$1不存在"
exit
fi
if [ $# -gt 1 ] ; then
cat $1
else
cat -n $1
fi
}
function mkhd(){
PreCutHexFile $hexfile | sort | uniq > $file1
#cat $hexfile | sort | uniq > $file1
begin="$(EchoDirec mcu.v | grep "SCRIPT_BEGIN" | cut -d'/' -f1)"
end=$(EchoDirec mcu.v | grep "SCRIPT_END" | cut -d'/' -f1)
#EchoDirec mcu.v -t | head -n $end | tail -n $begin | grep "=" | awk -F",|;" '{print $1}' | awk -F"=|'" '{print $3 $1}' #> $file2
EchoDirec mcu.v -t | sed -n "$begin,${end}p" | grep "=" | sed 's/ //g' | awk -F",|;" '{print $1}' > $file2
cat /dev/null > $incfile
if [ -f tmp/isr.txt ] ;then
cat tmp/isr.txt > $incfile
else
echo "\`define ISR_ADDR 12'h3FF" > $incfile
fi
while read line
do
A=$(cat $file2 |grep $line | cut -d'=' -f1)
echo "\`define _${A}_" >> $incfile
done < $file1
# rm $file1
#rm $file2
}
############### 调用主函数 ################
main $*
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。