# Creating SmartDesign "uart_interface"
set sd_name {uart_interface}
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 {RESET_N} -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 {RX_VAL} -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 {clear} -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}
sd_mark_pins_unused -sd_name ${sd_name} -pin_names {FabUART_0:switch}
sd_mark_pins_unused -sd_name ${sd_name} -pin_names {FabUART_0:connect_o}
sd_mark_pins_unused -sd_name ${sd_name} -pin_names {FabUART_0:timer_switch}



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



# Add scalar net connections
sd_connect_pins -sd_name ${sd_name} -pin_names {"CLK" "FabUART_0:clk" "UART_core_0:CLK" }
sd_connect_pins -sd_name ${sd_name} -pin_names {"FabUART_0:clear" "clear" }
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_core_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:rx_val" "RX_VAL" }
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_core_0:OEN" }
sd_connect_pins -sd_name ${sd_name} -pin_names {"FabUART_0:uart_rxrdy" "UART_core_0:RXRDY" }
sd_connect_pins -sd_name ${sd_name} -pin_names {"FabUART_0:uart_txrdy" "UART_core_0:TXRDY" }
sd_connect_pins -sd_name ${sd_name} -pin_names {"FabUART_0:uart_wen" "UART_core_0:WEN" }
sd_connect_pins -sd_name ${sd_name} -pin_names {"RX" "UART_core_0:RX" }
sd_connect_pins -sd_name ${sd_name} -pin_names {"TX" "UART_core_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_core_0:DATA_OUT" }
sd_connect_pins -sd_name ${sd_name} -pin_names {"FabUART_0:uart_data_out" "UART_core_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_interface"
generate_component -component_name ${sd_name}
