• system verilog(1) --- 数据类型


    1 Structual Data Types

    结构数据类型可以被建模为硬件中之间的连线。reg类型可以保持值知道下一个新的值被放进去,就像一个硬件寄存器组成部分。需要注意的是wire和reg信号的声明是在一个模型中,而不是一个initial或者always语句块中。一般而言,它们起初的状态是未知的,那么reg类型的值是x,wire信号的值是z,其中x表示是未知值,z表示是高阻态。0,1则分别表示高低电平。

    2 Behavioral Data Types

    2.1 integer

    integer 类型可以表示值得范围为:-2^31 到 2^31-1
    其声明形式如下

    integer integer_var_name;
    
    • 1

    2.2 real

    real可以声明实数,可以用10进制的形式表示(14.72),也可以使用科学计数法表示(37e3)。其声明形式如下:

    real real_varible_name;
    
    • 1

    需要注意的是integer 的default值是x,而real的default的默认值是0。

    integer a[0:64] ; // an array of 65 integer values
    
    • 1

    2.3 Time

    可以声明一个64bit值,可以通过系统函数 $time保存当千的仿真时间,注意,仅仅用于仿真。其声明形式如下:

    time time_varible_name;
    
    • 1

    2.4 Parameters

    其表示常数,在runtime中不可以更改,但是可以在编译期间内进行更改,例如defparam,或者模块例化的语句中。其声明形式如下:

    parameter SISE = 16
    • 1

    2.5 Logic

    logic是对verilog中reg类型的改进。因此它可以被连续赋值、门和模块驱动,同时也支持reg的变量功能。

    3 Void Data Types

    空数据类型表示不存在数据,可以用于没有返回值的函数。
    如:

    void(function_call());
    
    • 1

    4 string

    string类型大小可变,是一个动态分配的byte数组。

    module  string_datatype;
    
    //declaration
    string s1   =   "Hello World"   ;
    string s2   =   {"Hi", ",", s1} ;
    bit [31:0] b=   65             ;
    //string  s3  =   b               ;  // sets 128 to s3, error:Assigning a packed type 'bit[31:0]' to a string requires a cast.
    string s3 = string'(b);
    //string s3 = $cast(b);
    initial begin
        //display values
        $display("String 1 s1 = %0s", s1);
        $display("String 2 S2 = %0s", s2);
        $display("string 3 s3 = %0d bit b = %0d", s3, b);
    end
    endmodule
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16

    它的模拟输出结果是:
    在这里插入图片描述

    4 event

    sv还从几方面对event进行加强,event现在是同步对象synchronization object的句柄handle,可以传递给函数routine。在verilog中,如果触发线程triggering thread在块线程blocking trigger前执行,触发将会丢失。sv引入了触发函数triggered function,允许程序员检查事件是否被触发。

    5 User defined

    用户可以像C一样,使用typedef来定义新的数据类型。

    6 enumrated

    enum { red, green, blue, yellow, white, black } Colors;
    
    • 1

    默认red的值是0,然后依次累加。因此最后的结果便是0,1,2,3,4,5。
    在下个例子中,red = 0, blue = 4, white = 10

    enum { red=0, green, blue=4, yellow, white=10, black } Colors;
    
    • 1

    由递增的原理可以知道green = 1, yellow = 5, black = 11。

    而 enum一般会和typedef结合使用。

    typedef enum {GOOD, BAD} pkt_type; 
    
    pkt_type pkt_a; // named type
    
    • 1
    • 2
    • 3

    Method Description
    first() returns the value of the first member of the enumeration
    last() returns the value of the last member of the enumeration
    next() returns the value of next member of the enumeration
    next(N) returns the value of next Nth member of the enumeration
    prev() returns the value of previous member of the enumeration
    prev(N) returns the value of previous Nth member of the enumeration
    num() returns the number of elements in the given enumeration
    name() returns the string representation of the given enumeration value
    下面将会给出在例子:

    module enum_datatype;
    
    initial begin
    	typedef enum {st1, st2, st3} state_s;
    	//state_s是一个枚举类型变量
    	//st1,st2,st3是枚举常量
    	state_s state, next_state;
    	$display("state -> %0d, %0d, %0d", st1, st2, st3);
    end
    
    endmodule
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    输出结果是:
    在这里插入图片描述

  • 相关阅读:
    数据挖掘实战(4)——聚类(Kmeans、MiniBatchKmeans、DBSCAN、AgglomerativeClustering、MeanShift)
    我的创作纪念日
    TCPIP协议栈的心跳、丢包重传、连接超时机制实例详解
    RocketMQ学习笔记
    MySQL(三)存储引擎
    无人机镜头稳定的原理和相关算法
    第十五章《网络编程》第1节:网络基础知识
    用Rust语言开发Linux内核,得先过内存模型这关
    每天一个数据分析题(四百零一)- 逻辑回归
    猿创征文|【JavaSE】 Collection集合全家桶
  • 原文地址:https://blog.csdn.net/weixin_45614076/article/details/126201201