proc init_gui { IPINST PROJECT_PARAM.ARCHITECTURE} {

	set Component_Name [ ipgui::add_param  $IPINST  -name Component_Name ]
	set main_tab [ipgui::add_page $IPINST -name "Configuration" -parent $IPINST -layout vertical]
	#set IPINST [ipgui::add_panel $IPINST -name ParentPanel -parent $IPINST ]
	set panel1 [ipgui::add_panel $IPINST -name panel1 -parent $main_tab -layout horizontal]	
	set Data_flow_direction [ipgui::add_param $IPINST -parent $panel1 -name Data_flow_direction -widget radioGroup]
	set Protocol_Selection  [ipgui::add_param $IPINST -parent $panel1 -name Protocol_Selection] 	 
	set PHY_type_External [ipgui::add_param $IPINST -parent $panel1 -name PHY_type_External]
	set_property visible false $PHY_type_External
	set_property display_name "PHY Type" $PHY_type_External

	# Link Configuration
	set panel6 [ipgui::add_panel $IPINST -name panel6 -parent $main_tab -layout horizontal]	
	set Group1 [ipgui::add_group $IPINST -name Group1 -parent $panel6 -layout horizontal]
	set_property display_name "Link Configuration" $Group1
	set Number_of_Lanes [ipgui::add_param $IPINST -parent $Group1 -name Number_of_Lanes -widget comboBox]
	set Link_Rate [ipgui::add_param $IPINST -parent $Group1 -name Link_Rate -widget comboBox]
	set_property display_name "Max Link Rate" $Link_Rate	
        ipgui::add_row $IPINST -parent $Group1
	set AXI_Frequency [ipgui::add_param $IPINST -parent $Group1 -name AXI_Frequency -widget textEdit]
	set_property display_name "AXI Clock Frequency (In MHz)" $AXI_Frequency
	
	set c_family [get_project_property ARCHITECTURE]
	if { ($c_family == "kintexu") || ($c_family == "virtexu") || ($c_family == "kintexuplus") || ($c_family == "zynquplus") } {
	 set_property visible true  $AXI_Frequency	
	 } else {	
	 set_property visible false $AXI_Frequency
	 }
	 
	 
	set TX_GT_BufferBypass [ipgui::add_param $IPINST -parent $Group1 -name TX_GT_BufferBypass] 	
	set_property visible false $TX_GT_BufferBypass
	set_property display_name "GT Buffer Bypass" $TX_GT_BufferBypass
        set CHANNEL_ENABLE [ipgui::add_param $IPINST -parent $Group1 -name CHANNEL_ENABLE] 	
	set_property visible false $CHANNEL_ENABLE
        set Group2 [ipgui::add_group $IPINST -name Group2 -parent $panel6 -layout horizontal]
	set_property display_name "AUX IO Configuration" $Group2
        set aux_io_loc [ipgui::add_param $IPINST -parent $Group2 -name aux_io_loc -widget comboBox]    
        set_property display_name "AUX I/O location" $aux_io_loc
	#set_property visible false $aux_io_loc
        set aux_io_type [ipgui::add_param $IPINST -parent $Group2 -name aux_io_type -widget comboBox]    
        set_property display_name "I/O Standard" $aux_io_type
        
        set SS_Mode [ipgui::add_param $IPINST -parent $Group1 -name SS_Mode]
	set_property visible false $SS_Mode
	set SIM_Mode [ipgui::add_param $IPINST -parent $Group1 -name SIM_Mode]
	set_property visible false $SIM_Mode
	#GT Configuration
	set panel5 [ipgui::add_panel $IPINST -name panel5 -parent $main_tab -layout horizontal]
	set GT_Data_Width [ipgui::add_param $IPINST -parent $panel5 -name GT_Data_Width] 	
	set_property display_name "GT Interface Width" $GT_Data_Width
#	set_property visible false $GT_Data_Width
   set TransceiverControl  [ipgui::add_param $IPINST -parent $main_tab -name TransceiverControl -layout horizontal]    
   set_property display_name "Additional transceiver control and status ports" $TransceiverControl

	# MST Configuration
	set MST [ipgui::add_group $IPINST -name MST_Configuration -parent $main_tab -layout horizontal]
	set_property display_name "MST Configuration"	$MST
	set MST_Enable [ipgui::add_param $IPINST -name MST_Enable -parent $MST]
	set Number_of_MST_Streams [ipgui::add_param $IPINST -name Number_of_MST_Streams -parent $MST -widget comboBox]
	set_property display_name "MST Streams" $Number_of_MST_Streams	

	
	
	# Video Interface Configuration
	set VIC [ipgui::add_group $IPINST -name VIC -parent $main_tab -layout horizontal]
	set_property display_name "Video Interface Configuration" $VIC
	set panel2 [ipgui::add_panel $IPINST -name panel2 -parent $VIC]
	set Max_Bits_Per_Color [ipgui::add_param $IPINST -name Max_Bits_Per_Color -parent $panel2 -widget comboBox]
	set panel3 [ipgui::add_panel $IPINST -name panel3 -parent $VIC -layout horizontal]
	set Quad_Pixel_Enable [ipgui::add_param $IPINST -name Quad_Pixel_Enable -parent $panel3]
	set YOnly_Enable [ipgui::add_param $IPINST -name YOnly_Enable -parent $panel3]
	set_property display_name "Y Only Enable" $YOnly_Enable
	ipgui::add_row $IPINST -parent $panel3
	set Dual_Pixel_Enable [ipgui::add_param $IPINST -name Dual_Pixel_Enable -parent $panel3]
	set YCRCB_Enable [ipgui::add_param $IPINST -name YCRCB_Enable -parent $panel3]
	set_property display_name "YCrCb Enable" $YCRCB_Enable
	
	# Audio Interface Configuration
	set SecondaryStreamgroupbox [ipgui::add_group $IPINST -name SecondaryStreamgroupbox -parent $main_tab -layout horizontal]
	set_property display_name "Audio Interface Configuration" $SecondaryStreamgroupbox
	set Enable_of_Audio_Channels [ipgui::add_param $IPINST -parent $SecondaryStreamgroupbox -name Enable_of_Audio_Channels]
	set_property display_name "Enable Audio Option" $Enable_of_Audio_Channels
	set Number_of_Audio_Channels [ipgui::add_param $IPINST -parent $SecondaryStreamgroupbox -name Number_of_Audio_Channels -widget comboBox]
	set_property display_name "Audio Channels" $Number_of_Audio_Channels

        # eDP configuration
	set eDPgroupbox [ipgui::add_group $IPINST -name eDPgroupbox -parent $main_tab -layout horizontal]
	set_property display_name "eDP Configuration" $eDPgroupbox
	set eDP_Enable [ipgui::add_param $IPINST -parent $eDPgroupbox -name eDP_Enable] 	
	set_property display_name "eDP Enable " $eDP_Enable

	# IEEE OUI
	set Group4 [ipgui::add_group $IPINST -name Group4 -parent $main_tab -layout horizontal]
	set_property display_name "DPCD Configuration" $Group4
	set IEEE_OUI [ipgui::add_param $IPINST -parent $Group4 -name IEEE_OUI]
	ipgui::add_static_text $IPINST -name IEEE_OUI_ST -text "Range: 000000 to FFFFFF" -parent $Group4 
	set Vendor_Specific [ipgui::add_param $IPINST -parent $Group4 -name Vendor_Specific]
	
	set panel4 [ipgui::add_panel $IPINST -name panel4 -parent $main_tab -layout horizontal]
	
	# Encryption
	set Encryptiongroupbox [ipgui::add_group $IPINST -name Encryptiongroupbox -parent $panel4]
	set_property display_name "Encryption" $Encryptiongroupbox	
	set Enable_HDCP_Encryption_Hooks [ipgui::add_param $IPINST -parent $Encryptiongroupbox -name Enable_HDCP_Encryption_Hooks]
	
	set_property visible false $Encryptiongroupbox
	
	  

	set shared_logic_tab [ipgui::add_page $IPINST -name "Shared Logic"]
        set SupportLevel [ipgui::add_param $IPINST -parent $shared_logic_tab -name SupportLevel -widget radioGroup]
	     set_property display_name "Shared Logic" $SupportLevel 
              
        set_property description "Select whether the transceiver quad PLL and transceiver differential refclk buffer\nare included in the core itself or in the example design" $SupportLevel

        set shared_logic_info_group [ipgui::add_group $IPINST -parent $shared_logic_tab -name "Shared Logic Overview" -layout vertical]
        ipgui::add_dynamic_text $IPINST -name label_shared_logic -parent $shared_logic_info_group -tclproc DT_Shared_Logic	
        ipgui::add_image $IPINST -name PixmapAFix2 -parent $shared_logic_info_group -width 400 -height 400
	set_property load_image "xgui/without_shared_logic.png" [ipgui::get_imagespec PixmapAFix2 -of $IPINST]

	# Adding empty lines for better GUI layout
	#ipgui::add_static_text $IPINST -name ST1 -text "\n\n" -parent $IPINST
	
	# display names for the parameters if they were missed earlier
	set_property display_name "Number of Lanes" $Number_of_Lanes
	set_property display_name "Enable HDCP Encryption Hooks" $Enable_HDCP_Encryption_Hooks
	set_property display_name "IEEE OUI" $IEEE_OUI
	####set_property display_name "Base Address" [ipgui::get_paramspec  BASEADDR  -of $IPINST]
	####set_property display_name "High Address" [ipgui::get_paramspec  HIGHADDR  -of $IPINST]
	#set_property display_name "Vendor Specific DPCD Enable" $Vendor_Specific

	# Tooltips
	set_property tooltip "Select the type of PHY -Test4 External PHY for \nsharing the GT with any other Video IP like SDI/HDMI.\n Refer to Video PHY Controller Documentation." $PHY_type_External
	set_property tooltip "Select the type of core to be generated. Source cores use the transmit side \nof the transceivers and Sink cores use the receive side of the transceivers." $Data_flow_direction 
	set_property tooltip "Select protocol version on which the core has to be generated." $Protocol_Selection 
	set_property tooltip "Select GT Interface Width per lane." $GT_Data_Width
	set_property tooltip "Enables the eDP features reduced AUX Timing, Display Authentication and Content protection " $eDP_Enable
	set_property tooltip "Select to bypass the GT buffer" $TX_GT_BufferBypass
	set_property tooltip "Defines the maximum number of lanes for the core is generated." $Number_of_Lanes 
	set_property tooltip "Defines the maximum link rate supported by the design." $Link_Rate 
	set_property tooltip "Frequency of the AXI Clock connected in MHZ" $AXI_Frequency 
	set_property tooltip "Enable MST feature of a DP 1.2 version core" $MST_Enable
	set_property tooltip "Defines the maximum number of video streams supported in MST mode." $Number_of_MST_Streams 
	set_property tooltip "Defines the maximum supported bits per colour of the generated design." $Max_Bits_Per_Color 
	set_property tooltip "Defines if the video interface support 4-Pixel mode." $Quad_Pixel_Enable 
	set_property tooltip "Defines if the video interface support 2-Pixel mode." $Dual_Pixel_Enable 
	set_property tooltip "The core support YCRCB 4:2:2 pixel mapping when enabled." $YCRCB_Enable 
	set_property tooltip "The core support Luminance only pixel mapping when enabled." $YOnly_Enable 
	set_property tooltip "Secondary Audio transfer support enable." $Enable_of_Audio_Channels 
	set_property tooltip "Set a default OUI value here instead of programming it after reset." $IEEE_OUI 
	set_property tooltip "Enable when Sink requires access to Vendor Specific fields in DPCD" $Vendor_Specific	
        set_property tooltip "Select the location of shareable logic" $SupportLevel
        set_property tooltip "If selected, enables addition transceiver control ports for debug or control purpose" $TransceiverControl
        set_property tooltip "Select IOSTANDARD for the AUX ports" $aux_io_type
        set_property tooltip "Select location for the AUX buffer" $aux_io_loc

	# Other default settings
	
	set c_family [string tolower [get_project_property FAMILY]]
	if {[string match -nocase *spartan6* $c_family]} {
		set spartan_family 1
	} else {
		set spartan_family 0	
	}

	
} ;# end create_gui


