<?xml version="1.0"?>
<lsccip:ip version="1.0"
    xmlns:lsccip="http://www.latticesemi.com/XMLSchema/Radiant/ip"
    xmlns:xi="http://www.w3.org/2001/XInclude"> 

  <lsccip:general>
    <lsccip:vendor>latticesemi.com</lsccip:vendor>
    <lsccip:library>ip</lsccip:library>
    <lsccip:name>uart</lsccip:name>
    <lsccip:display_name>UART</lsccip:display_name>
    <lsccip:version>1.6.0</lsccip:version>
    <lsccip:category>Processors_Controllers_and_Peripherals</lsccip:category>
	<lsccip:keywords>BusType_APB</lsccip:keywords>	
    <lsccip:min_radiant_version>2.0</lsccip:min_radiant_version>
    <lsccip:min_esi_version>1.1</lsccip:min_esi_version>
    <lsccip:supported_products>
      <lsccip:supported_family name="*"/>
    </lsccip:supported_products>
	<lsccip:supported_platforms>
      <lsccip:supported_platform name="esi" />
	  <lsccip:supported_platform name="radiant" />
    </lsccip:supported_platforms>
  </lsccip:general>

  <lsccip:settings>
    <!-- General -->
    <lsccip:setting id                 = "APB_ENABLE"
                    type               = "param"
                    conn_mod           = "lscc_uart"
                    value_type         = "bool"
                    title              = "Enable APB"
                    default            = "True"
                    editable           = "False"
                    group1             = "General"
    />	
		   
    <lsccip:setting id                 = "SYS_CLOCK_FREQ"
                    type               = "param"
                    conn_mod           = "lscc_uart"
                    value_type         = "float"
                    title              = "System Clock Frequency (MHz)"
                    value_range        = "(2, 200)"
                    default            = "50"
                    group1             = "General"
    />

    <lsccip:setting id                 = "LCR_DATA_BITS"
                    type               = "param"
                    conn_mod           = "lscc_uart"
                    value_type         = "int"
                    title              = "Serial Data Width"
                    options            = "[5, 6, 7, 8]"
                    default            = "8"
                    group1             = "General"
    />

    <lsccip:setting id                 = "LCR_STOP_BITS"
                    type               = "param"
                    conn_mod           = "lscc_uart"
                    value_type         = "int"
                    title              = "Stop Bits"
                    options            = "[1, 2]"
                    default            = "1"
                    group1             = "General"
    />

    <lsccip:setting id                 = "FAMILY"
                    type               = "input"
                    conn_mod           = "lscc_uart"
                    value_type         = "string"
                    title              = "Device Architecture"
                    default            = "iCE40UP"
                    value_expr         = "runtime_info.device_info.architecture(1)"
                    editable           = "False"
                    group1             = "General"
                    hidden             = "True"
    />

    <!-- Parity -->
    <lsccip:setting id                 = "LCR_PARITY_ENABLE_IN"
                    type               = "input"
                    conn_mod           = "lscc_uart"
                    value_type         = "bool"
                    title              = "Parity Enable"
                    default            = "False"
                    group1             = "General"
    />

    <lsccip:setting id                 = "LCR_PARITY_ENABLE"
                    type               = "param"
                    conn_mod           = "lscc_uart"
                    value_type         = "int"
                    value_expr         = "1 if(LCR_PARITY_ENABLE_IN) else 0"
                    title              = "Parity Enable"
                    default            = "0"
                    hidden             = "True"
                    editable           = "False"
                    group1             = "General"
    />

    <lsccip:setting id                 = "LCR_PARITY_ODD_IN"
                    type               = "input"
                    conn_mod           = "lscc_uart"
                    value_type         = "bool"
                    title              = "ODD Parity"
                    default            = "False"
                    editable           = "LCR_PARITY_ENABLE_IN"
                    group1             = "General"
    />

    <lsccip:setting id                 = "LCR_PARITY_ODD"
                    type               = "param"
                    conn_mod           = "lscc_uart"
                    value_type         = "int"
                    value_expr         = "1 if(LCR_PARITY_ODD_IN) else 0"
                    title              = "ODD Parity"
                    default            = "0"
                    hidden             = "True"
                    editable           = "False"
                    group1             = "General"
    />

    <lsccip:setting id                 = "LCR_PARITY_STICK_IN"
                    type               = "input"
                    conn_mod           = "lscc_uart"
                    value_type         = "bool"
                    title              = "Enable Stick Parity"
                    default            = "False"
                    editable           = "LCR_PARITY_ENABLE"
                    group1             = "General"
    />

    <lsccip:setting id                 = "LCR_PARITY_STICK"
                    type               = "param"
                    conn_mod           = "lscc_uart"
                    value_type         = "int"
                    value_expr         = "1 if(LCR_PARITY_STICK_IN) else 0"
                    title              = "Enable Stick Parity"
                    default            = "0"
                    hidden             = "True"
                    editable           = "False"
                    group1             = "General"
    />

    <!-- Baud Rate -->
    <lsccip:setting id                 = "BAUD_RATE_TYPE"
                    type               = "input"
                    conn_mod           = "lscc_uart"
                    value_type         = "string"
                    title              = "Baud Rate Type"
                    options            = "['Standard', 'Custom']"
                    default            = "Standard"
                    group1             = "Baud Rate"
    />

    <lsccip:setting id                 = "STANDARD_BAUD_RATE"
                    type               = "input"
                    conn_mod           = "lscc_uart"
                    value_type         = "int"
                    title              = "UART Standard Baud Rate"
                    options            = "[2400, 4800, 9600, 14400, 19200, 28800, 38400, 56000, 57600, 115200]"
                    drc                = "ext_check_baud_rate(SYS_CLOCK_FREQ, STANDARD_BAUD_RATE, 'Standard')"
                    default            = "115200"
                    editable           = "BAUD_RATE_TYPE == 'Standard'"
                    group1             = "Baud Rate"
    />

    <lsccip:setting id                 = "CUSTOM_BAUD_RATE"
                    type               = "input"
                    conn_mod           = "lscc_uart"
                    value_type         = "int"
                    title              = "UART Custom Baud Rate"
                    value_range        = "(2400, 1000000)"
                    drc                = "ext_check_baud_rate(SYS_CLOCK_FREQ, CUSTOM_BAUD_RATE, 'Custom')"
                    default            = "115200"
                    editable           = "BAUD_RATE_TYPE == 'Custom'"
                    group1             = "Baud Rate"
    />

    <lsccip:setting id                 = "BAUD_RATE"
                    type               = "param"
                    conn_mod           = "lscc_uart"
                    value_type         = "int"
                    value_expr         = "CUSTOM_BAUD_RATE if(BAUD_RATE_TYPE=='CUSTOM') else STANDARD_BAUD_RATE"
                    hidden             = "True"
                    editable           = "False"
                    group1             = "Baud Rate"
    />
    
    <lsccip:setting id                 = "CLK_DIVISOR"
                    type               = "param"
                    conn_mod           = "lscc_uart"
                    value_type         = "int"
                    value_expr         = "int((SYS_CLOCK_FREQ * 1000000) / BAUD_RATE)"
                    hidden             = "True"
                    editable           = "False"
                    group1             = "Baud Rate"
    />
    
    <lsccip:setting id                 = "FIFO"
                    type               = "param"
                    conn_mod           = "lscc_uart"
                    value_type         = "bool"
                    title              = "FIFO Enable"
                    default            = "False"                   
                    group1             = "UART Feature Enables"
    />    

    <!-- <lsccip:setting id                 = "FIFO"
                    type               = "param"
                    conn_mod           = "lscc_uart"
                    value_type         = "bool"
                    title              = "FIFO Enable"
                    default            = "False"
                    hidden             = "True if FAMILY=='LFMXO4' else False"                    
                    group1             = "UART Feature Enables"
    /> -->
    
    <lsccip:setting id                 = "MODEM_ENA"
                    type               = "param"
                    conn_mod           = "lscc_uart"
                    value_type         = "bool"
                    title              = "MODEM Enable"
                    default            = "False"
                    editable           = "False"
                    group1             = "UART Feature Enables"
    />
    
    <lsccip:setting id                 = "RXRDY_ENA"
                    type               = "input"
                    conn_mod           = "lscc_uart"
                    value_type         = "bool"
                    title              = "Rx Ready Enable"
                    default            = "False"
                    group1             = "UART Feature Enables"
    />
    
    <lsccip:setting id                 = "TXRDY_ENA"
                    type               = "input"
                    conn_mod           = "lscc_uart"
                    value_type         = "bool"
                    title              = "Tx Ready Enable"
                    default            = "False"
                    group1             = "UART Feature Enables"
    />

  </lsccip:settings>

  <lsccip:ports>
    <!-- Modem Lines -->
    <lsccip:port name       = "rts_n_o"
                 dir        = "out"
                 conn_mod   = "lscc_uart"
                 dangling   = "not MODEM_ENA"
                 conn_port  = "RTS_N"
    />

    <lsccip:port name       = "dtr_n_o"
                 dir        = "out"
                 conn_mod   = "lscc_uart"
                 dangling   = "not MODEM_ENA"
                 conn_port  = "DTR_N"
    />

    <lsccip:port name       = "dsr_n_i"
                 dir        = "in"
                 conn_mod   = "lscc_uart"
                 stick_low  = "not MODEM_ENA"
                 conn_port  = "DSR_N"
    />

    <lsccip:port name       = "dcd_n_i"
                 dir        = "in"
                 conn_mod   = "lscc_uart"
                 stick_high = "not MODEM_ENA"
                 conn_port  = "DCD_N"
    />

    <lsccip:port name       = "cts_n_i"
                 dir        = "in"
                 conn_mod   = "lscc_uart"
                 stick_low  = "not MODEM_ENA"
                 conn_port  = "CTS_N"
    />

    <lsccip:port name       = "ri_n_i"
                 dir        = "in"
                 conn_mod   = "lscc_uart"
                 stick_high = "not MODEM_ENA"
                 conn_port  = "RI_N"
    />

    <!-- Serial I/O Lines -->
    <lsccip:port name       = "rxd_i"
                 dir        = "in"
                 conn_mod   = "lscc_uart"
                 conn_port  = "SIN"
    />

    <lsccip:port name       = "txd_o"
                 dir        = "out"
                 conn_mod   = "lscc_uart"
                 conn_port  = "SOUT"
    />
    
    <lsccip:port name       = "clk_i"
                 dir        = "in"
                 conn_mod   = "lscc_uart"
                 conn_port  = "pclk"
                 extension = "clock_param='SYS_CLOCK_FREQ'"
				 port_type  = "clock"
    />

    <lsccip:port name       = "rst_n_i"
                 dir        = "in"
                 conn_mod   = "lscc_uart"
                 conn_port  = "presetn"
				 port_type  = "reset"
    />
    <!-- LMMI Interface -->
