cariboulabs-cariboulite/firmware/smi_ctrl.v

184 wiersze
6.7 KiB
Coq
Czysty Zwykły widok Historia

2021-06-13 11:45:08 +00:00
module smi_ctrl
(
2021-07-14 18:47:12 +00:00
input i_reset,
2021-06-13 11:45:08 +00:00
input i_sys_clk, // FPGA Clock
input [4:0] i_ioc,
input [7:0] i_data_in,
output reg [7:0] o_data_out,
input i_cs,
input i_fetch_cmd,
2021-07-13 09:39:03 +00:00
input i_load_cmd,
2021-08-18 20:02:35 +00:00
2021-07-13 10:04:44 +00:00
// FIFO INTERFACE 0.9 GHz
2021-07-13 09:39:03 +00:00
output o_fifo_09_pull,
input [31:0] i_fifo_09_pulled_data,
2021-07-13 10:04:44 +00:00
input i_fifo_09_full,
2021-07-13 09:39:03 +00:00
input i_fifo_09_empty,
2021-07-13 10:04:44 +00:00
// FIFO INTERFACE 2.4 GHz
2021-07-13 09:39:03 +00:00
output o_fifo_24_pull,
input [31:0] i_fifo_24_pulled_data,
2021-07-13 10:04:44 +00:00
input i_fifo_24_full,
input i_fifo_24_empty,
// SMI INTERFACE
input [2:0] i_smi_a,
input i_smi_soe_se,
input i_smi_swe_srw,
2021-07-14 19:53:59 +00:00
output reg [7:0] o_smi_data_out,
input [7:0] i_smi_data_in,
2021-07-13 10:04:44 +00:00
output o_smi_read_req,
2021-07-14 19:53:59 +00:00
output o_smi_write_req,
2021-07-18 08:20:56 +00:00
output o_smi_writing,
2021-08-18 20:02:35 +00:00
input i_smi_test,
2021-07-18 08:20:56 +00:00
// Errors
output reg o_address_error );
2021-06-13 11:45:08 +00:00
// MODULE SPECIFIC IOC LIST
// ------------------------
localparam
2021-07-13 10:04:44 +00:00
ioc_module_version = 5'b00000, // read only
ioc_fifo_status = 5'b00001; // read-only
2021-06-13 11:45:08 +00:00
// MODULE SPECIFIC PARAMS
// ----------------------
localparam
module_version = 8'b00000001;
2021-08-10 06:02:20 +00:00
// SMI ADDRESS DEFS
// ----------------
localparam
smi_address_idle = 3'b000,
2021-08-10 11:27:21 +00:00
smi_address_write_900 = 3'b001,
smi_address_write_2400 = 3'b010,
smi_address_write_res2 = 3'b011,
2021-08-10 06:02:20 +00:00
smi_address_read_res1 = 3'b100,
2021-08-10 11:27:21 +00:00
smi_address_read_900 = 3'b101,
smi_address_read_2400 = 3'b110,
2021-08-18 20:02:35 +00:00
smi_address_read_res = 3'b111;
2021-06-13 11:45:08 +00:00
always @(posedge i_sys_clk)
begin
2021-07-14 18:47:12 +00:00
if (i_reset) begin
2021-07-18 08:20:56 +00:00
o_address_error <= 1'b0;
2021-07-14 18:47:12 +00:00
// put the initial states here
2021-08-18 20:02:35 +00:00
end else begin
2021-07-14 18:47:12 +00:00
if (i_cs == 1'b1) begin
if (i_fetch_cmd == 1'b1) begin
case (i_ioc)
//----------------------------------------------
ioc_module_version: o_data_out <= module_version; // Module Version
2021-07-13 10:04:44 +00:00
2021-07-14 18:47:12 +00:00
//----------------------------------------------
ioc_fifo_status: begin
o_data_out[0] <= i_fifo_09_empty;
o_data_out[1] <= i_fifo_09_full;
o_data_out[2] <= i_fifo_24_empty;
o_data_out[3] <= i_fifo_24_full;
o_data_out[7:4] <= 4'b0000;
end
2021-07-13 10:04:44 +00:00
2021-07-14 18:47:12 +00:00
endcase
end
2021-08-18 20:02:35 +00:00
end
2021-06-13 11:45:08 +00:00
end
end
2021-07-14 10:58:21 +00:00
// Tell the RPI that data is pending in either of the two fifos
2021-08-18 20:02:35 +00:00
assign o_smi_read_req = !i_fifo_09_empty || !i_fifo_24_empty || i_smi_test;
2021-07-14 10:58:21 +00:00
2021-08-18 20:02:35 +00:00
reg r_last_soe_1;
reg r_last_soe_2;
2021-07-17 13:23:17 +00:00
reg [5:0] int_cnt_09;
reg [5:0] int_cnt_24;
reg r_fifo_09_pull;
reg r_fifo_24_pull;
2021-08-18 20:02:35 +00:00
reg [7:0] r_smi_test_count_09;
reg [7:0] r_smi_test_count_24;
2021-08-27 09:57:20 +00:00
wire soe_change_falling;
assign soe_change_falling = (r_last_soe_2 == 1'b1 && r_last_soe_1 == 1'b0);
2021-07-14 19:53:59 +00:00
2021-07-13 09:39:03 +00:00
always @(posedge i_sys_clk)
2021-07-14 10:58:21 +00:00
begin
2021-07-14 19:53:59 +00:00
if (i_reset) begin
2021-07-17 13:23:17 +00:00
int_cnt_09 <= 6'd32;
int_cnt_24 <= 6'd32;
2021-08-18 20:02:35 +00:00
r_last_soe_1 <= 1'b1;
r_last_soe_2 <= 1'b1;
2021-07-17 13:23:17 +00:00
r_fifo_09_pull <= 1'b0;
r_fifo_24_pull <= 1'b0;
2021-08-18 20:02:35 +00:00
r_smi_test_count_09 <= 8'b00000000;
r_smi_test_count_24 <= 8'b00000000;
end else begin
2021-07-14 19:53:59 +00:00
//==========================
2021-07-17 13:23:17 +00:00
// 0.9 GHz Data Sender
2021-07-14 19:53:59 +00:00
//==========================
2021-08-10 06:02:20 +00:00
if (i_smi_a == smi_address_read_900) begin
2021-08-27 09:57:20 +00:00
if (soe_change_falling) begin
if (i_smi_test == 1'b1) begin
2021-08-24 13:49:06 +00:00
o_smi_data_out <= r_smi_test_count_09;
r_smi_test_count_09 <= r_smi_test_count_09 + 1'b1;
2021-08-27 09:57:20 +00:00
end else begin
if (int_cnt_09 > 8) int_cnt_09 <= int_cnt_09 - 8;
2021-08-18 20:02:35 +00:00
2021-08-27 09:57:20 +00:00
if (r_fifo_09_pull) begin
r_fifo_09_pull <= 1'b0;
o_smi_data_out <= i_fifo_09_pulled_data[int_cnt_09-1:int_cnt_09-8];
end
2021-07-17 13:23:17 +00:00
end
2021-08-27 09:57:20 +00:00
end else if (r_last_soe_1 == 1'b1 && i_smi_test == 1'b0) begin
2021-07-17 13:23:17 +00:00
if (int_cnt_09 > 0) begin
r_fifo_09_pull <= 1'b0;
o_smi_data_out <= i_fifo_09_pulled_data[int_cnt_09-1:int_cnt_09-8];
end else if ((i_fifo_09_empty == 1'b0) && (int_cnt_09 == 6'd0)) begin
r_fifo_09_pull <=1'b1;
int_cnt_09 <= 6'd32;
end
2021-08-27 09:57:20 +00:00
end
2021-07-17 13:23:17 +00:00
end
2021-07-14 19:53:59 +00:00
//==========================
2021-07-17 13:23:17 +00:00
// 2.4 GHz Data Sender
2021-07-14 19:53:59 +00:00
//==========================
2021-08-10 06:02:20 +00:00
else if (i_smi_a == smi_address_read_2400) begin
2021-08-27 09:57:20 +00:00
if (soe_change_falling) begin
if (i_smi_test == 1'b1) begin
2021-08-24 13:49:06 +00:00
o_smi_data_out <= r_smi_test_count_24;
r_smi_test_count_24 <= r_smi_test_count_24 + 1'b1;
2021-08-27 09:57:20 +00:00
end else begin
if (int_cnt_24 > 8) int_cnt_24 <= int_cnt_24 - 8;
2021-08-18 20:02:35 +00:00
2021-08-27 09:57:20 +00:00
if (r_fifo_24_pull) begin
r_fifo_24_pull <= 1'b0;
o_smi_data_out <= i_fifo_24_pulled_data[int_cnt_24-1:int_cnt_24-8];
end
2021-07-17 13:23:17 +00:00
end
2021-08-27 09:57:20 +00:00
end else if (r_last_soe_1 == 1'b1 && i_smi_test == 1'b0) begin
2021-07-17 13:23:17 +00:00
if (int_cnt_24 > 0) begin
r_fifo_24_pull <= 1'b0;
o_smi_data_out <= i_fifo_24_pulled_data[int_cnt_24-1:int_cnt_24-8];
end else if ((i_fifo_24_empty == 1'b0) && (int_cnt_24 == 6'd0)) begin
r_fifo_24_pull <=1'b1;
int_cnt_24 <= 6'd32;
end
2021-08-27 09:57:20 +00:00
end
2021-07-14 19:53:59 +00:00
end
2021-07-18 08:20:56 +00:00
else begin
2021-08-27 09:57:20 +00:00
//o_smi_data_out <= 8'b00000000;
2021-07-18 08:20:56 +00:00
// error with address
o_address_error <= 1'b1;
end
2021-07-17 13:23:17 +00:00
2021-08-18 20:02:35 +00:00
r_last_soe_2 <= r_last_soe_1;
r_last_soe_1 <= i_smi_soe_se;
2021-07-14 19:07:15 +00:00
end
2021-07-13 09:39:03 +00:00
end
2021-08-18 20:02:35 +00:00
//assign o_smi_data_out = 8'b01011010;
2021-07-17 13:23:17 +00:00
assign o_fifo_09_pull = r_fifo_09_pull;
assign o_fifo_24_pull = r_fifo_24_pull;
2021-07-14 19:53:59 +00:00
assign o_smi_writing = i_smi_a[2];
2021-07-13 09:39:03 +00:00
2021-06-13 11:45:08 +00:00
endmodule // smi_ctrl