Thiết kế mô-đun cấp cao nhất:
module EEPROM_I2C_Controller(
input wire sys_clk ,
input wire sys_rst_n ,
input wire read_key ,
input wire write_key ,
output wire sda_line ,
inout wire scl_line
);
wire read_press ;
wire write_press ;
wire [7:0] data_fifo_out;
wire start_transmit;
wire write_enable;
wire read_enable ;
wire [15:0] address_val ;
wire [7:0] transmit_byte;
wire i2c_clock ;
wire transaction_done;
wire [7:0] received_byte;
button_debounce write_debouncer(
.clock ( sys_clk ),
.reset_active_low ( sys_rst_n ),
.input_button ( write_key ),
.pulse_positive ( write_press ),
.pulse_negative ( ),
.current_state ( )
);
button_debounce read_debouncer(
.clock ( sys_clk ),
.reset_active_low ( sys_rst_n ),
.input_button ( read_key ),
.pulse_positive ( read_press ),
.pulse_negative ( ),
.current_state ( )
);
data_handler data_handler_unit(
.clock (sys_clk ),
.reset_active_low (sys_rst_n ),
.read_trigger (read_press ),
.write_trigger (write_press ),
.i2c_timer (i2c_clock ),
.transaction_complete(transaction_done ),
.received_data (received_byte ),
.fifo_output (data_fifo_out ),
.start_signal (start_transmit ),
.write_control (write_enable ),
.read_control (read_enable ),
.target_address (address_val ),
.transmit_value (transmit_byte )
);
i2c_master_controller i2c_master_unit(
.clock (sys_clk ),
.reset_active_low (sys_rst_n ),
.start_request (start_transmit ),
.write_cmd (write_enable ),
.read_cmd (read_enable ),
.access_address (address_val ),
.data_to_write (transmit_byte ),
.address_count (1'd1 ),
.scl_pin (scl_line ),
.sda_pin (sda_line ),
.timer_input (i2c_clock ),
.completion_flag (transaction_done ),
.received_data (received_byte )
);
endmodule
Sơ đồ RTL cấp cao:
(Hình ảnh minh họa sơ đồ kết nối các mô-đun)
Mã kiểm thử mô phỏng:
`timescale 1ns / 1ps
module EEPROM_I2C_testbench;
reg system_clock;
reg active_reset;
reg read_button ;
reg write_button;
wire sda_signal ;
wire scl_signal ;
initial system_clock = 1'd1;
always #10 system_clock = ~ system_clock;
defparam EEPROM_I2C_unit.write_debouncer.COUNT_LIMIT = 5;
defparam EEPROM_I2C_unit.read_debouncer.COUNT_LIMIT = 5;
defparam EEPROM_I2C_unit.data_handler_unit.WAIT_COUNT_MAX = 10_000;
initial begin
active_reset <= 1'd0;
read_button <= 1'd1;
write_button <= 1'd1;
#21;
active_reset <= 1'd1;
#1000;
read_button <= 1'd1;
write_button <= 1'd0;
#400;
read_button <= 1'd1;
write_button <= 1'd1;
#200_000_000;
read_button <= 1'd0;
write_button <= 1'd1;
#400;
read_button <= 1'd1;
write_button <= 1'd1;
#400_000_000;
$stop;
end
EEPROM_I2C_Controller EEPROM_I2C_unit(
.sys_clk ( system_clock ),
.sys_rst_n ( active_reset ),
.read_key ( read_button ),
.write_key ( write_button ),
.sda_line (sda_signal ),
.scl_line (scl_signal )
);
M24LC64_EEPROM eeprom_simulation(
.A0 (1'd1 ),
.A1 (1'd1 ),
.A2 (1'd0 ),
.WP (1'd0 ),
.SDA (sda_signal ),
.SCL (scl_signal ),
.RESET (~active_reset )
);
endmodule
Kết quả mô phỏng (Mô hình mô phỏng từ nhà cung cấp chưa đạt yêu cầu, dữ liệu đọc không như mong đợi):
(Biểu đồ sóng mô phỏng cho thấy các tín hiệu trong quá trình truyền nhận)
Tích hợp IP ILA vào thiết kế cấp cao để phân tích logic thời gian thực:
(Hình ảnh minh họa việc tích hợp và cấu hình IP ILA trong thiết kế)