
################################################################
# This is a generated script based on design: design_1
#
# Though there are limitations about the generated script,
# the main purpose of this utility is to make learning
# IP Integrator Tcl commands easier.
################################################################

################################################################
# Check if script is running in correct Vivado version.
################################################################
set scripts_vivado_version 2015.4
set current_vivado_version [version -short]

if { [string first $scripts_vivado_version $current_vivado_version] == -1 } {
   puts ""
   puts "ERROR: This script was generated using Vivado <$scripts_vivado_version> and is being run in <$current_vivado_version> of Vivado. Please run the script in Vivado <$scripts_vivado_version> then open the design in Vivado <$current_vivado_version>. Upgrade the design by running \"Tools => Report => Report IP Status...\", then run write_bd_tcl to create an updated script."

   return 1
}

################################################################
# START
################################################################

# To test this script, run the following commands from Vivado Tcl console:
# source design_1_script.tcl

# If you do not already have a project created,
# you can create a project using the following command:
#    create_project project_1 myproj -part xc7a35tcpg236-2

# CHECKING IF PROJECT EXISTS
if { [get_projects -quiet] eq "" } {
   puts "ERROR: Please open or create a project!"
   return 1
}



# CHANGE DESIGN NAME HERE
set design_name design_1

# If you do not already have an existing IP Integrator design open,
# you can create a design using the following command:
#    create_bd_design $design_name

# Creating design if needed
set errMsg ""
set nRet 0

set cur_design [current_bd_design -quiet]
set list_cells [get_bd_cells -quiet]

if { ${design_name} eq "" } {
   # USE CASES:
   #    1) Design_name not set

   set errMsg "ERROR: Please set the variable <design_name> to a non-empty value."
   set nRet 1

} elseif { ${cur_design} ne "" && ${list_cells} eq "" } {
   # USE CASES:
   #    2): Current design opened AND is empty AND names same.
   #    3): Current design opened AND is empty AND names diff; design_name NOT in project.
   #    4): Current design opened AND is empty AND names diff; design_name exists in project.

   if { $cur_design ne $design_name } {
      puts "INFO: Changing value of <design_name> from <$design_name> to <$cur_design> since current design is empty."
      set design_name [get_property NAME $cur_design]
   }
   puts "INFO: Constructing design in IPI design <$cur_design>..."

} elseif { ${cur_design} ne "" && $list_cells ne "" && $cur_design eq $design_name } {
   # USE CASES:
   #    5) Current design opened AND has components AND same names.

   set errMsg "ERROR: Design <$design_name> already exists in your project, please set the variable <design_name> to another value."
   set nRet 1
} elseif { [get_files -quiet ${design_name}.bd] ne "" } {
   # USE CASES: 
   #    6) Current opened design, has components, but diff names, design_name exists in project.
   #    7) No opened design, design_name exists in project.

   set errMsg "ERROR: Design <$design_name> already exists in your project, please set the variable <design_name> to another value."
   set nRet 2

} else {
   # USE CASES:
   #    8) No opened design, design_name not in project.
   #    9) Current opened design, has components, but diff names, design_name not in project.

   puts "INFO: Currently there is no design <$design_name> in project, so creating one..."

   create_bd_design $design_name

   puts "INFO: Making design <$design_name> as current_bd_design."
   current_bd_design $design_name

}

puts "INFO: Currently the variable <design_name> is equal to \"$design_name\"."

if { $nRet != 0 } {
   puts $errMsg
   return $nRet
}

##################################################################
# DESIGN PROCs
##################################################################