proc init_params { IPINST PROJECT_PARAM.PART PARAM_VALUE.TransceiverControl PARAM_VALUE.Number_of_Lanes PROJECT_PARAM.DEVICE PARAM_VALUE.Enable_HDCP_Encryption_Hooks PARAM_VALUE.Dual_Pixel_Enable PARAM_VALUE.YCRCB_Enable PARAM_VALUE.MST_Enable PARAM_VALUE.IEEE_OUI PARAM_VALUE.Vendor_Specific PARAM_VALUE.YOnly_Enable} {

	set x_val ${PROJECT_PARAM.PART}
	if {[regexp {xc7a} $x_val] == 1 || [regexp {xa7a} $x_val] == 1 || [regexp {xq7a} $x_val] == 1} {
		send_msg_id PSU-32 {WARNING} "Xilinx plans to remove this Device Support for DisplayPort Solution in 2017.4."
	}

	 #send_msg_id  PSU-32 {WARNING} "Answer Record: 68892 - Xilinx plans to obsolete the standalone DisplayPort LogiCORE in the Vivado release 2017.2 and hence users are strongly recommended to use DisplayPort Subsystems for all new designs."
	 set_property enabled false ${PARAM_VALUE.MST_Enable}
	 set_property enabled false ${PARAM_VALUE.IEEE_OUI}
	 set_property enabled false ${PARAM_VALUE.Vendor_Specific}
	 set_property enabled false ${PARAM_VALUE.YOnly_Enable}

	if {${PROJECT_PARAM.DEVICE} == "xc7a12t" }  {
	 	set_property range "1,2" ${PARAM_VALUE.Number_of_Lanes}
 	} else {
 		set_property range "1,2,4" ${PARAM_VALUE.Number_of_Lanes}
 	}

}
# ### update procs

