# Creating SmartDesign "uart_block"
set sd_name {uart_block}
create_smartdesign -sd_name ${sd_name}

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

# Create top level Scalar 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 {EPCS_RX_VAL} -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 {rx_error} -port_direction {IN}
sd_create_scalar_port -sd_name ${sd_name} -port_name {rx_lock} -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 {clear} -port_direction {OUT}
sd_create_scalar_port -sd_name ${sd_name} -port_name {connect_o} -port_direction {OUT}
sd_create_scalar_port -sd_name ${sd_name} -port_name {genrate_err} -port_direction {OUT}
sd_create_scalar_port -sd_name ${sd_name} -port_name {start} -port_direction {OUT}


# Create top level Bus Ports
sd_create_bus_port -sd_name ${sd_name} -port_name {error_count} -port_direction {IN} -port_range {[31:0]}


# Add FabUART_0 instance
sd_instantiate_hdl_module -sd_name ${sd_name} -hdl_module_name {FabUART} -hdl_file {hdl\FabUART.v} -instance_name {FabUART_0}



# Add uart_ip_0 instance
sd_instantiate_component -sd_name ${sd_name} -component_name {uart_ip} -instance_name {uart_ip_0}
sd_connect_pins_to_constant -sd_name ${sd_name} -pin_names {uart_ip_0:BIT8} -value {VCC}
sd_connect_pins_to_constant -sd_name ${sd_name} -pin_names {uart_ip_0:CSN} -value {GND}
sd_connect_pins_to_constant -sd_name ${sd_name} -pin_names {uart_ip_0:ODD_N_EVEN} -value {GND}
sd_connect_pins_to_constant -sd_name ${sd_name} -pin_names {uart_ip_0:PARITY_EN} -value {GND}
sd_connect_pins_to_constant -sd_name ${sd_name} -pin_names {uart_ip_0:BAUD_VAL} -value {0001100101100}
sd_connect_pins_to_constant -sd_name ${sd_name} -pin_names {uart_ip_0:BAUD_VAL_FRACTION} -value {110}



# Add scalar net connections
sd_connect_pins -sd_name ${sd_name} -pin_names {"CLK" "FabUART_0:clk" "uart_ip_0:CLK" }
sd_connect_pins -sd_name ${sd_name} -pin_names {"EPCS_RX_VAL" "FabUART_0:rx_val" }
sd_connect_pins -sd_name ${sd_name} -pin_names {"FabUART_0:clear" "clear" }
sd_connect_pins -sd_name ${sd_name} -pin_names {"FabUART_0:connect_o" "connect_o" }
sd_connect_pins -sd_name ${sd_name} -pin_names {"FabUART_0:genrate_err" "genrate_err" }
sd_connect_pins -sd_name ${sd_name} -pin_names {"FabUART_0:reset" "RESET_N" "uart_ip_0:RESET_N" }
sd_connect_pins -sd_name ${sd_name} -pin_names {"FabUART_0:rx_error" "rx_error" }
sd_connect_pins -sd_name ${sd_name} -pin_names {"FabUART_0:rx_lock" "rx_lock" }
sd_connect_pins -sd_name ${sd_name} -pin_names {"FabUART_0:start" "start" }
sd_connect_pins -sd_name ${sd_name} -pin_names {"FabUART_0:uart_oen" "uart_ip_0:OEN" }
sd_connect_pins -sd_name ${sd_name} -pin_names {"FabUART_0:uart_rxrdy" "uart_ip_0:RXRDY" }
sd_connect_pins -sd_name ${sd_name} -pin_names {"FabUART_0:uart_txrdy" "uart_ip_0:TXRDY" }
sd_connect_pins -sd_name ${sd_name} -pin_names {"FabUART_0:uart_wen" "uart_ip_0:WEN" }
sd_connect_pins -sd_name ${sd_name} -pin_names {"RX" "uart_ip_0:RX" }
sd_connect_pins -sd_name ${sd_name} -pin_names {"TX" "uart_ip_0:TX" }

# Add bus net connections
sd_connect_pins -sd_name ${sd_name} -pin_names {"FabUART_0:error_count" "error_count" }
sd_connect_pins -sd_name ${sd_name} -pin_names {"FabUART_0:uart_data_in" "uart_ip_0:DATA_OUT" }
sd_connect_pins -sd_name ${sd_name} -pin_names {"FabUART_0:uart_data_out" "uart_ip_0:DATA_IN" }


# 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 "uart_block"
generate_component -component_name ${sd_name}
