Commit 1765282e authored by Thomas Lange's avatar Thomas Lange
Browse files

+add: Design flow scripts for Libero SoC to create and synthesise a project.

parent 84f35e48
################################################################################
# title : devices_microsemi.py
# description : Defines necessary variables for the synthesis of Microsemi devices
# author : Thomas Lange
# email : thomas.lange@esa.int
# usage : source script and use set_device function with device
# libero_version : Libero SoC 11.7
################################################################################
# Select FPGA device and set corresponding variables
# @param device The selected device
# @return 1 when device was found
proc set_device {device} {
global device_family
global device_die
global device_package
global device_speed
global device_die_voltage
if { [string equal $device "RTG4"] } {
set device_family "RTG4"
set device_die "RT4G150"
set device_package "1657 CG"
set device_speed "STD"
set device_die_voltage "1.2"
return 0
}
if { [string equal $device "RTAX2000"] } {
set device_family "Axcelerator"
set device_die "RTAX2000D"
set device_package "352 CQFP"
return 0
}
return 1
}
################################################################################
# title : libero_env.csh
# description : Sets Libero license environment variable and path to Libero
# binaries (C shell).
# author : Thomas Lange
# email : thomas.lange@esa.int
# usage : source libero_env.csh
################################################################################
if ($?LM_LICENSE_FILE) then
else
setenv LM_LICENSE_FILE
endif
# Set license server
setenv LM_LICENSE_FILE 1702@mars:$LM_LICENSE_FILE
# Set Libero SoC path
setenv LIBERO_INSTALLED_DIR /cadlinux/actel/current/Libero
setenv PATH $LIBERO_INSTALLED_DIR/bin:$PATH
# Fix for error message "Wind/U X-toolkit Error: wuDisplay: Can't open display"
setenv DISPLAY `echo $DISPLAY |sed s/'\.0'//`
################################################################################
# title : new_libero_project.tcl
# description : Script to create a new Libero project.
# author : Thomas Lange
# email : thomas.lange@esa.int
# usage : libero SCRIPT:"new_libero_project.tcl" SCRIPT_ARGS:"<project_settings_file> [<device>]"
# version : Libero SoC 11.7
################################################################################
# set the used device
set default_device "RTG4"
# set the general project folder
set project_location "./syn/microsemi"
# load JSON parser package
set script_basedir [file dirname $argv0]/..
# load dict package
source $script_basedir/tcl_common/dict.tcl
# load JSON parser package
source $script_basedir/tcl_common/json_parser.tcl
# load device selecting function
source $script_basedir/microsemi/devices_microsemi.tcl
# check if enough arguments are given
if {$argc < 1} {
puts "Location of the project settings file is missing."
puts "Usage: libero SCRIPT:\"new_libero_project.tcl\" SCRIPT_ARGS:\"<project_settings_file> \[<device>\]\""
exit 1
} elseif {$argc == 1} {
set device $default_device
} elseif {$argc == 2} {
set device [lindex $argv 1]
} elseif {$argc > 2} {
puts "Too many arguments."
exit 1
}
# first argument is location of the project settings file
set prj_set_file [lindex $argv 0]
# open project settings file
set fp [open $prj_set_file r]
set prj_set_json [read $fp]
close $fp
# parse project settings file with JSON parser
set prj_set [json::json2dict $prj_set_json]
# extract values
set project_name [dict get $prj_set name]
set hdl_files [dict get $prj_set hdlFiles]
set VHDL_ver [dict get $prj_set vhdlVersion]
# select device
if { [set_device $device] } {
puts "Device $device is not defined."
exit 1
}
# delete old project directory
file delete -force $project_location
# create new project and set project-level properties
new_project \
-location $project_location \
-name $project_name \
-hdl "VHDL" \
-family $device_family \
-die $device_die \
-package $device_package \
-speed $device_speed \
-die_voltage $device_die_voltage \
-adv_options {IO_DEFT_STD:LVCMOS 2.5V} \
-adv_options {PART_RANGE:MIL} \
-adv_options {TEMPR:MIL} \
-adv_options {VCCI_1.2_VOLTR:MIL} \
-adv_options {VCCI_1.5_VOLTR:MIL} \
-adv_options {VCCI_1.8_VOLTR:MIL} \
-adv_options {VCCI_2.5_VOLTR:MIL} \
-adv_options {VCCI_3.3_VOLTR:MIL} \
-adv_options {VOLTR:MIL}
# set which VHDL version is used (not supported in current version).
#if { [string equal $VHDL_ver "VHDL1993"] } {
# project_settings \
# -vhdl_mode "VHDL_93"
#} elseif { [string equal $VHDL_ver "VHDL2008"] } {
# project_settings \
# -vhdl_mode "VHDL_2008"
#}
set prj_basedir [file dirname $prj_set_file]
# add HDL source files
foreach filename $hdl_files {
create_links -hdl_source $prj_basedir/$filename
}
# set name of top level entity
set_root -module $project_name
# clean up (remove temporary folder)
file delete -force "./\""
################################################################################
# title : syn_libero.tcl
# description : Script to synthesize a Libero project.
# author : Thomas Lange
# email : thomas.lange@esa.int
# usage : libero SCRIPT:"syn_libero.tcl" SCRIPT_ARGS:"<project_name> [<synthesis_step>"]
# version : Libero SoC 11.7
################################################################################
# check if enough arguments are given
if {$argc < 1} {
puts "Project name is missing."
puts "Usage: libero syn_libero.tcl <project_name> [<synthesis_step>]"
puts "Set <synthesis_step> to 1: Synthesize; 2: Compile, 3: Place & Route"
exit 1
} elseif {$argc < 2} {
set sec_arg 3
} elseif {$argc == 2} {
set sec_arg [lindex $argv 1]
} elseif {$argc > 2} {
puts "Too many arguements."
exit 1
}
# first argument defines the project name
set project_name [lindex $argv 0]
# second (optional) argument defines the synthesis step
set syn_step $sec_arg
# open project
open_project \
-file "./syn/microsemi/$project_name.prjx" \
-do_backup_on_convert 1 \
-backup_file "./syn/microsemi/$project_name.zip"
# run synthesis steps
if {$syn_step >= 1} {
run_tool -name {SYNTHESIZE}
}
if {$syn_step >= 2} {
run_tool -name {COMPILE}
}
if {$syn_step == 3} {
run_tool -name {PLACEROUTE}
}
# clean up (remove temporary folder)
file delete -force "./\""
if ($?LM_LICENSE_FILE) then
else
setenv LM_LICENSE_FILE
endif
# Set license server
setenv SYNOPSYS_KEY_FILE 1700@mars
setenv SNPSLMD_LICENSE_FILE 1700@mars
setenv LM_LICENSE_FILE 1700@mars:$LM_LICENSE_FILE
setenv SNPSLMD_ENABLE_INCREMENTAL_LICENSE_HANDLING 1
# Path settings
setenv SYNOPSYS /cadlinux/synopsys/current
setenv PATH /cadlinux/synopsys/mw/bin:$PATH
setenv PATH /cadlinux/synopsys/shls/bin:$PATH
setenv PATH /cadlinux/synopsys/fpga/bin:$PATH
setenv PATH /cadlinux/synopsys/fm/bin:$PATH
setenv PATH /cadlinux/synopsys/pt/bin:$PATH
setenv PATH /cadlinux/synopsys/tx/bin:$PATH
setenv PATH $SYNOPSYS/bin:$PATH
This diff is collapsed.
#
# JSON parser for Tcl.
#
# See http://www.json.org/ && http://www.ietf.org/rfc/rfc4627.txt
#
# Total rework of the code published with version number 1.0 by
# Thomas Maeder, Glue Software Engineering AG
#
# $Id: json.tcl,v 1.7 2011/11/10 21:05:58 andreas_kupries Exp $
#
if {![package vsatisfies [package provide Tcl] 8.5]} {
package require dict
}
package provide json 1.1.2
namespace eval json {
# Regular expression for tokenizing a JSON text (cf. http://json.org/)
# tokens consisting of a single character
variable singleCharTokens { "{" "}" ":" "\\[" "\\]" "," }
variable singleCharTokenRE "\[[join $singleCharTokens {}]\]"
# quoted string tokens
variable escapableREs { "[\\\"\\\\/bfnrt]" "u[[:xdigit:]]{4}" }
variable escapedCharRE "\\\\(?:[join $escapableREs |])"
variable unescapedCharRE {[^\\\"]}
variable stringRE "\"(?:$escapedCharRE|$unescapedCharRE)*\""
# (unquoted) words
variable wordTokens { "true" "false" "null" }
variable wordTokenRE [join $wordTokens "|"]
# number tokens
# negative lookahead (?!0)[[:digit:]]+ might be more elegant, but
# would slow down tokenizing by a factor of up to 3!
variable positiveRE {[1-9][[:digit:]]*}
variable cardinalRE "-?(?:$positiveRE|0)"
variable fractionRE {[.][[:digit:]]+}
variable exponentialRE {[eE][+-]?[[:digit:]]+}
variable numberRE "${cardinalRE}(?:$fractionRE)?(?:$exponentialRE)?"
# JSON token
variable tokenRE "$singleCharTokenRE|$stringRE|$wordTokenRE|$numberRE"
# 0..n white space characters
set whiteSpaceRE {[[:space:]]*}
# Regular expression for validating a JSON text
variable validJsonRE "^(?:${whiteSpaceRE}(?:$tokenRE))*${whiteSpaceRE}$"
}
# Validate JSON text
# @param jsonText JSON text
# @return 1 iff $jsonText conforms to the JSON grammar
# (@see http://json.org/)
proc json::validate {jsonText} {
variable validJsonRE
return [regexp -- $validJsonRE $jsonText]
}
# Parse JSON text into a dict
# @param jsonText JSON text
# @return dict (or list) containing the object represented by $jsonText
proc json::json2dict {jsonText} {
variable tokenRE
set tokens [regexp -all -inline -- $tokenRE $jsonText]
set nrTokens [llength $tokens]
set tokenCursor 0
return [parseValue $tokens $nrTokens tokenCursor]
}
# Throw an exception signaling an unexpected token
proc json::unexpected {tokenCursor token expected} {
return -code error "unexpected token \"$token\" at position $tokenCursor; expecting $expected"
}
# Get rid of the quotes surrounding a string token and substitute the
# real characters for escape sequences within it
# @param token
# @return unquoted unescaped value of the string contained in $token
proc json::unquoteUnescapeString {token} {
set unquoted [string range $token 1 end-1]
return [subst -nocommands -novariables $unquoted]
}
# Parse an object member
# @param tokens list of tokens
# @param nrTokens length of $tokens
# @param tokenCursorName name (in caller's context) of variable
# holding current position in $tokens
# @param objectDictName name (in caller's context) of dict
# representing the JSON object of which to
# parse the next member
proc json::parseObjectMember {tokens nrTokens tokenCursorName objectDictName} {
upvar $tokenCursorName tokenCursor
upvar $objectDictName objectDict
set token [lindex $tokens $tokenCursor]
incr tokenCursor
set leadingChar [string index $token 0]
if {$leadingChar eq "\""} {
set memberName [unquoteUnescapeString $token]
if {$tokenCursor == $nrTokens} {
unexpected $tokenCursor "END" "\":\""
} else {
set token [lindex $tokens $tokenCursor]
incr tokenCursor
if {$token eq ":"} {
set memberValue [parseValue $tokens $nrTokens tokenCursor]
dict set objectDict $memberName $memberValue
} else {
unexpected $tokenCursor $token "\":\""
}
}
} else {
unexpected $tokenCursor $token "STRING"
}
}
# Parse the members of an object
# @param tokens list of tokens
# @param nrTokens length of $tokens
# @param tokenCursorName name (in caller's context) of variable
# holding current position in $tokens
# @param objectDictName name (in caller's context) of dict
# representing the JSON object of which to
# parse the next member
proc json::parseObjectMembers {tokens nrTokens tokenCursorName objectDictName} {
upvar $tokenCursorName tokenCursor
upvar $objectDictName objectDict
while true {
parseObjectMember $tokens $nrTokens tokenCursor objectDict
set token [lindex $tokens $tokenCursor]
incr tokenCursor
switch -exact $token {
"," {
# continue
}
"\}" {
break
}
default {
unexpected $tokenCursor $token "\",\"|\"\}\""
}
}
}
}
# Parse an object
# @param tokens list of tokens
# @param nrTokens length of $tokens
# @param tokenCursorName name (in caller's context) of variable
# holding current position in $tokens
# @return parsed object (Tcl dict)
proc json::parseObject {tokens nrTokens tokenCursorName} {
upvar $tokenCursorName tokenCursor
if {$tokenCursor == $nrTokens} {
unexpected $tokenCursor "END" "OBJECT"
} else {
set result [dict create]
set token [lindex $tokens $tokenCursor]
if {$token eq "\}"} {
# empty object
incr tokenCursor
} else {
parseObjectMembers $tokens $nrTokens tokenCursor result
}
return $result
}
}
# Parse the elements of an array
# @param tokens list of tokens
# @param nrTokens length of $tokens
# @param tokenCursorName name (in caller's context) of variable
# holding current position in $tokens
# @param resultName name (in caller's context) of the list
# representing the JSON array
proc json::parseArrayElements {tokens nrTokens tokenCursorName resultName} {
upvar $tokenCursorName tokenCursor
upvar $resultName result
while true {
lappend result [parseValue $tokens $nrTokens tokenCursor]
if {$tokenCursor == $nrTokens} {
unexpected $tokenCursor "END" "\",\"|\"\]\""
} else {
set token [lindex $tokens $tokenCursor]
incr tokenCursor
switch -exact $token {
"," {
# continue
}
"\]" {
break
}
default {
unexpected $tokenCursor $token "\",\"|\"\]\""
}
}
}
}
}
# Parse an array
# @param tokens list of tokens
# @param nrTokens length of $tokens
# @param tokenCursorName name (in caller's context) of variable
# holding current position in $tokens
# @return parsed array (Tcl list)
proc json::parseArray {tokens nrTokens tokenCursorName} {
upvar $tokenCursorName tokenCursor
if {$tokenCursor == $nrTokens} {
unexpected $tokenCursor "END" "ARRAY"
} else {
set result {}
set token [lindex $tokens $tokenCursor]
set leadingChar [string index $token 0]
if {$leadingChar eq "\]"} {
# empty array
incr tokenCursor
} else {
parseArrayElements $tokens $nrTokens tokenCursor result
}
return $result
}
}
# Parse a value
# @param tokens list of tokens
# @param nrTokens length of $tokens
# @param tokenCursorName name (in caller's context) of variable
# holding current position in $tokens
# @return parsed value (dict, list, string, number)
proc json::parseValue {tokens nrTokens tokenCursorName} {
upvar $tokenCursorName tokenCursor
if {$tokenCursor == $nrTokens} {
unexpected $tokenCursor "END" "VALUE"
} else {
set token [lindex $tokens $tokenCursor]
incr tokenCursor
set leadingChar [string index $token 0]
switch -exact -- $leadingChar {
"\{" {
return [parseObject $tokens $nrTokens tokenCursor]
}
"\[" {
return [parseArray $tokens $nrTokens tokenCursor]
}
"\"" {
# quoted string
return [unquoteUnescapeString $token]
}
"t" -
"f" -
"n" {
# bare word: true, false or null
return $token
}
default {
# number?
if {[string is double -strict $token]} {
return $token
} else {
unexpected $tokenCursor $token "VALUE"
}
}
}
}
}
proc json::dict2json {dictVal} {
# XXX: Currently this API isn't symmetrical, as to create proper
# XXX: JSON text requires type knowledge of the input data
set json ""
dict for {key val} $dictVal {
# key must always be a string, val may be a number, string or
# bare word (true|false|null)
if {0 && ![string is double -strict $val]
&& ![regexp {^(?:true|false|null)$} $val]} {
set val "\"$val\""
}
append json "\"$key\": $val," \n
}
return "\{${json}\}"
}
proc json::list2json {listVal} {
return "\[[join $listVal ,]\]"
}
proc json::string2json {str} {
return "\"$str\""
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment