1 Star 2 Fork 2

yhp / mini-mcu

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
run 3.33 KB
一键复制 编辑 原始数据 按行查看 历史
yhp 提交于 2020-11-30 23:03 . 2020/11/30 23:03:23
#!/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 $*
1
https://gitee.com/yuan_hp/mini-mcu.git
git@gitee.com:yuan_hp/mini-mcu.git
yuan_hp
mini-mcu
mini-mcu
master

搜索帮助