hdlc_receive_code.rar
源代码在线查看: testhdlc.v
///////////////////////////////////////////////// //If you have any question about this testbench //please get in touch with me: llbt24@zju.edu.cn // // // ///////////////////////////////////////////////// `timescale 1ns/1ns module testHDLC; reg RXD,RXCLK,RESET; wire TXCLK; wire[7:0] TXD; wire[2:0] TXDS; reg isfix; reg[7:0] bytedate; reg[2:0] bytekind; reg iswrong; reg isinsert; integer RXDOUT; integer insertnum; integer bittest; integer bitstream; integer bytecount; integer framecount; integer TXD_REF_int; integer TXDS_REF_int; integer seednum; reg[7:0] TXD_REF; reg[2:0] TXDS_REF; hdlc_recv instance(RXD,RXCLK,RESET,TXD,TXCLK,TXDS); //HDLC instance(RXD,RXCLK,RESET,TXD,TXCLK,TXDS); always #10 RXCLK=!RXCLK; initial begin RESET=1; RXCLK=0; RXD=1; isfix=0; bytedate=0; bytekind=0; iswrong=0; bitstream=0; bytecount=0; framecount=0; isinsert=1; TXD_REF=0; TXDS_REF=0; $hello; #20 RESET=0; #20 RESET=1; seednum=21; $seed(seednum); #70 task_flag_gen; framecount=framecount+1; //framecount=1; isfix=1; bytedate=8'h23; bytekind=3'b110; task_byte_fix; task_byte_gen; //1-5 isfix=1; bytedate=8'h67; bytekind=3'b101; task_byte_fix; task_byte_gen; isfix=0; bytedate=8'h00; bytekind=3'b100; task_byte_fix; task_byte_gen; isfix=1; bytedate=8'h8F; bytekind=3'b100; task_byte_fix; task_byte_gen; isfix=1; bytedate=8'hFE; bytekind=3'b100; task_byte_fix; task_byte_gen; isfix=1; bytedate=8'h7F; bytekind=3'b100; task_byte_fix; task_byte_gen; //6-10 isfix=0; bytedate=8'h00; bytekind=3'b100; task_byte_fix; task_byte_gen; isfix=1; bytedate=8'hC3; bytekind=3'b100; task_byte_fix; task_byte_gen; isfix=1; bytedate=8'hE7; bytekind=3'b100; task_byte_fix; task_byte_gen; isfix=1; bytedate=8'h10; bytekind=3'b100; task_byte_fix; task_byte_gen; isfix=1; bytedate=8'h3F; bytekind=3'b011; task_byte_fix; task_byte_gen; //11-15 // task_flag_gen; // insertnum=11; task_ones_insert; task_flag_gen; framecount=framecount+1; //framecount=2; isfix=0; bytedate=8'h00; bytekind=3'b110; task_byte_fix; task_byte_gen; //1-5 isfix=1; bytedate=8'h03; bytekind=3'b101; task_byte_fix; task_byte_gen; isfix=1; bytedate=8'hF2; bytekind=3'b010; task_byte_fix; task_byte_gen; task_flag_gen; task_flag_gen; task_flag_gen; // insertnum=2; task_ones_insert; task_flag_gen; framecount=framecount+1; //framecount=3; isfix=1; bytedate=8'h45; bytekind=3'b010; task_byte_fix; task_byte_gen; //1-5 task_flag_gen; insertnum=0; task_ones_insert; task_flag_gen; framecount=framecount+1; //framecount=4; isfix=0; bytedate=8'h00; bytekind=3'b110; task_byte_fix; task_byte_gen; //1-5 isfix=1; bytedate=8'h7E; bytekind=3'b101; task_byte_fix; task_byte_gen; isfix=1; bytedate=8'hF7; bytekind=3'b100; task_byte_fix; task_byte_gen; isfix=1; bytedate=8'h7E; bytekind=3'b011; task_byte_fix; task_byte_gen; task_flag_gen; insertnum=21; task_ones_insert; task_flag_gen; framecount=framecount+1; //framecount=5; isfix=1; bytedate=8'h37; bytekind=3'b110; task_byte_fix; task_byte_gen; //1-5 isfix=0; bytedate=8'h00; bytekind=3'b101; task_byte_fix; task_byte_gen; repeat(61) begin isfix=0; bytedate=8'h00; bytekind=3'b100; task_byte_fix; task_byte_gen; //3-63 end isfix=1; bytedate=8'h1F; bytekind=3'b011; task_byte_fix; task_byte_gen; //64 task_flag_gen; insertnum=5; task_ones_insert; task_flag_gen; framecount=framecount+1; //framecount=6; isfix=1; bytedate=8'h37; bytekind=3'b110; task_byte_fix; task_byte_gen; //1-5 isfix=0; bytedate=8'h00; bytekind=3'b101; task_byte_fix; task_byte_gen; repeat(62) begin isfix=0; bytedate=8'h00; bytekind=3'b100; task_byte_fix; task_byte_gen; //3-64 end isfix=1; bytedate=8'h56; bytekind=3'b001; task_byte_fix; task_byte_gen; //65 task_flag_gen; insertnum=3; task_ones_insert; task_flag_gen; framecount=framecount+1; //framecount=7; isfix=0; bytedate=8'h00; bytekind=3'b110; task_byte_fix; task_byte_gen; //1-5 isfix=1; bytedate=8'h3E; bytekind=3'b010; task_byte_fix; task_byte_gen; task_flag_gen; insertnum=20; task_ones_insert; task_flag_gen; framecount=framecount+1; //framecount=8; isfix=1; bytedate=8'h54; bytekind=3'b110; task_byte_fix; task_byte_gen; //1-5 isfix=0; bytedate=8'h00; bytekind=3'b101; task_byte_fix; task_byte_gen; repeat(125) begin isfix=0; bytedate=8'h00; bytekind=3'b100; task_byte_fix; task_byte_gen; //3-127 end isfix=1; bytedate=8'h5D; bytekind=3'b001; task_byte_fix; task_byte_gen; //128 task_flag_gen; insertnum=7; task_ones_insert; task_flag_gen; framecount=framecount+1; isinsert=0; //framecount=9; isfix=1; bytedate=8'h37; bytekind=3'b110; task_byte_fix; task_byte_gen; //1-5 isfix=1; bytedate=8'h17; bytekind=3'b101; task_byte_fix; task_byte_gen; isfix=1; bytedate=8'hEC; bytekind=3'b111; task_byte_fix; task_byte_gen; isinsert=1; isfix=1; bytedate=8'h32; bytekind=3'b111; task_byte_fix; task_byte_gen; isfix=0; bytedate=8'h00; bytekind=3'b111; task_byte_fix; task_byte_gen; task_flag_gen; insertnum=2; task_ones_insert; task_flag_gen; framecount=framecount+1; //framecount=10; isfix=1; bytedate=8'h34; bytekind=3'b110; task_byte_fix; task_byte_gen; //1-5 isfix=1; bytedate=8'h5A; bytekind=3'b101; task_byte_fix; task_byte_gen; isfix=0; bytedate=8'h00; bytekind=3'b100; task_byte_fix; task_byte_gen; isfix=0; bytedate=8'h00; bytekind=3'b100; task_byte_fix; task_byte_gen; isfix=0; bytedate=8'h00; bytekind=3'b100; task_byte_fix; task_byte_gen; isfix=1; bytedate=8'hC6; bytekind=3'b011; task_byte_fix; task_byte_gen; //6-10 task_flag_gen; insertnum=11; task_ones_insert; $finish; end always @(posedge RXCLK) task_display_RXD; always @(negedge TXCLK) begin $readresult(TXD_REF_int,TXDS_REF_int); TXD_REF=TXD_REF_int; TXDS_REF=TXDS_REF_int; // if(TXD==TXD_REF&&TXDS==TXDS_REF) // $display("Current byte is OK\n"); // else // $display("Current byte is WRONG\n"); end task task_flag_gen; begin bytecount=0; #1 $display("------------------------\n"); $display("\tnew flag\n"); $display("------------------------\n"); repeat(8) @(negedge RXCLK) begin $flag(RXDOUT); RXD=RXDOUT; end #10; end endtask task task_ones_insert; begin #1 $display("************************\n"); $display("\tones_insert\n"); $display("************************\n"); repeat(insertnum) @(negedge RXCLK) RXD=1; if(insertnum) #10; end endtask task task_byte_fix; $fix(isfix,bytedate,bytekind); endtask task task_byte_gen; begin bytecount=bytecount+1; #1 $display("^^^^^^^^^^^^^^^^^^^^^^^^\n"); $display("\tnew byte %0d-%0d\n",framecount,bytecount); $display("^^^^^^^^^^^^^^^^^^^^^^^^\n"); while(bitstream @(negedge RXCLK) begin $stuff(bittest); if(isinsert&&bittest) begin RXD=iswrong; $display("--the next bit is bitstuff--\n"); end else begin $byte(RXDOUT); RXD=RXDOUT; bitstream=bitstream+1; end end bitstream=0; #10; end endtask task task_display_RXD; $display("At time: %0t\t\t",$time,"RXD=%b",RXD); endtask endmodule