在状态机中我们经常使用独热码,独热码的一个优势就是可以非常方便的取出一位就可以表示状态,免除复杂的比较电路,下面的代码定义了状态和状态信号提取.
reg [6:0] txresp_state;
localparam RD_FIFO = 8'h01;
localparam START_RESP = 8'h02;
localparam WAIT_DATA1 = 8'h04;
localparam WAIT_DATA2 = 8'h08;
localparam SEND_FIRST = 8'h10;
localparam SEND_MAX = 8'h20;
localparam SEND_LAST = 8'h40;
// State machine output assignments
assign rd_fifo = txresp_state[0];
assign start_resp = txresp_state[1];
assign wait_data1 = txresp_state[2];
assign wait_data2 = txresp_state[3];
assign send_first = txresp_state[4];
assign send_max = txresp_state[5];
assign send_last = txresp_state[6]; |