📄 rs_decoder_v3_0.v
字号:
err_found_out<=0;err_found_sig<=0;fail_out<=0;fail_sig<=0;blk_strt_out<=0;blk_strt_sig<=0;blk_end_out<=0;blk_end_sig<=0;ready_out<=1;ready_dc=0;index<=-1;index_out<=0;input_count<=-1;init_erase_locator;for(i=0;i<=IILL10000OllL0OI1lLI0I0IO0+1;i=i+1)begin funnv_shift[i]<=1'b0;funny_shift[i]<=1'b0;end end endtask task reset_code_buf;integer i;begin for(i=0;i<=IILL10000OllL0OI1lLI0I0IO0;i=i+1)code_buff_in[i]<=0;end endtask task reset_proc;begin ce_d<=0;erase_d<=0;data_in_d<=0;sync_d<=0;sync_db<=0;start<=0;flag_funny<=0;flag_funnv<=0;flag_funny_d<=0;flag_funnv_d<=0;end endtask assign#(IIl0II0O0LII0LlLlIl1LO1O0I)ERR_CNT=err_cnt_out;assign#(IIl0II0O0LII0LlLlIl1LO1O0I)ERR_FOUND=err_found_out;assign#(IIl0II0O0LII0LlLlIl1LO1O0I)FAIL=fail_out;assign#(IIl0II0O0LII0LlLlIl1LO1O0I)BLK_STRT=blk_strt_out;assign#(IIl0II0O0LII0LlLlIl1LO1O0I)BLK_END=blk_end_out;assign#(IIl0II0O0LII0LlLlIl1LO1O0I)ERASE_CNT=erase_cnt_out;assign#(IIl0II0O0LII0LlLlIl1LO1O0I)READY=ready_out;assign#(IIl0II0O0LII0LlLlIl1LO1O0I)DATA_OUT=data_out_out;assign#(IIl0II0O0LII0LlLlIl1LO1O0I)DATA_DEL=data_del_out;always@(CLK or posedge RESET or pwr_on_reset)begin if(RESET||pwr_on_reset)begin sync_bit<=0;sym_clk<=0;flag_funny<=0;flag_funnv<=0;end else if(C_CLKS_PER_SYM==1)begin flag_funny<=0;flag_funnv<=0;end else begin if(CLK)begin sync_bit<=SYNC;if(sync_bit==0&&SYNC==1)begin if(sym_clk!=0)begin if(input_count!=-1)begin if(input_count<IILL10000OllL0OI1lLI0I0IO0-1)$display("** Warning in %m at %dns. Resynchronization before code word output! Accuracy of model not guaranteed. Expect erroneous behavior in real circuit!",$time);end end if(sym_clk==C_CLKS_PER_SYM-2)begin if(C_CLKS_PER_SYM==2)flag_funnv<=0;else flag_funny<=1;end else if(sym_clk==C_CLKS_PER_SYM-1&&(CE==1||C_HAS_CE==0))flag_funnv<=1;else flag_funnv<=0;if(ce_d==1||C_HAS_CE==0)begin sym_clk<=1;end end else begin flag_funny<=0;if(sym_clk==C_CLKS_PER_SYM-1&&(CE==1||C_HAS_CE==0))flag_funnv<=0;if(sym_clk==C_CLKS_PER_SYM-1)sym_clk<=0;else sym_clk<=sym_clk+1;end end end end always@(CLK or posedge RESET or pwr_on_reset)begin if(RESET||pwr_on_reset)begin reset_proc;if(IO10IIlO0III0LO01lLI0L1I10==1'b0)code_buff_in[0]<=0;else begin code_buff_in[IILL10000OllL0OI1lLI0I0IO0]<=0;end if(C_HAS_CE==0)begin@(RESET or pwr_on_reset or posedge CLK)if((RESET||pwr_on_reset)&&CLK)begin if((sym_clk==C_CLKS_PER_SYM-1)||flag_funny||(C_CLKS_PER_SYM==1))begin if(IO10IIlO0III0LO01lLI0L1I10==1'b0)for(i=0;i<=IILL10000OllL0OI1lLI0I0IO0-1;i=i+1)code_buff_in[i+1]<=code_buff_in[i];else begin for(i=0;i<IILL10000OllL0OI1lLI0I0IO0-1;i=i+1)code_buff_in[i+1]<=code_buff_in[i];code_buff_in[0]<=db_to_normal[data_in_d];end end end else if(RESET==0)begin start<=1;end end end else begin start<=1;if(CLK)begin if((sym_clk==C_CLKS_PER_SYM-1)||flag_funny||(C_CLKS_PER_SYM==1))begin data_in_d<=DATA_IN;sync_d<=SYNC;ce_d<=CE;sr_d<=SR;if(C_HAS_ERASE!=0)erase_d<=ERASE;if(IO10IIlO0III0LO01lLI0L1I10==1'b0)code_buff_in[0]<=DATA_IN;if(ce_d==1||C_HAS_CE==0)begin if(sr_d==1&&C_HAS_SR==1)sync_db<=0;else sync_db<=sync_d;if(IO10IIlO0III0LO01lLI0L1I10==1'b1)begin data_in_d_var=db_to_normal[data_in_d];code_buff_in[0]<=data_in_d_var;data_in_db<=data_in_d_var;if(C_HAS_ERASE!=0)erase_db<=erase_d;end for(i=0;i<=IILL10000OllL0OI1lLI0I0IO0-1;i=i+1)code_buff_in[i+1]<=code_buff_in[i];end end end end end assign data_in_d_sig=(IO10IIlO0III0LO01lLI0L1I10==1'b1)?data_in_db:data_in_d;assign sync_d_sig=(IO10IIlO0III0LO01lLI0L1I10==1'b1)?sync_db:sync_d;assign erase_d_sig=(IO10IIlO0III0LO01lLI0L1I10==1'b1)?erase_db:erase_d;always@(CLK or RESET or pwr_on_reset)begin if(RESET||pwr_on_reset)begin reset_proc2;reset_cnt<=C_N;if(C_HAS_CE==0)begin@(RESET or pwr_on_reset or posedge CLK)if((RESET||pwr_on_reset)&&CLK)begin if((sym_clk==C_CLKS_PER_SYM-1)||flag_funny||(C_CLKS_PER_SYM==1))begin data_out_db<=code_buff_in[IILL10000OllL0OI1lLI0I0IO0];data_del_db<=code_buff_in[IILL10000OllL0OI1lLI0I0IO0];end end end end else begin if(start)begin if(CLK==1)begin if(ce_d==1||C_HAS_CE==0)begin if((sym_clk==C_CLKS_PER_SYM-1)||(flag_funny==1)||(C_CLKS_PER_SYM==1))begin if(sr_d==1&&C_HAS_SR==1)begin reset_proc3;index<=-1;sr_flag=1;if(IO10IIlO0III0LO01lLI0L1I10==1'b1)begin data_out_out<=normal_to_db[data_out_db];if(reset_high_cnt>1)begin data_out_db<=code_buff_in[IILL10000OllL0OI1lLI0I0IO0];end else begin data_out_db<=data_out_shift[0];end if(C_HAS_DATA_DEL!=0)begin data_del_out<=normal_to_db[data_del_db];data_del_db<=code_buff_in[IILL10000OllL0OI1lLI0I0IO0];end end else begin if(reset_high_cnt>0)begin data_out_out<=code_buff_in[IILL10000OllL0OI1lLI0I0IO0-1];end else begin data_out_out<=data_out_shift[0];end if(C_HAS_DATA_DEL!=0)data_del_out<=code_buff_in[IILL10000OllL0OI1lLI0I0IO0-1];end if(index_out>0)index_out<=index_out-1;reset_cnt<=C_N;reset_high_cnt<=reset_high_cnt+1;end else begin reset_high_cnt<=0;if(CE==1||C_HAS_CE==0)flag_funny_d<=flag_funny;flag_funnv_d<=flag_funnv;if(flag_funnv==1&&flag_funnv_d==0)funnv_shift[0]<=1;else funnv_shift[0]<=0;if((flag_funny==1)&&(flag_funny_d==0)&&((CE==1)||C_HAS_CE==0))funny_shift[0]<=1;else funny_shift[0]<=0;for(i=0;i<=IILL10000OllL0OI1lLI0I0IO0;i=i+1)begin funnv_shift[i+1]<=funnv_shift[i];funny_shift[i+1]<=funny_shift[i];end if((index==0)&&(index_out==0))index_out<=C_N-1;else begin if(index_out>0)index_out<=index_out-1;else index_out<=0;end if(IO10IIlO0III0LO01lLI0L1I10==1'b1)begin if((flag_funnv_d==0)&&(funny_shift[1]==0))sync_dd<=sync_d_sig;end else begin if((flag_funnv==0)&&(flag_funny_d==0))sync_dd<=sync_d_sig;end if(index_out==0)sr_flag=0;if(reset_cnt<=-2000000000)reset_cnt<=reset_cnt;else reset_cnt<=reset_cnt-1;if((sync_dd==0)&&(sync_d_sig==1))begin index_var=C_N-1;if(((IO10IIlO0III0LO01lLI0L1I10==1'b0)&&(!(flag_funnv_d==0&&flag_funnv==1)&&!(flag_funny_d==1)))||((IO10IIlO0III0LO01lLI0L1I10==1'b1)&&(flag_funnv_d==0&&funny_shift[1]==0)))begin blk_strt_sig<=1;input_count<=1;end init_erase_locator;num_erasures=0;end else begin if(index>=0)index_var=index;else index_var=0;blk_strt_sig<=0;if(!(sync_dd==0&&sync_d==1)||(IO10IIlO0III0LO01lLI0L1I10==1'b0))begin if(input_count>-1&&input_count<2000000000)input_count<=input_count+1;end end fail_out<=fail_shift[0];err_found_out<=err_found_shift[0];err_cnt_out<=err_cnt_shift[0];blk_strt_out<=blk_strt_shift[0];blk_end_out<=blk_end_shift[0];if(C_HAS_ERASE!=0)erase_cnt_out<=erase_cnt_shift[0];gf_int=data_in_d_sig;r_ap[index_var]=gf_ap[gf_int];if(reset_cnt>IOI1L1I1OlLLOO1I1l011l0I1l)begin if(IO10IIlO0III0LO01lLI0L1I10==1'b1)begin if(reset_cnt<=C_N)begin data_out_db_var=code_buff_in[IILL10000OllL0OI1lLI0I0IO0];end else begin data_out_db_var=data_out_shift[0];end end else data_out_db_var=code_buff_in[IILL10000OllL0OI1lLI0I0IO0-1];end else if(funnv_shift[IO1L000LOl0OIOOlLO11IILlIO]==1||funny_shift[II0000OII1l1LLLOI1LL0Ll1OO]==1)data_out_db_var=code_buff_in[IILL10000OllL0OI1lLI0I0IO0-1];else data_out_db_var=data_out_shift[0];if(IO10IIlO0III0LO01lLI0L1I10==1'b1)begin data_out_out<=normal_to_db[data_out_db];data_out_db<=data_out_db_var;if(C_HAS_DATA_DEL!=0)begin data_del_out<=normal_to_db[data_del_db];data_del_db<=code_buff_in[IILL10000OllL0OI1lLI0I0IO0];end end else begin data_out_out<=data_out_db_var;if(C_HAS_DATA_DEL!=0)data_del_out<=code_buff_in[IILL10000OllL0OI1lLI0I0IO0-1];end if(erase_d_sig==1)begin update_erase_locator;num_erasures=num_erasures+1;end if(II0O1l1lOLl01LO1O0LI1OLlOI>0)begin if(((IO10IIlO0III0LO01lLI0L1I10==1'b1&&index==2)||(IO10IIlO0III0LO01lLI0L1I10==1'b0&&index==1))&&sync_d==0)ready_dc=II0O1l1lOLl01LO1O0LI1OLlOI;if(ready_dc>0)ready_out<=0;else ready_out<=1;ready_dc=ready_dc-1;end else ready_out<=1;if(index==0&&index_out==0)begin if(sr_flag==0||C_HAS_SR==0)get_syndromes;temp=0;temp2=0;temp3=0;temp4=0;temp7=0;temp8=0;gamma=0;num_errors_var=0;l=num_erasures;for(i=IOLOIL0I0lIL0I0lO11IOL1110;i>=0;i=i-1)begin lambda_var[i]=erase_locator[i];b_var[i]=erase_locator[i];end for(i=1+num_erasures;i<=IIIIl00OII0lOOL0010L1OOLOI;i=i+1)begin discrep=-1;for(j=0;j<=(i-1);j=j+1)begin if(j<=IOLOIL0I0lIL0I0lO11IOL1110)begin temp=gf_mult(lambda_var[j],syndromes[i-1-j]);discrep=gf_add(discrep,temp);end end if((discrep!=-1)&&(2*l<=i-1+num_erasures))delta=1;else delta=0;for(j=IOLOIL0I0lIL0I0lO11IOL1110;j>=0;j=j-1)begin if(j==0)temp2=-1;else temp2=gf_mult(b_var[j-1],discrep);temp3=gf_mult(lambda_var[j],gamma);temp_poly[j]=gf_add(temp3,temp2);end for(j=IOLOIL0I0lIL0I0lO11IOL1110;j>=0;j=j-1)begin if(delta==1)b_var[j]=lambda_var[j];else if(delta==0)begin if(j==0)b_var[j]=-1;else b_var[j]=b_var[j-1];end end for(z=0;z<=IOLOIL0I0lIL0I0lO11IOL1110;z=z+1)lambda_var[z]=temp_poly[z];if(delta==1)begin gamma=discrep;l=i+num_erasures-l;end end for(i=0;i<=II0I1OL0IOll111L0llLI10IL1;i=i+1)begin omega_var[i]=-1;for(j=0;j<=i;j=j+1)begin temp4=gf_mult(lambda_var[j],syndromes[i-j]);omega_var[i]=gf_add(omega_var[i],temp4);end end for(z=0;z<=II0I1OL0IOll111L0llLI10IL1;z=z+1)error_evaluator[z]=omega_var[z];for(z=0;z<=IOLOIL0I0lIL0I0lO11IOL1110;z=z+1)error_locator[z]=lambda_var[z];deg_cnt=l;for(z=0;z<=IOLOIL0I0lIL0I0lO11IOL1110;z=z+1)lambda_diff_var[z]=error_locator[z];for(i=0;i<=IOLOIL0I0lIL0I0lO11IOL1110;i=i+1)begin if(i%2==0)lambda_diff_var[i]=-1;end for(i=C_N-1;i>=0;i=i-1)begin deg_lambda=IOLOIL0I0lIL0I0lO11IOL1110;deg_omega=II0I1OL0IOll111L0llLI10IL1;lambda_value=-1;lambda_diff_value=-1;omega_value=-1;if(i==0)reciprocal=0;else reciprocal=IIlLLL10LllllLO0I1ILIIIO0L-i;reciprocal=(C_H*reciprocal)%IIlLLL10LllllLO0I1ILIIIO0L;while(deg_lambda>=0)begin substitute=0;for(j=deg_lambda;j>=1;j=j-1)substitute=gf_mult(substitute,reciprocal);temp7=gf_mult(substitute,lambda_diff_var[deg_lambda]);temp8=gf_mult(substitute,error_locator[deg_lambda]);lambda_diff_value=gf_add(lambda_diff_value,temp7);lambda_value=gf_add(lambda_value,temp8);deg_lambda=deg_lambda-1;end while(deg_omega>=0)begin substitute=0;for(j=deg_omega;j>=1;j=j-1)substitute=gf_mult(substitute,reciprocal);temp7=gf_mult(substitute,error_evaluator[deg_omega]);omega_value=gf_add(omega_value,temp7);deg_omega=deg_omega-1;end scaler=C_H*i*(-C_GEN_START);while(scaler<0)begin scaler=scaler+(1<<C_SYMBOL_WIDTH)-1;end omega_value=gf_mult(omega_value,scaler);if(lambda_value==-1)begin num_errors_var=num_errors_var+1;if(lambda_diff_value==0)reciprocal=0;else if(lambda_diff_value==-1)reciprocal=-1;else reciprocal=IIlLLL10LllllLO0I1ILIIIO0L-lambda_diff_value;errors[i]=gf_mult(omega_value,reciprocal);symbol_corrected[i]=1;end else begin errors[i]=-1;symbol_corrected[i]=0;end end if(sr_flag==0||C_HAS_SR==0)for(i=C_N-1;i>=0;i=i-1)begin corrected_message[i]=gf_add(r_ap[i],errors[i]);sym_int[i]<=gf_field[corrected_message[i]];end else for(i=C_N-1;i>=0;i=i-1)begin corrected_message[i]=r_ap[i];sym_int[i]<=gf_field[corrected_message[i]];end end else begin index<=index_var-1;end index_last<=index_out;if(index_out==0&&index==0)begin if(reset_cnt<2)begin err_cnt_sig<=num_errors_var;erase_cnt_sig<=num_erasures;if(deg_cnt!=0)err_found_sig<=1;else err_found_sig<=0;if((num_errors_var!=deg_cnt)&&(deg_cnt!=-1))fail_sig<=1;else fail_sig<=0;end else begin fail_sig<=0;err_found_sig<=0;end blk_end_sig<=1;end else blk_end_sig<=0;end end end end end end end always@(CLK or RESET or pwr_on_reset)begin if(RESET==1||pwr_on_reset)begin if(IO10IIlO0III0LO01lLI0L1I10==1'b1)data_out_shift[0]=IIlLlLL1O1l0I0Ll0lLILlIOO1;for(i=IIO1lL0IOL000IOOl11IL11IlI;i>=0;i=i-1)begin blk_strt_shift[i]<=0;blk_end_shift[i]<=0;fail_shift[i]<=0;err_found_shift[i]<=0;err_cnt_shift[i]<=0;erase_cnt_shift[i]<=0;end end else begin if(CLK==1&&(ce_d==1||C_HAS_CE==0))begin if(sym_clk==C_CLKS_PER_SYM-1||flag_funny==1||C_CLKS_PER_SYM==1)begin if(sr_d&&C_HAS_SR==1)begin for(i=IIO1lL0IOL000IOOl11IL11IlI;i>=0;i=i-1)begin blk_strt_shift[i]<=0;blk_end_shift[i]<=0;fail_shift[i]<=0;err_found_shift[i]<=0;err_cnt_shift[i]<=0;erase_cnt_shift[i]<=0;end data_out_shift[IOOLLI0OlILIOIO10lIlL11L1O]<=code_buff_in[C_N];for(i=IOOLLI0OlILIOIO10lIlL11L1O;i>0;i=i-1)data_out_shift[i-1]<=data_out_shift[i];end else begin if(index_out==0&&index_last==0)data_out_shift[IOOLLI0OlILIOIO10lIlL11L1O]<=code_buff_in[C_N];else data_out_shift[IOOLLI0OlILIOIO10lIlL11L1O]<=sym_int[index_out];blk_strt_shift[IIO1lL0IOL000IOOl11IL11IlI]<=blk_strt_sig;blk_end_shift[IIO1lL0IOL000IOOl11IL11IlI]<=blk_end_sig;err_found_shift[IIO1lL0IOL000IOOl11IL11IlI]<=err_found_sig;fail_shift[IIO1lL0IOL000IOOl11IL11IlI]<=fail_sig;err_cnt_shift[IIO1lL0IOL000IOOl11IL11IlI]<=err_cnt_sig;erase_cnt_shift[IIO1lL0IOL000IOOl11IL11IlI]<=erase_cnt_sig;for(i=IOOLLI0OlILIOIO10lIlL11L1O;i>0;i=i-1)data_out_shift[i-1]<=data_out_shift[i];for(i=IIO1lL0IOL000IOOl11IL11IlI;i>0;i=i-1)begin blk_strt_shift[i-1]<=blk_strt_shift[i];err_cnt_shift[i-1]<=err_cnt_shift[i];erase_cnt_shift[i-1]<=erase_cnt_shift[i];fail_shift[i-1]<=fail_shift[i];err_found_shift[i-1]<=err_found_shift[i];blk_end_shift[i-1]<=blk_end_shift[i];end end end end end end// synopsys_translate_on // synthesis attribute GENERATOR_DEFAULT of RS_DECODER_V3_0 is "generatecore com.xilinx.ip.rs_decoder_v3_0.rs_decoder_v3_0" // box_type "black_box" // synthesis attribute box_type of RS_DECODER_V3_0 is "black_box" endmodule
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -