|
| 1 | +############################################################################### |
| 2 | +## Copyright (C) 2016-2023 Analog Devices, Inc. All rights reserved. |
| 3 | +### SPDX short identifier: ADIBSD |
| 4 | +############################################################################### |
| 5 | + |
| 6 | +proc adi_xcvr_parameters {file_paths parameters} { |
| 7 | + |
| 8 | + set default_parameters { |
| 9 | + "RX_NUM_OF_LANES" "8" |
| 10 | + "TX_NUM_OF_LANES" "8" |
| 11 | + "RX_LANE_RATE" "12.5" |
| 12 | + "TX_LANE_RATE" "12.5" |
| 13 | + "LINK_MODE" "1" |
| 14 | + "RX_LANE_INVERT" "0" |
| 15 | + "TX_LANE_INVERT" "0" |
| 16 | + "QPLL_REFCLK_DIV" "1" |
| 17 | + "QPLL_FBDIV_RATIO" "1" |
| 18 | + "POR_CFG" "16'b0000000000000110" |
| 19 | + "PPF0_CFG" "16'b0000011000000000" |
| 20 | + "PPF1_CFG" "16'b0000011000000000" |
| 21 | + "QPLL_CFG" "27'h0680181" |
| 22 | + "QPLL_FBDIV" "10'b0000110000" |
| 23 | + "QPLL_CFG0" "16'b0011001100011100" |
| 24 | + "QPLL_CFG1" "16'b1101000000111000" |
| 25 | + "QPLL_CFG1_G3" "16'b1101000000111000" |
| 26 | + "QPLL_CFG2" "16'b0000111111000000" |
| 27 | + "QPLL_CFG2_G3" "16'b0000111111000000" |
| 28 | + "QPLL_CFG3" "16'b0000000100100000" |
| 29 | + "QPLL_CFG4" "16'b0000000000000011" |
| 30 | + "QPLL_CP_G3" "10'b0000011111" |
| 31 | + "QPLL_LPF" "10'b0100110111" |
| 32 | + "QPLL_CP" "10'b0001111111" |
| 33 | + "CPLL_FBDIV" "2" |
| 34 | + "CPLL_FBDIV_4_5" "5" |
| 35 | + "CPLL_CFG0" "16'b0000000111111010" |
| 36 | + "CPLL_CFG1" "16'b0000000000100011" |
| 37 | + "CPLL_CFG2" "16'b0000000000000010" |
| 38 | + "CPLL_CFG3" "16'b0000000000000000" |
| 39 | + "CH_HSPMUX" "16'b0010010000100100" |
| 40 | + "PREIQ_FREQ_BST" "0" |
| 41 | + "RXPI_CFG0" "16'b0000000000000010" |
| 42 | + "RXPI_CFG1" "16'b0000000000010101" |
| 43 | + "RTX_BUF_CML_CTRL" "3'b011" |
| 44 | + "TX_OUT_DIV" "1" |
| 45 | + "TX_CLK25_DIV" "20" |
| 46 | + "TX_PI_BIASSET" "1" |
| 47 | + "TXPI_CFG" "16'b0000000001010100" |
| 48 | + "A_TXDIFFCTRL" "5'b10110" |
| 49 | + "RX_OUT_DIV" "1" |
| 50 | + "RX_CLK25_DIV" "20" |
| 51 | + "RX_DFE_LPM_CFG" "16'h0104" |
| 52 | + "RX_PMA_CFG" "32'h001e7080" |
| 53 | + "RX_CDR_CFG" "72'h0b000023ff10400020" |
| 54 | + "RXCDR_CFG0" "16'b0000000000000010" |
| 55 | + "RXCDR_CFG2" "16'b0000001001101001" |
| 56 | + "RXCDR_CFG2_GEN2" "10'b1001100101" |
| 57 | + "RXCDR_CFG2_GEN4" "16'b0000000010110100" |
| 58 | + "RXCDR_CFG3" "16'b0000000000010010" |
| 59 | + "RXCDR_CFG3_GEN2" "6'b011010" |
| 60 | + "RXCDR_CFG3_GEN3" "16'b0000000000010010" |
| 61 | + "RXCDR_CFG3_GEN4" "16'b0000000000100100" |
| 62 | + "RXDFE_KH_CFG2" "16'h0200" |
| 63 | + "RXDFE_KH_CFG3" "16'h4101" |
| 64 | + "RX_WIDEMODE_CDR" "2'b00" |
| 65 | + "RX_XMODE_SEL" "1'b1" |
| 66 | + "TXDRV_FREQBAND" "0" |
| 67 | + "TXFE_CFG0" "16'b0000001111000010" |
| 68 | + "TXFE_CFG1" "16'b0110110000000000" |
| 69 | + "TXFE_CFG2" "16'b0110110000000000" |
| 70 | + "TXFE_CFG3" "16'b0110110000000000" |
| 71 | + "TXPI_CFG0" "16'b0000001100000000" |
| 72 | + "TXPI_CFG1" "16'b0001000000000000" |
| 73 | + "TXSWBST_EN" "0" |
| 74 | + } |
| 75 | + |
| 76 | + set correction_map { |
| 77 | + "TXOUT_DIV" "TX_OUT_DIV" |
| 78 | + "RXOUT_DIV" "RX_OUT_DIV" |
| 79 | + "CPLL_FBDIV_45" "CPLL_FBDIV_4_5" |
| 80 | + "RXCDR_CFG" "RX_CDR_CFG" |
| 81 | + } |
| 82 | + |
| 83 | + set updated_params {} |
| 84 | + set param_file_path [dict get $file_paths param_file_path] |
| 85 | + set cfng_file_path [dict get $file_paths cfng_file_path] |
| 86 | + |
| 87 | + if {$param_file_path ne ""} { |
| 88 | + |
| 89 | + set param_file_content [read [open $param_file_path r]] |
| 90 | + |
| 91 | + # Define a regex pattern for extracting the value of QPLL_FBDIV_TOP from $param_file_path |
| 92 | + set param_pattern {QPLL_FBDIV_TOP = ([0-9]+);} |
| 93 | + set match [regexp -inline $param_pattern $param_file_content] |
| 94 | + set QPLL_FBDIV_TOP [lindex $match 1] |
| 95 | + |
| 96 | + switch $QPLL_FBDIV_TOP { |
| 97 | + 16 {set QPLL_FBDIV_IN "10'b0000100000"} |
| 98 | + 20 {set QPLL_FBDIV_IN "10'b0000110000"} |
| 99 | + 32 {set QPLL_FBDIV_IN "10'b0001100000"} |
| 100 | + 40 {set QPLL_FBDIV_IN "10'b0010000000"} |
| 101 | + 64 {set QPLL_FBDIV_IN "10'b0011100000"} |
| 102 | + 66 {set QPLL_FBDIV_IN "10'b0101000000"} |
| 103 | + 80 {set QPLL_FBDIV_IN "10'b0100100000"} |
| 104 | + 100 {set QPLL_FBDIV_IN "10'b0101110000"} |
| 105 | + default {set QPLL_FBDIV_IN "10'b0000000000"} |
| 106 | + } |
| 107 | + |
| 108 | + switch $QPLL_FBDIV_TOP { |
| 109 | + 66 {set QPLL_FBDIV_RATIO "1'b0"} |
| 110 | + default {set QPLL_FBDIV_RATIO "1'b1"} |
| 111 | + } |
| 112 | + } |
| 113 | + |
| 114 | + set file_content [read [open $cfng_file_path r]] |
| 115 | + set match "" |
| 116 | + regexp {QPLL[0-9]+} $cfng_file_path match |
| 117 | + |
| 118 | + # Define a regex pattern for extracting parameters and their values |
| 119 | + set pattern {'([^']+)' => '([^']+\\?'?[0-9a-hA-H]*)'} |
| 120 | + set results {} |
| 121 | + set matches [regexp -all -inline $pattern $file_content] |
| 122 | + |
| 123 | + for {set i 0} {$i < [llength $matches]} {incr i 3} { |
| 124 | + |
| 125 | + set param [lindex $matches $i+1] |
| 126 | + set value [lindex $matches $i+2] |
| 127 | + |
| 128 | + set cleaned_value [string map {"\\" ""} $value] |
| 129 | + set corrected_param $param |
| 130 | + |
| 131 | + if {[dict exists $correction_map $param]} { |
| 132 | + set corrected_param [dict get $correction_map $param] |
| 133 | + } |
| 134 | + |
| 135 | + if {[string first $match $param] == 0} { |
| 136 | + |
| 137 | + if {[regexp {^(QPLL)[0-9]+(.*)} $param _ prefix rest]} { |
| 138 | + set corrected_param "${prefix}${rest}" |
| 139 | + } |
| 140 | + } |
| 141 | + |
| 142 | + if {[dict exists $default_parameters $corrected_param]} { |
| 143 | + |
| 144 | + set default_value [dict get $default_parameters $corrected_param] |
| 145 | + |
| 146 | + if {$cleaned_value != $default_value} { |
| 147 | + |
| 148 | + if {[string equal $cleaned_value "QPLL_FBDIV_IN"]} { |
| 149 | + set cleaned_value $QPLL_FBDIV_IN |
| 150 | + } |
| 151 | + if {[string equal $cleaned_value "QPLL_FBDIV_RATIO"]} { |
| 152 | + set cleaned_value $QPLL_FBDIV_RATIO |
| 153 | + } |
| 154 | + if {[string equal $corrected_param "PREIQ_FREQ_BST"]} { |
| 155 | + set cleaned_value [expr {$cleaned_value}] |
| 156 | + } |
| 157 | + |
| 158 | + dict set updated_params $corrected_param $cleaned_value |
| 159 | + } |
| 160 | + } |
| 161 | + lappend results [list $corrected_param $cleaned_value] |
| 162 | + } |
| 163 | + |
| 164 | + if {[llength $parameters] > 0} { |
| 165 | + foreach {key value} $parameters { |
| 166 | + |
| 167 | + if {[dict exists $default_parameters $key]} { |
| 168 | + set default_value [dict get $default_parameters $key] |
| 169 | + |
| 170 | + if {$value != $default_value} { |
| 171 | + dict set updated_params $key $value |
| 172 | + } |
| 173 | + } |
| 174 | + if {[dict exists $updated_params $key]} { |
| 175 | + set default_value [dict get $updated_params $key] |
| 176 | + |
| 177 | + if {$value != $default_value} { |
| 178 | + dict set updated_params $key $value |
| 179 | + } |
| 180 | + } |
| 181 | + } |
| 182 | + } |
| 183 | + |
| 184 | + return $updated_params |
| 185 | +} |
0 commit comments