如何从 Verilog 中的单独模块调用任务? [英] How to call tasks from a separate module in Verilog?
问题描述
我是 Verilog 的新手,如果有人可以帮助我,我将不胜感激.
我有一个任务写在一个单独的文件中 - task.v":
I'm new to Verilog and would really appreciate it if someone could help me with this.
I have a task written in a separate file - "task.v" :
module task_create();
task assign_inp;
reg a,b,c,d;
//details
endtask
endmodule
我有一个调用这个任务的模块:
I have a module that is calling this task:
module tb();
`include "task.v"
assign_inp(a,b,c,d);
endmodule
当我执行此操作时,出现此错误:
When I execute this, I get this error:
模块定义 task_create 不能嵌套到模块 tb
Module definition task_create cannot nest into module tb
当我删除 task.v 中的模块和结束模块时,出现此错误:
When I remove the module and endmodule in task.v, I get this error:
任务必须包含在模块中
我哪里出错了?非常感谢!
Where am I going wrong? Thank you so much!
推荐答案
你的任务在一个模块中,所以只能在模块中看到.您可以做的是删除模块包装器并在单独的文件中声明任务.
Your task in in a module and so can only be seen in the module. What you can do is remove the module wrapper and just declare the task in a separate file.
task assign_inp;
reg a,b,c,d;
//details
endtask
您可以包含该任务,并且您应该能够看到该任务.
You can include the task and you should be able to see the task.
删除模块对我有用.
您可能需要将 verilog 文件声明为任务的头文件
You may need to declare the verilog file as a header file for the task
这篇关于如何从 Verilog 中的单独模块调用任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!