如何在Verilog中一起使用inout和reg

用户名

我有以下代码:

module s(clock, direction, readWrite, LA1, LA2, LA3, LA4, LD1, LD2, LD3, LD4, RA1, RA2, RA3, RA4, RD1, RD2, RD3, RD4);
// parameters
input clock, direction, readWrite;      
inout reg [7:0] LD1, LD2, LD3, LD4, RD1, RD2, RD3, RD4;
inout reg [11:0] LA1, LA2, LA3, LA4, RA1, RA2, RA3, RA4;

// code
always @(posedge clock) begin
    if(direction==1) begin          // left to right
        assign RA1 = LA1 | LA2 | LA3 | LA4;
        assign RD1 = LD1 | LD2 | LD3 | LD4;     
        assign { RA2, RA3, RA4 } = RA1;
        assign { RD2, RD3, RD4 } = RD1;     
    end else begin
        if(direction==1) begin      // right to left
            assign LA1 = RA1 | RA2 | RA3 | RA4;
            assign LD1 = RD1 | RD2 | RD3 | RD4;     
            assign { LA2, LA3, LA4 } = LA1;
            assign { LD2, LD3, LD4 } = LD1; 
        end
    end
end
endmodule

但是,在第二行,“ inout reg [7:0] LD1,...”声明在VeritakWin 3.84F中引发了语法错误。(Veritak允许一起使用“ output reg”,因为我在程序中的给定代码之后有一个类似的代码)。如果删除“ reg”,则会在分配行中收到错误消息。如果删除“ inout”,显然会出现错误。我什至尝试删除“ assign”关键字,并通过将“ =”替换为“ <=”,但仍然存在错误。我究竟做错了什么?(我是Verilog的新手)

梅兰·托基(Mehran Torki)

inout端口不能为类型regassign您用来为inout端口分配值的类型称为过程连续分配,但是这种类型的端口不允许这样做。您必须改为使用连续分配在您的代码中:

module s(clock, direction, readWrite, LA1, LA2, LA3, LA4, LD1, LD2, LD3, LD4, RA1, RA2, RA3, RA4, RD1, RD2, RD3, RD4);
// parameters input clock, direction, readWrite;      
inout [7:0] LD1, LD2, LD3, LD4, RD1, RD2, RD3, RD4;
inout [11:0] LA1, LA2, LA3, LA4, RA1, RA2, RA3, RA4;

// left to right
assign RA1 = (direction) ? (LA1 | LA2 | LA3 | LA4) : 'bz;
assign RD1 = (direction) ? (LD1 | LD2 | LD3 | LD4) : 'bz;     
assign { RA2, RA3, RA4 } = (direction) ? RA1 : 'bz;
assign { RD2, RD3, RD4 } = (direction) ? RD1 : 'bz;     

// right to left
assign LA1 = (!direction) ? (RA1 | RA2 | RA3 | RA4) : 'bz;
assign LD1 = (!direction) ? (RD1 | RD2 | RD3 | RD4) : 'bz;     
assign { LA2, LA3, LA4 } = (!direction) ? LA1 : 'bz;
assign { LD2, LD3, LD4 } = (!direction) ? LD1 : 'bz; 

endmodule

请注意,您不能同时读写inout端口,因此在读取时设置了高阻抗值。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在while和foreach循环中一起使用PHP和MySQL?

如何在 Swift iOS 中一起使用 UITableView 和 NSLink?

如何在PHP中一起使用复选框和输入类型编号

如何在SQL Server中一起使用相等和不相等

如何在for循环中一起使用innerHTML和ejs?

如何在 MongoDB 中一起使用 match 和 sum?

如何在python中一起使用.join()和.format()

如何在熊猫中一起使用distinct和where子句?

我如何在React中一起使用'update'和setState(prevState)?

如何在Google表格中一起使用to_date和IFERROR?

如何在 Pandas 中一起使用 groupby、select、count(*) 和 SQL 的 where 命令

如何在Bash中一起使用watch和jobs命令?

如何在Apache Beam中一起使用MapElements和KV?

如何在输入中一起使用 :value 和 v-model

如何在Python中一起使用filter,group by和agg函数

如何在SQL Server中一起使用count,case和Distinct

如何在laravel中一起使用whereBetween和like运算符?

如何在SQL中一起使用IN子句和AND子句

如何在Scrapy中一起使用http和https代理?

您如何在Groovy中一起使用GroupBy和Sum?

如何在SQL Server查询中一起使用LIKE和NOT LIKE

如何在angular 1中一起使用ng-if和ng-options

如何在SQL中一起使用数据透视和分组依据?

如何在Redis中一起使用复制和分片?

如何在适配器类和活动中一起使用Interface

如何在Powerapps中一起使用collect和if函数?

如何在Ansible中一起使用loop和with_nested

如何在Access VBA编码中一起使用Select Case和AND功能?

如何在SQLAlchemy中一起使用JOIN和SELECT AS?