Change MISO logic
This commit is contained in:
+18
-6
@@ -76,18 +76,31 @@ module BUS_Con (
|
|||||||
localparam DONE = 2'b11;
|
localparam DONE = 2'b11;
|
||||||
|
|
||||||
|
|
||||||
always @(posedge i_sys_clk) begin
|
always @(posedge i_sys_clk) begin
|
||||||
if (!i_rst_n) begin
|
if (!i_rst_n) begin
|
||||||
recv_reg <= 32'd0;
|
recv_reg <= 32'd0;
|
||||||
bit_cnt <= 6'd0;
|
bit_cnt <= 6'd0;
|
||||||
data_ready <= 1'b0;
|
data_ready <= 1'b0;
|
||||||
err_flag <= 1'b0;
|
err_flag <= 1'b0;
|
||||||
end
|
end
|
||||||
else begin
|
else begin
|
||||||
|
// Clear data_ready when FSM has consumed the command
|
||||||
|
if (state == CMD_SENT) begin
|
||||||
|
data_ready <= 1'b0;
|
||||||
|
end
|
||||||
|
|
||||||
if (cs_active) begin
|
if (cs_active) begin
|
||||||
if (sclk_rise) begin
|
if (sclk_rise) begin
|
||||||
recv_reg <= {recv_reg[30:0], mosi_data};
|
recv_reg <= {recv_reg[30:0], mosi_data};
|
||||||
if (bit_cnt == 6'd31) begin
|
if (bit_cnt == 6'd7) begin
|
||||||
|
// 8th bit received: check if read (MSB=0) or write (MSB=1)
|
||||||
|
if (recv_reg[0] == 1'b0) begin
|
||||||
|
// Read command: set data_ready after 8 bits
|
||||||
|
data_ready <= 1'b1;
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else if (bit_cnt == 6'd31) begin
|
||||||
|
// 32nd bit received: write command complete
|
||||||
data_ready <= 1'b1;
|
data_ready <= 1'b1;
|
||||||
end
|
end
|
||||||
bit_cnt <= bit_cnt + 1'b1;
|
bit_cnt <= bit_cnt + 1'b1;
|
||||||
@@ -108,8 +121,8 @@ module BUS_Con (
|
|||||||
if (state == DONE) begin
|
if (state == DONE) begin
|
||||||
recv_reg <= 'd0;
|
recv_reg <= 'd0;
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
// --- 3. MISO (Transmit) Logic ---
|
// --- 3. MISO (Transmit) Logic ---
|
||||||
// Protocol: We shift out 32 bits.
|
// Protocol: We shift out 32 bits.
|
||||||
@@ -187,7 +200,6 @@ module BUS_Con (
|
|||||||
|
|
||||||
CMD_SENT: begin
|
CMD_SENT: begin
|
||||||
cmd_valid_out <= 1'b0;
|
cmd_valid_out <= 1'b0;
|
||||||
data_ready <= 1'b0; // Clear data_ready when FSM consumes it
|
|
||||||
state <= DONE;
|
state <= DONE;
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
+18
-6
@@ -76,18 +76,31 @@ module BUS_Con (
|
|||||||
localparam DONE = 2'b11;
|
localparam DONE = 2'b11;
|
||||||
|
|
||||||
|
|
||||||
always @(posedge i_sys_clk) begin
|
always @(posedge i_sys_clk) begin
|
||||||
if (!i_rst_n) begin
|
if (!i_rst_n) begin
|
||||||
recv_reg <= 32'd0;
|
recv_reg <= 32'd0;
|
||||||
bit_cnt <= 6'd0;
|
bit_cnt <= 6'd0;
|
||||||
data_ready <= 1'b0;
|
data_ready <= 1'b0;
|
||||||
err_flag <= 1'b0;
|
err_flag <= 1'b0;
|
||||||
end
|
end
|
||||||
else begin
|
else begin
|
||||||
|
// Clear data_ready when FSM has consumed the command
|
||||||
|
if (state == CMD_SENT) begin
|
||||||
|
data_ready <= 1'b0;
|
||||||
|
end
|
||||||
|
|
||||||
if (cs_active) begin
|
if (cs_active) begin
|
||||||
if (sclk_rise) begin
|
if (sclk_rise) begin
|
||||||
recv_reg <= {recv_reg[30:0], mosi_data};
|
recv_reg <= {recv_reg[30:0], mosi_data};
|
||||||
if (bit_cnt == 6'd31) begin
|
if (bit_cnt == 6'd7) begin
|
||||||
|
// 8th bit received: check if read (MSB=0) or write (MSB=1)
|
||||||
|
if (recv_reg[0] == 1'b0) begin
|
||||||
|
// Read command: set data_ready after 8 bits
|
||||||
|
data_ready <= 1'b1;
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else if (bit_cnt == 6'd31) begin
|
||||||
|
// 32nd bit received: write command complete
|
||||||
data_ready <= 1'b1;
|
data_ready <= 1'b1;
|
||||||
end
|
end
|
||||||
bit_cnt <= bit_cnt + 1'b1;
|
bit_cnt <= bit_cnt + 1'b1;
|
||||||
@@ -108,8 +121,8 @@ module BUS_Con (
|
|||||||
if (state == DONE) begin
|
if (state == DONE) begin
|
||||||
recv_reg <= 'd0;
|
recv_reg <= 'd0;
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
// --- 3. MISO (Transmit) Logic ---
|
// --- 3. MISO (Transmit) Logic ---
|
||||||
// Protocol: We shift out 32 bits.
|
// Protocol: We shift out 32 bits.
|
||||||
@@ -189,7 +202,6 @@ module BUS_Con (
|
|||||||
|
|
||||||
CMD_SENT: begin
|
CMD_SENT: begin
|
||||||
cmd_valid_out <= 1'b0;
|
cmd_valid_out <= 1'b0;
|
||||||
data_ready <= 1'b0; // Clear data_ready when FSM consumes it
|
|
||||||
state <= DONE;
|
state <= DONE;
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
+18
-6
@@ -76,18 +76,31 @@ module BUS_Con (
|
|||||||
localparam DONE = 2'b11;
|
localparam DONE = 2'b11;
|
||||||
|
|
||||||
|
|
||||||
always @(posedge i_sys_clk) begin
|
always @(posedge i_sys_clk) begin
|
||||||
if (!i_rst_n) begin
|
if (!i_rst_n) begin
|
||||||
recv_reg <= 32'd0;
|
recv_reg <= 32'd0;
|
||||||
bit_cnt <= 6'd0;
|
bit_cnt <= 6'd0;
|
||||||
data_ready <= 1'b0;
|
data_ready <= 1'b0;
|
||||||
err_flag <= 1'b0;
|
err_flag <= 1'b0;
|
||||||
end
|
end
|
||||||
else begin
|
else begin
|
||||||
|
// Clear data_ready when FSM has consumed the command
|
||||||
|
if (state == CMD_SENT) begin
|
||||||
|
data_ready <= 1'b0;
|
||||||
|
end
|
||||||
|
|
||||||
if (cs_active) begin
|
if (cs_active) begin
|
||||||
if (sclk_rise) begin
|
if (sclk_rise) begin
|
||||||
recv_reg <= {recv_reg[30:0], mosi_data};
|
recv_reg <= {recv_reg[30:0], mosi_data};
|
||||||
if (bit_cnt == 6'd31) begin
|
if (bit_cnt == 6'd7) begin
|
||||||
|
// 8th bit received: check if read (MSB=0) or write (MSB=1)
|
||||||
|
if (recv_reg[0] == 1'b0) begin
|
||||||
|
// Read command: set data_ready after 8 bits
|
||||||
|
data_ready <= 1'b1;
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else if (bit_cnt == 6'd31) begin
|
||||||
|
// 32nd bit received: write command complete
|
||||||
data_ready <= 1'b1;
|
data_ready <= 1'b1;
|
||||||
end
|
end
|
||||||
bit_cnt <= bit_cnt + 1'b1;
|
bit_cnt <= bit_cnt + 1'b1;
|
||||||
@@ -108,8 +121,8 @@ module BUS_Con (
|
|||||||
if (state == DONE) begin
|
if (state == DONE) begin
|
||||||
recv_reg <= 'd0;
|
recv_reg <= 'd0;
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
// --- 3. MISO (Transmit) Logic ---
|
// --- 3. MISO (Transmit) Logic ---
|
||||||
// Protocol: We shift out 32 bits.
|
// Protocol: We shift out 32 bits.
|
||||||
@@ -189,7 +202,6 @@ module BUS_Con (
|
|||||||
|
|
||||||
CMD_SENT: begin
|
CMD_SENT: begin
|
||||||
cmd_valid_out <= 1'b0;
|
cmd_valid_out <= 1'b0;
|
||||||
data_ready <= 1'b0; // Clear data_ready when FSM consumes it
|
|
||||||
state <= DONE;
|
state <= DONE;
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user