Search code examples
system-veriloguvm

Pausing/restarting a sequence


I have a design that requires a pause in data traffic to enter a low power mode. Is there a way to pause the traffic generation sequence or driver to allow this happen? And then resume the sequence at a later time?

I currently have a flag in the sequence that I set to tell it to break the forever loop. However, that is not ideal, because the sequence finishes and then I have to restart it.


Solution

  • You could lock (or grab the sequencer) from a virtual sequence, eg:

    class virtual_seq extends uvm_sequence;
    
      `uvm_object_utils(virtual_zero_seq)
      `uvm_declare_p_sequencer(virtual_sequencer)
    
      function new(string name = "");
        super.new(name);
      endfunction: new
    
      task body;
        // start the normal traffic sequence
        normal_traffic_seq seq;
        seq = serial_fixed_seq::type_id::create("seq");
        if (! seq.randomize() ...
        seq.set_starting_phase(get_starting_phase());
        seq.start(p_sequencer.seqr, this);
    
        // when you're ready, lock the sequencer
        #12345;
        this.lock(p_sequencer.seqr);   // or grab
    
        // wait till you're ready to resume
        #12345; 
        // you could start another sequence on the same sequencer if you need to
        // if you do, you must input the reference to this virtual sequence in 
        // the sequence's start method, otherwise that sequence will be locked too
        // eg
        // power_down_seq.start(p_sequencer.seqr, this);
        //                                        ^^^^
    
        // when you're ready, start normal traffic again
        this.unlock(p_sequencer.seqr);   // or ungrab
      endtask : body
    
    endclass : virtual_zero_seq
    

    A grab is a higher priority lock. If multiple virtual sequences try to lock a sequencer, then they will gain access in the order they request it. If multiple virtual sequences try to grab a sequencer, if it is already locked (or grabbed), those virtual sequences will gain access to it on a last come first served basis.