Fsm ps2data

See also: PS/2 packet parser.

Now that you have a state machine that will identify three-byte messages in a PS/2 byte stream, add a datapath that will also output the 24-bit (3 byte) message whenever a packet is received (out_bytes[23:16] is the first byte, out_bytes[15:8] is the second byte, etc.).

out_bytes needs to be valid whenever the done signal is asserted. You may output anything at other times (i.e., don't-care).

For example:

cpp 复制代码
module top_module(
    input clk,
    input [7:0] in,
    input reset,    // Synchronous reset
    output [23:0] out_bytes,
    output done); //

    parameter BYTE1 = 2'b00,
    			BYTE2 = 2'b01,
    		BYTE3 = 2'b11,
    		DONE = 2'b10;
    
    reg [1:0] state;
    reg [1:0] next_state;
    reg [7:0] in_1, in_2;
   
  
    always@(*)
        case(state)
        	BYTE1: 
                if(in[3])
                    next_state <= BYTE2;
            	else 
                     next_state <= BYTE1;
            BYTE2:  
                     next_state <= BYTE3;
            BYTE3:  
                    next_state <= DONE; 
            DONE: 
                if(in[3])
                    next_state <= BYTE2;
            	else 
                     next_state <= BYTE1;
            default:
                next_state <= BYTE1;
        endcase
    
     
    always@(posedge clk)
        if(reset)
        	state <= BYTE1;
    	else 
            state <= next_state;
     
    always@(posedge clk)
        if(reset) begin
        	in_1 <=  8'b0;
            in_2 <=  8'b0;
            out_bytes <= 24'b0;
        end
    	else  begin
            in_1 <=  in; 
            in_2 <= in_1;
            out_bytes <= {in_2,in_1,in};
        end
    
	assign done = state == DONE;

endmodule
相关推荐
闻道且行之4 天前
FPGA|Quartus II 中使用TCL文件进行引脚一键分配
fpga开发·verilog·tcl
一丢沙7 天前
Verilog 硬件描述语言自学——重温数电之典型组合逻辑电路
开发语言·算法·fpga开发·verilog
徐晓康的博客14 天前
Verilog功能模块--SPI主机和从机(03)--SPI从机设计思路与代码解析
fpga开发·verilog·主机·spi·从机
微小冷1 个月前
OV5640 相机开发流程
fpga开发·verilog·ov5640·双目相机·相机开发
ChipCamp1 个月前
ChipCamp探索系列 -- 1. Soft-Core RISC-V on FPGA
fpga开发·verilog·risc-v
FPGA小迷弟1 个月前
京微齐力系列FPGA---- Debugware IP核使用教程!!!
物联网·fpga开发·硬件架构·verilog·fpga
月光技术杂谈1 个月前
上海RISC-V峰会-香山开源RISC-V CPU随想随记
verilog·risc-v·chisel·vhdl·香山·开源cpu·xiangshan
可编程芯片开发2 个月前
基于FPGA的多级流水线加法器verilog实现,包含testbench测试文件
fpga开发·verilog·加法器·多级流水线
进击的奶龙2 个月前
02VCS_使用教程
verilog·仿真·eda
热爱学习地派大星2 个月前
Xilinx FPGA功耗评估
fpga开发·verilog·vivado·fpga功耗·xpe