-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgtx_tx_mux.vhd
153 lines (90 loc) · 4.32 KB
/
gtx_tx_mux.vhd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
library ieee;
use ieee.std_logic_1164.all;
library work;
use work.user_package.all;
entity gtx_tx_mux is
port(
gtx_clk_i : in std_logic;
reset_i : in std_logic;
vi2c_en_i : in std_logic;
vi2c_data_i : in std_logic_vector(31 downto 0);
regs_en_i : in std_logic;
regs_data_i : in std_logic_vector(47 downto 0);
tx_kchar_o : out std_logic_vector(1 downto 0);
tx_data_o : out std_logic_vector(15 downto 0)
);
end gtx_tx_mux;
architecture Behavioral of gtx_tx_mux is
begin
process(gtx_clk_i)
-- State for sending
variable state : integer range 0 to 3 := 0;
-- Data
variable header : std_logic_vector(7 downto 0) := (others => '0');
variable data : std_logic_vector(47 downto 0) := (others => '0');
variable data_cnt : integer range 0 to 15 := 0;
-- Last kchar sent
variable kchar_count : integer range 0 to 1023 := 0;
begin
if (rising_edge(gtx_clk_i)) then
-- Reset
if (reset_i = '1') then
tx_kchar_o <= "00";
tx_data_o <= def_gtx_idle & x"BC";
state := 0;
kchar_count := 0;
else
-- Ready to send state
if (state = 0) then
tx_data_o <= def_gtx_idle & x"BC"; -- Idle code
if (kchar_count = 1023) then
-- Set kchar
tx_kchar_o <= "01";
kchar_count := 0;
else
-- Clear kchar
tx_kchar_o <= "00";
kchar_count := kchar_count + 1;
end if;
-- VFAT2 I2C data is available
if (vi2c_en_i = '1') then
header := def_gtx_vi2c;
data(31 downto 0) := vi2c_data_i;
data_cnt := 2;
state := 1;
-- Registers data is available
elsif (regs_en_i = '1') then
header := def_gtx_regs;
data(47 downto 0) := regs_data_i;
data_cnt := 3;
state := 1;
end if;
-- Send header
elsif (state = 1) then
-- Set the TX data
tx_data_o <= header & x"BC";
-- Set TX kchar
tx_kchar_o <= "01";
state := 2;
-- Send body
elsif (state = 2) then
-- Set TX kchar
tx_kchar_o <= "00";
-- Set the TX data
tx_data_o <= data((data_cnt * 16 - 1) downto ((data_cnt - 1) * 16));
if (data_cnt = 1) then
state := 0;
else
data_cnt := data_cnt - 1;
end if;
-- Out of FSM
else
tx_kchar_o <= "00";
tx_data_o <= def_gtx_idle & x"BC";
state := 0;
kchar_count := 0;
end if;
end if;
end if;
end process;
end Behavioral;