2022-08-28 11:44:19 -05:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-Only
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2022 Sean Anderson <seanga2@gmail.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
`include "common.vh"
|
|
|
|
`include "io.vh"
|
|
|
|
|
|
|
|
module mii_io_rx (
|
|
|
|
input clk,
|
2022-08-28 17:43:23 -05:00
|
|
|
input isolate,
|
|
|
|
|
|
|
|
/* On-chip */
|
2022-08-28 11:44:19 -05:00
|
|
|
input ce,
|
|
|
|
input valid,
|
|
|
|
input err,
|
|
|
|
input [3:0] data,
|
|
|
|
|
|
|
|
/* Off-chip */
|
|
|
|
output reg rx_clk,
|
|
|
|
output reg rx_dv,
|
|
|
|
output reg rx_er,
|
|
|
|
output reg [3:0] rxd
|
|
|
|
);
|
|
|
|
|
|
|
|
reg rx_clk_p_next, rx_clk_n, rx_clk_n_next;
|
2022-10-16 16:40:44 -05:00
|
|
|
reg [1:0] state, state_next;
|
|
|
|
initial state = HIGH;
|
2022-08-28 11:44:19 -05:00
|
|
|
|
2022-08-29 20:36:24 -05:00
|
|
|
localparam LOW = 2;
|
|
|
|
localparam RISING = 1;
|
|
|
|
localparam HIGH = 0;
|
2022-08-28 11:44:19 -05:00
|
|
|
|
|
|
|
always @(*) begin
|
|
|
|
if (ce) begin
|
|
|
|
state_next = LOW;
|
2022-10-16 16:40:44 -05:00
|
|
|
rx_clk_p_next = 0;
|
|
|
|
rx_clk_n_next = 0;
|
|
|
|
end else if (state == LOW) begin
|
2022-08-28 11:44:19 -05:00
|
|
|
state_next = RISING;
|
2022-10-16 16:40:44 -05:00
|
|
|
rx_clk_p_next = 0;
|
|
|
|
rx_clk_n_next = 0;
|
|
|
|
end else if (state == RISING) begin
|
2022-08-28 11:44:19 -05:00
|
|
|
state_next = HIGH;
|
2022-10-16 16:40:44 -05:00
|
|
|
rx_clk_p_next = 0;
|
2022-08-28 11:44:19 -05:00
|
|
|
rx_clk_n_next = 1;
|
2022-10-16 16:40:44 -05:00
|
|
|
end else begin
|
2022-08-28 11:44:19 -05:00
|
|
|
state_next = HIGH;
|
|
|
|
rx_clk_p_next = 1;
|
|
|
|
rx_clk_n_next = 1;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
always @(posedge clk) begin
|
|
|
|
state <= state_next;
|
|
|
|
rx_clk_n <= rx_clk_n_next;
|
|
|
|
end
|
|
|
|
|
|
|
|
`ifdef SYNTHESIS
|
|
|
|
SB_IO #(
|
2022-08-28 17:43:23 -05:00
|
|
|
.PIN_TYPE(`PIN_OUTPUT_ENABLE | `PIN_OUTPUT_DDR)
|
2022-08-28 11:44:19 -05:00
|
|
|
) rx_clk_pin (
|
|
|
|
.PACKAGE_PIN(rx_clk),
|
|
|
|
.OUTPUT_CLK(clk),
|
2022-08-28 17:43:23 -05:00
|
|
|
.OUTPUT_ENABLE(!isolate),
|
2022-08-28 11:44:19 -05:00
|
|
|
.D_OUT_0(rx_clk_p_next),
|
|
|
|
.D_OUT_1(rx_clk_n)
|
|
|
|
);
|
|
|
|
|
|
|
|
SB_IO #(
|
2022-08-28 17:43:23 -05:00
|
|
|
.PIN_TYPE(`PIN_OUTPUT_ENABLE | `PIN_OUTPUT_REGISTERED)
|
2022-08-28 11:44:19 -05:00
|
|
|
) rx_dv_pin (
|
|
|
|
.PACKAGE_PIN(rx_dv),
|
|
|
|
.CLOCK_ENABLE(ce),
|
2022-08-28 17:43:23 -05:00
|
|
|
.OUTPUT_ENABLE(!isolate),
|
2022-08-28 11:44:19 -05:00
|
|
|
.OUTPUT_CLK(clk),
|
|
|
|
.D_OUT_0(valid)
|
|
|
|
);
|
|
|
|
|
|
|
|
SB_IO #(
|
2022-08-28 17:43:23 -05:00
|
|
|
.PIN_TYPE(`PIN_OUTPUT_ENABLE | `PIN_OUTPUT_REGISTERED)
|
2022-08-28 11:44:19 -05:00
|
|
|
) rx_er_pin (
|
|
|
|
.PACKAGE_PIN(rx_er),
|
|
|
|
.CLOCK_ENABLE(ce),
|
2022-08-28 17:43:23 -05:00
|
|
|
.OUTPUT_ENABLE(!isolate),
|
2022-08-28 11:44:19 -05:00
|
|
|
.OUTPUT_CLK(clk),
|
|
|
|
.D_OUT_0(err)
|
|
|
|
);
|
|
|
|
|
|
|
|
genvar i;
|
|
|
|
generate for (i = 0; i < 4; i = i + 1) begin
|
|
|
|
SB_IO #(
|
2022-08-28 17:43:23 -05:00
|
|
|
.PIN_TYPE(`PIN_OUTPUT_ENABLE | `PIN_OUTPUT_REGISTERED)
|
2022-08-28 11:44:19 -05:00
|
|
|
) rxd_pin (
|
|
|
|
.PACKAGE_PIN(rxd[i]),
|
|
|
|
.CLOCK_ENABLE(ce),
|
2022-08-28 17:43:23 -05:00
|
|
|
.OUTPUT_ENABLE(!isolate),
|
2022-08-28 11:44:19 -05:00
|
|
|
.OUTPUT_CLK(clk),
|
|
|
|
.D_OUT_0(data[i])
|
|
|
|
);
|
|
|
|
end
|
|
|
|
endgenerate
|
|
|
|
`else
|
|
|
|
always @(posedge clk) begin
|
2022-08-28 17:43:23 -05:00
|
|
|
if (isolate) begin
|
|
|
|
rx_dv <= 1'bz;
|
|
|
|
rx_er <= 1'bz;
|
|
|
|
rxd <= 4'bz;
|
|
|
|
end else if (ce) begin
|
2022-08-28 11:44:19 -05:00
|
|
|
rx_dv <= valid;
|
|
|
|
rx_er <= err;
|
|
|
|
rxd <= data;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-08-28 17:43:23 -05:00
|
|
|
always @(posedge clk, negedge clk) begin
|
|
|
|
if (isolate)
|
|
|
|
rx_clk <= 1'bz;
|
|
|
|
else
|
|
|
|
rx_clk <= clk ? rx_clk_p_next : rx_clk_n;
|
|
|
|
end
|
2022-08-28 11:44:19 -05:00
|
|
|
`endif
|
|
|
|
|
|
|
|
endmodule
|