rtl: timing optimization

Signed-off-by: liangkangnan <liangkangnan@163.com>
pull/1/head
liangkangnan 2020-09-09 21:00:14 +08:00
parent 5e4ab8c33c
commit b57bfe7736
9 changed files with 1313 additions and 1306 deletions

View File

@ -47,7 +47,6 @@ module csr_reg(
); );
reg[`DoubleRegBus] cycle; reg[`DoubleRegBus] cycle;
reg[`RegBus] mtvec; reg[`RegBus] mtvec;
reg[`RegBus] mcause; reg[`RegBus] mcause;
@ -56,14 +55,12 @@ module csr_reg(
reg[`RegBus] mstatus; reg[`RegBus] mstatus;
reg[`RegBus] mscratch; reg[`RegBus] mscratch;
assign global_int_en_o = (mstatus[3] == 1'b1)? `True: `False; assign global_int_en_o = (mstatus[3] == 1'b1)? `True: `False;
assign clint_csr_mtvec = mtvec; assign clint_csr_mtvec = mtvec;
assign clint_csr_mepc = mepc; assign clint_csr_mepc = mepc;
assign clint_csr_mstatus = mstatus; assign clint_csr_mstatus = mstatus;
// cycle counter // cycle counter
// //
always @ (posedge clk) begin always @ (posedge clk) begin
@ -142,9 +139,6 @@ module csr_reg(
// read reg // read reg
// exCSR // exCSR
always @ (*) begin always @ (*) begin
if (rst == `RstEnable) begin
data_o = `ZeroWord;
end else begin
if ((waddr_i[11:0] == raddr_i[11:0]) && (we_i == `WriteEnable)) begin if ((waddr_i[11:0] == raddr_i[11:0]) && (we_i == `WriteEnable)) begin
data_o = data_i; data_o = data_i;
end else begin end else begin
@ -179,14 +173,10 @@ module csr_reg(
endcase endcase
end end
end end
end
// read reg // read reg
// clintCSR // clintCSR
always @ (*) begin always @ (*) begin
if (rst == `RstEnable) begin
clint_data_o = `ZeroWord;
end else begin
if ((clint_waddr_i[11:0] == clint_raddr_i[11:0]) && (clint_we_i == `WriteEnable)) begin if ((clint_waddr_i[11:0] == clint_raddr_i[11:0]) && (clint_we_i == `WriteEnable)) begin
clint_data_o = clint_data_i; clint_data_o = clint_data_i;
end else begin end else begin
@ -221,6 +211,5 @@ module csr_reg(
endcase endcase
end end
end end
end
endmodule endmodule

View File

@ -46,11 +46,6 @@ module ctrl(
always @ (*) begin always @ (*) begin
if (rst == `RstEnable) begin
hold_flag_o = `Hold_None;
jump_flag_o = `JumpDisable;
jump_addr_o = `ZeroWord;
end else begin
jump_addr_o = jump_addr_i; jump_addr_o = jump_addr_i;
jump_flag_o = jump_flag_i; jump_flag_o = jump_flag_i;
// //
@ -69,6 +64,5 @@ module ctrl(
hold_flag_o = `Hold_None; hold_flag_o = `Hold_None;
end end
end end
end
endmodule endmodule

View File

@ -170,10 +170,6 @@ module ex(
// //
always @ (*) begin always @ (*) begin
if (rst == `RstEnable) begin
mul_op1 = `ZeroWord;
mul_op2 = `ZeroWord;
end else begin
if ((opcode == `INST_TYPE_R_M) && (funct7 == 7'b0000001)) begin if ((opcode == `INST_TYPE_R_M) && (funct7 == 7'b0000001)) begin
case (funct3) case (funct3)
`INST_MUL, `INST_MULHU: begin `INST_MUL, `INST_MULHU: begin
@ -198,23 +194,9 @@ module ex(
mul_op2 = reg2_rdata_i; mul_op2 = reg2_rdata_i;
end end
end end
end
// //
always @ (*) begin always @ (*) begin
if (rst == `RstEnable) begin
div_dividend_o = `ZeroWord;
div_divisor_o = `ZeroWord;
div_op_o = 3'b0;
div_reg_waddr_o = `ZeroWord;
div_waddr = `ZeroWord;
div_hold_flag = `HoldDisable;
div_we = `WriteDisable;
div_wdata = `ZeroWord;
div_start = `DivStop;
div_jump_flag = `JumpDisable;
div_jump_addr = `ZeroWord;
end else begin
div_dividend_o = reg1_rdata_i; div_dividend_o = reg1_rdata_i;
div_divisor_o = reg2_rdata_i; div_divisor_o = reg2_rdata_i;
div_op_o = funct3; div_op_o = funct3;
@ -261,24 +243,9 @@ module ex(
end end
end end
end end
end
// //
always @ (*) begin always @ (*) begin
if (rst == `RstEnable) begin
jump_flag = `JumpDisable;
hold_flag = `HoldDisable;
jump_addr = `ZeroWord;
mem_wdata_o = `ZeroWord;
mem_raddr_o = `ZeroWord;
mem_waddr_o = `ZeroWord;
mem_we = `WriteDisable;
mem_req = `RIB_NREQ;
reg_wdata = `ZeroWord;
reg_we = `WriteDisable;
reg_waddr = `ZeroReg;
csr_wdata_o = `ZeroWord;
end else begin
reg_we = reg_we_i; reg_we = reg_we_i;
reg_waddr = reg_waddr_i; reg_waddr = reg_waddr_i;
mem_req = `RIB_NREQ; mem_req = `RIB_NREQ;
@ -904,6 +871,5 @@ module ex(
end end
endcase endcase
end end
end
endmodule endmodule

View File

@ -69,24 +69,6 @@ module id(
always @ (*) begin always @ (*) begin
if (rst == `RstEnable) begin
reg1_raddr_o = `ZeroReg;
reg2_raddr_o = `ZeroReg;
csr_raddr_o = `ZeroWord;
inst_o = `INST_NOP;
inst_addr_o = `ZeroWord;
reg1_rdata_o = `ZeroWord;
reg2_rdata_o = `ZeroWord;
csr_rdata_o = `ZeroWord;
reg_we_o = `WriteDisable;
csr_we_o = `WriteDisable;
reg_waddr_o = `ZeroReg;
csr_waddr_o = `ZeroWord;
op1_o = `ZeroWord;
op2_o = `ZeroWord;
op1_jump_o = `ZeroWord;
op2_jump_o = `ZeroWord;
end else begin
inst_o = inst_i; inst_o = inst_i;
inst_addr_o = inst_addr_i; inst_addr_o = inst_addr_i;
reg1_rdata_o = reg1_rdata_i; reg1_rdata_o = reg1_rdata_i;
@ -316,6 +298,5 @@ module id(
end end
endcase endcase
end end
end
endmodule endmodule

View File

@ -38,69 +38,74 @@ module id_ex(
input wire[`Hold_Flag_Bus] hold_flag_i, // 线 input wire[`Hold_Flag_Bus] hold_flag_i, // 线
output reg[`MemAddrBus] op1_o, output wire[`MemAddrBus] op1_o,
output reg[`MemAddrBus] op2_o, output wire[`MemAddrBus] op2_o,
output reg[`MemAddrBus] op1_jump_o, output wire[`MemAddrBus] op1_jump_o,
output reg[`MemAddrBus] op2_jump_o, output wire[`MemAddrBus] op2_jump_o,
output reg[`InstBus] inst_o, // output wire[`InstBus] inst_o, //
output reg[`InstAddrBus] inst_addr_o, // output wire[`InstAddrBus] inst_addr_o, //
output reg reg_we_o, // output wire reg_we_o, //
output reg[`RegAddrBus] reg_waddr_o, // output wire[`RegAddrBus] reg_waddr_o, //
output reg[`RegBus] reg1_rdata_o, // 1 output wire[`RegBus] reg1_rdata_o, // 1
output reg[`RegBus] reg2_rdata_o, // 2 output wire[`RegBus] reg2_rdata_o, // 2
output reg csr_we_o, // CSR output wire csr_we_o, // CSR
output reg[`MemAddrBus] csr_waddr_o, // CSR output wire[`MemAddrBus] csr_waddr_o, // CSR
output reg[`RegBus] csr_rdata_o // CSR output wire[`RegBus] csr_rdata_o // CSR
); );
always @ (posedge clk) begin wire hold_en = (hold_flag_i >= `Hold_Id);
if (rst == `RstEnable) begin
inst_o <= `INST_NOP; wire[`InstBus] inst;
inst_addr_o <= `ZeroWord; gen_pipe_dff #(32) inst_ff(clk, rst, hold_en, `INST_NOP, inst_i, inst);
reg_we_o <= `WriteDisable; assign inst_o = inst;
reg_waddr_o <= `ZeroWord;
reg1_rdata_o <= `ZeroWord; wire[`InstAddrBus] inst_addr;
reg2_rdata_o <= `ZeroWord; gen_pipe_dff #(32) inst_addr_ff(clk, rst, hold_en, `ZeroWord, inst_addr_i, inst_addr);
csr_we_o <= `WriteDisable; assign inst_addr_o = inst_addr;
csr_waddr_o <= `ZeroWord;
csr_rdata_o <= `ZeroWord; wire reg_we;
op1_o <= `ZeroWord; gen_pipe_dff #(1) reg_we_ff(clk, rst, hold_en, `WriteDisable, reg_we_i, reg_we);
op2_o <= `ZeroWord; assign reg_we_o = reg_we;
op1_jump_o <= `ZeroWord;
op2_jump_o <= `ZeroWord; wire[`RegAddrBus] reg_waddr;
end else begin gen_pipe_dff #(5) reg_waddr_ff(clk, rst, hold_en, `ZeroReg, reg_waddr_i, reg_waddr);
// 线 assign reg_waddr_o = reg_waddr;
if (hold_flag_i >= `Hold_Id) begin
inst_o <= `INST_NOP; wire[`RegBus] reg1_rdata;
inst_addr_o <= inst_addr_i; gen_pipe_dff #(32) reg1_rdata_ff(clk, rst, hold_en, `ZeroWord, reg1_rdata_i, reg1_rdata);
reg_we_o <= `WriteDisable; assign reg1_rdata_o = reg1_rdata;
reg_waddr_o <= `ZeroWord;
reg1_rdata_o <= `ZeroWord; wire[`RegBus] reg2_rdata;
reg2_rdata_o <= `ZeroWord; gen_pipe_dff #(32) reg2_rdata_ff(clk, rst, hold_en, `ZeroWord, reg2_rdata_i, reg2_rdata);
csr_we_o <= `WriteDisable; assign reg2_rdata_o = reg2_rdata;
csr_waddr_o <= `ZeroWord;
csr_rdata_o <= `ZeroWord; wire csr_we;
op1_o <= `ZeroWord; gen_pipe_dff #(1) csr_we_ff(clk, rst, hold_en, `WriteDisable, csr_we_i, csr_we);
op2_o <= `ZeroWord; assign csr_we_o = csr_we;
op1_jump_o <= `ZeroWord;
op2_jump_o <= `ZeroWord; wire[`MemAddrBus] csr_waddr;
end else begin gen_pipe_dff #(32) csr_waddr_ff(clk, rst, hold_en, `ZeroWord, csr_waddr_i, csr_waddr);
inst_o <= inst_i; assign csr_waddr_o = csr_waddr;
inst_addr_o <= inst_addr_i;
reg_we_o <= reg_we_i; wire[`RegBus] csr_rdata;
reg_waddr_o <= reg_waddr_i; gen_pipe_dff #(32) csr_rdata_ff(clk, rst, hold_en, `ZeroWord, csr_rdata_i, csr_rdata);
reg1_rdata_o <= reg1_rdata_i; assign csr_rdata_o = csr_rdata;
reg2_rdata_o <= reg2_rdata_i;
csr_we_o <= csr_we_i; wire[`MemAddrBus] op1;
csr_waddr_o <= csr_waddr_i; gen_pipe_dff #(32) op1_ff(clk, rst, hold_en, `ZeroWord, op1_i, op1);
csr_rdata_o <= csr_rdata_i; assign op1_o = op1;
op1_o <= op1_i;
op2_o <= op2_i; wire[`MemAddrBus] op2;
op1_jump_o <= op1_jump_i; gen_pipe_dff #(32) op2_ff(clk, rst, hold_en, `ZeroWord, op2_i, op2);
op2_jump_o <= op2_jump_i; assign op2_o = op2;
end
end wire[`MemAddrBus] op1_jump;
end gen_pipe_dff #(32) op1_jump_ff(clk, rst, hold_en, `ZeroWord, op1_jump_i, op1_jump);
assign op1_jump_o = op1_jump;
wire[`MemAddrBus] op2_jump;
gen_pipe_dff #(32) op2_jump_ff(clk, rst, hold_en, `ZeroWord, op2_jump_i, op2_jump);
assign op2_jump_o = op2_jump;
endmodule endmodule

View File

@ -28,28 +28,25 @@ module if_id(
input wire[`Hold_Flag_Bus] hold_flag_i, // 线 input wire[`Hold_Flag_Bus] hold_flag_i, // 线
input wire[`INT_BUS] int_flag_i, // input wire[`INT_BUS] int_flag_i, //
output reg[`INT_BUS] int_flag_o, output wire[`INT_BUS] int_flag_o,
output reg[`InstBus] inst_o, // output wire[`InstBus] inst_o, //
output reg[`InstAddrBus] inst_addr_o // output wire[`InstAddrBus] inst_addr_o //
); );
always @ (posedge clk) begin wire hold_en = (hold_flag_i >= `Hold_If);
if (rst == `RstEnable) begin
inst_o <= `INST_NOP; wire[`InstBus] inst;
inst_addr_o <= `ZeroWord; gen_pipe_dff #(32) inst_ff(clk, rst, hold_en, `INST_NOP, inst_i, inst);
int_flag_o <= `INT_NONE; assign inst_o = inst;
// 线
end else if (hold_flag_i >= `Hold_If) begin wire[`InstAddrBus] inst_addr;
inst_o <= `INST_NOP; gen_pipe_dff #(32) inst_addr_ff(clk, rst, hold_en, `ZeroWord, inst_addr_i, inst_addr);
inst_addr_o <= inst_addr_i; assign inst_addr_o = inst_addr;
int_flag_o <= `INT_NONE;
end else begin wire[`INT_BUS] int_flag;
inst_o <= inst_i; gen_pipe_dff #(8) int_ff(clk, rst, hold_en, `INT_NONE, int_flag_i, int_flag);
inst_addr_o <= inst_addr_i; assign int_flag_o = int_flag;
int_flag_o <= int_flag_i;
end
end
endmodule endmodule