proc update_gui_for_PARAM_VALUE.ENABLE_OF_AUDIO_CHANNELS {IPINST PARAM_VALUE.ENABLE_OF_AUDIO_CHANNELS } {
	
    if { [ get_property value ${PARAM_VALUE.ENABLE_OF_AUDIO_CHANNELS} ] == "true" }	{
		set_property visible true [ipgui::get_guiparamspec Number_of_Audio_Channels -of $IPINST] 
    } else {
		set_property visible false [ipgui::get_guiparamspec Number_of_Audio_Channels -of $IPINST] 
    }
}

proc update_PARAM_VALUE.Number_of_Audio_Channels {IPINST PARAM_VALUE.ENABLE_OF_AUDIO_CHANNELS PARAM_VALUE.Number_of_Audio_Channels  } {
# # add Data flow direction to args if needed
	set Number_of_Audio_Channels  [ipgui::get_paramspec Number_of_Audio_Channels -of $IPINST] 
    if { [ get_property value ${PARAM_VALUE.ENABLE_OF_AUDIO_CHANNELS} ] == "true" }	{
		
        set_property value [ get_property value ${PARAM_VALUE.Number_of_Audio_Channels} ] $Number_of_Audio_Channels
       } 
	#set_property value [get_property default_value $Number_of_Audio_Channels] $Number_of_Audio_Channels
	#set_property enabled false $Number_of_Audio_Channels

}

proc update_PARAM_VALUE.YOnly_Enable {IPINST PARAM_VALUE.Protocol_Selection PARAM_VALUE.YOnly_Enable} {
# # add Data flow direction to args if needed
   set YOnly_Enable  [ipgui::get_paramspec YOnly_Enable -of $IPINST] 

   if { [ get_property value ${PARAM_VALUE.Protocol_Selection} ] == "DP_1_2" } {
			set_property enabled true $YOnly_Enable
   } else {
			set_property value false $YOnly_Enable	
			set_property enabled false $YOnly_Enable
   }


}

proc update_PARAM_VALUE.YCRCB_Enable {IPINST PARAM_VALUE.YCRCB_Enable} {
# # add PARAM_VALUE.PROTOCOL_SELECTION to args if needed
# # add Data flow direction to args if needed
	 set_property enabled true  [ipgui::get_paramspec YCRCB_Enable -of $IPINST] 	

}

proc update_PARAM_VALUE.LINK_RATE { IPINST PARAM_VALUE.LINK_RATE PARAM_VALUE.Protocol_Selection  } {

   set Link_Rate  [ipgui::get_paramspec Link_Rate -of $IPINST] 
   set curvalue [ get_property value ${PARAM_VALUE.LINK_RATE} ]
   set c_family [string tolower [get_project_property FAMILY]]
   if { ($c_family == "kintex7l") || ($c_family == "qkintex7l") || ($c_family == "artix7l") } {
                        set_property range_value "2.7,1.62,2.7" $Link_Rate
   } else {
   if { [ get_property value ${PARAM_VALUE.Protocol_Selection} ] == "DP_1_2" } {
			set_property range "1.62,2.7,5.4" $Link_Rate	
   } else {
			set_property range_value "2.7,1.62,2.7" $Link_Rate
   }
   }

}

