当前位置:网站首页>[in simple terms, play with FPGA learning 11 --- testbench writing skills 1]
[in simple terms, play with FPGA learning 11 --- testbench writing skills 1]
2022-07-26 01:47:00 【Ape Zhou】
Play in depth FPGA Study 11----Testbench Writing skills 1
Encapsulate useful subroutines
stay C In language , An experienced software engineer must write a subroutine for a piece of code that is often used , Then call it with different parameters . This can achieve the effect of code reuse , Reduce unnecessary repetitive labor , It also makes the code relatively simple . stay Testbench Can also be used in task Encapsulate the code , It can communicate with C The sub functions of the language are called flexibly .
The following example gives a very practical package subroutine , Maybe it can be used in the test script of every project .
// Encapsulate some useful reports for testing
// Including tasks error, warning, fatal, terminate
module print_task();
// Show warning The report , It also includes the current time and warning content ( Input by user )
task warning;
input [80*8:1] msg;
begin
$write("WARNING at %t: %s", $time,msg);
end
endtask
// Show error The report , It also includes displaying the current time and error content ( Input by user )
task error;
input [80*8:1] msg;
begin
$write("-ERROR- at %t: %s", $time, msg);
end
endtask
// Show fatal The report , It also includes the display of the current time and fatal content ( Input by user )
task fatal;
input [80*8:1] msg;
begin
$write(" *FATAL* at %t: %s", $time, msg);
terminate;
end
endtask
// Show warning The report , It also includes the current time and end information ( This task generates )
task terminate;
begin
$write("Simulation completed\n");
$ finish;
end
endtask
endmodule
When using encapsulated subroutines , As shown in the following code :
// Use print_task.v, Then you can call its encapsulated task 了
print_task print();
...
initial begin
if (...) print.error("Unexpected response\n"); // call error Mission
...
print.terminate; // call terminate Mission
end
...
endmodule
About the definition of variables
Writing Testbench when , The common mistake about the definition of variables is to apply a well-defined global variable to two different always In block ( Such as EX1C), So because of these two always Block independent and parallel working mechanism , It is likely to lead to unexpected consequences .
EX1C:
interger i;
always begin
for(i=0; i<32; i=i+1) begin
end
end
always begin
for(i=0; i<32;i=i+1) begin
...
end
end
actually , stay Verilog in ( To write Testbench when ), If in begin…end Defined between always Block name of , Then it can be as EX1C Also declare variables . These two always Variables in the block i Is irrelevant , It will not produce unpredictable results .
EX2C:
always begin
integer i;
for(i=0; i<32; i=i+1) begin
...
end
end
always
begin: block_2
integer i;
for(i=0; i<32;i=i+1) begin
...
end
end
in addition to , stay Verilog Medium function and task It also supports local variable definitions similar to the above .
HDL The parallelism of
Why? C Can't replace Verilog and VHDL As a hardware description language ? because C The most basic hardware description is missing 3 A thought : Connectivity (connectivity)、 Timeliness (Time) And parallelism (Concurrency).
Connectivity is the ability to use a simple and interconnected module to describe a design , Schematic design tools are supporting tools with perfect connectivity .
Timeliness is the ability to express the time change of the evolution of design state , This ability is different from measuring the time taken by a code to execute .
Parallelism is the ability to describe simultaneous independent behaviors .
边栏推荐
- "Weilai Cup" 2022 Niuke summer multi school training camp 2 h.[take the elevator] maintenance section
- How idea can quickly delete recently opened projects
- Practice sharing of monorepo based on yarn1.x
- “蔚来杯“2022牛客暑期多校训练营2 I.[let fat tension] 矩阵乘法 J.[Link with Arithmetic Progression]线性回归
- Record a failure caused by a custom redis distributed lock
- Leetcode 537. complex multiplication (netizens' thoughts, ashamed)
- Is it safe to open an account for stock speculation through the online account manager?
- Detailed explanation of redis data structure, combined with books
- “蔚来杯“2022牛客暑期多校训练营2 D.[Link with Game Glitch] 二分答案+SPFA判环
- How uxdb works on multiple processors
猜你喜欢

Three modes of CPU

餐饮连锁门店重塑增长背后的数字化转型

网络之IP地址

What should I do when my blog is attacked by hackers?

After reading this article, you should thoroughly understand how to do interface testing

pt-onnx-ncnn转换的问题记录(接yolov5训练)

Easyrecovery15 data recovery software with high recovery rate and high download volume

《分布式微服务电商》专题(一)-项目简介
![4QAM, 16QAM modulation and demodulation simulation circuit, observe and analyze QAM constellation and bit error rate curve [matlab code]](/img/95/5b9a2347d20cc5da0d2920b7f583ce.png)
4QAM, 16QAM modulation and demodulation simulation circuit, observe and analyze QAM constellation and bit error rate curve [matlab code]

Handler message mechanism - FWK layer
随机推荐
Huawei wireless device WDS configuration command
Prime Ring Problem
Oracle is nested at multiple levels, and the alias problem of the table cannot be found
推荐系统-协同过滤在Spark中的实现
销量连连夺冠,五菱的成功秘诀只有低价吗?
【深入浅出玩转FPGA学习11----Testbench书写技巧1】
Go operation excel library excel use
poj1521
Practice sharing of monorepo based on yarn1.x
How uxdb works on multiple processors
[untitled]
Prime Ring Problem
Leetcode537. Complex multiplication (yes, solved)
ABC find 4-cycle (pigeon nest theorem)
Qtreewidget dotted line setting
What should I do when my blog is attacked by hackers?
Leetcode/ numbers that appear only once
Zero copy of network file transfer
I just test it
SQL injection tutorial: learn through examples