View File

@ -55,9 +55,9 @@ module regs(
always @ (posedge clk) begin always @ (posedge clk) begin
if (rst == `RstDisable) begin if (rst == `RstDisable) begin
// ex // ex
if ((we_i == `WriteEnable) && (waddr_i != `RegNumLog2'h0)) begin if ((we_i == `WriteEnable) && (waddr_i != `ZeroReg)) begin
regs[waddr_i] <= wdata_i; regs[waddr_i] <= wdata_i;
end else if ((jtag_we_i == `WriteEnable) && (jtag_addr_i != `RegNumLog2'h0)) begin end else if ((jtag_we_i == `WriteEnable) && (jtag_addr_i != `ZeroReg)) begin
regs[jtag_addr_i] <= jtag_data_i; regs[jtag_addr_i] <= jtag_data_i;
end end
end end
@ -65,9 +65,7 @@ module regs(
// 1 // 1
always @ (*) begin always @ (*) begin
if (rst == `RstEnable) begin if (raddr1_i == `ZeroReg) begin
rdata1_o = `ZeroWord;
end else if (raddr1_i == `RegNumLog2'h0) begin
rdata1_o = `ZeroWord; rdata1_o = `ZeroWord;
// //
end else if (raddr1_i == waddr_i && we_i == `WriteEnable) begin end else if (raddr1_i == waddr_i && we_i == `WriteEnable) begin
@ -79,9 +77,7 @@ module regs(
// 2 // 2
always @ (*) begin always @ (*) begin
if (rst == `RstEnable) begin if (raddr2_i == `ZeroReg) begin
rdata2_o = `ZeroWord;
end else if (raddr2_i == `RegNumLog2'h0) begin
rdata2_o = `ZeroWord; rdata2_o = `ZeroWord;
// //
end else if (raddr2_i == waddr_i && we_i == `WriteEnable) begin end else if (raddr2_i == waddr_i && we_i == `WriteEnable) begin
@ -93,9 +89,7 @@ module regs(
// jtag // jtag
always @ (*) begin always @ (*) begin
if (rst == `RstEnable) begin if (jtag_addr_i == `ZeroReg) begin
jtag_data_o = `ZeroWord;
end else if (jtag_addr_i == `RegNumLog2'h0) begin
jtag_data_o = `ZeroWord; jtag_data_o = `ZeroWord;
end else begin end else begin
jtag_data_o = regs[jtag_addr_i]; jtag_data_o = regs[jtag_addr_i];

View File

@ -93,7 +93,7 @@ module rib(
// 访4访 // 访4访
// 16 // 16
parameter [3:0]slave_0 = 4'b0000; parameter [3:0]slave_0 = 4'b0000;
parameter [3:0]slave_1 = 4'b0001; parameter [3:0]slave_1 = 4'b0001;
parameter [3:0]slave_2 = 4'b0010; parameter [3:0]slave_2 = 4'b0010;
@ -115,12 +115,8 @@ module rib(
// //
// //
// 021 // 3021
always @ (*) begin always @ (*) begin
if (rst == `RstEnable) begin
grant = grant1;
hold_flag_o = `HoldDisable;
end else begin
if (req[3]) begin if (req[3]) begin
grant = grant3; grant = grant3;
hold_flag_o = `HoldEnable; hold_flag_o = `HoldEnable;
@ -135,35 +131,9 @@ module rib(
hold_flag_o = `HoldDisable; hold_flag_o = `HoldDisable;
end end
end end
end
// (访) // (访)
always @ (*) begin always @ (*) begin
if (rst == `RstEnable) begin
m0_data_o = `ZeroWord;
m1_data_o = `INST_NOP;
m2_data_o = `ZeroWord;
m3_data_o = `ZeroWord;
s0_addr_o = `ZeroWord;
s1_addr_o = `ZeroWord;
s2_addr_o = `ZeroWord;
s3_addr_o = `ZeroWord;
s4_addr_o = `ZeroWord;
s5_addr_o = `ZeroWord;
s0_data_o = `ZeroWord;
s1_data_o = `ZeroWord;
s2_data_o = `ZeroWord;
s3_data_o = `ZeroWord;
s4_data_o = `ZeroWord;
s5_data_o = `ZeroWord;
s0_we_o = `WriteDisable;
s1_we_o = `WriteDisable;
s2_we_o = `WriteDisable;
s3_we_o = `WriteDisable;
s4_we_o = `WriteDisable;
s5_we_o = `WriteDisable;
end else begin
m0_data_o = `ZeroWord; m0_data_o = `ZeroWord;
m1_data_o = `INST_NOP; m1_data_o = `INST_NOP;
m2_data_o = `ZeroWord; m2_data_o = `ZeroWord;
@ -366,6 +336,5 @@ module rib(
end end
endcase endcase
end end
end
endmodule endmodule

View File

@ -58,22 +58,22 @@ module uart_debug(
// //
localparam S_IDLE = 1; localparam S_IDLE = 14'h0001;
localparam S_INIT_UART_BAUD = 2; localparam S_INIT_UART_BAUD = 14'h0002;
localparam S_CLEAR_UART_RX_OVER_FLAG = 3; localparam S_CLEAR_UART_RX_OVER_FLAG = 14'h0004;
localparam S_WAIT_BYTE = 4; localparam S_WAIT_BYTE = 14'h0008;
localparam S_WAIT_BYTE2 = 5; localparam S_WAIT_BYTE2 = 14'h0010;
localparam S_GET_BYTE = 6; localparam S_GET_BYTE = 14'h0020;
localparam S_REC_FIRST_PACKET = 7; localparam S_REC_FIRST_PACKET = 14'h0040;
localparam S_REC_REMAIN_PACKET = 8; localparam S_REC_REMAIN_PACKET = 14'h0080;
localparam S_SEND_ACK = 9; localparam S_SEND_ACK = 14'h0100;
localparam S_SEND_NAK = 10; localparam S_SEND_NAK = 14'h0200;
localparam S_CRC_START = 11; localparam S_CRC_START = 14'h0400;
localparam S_CRC_CALC = 12; localparam S_CRC_CALC = 14'h0800;
localparam S_CRC_END = 13; localparam S_CRC_END = 14'h1000;
localparam S_WRITE_MEM = 14; localparam S_WRITE_MEM = 14'h2000;
reg[3:0] state; reg[13:0] state;
// //
reg[7:0] rx_data[0:131]; reg[7:0] rx_data[0:131];
@ -83,7 +83,10 @@ module uart_debug(
reg[31:0] fw_file_size; reg[31:0] fw_file_size;
reg[31:0] write_mem_addr; reg[31:0] write_mem_addr;
reg[31:0] write_mem_data; reg[31:0] write_mem_data;
reg[7:0] write_mem_byte_index; reg[7:0] write_mem_byte_index0;
reg[7:0] write_mem_byte_index1;
reg[7:0] write_mem_byte_index2;
reg[7:0] write_mem_byte_index3;
reg[15:0] crc_result; reg[15:0] crc_result;
reg[3:0] crc_bit_index; reg[3:0] crc_bit_index;
@ -177,7 +180,7 @@ module uart_debug(
end end
end end
S_WRITE_MEM: begin S_WRITE_MEM: begin
if (write_mem_byte_index == (need_to_rec_bytes + 2)) begin if (write_mem_byte_index0 == (need_to_rec_bytes + 2)) begin
state <= S_SEND_ACK; state <= S_SEND_ACK;
end else begin end else begin
mem_addr_o <= write_mem_addr; mem_addr_o <= write_mem_addr;
@ -262,25 +265,107 @@ module uart_debug(
always @ (posedge clk) begin always @ (posedge clk) begin
if (rst == 1'b0 || debug_en_i == 1'b0) begin if (rst == 1'b0 || debug_en_i == 1'b0) begin
write_mem_addr <= 32'h0; write_mem_addr <= 32'h0;
write_mem_data <= 32'h0;
write_mem_byte_index <= 8'h0;
end else begin end else begin
case (state) case (state)
S_REC_FIRST_PACKET: begin S_REC_FIRST_PACKET: begin
write_mem_addr <= `ROM_START_ADDR; write_mem_addr <= `ROM_START_ADDR;
write_mem_data <= 32'h0;
write_mem_byte_index <= 8'h0;
end end
S_CRC_END: begin S_CRC_END: begin
write_mem_data <= {rx_data[4], rx_data[3], rx_data[2], rx_data[1]};
write_mem_byte_index <= 8'h5;
if (write_mem_addr > 0) if (write_mem_addr > 0)
write_mem_addr <= write_mem_addr - 4; write_mem_addr <= write_mem_addr - 4;
end end
S_WRITE_MEM: begin S_WRITE_MEM: begin
write_mem_addr <= write_mem_addr + 4; write_mem_addr <= write_mem_addr + 4;
write_mem_data <= {rx_data[write_mem_byte_index + 3], rx_data[write_mem_byte_index + 2], rx_data[write_mem_byte_index + 1], rx_data[write_mem_byte_index]}; end
write_mem_byte_index <= write_mem_byte_index + 4; endcase
end
end
always @ (posedge clk) begin
if (rst == 1'b0 || debug_en_i == 1'b0) begin
write_mem_data <= 32'h0;
end else begin
case (state)
S_REC_FIRST_PACKET: begin
write_mem_data <= 32'h0;
end
S_CRC_END: begin
write_mem_data <= {rx_data[4], rx_data[3], rx_data[2], rx_data[1]};
end
S_WRITE_MEM: begin
write_mem_data <= {rx_data[write_mem_byte_index3], rx_data[write_mem_byte_index2], rx_data[write_mem_byte_index1], rx_data[write_mem_byte_index0]};
end
endcase
end
end
always @ (posedge clk) begin
if (rst == 1'b0 || debug_en_i == 1'b0) begin
write_mem_byte_index0 <= 8'h0;
end else begin
case (state)
S_REC_FIRST_PACKET: begin
write_mem_byte_index0 <= 8'h0;
end
S_CRC_END: begin
write_mem_byte_index0 <= 8'h5;
end
S_WRITE_MEM: begin
write_mem_byte_index0 <= write_mem_byte_index0 + 4;
end
endcase
end
end
always @ (posedge clk) begin
if (rst == 1'b0 || debug_en_i == 1'b0) begin
write_mem_byte_index1 <= 8'h0;
end else begin
case (state)
S_REC_FIRST_PACKET: begin
write_mem_byte_index1 <= 8'h0;
end
S_CRC_END: begin
write_mem_byte_index1 <= 8'h6;
end
S_WRITE_MEM: begin
write_mem_byte_index1 <= write_mem_byte_index1 + 4;
end
endcase
end
end
always @ (posedge clk) begin
if (rst == 1'b0 || debug_en_i == 1'b0) begin
write_mem_byte_index2 <= 8'h0;
end else begin
case (state)
S_REC_FIRST_PACKET: begin
write_mem_byte_index2 <= 8'h0;
end
S_CRC_END: begin
write_mem_byte_index2 <= 8'h7;
end
S_WRITE_MEM: begin
write_mem_byte_index2 <= write_mem_byte_index2 + 4;
end
endcase
end
end
always @ (posedge clk) begin
if (rst == 1'b0 || debug_en_i == 1'b0) begin
write_mem_byte_index3 <= 8'h0;
end else begin
case (state)
S_REC_FIRST_PACKET: begin
write_mem_byte_index3 <= 8'h0;
end
S_CRC_END: begin
write_mem_byte_index3 <= 8'h8;
end
S_WRITE_MEM: begin
write_mem_byte_index3 <= write_mem_byte_index3 + 4;
end end
endcase endcase
end end
@ -290,30 +375,21 @@ module uart_debug(
always @ (posedge clk) begin always @ (posedge clk) begin
if (rst == 1'b0 || debug_en_i == 1'b0) begin if (rst == 1'b0 || debug_en_i == 1'b0) begin
crc_result <= 16'h0; crc_result <= 16'h0;
crc_bit_index <= 4'h0;
crc_byte_index <= 8'h0;
end else begin end else begin
case (state) case (state)
S_CRC_START: begin S_CRC_START: begin
crc_result <= 16'hffff; crc_result <= 16'hffff;
crc_bit_index <= 4'h0;
crc_byte_index <= 8'h1;
end end
S_CRC_CALC: begin S_CRC_CALC: begin
if (crc_bit_index == 4'h0) begin if (crc_bit_index == 4'h0) begin
crc_result <= crc_result ^ rx_data[crc_byte_index]; crc_result <= crc_result ^ rx_data[crc_byte_index];
crc_byte_index <= crc_byte_index + 1'b1;
crc_bit_index <= crc_bit_index + 1'b1;
end else begin end else begin
if (crc_bit_index < 4'h9) begin if (crc_bit_index < 4'h9) begin
crc_bit_index <= crc_bit_index + 1'b1;
if (crc_result[0] == 1'b1) begin if (crc_result[0] == 1'b1) begin
crc_result <= {1'b0, crc_result[15:1]} ^ 16'ha001; crc_result <= {1'b0, crc_result[15:1]} ^ 16'ha001;
end else begin end else begin
crc_result <= {1'b0, crc_result[15:1]}; crc_result <= {1'b0, crc_result[15:1]};
end end
end else begin
crc_bit_index <= 4'h0;
end end
end end
end end
@ -321,4 +397,40 @@ module uart_debug(
end end
end end
always @ (posedge clk) begin
if (rst == 1'b0 || debug_en_i == 1'b0) begin
crc_bit_index <= 4'h0;
end else begin
case (state)
S_CRC_START: begin
crc_bit_index <= 4'h0;
end
S_CRC_CALC: begin
if (crc_bit_index < 4'h9) begin
crc_bit_index <= crc_bit_index + 1'b1;
end else begin
crc_bit_index <= 4'h0;
end
end
endcase
end
end
always @ (posedge clk) begin
if (rst == 1'b0 || debug_en_i == 1'b0) begin
crc_byte_index <= 8'h0;
end else begin
case (state)
S_CRC_START: begin
crc_byte_index <= 8'h1;
end
S_CRC_CALC: begin
if (crc_bit_index == 4'h0) begin
crc_byte_index <= crc_byte_index + 1'b1;
end
end
endcase
end
end
endmodule endmodule