# Procedure to create entire design; Provide argument to make
# procedure reusable. If parentCell is "", will use root.
proc create_root_design { parentCell } {

  if { $parentCell eq "" } {
     set parentCell [get_bd_cells /]
  }

  # Get object for parentCell
  set parentObj [get_bd_cells $parentCell]
  if { $parentObj == "" } {
     puts "ERROR: Unable to find parent cell <$parentCell>!"
     return
  }

  # Make sure parentObj is hier blk
  set parentType [get_property TYPE $parentObj]
  if { $parentType ne "hier" } {
     puts "ERROR: Parent <$parentObj> has TYPE = <$parentType>. Expected to be <hier>."
     return
  }

  # Save current instance; Restore later
  set oldCurInst [current_bd_instance .]

  # Set parent object as current
  current_bd_instance $parentObj


  # Create interface ports

  # Create ports
  set C_or_F [ create_bd_port -dir I C_or_F ]
  set XA1_N [ create_bd_port -dir I XA1_N ]
  set XA1_P [ create_bd_port -dir I XA1_P ]
  set clk [ create_bd_port -dir I clk ]
  set digit_select [ create_bd_port -dir O -from 7 -to 0 digit_select ]
  set dp [ create_bd_port -dir O dp ]
  set reset [ create_bd_port -dir I reset ]
  set seg [ create_bd_port -dir O -from 6 -to 0 seg ]

  # Create instance: Hex_to_7_Seg_0, and set properties
  set Hex_to_7_Seg_0 [ create_bd_cell -type ip -vlnv xilinx.com:user:Hex_to_7_Seg:1.0 Hex_to_7_Seg_0 ]

  # Create instance: Hex_to_7_Seg_1, and set properties
  set Hex_to_7_Seg_1 [ create_bd_cell -type ip -vlnv xilinx.com:user:Hex_to_7_Seg:1.0 Hex_to_7_Seg_1 ]

  # Create instance: Hex_to_7_Seg_2, and set properties
  set Hex_to_7_Seg_2 [ create_bd_cell -type ip -vlnv xilinx.com:user:Hex_to_7_Seg:1.0 Hex_to_7_Seg_2 ]

  # Create instance: Hex_to_7_Seg_3, and set properties
  set Hex_to_7_Seg_3 [ create_bd_cell -type ip -vlnv xilinx.com:user:Hex_to_7_Seg:1.0 Hex_to_7_Seg_3 ]

  # Create instance: Hex_to_7_Seg_4, and set properties
  set Hex_to_7_Seg_4 [ create_bd_cell -type ip -vlnv xilinx.com:user:Hex_to_7_Seg:1.0 Hex_to_7_Seg_4 ]

  # Create instance: Seg_Display_16_0, and set properties
  set Seg_Display_16_0 [ create_bd_cell -type ip -vlnv xilinx.com:user:Seg_Display_16:1.0 Seg_Display_16_0 ]

  # Create instance: binary_bcd_0, and set properties
  set binary_bcd_0 [ create_bd_cell -type ip -vlnv xilinx.com:user:binary_bcd:1.0 binary_bcd_0 ]

  # Create instance: microblaze_mcs_0, and set properties
  set microblaze_mcs_0 [ create_bd_cell -type ip -vlnv xilinx.com:ip:microblaze_mcs:2.3 microblaze_mcs_0 ]
  set_property -dict [ list \
CONFIG.GPI1_SIZE {16} \
CONFIG.GPI2_SIZE {1} \
CONFIG.GPO1_SIZE {7} \
CONFIG.GPO2_SIZE {16} \
CONFIG.GPO3_SIZE {7} \
CONFIG.MEMSIZE {65536} \
CONFIG.USE_GPI1 {1} \
CONFIG.USE_GPI2 {1} \
CONFIG.USE_GPO1 {1} \
CONFIG.USE_GPO2 {1} \
CONFIG.USE_GPO3 {1} \
 ] $microblaze_mcs_0

  # Create instance: xadc_address, and set properties
  set xadc_address [ create_bd_cell -type ip -vlnv xilinx.com:ip:xlconstant:1.1 xadc_address ]
  set_property -dict [ list \
CONFIG.CONST_VAL {22} \
CONFIG.CONST_WIDTH {7} \
 ] $xadc_address

  # Create instance: xadc_enable, and set properties
  set xadc_enable [ create_bd_cell -type ip -vlnv xilinx.com:ip:xlconstant:1.1 xadc_enable ]

  # Create instance: xadc_wiz_0, and set properties
  set xadc_wiz_0 [ create_bd_cell -type ip -vlnv xilinx.com:ip:xadc_wiz:3.2 xadc_wiz_0 ]
  set_property -dict [ list \
CONFIG.ADC_CONVERSION_RATE {200} \
CONFIG.ENABLE_CALIBRATION_AVERAGING {false} \
CONFIG.ENABLE_EXTERNAL_MUX {true} \
CONFIG.ENABLE_RESET {true} \
CONFIG.EXTERNAL_MUX_CHANNEL {VAUXP6_VAUXN6} \
CONFIG.INTERFACE_SELECTION {ENABLE_DRP} \
CONFIG.OT_ALARM {false} \
CONFIG.SINGLE_CHANNEL_SELECTION {VAUXP6_VAUXN6} \
CONFIG.USER_TEMP_ALARM {false} \
CONFIG.VCCAUX_ALARM {false} \
CONFIG.VCCINT_ALARM {false} \
 ] $xadc_wiz_0

  # Create instance: xlconstant_0, and set properties
  set xlconstant_0 [ create_bd_cell -type ip -vlnv xilinx.com:ip:xlconstant:1.1 xlconstant_0 ]
  set_property -dict [ list \
CONFIG.CONST_VAL {28} \
CONFIG.CONST_WIDTH {7} \
 ] $xlconstant_0

  # Create port connections
  connect_bd_net -net C_or_F_1 [get_bd_ports C_or_F] [get_bd_pins microblaze_mcs_0/GPI2]
  connect_bd_net -net Hex_to_7_Seg_0_seven_seg [get_bd_pins Hex_to_7_Seg_0/seven_seg] [get_bd_pins Seg_Display_16_0/digit_6]
  connect_bd_net -net Hex_to_7_Seg_1_seven_seg [get_bd_pins Hex_to_7_Seg_1/seven_seg] [get_bd_pins Seg_Display_16_0/digit_5]
  connect_bd_net -net Hex_to_7_Seg_2_seven_seg [get_bd_pins Hex_to_7_Seg_2/seven_seg] [get_bd_pins Seg_Display_16_0/digit_4]
  connect_bd_net -net Hex_to_7_Seg_3_seven_seg [get_bd_pins Hex_to_7_Seg_3/seven_seg] [get_bd_pins Seg_Display_16_0/digit_3]
  connect_bd_net -net Hex_to_7_Seg_4_seven_seg [get_bd_pins Hex_to_7_Seg_4/seven_seg] [get_bd_pins Seg_Display_16_0/digit_2]
  connect_bd_net -net Seg_Display_16_0_an [get_bd_ports digit_select] [get_bd_pins Seg_Display_16_0/an]
  connect_bd_net -net Seg_Display_16_0_dp [get_bd_ports dp] [get_bd_pins Seg_Display_16_0/dp]
  connect_bd_net -net Seg_Display_16_0_seg [get_bd_ports seg] [get_bd_pins Seg_Display_16_0/seg]
  connect_bd_net -net XA1_N_1 [get_bd_ports XA1_N] [get_bd_pins xadc_wiz_0/vauxn6]
  connect_bd_net -net XA1_P_1 [get_bd_ports XA1_P] [get_bd_pins xadc_wiz_0/vauxp6]
  connect_bd_net -net binary_bcd_0_bcd0 [get_bd_pins Hex_to_7_Seg_0/hex] [get_bd_pins binary_bcd_0/bcd0]
  connect_bd_net -net binary_bcd_0_bcd1 [get_bd_pins Hex_to_7_Seg_1/hex] [get_bd_pins binary_bcd_0/bcd1]
  connect_bd_net -net binary_bcd_0_bcd2 [get_bd_pins Hex_to_7_Seg_2/hex] [get_bd_pins binary_bcd_0/bcd2]
  connect_bd_net -net binary_bcd_0_bcd3 [get_bd_pins Hex_to_7_Seg_3/hex] [get_bd_pins binary_bcd_0/bcd3]
  connect_bd_net -net binary_bcd_0_bcd4 [get_bd_pins Hex_to_7_Seg_4/hex] [get_bd_pins binary_bcd_0/bcd4]
  connect_bd_net -net clk_1 [get_bd_ports clk] [get_bd_pins Seg_Display_16_0/clk] [get_bd_pins binary_bcd_0/clk] [get_bd_pins microblaze_mcs_0/Clk] [get_bd_pins xadc_wiz_0/dclk_in]
  connect_bd_net -net microblaze_mcs_0_GPO1 [get_bd_pins Seg_Display_16_0/digit_1] [get_bd_pins microblaze_mcs_0/GPO1]
  connect_bd_net -net microblaze_mcs_0_GPO2 [get_bd_pins binary_bcd_0/binary_in] [get_bd_pins microblaze_mcs_0/GPO2]
  connect_bd_net -net microblaze_mcs_0_GPO3 [get_bd_pins Seg_Display_16_0/digit_8] [get_bd_pins microblaze_mcs_0/GPO3]
  connect_bd_net -net reset_1 [get_bd_ports reset] [get_bd_pins binary_bcd_0/reset] [get_bd_pins microblaze_mcs_0/Reset] [get_bd_pins xadc_wiz_0/reset_in]
  connect_bd_net -net xadc_address_dout [get_bd_pins xadc_address/dout] [get_bd_pins xadc_wiz_0/daddr_in]
  connect_bd_net -net xadc_enable_dout [get_bd_pins xadc_enable/dout] [get_bd_pins xadc_wiz_0/den_in]
  connect_bd_net -net xadc_wiz_0_do_out [get_bd_pins microblaze_mcs_0/GPI1] [get_bd_pins xadc_wiz_0/do_out]
  connect_bd_net -net xlconstant_0_dout [get_bd_pins Seg_Display_16_0/digit_7] [get_bd_pins xlconstant_0/dout]

  # Create address segments

  # Perform GUI Layout
  regenerate_bd_layout -layout_string {
   guistr: "# # String gsaved with Nlview 6.5.5  2015-06-26 bk=1.3371 VDI=38 GEI=35 GUI=JA:1.6
#  -string -flagsOSRD
preplace port XA1_N -pg 1 -y 480 -defaultsOSRD
preplace port XA1_P -pg 1 -y 500 -defaultsOSRD
preplace port dp -pg 1 -y 300 -defaultsOSRD
preplace port C_or_F -pg 1 -y 270 -defaultsOSRD
preplace port clk -pg 1 -y 120 -defaultsOSRD
preplace port reset -pg 1 -y 140 -defaultsOSRD
preplace portBus digit_select -pg 1 -y 320 -defaultsOSRD
preplace portBus seg -pg 1 -y 280 -defaultsOSRD
preplace inst microblaze_mcs_0 -pg 1 -lvl 1 -y 130 -defaultsOSRD
preplace inst xlconstant_0 -pg 1 -lvl 4 -y 460 -defaultsOSRD
preplace inst Hex_to_7_Seg_0 -pg 1 -lvl 4 -y 380 -defaultsOSRD
preplace inst xadc_wiz_0 -pg 1 -lvl 2 -y 420 -defaultsOSRD
preplace inst Hex_to_7_Seg_1 -pg 1 -lvl 4 -y 300 -defaultsOSRD
preplace inst xadc_enable -pg 1 -lvl 1 -y 400 -defaultsOSRD
preplace inst Hex_to_7_Seg_2 -pg 1 -lvl 4 -y 220 -defaultsOSRD
preplace inst Hex_to_7_Seg_3 -pg 1 -lvl 4 -y 140 -defaultsOSRD
preplace inst Hex_to_7_Seg_4 -pg 1 -lvl 4 -y 60 -defaultsOSRD
preplace inst binary_bcd_0 -pg 1 -lvl 3 -y 240 -defaultsOSRD
preplace inst Seg_Display_16_0 -pg 1 -lvl 5 -y 300 -defaultsOSRD
preplace inst xadc_address -pg 1 -lvl 1 -y 320 -defaultsOSRD
preplace netloc Hex_to_7_Seg_2_seven_seg 1 4 1 NJ
preplace netloc Seg_Display_16_0_seg 1 5 1 NJ
preplace netloc microblaze_mcs_0_GPO1 1 1 4 NJ 70 NJ 10 NJ 10 1040
preplace netloc microblaze_mcs_0_GPO2 1 1 2 NJ 140 550
preplace netloc microblaze_mcs_0_GPO3 1 1 4 250 250 NJ 350 NJ 510 NJ
preplace netloc Hex_to_7_Seg_3_seven_seg 1 4 1 NJ
preplace netloc binary_bcd_0_bcd0 1 3 1 810
preplace netloc Seg_Display_16_0_dp 1 5 1 NJ
preplace netloc binary_bcd_0_bcd1 1 3 1 800
preplace netloc Hex_to_7_Seg_0_seven_seg 1 4 1 NJ
preplace netloc clk_1 1 0 5 30 510 270 230 560 520 NJ 520 NJ
preplace netloc xlconstant_0_dout 1 4 1 NJ
preplace netloc binary_bcd_0_bcd2 1 3 1 N
preplace netloc XA1_N_1 1 0 2 NJ 480 NJ
preplace netloc C_or_F_1 1 0 2 NJ 270 230
preplace netloc Hex_to_7_Seg_4_seven_seg 1 4 1 NJ
preplace netloc binary_bcd_0_bcd3 1 3 1 790
preplace netloc binary_bcd_0_bcd4 1 3 1 780
preplace netloc XA1_P_1 1 0 2 NJ 500 NJ
preplace netloc Seg_Display_16_0_an 1 5 1 NJ
preplace netloc Hex_to_7_Seg_1_seven_seg 1 4 1 NJ
preplace netloc reset_1 1 0 3 20 520 240 240 NJ
preplace netloc xadc_address_dout 1 1 1 NJ
preplace netloc xadc_enable_dout 1 1 1 NJ
preplace netloc xadc_wiz_0_do_out 1 1 1 260
levelinfo -pg 1 0 130 410 670 910 1130 1240 -top 0 -bot 590
",
}

  # Restore current instance
  current_bd_instance $oldCurInst

  save_bd_design
}
# End of create_root_design()


##################################################################
# MAIN FLOW
##################################################################

create_root_design ""


