VMM DATA_vm文件

VMM DATA_vm文件VMMDATAvmm_dataclassistobeusedtomodelalltransactionsintheinfrastructure.Itprovidesastandardsetofmethodsexpectedtobefoundinalltransactions.Alltransactionsinthever

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

VMM DATA

vmm_data class is to be used to model all transactions in the infrastructure . It provides a standard set of methods expected to be found in all transactions. All transactions in the verification environment inherit this object and override its main generic virtual tasks such as copy(), byte_pack(), byte_unpack(), compare() and psdisplay().

vmm_data has 3 unique identifiers for identifying transaction instance.

int stream_id;  // Stream identifier
int scenario_id;// Sequence identifier within stream
int data_id;    // instance identifier within sequence

This class is used to generate random, constraint random and directed transactions.

We will see the implementation of some methods.

Let us implement a simple packet using vmm_data.

Packet Specification
——————————-
Packet has DA,SA,Len and ….. few more feilds.
All the feilds are 8 bit.

1) Define a packet class by extending vmm_data

   class Packet extends vmm_data;

2) Define all the packet fields as rand variables

    rand bit [7:0] da;
    rand bit [7:0] sa;
    rand bit [7:0] length;
    ….
    ….

3) Constraint the rand variables based on the specification.

    constraint address_c {
da inside {
`P0,`P1,`P2,`P3}; }
    ….
    …..

4) Define psdisplay() method.
  
psdisplay() method displays the current value of the transaction or data described by this instance in a human-readable format on the standard output.

    virtual function string psdisplay(string prefix= “”);
         int i;

         $write(psdisplay,”   %s%s   da:0x%h\n”, psdisplay, prefix,this.da);
         $write(psdisplay,”   %s%s   sa:0x%h\n”, psdisplay, prefix,this.sa);
         $write(psdisplay,”   %s%s   length:0x%h (data.size=%0d)\n”, psdisplay, prefix,this.length,this.data.size());
         ………
         
    endfunction

5) Define copy() method.

copy() method copies the current value of the object instance to the specified object instance.

     virtual function vmm_data copy(vmm_data to= null);
         Packet cpy;
         cpy = new;
        
         super.copy_data(cpy);
        
         cpy.da =this.da;
         cpy.sa =this.sa;
         cpy.length = this.length;
         ………..
注:copy函数的返回值类型为vmm_data类,而不是扩展类类型,这是因为扩展类的虚函数必须跟其基类的函数相匹配,包括所有的参数和返回类型。

6) Define compare() method.

Compare method compares the current value of the object instance with the current value of the specified object instance.

    virtual function bitcompare(input vmm_data   to,outputstring diff,inputint   kind = 1);
        Packet cmp;
    
        compare =1; // Assume success by default.
        diff    = “No differences found”;
       
        // data types are the same, do comparison:
        if (this.da!= cmp.da)
        begin
           diff = $psprintf(“Different DA values: %b != %b”,this.da, cmp.da);
           compare = 0;
        end
         
        if (this.sa!= cmp.sa)
        begin
           diff = $psprintf(“Different SA values: %b != %b”,this.sa, cmp.sa);
           compare = 0;
        end
        ……..
        ……..

7) Define byte_pack() method.

   byte_pack() method Packs the content of the transaction or data into the specified dynamic array of bytes.

   virtual function intunsigned byte_pack(
                     ref logic [7:0] bytes[],
                     input int unsigned offset=0 ,
                     input int   kind = 1);
      byte_pack = 0;
      bytes = new[this.data.size()+ 4];
      bytes[0]= this.da;
      bytes[1]= this.sa;
      bytes[2]= this.length;
      ……..
      ……..

8) Define byte_unpack() method.

   byte_unpack() method unpacket the array in to different data feilds.

    virtual function intunsigned byte_unpack(
                     const ref logic[7:0] bytes[],
                     input int unsigned offset= 0,
                     input int len = 1,
                     input int kind = 1);
      this.da= bytes[0];
      this.sa= bytes[1];
      this.length= bytes[2];
      ………
      ………

  Complete Packet Class 

class Packet extends vmm_data;

static vmm_log log = new(“Packet”,“Class”);

rand bit [7:0] length;
rand bit [7:0] da;
rand bit [7:0] sa;
rand bit [7:0]data[];//Payload using Dynamic array,size is generated on the fly
rand byte fcs;

