<?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>gpio</lsccip:name>
    <lsccip:display_name>GPIO</lsccip:display_name>
    <lsccip:version>1.8.1</lsccip:version>
    <lsccip:category>Processors_Controllers_and_Peripherals</lsccip:category>
	<lsccip:keywords>BusType_APB</lsccip:keywords> 
    <lsccip:min_radiant_version>2023.2</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>

    <lsccip:setting id                 = "FAMILY"
                    type               = "param"
                    conn_mod           = "lscc_gpio"
                    value_type         = "string"
                    title              = "Device Architecture"
                    default            = "LIFCL"
                    value_expr         = "runtime_info.device_info.architecture(1)"
                    editable           = "False"
                    group1             = "General"
                    hidden             = "True"
    />
	
    <lsccip:setting id                 = "IO_LINES_COUNT"
                    type               = "param"
                    conn_mod           = "lscc_gpio"
                    value_type         = "int"
                    title              = "Number of I/O Lines"
                    value_range        = "(1, 32)"
                    default            = "1"
                    group1             = "General"
    />
	
    <lsccip:setting id                 = "EXTERNAL_BUF"
                    type               = "param"
                    conn_mod           = "lscc_gpio"
                    value_type         = "bool"
                    title              = "Remove Tri-State Buffer"
                    default            = "False"
                    group1             = "General"
    />
	
    <lsccip:setting id                 = "OUT_RESET_VAL_INPUT"
                    type               = "input"
                    conn_mod           = "lscc_gpio"
                    value_type         = "string"
                    title              = "Initial Output Value (hex) [0 - FFFFFFFF]"
                    drc                = "ext_check_hex_value(
                                              OUT_RESET_VAL_INPUT,
                                              IO_LINES_COUNT,
                                              'Initial Output Value')"
                    default            = "0"
					output_formatter   = "nostr" 
                    group1             = "General"
    />

    <lsccip:setting id                 = "OUT_RESET_VAL"
                    type               = "param"
                    conn_mod           = "lscc_gpio"
                    value_type         = "string"
                    title              = "Initial Output Value (hex) [0 - FFFFFFFF]"
                    value_expr         = "'32\'h' + OUT_RESET_VAL_INPUT.zfill(8)"
                    default            = "00000000"
                    editable           = "False"
                    hidden             = "True"
                    group1             = "General"
    />

    <lsccip:setting id                 = "IO_OUT_DEF_VAL"
                    type               = "input"
                    conn_mod           = "lscc_gpio"
                    title              = "Initial Output Binary Value"
                    value_type         = "string"
                    value_expr         = "ext_get_output_bin_value(
                                              OUT_RESET_VAL_INPUT,
                                              IO_LINES_COUNT)"
                    editable           = "False"
                    group1             = "General"
    />

    <lsccip:setting id                 = "DIRECTION_DEF_VAL_INPUT"
                    type               = "input"
                    conn_mod           = "lscc_gpio"
                    value_type         = "string"
                    title              = "IO Direction (hex) [0 - FFFFFFFF]"
                    drc                = "ext_check_hex_value(
                                              DIRECTION_DEF_VAL_INPUT,
                                              IO_LINES_COUNT,
                                              'IO Direction')"
                    default            = "1"
					output_formatter   = "nostr" 
                    group1             = "General"
    />

    <lsccip:setting id                 = "DIRECTION_DEF_VAL"
                    type               = "param"
                    conn_mod           = "lscc_gpio"
                    value_type         = "string"
                    title              = "IO Direction (hex) [0 - FFFFFFFF]"
                    value_expr         = "'32\'h' + DIRECTION_DEF_VAL_INPUT.rjust(8, '0')"
                    default            = "00000000"
                    editable           = "False"
                    hidden             = "True"
                    group1             = "General"
    />

    <lsccip:setting id                 = "DIRECTION_DEF_ENCODING"
                    type               = "input"
                    conn_mod           = "lscc_gpio"
                    title              = "IO Direction Encoded Value"
                    value_type         = "string"
                    value_expr         = "ext_get_io_encoding(
                                              DIRECTION_DEF_VAL_INPUT,
                                              IO_LINES_COUNT)"
                    editable           = "False"
                    group1             = "General"
    />
        <!-- User interface -->
    <lsccip:setting id      = "IF_USER_INTF"
                    type               = "param"
                    conn_mod           = "lscc_gpio"
                    value_type         = "string"
                    title              = "Interface"
                    options            = "['LMMI', 'APB']"
                    value_expr         = "dflt_interf (FAMILY)"
                    group1             = "General"
    />
  </lsccip:settings>

  <lsccip:ports>
    <!-- GPIO inout -->
    <lsccip:port name      = "gpio_io"
                 dir       = "inout"
                 conn_mod  = "lscc_gpio"
                 conn_port = "gpio_io"
                 range     = "(IO_LINES_COUNT - 1, 0)"
				 dangling  = "EXTERNAL_BUF"

    />
    
	<lsccip:port name      = "gpio_i"
                 dir       = "in"
                 conn_mod  = "lscc_gpio"
                 conn_port = "gpio_i"
                 range     = "(IO_LINES_COUNT - 1, 0)"
				 stick_low = "EXTERNAL_BUF == False"

    />
	
	<lsccip:port name      = "gpio_o"
                 dir       = "out"
                 conn_mod  = "lscc_gpio"
                 conn_port = "gpio_o"
                 range     = "(IO_LINES_COUNT - 1, 0)"
				 dangling  = "EXTERNAL_BUF == False"
    />
	
	<lsccip:port name      = "gpio_en_o"
                 dir       = "out"
                 conn_mod  = "lscc_gpio"
                 conn_port = "gpio_en_o"
                 range     = "(IO_LINES_COUNT - 1, 0)"
				 dangling  = "EXTERNAL_BUF == False"
    />
    
	<lsccip:port name      = "clk_i"
                 dir       = "in"
                 conn_mod  = "lscc_gpio"
                 conn_port = "clk_i"
				 port_type = "clock"
    />

    <lsccip:port name      = "resetn_i"
                 dir       = "in"
                 conn_mod  = "lscc_gpio"
                 conn_port = "resetn_i"
				 port_type = "reset"
    />

    <!-- LMMI inputs -->


    <lsccip:port name          = "lmmi_request_i"
                 dir           = "in"
                 conn_mod      = "lscc_gpio"
                 conn_port     = "lmmi_request_i"
                 stick_low     = "IF_USER_INTF != 'LMMI'"
    />

    <lsccip:port name          = "lmmi_wr_rdn_i"
                 dir           = "in"
                 conn_mod      = "lscc_gpio"
                 conn_port     = "lmmi_wr_rdn_i"
                 stick_low     = "IF_USER_INTF != 'LMMI'"
    />

    <lsccip:port name          = "lmmi_offset_i"
                 dir           = "in"
                 conn_mod      = "lscc_gpio"
                 conn_port     = "lmmi_offset_i"
                 range         = "(3, 0)"
                 stick_low     = "IF_USER_INTF != 'LMMI'"
    />

    <lsccip:port name          = "lmmi_wdata_i"
                 dir           = "in"
                 conn_mod      = "lscc_gpio"
                 conn_port     = "lmmi_wdata_i"
                 range         = "(IO_LINES_COUNT - 1, 0)"
                 stick_low     = "IF_USER_INTF != 'LMMI'"
    />

    <!-- LMMI outputs -->
    <lsccip:port name          = "lmmi_rdata_o"
                 dir           = "out"
                 conn_mod      = "lscc_gpio"
                 conn_port     = "lmmi_rdata_o"
                 range         = "(IO_LINES_COUNT - 1, 0)"
                 dangling      = "IF_USER_INTF != 'LMMI'"
    />

    <lsccip:port name          = "lmmi_rdata_valid_o"
                 dir           = "out"
                 conn_mod      = "lscc_gpio"
                 conn_port     = "lmmi_rdata_valid_o"
                 dangling      = "IF_USER_INTF != 'LMMI'"
    />

    <lsccip:port name          = "lmmi_ready_o"
                 dir           = "out"
                 conn_mod      = "lscc_gpio"
                 conn_port     = "lmmi_ready_o"
                 dangling      = "IF_USER_INTF != 'LMMI'"
    />

    <!-- APB Interface -->
    <lsccip:port name          = "apb_penable_i"
                 dir           = "in"
                 conn_mod      = "lscc_gpio"
                 conn_port     = "apb_penable_i"
                 stick_low     = "IF_USER_INTF != 'APB'"
                 bus_interface = "APB_S0"
    />

    <lsccip:port name          = "apb_psel_i"
                 dir           = "in"
                 conn_mod      = "lscc_gpio"
                 conn_port     = "apb_psel_i"
                 stick_low     = "IF_USER_INTF != 'APB'"
                 bus_interface = "APB_S0"
    />

    <lsccip:port name          = "apb_pwrite_i"
                 dir           = "in"
                 conn_mod      = "lscc_gpio"
                 conn_port     = "apb_pwrite_i"
                 stick_low     = "IF_USER_INTF != 'APB'"
                 bus_interface = "APB_S0"
    />

    <lsccip:port name          = "apb_paddr_i"
                 dir           = "in"
                 conn_mod      = "lscc_gpio"
                 conn_port     = "apb_paddr_i"
                 range         = "(5, 0)"
                 stick_low     = "IF_USER_INTF != 'APB'"
                 bus_interface = "APB_S0"
    />

    <lsccip:port name          = "apb_pwdata_i"
                 dir           = "in"
                 conn_mod      = "lscc_gpio"
                 conn_port     = "apb_pwdata_i"
                 range         = "(31, 0)"
                 stick_low     = "IF_USER_INTF != 'APB'"
                 bus_interface = "APB_S0"
    />

    <lsccip:port name          = "apb_prdata_o"
                 dir           = "out"
                 conn_mod      = "lscc_gpio"
                 conn_port     = "apb_prdata_o"
                 range         = "(31, 0)"
                 dangling      = "IF_USER_INTF != 'APB'"
                 bus_interface = "APB_S0"
    />

    <lsccip:port name          = "apb_pslverr_o"
                 dir           = "out"
                 conn_mod      = "lscc_gpio"
                 conn_port     = "apb_pslverr_o"
                 dangling      = "IF_USER_INTF != 'APB'"
                 bus_interface = "APB_S0"
    />

    <lsccip:port name          = "apb_pready_o"
                 dir           = "out"
                 conn_mod      = "lscc_gpio"
                 conn_port     = "apb_pready_o"
                 dangling      = "IF_USER_INTF != 'APB'"
                 bus_interface = "APB_S0"
    />

    <!-- LINTR output -->
    <lsccip:port name      = "int_o"
                 dir       = "out"
                 conn_mod  = "lscc_gpio"
                 conn_port = "int_o"
                 bus_interface = "INTR"
    />

  </lsccip:ports>

  <xi:include href="bus_interface.xml" parse="xml" />
  <xi:include href="memory_map.xml" parse="xml" />

</lsccip:ip>
