|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
才学会标准状态机的3个process格式书写规范:
module fsm_cc8_3r
(output reg y1, y2, y3,
input jmp, go, sk0, sk1, clk, rst_n);
parameter S0 = 4'b0000,
S1 = 4'b0001,
S2 = 4'b0010,
S3 = 4'b0011,
S4 = 4'b0100,
S5 = 4'b0101,
S6 = 4'b0110,
S7 = 4'b0111,
S8 = 4'b1000,
S9 = 4'b1001;
reg [3:0] state, next;
always @(posedge clk or negedge rst_n)
if (!rst_n) state <= S0;
else state <= next;
always @(state or jmp or go or sk0 or sk1)
begin
next = 4'bx;
case (state)
S0 : if (!go) next = S0;
else if (jmp) next = S3;
else next = S1;
S1 : if (jmp) next = S3;
else next = S2;
S2 : if (jmp) next = S3;
else next = S9;
S3 : if (jmp) next = S3;
else next = S4;
S4 : if (jmp) next = S3;
else if (sk0 && !jmp) next = S6;
else next = S5;
S5 : if (jmp) next = S3;
else if (!sk1 && !sk0 && !jmp) next = S6;
else if (!sk1 && sk0 && !jmp) next = S7;
else if ( sk1 && !sk0 && !jmp) next = S8;
else next = S9;
S6 : if (jmp) next = S3;
else if (go && !jmp) next = S7;
else next = S6;
S7 : if (jmp) next = S3;
else next = S8;
S8 : if (jmp) next = S3;
else next = S9;
S9 : if (jmp) next = S3;
else next = S0;
endcase
end
always @(posedge clk or negedge rst_n)
if (!rst_n) begin
y1 <= 1'b0;
y2 <= 1'b0;
y3 <= 1'b0;
end
else begin
y1 <= 1'b0;
y2 <= 1'b0;
y3 <= 1'b0;
case (next)
S0, S2, S4, S5 : ; // default outputs
S7 : y3 <= 1'b1;
S1 : y2 <= 1'b1;
S3 : begin
y1 <= 1'b1;
y2 <= 1'b1;
end
S8 : begin
y2 <= 1'b1;
y3 <= 1'b1;
end
S6, S9 : begin
y1 <= 1'b1;
y2 <= 1'b1;
y3 <= 1'b1;
end
endcase
end
endmodule
这是从一篇讲状态机编写规范的pdf里面找到的。但是没有提及如何做多状态机的嵌套(比如说母状态机与子状态机的分割设计)。想问一下如果按照3个process书写规范来做的话,应该如何做一个多状态机的嵌套? |
|