Scripting Xilinx® ISE™ using Tcl

 

 A Tutorial based on a simple implementation

 

Doulos, July 2008

Introduction

Xilinx ISE is one of the many EDA tools that can be controlled using Tcl. Why would you want to do that? Well, on our courses we often see delegates make an edit to their source code, then re-implement it only to find that the synthesis/layout doesn't do the same as it did before.

This is a constant danger if repeatability depends on remembering to click on the correct boxes and menus in the user interface. If you create a command file you can run that same file many times, thus guaranteeing that you are issuing the same commands to the tool each time.

There are two ways of running the script:

  1. Within the GUI there is a Tcl command window, in which you can source (i.e. call/run) a script.
  2. You can issue the command "xtclsh scriptname" in your DOS command window or *nix shell and avoid the overhead of a graphical interface completely.

With all this in mind, we are now going to explore some of the ways in which we can drive ISE from a Tcl script. We will synthesise a small design using XST and implement it in a Spartan3e device (chosen to match the boards used on our course VHDL for FPGA Design).

Input files

The first thing we need to do is to tell the tool which source files will be used. We want to do this in a maintainable way, and to this end all filenames are given at the top of the script.

We set some Tcl variables to contain the filenames we require:

# where all output will be created
set compile_directory     spartan3e
# the top-level of our HDL source:
set top_name              spartan3e_top
# input source files:
set hdl_files [ list \
  ../constants_spartan.vhd \
  ../components.vhd \
  ...Other files... \
]
# constraints with pin placements.
set constraints_file      ../spartan3e_fsm.ucf

A # denotes a comment; the comment is terminated by a newline and is ignored by the parser. Care is required, as other Tcl behaviour means a hash character will not always be interpreted as the beginning of a comment. Until you know this behaviour it's best to follow these rules about comments:

  • Each comment appears on a separate line where # is the first character on that line
  • In a comment, don't include mismatched round or square brackets and don't use curly brackets at all

The set command is used to apply a value to a variable:

set variable_name value

In the setting of the variable "hdl_files" we used the list command to create a Tcl list from the text strings that follow it. As a simpler alternative, we could have used braces to enclose a set of strings:

set hdl_files {
  ../constants_spartan.vhd
  ../components.vhd
  ...Other files...
}

This approach has some drawbacks, especially when the list items have spaces or special characters. It's generally best to construct the list using the list command. This also allows you to use lappend and lindex commands to manipulate the list.

Setting a Compilation Directory

We now need somewhere to process our files. We can use the file command and its sub-command mkdir to create a directory:

if {![file isdirectory $compile_directory]} {
  file mkdir $compile_directory
}

This code asks if the directory exists; if not, it is created. You may also find file exists useful. Using $ in front of a variable name give you the content of that variable.

Project Creation and Settings

So, now we have a directory and we can do something there. Assuming no project exists in this directory we can go ahead and make one. Xilinx provide the project command, which includes sub-commands for the project settings and other related tasks. Let's try some:

project new $proj.ise
project set family Spartan3E
project set device xc3s500e
project set package fg320
project set speed -4

This is one of the strengths of Tcl; it is easy to add new commands by writing your own procedures. Doing that is outside the scope of this discussion but is covered fully in Essential Tcl/Tk.

Now we need to add some files to the project. Again, Xilinx provide a Tcl command for this: the xfile command is used to add or remove files and to get information on any source files in the current ISE project. We need to add some files, but we don't really want to type filenames again (maintainability, remember?) and we already have a list of source files. The solution is to loop through the list adding each file to the project:

foreach filename $hdl_files {
  xfile add $filename
  puts "Adding file $filename to the project."
}

The puts command is a simple way to write to STDOUT (which is usually the console/shell). Note: don't forget to add the constraints file; NGDBuild does not automatically detect .ucf files when run from Tcl. Use xfile add in the same way.

Running Processes

Before we run any processes, we can set process options using project set as above; see the provided script for examples and the Xilinx Development System Reference Guide for exhaustive detail.

Now we can run something. Just as with the ISE graphical interface, running any given process will run any required prior processes. In our example, I can issue this command:

process run "Generate Programming File"

and the design will be synthesised and implemented first before the bitfile is created. Again, just as in the graphical interface, source and intermediate file dependencies are checked and processes are run only if required. For example, to force a rerun:

process run "Implement Design" -force rerun_all

Programming the Device

Here we have to change our approach as Impact does not have a Tcl interface. However, this does allow us to explore another way of controlling applications. Impact has the ability to run a script file that consists of a series of commands. These are not Tcl commands, but we can use Tcl to construct this file. We can then run Impact from with the Tcl script. Let's see how.

First we need to open a file that will become the Impact script. We do this with the open command:

if {[catch {set f_id [open $impact_script_filename w]} msg]} {
  puts "Can't create $impact_script_filename"
  puts $msg
  exit
}

What's going on here? The open command returns a handle to the file which we put in the variable "f_id". If open fails it would stop the script; this is probably the best thing to do here, but in general you may want to trap errors and continue with other things. That's what catch can do; it will return a non-zero error code if the command it runs (in this case the open) fails, and it places any error message from that command in the variable that here we have called "msg". Hence, if the open fails $msg will contain the reason why.

How do we write text to the file? With the puts command. Earlier we used it to write text to the console, but here we see an addition:

puts $f_id "addDevice -position 1 -file $bit_filename"

Well, it's not really an addition: the default destination of a puts command is the standard output, so if we leave off the second argument then STOUT is where the output goes. The line above uses a second argument, so the text is written to the file given by $f_id instead. After we have written the required command to the Impact script we should close the file.

Now we have to start Impact. There are several ways of calling external programs from Tcl; the easiest is to use the exec command, which runs the external program, waits for it to finish and returns all its output. This is acceptable for quick programs but not for anything more complicated, as you cannot direct any input to the program or control it while it is running. More flexibility is provided by using open, but this time as a pipe from the program:

set impact_p [open "|impact -batch $impact_script_filename" r]

This line starts Impact with the script, and returns its output to the variable "impact_p". The benefit of using the pipe is that we can now watch the STDOUT of the tool from within our Tcl script:

while {![eof $impact_p]} { gets $impact_p line ; puts $line }

This code writes each line of Impact's output to the Tcl script's own standard output. The command eof returns true when the external program finishes. This approach will not work if the external program requires some interaction because that program will not tell you when it requires some input. In our case, however, this is fine, because we want the Impact script to run until completion. We explore ways of interacting with programs in Essential Tcl/Tk.

Assuming all this runs successfully you should have a working device. Congratulations!

Click here to download the source files for this example and this page as a PDF file. In exchange, we will ask you to enter some personal details. To read about how we use your details, click here. On the registration form, you will be asked whether you want us to send you further information concerning other Doulos products and services in the subject area concerned.