proc update_gui_for_PARAM_VALUE.MST_Enable {IPINST PARAM_VALUE.MST_Enable   } {


   if { [ get_property value ${PARAM_VALUE.MST_Enable} ]  == "true" } {
				set_property visible true [ipgui::get_guiparamspec Number_of_MST_Streams -of $IPINST] 
   } else {
				set_property visible false [ipgui::get_guiparamspec Number_of_MST_Streams -of $IPINST] 
   }
}

proc update_gui_for_PARAM_VALUE.aux_io_loc {IPINST PARAM_VALUE.aux_io_loc   } {


   if { [ get_property value ${PARAM_VALUE.aux_io_loc} ]  == "0" } {
				set_property visible true [ipgui::get_guiparamspec aux_io_type -of $IPINST] 
   } else {
				set_property visible false [ipgui::get_guiparamspec aux_io_type -of $IPINST] 
   }
}


proc update_PARAM_VALUE.NUMBER_OF_MST_STREAMS {IPINST PARAM_VALUE.MST_Enable PARAM_VALUE.NUMBER_OF_MST_STREAMS  } {
# # add Protocol_selection to args if needed
   set Number_of_MST_Streams  [ipgui::get_paramspec Number_of_MST_Streams -of $IPINST] 

   if { [ get_property value ${PARAM_VALUE.MST_Enable} ]  == "true" } {
				set_property enabled true $Number_of_MST_Streams
                set_property value [ get_property value ${PARAM_VALUE.NUMBER_OF_MST_STREAMS} ] $Number_of_MST_Streams
   } else {
				set_property enabled false $Number_of_MST_Streams
				set_property value 2 $Number_of_MST_Streams
   }
}

proc update_PARAM_VALUE.MST_Enable {IPINST PARAM_VALUE.Protocol_Selection PARAM_VALUE.MST_Enable} {
# add dataflow direction in args if needed
    set MST_Enable  [ipgui::get_paramspec MST_Enable -of $IPINST] 
    
 	    # Coregen DRCs always set it to false. 
	if { [ get_property value ${PARAM_VALUE.Protocol_Selection} ] == "DP_1_2" } {
	        set_property value false $MST_Enable	
			set_property enabled true $MST_Enable
        } else {
                set_property enabled false $MST_Enable
	        set_property value false $MST_Enable	
        }   
}

proc update_PARAM_VALUE.SS_MODE {IPINST PARAM_VALUE.SS_MODE} {

	 set_property enabled true  [ipgui::get_paramspec SS_Mode -of $IPINST] 

}

proc update_PARAM_VALUE.Quad_Pixel_Enable { IPINST PARAM_VALUE.MST_Enable PARAM_VALUE.NUMBER_OF_LANES PARAM_VALUE.Quad_Pixel_Enable} {

   set Quad_Pixel_Enable  [ipgui::get_paramspec Quad_Pixel_Enable -of $IPINST] 
   # Only update this parameter's state
   # Allowing quad pixel enable when lane count is 1/2 when MST enabled as internally MST works 4 lane
   if { [ get_property value ${PARAM_VALUE.NUMBER_OF_LANES} ] == "4" || [ get_property value ${PARAM_VALUE.MST_Enable} ] == "true"  } {
           #if { [ get_property value ${PARAM_VALUE.DUAL_PIXEL_ENABLE} ]  == "true" } {
			#set_property value false $Quad_Pixel_Enable
           #} else {
			#set_property enabled true $Quad_Pixel_Enable
			#}
			set_property enabled true $Quad_Pixel_Enable
   } else  {
   		set_property enabled false $Quad_Pixel_Enable
   		set_property value [get_property default_value $Quad_Pixel_Enable] $Quad_Pixel_Enable
   }

}

proc update_PARAM_VALUE.DUAL_PIXEL_ENABLE {IPINST PARAM_VALUE.NUMBER_OF_LANES PARAM_VALUE.Quad_Pixel_Enable  PARAM_VALUE.DUAL_PIXEL_ENABLE} {

   set Dual_Pixel_Enable  [ipgui::get_paramspec Dual_Pixel_Enable -of $IPINST] 

   # Only update this parameter's state
   if { [ get_property value ${PARAM_VALUE.NUMBER_OF_LANES} ] == "1" } {
			set_property value false $Dual_Pixel_Enable
			set_property enabled false $Dual_Pixel_Enable
   } else  {
       if { [ get_property value ${PARAM_VALUE.Quad_Pixel_Enable} ]  == "true" } {
					set_property value false $Dual_Pixel_Enable
			                set_property enabled false $Dual_Pixel_Enable
       } else {
					set_property enabled true $Dual_Pixel_Enable
       }
   }

}
proc update_gui_for_PARAM_VALUE.Protocol_Selection { IPINST PARAM_VALUE.Protocol_Selection } {

    set edpgroup   [ipgui::get_groupspec eDPgroupbox -of $IPINST]
    
	if { [ get_property value ${PARAM_VALUE.Protocol_Selection} ] == "DP_1_2" } {
	        set_property visible false $edpgroup		
        } else {
	        set_property visible false $edpgroup	    
        }
 
}

proc update_PARAM_VALUE.eDP_Enable { IPINST PARAM_VALUE.Protocol_Selection PARAM_VALUE.eDP_Enable} {

    
    set eDP_Enable  [ipgui::get_paramspec eDP_Enable -of $IPINST] 
    
	if { [ get_property value ${PARAM_VALUE.Protocol_Selection} ] == "DP_1_2" } {	
			set_property enabled true $eDP_Enable
        } else {
	        set_property value false $eDP_Enable	
			set_property enabled false $eDP_Enable
        }

    
}



