错误:(vlog-2110) 非法引用网络“代码”

问题描述

我试过这段代码,但它显示了错误:

gray_counter\gray_counter.v(2): (vlog-2110) 非法引用网络 “代码”

module gray_counter(code,clk,rst,count);//module declaration
 input [2:0]code=3'b000;
 input clk,rst;
 output reg count;
 reg [2:0]conv_code;
always@(posedge clk,posedge rst)
 begin
if(rst)
 begin
 count=0;
 end
 else
 begin
 conv_code={code[0],code[0]^code[1],code[1]^code[2]};//converting binary code to gray 
 case(conv_code)
 3'b000:count=count+1;
 3'b001:count=count+1;
 3'b011:count=count+1;
 3'b010:count=count+1;
 3'b110:count=count+1;
 3'b100:count=count+1;
 3'b101:count=count+1;
 3'b111:count=count+1;
 default:count=count+0;
 endcase
 end
 end
endmodule

解决方法

为模块内的 input 端口赋值是非法的。更改:

 input [2:0]code=3'b000;

到:

 input [2:0]code;

您只能从模块外部驱动值,例如在测试平台模块中。

一些模拟器会给你更具体的帮助。我在 VCS 中看到了这一点:

Error-[V2KIIAD] Invalid initialization at declaration
  Source info:  input [2:0]code=3'b000;
  Non-output port 'code' cannot be initialized at declaration.

如果您在 edaplayground 上注册一个免费帐户,您可以在多个模拟器上试用您的代码。

,

Verilog 不允许端口具有默认值。要符合 Verilog,请将 plugins { id "java" id "com.github.johnrengelman.shadow" version "6.1.0" id 'maven-publish' } group 'net.grandtheftmc' version '2.6.1' sourceCompatibility = 1.8 targetCompatibility = 1.8 compileJava.options.encoding = "UTF-8" compileTestJava.options.encoding = "UTF-8" repositories { maven { url 'http://repo.destroystokyo.com/repository/maven-public/' allowInsecureProtocol = true } maven { url 'http://nexus.grandtheftmc.net/content/repositories/releases/' allowInsecureProtocol = true credentials { username mavenUser password mavenPassword } } maven { url 'http://jitpack.io' allowInsecureProtocol = true } maven { url 'http://maven.sk89q.com/repo/' allowInsecureProtocol = true } maven { url 'http://repo.viaversion.com' allowInsecureProtocol = true } maven { url 'http://repo.citizensnpcs.co/' allowInsecureProtocol = true } } dependencies { compileOnly 'com.sk89q.worldedit:worldedit-bukkit:6.1.4-SNAPSHOT' compileOnly 'net.citizensnpcs:citizensapi:2.0.22' compileOnly 'us.myles:viaversion:3.1.0' compileOnly 'com.destroystokyo.paper:paper-api:1.12.2-R0.1-SNAPSHOT' compileOnly 'org.spigotmc:spigot:1.12.2-R0.1' compileOnly 'net.buycraft:BuycraftX:10.3.0' compileOnly 'com.comphenix.protocol:ProtocolLib:4.6.0' compileOnly 'com.github.j0ach1mmall3:JLib:1.10.0' compileOnly 'net.grandtheftmc:wastedguns:1.2.6' compileOnly 'net.grandtheftmc:wastedvehicles:1.1.0' compileOnly 'net.grandtheftmc:wastedcops:1.1.0' compileOnly 'net.grandtheftmc:core:2.6.1' compileOnly 'net.grandtheftmc:houses:1.1.2' compileOnly 'com.gmail.filoghost.holographicdisplays:HolographicDisplays:1.0.0' implementation 'net.grandtheftmc:common:1.1.6' compileOnly 'com.earth2me:Essentials:2.0.0' } shadowJar { archiveFileName = project.name + ".jar" exclude 'META-INF','META-INF/**' destinationDirectory = file("build") } // Force character encoding in case the workspace was not set up correctly tasks.withType(Javadoc) { options.encoding = 'UTF-8' } publishing { publications { maven(MavenPublication) { artifactId = 'gtm' from components.java } } repositories { maven { url 'http://nexus.grandtheftmc.net/content/repositories/releases/' allowInsecureProtocol = true credentials { username mavenUser password mavenPassword } } } } 更改为 input [2:0]code=3'b000;,并且永远不要在 gray_counter 模块中分配 input [2:0]code;

SystemVerilog 确实允许它使用符合 IEEE1800-2012 § 23.2.2.2 ANSI 风格的端口声明列表的 ANSI 风格的模块头文件。与较新的 IEEE1800-2017 相同的部分。我无法对 LRM 中的示例进行罚款,但从语法中可以清楚地看出。我在较旧的 IEEE1800-2005 中没有发现它们的语法相同。我没有看到 LRM 建议默认分配对于非 ANSI 标头是合法的;但是我确实注意到支持带有 ANSI 模块标头的默认值的模拟器也支持非 ANSI。

要启用 SystemVerilog 解析,请将文件扩展名从 code 更改为 .v。请注意,某些模拟器仅支持有限的 SystemVerilog 功能子集。您的模拟器或合成器可能不支持具有默认值的端口。如果没有,您必须删除默认分配。

通常,您希望在实例化的地方驱动所有输入。通过为输入分配默认值,您可以使连接成为可选的。这在行业中并不常见,部分原因是完整的工具链(模拟器、合成器、linter 等)需要支持它,部分原因是编码/调试实践。

使用 SystemVerilog,您可以为输入指定默认值,但在大多数情况下您不应该这样做。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...