我的代码片段

TCL片段

实现vivado的bit,crc,ltx代码备份功能

    1 运行add_tool_crc16_5.exe软件,生成CRC  
    2:备份bit,ltx,crc文件
#####################################################
#   1.5工程执行脚本 --1:  运行add_tool_crc16_5.exe软件,生成CRC   --2:备份bit,ltx,crc文件
#   这个脚本需要放在 vivado工程的impl_1或者impl_n下面才能正常识别
#####################################################
    # tclsh .\crc_copy_bit.tcl

## 工程名称 
    # 获取当前脚本的绝对路径
    set script_path [file normalize [info script]]
    # 获取当前路径
    set current_path [file dirname $script_path]
    # 使用正则表达式匹配倒数第四个斜杠之前的路径变量名
    regexp {/([^/]+)/[^/]+/[^/]+$} $current_path -> variable_name
    # 获取bit的文件路径---
        regexp {(.*)/[^/]+$} $current_path -> copy_path
    # 输出路径变量名
    # puts "rote1: $current_path"
    # puts "rote2: $variable_name"
    # puts "rote3: $copy_path"

    # 工程名
    set vivado_pro_name    $variable_name;
    puts "vivado_pro_name: $variable_name"
    # 设置工程的impl_1的文件夹路径
    set impl_1_path  $current_path;
    puts "vivado_pro_impl_1_path: $current_path"

## 运行add_tool_crc16_5.exe软件
    exec "$current_path/add_tool_crc16_5.exe" 

## 备份比特流文件
    # 获取当前时间
    set now [clock format [clock seconds] -format "bit-%Y-%m-%d %H.%M.%S"]  
    # 目标文件夹路径
    set target_folder $copy_path/bit/$now
    # 创建目标文件夹
    file mkdir $target_folder
    puts "mdir_path $target_folder"
    # 复制文件
    file copy -force "$current_path/top.ltx"            "$target_folder/top.ltx"
    file copy -force "$current_path/top.bit"            "$target_folder/top.bit"
    file copy -force "$current_path/top_bit_crc.txt"    "$target_folder/top_bit_crc.txt"

modelsim 片段

  1. tb.do 脚本会用到的一些命令
project compileall 
vsim -gui work.tb -novopt
do wave.do 
log -r */ 
radix hex
run 100ns
  1. tb里面可以读取.csv文件的函数
    1. 读取十六进制:readmemh
    2. 读取二进制:readmemb
      例子:
`timescale 1ns / 1ps
//****************************************Copyright (c)***********************************// 
//Copyright(C) 
//All rights reserved 
//----------------------------------------------------------------------------------------
// File name:           
// Last modified Date:  2023/09/11 14:06:51
// Last Version:        V1.0
// Descriptions:        
//----------------------------------------------------------------------------------------
// Created by:          jiang quan cai 
// Created date:        2023/09/11 14:06:51
// Version:             V1.0
// Descriptions:        
//
//----------------------------------------------------------------------------------------
//****************************************************************************************//

 
module tb();
    reg                                 clk                        ;
    reg                                 rst_n                      ;
    initial
    begin
        #2
                rst_n = 0   ;
                clk = 0     ;
        #10
                rst_n = 1   ;
    end                         
    parameter                           CLK_FREQ = 100             ;//Mhz               
    always # ( 1000/CLK_FREQ/2 ) clk = ~clk ;
    reg                [  15:0]         data[0:40]                 ;
    reg                [  15:0]         wave_data                  ;
    // integer i ;
    initial begin
      $readmemh("data.txt", data);
    end
   
    reg                [   5:0]         i                          ;
    always @(posedge clk)
      begin
        wave_data = data[i];
      end
    always @(posedge clk or negedge rst_n)
        begin
            if(!rst_n)
                i <= 'd0   ;
            else if(i <= 'd10 )
                i <= i + 1'b1;
            else
                i <= i  ;
        end
	```
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值