proc update_PARAM_VALUE.AXI_FREQUENCY { IPINST PARAM_VALUE.AXI_FREQUENCY PROJECT_PARAM.ARCHITECTURE PARAM_VALUE.PHY_TYPE_EXTERNAL} {

    set phy_type [get_property value  ${PARAM_VALUE.PHY_TYPE_EXTERNAL}]
    set c_family [get_project_property ARCHITECTURE]
	if { (($c_family == "kintexu") || ($c_family == "virtexu") || ($c_family == "kintexuplus") || ($c_family == "zynquplus") ) && ($phy_type == "Internal_phy") } {
	 set_property enabled true  [ipgui::get_paramspec AXI_Frequency -of $IPINST] 	
	
	 } else {
	 set_property enabled false  [ipgui::get_paramspec AXI_Frequency -of $IPINST] 	
	 
	 }

}



proc update_PARAM_VALUE.CHANNEL_ENABLE { IPINST PARAM_VALUE.CHANNEL_ENABLE PARAM_VALUE.NUMBER_OF_LANES PARAM_VALUE.PHY_TYPE_EXTERNAL PROJECT_PARAM.ARCHITECTURE} {

      if {[ get_property value ${PARAM_VALUE.PHY_TYPE_EXTERNAL} ] == "Internal_phy"} {

  set c_family [get_project_property ARCHITECTURE]
	if { ($c_family == "kintexu") || ($c_family == "virtexu") || ($c_family == "kintexuplus") || ($c_family == "zynquplus")} {
	   set_property enabled true   [ipgui::get_paramspec CHANNEL_ENABLE -of $IPINST] 
	   set_property value [channel_enable_value [  get_property value ${PARAM_VALUE.NUMBER_OF_LANES} ] ${PROJECT_PARAM.ARCHITECTURE}]  [ipgui::get_paramspec CHANNEL_ENABLE -of $IPINST] 
        } else { 
	   set_property value X0Y0  [ipgui::get_paramspec CHANNEL_ENABLE -of $IPINST] 
	   set_property enabled false   [ipgui::get_paramspec CHANNEL_ENABLE -of $IPINST] 
        }
}

}

# ## to check

proc update_PARAM_VALUE.GT_Data_Width {PARAM_VALUE.GT_Data_Width} {
# Add Data_flow_direction in args if needed
	set_property enabled true ${PARAM_VALUE.GT_Data_Width} 
}

proc update_PARAM_VALUE.TX_GT_BufferBypass {PARAM_VALUE.TX_GT_BufferBypass} {
	set_property enabled true ${PARAM_VALUE.TX_GT_BufferBypass} 
}

proc update_PARAM_VALUE.SupportLevel {PARAM_VALUE.SupportLevel PARAM_VALUE.PHY_type_External} {
	set phy_type_External  [ get_property value ${PARAM_VALUE.PHY_type_External} ]
	
	 if {$phy_type_External == "External_phy"} {
		set_property value 0 ${PARAM_VALUE.SupportLevel}
		set_property enabled false ${PARAM_VALUE.SupportLevel}
		
	 } else {
		set_property enabled true ${PARAM_VALUE.SupportLevel}
	 }
}

proc update_PARAM_VALUE.Enable_of_Audio_Channels {IPINST PARAM_VALUE.Enable_of_Audio_Channels PARAM_VALUE.MST_Enable} {
	
	set Enable_of_Audio_Channels [ipgui::get_paramspec -name Enable_of_Audio_Channels -of $IPINST]
 ## CR fix 714961
	if { [ get_property value ${PARAM_VALUE.MST_Enable} ] == "true" } {
		set_property value 0 $Enable_of_Audio_Channels
		set_property enabled false $Enable_of_Audio_Channels
	} else {
		set_property enabled true  $Enable_of_Audio_Channels
	}	
}

proc update_PARAM_VALUE.TX_GT_BufferBypass {IPINST PARAM_VALUE.PHY_type_External PARAM_VALUE.Data_flow_direction PARAM_VALUE.TX_GT_BufferBypass} {
# # ADD Data_flow_direction to args if needed
	set buf_bypass [ipgui::get_paramspec TX_GT_BufferBypass   -of   $IPINST ]
    set data_flow_direction  [get_property value ${PARAM_VALUE.Data_flow_direction}]
    set phy_type_External  [get_property value ${PARAM_VALUE.PHY_type_External}]
    if {$phy_type_External == "Internal_phy"} {
        if {$data_flow_direction == "Receive_Sink_Core"} {
			set_property enabled false  $buf_bypass
        } else {
            set_property enabled true  $buf_bypass
	    }
    } 
}

proc update_gui_for_PARAM_VALUE.Data_flow_direction {IPINST PARAM_VALUE.Data_flow_direction } {
	set ieee_oui_st [ipgui::get_textspec IEEE_OUI_ST -of $IPINST]
	set Group4	[ipgui::get_groupspec Group4 -of $IPINST]
	set data_flow_direction  [get_property value ${PARAM_VALUE.Data_flow_direction}]
    if {$data_flow_direction == "Receive_Sink_Core"} {	
       set_property enabled true $Group4
	set_property enabled true $ieee_oui_st
    } else {
    set_property enabled  false  $Group4
	set_property enabled false $ieee_oui_st
    }	
}


proc update_PARAM_VALUE.IEEE_OUI {IPINST PARAM_VALUE.Data_flow_direction PARAM_VALUE.IEEE_OUI} {
# # ADD Data_flow_direction to args if needed	 
	set ieee_oui [ipgui::get_paramspec IEEE_OUI       -of     $IPINST ]
	#set ieee_oui_st [ipgui::get_textspec IEEE_OUI_ST -of $IPINST]
	#set Group4	[ipgui::get_groupspec Group4 -of $IPINST]
	set data_flow_direction  [get_property value ${PARAM_VALUE.Data_flow_direction}]
    if {$data_flow_direction == "Receive_Sink_Core"} {
      	set_property enabled true $ieee_oui
		#set_property enabled true $ieee_oui_st
        #set_property enabled true $Group4
    } else {
		set val [get_property default_value ${PARAM_VALUE.IEEE_OUI}]
	    set_property  value  $val $ieee_oui
	    set_property  enabled false  $ieee_oui
		#set_property  enabled false  $ieee_oui_st
    	#set_property enabled  false  $Group4
    }	 
}

