From 9e3862f6943d610b7e962525eedb908206ae46d2 Mon Sep 17 00:00:00 2001 From: yangshenbo Date: Sun, 5 Apr 2026 14:55:47 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=B1=E5=8E=9F=E6=9D=A5=E7=9A=84=E5=B0=8F?= =?UTF-8?q?=E7=AB=AF=E5=BA=8F=E6=94=B9=E4=B8=BA=E5=A4=A7=E7=AB=AF=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rtl/uart_top_32bit.v | 14 +++++++------- tb/TB_top.sv | 6 ++---- tb/tb_uart_ctrl_sysreg.v | 8 ++++---- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/rtl/uart_top_32bit.v b/rtl/uart_top_32bit.v index c3d8594..f5574ed 100644 --- a/rtl/uart_top_32bit.v +++ b/rtl/uart_top_32bit.v @@ -62,7 +62,7 @@ module uart_top_32bit #( end 1, 2, 3, 4: begin // 依次发送字节0, 1, 2, 3 - byte_tx_data_reg <= tx_data_buffer[7:0]; // 优先发低位(小端) + byte_tx_data_reg <= tx_data_buffer[31:24]; // 优先发高位置(大端) byte_tx_go_reg <= 1; tx_state <= tx_state + 4; // 跳转到等待状态 (利用加法偏移) end @@ -71,7 +71,7 @@ module uart_top_32bit #( 5, 6, 7, 8: begin byte_tx_go_reg <= 0; if (byte_tx_done) begin - tx_data_buffer <= tx_data_buffer >> 8; // 移位,准备下一字节 + tx_data_buffer <= tx_data_buffer << 8; // 移位,准备下一字节 if (tx_state == 8) tx_state <= 0; // 发完4个 else tx_state <= tx_state - 3; // 回到下一个发送状态 end @@ -97,12 +97,12 @@ module uart_top_32bit #( end else begin rx_done32_reg <= 0; if (byte_rx_done) begin - // 拼接数据 (小端模式) + // 拼接数据 (大端模式) case(rx_cnt) - 0: rx_data_buffer[7:0] <= byte_rx_data; - 1: rx_data_buffer[15:8] <= byte_rx_data; - 2: rx_data_buffer[23:16] <= byte_rx_data; - 3: rx_data_buffer[31:24] <= byte_rx_data; + 0: rx_data_buffer[31:24] <= byte_rx_data; + 1: rx_data_buffer[23:16] <= byte_rx_data; + 2: rx_data_buffer[15:8] <= byte_rx_data; + 3: rx_data_buffer[7:0] <= byte_rx_data; endcase if (rx_cnt == 3) begin diff --git a/tb/TB_top.sv b/tb/TB_top.sv index 91f3b1c..6068fd9 100644 --- a/tb/TB_top.sv +++ b/tb/TB_top.sv @@ -47,8 +47,7 @@ module TB_top(); // 任务:发送 32/64 位数据 task automatic send_data(input [63:0] data, input int len_bits); int bytes = len_bits / 8; - for (int i = 0; i < bytes; i++) begin - // 默认小端发送:低字节在前 + for (int i = bytes - 1; i >= 0; i--) begin // 从最高字节往下发 send_byte(data[i*8 +: 8]); end endtask @@ -128,7 +127,7 @@ module TB_top(); #(BIT_TIME); end // 组合成32位数据(小端序:先收到的在低位) - packet_word[8*byte_idx +: 8] = rx_byte; + packet_word[24 - 8*byte_idx +: 8] = rx_byte; $display("[%t] Byte %0d: 0x%h", $time, byte_idx, rx_byte); // 等待停止位结束 if (byte_idx < 3) begin @@ -139,7 +138,6 @@ module TB_top(); // 写入文件(一行一个32位数据) $fdisplay(rx_file_h, "%08h", packet_word); $display("[%t] Packet (32-bit): 0x%08h", $time, packet_word); - // 等待最后一个字节的停止位结束 #(BIT_TIME / 2); end diff --git a/tb/tb_uart_ctrl_sysreg.v b/tb/tb_uart_ctrl_sysreg.v index fcdccb0..5a0a2ca 100644 --- a/tb/tb_uart_ctrl_sysreg.v +++ b/tb/tb_uart_ctrl_sysreg.v @@ -83,11 +83,11 @@ uart_ctrl_sysreg #( input [31:0] data; begin // 注意:这里发送顺序要和你的串口接收模块端序一致 - // 假设小端发送:先发 [7:0] - send_byte(data[7:0]); - send_byte(data[15:8]); - send_byte(data[23:16]); + // 假设大端发送:先发 [7:0] send_byte(data[31:24]); + send_byte(data[23:16]); + send_byte(data[15:8]); + send_byte(data[7:0]); end endtask