TCL scripting language
Tcl (Tool Command Language) is a very common scripting language that can be interpreted and run on almost all platforms, and VIVADO also provides the TCL command line. Recently, it has been found that the TCL script seems to be more efficient and convenient than the VIVADO operation under the GUI. And recently followed the official website document to do SDSOC flatform, found that the xilinx official website documents are completed with TCL commands, so determined to learn the TCL syntax.
Applications such as VIVADO use Tcl as a benefit of its command language:
1 Tcl provides a standard syntax that can be easily issued to Tcl-based programs once the user has mastered Tcl.
2 Tcl implements a lot of features to make your work very convenient.
3 TCl can be used as an interface for inter-program communication.
Command format
When a Tcl command string contains multiple commands, they are separated by a newline or a semicolon.
Each command contains a collection of fields, the fields are separated by white space, the first field is the name of a command, and the other is passed to it as a parameter.
type of data
Tcl only supports one data structure: string. All commands, all parameters in the command, the result of the command, and the variables are all strings.
Simple example:
Set i 123
Assign the string 123 to the i variable
Unset i
Clear variable
Set i hi
Assign the string hi to the i variable
Set i “hi helloâ€
Hi hello has spaces, so quotes
Set i 123;#Start comment
Before paying attention to the comment, you must first use the semicolon to end the command, or wrap the comment.
Basic syntax and basic commands
Learn these basic grammars in the TCL command line in VIVADO
(Windows –†Start – “All Programs –†Xilinx Design Tools – “Vivado xxx –†Vivado xxx Tcl Shell)
1" uses the $ symbol to reference variables
Where puts is the print command
2" use [] to return the value of the command as a parameter of the new command
Set j 232 command will return the value 232
The new command becomes set i 232
Here is a slightly more complicated example:
Set ia[set jb][set kc]
The final result is: j = b ; k = c ; i = abc
3" array
Arrays don't need to be declared, they can be assigned directly, and they don't have to be in order:
Set i(1) 123 ; set i(16) hi
Of course, arrays of any dimension are also supported:
Set i(1,2,3) hi
When you quote, you can directly $i(1,2,3)
· parray command
Can print out all the information of an array:
· array command
Command format: array opTIon arrayName
opTIon is an operation option with the following options:
Name : returns the name of all elements of the array
Size : returns the length of the array
Startsearch : Initializes a traversal and returns a traversal identifier (searchId). This searchId is used below (it can be done simultaneously with multiple traversals)
The following command format is: array opTIon arrayName searchId
-"nextelement : returns the next element in the array, if no return is empty
-"anymore : If there are elements next, return 1; otherwise return 0
-"donesearch : End traversal
4" string command
· string command
Command format: string opTIon string1 string2
Option is an operation option with the following options:
Compare : compares the order of the letters, string1 ", =," string2, respectively -1,0,1
Match : determine if string1 and string2 match
First : retrieves the position of string1 in string2 for the first time, or -1 if string1 does not appear
Last : opposite to first
Trim : remove the beginning and end of string2 characters from string1
Command format: string option string
Tolower : returns a new string after all characters in string are converted to lowercase characters
Toupper : returns all strings in string to uppercase strings
Trimleft : , remove the string left blank, similar to trimright
Length : returns the length of string1
Range :
String range abcdef 1 2, return the output as bc
· append command
String append, can be infinitely stitched
Set ia
Append ibcd
Puts $i
The value of the i variable becomes abcd, pay attention to the append ibcd command instead of append $ibcd
· split command
Command format: split string separator, converts a string to a list
5" digital operation
There are only string type variables in tcl, so when performing numerical operations, you need to use the incr and expr operation commands.
· incr command
a variable self-add-3:incr a -3
a variable self-added 1: incr a
· expr command
Similar to the arithmetic operators in C (the logic in Tcl: true 1, false 0):
! , *, /, %, +, -, ",", ",", "=," =, ==,! =, &, ^, |, &&, || , x ? y : z
In addition to this, expr recognizes some functions and their return values:
Abs(x) , round(x) , sin(x), cos(x), etc.
Use method: expr expression
6"list list
Like a list in Python, for example: {abc {def {jkl ccc}}} is a list of two elements abc and {def {jkl ccc}}, the commands for list in Tcl are:
(First set l {abc {def {jkl ccc}}}, the following example will operate on this l list)
It should be noted that most of the commands are processed for $l, and the content string of l is taken out and processed, which does not affect the content of the list.
Need to pay attention to is the lappend command, lappend $l abcd is invalid, you must lappend l abcd to achieve the update of the list content, and directly change the contents of the list
7 "proc custom function
Proc:
Proc hello {str} {
Puts hello: $str
}
It should be noted that if you can't write one line, it is recommended to define it in the following format (mainly to put "{" at the end of the first line):
The first line: proc+ (space) + function name + (space) + {parameter} + (space) + {
Middle line: logical operation
Last line: }
Global variable global:
Used to turn local variables in the process into externally operable global variables
Proc hello {} {
Global x
Set x hi
Set i hello}
The above code, the result of the execution:
Return command:
Proc hello {} {return world}
Set i [hello]
The return command has nothing to say, the result of the above code is that the i variable is assigned to the world string.
8" flow control
If flow control
This is also recommended by format:
First line: if+ (space) + {expression} + (space) + {
Middle line: logical operation
Line N: }+ (space) +else+ (space)+{
Middle line: logical operation
Last line: }
Switch flow control
The examples are as follows, at a glance:
Switch 2 {
1 {puts 111}
2 {puts 222}
3 {puts 333}
Default {puts xxx}
}
Case flow control
Case abcd in a {puts 111} *bc* {puts 333} default {puts xxx}
The above program judges the string abcd:
Condition one: the string is a
Condition 2: Regardless of the character before and after the string is å•¥, as long as there is a bc substring in the middle
Condition three: default
9" loop control
Foreach loop:
If you want to put 0, 3, 2, 1 in the decision condition (list) of the above switch in order, and output four results, you need this foreach:
Foreach i {0 3 2 1} {
Switch $i {
1 {puts 111}
2 {puts 222}
3 {puts 333}
Default {puts xxx}
}
}
For loop:
The for loop of TCL is also very similar to C:
For {set i 0} {$i " 10} {incr i} {
Puts $i
}
Initialize i=0, range i "10, loop i=i+1
While loop:
Set i 10
While {$i! =5} {
Puts $i
Incr i -1
}
I can imagine the results of the operation.
10" string converted to command
Eval command:
Set a set ; set bi ; set c hello ; eval $a $b $c
The above code is equivalent to: set i hello
Eval executes the contents of the string as a command
11" printout
The previous puts command can also be printed to the command line, but it can only be printed out, and this format is similar to sprintf in C (for formatting output):
Format command:
Format can be used like this:
Format "%s %d" hello 666
Set i [format "%s %d" hello 666]
Scan command:
Speaking of format, just put the scan together, these two commands can be seen as the opposite pair, the former is combined into a string, the latter is assigned to the variable after splitting the string
Scan 12.34.56.78 %d.%d.%d.%dabcd
Split 12.34.56.78 and assign them to abcd four variables respectively. The command returns the number of variables that have been successfully assigned.
Puts command:
Puts can of course also be printed to a file
Set f [open test.txt w]
Puts -nonewline $f "hello"
Puts $f "world"
Close $f
Puts -nonewline $f "hello" means to force no line break printing, otherwise automatically append a newline
File system
Basic common operations:
Gets -" read one line at a time
Puts –†write to file
Open –†open file
Close –》 Close file
Flush –†flush buffer
Cd command
Same as cd in shell
Pwd command
Used to view the current directory
Open command
Open file, return file descriptor
Command format: open file name mode, support 6 modes, and file IO in other programming languages, is also very similar, the mode is as follows:
r mode: Open read-only file (file must exist)
r+ mode: Open readable and writable files [r+ and a+ mode can be analogized]
w mode: Opens a write-only file, clears the content if it exists, and creates a file if it does not exist.
a mode: Open the write-only file in append mode, if the file does not exist, create it; if the file exists, append the written data to the end of the file content
Xxxx
In theory, open | file name mode, add a "|" symbol in front of the file name, you can open the file in the pipeline mode, but the test has not been successful, then use it to solve it.
Xxxx
Read command
Set f [open test.txt r]
Read $f 6
Close $f
You can use the eof command to determine whether the file has been read, eof $f, return 1 after reading, or 0 otherwise.
The above code reads 6 bytes directly from the file; if you want to read all the contents of the file, read $f directly; if you want to read it line by line, use the gets command: gets $f
Source command
Command format: source $f
Read the content from the corresponding file and pass it to Tcl to explain the execution.
Tell command
Returns the pointer position of the file, command format: tell $f
File command
Command format: file option name
If there are more option operation options, just list the tables directly, as shown below:
In addition to this, the stat status operation option for file:
Command format: file stat name k, the result exists in the array k
Glob command
1) View the files in the current directory (similar to ls in the shell)
Glo *
2) View the files of the specific suffix in the current directory
Glob *.txt *.tcl
3) View the txt, txl, tcl and tct files in the current directory:
Glob {*t[xc][tl]}
4) View the txt, txl, tcl, and tct files in the subdirectory under the current directory:
Split the path with "\" in the format: glob {{directory 1, directory 2, etc.}\\*.suffix}
5)-type select view type:
Command format: glob -type {type 1 type 2, etc.} target directory
Types are:
Type meaning
b block device
c character device
d stands for directory
f file
l represents symbolic links
p stands for named pipe
s stands for socket
r read
w write
x executable
Seek command
Used to adjust the file pointer
The command seek $f 2, the file pointer is positioned to the sequence number 2, and now there is a file named s1.txt, the content is the hello string, then, design a program to start reading the file content from the third string:
Info command to get information
If a process is created: proc hello { abc } {puts hi}
Execute the command: info args hello, return abc, parameter list
Execute the command: info body hello, then return puts hi, function body
Info procs, returns a list of all the procedures
Info procs hello, returns a hello string if there is a hello process, does not return if it does not exist
Info commands, which lists all commands supported by the interpreter
Info commands create_ip, create_ip is the tcl command supported by vivado, so the value returned by this info is create_ip. If the command is not supported, the value is not returned.
Info exists kkk, to determine whether the kkk variable exists
Info vars, returns a list of current variable names
Info vars i, return i string if the i variable exists, not return if it does not exist
Info globals, returns a list of global variables
Info globals env, returns env if the env global variable exists, does not return if it does not exist
Info locals, returns a list of local variables
Info locals i, return i if there is this i local variable, not return if it does not exist
Info hostname, return the host name
Info cmdcount, returns the number of commands that the current interpreter has executed.
Info tclversion, return the interpreter version number
Info level, returns the current absolute position on the stack
Info level 1, if the parameter number is added, the commands and parameters of the layer are returned.
Note: uplevel command (connection parameter)
Since the level is said, the uplevel command is said. The level value is 0 for the top level, and the level is the absolute position on the stack. When the procedure is called, the level is higher than the level of the layer by one. Want to perform operations in the upper layer environment, then you need the uplevel command
Proc hello {} { uplevel set a “helloworld†}
Set a hi ; hello ; puts $a
Note: upvar command (connection variable)
Since the uplevel is said, the upvar command is also said, which is similar to the uplevel command, but it focuses on connecting a single variable between different layers.
Proc hello {a} {upvar $ax ; set x helloworld}
Set i hi ; hello i ; puts $i
System exception, system monitoring
Catch command
Used to prevent interrupt execution caused by errors, similar to the exception in python, the execution returns 0, otherwise it returns 1
Unknown command
I classify this instruction as an exception instruction.
Usage: First define an unknown process, the parameters of this process are cwd (command) and args (parameter)
Proc unknown {cwd args} {
Puts commend:$cwd
Puts args:$args
}
In this case, when there is an unknown command or the wrong code, you can control the error through the unknown process.
Time command
Time "set i 10", the command will calculate the execution time
Trace command
The command to store the variables is not available for the time being.
Namespace namespace
A namespace is a collection of commands and variables that are guaranteed by namespaces to prevent them from affecting variables and commands in other namespaces.
Set a new namespace
First define two hello processes, one of which is in the hlf namespace and then test
Namespace eval hlf {pro hello {} {puts hello_hlf}}
Pro hello {} {puts hello_all}
Set new variables
Set the hlf space i directly through set hlf::i 888
Delete namespace
Command: namespace delete hlf
Shared variables and procedures in different namespaces
Through the export and import commands, complete a namespace export process, another namespace to import it, complete the process sharing
Set or access variables in the namespace
The variable command is illustrated by an example:
Array eval hlf {
Variable i 5
Proc next {} {variable i;return [incr i]}
Proc reset {} {variable i;set i 0}
}
The current understanding is that you can pass variables in different processes within the same namespace, so you don’t get to the bottom.
So far, I have a rough understanding of the basic use of TCL. There are still a lot of specific functions and function options that are not involved. If you use it later, then add it, but I think it should deal with VIVADO's TCL. Grammar, these basic grammars should be sufficient. The next step is to understand the functions of the TCL library that comes with VIVADO.
After encountering a command that you don't understand, just type the command -help and you will see a bunch of help.
Sapphire is a single crystal form of Al2O3, with a favorable combination of chemical, mechanical and optical properties. Sapphire is resistant to attack by strong acids, enabling use in a corrosive atmosphere. It is resistant to scratch and abrasion with very high Knoop hardness of 1800 parallel to the optic axis (C-axis), 2200 perpendicular to the optic axis.
Sapphire Crystal,Sapphire Windows,Sapphire Glass Tube,Sapphire Tube
Zoolied Inc. , https://www.zoolied.com