| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- `timescale 1ns/1ps
- // 16-bit register bank for the Host-I2C frontend. Application semantics are
- // reported through the response registers; bus ACK is handled by the slave.
- module host_i2c_register_bank (
- input wire clk,
- input wire rst_n,
- input wire write_strobe,
- input wire [15:0] write_address,
- input wire [7:0] write_data,
- input wire command_strobe,
- input wire [7:0] command_data,
- input wire [15:0] read_address,
- output reg [7:0] read_data,
- output reg response_valid,
- output reg [7:0] response_ok,
- output reg [7:0] response_command,
- output reg [7:0] response_status,
- output reg [7:0] response_detail,
- output reg [15:0] snapshot_length,
- input wire [7:0] snapshot_data,
- output reg manual_wr_en,
- output reg [4:0] manual_wr_addr,
- output reg [7:0] manual_wr_data,
- output reg manual_commit,
- input wire manual_commit_done,
- input wire manual_commit_ok,
- input wire hard_protect,
- input wire manual_active,
- input wire watchdog_active,
- input wire bmc_valid,
- input wire bmc_stale,
- input wire snapshot_valid
- );
- reg [7:0] staging [0:31];
- reg [31:0] written_mask;
- reg bad_value_seen;
- reg [7:0] bad_value_index;
- reg pending_commit;
- reg [7:0] pending_command;
- reg [15:0] snapshot_base;
- integer i;
- always @* begin
- read_data = 8'd0;
- if (read_address >= 16'h0100 && read_address <= 16'h011F)
- read_data = staging[read_address[4:0]];
- else if (read_address == 16'h0000)
- read_data = {snapshot_valid, hard_protect, bmc_stale, bmc_valid, watchdog_active, manual_active, response_valid, pending_commit};
- else if (read_address == 16'h0001) read_data = response_ok;
- else if (read_address == 16'h0002) read_data = response_command;
- else if (read_address == 16'h0003) read_data = response_status;
- else if (read_address == 16'h0004) read_data = response_detail;
- else if (read_address == 16'h0005) read_data = 8'd0;
- else if (read_address == 16'h0006) read_data = written_mask[7:0];
- else if (read_address == 16'h0007) read_data = snapshot_length[7:0];
- else if (read_address == 16'h0008) read_data = snapshot_length[15:8];
- else if (read_address >= 16'h0200 && read_address <= 16'h02FF)
- read_data = snapshot_data;
- end
- always @(posedge clk or negedge rst_n) begin
- if (!rst_n) begin
- written_mask <= 0; bad_value_seen <= 0; bad_value_index <= 0; pending_commit <= 0; pending_command <= 0;
- response_valid <= 0; response_ok <= 0; response_command <= 0;
- response_status <= 0; response_detail <= 0; snapshot_length <= 0;
- snapshot_base <= 0; manual_wr_en <= 0; manual_wr_addr <= 0;
- manual_wr_data <= 0; manual_commit <= 0;
- for (i = 0; i < 32; i = i + 1) staging[i] <= 0;
- end else begin
- manual_wr_en <= 0;
- manual_commit <= 0;
- if (write_strobe && write_address >= 16'h0100 && write_address <= 16'h011F) begin
- staging[write_address[4:0]] <= write_data;
- if (write_data <= 100) begin
- written_mask[write_address[4:0]] <= 1'b1;
- manual_wr_en <= 1;
- manual_wr_addr <= write_address[4:0];
- manual_wr_data <= write_data;
- end else if (!bad_value_seen) begin
- bad_value_seen <= 1'b1;
- bad_value_index <= write_address[7:0] - 8'h00;
- end
- end
- if (command_strobe) begin
- response_valid <= 0;
- response_command <= command_data;
- pending_command <= command_data;
- if (command_data == 8'h01) begin
- if (hard_protect) begin
- response_ok <= 0; response_status <= 4; response_detail <= 0; response_valid <= 1;
- end else if (bad_value_seen) begin
- response_ok <= 0; response_status <= 3; response_detail <= bad_value_index; response_valid <= 1;
- end else if (written_mask != 32'hFFFFFFFF) begin
- response_ok <= 0; response_status <= 2; response_detail <= 0; response_valid <= 1;
- end else begin
- pending_commit <= 1; manual_commit <= 1;
- end
- end else if (command_data == 8'h02) begin
- response_ok <= 1; response_status <= 0; response_detail <= 0;
- response_valid <= 1; snapshot_length <= 16'd201;
- end else begin
- response_ok <= 0; response_status <= 1; response_detail <= 0;
- response_valid <= 1;
- end
- end
- if (pending_commit && manual_commit_done) begin
- pending_commit <= 0;
- response_ok <= manual_commit_ok ? 1 : 0;
- response_status <= manual_commit_ok ? 0 : 4;
- response_detail <= 0;
- response_valid <= 1;
- if (manual_commit_ok) begin written_mask <= 0; bad_value_seen <= 0; end
- end
- end
- end
- endmodule
|