constraint payload_size_c {
data.sizeinside {
[1: 6]};}

function new();
     super.new(this.log);
endfunction:new

virtual function vmm_data allocate();
     Packet pkt;
     pkt = new();
     return pkt;
endfunction:allocate

virtual function string psdisplay(string prefix= “”);
    int i;

    $write(psdisplay,”   %s   packet #%0d.%0d.%0d\n”, prefix,this.stream_id,this.scenario_id,this.data_id);
    $write(psdisplay,”   %s%s   da:0x%h\n”, psdisplay, prefix,this.da);
    $write(psdisplay,”   %s%s   sa:0x%h\n”, psdisplay, prefix,this.sa);
    $write(psdisplay,”   %s%s   length:0x%h (data.size=%0d)\n”, psdisplay, prefix,this.length,this.data.size());
    $write(psdisplay,”   %s%s   data[%0d]:0x%h”, psdisplay, prefix,0,data[0]);
    if(data.size()> 1)
        $write(psdisplay,”   data[%0d]:0x%h”,1,data[1]);
    if(data.size()> 4)
        $write(psdisplay,”  ….  “);
    if(data.size()> 2)
        $write(psdisplay,”   data[%0d]:0x%h”,data.size()2,data[data.size()2]);
    if(data.size()> 3)
        $write(psdisplay,”   data[%0d]:0x%h”,data.size()1,data[data.size()1]);
    $write(psdisplay,“\n   %s%s   fcs:0x%h \n”, psdisplay, prefix,this.fcs);
   
endfunction

virtual function vmm_data copy(vmm_data to= null);
    Packet cpy;

    // Copying to a new instance?
    if (to == null)
       cpy = new;
     else

    // Copying to an existing instance. Correct type?
    if (!$cast(cpy, to))   
       begin
       `vmm_fatal(this.log,“Attempting to copy to a non packet instance”);
       copy = null;
       return copy;
       end
   

    super.copy_data(cpy);
   
    cpy.da =this.da;
    cpy.sa =this.sa;
    cpy.length =this.length;
    cpy.data= new[this.data.size()];
    foreach(data[i])
        begin
       cpy.data[i]= this.data[i];
        end                   
    cpy.fcs =this.fcs;
    copy = cpy;
endfunction:copy

virtual function bitcompare(input vmm_data   to,outputstring diff,inputint   kind = 1);
    Packet cmp;

    compare =1; // Assume success by default.
    diff    = “No differences found”;
   
    if (!$cast(cmp, to))
    begin
       `vmm_fatal(this.log,“Attempting to compare to a non packet instance”);
       compare =0;
       diff = “Cannot compare non packets”;
       return compare;
     end

    // data types are the same, do comparison:
    if (this.da!= cmp.da)
    begin
       diff = $psprintf(“Different DA values: %b != %b”,this.da, cmp.da);
       compare =0;
       return compare;
    end
     
    if (this.sa!= cmp.sa)
    begin
       diff = $psprintf(“Different SA values: %b != %b”,this.sa, cmp.sa);
       compare =0;
       return compare;
    end
    if (this.length!= cmp.length)
    begin
       diff = $psprintf(“Different LEN values: %b != %b”,this.length, cmp.length);
       compare =0;
       return compare;
    end

    foreach(data[i])
       if (this.data[i]!= cmp.data[i])
       begin
          diff = $psprintf(“Different data[%0d] values: 0x%h != 0x%h”,i,this.data[i], cmp.data[i]);
          compare = 0;
          return compare;
       end
    if (this.fcs!= cmp.fcs)
    begin
       diff = $psprintf(“Different FCS values: %b != %b”,this.fcs, cmp.fcs);
       compare =0;
       return compare;
    end
endfunction:compare

virtual function intunsigned byte_pack(
                     ref logic [7:0] bytes[],
                     input int unsigned offset=0 ,
                     input int   kind = 1);
      byte_pack = 0;
      bytes = new[this.data.size()+ 4];
      bytes[0]= this.da;
      bytes[1]= this.sa;
      bytes[2]= this.length;

      foreach(data[i])
          bytes[3+i]= data[i];

      bytes[this.data.size()+ 3 ] = fcs;
      byte_pack = this.data.size()+ 4;
endfunction:byte_pack    

virtual function intunsigned byte_unpack(
                     const ref logic[7:0] bytes[],
                     input int unsigned offset= 0,
                     input int len = 1,
                     input int kind = 1);
      this.da= bytes[0];
      this.sa= bytes[1];
      this.length= bytes[2];
      this.fcs= bytes[bytes.size()1];
      this.data= new[bytes.size() 4];
      foreach(data[i])
      this.data[i]= bytes[i+3];
      return bytes.size();
endfunction:byte_unpack

endclass

   Vmm_data Methods 

      virtual function string psdisplay( string prefix= “” );
      virtual function bit is_valid( bit silent= 1,int kind = 1);
      virtual function vmm_data allocate ();
      virtual function vmm_data copy ( vmm_data to= null);
      virtual function bitcompare (
      input vmm_data to,output string diff, input int kind= 1);
      function void display(string prefix= “”);
      virtual protected functionvoid copy_data ( vmm_data to );
      virtual function intunsigned byte_pack (
      ref logic [7:0] bytes[ ], int unsigned offset= 0,int kind = 1);
      virtual function intunsigned byte_unpack (
      const ref logic[7:0] bytes[ ], input intunsigned offset = 0,
      input int len = 1,input int kind = 1 );
      virtual function intunsigned byte_size ( int kind = 1);
      virtual function intunsigned max_byte_size ( int kind = 1);
      virtual function void save( int file);
      virtual function bit load( int file);

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/190602.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • java属于什么语言_java是什么语言 ?是什么系统?

    java属于什么语言_java是什么语言 ?是什么系统?一开始了解计算机这个专业,大家都会经常性听到Java这一词语,那么大家有真正的了解什么是Java吗?Java是属于什么语言呢?JAVA语言,其实是混合型的一种语言,Java语言是一个支持网络计算的面向对象程序设计语言。Java语言吸收了Smalltalk语言和C++语言的优点。下面来介绍一些Java的主要特征:1)Java语言是简单的。Java语言的语法与C语言和C++语言相似,这让很多程序员可…

    2022年7月8日
    18
  • 图书馆管理系统程序设计

    图书馆管理系统程序设计

    2021年11月18日
    42
  • 六大排序算法:插入排序、希尔排序、选择排序、冒泡排序、堆排序、快速排序「建议收藏」

    六大排序算法:插入排序、希尔排序、选择排序、冒泡排序、堆排序、快速排序「建议收藏」文章目录:1.插入排序2.希尔排序1.插入排序步骤:1.从第一个元素开始,该元素可以认为已经被排序2.取下一个元素tem,从已排序的元素序列从后往前扫描3.如果该元素大于tem,则将该元素移到下一位4.重复步骤3,直到找到已排序元素中小于等于tem的元素5.tem插入到该元素的后面,如果已排序所有元素都大于tem,则将tem插入到下标为0的位置6.重复步骤2~5动图演示如下:思路:  在待排序的元素中,假设前n-1个元素已有序,现将第n个元素插入到前面已经排好的序列中,使得前n个

    2022年7月12日
    17
  • 将字符串指针赋值给数组[通俗易懂]

    比如char*p=”sdflkjasljfsjlsdfsa”;charp1[200];将p赋给p1(1)strcpy(p1,p);(2)char*src=”helloworld”;chardes[100]={0};memcpy(des,src,strlen(src)+1);//void*memcpy(void*str1,const…

    2022年4月12日
    95
  • 客服客户聊天系统源码分享[通俗易懂]

    客服客户聊天系统源码分享[通俗易懂]静态H5聊天对话框html源码客服系统代码(3)此程序可用作客户与客服聊天使用,也可以作为app程序嵌入的聊天功能或者站内聊天使用的代码。运行视频效果:链接:https://pan.baidu.com/s/1lMbXgY3rVRw4ZFfwePJOTw提取码:bfyh复制这段内容后打开百度网盘手机App,操作更方便哦静态H5聊天输入对话框html代码(1)静态H5聊天输入对话框html代码(2)上节讲了消息对话如何实现,上节规划中是来如何实现做到推送实时刷新,看了ba.

    2022年9月15日
    0
  • python3.8安装matplotlib_matplotlib画图

    python3.8安装matplotlib_matplotlib画图1.直接打开命令提示符(快捷键window+r)2.若提示安装失败(Python——Youareusingpipversion9.0.1,howeverversion10.0.1isavailable.),输入python-mpipinstall-Upipsetuptools进行升级。安装成功,则下图所示:3.安装成功后,输入pytho…

    2022年8月31日
    0

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号