UVM寄存器模型(二) —— ralf文件语法格式


前言

在利用ralgen脚本生成uvm寄存器模型的过程中,ralgen需要加载一个ralf文件,这个文件按照一定的语法格式,记录了DUT中寄存器和memory的基本信息。本文主要介绍ralf文件的语法格式。

RALF描述是一个Tcl 8.5文件。因此,可以使用循环和变量等编程构造来快速而简洁地构造大型寄存器集和内存定义。可以使用Tcl source命令来执行多个和分层注册规范管理。此外,还可以使用Tcl表达式来指定寄存器偏移值、基值和寄存器名称。
RALF的构造包括一下几个部分:

  • field
  • register
  • regfile
  • memory
  • virtual register
  • block
  • system

1 field

field定义了寄存器连续bit的最小集合。不同的field串联构成寄存器。
在这里插入图片描述

1.1 语法格式

语法格式如下:

field name [{
<properties>
}]

1.2 属性Properties

  • [bits n;]
    指定字段中的位数。如果未指定,默认为1。此属性只能指定一次。
  • [access rw|ro|wo|w1|w1c|rc|rs|wrc|wrs|wc|ws| wsrc|wcrs|w1s|w1t|w0c|w0s|others…
    指定写或读字段时字段中所有位的功能。默认情况下,一个字段是可写的(rw)。
    下面列出所有access属性的可选项,供查阅。
rw
read/write
ro
read-only
wo
write-only
w1
write-once
w1c
write a 1 to bitwise-clear
rc
clear on read
rs
Read Sets All
wrc
Write Read Clears All
wrs
Write, Read Sets All
wc
Write Clears All
ws
Write Sets All
wsrc
Write Sets All, Read Clears All
wcrs
Write Clears All, Read Sets All
w1s
Write 1 to Set. If the bit in the written value is a '1', then the corresponding bit in the field is set to 1. Otherwise, the field bit is not affected.
w1t
Write 1 to Toggle. If the bit in the written value is a '1', then the corresponding bit in the field is inverted. Otherwise, the field bit is not affected.
w0c
Write 0 to Clear. If the bit in the written value is a '0', then the corresponding bit in the field is set to 0.Otherwise, the field bit is not affected.
w0s
Write 0 to Set. If the bit in the written value is a '0', then the corresponding bit in the field is set to 1. Otherwise, the field bit is not affected.
w0t
Write 0 to Toggle. If the bit in the written value is a '0', then the corresponding bit in the field is inverted. Otherwise, the field bit is not affected.
w1src
Write 1 to Set, Read Clears All. If the bit in the written value is a '1', then the corresponding bit in the field is set to 1. Otherwise, the field bit is not affected.
w1crs
Write 1 to Clear, Read Sets All. If the bit in the written value is a '1', then the corresponding bit in the field is set to 0. Otherwise, the field bit is not affected.
w0src
Write 0 to Set, Read Clears All. If the bit in the written value is a '0', then the corresponding bit in the field is set to 1. Otherwise, the field bit is not affected.
w0crs
Write 0 to Clear, Read Sets All. If the bit in the written value is a '0', then the corresponding bit in the field is set to 0. Otherwise, the field bit is not affected.
woc
Write Only Clears All
wos
Write Only Sets All
wo1
Write Only, Once. Changed to written value if this is the first write operation after a hard reset. Otherwise has no effect.
  • [reset|hard_reset value;]
    指定该字段的硬复位值。默认为0。
    支持未知(x或x)和高阻抗(z或z)位的值。但是,这些位最终在RAL基类中转换为0,因为RAL基类中的重置值是一个2状态值。
  • [soft_reset value;]
    指定字段的软复位值。默认值不受软复位影响。
  • [<constraint name [{ < expressions > }]>]
    指定字段值被随机化时的约束。约束不会被生成脚本执行,并且必须是有效的。
    如果没有指定约束属性,则该字段不能随机化。如果需要一个不受约束但随机的字段,只需指定一个空的约束块。
  • [enum { <name[=val],> }]
    定义字段值的符号名称。如果没有为符号名显式指定值,则该值为前一个名称的值加上1,如果是第一个名称,则为零。
  • [cover <+|- b|f>
    指定该字段中的位是包含(+b)在寄存器位覆盖模型中还是排除(-b)在寄存器位覆盖模型中。
    指定该字段的字段值覆盖点是否为显式目标(+f),在这种情况下,其权重等于指定的或隐式仓的数量。如果它被指定为作为交叉覆盖点的一部分的隐式目标(-f),它的覆盖点权重等于零。
  • [<coverpoint { <bins name [[[n]]] = { <n|[n:n],> } | default> }>]
    显式地指定字段值覆盖点中的仓。

1.3 Example

Example A-1 1-bit read/write Field

field tx_en;

Example A-2 2-bit Randomizable Field

field PAR {
	bits 2;
	reset 2’b11;
	constraint valid {
		value != 2’b00;
	}
}

Example A-3 Explicitly Specified Coverage Bins

field f2 {
	bits 8;
	enum { AA, BB, CC=15 }
	coverpoint {
		bins AAA = { 0, 12 }
		bins BBB [] = { 1, 2, AA, CC }
		bins CCC [3] = { 14,15, [ BB : 10 ] }
		bins DDD = default
	}
}

2 register

寄存器定义了字段的连接。寄存器用于寄存器文件和寄存器块中。
在这里插入图片描述

2.1 语法格式

语法格式如下:

register name {
<properties>
}

2.2 属性Properties

  • [attributes { < name > < value >[, …] }]
    为指定的用户定义属性指定一个值。可以通过用逗号分隔每个属性-值对来指定多个属性。如果该值包含空格,则必须包含在双引号之间。
  • [bytes n;]
    指定寄存器中的字节数。该寄存器中字段的总位数不能超过此字节数。如果未指定此属性,则寄存器的宽度是实现寄存器中包含的所有字段所需的最小整数字节数。
  • [left_to_right;]
    默认情况下,字段从寄存器的最低有效位开始连接。如果指定了此属性,字段将从寄存器的最重要部分开始连接,但从最低重要部分对齐。当使用从左到右的规范样式时,第一个字段不能指定位偏移量:第一个字段的偏移量取决于其他字段之间的大小和间距。
  • [< field name[=rename][[n]] [(hdl_path)] [@bit_offset[+incr]];
  • [<field name [[n]] [(hdl_path)] [@bit_offset[+incr]] { < field properties> }>]
    定义并实例化此寄存器中的指定字段。第一个表单指定前面定义的字段描述的一个实例。第二个表单定义了一个新的字段描述,并在注册文件中实例化它。
    必须指定至少一个field属性。
  • [<constraint name [{ < expression> }]>]
    指定对其随机化时包含的字段的值的约束。
  • [noise ro|rw|no;]
    指定在不影响设备配置或功能正确性的情况下,设计的正常操作期间是否可以访问该寄存器,以及如何访问该寄存器。
  • [shared [(hdl_path)];]
    指定此寄存器由实例化它的块中的所有域在物理上共享。
  • [cover <+|- a|b|f>
    指定该寄存器的地址是否应该从块的地址映射覆盖模型中排除(-a)。
    指定该寄存器中的位是包含(+b)在寄存器位覆盖模型中还是排除(-b)在寄存器位覆盖模型中。
    指定该寄存器中的字段应该包含(+f)还是从字段值覆盖模型中排除(-f)。

2.3 Example

Example A-4 Attribute specification for a register

register R {
	...
	attributes {
		NO_RAL_TESTS 1,
		RETAIN 1
	}
}

Figure A-1 Register Specification
在这里插入图片描述
Example A-5 Specification for Register in Figure A-1

register CTRL {
	field TXE {}
	field RXE {}
	field PAR {
		bits 2;
		reset 2’b11;
	}
	field DTR @11 {
		access rw;
	}
	field CTS {
		access rw;
		reset 1;
	}
}

Example A-6 Specification for Register in Figure A-1

source Example A-2
register CTRL {
	bytes 2;
	left_to_right;
	field CTS {
		access rw;
		reset 1;
	}
	field DTR {
		access rw;
	}
	field unused {
		bits 7;
	}
	field PAR;
	field RXE {}
	field TXE {}
}

设置后门路径:

register reg=reg_inst (.fld1(hdl_path1), .fld2(hdl_path2_high, hdl_path2_low, …));
register HOST_ID {
     field REV_ID {
         bits 32;
         access rw;
         reset 'h03;
     }
     field CHIP_ID {
         bits 8;
         access rw;
         reset 'h5A;
     }
}
block host_regmodel {
     bytes 2;
     register host_id=HOST_ID(.REV_ID(rev_id), .CHIP_ID(chip_id)); 
}

block host_regmodel {
     bytes 2;
     register host_id=HOST_ID(.REV_ID(rev_id), .CHIP_ID(chip_id_high, chip_id_low));
}

block host_regmodel {
    bytes 2;
    register HOST_ID (.REV_ID(rev_id), .CHIP_ID((chip_low, 0, 3), .(chip_high, 4, 7)))
}

3 regfile

寄存器文件定义了连续寄存器的集合。寄存器文件在块中使用。
在这里插入图片描述

3.1 语法格式

regfile name {
<properties>
}

3.2 属性Properties

  • [<register name[=rename][[n]] [(hdl_path)] [@offset] [read|write];>]
  • [<register name[[n]] [(hdl_path)] [@offset] {< property>}]
  • [<register name[=rename][m:n]] [(hdl_path)] [@offset] [read|write];>]
  • [<register name[[m:n]] [(hdl_path)] [@offset] {< property>}]
    寄存器声明应该以大于’ 0 '的索引开始。
    必须指定至少一个寄存器属性。

3.3 Example

寄存器文件的主要目的是定义寄存器组的数组。例如,图a -2中所示的寄存器组用于配置DMA通道。例a -8中所示的块RALF规范说明了如何描述16通道DMA控制器。
Figure A-2 DMC Channel Configuration Registers Specification
在这里插入图片描述
Example A-8 Specification for Multi-Channel DMA Controller

block dma_ctrl {
	regfile chan[16] {
		register src {
			bytes 2;
			field addr {
				bits 16;
			}
		}
	register dst {
		bytes 2;
		field addr {
			bits 16;
		}
	}
	register count {
		bytes 2;
		field n_bytes {
			bits 16;
		}
	}
	register ctrl {
		bytes 2;
		field TXE {
			bits 1;
			access rw;
		}
		field BSY {
			bits 1;
			access ro;
		}
		field DN @12 {
			bits 1;
			access ro;
		}
		field status {
			bits 3;
			access ro;
		}
	}
}
}

4 memory

内存定义了一个由连续可寻址位置组成的区域。内存以块的形式使用。
在这里插入图片描述

4.1 语法格式

memory name {
<property>
}

4.2 属性Properties

  • [attributes {< name> < value>[, …]}]
    为指定的用户定义属性指定一个值。可以通过用逗号分隔每个属性-值对来指定多个属性。如果该值包含空格,则必须包含在双引号之间。
  • size m[k|M|G];
    指定内存中连续地址的数量,其中每个位置都有由bits属性指定的位数。尺寸也可以包括一个单位。在这种情况下,指定的大小乘以:
    1024 (k)
    2^20 (M)
    2^30 (G)
    此属性是必需的。
  • bits n;
    指定每个内存位置中的位数。内存中的总位数是指定的位数乘以指定的大小。此属性是必需的。
  • [access rw|ro;]
    指定内存是RAM (rw)还是ROM (ro)。默认情况下,内存是RAM。
  • [initial x|0|1|addr|literal[++|–];]
    指定内存的初始内容是用未知数(x)填充,用0(0)填充,用1(1)填充,设置为物理地址值(addr),或设置为常量(字面量),递增(字面量++)或递减(字面量–)字面量值。
    当调用其抽象类中的uvm_ral_mem::initialize()方法时,内存的内容被初始化为指定的模式。默认情况下,内存用unknowns (x)初始化。
    初始化要求对内存内容的后门访问是可用的。
  • [shared [(hdl_path)];]
    指定此内存由实例化它的块中的所有域物理共享。只能在独立内存规范中使用。
    可选的hdl_path指定物理内存的分级访问路径。它用来代替实例化它的块中指定的(hdl_path)。如果指定了(hdl_path),则可以通过将共享内存与外围块的(hdl_path)连接起来,自动生成对共享内存的直接分层访问。(hdl_path)必须用圆括号括起来。
  • [cover <+|- a>
    指定该内存是包含(+a)在地址映射覆盖模型中还是排除(-a)在地址映射覆盖模型中。

4.3 Example

Example A-9 64 KB RAM

memory dma_bfr {
bits 8;
size 64k;
}

Example A-10 2 KB ROM

memory tx_bfr {
bits 16;
size 1024;
access ro;
initial 0++;
}

5 virtual register

虚寄存器定义了虚字段的连接。虚拟寄存器在块中使用。

5.1 语法格式

5.2 属性Properties

5.3 Example

6 block

块定义了一组寄存器和存储器。寄存器被连接成块。一个块可以有多个物理接口。寄存器和内存可以在块内的物理接口之间共享。
在这里插入图片描述
在这里插入图片描述

6.1 语法格式

block name {
<property>
}

6.2 属性Properties

  • [attributes {< name> < value>[, …]}]
  • bytes n;
    指定可并发访问并通过物理接口唯一寻址的字节数。此属性是必需的。
  • [endian little|big|fifo_ls|fifo_ms;]
    指定访问的方式,大端还是小端,默认是小端。
  • [<regfile name[=rename][[n]] [(hdl_path)] [@offset] [+incr] [read|write];>]
  • [<regfile name[[n]] [(hdl_path)] [@offset] [+incr] {< property>}]
  • [<memory name[=rename] [(hdl_path)] [@offset][read|write];>]
  • [<memory name [(hdl_path)] [@offset] {< property>}>]
  • [<virtual register name [=rename[n] mem@offset [+incr]];>]
  • [<virtual register name[[n] mem@offset [+incr]] {< property>}]
  • [<constraint name [{< expression>}]>]
  • [cover <+|- a|b|f>

6.3 Example

Example A-11 Block With Single Physical Interface

source Example A-6
source Example A-10
block uart {
	bytes 1;
	endian little;
	register CTRL;
	memory tx_bfr @’h00100;
}

Example A-12 Block With Register Array

block multi_chan {
	bytes 1;
	endian little;
	register CHAN_CTRL[32] @’h0200 {
		bytes 2;
		...
	};
}

Example A-13 Block With Two Physical Interfaces

register data_xfer {
		bytes 4;
		field data {
			bits 32;
		}
	shared;
}
register flags {
		field cts {
			access rw;
			reset 1;
		}
		field dtr {
			access rw;
		}
}
block bridge {
		domain pci {
			bytes 4;
			register flags=pci_flags @'h0;
			register data_xfer=to_ahb_write @'h4;
			register data_xfer=frm_ahb_read @'h8;
			change_reset frm_ahb_read 'h5a5a
		}
		domain ahb {
			bytes 4;
			register flags=ahb_flags @'h10;
			register data_xfer=to_pci_write @'h14;
			register data_xfer=frm_pci_read @'h18;
		}
}

7 system

系统定义由块或子系统组成的设计。一个系统可以用来创建更大的系统。
在这里插入图片描述
在这里插入图片描述

7.1 语法格式

system name {
<property>
}

7.2 属性Properties

  • [attributes {< name> [, …]}]
  • bytes n;
  • [endian little|big|fifo_ls|fifo_ms;]
  • [<block name[[.domain]=rename][[n]] [(hdl_path)]@offset [+incr];>]
  • [<block name[[n]] [(hdl_path)] @offset [+incr] {< property>}]
  • [<system name[[.domain]=rename][[n]] [(hdl_path)]@offset [+incr];>]
  • [<system name[[n]] [(hdl_path)] @offset [+incr] {< property>}]
  • [<constraint name [{< expression>}]>]
  • [cover <+|- a|b|f>

7.3 Example

Example A-14 System With Single Physical Interface

source Example A-11
system SoC {
	bytes 1;
	endian little;
	block uart[2] @’hF0000 +’h01000;
}

Example A-15 System With Two Physical Interfaces

source Example A-11
source Example A-13
system SoC {
	domain ahb {
		bytes 4;
		block uart[2] @’hF0000 +’h01000;
		block bridge.ahb=br @0;
	}
	domain pci {
		bytes 4;
		block bridge.pci=br @0;
	}
}

总结

本文主要介绍ralf文件的语法格式。

参考文献

uvm_ralgen_ug_sp2.pdf

  • 20
    点赞
  • 137
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值