cariboulabs-cariboulite/firmware/lvds_rx.v

101 wiersze
2.5 KiB
Coq
Czysty Zwykły widok Historia

2023-05-30 11:33:08 +00:00
module lvds_rx (
input i_rst_b,
input i_ddr_clk,
input [1:0] i_ddr_data,
2021-07-07 12:29:32 +00:00
2023-05-30 11:33:08 +00:00
input i_fifo_full,
output o_fifo_write_clk,
2023-07-03 11:40:33 +00:00
output o_fifo_push,
output [15:0] o_fifo_data,
2023-05-30 11:33:08 +00:00
input i_sync_input,
output [ 1:0] o_debug_state
);
2021-07-07 12:29:32 +00:00
2023-05-30 11:33:08 +00:00
// Internal FSM States
localparam state_idle = 2'b00, state_i_phase = 2'b01, state_q_sync = 2'b10, state_q_phase = 2'b11;
2021-09-01 21:50:13 +00:00
2023-05-30 11:33:08 +00:00
// Modem sync symbols
localparam modem_i_sync = 2'b10, modem_q_sync = 2'b01;
2021-07-07 12:29:32 +00:00
2023-05-30 11:33:08 +00:00
// Internal Registers
reg [1:0] r_state_if;
reg [2:0] r_phase_count;
reg r_sync_input;
reg r_fifo_push;
assign o_fifo_push = r_fifo_push;
2023-05-30 11:33:08 +00:00
// Initial conditions
initial begin
r_state_if = state_idle;
r_phase_count = 3'b111;
end
// Global Assignments
assign o_fifo_write_clk = i_ddr_clk;
assign o_debug_state = r_state_if;
2021-07-07 12:29:32 +00:00
reg [35:0] r_fifo_data;
always @(posedge i_ddr_clk) begin
r_fifo_data <= {r_fifo_data[33:0], i_ddr_data};;
end
assign o_fifo_data = r_fifo_data[19:4];
reg fifo_push2;
2023-05-30 11:33:08 +00:00
// Main Process
always @(posedge i_ddr_clk or negedge i_rst_b) begin
if (i_rst_b == 1'b0) begin
r_state_if <= state_idle;
r_fifo_push <= 1'b0;
r_phase_count <= 3'b000;
2023-05-30 11:33:08 +00:00
r_sync_input <= 1'b0;
fifo_push2 <= 1'b0;
2023-05-30 11:33:08 +00:00
end else begin
r_phase_count <= r_phase_count + 1;
2023-05-30 11:33:08 +00:00
case (r_state_if)
state_idle: begin
if (r_fifo_data[1:0] == modem_i_sync) begin
2023-05-30 11:33:08 +00:00
r_state_if <= state_i_phase;
2023-05-30 11:33:08 +00:00
r_sync_input <= i_sync_input; // mark the sync input for this sample
end
r_phase_count <= 3'b001;
r_fifo_push <= 1'b0;
if(fifo_push2) begin
r_fifo_push <= 1'b1;
fifo_push2 <= 1'b0;
end
2023-05-30 11:33:08 +00:00
end
2021-07-07 12:29:32 +00:00
2023-05-30 11:33:08 +00:00
state_i_phase: begin
if (r_phase_count == 3'b111) begin
r_state_if <= state_q_sync;
2023-07-03 11:40:33 +00:00
end
r_fifo_push <= 1'b0;
2023-05-30 11:33:08 +00:00
end
2021-09-03 20:17:44 +00:00
state_q_sync: begin
if (r_fifo_data[1:0] == modem_q_sync) begin
r_state_if <= state_q_phase;
r_fifo_push <= ~i_fifo_full;
fifo_push2 <= ~i_fifo_full;
end else begin
r_state_if <= state_idle;
end
end
2023-05-30 11:33:08 +00:00
state_q_phase: begin
if (r_phase_count == 3'b111) begin
2023-05-30 11:33:08 +00:00
r_state_if <= state_idle;
2023-05-30 11:33:08 +00:00
end
r_fifo_push <= 1'b0;
2021-07-07 13:04:37 +00:00
end
2023-05-30 11:33:08 +00:00
endcase
2023-02-14 15:39:24 +00:00
end
2023-05-30 11:33:08 +00:00
end
2023-02-14 15:39:24 +00:00
endmodule