【发布时间】:2020-05-31 07:05:27
【问题描述】:
我将一些 systermverilog 代码重写到 chisel 中,但我找不到在 chisel 中表达 systemverilog 打包联合的好方法。例如,
typedef struct packed {
logic [3:0] version;
logic [3:0] ihl;
logic [7:0] tos;
logic [15:0] total_length;
logic [15:0] id;
logic reserved;
logic df;
logic mf;
logic [12:0] frag_offset;
logic [7:0] ttl;
logic [7:0] protocol;
logic [15:0] checksum;
logic [31:0] ip_sa;
logic [31:0] ip_da;
} ipv4_s;
typedef struct packed {
logic [63:0] DW0;
logic [63:0] DW1;
logic [31:0] DW2;
} common_20b_s;
typedef union packed {
ipv4_s structured;
common_20b_s array;
logic [$bits(ipv4_s)-1:0] bits;
} ipv4_hdr_u;
module test (
input clk,
input [$bits(ipv4_s)-1:0] pkt_stream_in,
input [3:0] mode,
input [127:0] config_in,
output reg [$bits(ipv4_s)-1:0] pkt_stream_out
);
ipv4_hdr_u ipv4_hdr;
always @* begin
ipv4_hdr.bits = pkt_stream_in;
case(mode)
0: ipv4_hdr.structured.ip_sa = config_in[31:0];
1: ipv4_hdr.array.DW0 = config_in[63:0];
endcase
end
always @(posedge clk)
pkt_stream_out <= ipv4_hdr.bits;
endmodule: test
对于ipv4_s和common_2b_s这两个数据结构,结构中的每个字段都可以单独更新,但是要凿。有没有办法表达这种功能?
【问题讨论】:
标签: chisel