00001 --**************************************************************
00002 --* *
00003 --* The source code for the ATLAS BCM "AAA" FPGA is made *
00004 --* available via the GNU General Public License (GPL) *
00005 --* unless otherwise stated below. *
00006 --* *
00007 --* In case of problems/questions/bug reports etc. please *
00008 --* contact michael.niegl@cern.ch *
00009 --* *
00010 --**************************************************************
00011
00012 --**************************************************************
00013 --* *
00014 --* $Source: /local/reps/bcmfpga/bcm_aaa/bcm_aaa/eth/udp_addresses.vhd,v $
00015 --* $Revision: 2.22.2.5 $ *
00016 --* $Name: dev $ *
00017 --* $Author: mniegl $ *
00018 --* $Date: 2008/11/03 17:57:46 $ *
00019
00020
00021 --* *
00022 --**************************************************************
00023
00024 --*****************************************************************--
00025 --
00026 -- Ethernet Header
00027 --
00028 --*****************************************************************--
00029
00030
00031 library ieee;
00032
00033 use ieee.std_logic_1164.all;
00034
00035 use ieee.std_logic_arith.all;
00036
00037 use ieee.std_logic_unsigned.all;
00038
00039 library work;
00040
00041 use work.main_components.all;
00042
00043 use work.ipmac.all;
00044
00045 use work.build_parameters.all;
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090 package udp_addresses is
00091
00092 --*******************************************************************************
00093 --* type defs
00094 --*******************************************************************************
00095
00096 type arp_pkt is record
00097 htype : (15 downto 0);
00098 ptype : (15 downto 0);
00099 hlen : (7 downto 0);
00100 plen : (7 downto 0);
00101 operation : (15 downto 0);
00102 sha : (47 downto 0);
00103 spa : (31 downto 0);
00104 tha : (47 downto 0);
00105 tpa : (31 downto 0);
00106 end record;
00107
00108 --*******************************************************************************
00109 --* functions
00110 --*******************************************************************************
00111
00112
00113 function reverse4byte (a : (31 downto 0)) return ;
00114
00115 function reverse_any_vector(a : ) return ;
00116
00117 function cal_IP_chksum(a : ) return ;
00118
00119 function cal_UDP_chksum_base(a : ) return ;
00120
00121 function conf_tdaqport (sel : ) return ;
00122
00123 function conf_MAC (sel : ) return ;
00124
00125 function conf_IP return ;
00126
00127 function conf_chksum_rdy return ;
00128
00129 function conf_chksum_ovr return ;
00130
00131 function conf_chksum_start return ;
00132
00133 --*******************************************************************************
00134 --* constants
00135 --*******************************************************************************
00136
00137 alias zero_byte is gnd_vec;
00138
00139
00140 constant MAC_broadcast : (47 downto 0) := x"FF_FF_FF_FF_FF_FF";
00141
00142 constant src_MAC_1 : (47 downto 0) := conf_MAC(1);
00143
00144 constant src_MAC_2 : (47 downto 0) := conf_MAC(2);
00145
00146 constant des_MAC : (47 downto 0) := MAC_sbcbcmtcc01;
00147
00148 constant dcs_MAC : (47 downto 0) := MAC_pcatlbcmscs;
00149
00150 constant tdaq_MAC : (47 downto 0) := MAC_sbcbcmtcc01;
00151
00152 constant src_IP_addr : (31 downto 0) := conf_IP;
00153
00154 constant dest_IP_addr : (31 downto 0) := ip_sbcbcmtcc01;
00155
00156 constant rxsrcip : (31 downto 0) := dest_IP_addr;
00157
00158 constant dcs_IP_addr : (31 downto 0) := ip_pcatlbcmscs;
00159
00160 constant tdaq_IP_addr : (31 downto 0) := ip_sbcbcmtcc01;
00161
00162 constant rxdestip : (31 downto 0) := src_IP_addr;
00163
00164 constant src_port : (15 downto 0) := x"FFFF";
00165
00166 constant std_port : (15 downto 0) := x"0FF0";
00167
00168 constant dest_port : (15 downto 0) := conf_tdaqport(0);
00169
00170 constant rxsrc_port : (15 downto 0) := x"FFFF";
00171
00172 constant dcs_port : (15 downto 0) := x"FFF0";
00173
00174 constant tdaq_port : (15 downto 0) := conf_tdaqport(1);
00175
00176 constant rxdest_port : (15 downto 0) := x"FFFF";
00177
00178 constant ethertype : (15 downto 0) := x"0800";
00179
00180 constant arptype : (15 downto 0) := x"0806";
00181
00182 constant udp_protocol : (7 downto 0) := x"11";
00183
00184 constant raw_protocol : (7 downto 0) := x"FA";
00185
00186 constant protocol : (7 downto 0) := udp_protocol;
00187
00188 constant IPV4 : (3 downto 0) := x"4";
00189
00190 constant IHL : (3 downto 0) := x"5";
00191
00192 constant type_of_ser : (7 downto 0) := zero_byte;
00193
00194 constant realdatalen : := 192;
00195
00196 constant pktlen : := realdatalen + 7;
00197
00198 constant dcsdatalen : := 212;
00199
00200 constant tdaqdatalen : := 141;
00201
00202 constant ipheadlen : := 20;
00203
00204 constant udpheadlen : := 8;
00205
00206 constant udp_length : (15 downto 0) := conv_std_logic_vector(pktlen + udpheadlen, 16);
00207
00208 constant tot_length : (15 downto 0) := conv_std_logic_vector(pktlen + udpheadlen + ipheadlen, 16);
00209
00210 constant udp_dcs_length : (15 downto 0) := conv_std_logic_vector(dcsdatalen + udpheadlen, 16);
00211
00212 constant tot_dcs_length : (15 downto 0) := conv_std_logic_vector(dcsdatalen + udpheadlen + ipheadlen, 16);
00213
00214 constant udp_tdaq_length : (15 downto 0) := conv_std_logic_vector(tdaqdatalen + udpheadlen, 16);
00215
00216 constant tot_tdaq_length : (15 downto 0) := conv_std_logic_vector(tdaqdatalen + udpheadlen + ipheadlen, 16);
00217
00218 constant flags : (2 downto 0) := "010";
00219
00220 constant offset : (12 downto 0) := zero_byte & zero_byte(4 downto 0);
00221
00222 constant TTL : (7 downto 0) := x"FF";
00223
00224 constant id : (15 downto 0) := x"0000";
00225
00226 constant arp_ann_c : arp_pkt :=
00227 (
00228 htype => x"0001",
00229 ptype => x"0800",
00230 hlen => x"06",
00231 plen => x"04",
00232 operation => x"0001",
00233 sha => src_MAC_1,
00234 spa => src_IP_addr,
00235 tha => MAC_broadcast,
00236 tpa => src_IP_addr
00237 );
00238
00239 constant pause : := 5000;
00240
00241 constant cntwidth : := 19;
00242
00243 constant data : (15 downto 0) := x"f0f0";
00244
00245 constant rd_rdy_pat : (7 downto 0) := x"10";
00246
00247 constant rd_ovr_pat : (7 downto 0) := x"01";
00248
00249 constant ip_chksum : (15 downto 0) := cal_IP_chksum(IPV4 & IHL & type_of_ser &
00250 tot_length & id & flags & offset &
00251 TTL & protocol & x"0000" &
00252 src_IP_addr & dest_IP_addr);
00253
00254 constant ip_chksum_dcs : (15 downto 0) := cal_IP_chksum(IPV4 & IHL & type_of_ser &
00255 tot_dcs_length & id & flags & offset &
00256 TTL & protocol & x"0000" &
00257 src_IP_addr & dcs_IP_addr);
00258
00259 constant ip_chksum_tdaq : (15 downto 0) := cal_IP_chksum(IPV4 & IHL & type_of_ser &
00260 tot_tdaq_length & id & flags & offset &
00261 TTL & protocol & x"0000" &
00262 src_IP_addr & tdaq_IP_addr);
00263
00264 constant udp_chksum_base : (15 downto 0) := cal_UDP_chksum_base(src_IP_addr & dest_IP_addr &
00265 zero_byte & protocol & udp_length &
00266 src_port & dest_port & udp_length &
00267 zero_byte & zero_byte);
00268
00269 constant udp_chksum_base_dcs : (15 downto 0) := cal_UDP_chksum_base(src_IP_addr & dcs_IP_addr &
00270 zero_byte & protocol & udp_dcs_length &
00271 src_port & dcs_port & udp_dcs_length &
00272 zero_byte & zero_byte);
00273
00274 constant udp_chksum_base_tdaq : (15 downto 0) := cal_UDP_chksum_base(src_IP_addr & tdaq_IP_addr &
00275 zero_byte & protocol & udp_tdaq_length &
00276 src_port & tdaq_port & udp_tdaq_length &
00277 zero_byte & zero_byte);
00278
00279 constant start_chksum : (15 downto 0) := conf_chksum_start;
00280
00281 constant rdy_chksum : (15 downto 0) := conf_chksum_rdy;
00282
00283 constant ovr_chksum : (15 downto 0) := conf_chksum_ovr;
00284
00285 end udp_addresses;
00286
00287 package body udp_addresses is
00288
00289 --*******************************************************************************
00290 --* functions
00291 --*******************************************************************************
00292
00293 function conf_chksum_start
00294 return is
00295 variable p : (15 downto 0) := (others => '0');
00296 begin
00297 if kRODconf = "0" then
00298 p := x"f9e8";
00299 elsif kRODconf = "1" then
00300 p := x"f9ed";
00301 end if;
00302 return p;
00303 end conf_chksum_start;
00304
00305 function conf_chksum_rdy
00306 return is
00307 variable p : (15 downto 0) := (others => '0');
00308 begin
00309 if kRODconf = "0" then
00310 p := x"2f3e";
00311 elsif kRODconf = "1" then
00312 p := x"2f43";
00313 end if;
00314 return p;
00315 end conf_chksum_rdy;
00316
00317 function conf_chksum_ovr
00318 return is
00319 variable p : (15 downto 0) := (others => '0');
00320 begin
00321 if kRODconf = "0" then
00322 p := x"d4e3";
00323 elsif kRODconf = "1" then
00324 p := x"d4e8";
00325 end if;
00326 return p;
00327 end conf_chksum_ovr;
00328
00329 function conf_tdaqport(sel : )
00330 return is
00331 variable p : (15 downto 0);
00332 begin
00333 if kRODconf = "0" then
00334 if sel = 1 then
00335 p := std_port;
00336 else
00337 p := std_port+2;
00338 end if;
00339 elsif kRODconf = "1" then
00340 if sel = 1 then
00341 p := std_port + 1;
00342 else
00343 p := std_port+3;
00344 end if;
00345 end if;
00346 return p;
00347 end conf_tdaqport;
00348
00349 function conf_MAC(sel : )
00350 return is
00351 variable addr : (47 downto 0);
00352 begin -- conf_MAC
00353 if sel = 1 then
00354 if kRODconf = "0" then
00355 addr := testbeam_1;
00356 elsif kRODconf = "1" then
00357 addr := toronto_1;
00358 end if;
00359 elsif sel = 2 then
00360 if kRODconf = "0" then
00361 addr := testbeam_2;
00362 elsif kRODconf = "1" then
00363 addr := toronto_2;
00364 end if;
00365 end if;
00366 return addr;
00367 end conf_MAC;
00368
00369 function conf_IP
00370 return is
00371 begin -- conf_IP
00372 if kRODconf = "0" then
00373 return ip_testbeam_1;
00374 elsif kRODconf = "1" then
00375 return ip_toronto_1;
00376 else
00377 return x"0000_0000";
00378 end if;
00379 end conf_IP;
00380
00381 function reverse_any_vector (a : in )
00382 return is
00383 variable result : (a'range);
00384 alias aa : (a'reverse_range) is a;
00385 begin
00386 for i in aa'range loop
00387 result(i) := aa(i);
00388 end loop;
00389 return result;
00390 end reverse_any_vector;
00391
00392 function reverse4byte (a : in (31 downto 0))
00393 return is
00394 variable result : (31 downto 0);
00395 begin
00396 result(31 downto 24) := a(7 downto 0);
00397 result(23 downto 16) := a(15 downto 8);
00398 result(15 downto 8) := a(23 downto 16);
00399 result(7 downto 0) := a(31 downto 24);
00400 return result;
00401 end reverse4byte;
00402
00403 function cal_IP_chksum(a : )
00404 return is
00405 variable y : (15 downto 0) := (others => '0');
00406 variable input : (160 downto 1) := (others => '0');
00407 variable res, tmp, in1, in2 : (31 downto 0) := (others => '0');
00408 begin
00409 input := (others => '0');
00410 if a'length <= 160 then
00411 input((a'length) downto 1) := a;
00412 else
00413 input := a(159 downto 0);
00414 end if;
00415 for i in 5 downto 1 loop
00416 in1 := x"0000" & input(32*i downto (32*i)-15);
00417 in2 := x"0000" & input((32*i)-16 downto (32*i)-31);
00418 tmp := in1 + in2;
00419 res := res + tmp;
00420 end loop;
00421 y := res(31 downto 16) + res(15 downto 0);
00422 return not y;
00423 end cal_IP_chksum;
00424
00425 function cal_UDP_chksum_base (a : )
00426 return is
00427 variable y : (15 downto 0) := (others => '0');
00428 variable input : (160 downto 1) := (others => '0');
00429 variable res, tmp, in1, in2 : (31 downto 0) := (others => '0');
00430 begin
00431 input := (others => '0');
00432 if a'length <= 160 then
00433 input((a'length) downto 1) := a;
00434 else
00435 input := a(159 downto 0);
00436 end if;
00437 for i in 5 downto 1 loop
00438 in1 := x"0000" & input(32*i downto (32*i)-15);
00439 in2 := x"0000" & input((32*i)-16 downto (32*i)-31);
00440 tmp := in1 + in2;
00441 res := res + tmp;
00442 end loop;
00443 y := res(31 downto 16) + res(15 downto 0);
00444 return y;
00445 end cal_UDP_chksum_base;
00446
00447 end udp_addresses;