<!--
    <lsccip:port name       = "lmmi_request_i"
                 dir        = "in"
                 conn_mod   = "lscc_uart"
                 conn_port  = "lmmi_request_i"
				 stick_low  = "APB_ENABLE == 1" 
    />

    <lsccip:port name       = "lmmi_wr_rdn_i"
                 dir        = "in"
                 conn_mod   = "lscc_uart"
                 conn_port  = "lmmi_wr_rdn_i"
				 stick_low  = "APB_ENABLE == 1" 
    />

    <lsccip:port name       = "lmmi_offset_i"
                 dir        = "in"
                 conn_mod   = "lscc_uart"
                 conn_port  = "lmmi_offset_i"
                 range      = "(3, 0)"
				 stick_low  = "APB_ENABLE == 1" 
    />

    <lsccip:port name       = "lmmi_wdata_i"
                 dir        = "in"
                 conn_mod   = "lscc_uart"
                 conn_port  = "lmmi_wdata_i"
                 range      = "(7, 0)"
				 stick_low  = "APB_ENABLE == 1" 
    />

    <lsccip:port name       = "lmmi_ready_o"
                 dir        = "out"
                 conn_mod   = "lscc_uart"
                 conn_port  = "lmmi_ready_o"
				 dangling   = "APB_ENABLE == 1" 
    />
    <lsccip:port name       = "lmmi_rdata_o"
                 dir        = "out"
                 conn_mod   = "lscc_uart"
                 conn_port  = "lmmi_rdata_o"
                 range      = "(7, 0)"
				 dangling   = "APB_ENABLE == 1" 
    />

    <lsccip:port name       = "lmmi_rdata_valid_o"
                 dir        = "out"
                 conn_mod   = "lscc_uart"
                 conn_port  = "lmmi_rdata_valid_o"
				 dangling   = "APB_ENABLE == 1" 
    />