proc update_PARAM_VALUE.Vendor_Specific {IPINST PARAM_VALUE.Data_flow_direction PARAM_VALUE.Vendor_Specific} {	
# # ADD Data_flow_direction to args if needed     
    set vs [ipgui::get_paramspec Vendor_Specific -of  $IPINST ]
	set data_flow_direction  [get_property value ${PARAM_VALUE.Data_flow_direction}]	

    if {$data_flow_direction == "Receive_Sink_Core"} {
      	set_property enabled true $vs
    } else {  
	    set_property  enabled false  $vs
    }
}
# ###### validate
proc validate_PARAM_VALUE.COMPONENT_NAME { PARAM_VALUE.COMPONENT_NAME} {

   set errStr [ipgui::component_validate [ get_property value ${PARAM_VALUE.COMPONENT_NAME} ] ] 
   if  { $errStr == "" } { 
		return true 
	} else { 
			set_property errmsg $errStr   ${PARAM_VALUE.COMPONENT_NAME} 
			return false 
		}

}

proc validate_PARAM_VALUE.IEEE_OUI { PARAM_VALUE.IEEE_OUI} {

	 set ieee_oui  [ get_property value ${PARAM_VALUE.IEEE_OUI} ]
	 if { [string length [ get_property value ${PARAM_VALUE.IEEE_OUI} ]] > 6 } {
			set_property errmsg "The maximum number of digits allowed is 6"  ${PARAM_VALUE.IEEE_OUI} 
			return false
	}	
	
   if { [regexp -all {[a-fA-F0-9]} $ieee_oui] != [ string length $ieee_oui ]} {
                set_property errmsg "Entered invalid Hexadecimal value $ieee_oui"  ${PARAM_VALUE.IEEE_OUI} 
                return false
   }
   if {$ieee_oui  == ""} {
         set_property errmsg "Value cannot be empty"  ${PARAM_VALUE.IEEE_OUI} 
         return false
   }
   if {[ string length $ieee_oui ] > 6} {
				 # Check if there are any zeroes prefixed in the string provided	
				 if {[ipgen::number_utils::hex2dec $ieee_oui] > 16777215 } {
						set_property errmsg "Value cannot be more than 6 nibble"  ${PARAM_VALUE.IEEE_OUI} 
         		return false
				 }		
   }
   if {[expr 0xFFFFFF ] < [expr 0x$ieee_oui ] ||  [expr 0x$ieee_oui ] < 0} {
                set_property errmsg "Entered  Hexadecimal value $ieee_oui is out of range."  ${PARAM_VALUE.IEEE_OUI} 
                return false
   }
   return true

}

# ############# update Model Param

proc update_MODELPARAM_VALUE.C_VENDOR_SPECIFIC { MODELPARAM_VALUE.C_VENDOR_SPECIFIC PARAM_VALUE.VENDOR_SPECIFIC} {

  if { [ get_property value ${PARAM_VALUE.VENDOR_SPECIFIC} ] == "true"} {set value 1} else {set value 0}
	set_property value $value  ${MODELPARAM_VALUE.C_VENDOR_SPECIFIC} 

}

proc update_MODELPARAM_VALUE.C_PHY_TYPE_EXTERNAL { MODELPARAM_VALUE.C_PHY_TYPE_EXTERNAL PARAM_VALUE.PHY_TYPE_EXTERNAL} {

  if { [ get_property value ${PARAM_VALUE.PHY_TYPE_EXTERNAL} ] == "Internal_phy"} {set value 0} else {set value 1}
        set_property value $value  ${MODELPARAM_VALUE.C_PHY_TYPE_EXTERNAL} 

}

proc update_MODELPARAM_VALUE.C_IEEE_OUI { MODELPARAM_VALUE.C_IEEE_OUI PARAM_VALUE.IEEE_OUI} {

  set_property value  [ get_property value ${PARAM_VALUE.IEEE_OUI} ]  ${MODELPARAM_VALUE.C_IEEE_OUI} 

}

proc update_MODELPARAM_VALUE.C_BUF_BYPASS { MODELPARAM_VALUE.C_BUF_BYPASS PARAM_VALUE.TX_GT_BUFFERBYPASS} {

	if {[ get_property value ${PARAM_VALUE.TX_GT_BUFFERBYPASS} ] == "true"} {
		set result 1
	} else {
		set result 0
	}
	set_property value $result  ${MODELPARAM_VALUE.C_BUF_BYPASS} 

}

proc update_MODELPARAM_VALUE.C_SIM_MODE  { MODELPARAM_VALUE.C_SIM_MODE  PARAM_VALUE.SIM_Mode } {

	if {[  get_property value ${PARAM_VALUE.SIM_Mode} ] == "true"}  {
		set result 1
	} else {
		set result 0
	}
	set_property value $result  ${MODELPARAM_VALUE.C_SIM_MODE} 

}


proc update_MODELPARAM_VALUE.C_LANE_COUNT { MODELPARAM_VALUE.C_LANE_COUNT PARAM_VALUE.Number_of_Lanes} { 
  set Number_of_Lanes  [ get_property value ${PARAM_VALUE.Number_of_Lanes} ]
  set_property value $Number_of_Lanes  ${MODELPARAM_VALUE.C_LANE_COUNT} 

}

proc update_MODELPARAM_VALUE.C_FAMILY { MODELPARAM_VALUE.C_FAMILY} {

     variable devicefamily
     set_property value $devicefamily  ${MODELPARAM_VALUE.C_FAMILY} 
     

}

