不枉初心,砥砺前行

皮皮祥的博客

欢迎留言,评论

导航

Program Block-systemverilog

systemverilog中的Program Block与module有些类似,但module是基于硬件思想,Program Block纯粹是为了仿真。如果不熟悉program,可以不用program.

The program block serves three basic purposes:

  • » It provides an entry point to the execution of testbenches.
  • » It creates a scope that encapsulates program-wide data.
  • » It provides a syntactic context that specifies scheduling in the Reactive region.

module test(...) int shared; // variable shared by programs p1 and p1
program p1; ...
endprogram
program p2;
...
endprogram // p1 and p2 are implicitly instantiated once in module testendmodule

Examp:
  1.  `timescale 1ns/1ps
  2. class frame_start;
  3. rand byte length = 64'habcdabc101023acd123;
  4. rand byte tag_frame_ma;
  5. byte Num;//octal number
  6. integer Tx_en;
  7. task frame();
  8. begin
  9. if ((length/Num) || (length > tag_frame_ma))
  10. $display ("\nReport the Tag frame error length = %d",length);
  11. else
  12. $display("\nReport Tag frame %d",length);
  13. end
  14. endtask
  15. endclass
  16. program sim_top();
  17. frame_start new_frame;
  18. integer transmission_enable = 0;// Transmission of frame. Frame Tx include data encapulation and Media Access Management
  19. task transmit(integer transmission_enable);
  20. if (transmission_enable)
  21. $display("\n@%g, Frame is ready to transmit",$time);
  22. else
  23. $display("\n@%g, Frame is not ready now to transmit",$time);
  24. endtask
  25. initial
  26. begin
  27. new_frame = new;
  28. $display("*******--------*********--------********--------********");
  29. #1 transmit(transmission_enable);
  30. #1 transmission_enable = 1;
  31. #1 transmit(transmission_enable);
  32. #1 new_frame.frame();
  33. #1 new_frame.randomize();
  34. #1 $display("\n@%g, Transmit next frame now...", $time);
  35. #1 $display("\n*******--------*********--------********--------********");
  36. end
  37. endprogram
output:
  1.  
    # *******--------*********--------********--------********
  2. #
  3. # @1, Frame is not ready now to transmit
  4. #
  5. # @3, Frame is ready to transmit
  6. #
  7. # Report the Tag frame error length = 35
  8. #
  9. # @6, Transmit next frame now...
  10. #
  11. # *******--------*********--------********--------********


posted on 2022-10-04 18:36  皮皮祥  阅读(63)  评论(0编辑  收藏  举报