(FROM : http://www.doulos.com/knowhow/tcltk/xilinx/)

转载于:https://www.cnblogs.com/Jerome_Lee/archive/2010/05/14/1735537.html

Scripting Xilinx® ISE™ using Tcl相关推荐

  1. Xilinx ISE 开发过程中生成的各种文件(一)

    电路设计与输入-->功能仿真-->综合优化-->实现过程(翻译.映射.布局布线3个小步骤)-->烧写芯片,在线调试 综合优化: XST:全称为XilinxSynthesis T ...

  2. Xilinx_ISE和ModelSim的联合使用方法 / 从Xilinx ISE 14.7启动ModelSim时遇到的问题

    解决方法: 前提是安装了 xilinx ise14.7 和modelsim se 10.1a 1〉从Windows的Start Menu开始,Xilinx ISE Design Suite 14.7 ...

  3. Xilinx ISE系列教程(8):读取FPGA芯片唯一ID号

    文章目录 @[toc] 应用场景 方法1:通过JTAG读取 方法2:调用原语读取 DNA_PORT原语的使用 注意 本文是Xilinx ISE系列教程的第8篇文章. 用过单片机的朋友都知道,单片机芯片 ...

  4. Xilinx ISE系列教程(2):LED点灯工程、仿真、bit下载和mcs固化

    文章目录 @[toc] 1. 创建工程目录 2. 新建ISE工程 3. 新建verilog源文件 4. 新建testbench仿真文件 5. ISim功能仿真 6. 管脚分配和时钟约束 7. bit文 ...

  5. ModelSim SE 10.0a建立并调用Xilinx ISE 13.1仿真库详解

    从网上搜到的有很多,实践过其中几种,其中一种较简单的方法如下: 1)安装ModelSim 和ISE 并注册破解: 2)将ModelSim根目录下的modelsim.ini文件的只读属性去掉. 3)将c ...

  6. Xilinx ISE 14.7 官方Win10版本安装教程(解决Win10闪退问题)

    Xilinx ISE 14.7 官方Win10版本安装教程(解决Win10闪退问题) 说在前面 第一步 官网下载 ISE 14.7 Win10 第二步 安装 第三步 运行程序 第四步 Oracle V ...

  7. Xilinx ISE 出现 Bitgen:342 - This design contains pins which have locations (LOC)...解决办法

    当Xilinx ISE出现以下情况时 ERROR:Bitgen:342 - This design contains pins which have locations (LOC) that aren ...

  8. Linux环境下安装Xilinx ISE 14.6

    1.从官网下载ISE 到官网注册,然后下载linux版本的ISE14.7. 链接:http://www.xilinx.com/support/download/index.html/content/x ...

  9. Xilinx ISE、Synplify、Modelsim之间的关系,为什么会存在比ISE更专业的FPGA开发工具?

    虽说Xilinx的ISE内自带了综合和仿真工具,但是在网络论坛上很多人都说这两个功能模块(特别是仿真模块)并不好用而且不专业,所以建议专业用户使用Synopsys公司提供的Synplify.Synpl ...

最新文章

  1. 计算机设备图标怎么删除,电脑设备和驱动器中没用的图标怎么删除? 我的电脑中手机...
  2. List集合2-LinkedList
  3. 曙光与包头签署云计算中心战略合作协议
  4. HTTP 方法:GET 对比 POST
  5. 2019信安国赛逆向easyGo,bbvvmm题解
  6. 特征图大小_新手向快速了解图神经网络
  7. 据调查95%以上的AI从业者不具备修改模型或者提出新模型的技术能力
  8. 基于visual Studio2013解决C语言竞赛题之0710排序函数
  9. 亿佰特物联网通信专家:蓝牙模块和 Zigbee协议模块的区别
  10. java程序员内功_Java程序员如何成为内功深厚的架构师
  11. MySQL Root密码丢失解决方法总结
  12. linux qt目录查看,QT遍历目录获取文件信息
  13. JDY-1110B电压继电器
  14. Jquery 例外被抛出且未被接住
  15. PE文件偏移地址分析
  16. 电脑自动跳出计算机管理员登陆界面,解决运行wegame总是弹出用户账户控制界面的方法...
  17. WebGL场景的两种地面构造方法
  18. APP推广|小众APP推广渠道,总有适合你的。
  19. Matplotlib填充色Colormap
  20. python实战篇(六)---打造自己的签名软件

热门文章

  1. Python——遍历整个列表
  2. 高配置玩无主之地帧数过低解决方案
  3. java 圆的交点_Java:三角形的内切圆,外接圆
  4. c语言定义四个整型查表的数,C语言知识点速查表
  5. 这些iPhone 手机辅助功能你都了解吗(二)
  6. 庆阳市西峰区中小学武术教学开展现状及应对措施-1
  7. Python3 单行注释,多行注释,文档注释的用法
  8. 分享iOS开发常用(三方类库,工具,高仿APP,实用网站)
  9. 中文编程,最精致的python访客登记系统实例项目,微信机器人不再只当人工智障------03
  10. Halcon:正弦带通滤波器处理条纹