您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

5 个月前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. class axi_drv extends uvm_driver#(axi_tx);
  2. virtual axi_intf vif;
  3. `uvm_component_utils(axi_drv)
  4. `NEW_COMP
  5. function void build_phase(uvm_phase phase);
  6. super.build_phase(phase);
  7. if(!uvm_config_db#(virtual axi_intf)::get(this, "", "vif", vif)) begin
  8. `uvm_error("CONFG_DB", "Not able to get axi intf handle")
  9. end
  10. endfunction
  11. task run_phase(uvm_phase phase);
  12. @(negedge vif.arst);//waiting for release the reset
  13. forever begin
  14. seq_item_port.get_next_item(req);
  15. req.print();
  16. drive_tx(req);
  17. seq_item_port.item_done();
  18. end
  19. endtask
  20. task drive_tx(axi_tx tx);
  21. if (tx.wr_rd == 1) begin
  22. write_addr(tx);
  23. write_data(tx);
  24. write_resp(tx);
  25. end
  26. if (tx.wr_rd == 0) begin
  27. read_addr(tx);
  28. read_data(tx);
  29. end
  30. endtask
  31. task write_addr(axi_tx tx);
  32. `uvm_info("AXI_TX", "write_addr", UVM_MEDIUM);
  33. //Master drives all write address channel signals (aw), it will drive at the posedge of clock
  34. @(vif.mst_cb);
  35. vif.mst_cb.awaddr <= tx.addr;
  36. vif.mst_cb.awlen <= tx.burst_len;
  37. vif.mst_cb.awsize <= tx.burst_size;
  38. vif.mst_cb.awburst <= tx.burst_type;
  39. vif.mst_cb.awid <= tx.txid;
  40. vif.mst_cb.awvalid <= 1'b1;
  41. wait (vif.mst_cb.awready == 1'b1);
  42. @(vif.mst_cb);
  43. vif.mst_cb.awaddr <= 0;
  44. vif.mst_cb.awlen <= 0;
  45. vif.mst_cb.awsize <= 0;
  46. vif.mst_cb.awburst <= 0;
  47. vif.mst_cb.awid <= 0;
  48. vif.mst_cb.awvalid <= 0;
  49. endtask
  50. task write_data(axi_tx tx);
  51. `uvm_info("AXI_TX", "write_data", UVM_MEDIUM);
  52. for (int i = 0; i <= tx.burst_len; i++) begin
  53. @(vif.mst_cb)
  54. vif.mst_cb.wdata <= tx.dataQ.pop_front();
  55. vif.mst_cb.wstrb <= 4'b1111; //need to be updated as per the burst size
  56. vif.mst_cb.wvalid <= 1'b1;
  57. vif.mst_cb.wid <= tx.txid;
  58. //wlast=1 will be in last beat
  59. if(i == tx.burst_len) vif.mst_cb.wlast <= 1'b1;
  60. else vif.mst_cb.wlast <= 0;
  61. wait(vif.mst_cb.wready == 1'b1);
  62. end
  63. //once data beats are done, then reset all signals to 0
  64. @(vif.mst_cb);
  65. vif.mst_cb.wvalid <= 0;
  66. vif.mst_cb.wlast <= 0;
  67. vif.mst_cb.wdata <= 0;
  68. vif.mst_cb.wstrb <= 0;
  69. vif.mst_cb.wid <= 0;
  70. endtask
  71. task write_resp(axi_tx tx);
  72. bit bvalid_f = 0;
  73. //`uvm_info("AXI_TX", "write_resp", UVM_MEDIUM);
  74. //write response is initiated by slave
  75. while (bvalid_f == 0) begin
  76. @(vif.mst_cb);
  77. bvalid_f = vif.mst_cb.bvalid;
  78. end
  79. vif.mst_cb.bready <= 1'b1;
  80. @(vif.mst_cb);
  81. vif.mst_cb.bready <= 1'b0;
  82. endtask
  83. task read_addr(axi_tx tx);
  84. `uvm_info("AXI_TX", "read_addr", UVM_MEDIUM);
  85. @(vif.mst_cb);
  86. vif.mst_cb.araddr <= tx.addr;
  87. vif.mst_cb.arlen <= tx.burst_len;
  88. vif.mst_cb.arsize <= tx.burst_size;
  89. vif.mst_cb.arburst <= tx.burst_type;
  90. vif.mst_cb.arid <= tx.txid;
  91. vif.mst_cb.arvalid <= 1'b1;
  92. wait (vif.mst_cb.arready == 1'b1);
  93. @(vif.mst_cb);
  94. vif.mst_cb.araddr <= 0;
  95. vif.mst_cb.arlen <= 0;
  96. vif.mst_cb.arsize <= 0;
  97. vif.mst_cb.arburst <= 0;
  98. vif.mst_cb.arid <= 0;
  99. vif.mst_cb.arvalid <= 0;
  100. endtask
  101. task read_data(axi_tx tx);
  102. bit rvalid_f = 0;
  103. `uvm_info("AXI_TX", "read_data", UVM_MEDIUM);
  104. //since read data is happening multiple times, then handshaking should do multiple times
  105. for (int i = 0; i <= tx.burst_len; i++) begin
  106. rvalid_f = 0;
  107. while (rvalid_f == 0) begin
  108. @(vif.mst_cb);
  109. rvalid_f = vif.mst_cb.rvalid;
  110. vif.mst_cb.rready <= 1'b1;
  111. end
  112. end
  113. @(vif.mst_cb);
  114. vif.mst_cb.rready <= 1'b0;
  115. endtask
  116. endclass