另请参阅:PS/2 数据包解析器。
现在您有一个状态机来识别 PS/2 字节流中的三字节消息,请添加一个数据路径,该数据路径也将在收到数据包时输出 24 位(3 字节)消息(out_bytes[23:16] 是第一个字节,out_bytes[15:8] 是第二个字节,依此类推)。
每当断言完成信号时,out_bytes都需要有效。你可以在其他时间输出任何东西(即,不在乎)。
module top_module(
input clk,
input [7:0] in,
input reset, // Synchronous reset
output [23:0] out_bytes,
output done); //
reg [2:0] state,new_state;
parameter s0=0,s1=1,s2=2,s3=3;
always@(*)begin
case(state)
s0:begin new_state=in[3]?s1:s0;out_bytes[7:0]<=in[7:0] ;end
s1:begin new_state=s2; out_bytes[23:16]<=in[7:0] ;end
s2:begin new_state=s3;out_bytes[15:8]<=in[7:0];end
s3:begin new_state=in[3]?s1:s0;out_bytes[7:0]<= in[7:0] ;end
endcase
end
always@(posedge clk)begin
if(reset) state<=s0;
else state<=new_state;
end
assign done=state==s3;
endmodule
为什么把结果输出和状态放在一块不能实现结果