由原来的小端序改为大端序
This commit is contained in:
parent
be7c6d5c78
commit
9e3862f694
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue