• 【uvm】How to write uvm sequence


    Most important properties of a sequence are,

    • body method
    • m_sequencer handle

    body Method:

    body method defines, what the sequence does.

    m_sequencer Handle:

    The m_sequencer handle contains the reference to the sequencer on which the sequence is running.

    The sequence will get executed upon calling the start of the sequence from the test.

    sequence_name.start(sequencer_name);
    sequencer_name specifies on which sequencer sequence has to run.

    • There are Methods, macros and pre-defined callbacks associated with uvm_sequence.
    • Users can define the methods(task or function) to pre-defined callbacks. these methods will get executed automatically upon calling the start of the sequence.
    • These methods should not be called directly by the user.
      Below block diagram shows the order in which the methods will get called on calling the start of a sequence.

    在这里插入图片描述

    * mid_do and post_do are functions, All other are tasks

    Starting The Sequence:

    Logic to generate and send the sequence_item will be written inside the body() method of the sequence.
    The handshake between the sequence, sequencer and driver to send the sequence_item is given below.
    在这里插入图片描述

    sequence driver communication

    Communication between the Sequence and driver involves below steps,
    1.create_item() / create req.
    2.wait_for_grant().
    3.randomize the req.
    4.send the req.
    5.wait for item done.
    6.get response.

    • Step 5 and 6 are optional.

    seq driver communication without response stage
    在这里插入图片描述

    Writing UVM Sequence

    class mem_sequence extends uvm_sequence#(mem_seq_item);
       
      `uvm_object_utils(mem_sequence)
        
      //Constructor
      function new(string name = "mem_sequence");
        super.new(name);
      endfunction
       
      virtual task body();
     
        req = mem_seq_item::type_id::create("req");  //create the req (seq item)
        wait_for_grant();                            //wait for grant
        assert(req.randomize());                     //randomize the req                   
        send_request(req);                           //send req to driver
        wait_for_item_done();                        //wait for item done from driver
        get_response(rsp);                           //get response from driver
     
      endtask
    endclass
    

    Note: assert(req.randomize());, will return the assertion error on randomization failure.

    UVM Sequence macros

    These macros are used to start sequences and sequence items on default sequencer, m_sequencer.在这里插入图片描述

    Writing the sequence using Macro’s

    `UVM_DO()

    class mem_sequence extends uvm_sequence#(mem_seq_item);
       
      `uvm_object_utils(mem_sequence)
        
      //Constructor
      function new(string name = "mem_sequence");
        super.new(name);
      endfunction
       
      virtual task body();
        `uvm_do(req)
      endtask
       
    endclass
    

    `UVM_CREATE() AND `UVM_SEND()

    class mem_sequence extends uvm_sequence#(mem_seq_item);
       
      `uvm_object_utils(mem_sequence)
        
      //Constructor
      function new(string name = "mem_sequence");
        super.new(name);
      endfunction
       
      virtual task body();
        `uvm_create(req)
        assert(req.randomize());
        `uvm_send(req);
      endtask
       
    endclass
    

    `UVM_RAND_SEND()

    class mem_sequence extends uvm_sequence#(mem_seq_item);
       
      `uvm_object_utils(mem_sequence)
        
      //Constructor
      function new(string name = "mem_sequence");
        super.new(name);
      endfunction
       
      virtual task body();
        `uvm_create(req)
        `uvm_rand_send(req)
      endtask
       
    endclass
    

    `UVM_DO_WITH()

    class write_sequence extends uvm_sequence#(mem_seq_item);
       
      `uvm_object_utils(write_sequence)
        
      //Constructor
      function new(string name = "write_sequence");
        super.new(name);
      endfunction
       
      virtual task body();
        `uvm_do_with(req,{req.wr_en == 1;})
      endtask
       
    endclass
    

    `UVM_RAND_SEND_WITH()

    class read_sequence extends uvm_sequence#(mem_seq_item);
       
      `uvm_object_utils(read_sequence)
        
      //Constructor
      function new(string name = "read_sequence");
        super.new(name);
      endfunction
       
      virtual task body();
        `uvm_create(req)
        `uvm_rand_send_with(req,{req.rd_en == 1;})
      endtask
       
    endclass
    

    CALLING SEQUENCE’S INSIDE THE SEQUENCE

    class wr_rd_seq extends uvm_sequence#(mem_seq_item);
       
      write_sequence wr_seq;
      read_sequence  rd_seq;
       
      `uvm_object_utils(wr_rd_seq)
        
      //Constructor
      function new(string name = "wr_rd_seq");
        super.new(name);
      endfunction
       
      virtual task body();
        `uvm_do(wr_seq)
        `uvm_do(rd_seq)
      endtask
       
    endclass
    

    difference between m_sequencer and p_sequencer:

    m_sequencer,

    The m_sequencer handle contains the reference to the sequencer(default sequencer) on which the sequence is running.
    This is determined by,

    • the sequencer handle provided in the start method
    • the sequencer used by the parent sequence
    • the sequencer that was set using the set_sequencer method

    p_sequencer,

    The p_sequencer is a variable, used as a handle to access the sequencer properties.
    p_sequencer is defined using the macro
    `uvm_declare_p_sequencer(SEQUENCER_NAME)

    Link

  • 相关阅读:
    统计学习方法-感知机
    两种K线形态预示今日伦敦银走向
    Python 小贴士(3)
    【LVGL】弹性布局(Flex)学习
    [力扣] 剑指 Offer 第一天 - 包含min函数的栈
    2024-7-9 Windows NDK,Clion,C4droid 编译环境配置(基础|使用命令编译,非AndroidStudio),小白(记录)友好型教程
    Python学习基础笔记十二——文件
    grafana 配置自定义dashboard
    Java的继承
    初学者如何打开ABAQUS力学有限元仿真的大门
  • 原文地址:https://blog.csdn.net/weixin_39060517/article/details/127122925