Hi i need help regarding one scenario i have two functions defined one basic tc and other sqc .... for now mu_value vaues based on the condition is getting calculated based on the given condition and are stored in mu.txt file..But i need mu_value to be calculate for sqc condition also and be stored to mu.txt file .... So it should give me values like first basic case values which is stored currently and then some i should set up a condition to calculate mu_value for sqc and same to be stored in txt file followed by basic values ... But i am lacking the info how should i proceed with the below functions given ... I am dropping code below so if you understand anything about functions being used..
typedef enum {l,le,g,ge,eq} mu_cond;
typedef enum {And,Or,Nand,Nor} tc_cond;
typedef enum {AND,OR,NAND,NOR} sqc_cond;
module ila_seq_cap_input();
string match_value,cc0,cc1,cc2,cc3,val;
int tc_value,sqc_value;
string tc,tc1,tc_1,sqc,sqc1;
string op;
string match_op,tc_op,sqc_op;
int cc_value;
int cap_bit_width,depth;
int trigger_position_max,trigger_position_min;
int window_size_max,window_size_min;
int window_count_max,window_count_min;
string value;
string tc_val,tc_val1,sqc_val,mu_file,cc_file,tc_file,sqc_file,trigger_position_value;
int mu_value[],mu_value1[$];
int no_values,cc_sel;
int trigger_position ,trigger_value[];
tc_cond tccond;
sqc_cond sqccond;
mu_cond mucond=g;
`ifdef p01023
parameter C_PROBE0_WIDTH=1023;
`elsif p0511
parameter C_PROBE0_WIDTH = 511;
`elsif p0512
parameter C_PROBE0_WIDTH = 512;
`elsif p0255
parameter C_PROBE0_WIDTH = 255;
`elsif p0127
parameter C_PROBE0_WIDTH = 127;
`elsif p064
parameter C_PROBE0_WIDTH = 63;
`elsif p08
parameter C_PROBE0_WIDTH = 7;
`elsif p05
parameter C_PROBE0_WIDTH = 5;
`elsif p016
parameter C_PROBE0_WIDTH = 15;
`elsif p031
parameter C_PROBE0_WIDTH = 31;
`else
parameter C_PROBE0_WIDTH = 0;
`endif
`ifdef p11023
parameter C_PROBE1_WIDTH=1023;
`elsif p1511
parameter C_PROBE1_WIDTH = 511;
`elsif p1255
parameter C_PROBE1_WIDTH = 255;
`elsif p1256
parameter C_PROBE1_WIDTH = 256;
`elsif p1127
parameter C_PROBE1_WIDTH = 127;
`elsif p164
parameter C_PROBE1_WIDTH = 63;
`elsif p18
parameter C_PROBE1_WIDTH = 7;
`elsif p15
parameter C_PROBE1_WIDTH = 5;
`elsif p116
parameter C_PROBE1_WIDTH = 15;
`elsif p131
parameter C_PROBE1_WIDTH = 31;
`else
parameter C_PROBE1_WIDTH = 0;
`endif
`ifdef p21023
parameter C_PROBE2_WIDTH=1023;
`elsif p2512
parameter C_PROBE2_WIDTH = 511;
`elsif p2255
parameter C_PROBE2_WIDTH = 255;
`elsif p2127
parameter C_PROBE2_WIDTH = 127;
`elsif p263
parameter C_PROBE2_WIDTH = 63;
`elsif p264
parameter C_PROBE2_WIDTH = 64;
`elsif p28
parameter C_PROBE2_WIDTH = 7;
`elsif p25
parameter C_PROBE2_WIDTH = 5;
`elsif p216
parameter C_PROBE2_WIDTH = 15;
`elsif p231
parameter C_PROBE2_WIDTH = 31;
`else
parameter C_PROBE2_WIDTH = 0;
`endif
`ifdef p31023
parameter C_PROBE3_WIDTH=1023;
`elsif p3512
parameter C_PROBE3_WIDTH = 511;
`elsif p3255
parameter C_PROBE3_WIDTH = 255;
`elsif p3127
parameter C_PROBE3_WIDTH = 127;
`elsif p364
parameter C_PROBE3_WIDTH = 63;
`elsif p38
parameter C_PROBE3_WIDTH = 7;
`elsif p35
parameter C_PROBE3_WIDTH = 5;
`elsif p316
parameter C_PROBE3_WIDTH = 15;
`elsif p331
parameter C_PROBE3_WIDTH = 31;
`elsif p332
parameter C_PROBE3_WIDTH = 32;
`else
parameter C_PROBE3_WIDTH = 0;
`endif
`ifdef 1023
parameter C_PROBE_WIDTH=1023;
`elsif 768
parameter C_PROBE_WIDTH=768;
`elsif 511
parameter C_PROBE_WIDTH = 511;
`elsif 255
parameter C_PROBE_WIDTH = 255;
`elsif 127
parameter C_PROBE_WIDTH = 127;
`elsif 64
parameter C_PROBE_WIDTH = 63;
`elsif 8
parameter C_PROBE_WIDTH = 7;
`elsif 5
parameter C_PROBE_WIDTH = 5;
`elsif 16
parameter C_PROBE_WIDTH = 15;
`else
parameter C_PROBE_WIDTH = 31;
`endif
int fd;
int trigger_count;
int no_probes=1;
int mu_count=1;
function void parse(output int s [], output int size_s,input byte separator, input string in);
int index[$];
string out[];
s.delete();
foreach(in[i]) begin // find commas
if (in[i]==separator) begin
index.push_back(i-1); // before comma
index.push_back(i+1); // after comma
end
end
index.push_front(0); // first index
index.push_back(in.len()-1); // last index
out = new[index.size()/2];
s=new[index.size()/2];
foreach (out[i]) begin
out[i] = in.substr(index[2*i],index[2*i+1]);
$display(" out=%h", out[i].atoi());
s[i]= out[i].atoi();
end
size_s=s.size();
index.delete();
out.delete();
endfunction : parse
function automatic get_string(int n, int width,ref string s);
int a;
s.bintoa(n);
//$display("%s %d",s,s.len());
a=s.len();
for (int i=0;i<width-a;i++) begin
s={"0",s};
end
//$display("%s",s);
endfunction
function automatic get_mu_string(int n, int width,ref string s);
int a,b;
s.bintoa(n);
// $display(" %d %s %d",width,s,s.len());
a=s.len();
b=s.len();
for (int i=0;i<(width-b);i++) begin
if(a%4!=0) begin
s={"0",s};
a++;
//$display("%s %d",s,a);
end
else begin
if(match_op=="==")
s={"x",s};
else
s={"0",s};
//$display("%s %d",s,i);
end
end
match_value = {match_op,s};
op=match_op;
$fdisplay(fd,"%0d",n);
$fdisplay(fd,"%s",match_value);
$fdisplay(fd,"%s",match_op);
//$display("%s",s);
endfunction
function automatic get_x_string( int width,ref string s);
s="";
for (int i=0;i<width;i++) begin
s={"x",s};
end
endfunction
function void cap_width(input int s, output int a);
while(s!=1)
if(s%2==0) begin
a++;
s=s/2;
end
endfunction
// import "DPI-C" function string get_string(int value,int width);
function tc_config(input int tc_value,input string tc_op);
if($value$plusargs("tc_file=%s",tc_file))
fd=$fopen(tc_file,"a");
tc.bintoa(tc_value);
$display("before for loop %s %d",tc_op,tc_value);
for(int i=0;i<(no_probes*mu_count);i++)
tc1={tc1,tc};
tc_val={tc_op,tc1};
if(mu_count>1)
for(int i=0;i<(no_probes*mu_count)-no_probes;i++)
tc_1={tc_1,tc};
else
for(int i=0;i<(no_probes*mu_count);i++)
tc_1={tc_1,tc};
tc_val1={tc_op,tc_1};
$display("%s tc1 %d",tc_op,tc1);
$display("%s tc_val %s %s",tc_op,tc_val,tc_val1);
$fdisplay(fd,"%s",tc_val);
$fdisplay(fd,"%s",tc_val1);
op=tc_op;
$fdisplay(fd,"%s",tc_op);
$fclose(fd);
endfunction
function sqc_config(input int sqc_value,input string sqc_op);
if($value$plusargs("sqc_file=%s",sqc_file))
fd=$fopen(sqc_file,"a");
sqc.bintoa(sqc_value);
//$display("before for loop %s %d",tc_op,tc_value);
for(int i=0;i<no_probes;i++)
sqc1={sqc1,sqc};
sqc_val={sqc_op,sqc1};
//$display("%s tc1 %d",tc_op,tc1);
//$display("%s %d",tc_op,tc_value);
$fdisplay(fd,"%s",sqc_val);
op=sqc_op;
$fdisplay(fd,"%s",sqc_op);
$fclose(fd);
endfunction
function mu_config(input string match_op);
if($value$plusargs("mu_file=%s",mu_file))
fd=$fopen(mu_file,"a");
if(no_values==mu_count*no_probes) begin
$fdisplay(fd,"%0d",no_probes);
$fdisplay(fd,"%0d",mu_count);
for(int p=0;p<no_probes;p=p+4) begin
$display("probe value %d %d %h",p,p*mu_count,mu_value[p*mu_count]);
for(int i=0+(p*mu_count);i<mu_count+(p*mu_count);i++) begin
if(mu_value[i]!=0)
if(C_PROBE0_WIDTH!=0)
get_mu_string(mu_value[i],C_PROBE0_WIDTH,val);
else
get_mu_string(mu_value[i],C_PROBE_WIDTH,val);
$display("mu_value[%d] %h %d",i,mu_value[i],p*mu_count);
end
for(int i=mu_count+(p*mu_count);i<(mu_count*2)+(p*mu_count);i++) begin
if(mu_value[i]!=0)
if(C_PROBE1_WIDTH!=0)
get_mu_string(mu_value[i],C_PROBE1_WIDTH,val);
else
get_mu_string(mu_value[i],C_PROBE_WIDTH,val);
$display("mu_value[%d] %h",i,mu_value[i]);
end
for(int i=(mu_count*2)+(p*mu_count);i<(mu_count*3)+(p*mu_count);i++) begin
if(mu_value[i]!=0)
if(C_PROBE2_WIDTH!=0)
get_mu_string(mu_value[i],C_PROBE2_WIDTH,val);
else
get_mu_string(mu_value[i],C_PROBE_WIDTH,val);
$display("mu_value[%d] %h",i,mu_value[i]);
end
for(int i=(mu_count*3)+(p*mu_count);i<(mu_count*4)+(p*mu_count);i++) begin
if(mu_value[i]!=0)
if(C_PROBE3_WIDTH!=0)
get_mu_string(mu_value[i],C_PROBE3_WIDTH,val);
else
get_mu_string(mu_value[i],C_PROBE_WIDTH,val);
$display("mu_value[%d] %h",i,mu_value[i]);
end
end
//foreach(mu_value[i]) begin
// get_mu_string(mu_value[i],C_PROBE0_WIDTH,val);
//match_value = {match_op,val};
// op=match_op;
// $fdisplay(fd,"%0d",mu_value[i]);
// $fdisplay(fd,"%s",match_value);
// $fdisplay(fd,"%s",match_op);
end
$fclose(fd);
endfunction
initial
begin
$display("C_PROBE0_WIDTH %d C_PROBE1_WIDTH %d C_PROBE2_WIDTH %d C_PROBE3_WIDTH %d",C_PROBE0_WIDTH,C_PROBE1_WIDTH,C_PROBE2_WIDTH, C_PROBE3_WIDTH );
if($value$plusargs("no_probes=%d",no_probes) && $value$plusargs("Mu_count=%d",mu_count))
$display("probes %d no of comparators %d",no_probes, mu_count);
else
begin
mu_count=1;
no_probes=1;
$display("probes %d no of comparators %d",no_probes, mu_count);
end
if($value$plusargs("Value=%s",value)) begin
parse(mu_value,no_values,",",value);
if(mu_value.size()!=no_probes*mu_count) begin
$display("mu_value %d probes %d count %d",mu_value.size(),no_probes,mu_count);
for(int i=0;i<no_probes;i++) begin
if(i!=0) begin
no_values++;
mu_value=new[mu_value.size()+1](mu_value);
mu_value[i*mu_count]=mu_value[(i*mu_count)-1]+1;
//$display("mu_value[i] %d mu_value %d mu_value.size %d i %d",mu_value[(i*mu_count)],mu_value[i-1],mu_value.size(),i);
end
for(int j=1; j<mu_count;j++) begin
mu_value=new[mu_value.size()+1](mu_value);
mu_value[(i*mu_count)+j]=mu_value[i*mu_count];
no_values++;
//$display("mu_value[i] %d mu_value %d mu_value.size %d i %d j %d",mu_value[(i*mu_count)+j],mu_value[i],mu_value.size(),i,j);
end
end
end
//foreach(mu_value[i])
//$display("mu_value[i] %d i %d",mu_value[i],i);
for (int p=1;p<no_probes;p++)
for(int c1=0;c1<mu_count;c1++) begin
if(p<4) begin
mu_value[c1+(p*mu_count)]=mu_value[c1+((p-1)*mu_count)]+1;
//$display("mu_value %h %d p %d size %d",mu_value[c1+(p*mu_count)],c1+(p*mu_count),p,mu_value.size());
end
else begin
mu_value=new[mu_value.size()+1](mu_value);
mu_value[c1+(p*mu_count)]=mu_value[c1+((p-4)*mu_count)];
// no_values++;
//$display("mu_value %h %d p %d ",mu_value[c1+(p*mu_count)],c1+(p*mu_count),p,mu_value.size());
end
end
foreach(mu_value[i])
$display("%h no_values %d",mu_value[i],no_values);
if($value$plusargs("Match_op=%s",match_op))
begin
mu_config(match_op);
$display("match_op %s",match_op);
end
else
// for(int i=mucond.next();i<mucond.num-2;i++)
for(int i=mucond.first();i<mucond.num;i++)
begin
mucond=mu_cond'(i);
if(mucond==eq)
begin
match_op="==";
mu_config(match_op);
end
else if(mucond==g)
begin
match_op=">";
mu_config(match_op);
end
else if(mucond==ge)
begin
match_op=">=";
mu_config(match_op);
end
else if(mucond==l)
begin
match_op="<";
mu_config(match_op);
end
else if(mucond==le)
begin
match_op="<=";
mu_config(match_op);
end
end
end
if ($value$plusargs ("TRIGGER_CONDITION=%d", tc_value)) begin
if ($value$plusargs ("TC_op=%s", tc_op))
tc_config(tc_value,tc_op);
end
else
for(int i=tccond.first();i<tccond.num;i++)
begin
tc1="";;
tccond=tc_cond'(i);
if(tccond==And) begin
tc_op="==";
tc_value=1;
tc_config(tc_value,tc_op);
end
else if(tccond==Or) begin
tc_op="||";
tc_value=1;
tc_config(tc_value,tc_op);
end
else if(tccond==Nor) begin
tc_op="==";
tc_value=0;
tc_config(tc_value,tc_op);
end
else if(tccond==Nand) begin
tc_op="!=";
tc_value=1;
//$display("%s %d %d",tc_op,i,tc_value);
tc_config(tc_value,tc_op);
end
//$display("%s %d %d",tc_op,i,tc_value);
end
if ($value$plusargs ("SQC_CONDITION=%d", sqc_value)) begin
if ($value$plusargs ("SQC_op=%s", sqc_op))
sqc_config(sqc_value,sqc_op);
end
else
for(int i=sqccond.first();i<sqccond.num;i++)
begin
sqc1="";;
sqccond=sqc_cond'(i);
if(sqccond==AND) begin
sqc_op="==";
sqc_value=1;
sqc_config(sqc_value,sqc_op);
end
else if(sqccond==OR) begin
sqc_op="||";
sqc_value=1;
sqc_config(sqc_value,sqc_op);
end
else if(sqccond==NOR) begin
sqc_op="==";
sqc_value=0;
sqc_config(sqc_value,sqc_op);
end
else if(sqccond==NAND) begin
sqc_op="!=";
sqc_value=1;
//$display("%s %d %d",tc_op,i,tc_value);
sqc_config(sqc_value,sqc_op);
end
$display("%s %d %d",sqc_op,i,sqc_value);
end
if($value$plusargs("cc_file=%s",cc_file))
if ($value$plusargs ("DEPTH=%d", depth))
if( $value$plusargs ("window_size_max=%d",window_size_max))
if( $value$plusargs("window_size_min=%d",window_size_min))
if($value$plusargs ("window_count_max=%d",window_count_max))
if( $value$plusargs("window_count_min=%d",window_count_min)) begin
cap_width(depth,cap_bit_width);
if( $value$plusargs ("trigger_position_max=%d",trigger_position_max)) begin
if( $value$plusargs("trigger_position_min=%d",trigger_position_min))
for(int window_size=window_size_min;window_size<=window_size_max;window_size=window_size*2)
for(int window_count=window_count_min;(window_count<=window_count_max && (window_count*window_size)<=depth);window_count++)
if(trigger_position_max<trigger_position_min) begin
trigger_position=window_size-1;
fd=$fopen(cc_file,"a");
cc_count(window_size,window_count,cc0,cc1,cc2,cc3);
$fclose(fd);
end //trigger_position_max
else
for( trigger_position=trigger_position_min;(trigger_position<=trigger_position_max && trigger_position<window_size);trigger_position++)
begin
fd=$fopen(cc_file,"a");
cc_count(window_size,window_count,cc0,cc1,cc2,cc3);
$fclose(fd);
end //trigger_position
end //trigger_position_max
else
if( $value$plusargs ("trigger_position_value=%s",trigger_position_value))
begin
parse(trigger_value,no_values,",",trigger_position_value);
foreach(trigger_value[i])
for(int window_size=window_size_min;window_size<=window_size_max;window_size=window_size*2)
for(int window_count=window_count_min;(window_count<=window_count_max && (window_count*window_size)<=depth);window_count++)
if(trigger_position<window_size) begin
trigger_position=trigger_value[i];
$display("trigger_position %d window count %d sample count %d",trigger_position,window_count,window_size);
fd=$fopen(cc_file,"a");
cc_count(window_size,window_count,cc0,cc1,cc2,cc3);
$fclose(fd);
end //window_count
end //trigger_positio_value
end //window_count_min
end
task cc_count(int window_size,int window_count,string cc0,cc1,cc2,cc3);
$fdisplay(fd,"window_count");
$fdisplay(fd,"%0d", window_count);
$fdisplay(fd,"sample_count");
$fdisplay(fd,"%0d", window_size);
$fdisplay(fd,"trigger_position");
$fdisplay(fd,"%0d", trigger_position);
$fdisplay(fd,"depth");
$fdisplay(fd,"%0d", depth);
if(trigger_position==0) begin
if(window_size==1) begin
if(window_count>2) begin
get_string((window_count-2),cap_bit_width,cc2);
get_x_string(cap_bit_width,cc0);
get_x_string(cap_bit_width,cc1);
get_x_string(cap_bit_width,cc3);
cc_sel=2;
end
else if(window_count==2) begin
get_string(0,cap_bit_width,cc2);
get_string(0,cap_bit_width,cc3);
get_x_string(cap_bit_width,cc0);
get_x_string(cap_bit_width,cc1);
cc_sel=1;
end
else begin
get_x_string(cap_bit_width,cc0);
get_x_string(cap_bit_width,cc1);
get_string((window_count-1),cap_bit_width,cc2);
//get_x_string(cap_bit_width,cc2);
get_x_string(cap_bit_width,cc3);
cc_sel=0;
end
end
else if(window_size>1)
if(window_count>0) begin
get_x_string(cap_bit_width,cc0);
// get_string((window_size-2),cap_bit_width,cc0);
get_string((window_size-2),cap_bit_width,cc1);
get_string((window_size-2),cap_bit_width,cc3);
get_string((window_count-1),cap_bit_width,cc2);
cc_sel=3;
end
end
else if(trigger_position==1) begin
if(window_count>0)
if(window_size==2) begin
get_x_string(cap_bit_width,cc0);
get_x_string(cap_bit_width,cc3);
get_string((window_count-1),cap_bit_width,cc2);
get_string(0,cap_bit_width,cc1);
cc_sel=4;
end
else if(window_size>3) begin
get_x_string(cap_bit_width,cc0);
get_string((window_size-2),cap_bit_width,cc1);
get_string((window_size-2),cap_bit_width,cc3);
get_string((window_count-1),cap_bit_width,cc2);
cc_sel=6;
end
end
else if(trigger_position==window_size-1) begin
if(window_size>3)
if(window_count>0) begin
get_string((trigger_position-2),cap_bit_width,cc0);
get_string((window_size-2),cap_bit_width,cc1);
get_string((window_size-2),cap_bit_width,cc3);
get_string((window_count-1),cap_bit_width,cc2);
cc_sel=5;
end
end
else if(trigger_position>1)
if(window_size>3)
if(window_count>0) begin
get_string((trigger_position-2),cap_bit_width,cc0);
get_string((window_size-2),cap_bit_width,cc1);
get_string((window_size-2),cap_bit_width,cc3);
get_string((window_count-1),cap_bit_width,cc2);
cc_sel=7;
end
$fdisplay(fd,"value");
$fdisplay(fd,"%s", {"==",cc0});
$fdisplay(fd,"%s", {"==",cc1});
$fdisplay(fd,"%s", {"==",cc2});
$fdisplay(fd,"%s", {"==",cc3});
$fdisplay(fd,"%d",cc_sel );
endtask
initial
#20 $finish;
endmodule