proc update_MODELPARAM_VALUE.C_INCLUDE_HDCP { MODELPARAM_VALUE.C_INCLUDE_HDCP PARAM_VALUE.ENABLE_HDCP_ENCRYPTION_HOOKS} {

  if { [ get_property value ${PARAM_VALUE.ENABLE_HDCP_ENCRYPTION_HOOKS} ] == "true"} {set value 1} else {set value 0}
	set_property value $value  ${MODELPARAM_VALUE.C_INCLUDE_HDCP} 

}

proc update_MODELPARAM_VALUE.C_COMPONENT_NAME { MODELPARAM_VALUE.C_COMPONENT_NAME PARAM_VALUE.COMPONENT_NAME} {

	set_property value [ get_property value ${PARAM_VALUE.COMPONENT_NAME} ]  ${MODELPARAM_VALUE.C_COMPONENT_NAME} 

}

proc update_MODELPARAM_VALUE.C_EDP_EN { MODELPARAM_VALUE.C_EDP_EN PARAM_VALUE.eDP_Enable} {

	if {[ get_property value ${PARAM_VALUE.eDP_Enable} ] == "true"} {
		set result 1
	} else {
		set result 0
	}
	set_property value $result  ${MODELPARAM_VALUE.C_EDP_EN} 

}

proc update_MODELPARAM_VALUE.C_MAX_BITS_PER_COLOR { MODELPARAM_VALUE.C_MAX_BITS_PER_COLOR PARAM_VALUE.Max_Bits_Per_Color} {
	set_property value  [ get_property value ${PARAM_VALUE.Max_Bits_Per_Color} ]  ${MODELPARAM_VALUE.C_MAX_BITS_PER_COLOR} 
}

proc update_MODELPARAM_VALUE.C_GT_DATAWIDTH { MODELPARAM_VALUE.C_GT_DATAWIDTH PARAM_VALUE.GT_Data_Width } {
# # add Data_flow_direction to args if needed 
	if {[ get_property value ${PARAM_VALUE.GT_Data_Width} ] == "4" } {
		set result 4
	} else {
		set result 2
	}
	
	set_property value $result  ${MODELPARAM_VALUE.C_GT_DATAWIDTH} 

}

proc update_MODELPARAM_VALUE.C_SECONDARY_SUPPORT { MODELPARAM_VALUE.C_SECONDARY_SUPPORT PARAM_VALUE.ENABLE_OF_AUDIO_CHANNELS} {

  if { [ get_property value ${PARAM_VALUE.ENABLE_OF_AUDIO_CHANNELS} ] == "true"} {set value 1} else {set value 0}
	set_property value $value  ${MODELPARAM_VALUE.C_SECONDARY_SUPPORT} 

}

proc update_MODELPARAM_VALUE.C_DUAL_PIXEL_ENABLE { MODELPARAM_VALUE.C_DUAL_PIXEL_ENABLE PARAM_VALUE.DUAL_PIXEL_ENABLE} {

	if {[ get_property value ${PARAM_VALUE.DUAL_PIXEL_ENABLE} ] == "true"} {
			set result 1
	} else {
			set result 0
	}
	set_property value $result  ${MODELPARAM_VALUE.C_DUAL_PIXEL_ENABLE} 

}

proc update_MODELPARAM_VALUE.C_AUDIO_CHANNELS { MODELPARAM_VALUE.C_AUDIO_CHANNELS PARAM_VALUE.NUMBER_OF_AUDIO_CHANNELS} {

  set_property value  [ get_property value ${PARAM_VALUE.NUMBER_OF_AUDIO_CHANNELS} ]  ${MODELPARAM_VALUE.C_AUDIO_CHANNELS} 

}

proc update_MODELPARAM_VALUE.C_NUMBER_OF_MST_STREAMS { MODELPARAM_VALUE.C_NUMBER_OF_MST_STREAMS PARAM_VALUE.NUMBER_OF_MST_STREAMS} {

	set_property value  [ get_property value ${PARAM_VALUE.NUMBER_OF_MST_STREAMS} ]  ${MODELPARAM_VALUE.C_NUMBER_OF_MST_STREAMS} 

}

proc update_MODELPARAM_VALUE.C_PROTOCOL_SELECTION { MODELPARAM_VALUE.C_PROTOCOL_SELECTION PARAM_VALUE.Protocol_Selection} {

	if {[ get_property value ${PARAM_VALUE.Protocol_Selection} ] == "DP_1_2"} {
		set result 1
	} else {
		set result 0
	}
	set_property value $result  ${MODELPARAM_VALUE.C_PROTOCOL_SELECTION} 

}

proc update_MODELPARAM_VALUE.C_FLOW_DIRECTION { MODELPARAM_VALUE.C_FLOW_DIRECTION PARAM_VALUE.DATA_FLOW_DIRECTION} {

  if { [ get_property value ${PARAM_VALUE.DATA_FLOW_DIRECTION} ] == "Transmit_Source_Core"} {set value 0} else {set value 1}
        set_property value $value  ${MODELPARAM_VALUE.C_FLOW_DIRECTION} 

}

proc update_MODELPARAM_VALUE.C_YONLY_ENABLE { MODELPARAM_VALUE.C_YONLY_ENABLE PARAM_VALUE.YOnly_Enable} {

	if {[ get_property value ${PARAM_VALUE.YOnly_Enable} ] == "true"} {
		set result 1
	} else {
		set result 0
	}
	set_property value $result  ${MODELPARAM_VALUE.C_YONLY_ENABLE} 

}

proc update_MODELPARAM_VALUE.C_YCRCB_ENABLE { MODELPARAM_VALUE.C_YCRCB_ENABLE PARAM_VALUE.YCRCB_Enable} {

	if {[ get_property value ${PARAM_VALUE.YCRCB_Enable} ] == "true"} {
		set result 1
	} else {
		set result 0
	}
	set_property value $result  ${MODELPARAM_VALUE.C_YCRCB_ENABLE} 

}

