core-v-verif系列之lib<45>
UVM环境介绍
HEAD commitID: 1f968ef
1. core-v-verif/lib/uvm_agents/uvma_clknrst/seq/uvma_clknrst_base_seq.sv
//
// Copyright 2020 OpenHW Group
// Copyright 2020 Datum Technology Corporation
//
// Licensed under the Solderpad Hardware Licence, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://solderpad.org/licenses/
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
`ifndef __UVMA_CLKNRST_BASE_SEQ_SV__
`define __UVMA_CLKNRST_BASE_SEQ_SV__
/**
* Abstract object from which all other Clock & Reset agent sequences must extend.
* Subclasses must be run on Clock & Reset sequencer (uvma_clknrst_sqr_c) instance.
*/
class uvma_clknrst_base_seq_c extends uvm_sequence#(
.REQ(uvma_clknrst_seq_item_c),
.RSP(uvma_clknrst_seq_item_c)
);
`uvm_object_utils(uvma_clknrst_base_seq_c)
`uvm_declare_p_sequencer(uvma_clknrst_sqr_c)
/**
* Default constructor.
*/
extern function new(string name="uvma_clknrst_base_seq");
endclass : uvma_clknrst_base_seq_c
function uvma_clknrst_base_seq_c::new(string name="uvma_clknrst_base_seq");
super.new(name);
endfunction : new
`endif // __UVMA_CLKNRST_BASE_SEQ_SV__
下面将基于你当前正在编辑的 /home/corelab/lincoln/core-v-verif/core-v-verif/lib/uvm_agents/uvma_clknrst/seq/uvma_clknrst_base_seq.sv
文件,按照要求进行分析。
2. 接口介绍
2.1 类定义与继承
class uvma_clknrst_base_seq_c extends uvm_sequence#(
.REQ(uvma_clknrst_seq_item_c),
.RSP(uvma_clknrst_seq_item_c)
);
- 代码介绍:定义了一个名为
uvma_clknrst_base_seq_c
的类,它继承自uvm_sequence
。uvm_sequence
是 UVM(通用验证方法学)里用于定义序列的基类。这里通过参数化的方式,将请求(REQ
)和响应(RSP
)的类型都指定为uvma_clknrst_seq_item_c
,表明该序列处理的事务类型为uvma_clknrst_seq_item_c
。 - 逻辑分析:继承
uvm_sequence
让uvma_clknrst_base_seq_c
具备序列的基本功能,能在 UVM 环境里生成和管理事务序列。指定请求和响应类型,保证了序列和其他组件间能正确传递uvma_clknrst_seq_item_c
类型的事务。
2.2 UVM 工具宏
`uvm_object_utils(uvma_clknrst_base_seq_c)
`uvm_declare_p_sequencer(uvma_clknrst_sqr_c)
- 代码介绍:
uvm_object_utils(uvma_clknrst_base_seq_c)
:这是 UVM 提供的宏,用于将uvma_clknrst_base_seq_c
类注册到 UVM 对象工厂。注册后,该类就能在 UVM 环境里动态创建、复制和打印等。uvm_declare_p_sequencer(uvma_clknrst_sqr_c)
:此宏声明了一个指向uvma_clknrst_sqr_c
类型序列器的指针p_sequencer
,方便序列访问序列器的成员和方法。
- 逻辑分析:通过对象注册,
uvma_clknrst_base_seq_c
能更好地融入 UVM 框架;声明序列器指针,使序列能和指定类型的序列器交互,完成事务的发送和调度。
2.3 构造函数声明
extern function new(string name="uvma_clknrst_base_seq");
- 代码介绍:使用
extern
关键字声明构造函数new
,意味着该函数的实现位于类定义外部。构造函数接收一个字符串参数name
,默认值为"uvma_clknrst_base_seq"
,用于指定对象的名称。 - 逻辑分析:将构造函数的声明和实现分离,能让代码结构更清晰。默认的对象名称方便在创建对象时不指定名称,使用默认值即可。
3. 参数介绍
3.1 构造函数参数
extern function new(string name="uvma_clknrst_base_seq");
- 代码介绍:构造函数有一个字符串类型的参数
name
,默认值是"uvma_clknrst_base_seq"
。这个参数用于在创建uvma_clknrst_base_seq_c
类的对象时指定对象的名称。 - 逻辑分析:提供默认值让对象创建更灵活,若用户不指定名称,就使用默认名称;若指定名称,则使用用户提供的名称。
4. 模块实现介绍
4.1 头文件保护
`ifndef __UVMA_CLKNRST_BASE_SEQ_SV__
`define __UVMA_CLKNRST_BASE_SEQ_SV__
// ... 类定义 ...
`endif // __UVMA_CLKNRST_BASE_SEQ_SV__
- 代码介绍:运用条件编译指令
ifndef
、define
和endif
来防止头文件的重复包含。当__UVMA_CLKNRST_BASE_SEQ_SV__
宏未定义时,定义该宏并编译类定义部分的代码;若已定义,则跳过这部分代码的编译。 - 逻辑分析:在大型项目里,一个文件可能会被多个地方包含,使用头文件保护机制可避免因重复包含引发的编译错误。
4.2 构造函数实现
function uvma_clknrst_base_seq_c::new(string name="uvma_clknrst_base_seq");
super.new(name);
endfunction : new
- 代码介绍:构造函数的实现调用了父类
uvm_sequence
的构造函数super.new(name)
,把传入的name
参数传递给父类进行初始化。 - 逻辑分析:在创建
uvma_clknrst_base_seq_c
类的对象时,先调用父类的构造函数完成父类部分的初始化,保证对象能正常使用父类的属性和方法。
5. 总结
uvma_clknrst_base_seq_c
类是一个基于 UVM 方法学的序列基类,其他时钟与复位代理的序列都要继承该类。它借助继承 uvm_sequence
获得序列的基本功能,通过 UVM 工具宏注册到 UVM 对象工厂并声明序列器指针,方便和序列器交互。头文件保护机制保证了代码不会被重复编译,构造函数调用父类构造函数完成初始化。该类为时钟与复位代理的序列设计提供了基础框架,提升了代码的可维护性和可扩展性。
2. core-v-verif/lib/uvm_agents/uvma_clknrst/seq/uvma_clknrst_restart_clk_seq.sv
//
// Copyright 2020 OpenHW Group
// Copyright 2020 Datum Technology Corporation
//
// Licensed under the Solderpad Hardware Licence, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://solderpad.org/licenses/
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
`ifndef __UVMA_CLKNRST_RESTART_CLK_SEQ_SV__
`define __UVMA_CLKNRST_RESTART_CLK_SEQ_SV__
/**
* Object holding sequence library for Clock & Reset agent.
*/
class uvma_clknrst_restart_clk_seq_c extends uvma_clknrst_base_seq_c;
`uvm_object_utils (uvma_clknrst_restart_clk_seq_c);
`uvm_declare_p_sequencer(uvma_clknrst_sqr_c)
extern function new(string name="uvma_clknrst_restart_clk_seq");
extern task body();
endclass : uvma_clknrst_restart_clk_seq_c
function uvma_clknrst_restart_clk_seq_c::new(string name="uvma_clknrst_restart_clk_seq");
super.new(name);
endfunction : new
task uvma_clknrst_restart_clk_seq_c::body();
uvma_clknrst_seq_item_c clknrst_seq_item;
clknrst_seq_item = uvma_clknrst_seq_item_c::type_id::create("clknrst_seq_item", , get_full_name());
start_item(clknrst_seq_item);
clknrst_seq_item.action = UVMA_CLKNRST_SEQ_ITEM_ACTION_RESTART_CLK;
finish_item(clknrst_seq_item);
endtask : body
`endif // __UVMA_CLKNRST_RESTART_CLK_SEQ_SV__
2. 接口介绍
2.1 类定义与继承
class uvma_clknrst_restart_clk_seq_c extends uvma_clknrst_base_seq_c;
- 代码介绍:定义了一个名为
uvma_clknrst_restart_clk_seq_c
的类,它继承自uvma_clknrst_base_seq_c
。uvma_clknrst_base_seq_c
可能是时钟和复位序列的基类,通过继承,uvma_clknrst_restart_clk_seq_c
可以复用基类的属性和方法。 - 逻辑分析:继承机制使得代码具有更好的可维护性和扩展性。
uvma_clknrst_restart_clk_seq_c
专注于实现重启时钟的序列功能,而一些通用的序列操作可以在基类中实现。
2.2 UVM 工具宏
`uvm_object_utils (uvma_clknrst_restart_clk_seq_c);
`uvm_declare_p_sequencer(uvma_clknrst_sqr_c)
- 代码介绍:
uvm_object_utils(uvma_clknrst_restart_clk_seq_c)
:这是 UVM 提供的宏,用于将uvma_clknrst_restart_clk_seq_c
类注册到 UVM 对象工厂。注册后,该类的对象可以在 UVM 环境中动态创建、复制和打印等。uvm_declare_p_sequencer(uvma_clknrst_sqr_c)
:声明一个指向uvma_clknrst_sqr_c
类型序列器的指针p_sequencer
,方便序列访问序列器的成员和方法。
- 逻辑分析:通过对象注册,
uvma_clknrst_restart_clk_