module CellularAutomata#(
parameter INIT_VEC = 32'b0100_1000_0001_0010_0100_1000_0001_0010,
parameter RULE_VEC = 32'b0000_1100_0100_0111_0000_1100_0000_0110,
N = 32
)(
input clk_i, reset, //鍏ㄥ眬淇″彿
output [N-1:0] uni_out
);
reg [N-1:0] uni_r;
wire [N-1:0] uni_next;
assign uni_out = uni_r;
always @(posedge clk_i or negedge reset ) begin
if(reset)begin
uni_r <= INIT_VEC;
end
else begin
uni_r <= uni_next;
end
end
generate
genvar i;
for(i=0; i<N; i=i+1) begin
if (i==0) begin
SingleCell#(.init(INIT_VEC[i]), .head(1'b1), .tail(1'b0))
inst_SingleCell_head (
.clk_i (clk_i),
.ctrl (RULE_VEC[i]),
.left (1'b0),
.right (uni_r[1]),
.self (uni_r[i]),
.out (uni_next[i])
);
end
else if (i==N-1) begin
SingleCell#(.init(INIT_VEC[i]), .head(1'b0), .tail(1'b1))
inst_SingleCell_tail (
.clk_i (clk_i),
.ctrl (RULE_VEC[i]),
.left (uni_r[N-2]),
.right (1'b0),
.self (uni_r[i]),
.out (uni_next[i])
);
end
else begin
SingleCell#(.init(INIT_VEC[i]), .head(1'b0), .tail(1'b0))
inst_SingleCell (
.clk_i (clk_i),
.ctrl (RULE_VEC[i]),
.left (uni_r[i-1]),
.right (uni_r[i+1]),
.self (uni_r[i]),
.out (uni_next[i])
);
end
end
endgenerate
endmodule