# Creating SmartDesign DATA_HANDLE
set sd_name {DATA_HANDLE}
create_smartdesign -sd_name ${sd_name}

# Disable auto promotion of pins of type 'pad'
auto_promote_pad_pins -promote_all 0

# Create top level Ports
sd_create_scalar_port -sd_name ${sd_name} -port_name {CLK} -port_direction {IN}
sd_create_scalar_port -sd_name ${sd_name} -port_name {RESET_N} -port_direction {IN}
sd_create_scalar_port -sd_name ${sd_name} -port_name {RX} -port_direction {IN}
sd_create_scalar_port -sd_name ${sd_name} -port_name {TX} -port_direction {OUT}
sd_create_scalar_port -sd_name ${sd_name} -port_name {SYNC_N} -port_direction {IN}
sd_create_scalar_port -sd_name ${sd_name} -port_name {ALIGNED} -port_direction {IN}
sd_create_scalar_port -sd_name ${sd_name} -port_name {CGS_ERR} -port_direction {IN}
sd_create_scalar_port -sd_name ${sd_name} -port_name {LINK_CD_ERR} -port_direction {IN}
sd_create_scalar_port -sd_name ${sd_name} -port_name {UCC_ERR} -port_direction {IN}
sd_create_scalar_port -sd_name ${sd_name} -port_name {DATA_ERR} -port_direction {IN}
sd_create_scalar_port -sd_name ${sd_name} -port_name {EPCS_0_RX_VAL} -port_direction {IN}
sd_create_scalar_port -sd_name ${sd_name} -port_name {DATA_WEN} -port_direction {OUT}
sd_create_scalar_port -sd_name ${sd_name} -port_name {P_W_SEL} -port_direction {OUT}
sd_create_scalar_port -sd_name ${sd_name} -port_name {ERR_EN} -port_direction {OUT}
sd_create_scalar_port -sd_name ${sd_name} -port_name {LINK_ERR_EN} -port_direction {OUT}

sd_create_bus_port -sd_name ${sd_name} -port_name {JESD_RDATA} -port_direction {IN} -port_range {[31:0]}
sd_create_bus_port -sd_name ${sd_name} -port_name {DOUT_RDATA} -port_direction {IN} -port_range {[31:0]}
sd_create_bus_port -sd_name ${sd_name} -port_name {NIT_ERR} -port_direction {IN} -port_range {[3:0]}
sd_create_bus_port -sd_name ${sd_name} -port_name {DISP_ERR} -port_direction {IN} -port_range {[3:0]}
sd_create_bus_port -sd_name ${sd_name} -port_name {ERR_NO} -port_direction {IN} -port_range {[4:0]}
sd_create_bus_port -sd_name ${sd_name} -port_name {DATA_WADDR} -port_direction {OUT} -port_range {[9:0]}
sd_create_bus_port -sd_name ${sd_name} -port_name {R_ADDR} -port_direction {OUT} -port_range {[9:0]}
sd_create_bus_port -sd_name ${sd_name} -port_name {STATUS_OUT} -port_direction {OUT} -port_range {[31:0]}
sd_create_bus_port -sd_name ${sd_name} -port_name {PRBS_SEL} -port_direction {OUT} -port_range {[1:0]}

# Add CORE_UART_0_0 instance
sd_instantiate_component -sd_name ${sd_name} -component_name {CORE_UART_0} -instance_name {CORE_UART_0_0}
sd_connect_pins_to_constant -sd_name ${sd_name} -pin_names {CORE_UART_0_0:BIT8} -value {VCC}
sd_connect_pins_to_constant -sd_name ${sd_name} -pin_names {CORE_UART_0_0:CSN} -value {GND}
sd_connect_pins_to_constant -sd_name ${sd_name} -pin_names {CORE_UART_0_0:ODD_N_EVEN} -value {GND}
sd_mark_pins_unused -sd_name ${sd_name} -pin_names {CORE_UART_0_0:OVERFLOW}
sd_connect_pins_to_constant -sd_name ${sd_name} -pin_names {CORE_UART_0_0:PARITY_EN} -value {GND}
sd_mark_pins_unused -sd_name ${sd_name} -pin_names {CORE_UART_0_0:PARITY_ERR}
sd_mark_pins_unused -sd_name ${sd_name} -pin_names {CORE_UART_0_0:FRAMING_ERR}
sd_connect_pins_to_constant -sd_name ${sd_name} -pin_names {CORE_UART_0_0:BAUD_VAL} -value {0000001000010}
sd_connect_pins_to_constant -sd_name ${sd_name} -pin_names {CORE_UART_0_0:BAUD_VAL_FRACTION} -value {110}



