SPRUIE9D May 2017 – May 2024 DRA74P , DRA75P , DRA76P , DRA77P
The following Perl script is used to generate a coefficient memory image for a given set of scaling factors.
#!/usr/local/bin/perl
#$dir="coef/"; # directory which contains the coef files
#$cfg_file="sc_config1.cfg"; # configuration file name
#$spl_file="sc_config_supl.cfg"; # supplemental configuration file name
$cfg_file=$ARGV[0]; # configuration file name
$spl_file=$ARGV[1]; # supplemental configuration file name
$dir=$ARGV[2]; # directory which contains the coef files
$coef_width=13; # coef bit width
$coef_ntap=7; # coef tap
$coef_nphase=32; # coef phase
$coef_norm=11; # coef norm
#----------------------------------------------------------
# read config file to get srcH/tarH/interlace_i/interlace_o
#----------------------------------------------------------
open(INFILE, "<$cfg_file") or die "### ERROR: Cannot open $cfg_file";
while(<INFILE>){
if (m/([-0-9]+) +\/\/ +srcW/) {
$srcW = $1;
} elsif (m/([-0-9]+) +\/\/ +srcH/) {
$srcH = $1;
} elsif (m/([-0-9]+) +\/\/ +tarW/) {
$tarW = $1;
} elsif (m/([-0-9]+) +\/\/ +tarH/) {
$tarH = $1;
} elsif (m/([-0-9]+) +\/\/ +interlace_in/) {
$interlace_i = $1;
} elsif (m/([-0-9]+) +\/\/ +interlace_out/) {
$interlace_o = $1;
}
}
close(INFILE);
#----------------------------------------------------------
# read supplemental config file to get srcWi/tarWi from
#----------------------------------------------------------
open(INFILE,"<$spl_file") or die "### ERROR: Cannot open $spl_file";
while(<INFILE>){
if (m/([-0-9]+) +\/\/ +srcWi/) {
$srcWi = $1;
} elsif (m/([-0-9]+) +\/\/ +tarWi/) {
$tarWi = $1;
} elsif (m/([-0-9]+) +\/\/ +profile/) {
$profile = $1; # 0:HIGH,1:MEDIUM,2:LOW
}
}
close(INFILE);
#----------------------------------------------------------
# determine coef file based on the width/height
#----------------------------------------------------------
#VS
#$vsc_file0 = "mod_ppfcoef_scale_eq_1_32_phases_flip.dat";
$vsc_file0 = "ppfcoef_scale_eq_1_32_phases_flip_PPF3_peak5_gain_eq_1_25.dat";
#VS VER
$mod_tarH = ($interlace_i == 0 && $interlace_o == 1) $tarH<<1 : $tarH; if ($profile==2) {
# LOW profile
if ($mod_tarH >= $srcH) {
$vsc_ver_file0 = "ppfcoef_scale_eq_1_32_phases_ver_3tap_flip.dat";
} else {
if ($mod_tarH >=($srcH>>1)) {
$n = int(16.0*$mod_tarH/$srcH);
$vsc_ver_file0 = sprintf("ppfcoef_scale_eq_%ddiv16_32_phases_ver_3tap_flip.dat",$n);
} else {
$n = 0;
$vsc_ver_file0 = "ppfcoef_scale_eq_1_32_phases_ver_3tap_flip.dat";
}
}
} else {
if ($mod_tarH >= $srcH) {
$vsc_ver_file0 = "ppfcoef_scale_eq_1_32_phases_ver_5tap_flip.dat";
} else {
$n = int(16.0*$mod_tarH/$srcH);
$vsc_ver_file0 = sprintf("ppfcoef_scale_eq_%ddiv16_32_phases_ver_5tap_flip.dat",$n);
}
}
# HS
if ($tarWi >= $srcWi) {
$hsc_file0 = "ppfcoef_scale_eq_1_32_phases_flip.dat";
} elsif ( ($tarWi == ($srcWi>>1)) || ($tarWi == ($srcWi>>2)) ) {
$hsc_file0 = "ppfcoef_scale_eq_1_32_phases_flip.dat";
} else {
if ($tarWi > ($srcWi>>1)) {
$n = int(16.0*$tarWi/$srcWi);
} elsif ($tarWi > ($srcWi>>2)) {
$n = int(16.0*$tarWi/($srcWi>>1));
} elsif ($tarWi >=($srcWi>>3)) {
$n = int(16.0*$tarWi/($srcWi>>2));
} else {
$n = 0;
}
$hsc_file0 = sprintf("ppfcoef_scale_eq_%ddiv16_32_phases_flip.dat",$n);
}
#----------------------------------------------------------
# write out the coef hex file
#----------------------------------------------------------
&write_coef($hsc_file0);
&write_coef($hsc_file0);
&write_coef($vsc_ver_file0);
&write_coef($vsc_ver_file0);
&write_coef($vsc_file0);
&write_coef($vsc_file0);
sub write_coef {
my ($filename) = @_;
open(INFILE, "<$dir/$filename") or die "### ERROR: Cannot open $dir/$filename";
$line=<INFILE>;
@val=split(' ',$line);
$ntap=$val[0];
$nphase=$val[1];
$norm=$val[2];
for ($p=0;$p<$nphase;$p++) {
$line=<INFILE>;@val=split(' ',$line);
for($i=0;$i<$ntap;$i++) {
if ($val[$i]<0) {
$val[$i]+=(1<<$coef_width);
}
}
undef(@coef);
unshift(@coef, sprintf("%04x",$val[0]));
unshift(@coef, sprintf("%04x",$val[1]));
unshift(@coef, sprintf("%04x",$val[2]));
unshift(@coef, sprintf("%04x",$val[3]));
unshift(@coef, sprintf("%04x",$val[4]));
unshift(@coef, sprintf("%04x",$val[5]));
unshift(@coef, sprintf("%04x",$val[6]));
unshift(@coef, sprintf("%04x",0));
$coef=join("",@coef);
print "$coef\n";
}
close(INFILE);
}