-->
                               
    <!-- LINTR output -->      
    <lsccip:port name          = "int_o"
                 dir           = "out"
                 conn_mod      = "lscc_uart"
                 conn_port     = "INTR"
                 bus_interface = "INT_M0"
    />
    
    <!-- APB inputs -->     
    <lsccip:port name          = "apb_penable_i"
                 dir           = "in"
                 conn_mod      = "lscc_uart"
                 conn_port     = "apb_penable_i"
                 stick_low     = "not APB_ENABLE"
                 bus_interface = "APB_S0"
    />  
    
    <lsccip:port name          = "apb_psel_i"
                 dir           = "in"
                 conn_mod      = "lscc_uart"
                 conn_port     = "apb_psel_i"
                 stick_low     = "not APB_ENABLE"
                 bus_interface = "APB_S0"
    />  
    
    <lsccip:port name          = "apb_pwrite_i"
                 dir           = "in"
                 conn_mod      = "lscc_uart"
                 conn_port     = "apb_pwrite_i"
                 stick_low     = "not APB_ENABLE"
                 bus_interface = "APB_S0"
    />  
    
    <lsccip:port name          = "apb_paddr_i"
                 dir           = "in"
                 conn_mod      = "lscc_uart"
                 conn_port     = "apb_paddr_i"
                 range         = "(5, 0)"
                 stick_low     = "not APB_ENABLE"
                 bus_interface = "APB_S0"
    />  
    
    <lsccip:port name          = "apb_pwdata_i"
                 dir           = "in"
                 conn_mod      = "lscc_uart"
                 conn_port     = "apb_pwdata_i"
                 range         = "(31, 0)"
                 stick_low     = "not APB_ENABLE"
                 bus_interface = "APB_S0"
    />  

    <!-- APB outputs -->    
    <lsccip:port name          = "apb_pready_o"
                 dir           = "out"
                 conn_mod      = "lscc_uart"
                 conn_port     = "apb_pready_o"
                 dangling      = "not APB_ENABLE"
                 bus_interface = "APB_S0"
    />  
    
    <lsccip:port name          = "apb_pslverr_o"
                 dir           = "out"
                 conn_mod      = "lscc_uart"
                 conn_port     = "apb_pslverr_o"
                 dangling      = "not APB_ENABLE"
                 bus_interface = "APB_S0"
    />
    
    <lsccip:port name          = "apb_prdata_o"
                 dir           = "out"
                 conn_mod      = "lscc_uart"
                 conn_port     = "apb_prdata_o"
                 range         = "(31, 0)"
                 dangling      = "not APB_ENABLE"
                 bus_interface = "APB_S0"
    />  
    
    <!-- Auxiliary Signals  -->
    <lsccip:port name       = "rx_ready_n_o"
                 dir        = "out"
                 conn_mod   = "lscc_uart"
                 dangling   = "not RXRDY_ENA"
                 conn_port  = "RXRDY_N"
    />
    
    <lsccip:port name       = "tx_ready_n_o"
                 dir        = "out"
                 conn_mod   = "lscc_uart"
                 dangling   = "not TXRDY_ENA"
                 conn_port  = "TXRDY_N"
    />
  </lsccip:ports>

  <xi:include href="bus_interface.xml" parse="xml" />     
  <xi:include href="memory_map.xml" parse="xml" />    
  
</lsccip:ip>
