-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.vhdl
321 lines (271 loc) · 10 KB
/
main.vhdl
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use WORK.modules.all;
-- Library UNISIM;
-- use UNISIM.vcomponents.all;
entity main is
generic (
test_bench : natural := 0;
use_cpu : natural := 0
);
port(
-- SFP HARDWARE
los : in std_logic;
rate_select : out std_logic;
t_dis : out std_logic; -- TELL LASER TO SWITCH-ON (0: ON, 1: OFF)
t_fault : in std_logic;
-- Module Definition 2. Data line for Serial ID.
-- Module Definition 1. Clock line for Serial ID.
-- Module Definition 0. Grounded within the module.
mod_def : inout std_logic_vector(2 downto 0);
-- UTILITY
led : buffer std_logic_vector(7 downto 0);
tasto : in std_logic_vector(7 downto 0);
push_button : in std_logic_vector(3 downto 0);
digit_out : out std_logic_vector(3 downto 0);
seg_out : out std_logic_vector(7 downto 0);
-- SERDES MDIO SERIAL
mdio_sda : inout std_logic := 'Z';
mdio_scl : buffer std_logic; -- GGGG era out!!
-- TEST SLAVE
-- mdio_sda_slave : inout std_logic := 'Z';
-- mdio_scl_slave : in std_logic;
-- SERDES CLK_REF
clkref_serdes_p: out std_logic;
clkref_serdes_n: out std_logic;
sysclk_serdes_p: in std_logic;
sysclk_serdes_n: in std_logic;
rxclk : in std_logic;
rout : in std_logic_vector(9 downto 0);
txclk : out std_logic;
din : out std_logic_vector(9 downto 0);
-- PLASMA CPU PINS
clk_in : in std_logic;
reset : in std_logic;
uart_read : in std_logic;
uart_write : out std_logic
);
end main;
architecture Behavioral of main is
signal serial_clock : std_logic;
signal clkref_serdes : std_logic;
signal sysclk_serdes : std_logic;
-- SIGNAL FOR UART
signal uart_enable_read : std_logic;
signal uart_enable_write : std_logic;
signal uart_data_in : std_logic_vector(7 downto 0);
signal uart_data_out : std_logic_vector(7 downto 0);
signal uart_busy_write : std_logic;
signal uart_data_avail : std_logic;
-- DISPLAY
signal hexint : hexint_digit; -- std_logic_vector(15 downto 0) := (OTHERS => 'Z');
-- signal reset : std_logic := '1';
-- I2C FOR SFP
signal i2c_word_address : std_logic_vector(7 downto 0);
signal i2c_data_read : std_logic_vector(7 downto 0);
signal i2c_data_write : std_logic_vector(7 downto 0);
signal i2c_op : std_logic_vector(1 downto 0);
signal i2c_start_conversion: std_logic;
signal i2c_is_running : std_logic;
signal i2c_error_code : std_logic_vector(2 downto 0);
-- MDIO FOR SERDES
signal mdio_opcode : std_logic_vector(1 downto 0); -- 00: Address 10: Read-Inc 01: Write
signal mdio_data_read : std_logic_vector(15 downto 0);
signal mdio_data_write : std_logic_vector(15 downto 0);
signal mdio_start_conversion: std_logic;
signal mdio_running_conversion : std_logic;
signal mdio_error_code : std_logic_vector(2 downto 0);
begin
-- mdio_scl <= serial_clock;
rate_select <= '0';
t_dis <= '0'; -- not tasto(0);
-- led(0) <= tasto(0);
-- led(1) <= los;
-- led(2) <= mod_def(0);
-- led(7 downto 4) <= (OTHERS => '0');
-- led(3) <= mdio_sda;
-- DIN [8] is used as K-code select pin
-- When DIN [8] is low, DIN [0-7] is mapped to the
-- corresponding 10-bit D-group. When DIN [8] is high, DIN [0-7] is mapped to the
-- corresponding 10-bit K-group.
-- and DIN[9] should be tied Low.
-- ROUT [8] is the K-group indicator. A low at ROUT [8] indicates ROUT [0-7] belongs
-- to the D-group, while a high indicates it belongs to the K-group. ROUT [9] is the line
-- code violation (LCV) indicator. ROUT [9] is high for one ROUT cycle when a line code
-- violation occurs.
din(9) <= '0';
din_8_10b: process(clkref_serdes) is
begin
if rising_edge(clkref_serdes) then
if push_button(0) = '0' then
din(8) <= '0';
din(7 downto 0) <= tasto;
else
din(8) <= '1';
din(7 downto 0) <= "101" & "11100"; -- "11100" & "101"; -- K28.5
end if;
end if;
end process;
led(7 downto 2) <= rout(5 downto 0);
led(0) <= rout(8);
led(1) <= rout(9);
txclk <= clkref_serdes when push_button(2) = '0' else 'Z';
-- DEBUG ROUT K-CODES
hexint(0) <= rout(3 downto 0) when rout(8) ='1' else x"0";
hexint(1) <= rout(7 downto 4) when rout(8) ='1' else x"0";
debug_tx: process (rout(9)) is
begin
if rising_edge(rout(9)) then
hexint(2) <= rout(3 downto 0);
hexint(3) <= rout(7 downto 4);
end if;
end process;
-- -- ritardo il fronte di discesa di mdio_scl con monostabile
-- clock_pro: process(clk_in) is
-- variable cnt : integer := 0;
-- begin
-- if rising_edge(clk_in) then
-- if reset = '1' then
-- cnt := 0;
-- mdio_scl <= '0';
-- else
-- if serial_clock = '0' then
-- mdio_scl <= '0';
-- cnt := 0;
-- else
-- if cnt < 80 then
-- cnt := cnt + 1;
-- mdio_scl <= '0';
-- else
-- mdio_scl <= '1';
-- end if;
-- end if;
-- end if;
--
-- end if;
-- end process;
--
--
-- digit_out <= (OTHERS => '1' );
-- seg_out <= (OTHERS => '1' );
--sync_reset: process(clk_in) is
--begin
-- reset <= reset_in;
--end process;
-- IBUFG_inst : IBUFG
-- generic map (
-- IBUF_DELAY_VALUE => "0", -- Specify the amount of added input delay for buffer,
-- -- "0"-"12" (Spartan-3E)
-- -- "0"-"16" (Spartan-3A)
-- IOSTANDARD => "DEFAULT")
-- port map (
-- O => reset, -- Clock buffer output
-- I => reset_in -- Clock buffer input (connect directly to top-level port)
-- );
-- SERDES: MDIO serial master interface
serdes_io : mdio
generic map ( mdio_address => "11111", device_address => "11110")
port map (
reset => reset,
clk_in => serial_clock,
serial_clock => mdio_scl,
serial_data => mdio_sda,
opcode => mdio_opcode,
data_read => mdio_data_read,
data_write => mdio_data_write,
start_conversion => mdio_start_conversion,
running_conversion => mdio_running_conversion,
error_code => mdio_error_code,
hexint => open -- hexint(2)
);
-- SERDES SLAVE FOR TEST!!!: MDIO serial test slave interface
-- serdes_slave_io : mdio_slave
-- port map (
-- reset => reset,
-- clk_in => serial_clock,
-- serial_clock => mdio_scl_slave,
-- serial_data => mdio_sda_slave,
-- data_write_back => x"1492"
-- );
-- SFP: Small form-factor pluggable transceiver
sfp_io : i2c
generic map ( device_address => "1010000" ) -- A0
port map(
reset => reset,
double_clock_in => serial_clock,
word_address => i2c_word_address,
data_read => i2c_data_read,
data_write => i2c_data_write,
op => i2c_op,
serial_clock => mod_def(1),
serial_data => mod_def(2),
start_conversion => i2c_start_conversion,
is_running => i2c_is_running,
error_code => i2c_error_code,
hexint => open -- hexint(1)
);
-- Genero tutti i clock del progetto
instanzia_clocks : myclocks
port map(
reset => reset,
clkref_serdes_p => clkref_serdes_p, clkref_serdes_n => clkref_serdes_n,
sysclk_serdes_p => sysclk_serdes_p, sysclk_serdes_n => sysclk_serdes_n,
serial_clock => serial_clock, clkref_serdes => clkref_serdes,
sysclk_serdes => sysclk_serdes,
clk_in => clk_in
);
-- Gestisce un protocollino su seriale
-- per esportare lo stato attuale del sistema
-- ad un programma running su PC.
istanzia_menu : uart_menu
port map(
reset => reset,
clk_in => clk_in, clkref_serdes => clkref_serdes,
sysclk_serdes => sysclk_serdes,
serial_clock => serial_clock, -- CLOCKS
rxclk_serdes => rxclk,
hexint => open, -- hexint(0),
uart_enable_read => uart_enable_read,
uart_enable_write => uart_enable_write,
uart_busy_write => uart_busy_write,
uart_data_avail => uart_data_avail,
uart_data_out => uart_data_out,
uart_data_in => uart_data_in,
mdio_opcode => mdio_opcode,
mdio_data_read => mdio_data_read,
mdio_data_write => mdio_data_write,
mdio_start_conversion => mdio_start_conversion,
mdio_running_conversion => mdio_running_conversion,
mdio_error_code => mdio_error_code,
i2c_word_address => i2c_word_address,
i2c_data_read => i2c_data_read,
i2c_data_write => i2c_data_write,
i2c_op => i2c_op,
i2c_start_conversion => i2c_start_conversion,
i2c_is_running => i2c_is_running,
i2c_error_code => i2c_error_code
);
-- Istanzia la seriale UART a 57600 baud
u78 : uart
port map (
clk_in,
reset,
uart_enable_read,
uart_enable_write,
uart_data_in,
uart_data_out,
uart_read, uart_write, -- pins from physical serial port
uart_busy_write,
uart_data_avail
);
-- uart_write <= '1';
-- istanzia il display a 7 segmenti
disp1 : display7seg
port map (
clk50 => clk_in, -- in std_logic; -- 50 Mhz XTAL
reset => reset, -- in std_logic;
digit => digit_out, -- out std_logic_vector(3 downto 0); -- digit drivers
seg => seg_out, -- out std_logic_vector(7 downto 0)); -- segment drivers
hexint=> hexint -- x"C1A0" -- in std_logic_vector(15 downto 0) ; -- what to display
);
end Behavioral;