
# A common procedure to compute the runtime for each command run in Libero.
# Get tool name from the command
proc run_tool_wrapper { cmd } {
  regexp {run_tool\s+-name\s+\{*(\w*)\}*} $cmd full1 tool;
  puts "Starting $tool command";
  set full_cmd "time \{ $cmd \}";
  set TIME_start [clock seconds];
  set runtime [ eval $full_cmd ];
  set TIME_taken [expr [clock seconds] - $TIME_start];
  puts "\nRUNTIME:$tool=$TIME_taken secs\n";
  set runtime_secs [ expr [lindex $runtime 0]/1000000 ];
  puts "\nRUNTIME_bytime:$tool=$runtime_secs secs\n";
}


# Set Project name
set Prjname "BaseR_TOP"



# Generate FPGA Array Data
## run_tool -name GENERATEPROGRAMMINGDATA
run_tool_wrapper "run_tool -name GENERATEPROGRAMMINGDATA
"

puts "Programming file generated successfully\n"

 

## run_tool -name {DEV_MEM_INIT} 
run_tool_wrapper "run_tool -name {DEV_MEM_INIT} "


generate_design_initialization_data
    
# Configure and generate programming file data
# Examples for configuring the programming files TBD
## run_tool -name GENERATEPROGRAMMINGFILE
run_tool_wrapper "run_tool -name GENERATEPROGRAMMINGFILE
"

puts "Programming file generated successfully\n"
    
# Export STAPL file
export_bitstream_file \
    -file_name {BaseR_TOP} \
    -export_dir ${PrjLocation}/designer/BaseR_TOP/export \
    -format STP \
    -master_file 0 \
    -encrypted_uek1_file 0 \
    -encrypted_uek1_file_components {} \
    -encrypted_uek2_file 0 \
    -encrypted_uek2_file_components {} \
    -trusted_facility_file 1 \
    -trusted_facility_file_components "FABRIC SNVM"

puts "Exported bit stream successfully\n"

# Export Programming Job
# Programming job files can be imported in FlasPro Express standalone for programming the device
export_prog_job \
    -job_file_name {BaseR_TOP} \
    -export_dir ${PrjLocation}/designer/BaseR_TOP/export \
    -bitstream_file_type {TRUSTED_FACILITY} \
    -bitstream_file_components {FABRIC SNVM} \
    -program_design 1 \
    -program_spi_flash 0 \
    -include_plaintext_passkey 0 
	
puts "Exported job file successfully\n"
puts "Full design flow passed execution\n"	