proc update_MODELPARAM_VALUE.C_LINK_RATE { MODELPARAM_VALUE.C_LINK_RATE PARAM_VALUE.Link_Rate} {

	set xcoValue [ get_property value ${PARAM_VALUE.Link_Rate} ]
	if {$xcoValue == "5.4"} {
      set result 20
   } else {
      if {$xcoValue == "2.7"} {
					set result 10
      } else {
					set result 6
      }
   }
	set_property value $result  ${MODELPARAM_VALUE.C_LINK_RATE} 

}

proc update_MODELPARAM_VALUE.C_MST_ENABLE { MODELPARAM_VALUE.C_MST_ENABLE PARAM_VALUE.MST_Enable} {

	if {[ get_property value ${PARAM_VALUE.MST_Enable} ] == "true"} {
		set result 1
	} else {
		set result 0
	}
	set_property value $result  ${MODELPARAM_VALUE.C_MST_ENABLE} 

}

proc update_MODELPARAM_VALUE.C_QUAD_PIXEL_ENABLE { MODELPARAM_VALUE.C_QUAD_PIXEL_ENABLE PARAM_VALUE.Quad_Pixel_Enable} {

	if {[ get_property value ${PARAM_VALUE.Quad_Pixel_Enable} ] == "true"} {
			set result 1
	} else {
			set result 0
	}
	set_property value $result  ${MODELPARAM_VALUE.C_QUAD_PIXEL_ENABLE} 
}
# ### dynamic text proc
proc DT_Shared_Logic { PARAM_VALUE.SupportLevel} {
    set SupportLevel  [ get_property value ${PARAM_VALUE.SupportLevel} ]
    if {$SupportLevel == 1} {
        set    text "Include Shared Logic in core\n"
        append text "- For users who want a complete single solution.\n"
        append text "- For users who want one core with Shared Logic to drive multiple cores without Shared Logic.\n\n\n"
    } else {
        set    text "Include Shared Logic in example design\n"
        append text "- For users who want the Shared Logic outside the core.\n"
        append text "- For users who want to edit the Shared Logic or use their own.\n"
        append text "- For users who want one core with Shared Logic to drive multiple cores without Shared Logic.\n\n"
    }
	return $text
}
# ### update_gui_for
proc update_gui_for_PARAM_VALUE.SupportLevel { IPINST PARAM_VALUE.SupportLevel} {
	 if {([ get_property value ${PARAM_VALUE.SupportLevel} ] == 1)} {
        set_property load_image "xgui/with_shared_logic.png" [ipgui::get_imagespec PixmapAFix2 -of $IPINST]
    } else {
        set_property load_image "xgui/without_shared_logic.png" [ipgui::get_imagespec PixmapAFix2 -of $IPINST]
    }
}

# Procedure called to validate AXI_ACLK_FREQ_MHZ
proc validate_PARAM_VALUE.AXI_FREQUENCY {PARAM_VALUE.AXI_FREQUENCY PARAM_VALUE.GT_Data_Width} {
  set axi_clk [get_property value ${PARAM_VALUE.AXI_FREQUENCY}] 
  set gt_data_width [get_property value ${PARAM_VALUE.GT_Data_Width}] 
  if {$gt_data_width == 2 } {
  set freq_limit 80
  } else {
  set freq_limit 40
  }
  
  if {$axi_clk > $freq_limit || $axi_clk < 25} {
    set_property errmsg "AXI clock frequency must be less than or equal to the TXOUT/RXOUT clock of GT in ultrascale" ${PARAM_VALUE.AXI_FREQUENCY}
    return false
  } 
  return true
}

	
proc update_gui_for_PARAM_VALUE.PHY_type_External { IPINST PARAM_VALUE.PHY_type_External } {
      set phy_type_External  [ get_property value ${PARAM_VALUE.PHY_type_External} ]
      set TransceiverControl [ipgui::get_guiparamspec TransceiverControl -of $IPINST ]
      set SupportLevel [ipgui::get_guiparamspec SupportLevel -of $IPINST ]
   	  set shared_logic_tab [ipgui::get_pagespec "Shared Logic" -of $IPINST ]
	
      if {$phy_type_External == "External_phy"} {
      	set_property visible false $TransceiverControl
      	set_property visible false $SupportLevel
        set_property visible false $shared_logic_tab
      } else {
      	set_property visible true $TransceiverControl
      	set_property visible true $SupportLevel
        set_property visible true $shared_logic_tab
      }
}

proc channel_enable_value {num_lanes family} {
    set gt_sites ""
    #set family [get_project_property ARCHITECTURE]
    if {$family == "kintexu" || $family == "virtexu" } {
    set gt_sites [::xit::get_device_data D_AVAILABLE_GT_SITES GTHE3_CHANNEL -of [::xit::current_scope]]
    } else {
   ## for uplus
    set gt_sites [::xit::get_device_data D_AVAILABLE_GT_SITES GTHE4_CHANNEL -of [::xit::current_scope]] 
    }
    set sort_gsites [tcl::lsort -dictionary $gt_sites]
    set bonded_gt ""
    foreach gt $sort_gsites {
       if {[get_device_data D_GT_SITE_CLOCK_IS_BONDED $gt] == 1} {
           tcl::lappend bonded_gt $gt
       }
    }
    set site_loc_xy ""
    set site_loc ""
    set left_row [list X0Y0]
    set right_row [list X1Y0]
    foreach lane $bonded_gt {
        tcl::lappend site_loc_xy [lindex [split $lane _] end]
    }
    foreach loc $site_loc_xy {
      if {[regexp {X1.} $loc] == 1} {
       tcl::lappend right_row $loc
      } else {
       tcl::lappend left_row $loc
      }
    }
    if {[llength $right_row] > [llength $left_row]} {
       set res_sites [lrange $right_row 1 $num_lanes]
    } else {
       set res_sites [lrange $left_row 1 $num_lanes]
    }
    return $res_sites
}
