AMC13
Firmwares for the different applications of the AMC13 uTCA board made at Boston University
 All Classes Variables
encode_8b10b_pkg.vhd
1 ---------------------------------------------------------------------------
2 --
3 -- Module : encode_8b10b_pkg.vhd
4 --
5 -- Version : 1.1
6 --
7 -- Last Update : 2008-10-31
8 --
9 -- Project : 8b/10b Encoder Reference Design
10 --
11 -- Description : 8b/10b Encoder package file
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 USE IEEE.std_logic_misc.ALL;
66 USE STD.textio.ALL;
67 
68 -------------------------------------------------------------------------------
69 -- Package Declaration
70 -------------------------------------------------------------------------------
71 PACKAGE encode_8b10b_pkg IS
72 
73 -------------------------------------------------------------------------------
74 -- Constant Declaration
75 -------------------------------------------------------------------------------
76  CONSTANT TFF : time := 2 ns;
77 
78 -------------------------------------------------------------------------------
79 -- Function Declarations
80 -------------------------------------------------------------------------------
81  FUNCTION concat_force_code(
82  force_code_disp : INTEGER; force_code_val : STRING)
83  RETURN STRING;
84  FUNCTION str_to_slv(
85  bitsin : STRING; nbits : INTEGER)
86  RETURN STD_LOGIC_VECTOR;
87  FUNCTION boolean_to_std_logic(
88  value : BOOLEAN)
89  RETURN STD_LOGIC;
90  FUNCTION bint_2_sl (
91  X : INTEGER)
92  RETURN STD_LOGIC;
93  FUNCTION has_bport (
94  C_HAS_BPORTS : INTEGER; has_aport : INTEGER
95  ) RETURN INTEGER;
96 
97 END encode_8b10b_pkg;
98 
99 -------------------------------------------------------------------------------
100 -- Package Body
101 -------------------------------------------------------------------------------
102 PACKAGE BODY encode_8b10b_pkg IS
103 
104 -------------------------------------------------------------------------------
105 -- Determine initial value of DOUT based on C_FORCE_CODE_DISP and
106 -- C_FORCE_CODE_VAL
107 -------------------------------------------------------------------------------
108  FUNCTION concat_force_code(
109  force_code_disp : INTEGER;
110  force_code_val : STRING)
111  RETURN STRING IS
112  VARIABLE tmp : STRING (1 TO 12);
113  BEGIN
114  IF (force_code_disp = 1) THEN
115  tmp := "01" & force_code_val;
116  ELSE
117  tmp := "00" & force_code_val;
118  END IF;
119  RETURN tmp;
120  END concat_force_code;
121 
122 -------------------------------------------------------------------------------
123 -- Converts a STRING containing 1's and 0's into a STD_LOGIC_VECTOR of
124 -- width nbits.
125 -------------------------------------------------------------------------------
126  FUNCTION str_to_slv(bitsin : STRING; nbits : INTEGER)
127  RETURN STD_LOGIC_VECTOR IS
128  VARIABLE ret : STD_LOGIC_VECTOR(bitsin'range);
129  VARIABLE ret0s : STD_LOGIC_VECTOR(1 TO nbits) := (OTHERS => '0');
130  VARIABLE retpadded : STD_LOGIC_VECTOR(1 TO nbits) := (OTHERS => '0');
131  VARIABLE offset : INTEGER := 0;
132  BEGIN
133  IF(bitsin'length = 0) THEN -- Make all '0's
134  RETURN ret0s;
135  END IF;
136  IF(bitsin'length < nbits) THEN -- pad MSBs with '0's
137  offset := nbits - bitsin'length;
138  FOR i IN bitsin'range LOOP
139  IF bitsin(i) = '1' THEN
140  retpadded(i+offset) := '1';
141  ELSIF (bitsin(i) = 'X' OR bitsin(i) = 'x') THEN
142  retpadded(i+offset) := 'X';
143  ELSIF (bitsin(i) = 'Z' OR bitsin(i) = 'z') THEN
144  retpadded(i+offset) := 'Z';
145  ELSIF (bitsin(i) = '0') THEN
146  retpadded(i+offset) := '0';
147  END IF;
148  END LOOP;
149  retpadded(1 TO offset) := (OTHERS => '0');
150  RETURN retpadded;
151  END IF;
152  FOR i IN bitsin'range LOOP
153  IF bitsin(i) = '1' THEN
154  ret(i) := '1';
155  ELSIF (bitsin(i) = 'X' OR bitsin(i) = 'x') THEN
156  ret(i) := 'X';
157  ELSIF (bitsin(i) = 'Z' OR bitsin(i) = 'z') THEN
158  ret(i) := 'Z';
159  ELSIF (bitsin(i) = '0') THEN
160  ret(i) := '0';
161  END IF;
162  END LOOP;
163 
164  RETURN ret;
165  END str_to_slv;
166 
167 -------------------------------------------------------------------------------
168  -- This function takes in a boolean value and returns
169  -- a STD_LOGIC '0' or '1'
170 -------------------------------------------------------------------------------
171  FUNCTION boolean_to_std_logic(value : BOOLEAN) RETURN STD_LOGIC IS
172  BEGIN
173  IF (value=TRUE) THEN
174  RETURN '1';
175  ELSE
176  RETURN '0';
177  END IF;
178  END boolean_to_std_logic;
179 
180 -------------------------------------------------------------------------------
181 -- Converts a binary integer (0 or 1) to a std_logic binary value.
182 -------------------------------------------------------------------------------
183  FUNCTION bint_2_sl (X : INTEGER) RETURN STD_LOGIC IS
184  BEGIN
185  IF (X = 0) THEN
186  RETURN '0';
187  ELSE
188  RETURN '1';
189  END IF;
190  END bint_2_sl;
191 
192 -----------------------------------------------------------------------------
193 -- If C_HAS_BPORTS = 1, then the optional B ports are configured the
194 -- same as the optional A ports
195 -- If C_HAS_BPORTS = 0, then the optional B ports are disabled (= 0)
196 -----------------------------------------------------------------------------
197  FUNCTION has_bport (
198  C_HAS_BPORTS : INTEGER;
199  has_aport : INTEGER)
200  RETURN INTEGER IS
201  VARIABLE has_bport : INTEGER;
202  BEGIN
203  IF (C_HAS_BPORTS = 1) THEN
204  has_bport := has_aport;
205  ELSE
206  has_bport := 0;
207  END IF;
208  RETURN has_bport;
209  END has_bport;
210 
211 END encode_8b10b_pkg;
212