AMC13
Firmwares for the different applications of the AMC13 uTCA board made at Boston University
 All Classes Variables
encode_8b10b_lut_base.vhd
1 ---------------------------------------------------------------------------
2 --
3 -- Module : encode_8b10b_lut_base.vhd
4 --
5 -- Version : 1.1
6 --
7 -- Last Update : 2008-10-31
8 --
9 -- Project : 8b/10b Encoder Reference Design
10 --
11 -- Description : LUT-based Single-port Base Encoder
12 --
13 -- Company : Xilinx, Inc.
14 --
15 -- DISCLAIMER OF LIABILITY
16 --
17 -- This file contains proprietary and confidential information of
18 -- Xilinx, Inc. ("Xilinx"), that is distributed under a license
19 -- from Xilinx, and may be used, copied and/or disclosed only
20 -- pursuant to the terms of a valid license agreement with Xilinx.
21 --
22 -- XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION
23 -- ("MATERIALS") "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
24 -- EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING WITHOUT
25 -- LIMITATION, ANY WARRANTY WITH RESPECT TO NONINFRINGEMENT,
26 -- MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE. Xilinx
27 -- does not warrant that functions included in the Materials will
28 -- meet the requirements of Licensee, or that the operation of the
29 -- Materials will be uninterrupted or error-free, or that defects
30 -- in the Materials will be corrected. Furthermore, Xilinx does
31 -- not warrant or make any representations regarding use, or the
32 -- results of the use, of the Materials in terms of correctness,
33 -- accuracy, reliability or otherwise.
34 --
35 -- Xilinx products are not designed or intended to be fail-safe,
36 -- or for use in any application requiring fail-safe performance,
37 -- such as life-support or safety devices or systems, Class III
38 -- medical devices, nuclear facilities, applications related to
39 -- the deployment of airbags, or any other applications that could
40 -- lead to death, personal injury or severe property or
41 -- environmental damage (individually and collectively, "critical
42 -- applications"). Customer assumes the sole risk and liability
43 -- of any use of Xilinx products in critical applications,
44 -- subject only to applicable laws and regulations governing
45 -- limitations on product liability.
46 --
47 -- Copyright 2000, 2001, 2002, 2003, 2004, 2008 Xilinx, Inc.
48 -- All rights reserved.
49 --
50 -- This disclaimer and copyright notice must be retained as part
51 -- of this file at all times.
52 --
53 ---------------------------------------------------------------------------
54 --
55 -- History
56 --
57 -- Date Version Description
58 --
59 -- 10/31/2008 1.1 Initial release
60 --
61 -------------------------------------------------------------------------------
62 
63 LIBRARY IEEE;
64 USE IEEE.std_logic_1164.ALL;
65 
66 USE work.encode_8b10b_pkg.ALL;
67 
69  GENERIC (
70  C_HAS_DISP_IN : INTEGER :=0 ;
71  C_HAS_FORCE_CODE : INTEGER :=0 ;
72  C_FORCE_CODE_VAL : STRING :="1010101010" ;
73  C_FORCE_CODE_DISP : INTEGER :=0 ;
74  C_HAS_ND : INTEGER :=0 ;
75  C_HAS_KERR : INTEGER :=0
76  );
77  PORT (
78  DIN : IN STD_LOGIC_VECTOR(7 DOWNTO 0) :=(OTHERS => '0');
79  KIN : IN STD_LOGIC :='0' ;
80  CLK : IN STD_LOGIC :='0' ;
81  DOUT : OUT STD_LOGIC_VECTOR(9 DOWNTO 0) :=
82  str_to_slv(C_FORCE_CODE_VAL, 10) ;
83  CE : IN STD_LOGIC :='0' ;
84  FORCE_CODE : IN STD_LOGIC :='0' ;
85  FORCE_DISP : IN STD_LOGIC :='0' ;
86  DISP_IN : IN STD_LOGIC :='0' ;
87  DISP_OUT : OUT STD_LOGIC :=
88  bint_2_sl(C_FORCE_CODE_DISP);
89  KERR : OUT STD_LOGIC :='0' ;
90  ND : OUT STD_LOGIC :='0'
91  );
92 END encode_8b10b_lut_base;
93 
94 -----------------------------------------------------------------
95 -- Architecture
96 -----------------------------------------------------------------
97 ARCHITECTURE xilinx OF encode_8b10b_lut_base IS
98 
99 -----------------------------------------------------------------
100 -- Constant Declarations
101 -----------------------------------------------------------------
102  CONSTANT POS : STD_LOGIC := '1' ;
103  CONSTANT NEG : STD_LOGIC := '0' ;
104 
105 ------------------------------------------------------------------
106 -- Signal Declarations
107 ------------------------------------------------------------------
108  SIGNAL b6 : STD_LOGIC_VECTOR(5 DOWNTO 0) :=(OTHERS => '0');
109  SIGNAL b4 : STD_LOGIC_VECTOR(3 DOWNTO 0) :=(OTHERS => '0');
110  SIGNAL pdes6 : STD_LOGIC :='0';
111  SIGNAL pdes4 : STD_LOGIC :='0';
112  SIGNAL k28 : STD_LOGIC :='0';
113  SIGNAL l13 : STD_LOGIC :='0';
114  SIGNAL l31 : STD_LOGIC :='0';
115  SIGNAL a7 : STD_LOGIC :='0';
116  SIGNAL disp_in_i : STD_LOGIC :='0';
117  SIGNAL disp_run : STD_LOGIC :=bint_2_sl(C_FORCE_CODE_DISP);
118  SIGNAL kerr_i : STD_LOGIC :='0' ;
119 
120  ALIAS a : STD_LOGIC IS DIN(0) ;
121  ALIAS b : STD_LOGIC IS DIN(1) ;
122  ALIAS c : STD_LOGIC IS DIN(2) ;
123  ALIAS d : STD_LOGIC IS DIN(3) ;
124  ALIAS e : STD_LOGIC IS DIN(4) ;
125  ALIAS b5 : STD_LOGIC_VECTOR(4 DOWNTO 0) IS DIN(4 DOWNTO 0) ;
126  ALIAS b3 : STD_LOGIC_VECTOR(2 DOWNTO 0) IS DIN(7 DOWNTO 5) ;
127 
128 -----------------------------------------------------------------
129 -- Begin Architecture
130 -----------------------------------------------------------------
131 BEGIN
132 
133 -----------------------------------------------------------------
134 -- Map internal signals to proper port names
135 -----------------------------------------------------------------
136  DISP_OUT <= disp_run ;
137  KERR <= kerr_i ;
138 
139 -------------------------------------------------------------------------------
140 -- Calculate intermediate terms using notation and logic from 8b/10b spec
141 -------------------------------------------------------------------------------
142  k28 <= boolean_to_std_logic((KIN = '1') AND (b5 = "11100")) ;
143  l13 <= (((a XOR b) AND NOT(c OR d)) OR ((c XOR d) AND NOT(a OR b)));
144  l31 <= (((a XOR b) AND (c AND d)) OR ((c XOR d) AND (a AND b)));
145  a7 <= (KIN OR ((l31 AND D AND NOT(e) AND disp_in_i) OR
146  (l13 AND NOT(d) AND e AND NOT(disp_in_i))));
147 
148 ------------------------------------------------------
149 -- Check for invalid K codes
150 ------------------------------------------------------
151  gke : IF (C_HAS_KERR = 1) GENERATE
152  PROCESS (CLK)
153  BEGIN
154  IF (CLK'event AND CLK = '1') THEN
155  IF (CE = '1') THEN
156  IF (FORCE_CODE='1') THEN
157  kerr_i <= NEG AFTER TFF;
158  ELSIF (b5 = "11100") THEN
159  kerr_i <= NEG AFTER TFF;
160  ELSIF (b3 /= "111") THEN
161  kerr_i <= KIN AFTER TFF;
162  ELSIF ((b5 /= "10111") AND (b5 /= "11011") AND (b5 /= "11101")
163  AND (b5 /= "11110")) THEN
164  kerr_i <= KIN AFTER TFF;
165  ELSE
166  kerr_i <= NEG AFTER TFF;
167  END IF ;
168  END IF ;
169  END IF;
170  END PROCESS;
171  END GENERATE gke ;
172 
173  ngke : IF (C_HAS_KERR /= 1) GENERATE
174  kerr_i <= '0';
175  END GENERATE ngke ;
176 
177 -------------------------------------------------------
178 --Do the 5B/6B conversion (calculate the 6b symbol)
179 -------------------------------------------------------
180  PROCESS (b5, k28, disp_in_i)
181  BEGIN
182  IF (k28='1') THEN --K.28
183  IF (disp_in_i = NEG) THEN
184  b6 <= "111100" ;
185  ELSE
186  b6 <= "000011" ;
187  END IF;
188  ELSE
189  CASE b5 IS
190  WHEN "00000" => --D.0
191  IF (disp_in_i = POS)
192  THEN b6 <= "000110" ;
193  ELSE b6 <= "111001" ;
194  END IF ;
195  WHEN "00001" => --D.1
196  IF (disp_in_i = POS)
197  THEN b6 <= "010001" ;
198  ELSE b6 <= "101110" ;
199  END IF ;
200  WHEN "00010" => --D.2
201  IF (disp_in_i = POS)
202  THEN b6 <= "010010" ;
203  ELSE b6 <= "101101" ;
204  END IF ;
205  WHEN "00011" => b6 <= "100011" ; --D.3
206  WHEN "00100" => --D.4
207  IF (disp_in_i = POS)
208  THEN b6 <= "010100" ;
209  ELSE b6 <= "101011" ;
210  END IF ;
211  WHEN "00101" => b6 <= "100101" ; --D.5
212  WHEN "00110" => b6 <= "100110" ; --D.6
213  WHEN "00111" => --D.7
214  IF (disp_in_i = NEG)
215  THEN b6 <= "000111" ;
216  ELSE b6 <= "111000" ;
217  END IF ;
218  WHEN "01000" => --D.8
219  IF (disp_in_i = POS)
220  THEN b6 <= "011000" ;
221  ELSE b6 <= "100111" ;
222  END IF ;
223  WHEN "01001" => b6 <= "101001" ; --D.9
224  WHEN "01010" => b6 <= "101010" ; --D.10
225  WHEN "01011" => b6 <= "001011" ; --D.11
226  WHEN "01100" => b6 <= "101100" ; --D.12
227  WHEN "01101" => b6 <= "001101" ; --D.13
228  WHEN "01110" => b6 <= "001110" ; --D.14
229  WHEN "01111" => --D.15
230  IF (disp_in_i = POS)
231  THEN b6 <= "000101" ;
232  ELSE b6 <= "111010" ;
233  END IF ;
234 
235  WHEN "10000" => --D.16
236  IF (disp_in_i = NEG)
237  THEN b6 <= "110110" ;
238  ELSE b6 <= "001001" ;
239  END IF ;
240  WHEN "10001" => b6 <= "110001" ; --D.17
241  WHEN "10010" => b6 <= "110010" ; --D.18
242  WHEN "10011" => b6 <= "010011" ; --D.19
243  WHEN "10100" => b6 <= "110100" ; --D.20
244  WHEN "10101" => b6 <= "010101" ; --D.21
245  WHEN "10110" => b6 <= "010110" ; --D.22
246  WHEN "10111" => --D/K.23
247  IF (disp_in_i = NEG)
248  THEN b6 <= "010111" ;
249  ELSE b6 <= "101000" ;
250  END IF ;
251  WHEN "11000" => --D.24
252  IF (disp_in_i = POS)
253  THEN b6 <= "001100" ;
254  ELSE b6 <= "110011" ;
255  END IF ;
256  WHEN "11001" => b6 <= "011001" ; --D.25
257  WHEN "11010" => b6 <= "011010" ; --D.26
258  WHEN "11011" => --D/K.27
259  IF (disp_in_i = NEG)
260  THEN b6 <= "011011" ;
261  ELSE b6 <= "100100" ;
262  END IF ;
263  WHEN "11100" => b6 <= "011100" ; --D.28
264  WHEN "11101" => --D/K.29
265  IF (disp_in_i = NEG)
266  THEN b6 <= "011101" ;
267  ELSE b6 <= "100010" ;
268  END IF ;
269  WHEN "11110" => --D/K.30
270  IF (disp_in_i = NEG)
271  THEN b6 <= "011110" ;
272  ELSE b6 <= "100001" ;
273  END IF ;
274  WHEN "11111" => --D.31
275  IF (disp_in_i = NEG)
276  THEN b6 <= "110101" ;
277  ELSE b6 <= "001010" ;
278  END IF ;
279  WHEN OTHERS => NULL;
280  END CASE ;
281  END IF ;
282  END PROCESS ;
283 
284 -------------------------------------------------------
285 -- Calculate the running disparity -after- the 6B symbol
286 -------------------------------------------------------
287  PROCESS (b5, k28, disp_in_i)
288  BEGIN
289  IF (k28='1') THEN
290  pdes6 <= NOT(disp_in_i) ;
291  ELSE
292  CASE b5 IS
293  WHEN "00000" => pdes6 <= NOT(disp_in_i) ;
294  WHEN "00001" => pdes6 <= NOT(disp_in_i) ;
295  WHEN "00010" => pdes6 <= NOT(disp_in_i) ;
296  WHEN "00011" => pdes6 <= disp_in_i ;
297  WHEN "00100" => pdes6 <= NOT(disp_in_i) ;
298  WHEN "00101" => pdes6 <= disp_in_i ;
299  WHEN "00110" => pdes6 <= disp_in_i ;
300  WHEN "00111" => pdes6 <= disp_in_i ;
301 
302  WHEN "01000" => pdes6 <= NOT(disp_in_i) ;
303  WHEN "01001" => pdes6 <= disp_in_i ;
304  WHEN "01010" => pdes6 <= disp_in_i ;
305  WHEN "01011" => pdes6 <= disp_in_i ;
306  WHEN "01100" => pdes6 <= disp_in_i ;
307  WHEN "01101" => pdes6 <= disp_in_i ;
308  WHEN "01110" => pdes6 <= disp_in_i ;
309  WHEN "01111" => pdes6 <= NOT(disp_in_i) ;
310 
311  WHEN "10000" => pdes6 <= NOT(disp_in_i) ;
312  WHEN "10001" => pdes6 <= disp_in_i ;
313  WHEN "10010" => pdes6 <= disp_in_i ;
314  WHEN "10011" => pdes6 <= disp_in_i ;
315  WHEN "10100" => pdes6 <= disp_in_i ;
316  WHEN "10101" => pdes6 <= disp_in_i ;
317  WHEN "10110" => pdes6 <= disp_in_i ;
318  WHEN "10111" => pdes6 <= NOT(disp_in_i) ;
319 
320  WHEN "11000" => pdes6 <= NOT(disp_in_i) ;
321  WHEN "11001" => pdes6 <= disp_in_i ;
322  WHEN "11010" => pdes6 <= disp_in_i ;
323  WHEN "11011" => pdes6 <= NOT(disp_in_i) ;
324  WHEN "11100" => pdes6 <= disp_in_i ;
325  WHEN "11101" => pdes6 <= NOT(disp_in_i) ;
326  WHEN "11110" => pdes6 <= NOT(disp_in_i) ;
327  WHEN "11111" => pdes6 <= NOT(disp_in_i) ;
328  WHEN OTHERS => pdes6 <= disp_in_i;
329  END CASE ;
330  END IF ;
331  END PROCESS ;
332 
333 ------------------------------------------------------
334 -- Do the 3B/4B conversion (calculate the 4b symbol)
335 ------------------------------------------------------
336  PROCESS (b3, k28, pdes6, a7)
337  BEGIN
338  CASE b3 IS
339  WHEN "000" => --D/K.x.0
340  IF (pdes6 = POS)
341  THEN b4 <= "0010" ;
342  ELSE b4 <= "1101" ;
343  END IF ;
344  WHEN "001" => --D/K.x.1
345  IF ((k28='1') AND (pdes6 = NEG))
346  THEN b4 <= "0110" ;
347  ELSE b4 <= "1001" ;
348  END IF ;
349  WHEN "010" => --D/K.x.2
350  IF ((k28='1') AND (pdes6 = NEG))
351  THEN b4 <= "0101" ;
352  ELSE b4 <= "1010" ;
353  END IF ;
354  WHEN "011" => --D/K.x.3
355  IF (pdes6 = NEG)
356  THEN b4 <= "0011" ;
357  ELSE b4 <= "1100" ;
358  END IF ;
359  WHEN "100" => --D/K.x.4
360  IF (pdes6 = POS)
361  THEN b4 <= "0100" ;
362  ELSE b4 <= "1011" ;
363  END IF ;
364  WHEN "101" => --D/K.x.5
365  IF ((k28='1') AND (pdes6 = NEG))
366  THEN b4 <= "1010" ;
367  ELSE b4 <= "0101" ;
368  END IF ;
369  WHEN "110" => --D/K.x.6
370  IF ((k28='1') AND (pdes6 = NEG))
371  THEN b4 <= "1001" ;
372  ELSE b4 <= "0110" ;
373  END IF ;
374  WHEN "111" => --D.x.P7
375  IF (a7 /= '1') THEN
376  IF (pdes6 = NEG)
377  THEN b4 <= "0111" ;
378  ELSE b4 <= "1000" ;
379  END IF ;
380  ELSE --D/K.y.A7
381  IF (pdes6 = NEG)
382  THEN b4 <= "1110" ;
383  ELSE b4 <= "0001" ;
384  END IF ;
385  END IF ;
386  WHEN OTHERS => NULL;
387  END CASE ;
388 
389  END PROCESS ;
390 
391 -------------------------------------------------------
392 -- Calculate the running disparity -after- the 4B symbol
393 -------------------------------------------------------
394  PROCESS (b3, pdes6)
395  BEGIN
396  CASE b3 IS
397  WHEN "000" => pdes4 <= NOT(pdes6) ;
398  WHEN "001" => pdes4 <= pdes6 ;
399  WHEN "010" => pdes4 <= pdes6 ;
400  WHEN "011" => pdes4 <= pdes6 ;
401  WHEN "100" => pdes4 <= NOT(pdes6) ;
402  WHEN "101" => pdes4 <= pdes6 ;
403  WHEN "110" => pdes4 <= pdes6 ;
404  WHEN "111" => pdes4 <= NOT(pdes6) ;
405  WHEN OTHERS => pdes4 <= pdes6;
406  END CASE ;
407  END PROCESS ;
408 
409 -------------------------------------------------------
410 -- Update the running disparity on the clock
411 -------------------------------------------------------
412  gdr: IF ((C_HAS_FORCE_CODE = 1) AND (C_FORCE_CODE_DISP = 1)) GENERATE
413  PROCESS (CLK)
414  BEGIN
415  IF (CLK'event AND CLK = '1') THEN
416  IF (CE = '1') THEN
417  IF (FORCE_CODE = '1') THEN
418  disp_run <= '1' AFTER TFF;
419  ELSE
420  disp_run <= pdes4 AFTER TFF;
421  END IF;
422  END IF;
423  END IF;
424  END PROCESS;
425  END GENERATE gdr;
426 
427  gdc: IF ((C_HAS_FORCE_CODE = 1) AND (C_FORCE_CODE_DISP = 0)) GENERATE
428  PROCESS (CLK)
429  BEGIN
430  IF (CLK'event AND CLK = '1') THEN
431  IF (CE = '1') THEN
432  IF (FORCE_CODE = '1') THEN
433  disp_run <= '0' AFTER TFF;
434  ELSE
435  disp_run <= pdes4 AFTER TFF;
436  END IF;
437  END IF;
438  END IF;
439  END PROCESS;
440  END GENERATE gdc;
441 
442  ngdb: IF (C_HAS_FORCE_CODE = 0) GENERATE
443  PROCESS (CLK)
444  BEGIN
445  IF (CLK'event AND CLK = '1') THEN
446  IF (CE = '1') THEN
447  disp_run <= pdes4 AFTER TFF;
448  END IF;
449  END IF ;
450  END PROCESS;
451  END GENERATE ngdb;
452 
453 --------------------------------------------------------
454 -- Override the internal running disparity if FORCE_DISP=1
455 --------------------------------------------------------
456  gpd: IF (C_HAS_DISP_IN = 1) GENERATE
457  PROCESS (FORCE_DISP, DISP_IN, disp_run)
458  BEGIN
459  IF (FORCE_DISP = '1') THEN
460  disp_in_i <= DISP_IN ;
461  ELSE
462  disp_in_i <= disp_run ;
463  END IF ;
464  END PROCESS ;
465  END GENERATE gpd;
466 
467  ngpd: IF (C_HAS_DISP_IN=0) GENERATE
468  disp_in_i <= disp_run;
469  END GENERATE ngpd;
470 
471 --------------------------------------------------------
472 -- Update the data output on the clock
473 --------------------------------------------------------
474  PROCESS (CLK)
475  BEGIN
476  IF (CLK'event AND CLK = '1') THEN
477  IF (CE = '1') THEN
478  IF (FORCE_CODE = '1') THEN
479  DOUT <= str_to_slv(C_FORCE_CODE_VAL, 10) AFTER TFF;
480  ELSE
481  DOUT <= (b4 & b6) AFTER TFF ;
482  END IF ;
483  END IF;
484  END IF ;
485  END PROCESS ;
486 
487 -------------------------------------------------------
488 -- Update the ND output on the clock
489 -------------------------------------------------------
490  gnd: IF (C_HAS_ND=1) GENERATE
491  PROCESS (CLK)
492  BEGIN
493  IF (CLK'event AND CLK = '1') THEN
494  IF (FORCE_CODE = '1') THEN
495  ND <= '0' AFTER TFF;
496  ELSE
497  ND <= CE AFTER TFF;
498  END IF;
499  END IF;
500  END PROCESS;
501  END GENERATE gnd;
502 
503  END xilinx ;
504