# Add UART_IF_0 instance
sd_instantiate_hdl_module -sd_name ${sd_name} -hdl_module_name {UART_IF} -hdl_file {hdl\uart_if.v} -instance_name {UART_IF_0}



# Add scalar net connections
sd_connect_pins -sd_name ${sd_name} -pin_names {"UART_IF_0:ALIGNED" "ALIGNED" }
sd_connect_pins -sd_name ${sd_name} -pin_names {"UART_IF_0:CGS_ERR" "CGS_ERR" }
sd_connect_pins -sd_name ${sd_name} -pin_names {"CORE_UART_0_0:CLK" "UART_IF_0:CLK" "CLK" }
sd_connect_pins -sd_name ${sd_name} -pin_names {"CORE_UART_0_0:RXRDY" "UART_IF_0:RX_RDY" }
sd_connect_pins -sd_name ${sd_name} -pin_names {"CORE_UART_0_0:TXRDY" "UART_IF_0:TX_RDY" }
sd_connect_pins -sd_name ${sd_name} -pin_names {"UART_IF_0:DATA_ERR" "DATA_ERR" }
sd_connect_pins -sd_name ${sd_name} -pin_names {"UART_IF_0:DATA_WEN" "DATA_WEN" }
sd_connect_pins -sd_name ${sd_name} -pin_names {"UART_IF_0:EPCS_0_RX_VAL" "EPCS_0_RX_VAL" }
sd_connect_pins -sd_name ${sd_name} -pin_names {"UART_IF_0:ERR_EN" "ERR_EN" }
sd_connect_pins -sd_name ${sd_name} -pin_names {"UART_IF_0:LINK_CD_ERR" "LINK_CD_ERR" }
sd_connect_pins -sd_name ${sd_name} -pin_names {"UART_IF_0:LINK_ERR_EN" "LINK_ERR_EN" }
sd_connect_pins -sd_name ${sd_name} -pin_names {"UART_IF_0:P_W_SEL" "P_W_SEL" }
sd_connect_pins -sd_name ${sd_name} -pin_names {"CORE_UART_0_0:RESET_N" "UART_IF_0:RESET_N" "RESET_N" }
sd_connect_pins -sd_name ${sd_name} -pin_names {"CORE_UART_0_0:RX" "RX" }
sd_connect_pins -sd_name ${sd_name} -pin_names {"UART_IF_0:SYNC_N" "SYNC_N" }
sd_connect_pins -sd_name ${sd_name} -pin_names {"CORE_UART_0_0:TX" "TX" }
sd_connect_pins -sd_name ${sd_name} -pin_names {"CORE_UART_0_0:OEN" "UART_IF_0:OEN" }
sd_connect_pins -sd_name ${sd_name} -pin_names {"CORE_UART_0_0:WEN" "UART_IF_0:WEN" }
sd_connect_pins -sd_name ${sd_name} -pin_names {"UART_IF_0:UCC_ERR" "UCC_ERR" }

# Add bus net connections
sd_connect_pins -sd_name ${sd_name} -pin_names {"CORE_UART_0_0:DATA_OUT" "UART_IF_0:DATA_IN" }
sd_connect_pins -sd_name ${sd_name} -pin_names {"UART_IF_0:DATA_WADDR" "DATA_WADDR" }
sd_connect_pins -sd_name ${sd_name} -pin_names {"UART_IF_0:DISP_ERR" "DISP_ERR" }
sd_connect_pins -sd_name ${sd_name} -pin_names {"UART_IF_0:DOUT_RDATA" "DOUT_RDATA" }
sd_connect_pins -sd_name ${sd_name} -pin_names {"UART_IF_0:ERR_NO" "ERR_NO" }
sd_connect_pins -sd_name ${sd_name} -pin_names {"UART_IF_0:JESD_RDATA" "JESD_RDATA" }
sd_connect_pins -sd_name ${sd_name} -pin_names {"UART_IF_0:NIT_ERR" "NIT_ERR" }
sd_connect_pins -sd_name ${sd_name} -pin_names {"UART_IF_0:PRBS_SEL" "PRBS_SEL" }
sd_connect_pins -sd_name ${sd_name} -pin_names {"UART_IF_0:R_ADDR" "R_ADDR" }
sd_connect_pins -sd_name ${sd_name} -pin_names {"UART_IF_0:STATUS_OUT" "STATUS_OUT" }
sd_connect_pins -sd_name ${sd_name} -pin_names {"CORE_UART_0_0:DATA_IN" "UART_IF_0:DATA_OUT" }


# Re-enable auto promotion of pins of type 'pad'
auto_promote_pad_pins -promote_all 1
# Save the smartDesign
save_smartdesign -sd_name ${sd_name}
# Generate SmartDesign DATA_HANDLE
generate_component -component_name ${sd_name}
