#!/usr/bin/perl
my @crc;
$preamble = '1010101010101010101010101010101010101010101010101010101010101011';
$da = '110111111101110100111101110000111101110000111101';
$sa = '110000111101110000111101110000111101110000111101';
$data_len = int( rand(50)) + 46;
print "$data_len ok\n";
$data_len_str = dec2bin($data_len);
#print "yes $data_len_str\n";
for ($i=0; $i < $data_len; $i++)
#for ($i=0; $i < 2; $i++)
{
$data_random = int( rand(255));
#print "$data_random \n";
$data_ran_str = dec2bin($data_random);
$pay_load = $pay_load . substr($data_ran_str,8);
#print "es $pay_load\n";
}
$crc_str_data = $da . $sa . $pay_load;
$crc_ini = '11111111111111111111111111111111' ;
@crc = split ("",$crc_ini);
print "\n crc initial @crc\n";
for ($i=0; $i < $data_len + 12; $i++)
{
print "for loop $i ";
$crc_char = substr ($crc_str_data , 8*$i ,8);
chomp($crc_char);
@data = split ("", $crc_char);
open (ABC,">> crccheck.txt");
print ABC "data $crc_char\n d0 @data[0] d1 @data[1] d2 @data[2] d3 @data[3],d4 @data[4] d5 @data[5] d6 @data[6] d7 @data[7] ";
@crc1[0] = @data[6] ^ @data[0] ^ @crc[24] ^ @crc[30];
print ABC "@crc11[0] @crc11[1] crc0= @crc1[0], data6= @data[6], data0= @data[0] ,crc24= @crc[24], crc30= @crc[30] \n";
@crc1[1] = @data[7] ^ @data[6] ^ @data[1] ^ @data[0] ^ @crc[24] ^ @crc[25] ^ @crc[30] ^ @crc[31];
@crc1[2] = @data[7] ^ @data[6] ^ @data[2] ^ @data[1] ^ @data[0] ^ @crc[24] ^ @crc[25] ^ @crc[26] ^ @crc[30] ^ @crc[31];
@crc1[3] = @data[7] ^ @data[3] ^ @data[2] ^ @data[1] ^ @crc[25] ^ @crc[26] ^ @crc[27] ^ @crc[31];
@crc1[4] = @data[6] ^ @data[4] ^ @data[3] ^ @data[2] ^ @data[0] ^ @crc[24] ^ @crc[26] ^ @crc[27] ^ @crc[28] ^ @crc[30];
@crc1[5] = @data[7] ^ @data[6] ^ @data[5] ^ @data[4] ^ @data[3] ^ @data[1] ^ @data[0] ^ @crc[24] ^ @crc[25] ^ @crc[27] ^ @crc[28] ^ @crc[29] ^ @crc[30] ^ @crc[31];
@crc1[6] = @data[7] ^ @data[6] ^ @data[5] ^ @data[4] ^ @data[2] ^ @data[1] ^ @crc[25] ^ @crc[26] ^ @crc[28] ^ @crc[29] ^ @crc[30] ^ @crc[31];
@crc1[7] = @data[7] ^ @data[5] ^ @data[3] ^ @data[2] ^ @data[0] ^ @crc[24] ^ @crc[26] ^ @crc[27] ^ @crc[29] ^ @crc[31];
@crc1[8] = @data[4] ^ @data[3] ^ @data[1] ^ @data[0] ^ @crc[0] ^ @crc[24] ^ @crc[25] ^ @crc[27] ^ @crc[28];
@crc1[9] = @data[5] ^ @data[4] ^ @data[2] ^ @data[1] ^ @crc[1] ^ @crc[25] ^ @crc[26] ^ @crc[28] ^ @crc[29];
@crc1[10] = @data[5] ^ @data[3] ^ @data[2] ^ @data[0] ^ @crc[2] ^ @crc[24] ^ @crc[26] ^ @crc[27] ^ @crc[29];
@crc1[11] = @data[4] ^ @data[3] ^ @data[1] ^ @data[0] ^ @crc[3] ^ @crc[24] ^ @crc[25] ^ @crc[27] ^ @crc[28];
@crc1[12] = @data[6] ^ @data[5] ^ @data[4] ^ @data[2] ^ @data[1] ^ @data[0] ^ @crc[4] ^ @crc[24] ^ @crc[25] ^ @crc[26] ^ @crc[28] ^ @crc[29] ^ @crc[30];
@crc1[13] = @data[7] ^ @data[6] ^ @data[5] ^ @data[3] ^ @data[2] ^ @data[1] ^ @crc[5] ^ @crc[25] ^ @crc[26] ^ @crc[27] ^ @crc[29] ^ @crc[30] ^ @crc[31];
@crc1[14] = @data[7] ^ @data[6] ^ @data[4] ^ @data[3] ^ @data[2] ^ @crc[6] ^ @crc[26] ^ @crc[27] ^ @crc[28] ^ @crc[30] ^ @crc[31];
@crc1[15]= @data[7] ^ @data[5] ^ @data[4] ^ @data[3] ^ @crc[7] ^ @crc[27] ^ @crc[28] ^ @crc[29] ^ @crc[31];
@crc1[16] = @data[5] ^ @data[4] ^ @data[0] ^ @crc[8] ^ @crc[24] ^ @crc[28] ^ @crc[29];
@crc1[17] = @data[6] ^ @data[5] ^ @data[1] ^ @crc[9] ^ @crc[25] ^ @crc[29] ^ @crc[30];
@crc1[18] = @data[7] ^ @data[6] ^ @data[2] ^ @crc[10] ^ @crc[26] ^ @crc[30] ^ @crc[31];
@crc1[19]= @data[7] ^ @data[3] ^ @crc[11] ^ @crc[27] ^ @crc[31];
@crc1[20] = @data[4] ^ @crc[12] ^ @crc[28];
@crc1[21] = @data[5] ^ @crc[13] ^ @crc[29];
@crc1[22] = @data[0] ^ @crc[14] ^ @crc[24];
@crc1[23] = @data[6] ^ @data[1] ^ @data[0] ^ @crc[15] ^ @crc[24] ^ @crc[25] ^ @crc[30];
@crc1[24] = @data[7] ^ @data[2] ^ @data[1] ^ @crc[16] ^ @crc[25] ^ @crc[26] ^ @crc[31];
@crc1[25]= @data[3] ^ @data[2] ^ @crc[17] ^ @crc[26] ^ @crc[27];
@crc1[26]= @data[6] ^ @data[4] ^ @data[3] ^ @data[0] ^ @crc[18] ^ @crc[24] ^ @crc[27] ^ @crc[28] ^ @crc[30];
@crc1[27] = @data[7] ^ @data[5] ^ @data[4] ^ @data[1] ^ @crc[19] ^ @crc[25] ^ @crc[28] ^ @crc[29] ^ @crc[31];
@crc1[28] = @data[6] ^ @data[5] ^ @data[2] ^ @crc[20] ^ @crc[26] ^ @crc[29] ^ @crc[30];
@crc1[29] = @data[7] ^ @data[6] ^ @data[3] ^ @crc[21] ^ @crc[27] ^ @crc[30] ^ @crc[31];
@crc1[30] = @data[7] ^ @data[4] ^ @crc[22] ^ @crc[28] ^ @crc[31];
@crc1[31]= @data[5] ^ @crc[23] ^ @crc[29];
@crc = @crc1 ;
#print" data @data \n"
}
$crc_32 = "@crc";
$crc_32 =~ s/(.)\s/$1/seg;
#$init_value1 = 0 unless (defined $init_value);
#$polynomial1 = 0xedb88320 unless (defined $polynomial);
#$crc_32 = mycrc32 ($crc_str_data,$init_value1,$polynomial1);
print "\n$crc_32";
$frame_data = $preamble . $crc_str_data . $crc_32 ;
sub dec2bin
{
my $str1 = unpack("B16", pack("n", shift));
# my $str = unpack("B32", pack("N", shift));
#$str1 = substr($str, 16);
return $str1;
}
sub mycrc32 {
my ($input, $init_value, $polynomial) = @_;
print "$input";
$init_value = 0 unless (defined $init_value);
$polynomial = 0xedb88320 unless (defined $polynomial);
my @lookup_table;
for (my $i=0; $i<256 br="" i=""> my $x = $i;
for (my $j=0; $j<8 br="" j=""> if ($x & 1) {
$x = ($x >> 1) ^ $polynomial;
} else {
$x = $x >> 1;
}
}
push @lookup_table, $x;
}
my $crc = $init_value ^ 0xffffffff;
foreach my $x (unpack ('C*', $input)) {
$crc = (($crc >> 8) & 0xffffff) ^ $lookup_table[ ($crc ^ $x) & 0xff ];
}
$crc = $crc ^ 0xffffffff;
return $crc;
}
8>256>
Decimal to Binary Conversion in Perl
$binstr = dec2bin(54);
print "$binstr";
sub dec2bin {
my $str = unpack("B32", pack("N", shift));
$str =~ s/^0+(?=\d)//; # otherwise you'll get leading zeros
return $str;
}
print "$binstr";
sub dec2bin {
my $str = unpack("B32", pack("N", shift));
$str =~ s/^0+(?=\d)//; # otherwise you'll get leading zeros
return $str;
}
Veilog code for Back-Off Time Calculation for GMAC
/////// Back-Off Calculation for GMAC /////////
if ( back_off_enable )
begin
// 32 bit crc polynomial...lfsr
// taps for lfsr [32,26,23,22,16,12,11,10,8,7,5,4,2,1,0] as per IEEE 802.3
lfsr_32[0] = lfsr_32[31];
lfsr_32[1] = lfsr_32[0] ^ lfsr_32[31];
lfsr_32[2] = lfsr_32[1] ^ lfsr_32[31];
lfsr_32[3] = lfsr_32[2];
lfsr_32[4] = lfsr_32[3] ^ lfsr_32[31];
lfsr_32[5] = lfsr_32[4] ^ lfsr_32[31];
lfsr_32[6] = lfsr_32[5] ;
lfsr_32[7] = lfsr_32[6] ^ lfsr_32[31];
lfsr_32[8] = lfsr_32[7] ^ lfsr_32[31];
lfsr_32[9] = lfsr_32[8];
lfsr_32[10] = lfsr_32[9] ^ lfsr_32[31];
lfsr_32[11] = lfsr_32[10] ^ lfsr_32[31];
lfsr_32[12] = lfsr_32[11] ^ lfsr_32[31];
lfsr_32[13:15] = lfsr_32[12:14];
lfsr_32[16] = lfsr_32[15] ^ lfsr_32[31];
lfsr_32[17:21] = lfsr_32[16:20];
lfsr_32[22] = lfsr_32[21] ^ lfsr_32[31];
lfsr_32[23] = lfsr_32[22] ^ lfsr_32[31];
lfsr_32[24:25] = lfsr_32[23:24];
lfsr_32[26] = lfsr_32[25] ^ lfsr_32[31];
lfsr_32[27:31] = lfsr_32[26:30];
end
end
end
always @ ( retrans_atempt or lfsr_32 )
begin : backoff_time
case( retxn_atmpt )
5'd1 : begin
back_off_time_tmp[9] = lfsr_32[0];
back_off_time_tmp[8:0] = 9'd 0;
end
5'd2 : begin
back_off_time_tmp[8:9] = lfsr_32[0:1];
back_off_time_tmp[7:0] = 8'd 0;
end
5'd3 : begin
back_off_time_tmp [7:9] = lfsr_32[0:2];
back_off_time_tmp[6:0] = 7'd 0;
end
5'd4 : begin
back_off_time_tmp[6:9] = lfsr_32[0:3];
back_off_time_tmp[5:0] = 6'd 0;
end
5'd5 : begin
back_off_time_tmp[5:9] = lfsr_32[0:4];
back_off_time_tmp[4:0] = 5'd 0;
end
5'd6 : begin
back_off_time_tmp[4:9] = lfsr_32[0:5];
back_off_time_tmp[3:0] = 4'd 0;
end
5'd7 : begin
back_off_time_tmp[3:9] = lfsr_32[0:6];
back_off_time_tmp[2:0] = 3'd 0;
end
5'd8 : begin
back_off_time_tmp[2:9] = lfsr_32[0:7];
back_off_time_tmp[1:0] = 2'd 0;
end
5'd9 : begin
back_off_time_tmp[1:9] = lfsr_32[0:8];
back_off_time_tmp[0] = 1'd 0;
end
5'd10,5'd11,5'd12,5'd13,5'd14,5'd15,
5'd16: back_off_time_tmp [9:0] = lfsr_32[9:0];
default : back_off_time_tmp [9:0] = 10'd 0;
endcase
end
if ( back_off_enable )
begin
// 32 bit crc polynomial...lfsr
// taps for lfsr [32,26,23,22,16,12,11,10,8,7,5,4,2,1,0] as per IEEE 802.3
lfsr_32[0] = lfsr_32[31];
lfsr_32[1] = lfsr_32[0] ^ lfsr_32[31];
lfsr_32[2] = lfsr_32[1] ^ lfsr_32[31];
lfsr_32[3] = lfsr_32[2];
lfsr_32[4] = lfsr_32[3] ^ lfsr_32[31];
lfsr_32[5] = lfsr_32[4] ^ lfsr_32[31];
lfsr_32[6] = lfsr_32[5] ;
lfsr_32[7] = lfsr_32[6] ^ lfsr_32[31];
lfsr_32[8] = lfsr_32[7] ^ lfsr_32[31];
lfsr_32[9] = lfsr_32[8];
lfsr_32[10] = lfsr_32[9] ^ lfsr_32[31];
lfsr_32[11] = lfsr_32[10] ^ lfsr_32[31];
lfsr_32[12] = lfsr_32[11] ^ lfsr_32[31];
lfsr_32[13:15] = lfsr_32[12:14];
lfsr_32[16] = lfsr_32[15] ^ lfsr_32[31];
lfsr_32[17:21] = lfsr_32[16:20];
lfsr_32[22] = lfsr_32[21] ^ lfsr_32[31];
lfsr_32[23] = lfsr_32[22] ^ lfsr_32[31];
lfsr_32[24:25] = lfsr_32[23:24];
lfsr_32[26] = lfsr_32[25] ^ lfsr_32[31];
lfsr_32[27:31] = lfsr_32[26:30];
end
end
end
always @ ( retrans_atempt or lfsr_32 )
begin : backoff_time
case( retxn_atmpt )
5'd1 : begin
back_off_time_tmp[9] = lfsr_32[0];
back_off_time_tmp[8:0] = 9'd 0;
end
5'd2 : begin
back_off_time_tmp[8:9] = lfsr_32[0:1];
back_off_time_tmp[7:0] = 8'd 0;
end
5'd3 : begin
back_off_time_tmp [7:9] = lfsr_32[0:2];
back_off_time_tmp[6:0] = 7'd 0;
end
5'd4 : begin
back_off_time_tmp[6:9] = lfsr_32[0:3];
back_off_time_tmp[5:0] = 6'd 0;
end
5'd5 : begin
back_off_time_tmp[5:9] = lfsr_32[0:4];
back_off_time_tmp[4:0] = 5'd 0;
end
5'd6 : begin
back_off_time_tmp[4:9] = lfsr_32[0:5];
back_off_time_tmp[3:0] = 4'd 0;
end
5'd7 : begin
back_off_time_tmp[3:9] = lfsr_32[0:6];
back_off_time_tmp[2:0] = 3'd 0;
end
5'd8 : begin
back_off_time_tmp[2:9] = lfsr_32[0:7];
back_off_time_tmp[1:0] = 2'd 0;
end
5'd9 : begin
back_off_time_tmp[1:9] = lfsr_32[0:8];
back_off_time_tmp[0] = 1'd 0;
end
5'd10,5'd11,5'd12,5'd13,5'd14,5'd15,
5'd16: back_off_time_tmp [9:0] = lfsr_32[9:0];
default : back_off_time_tmp [9:0] = 10'd 0;
endcase
end
Convert String in Array
Conversion of string into an Array in perl
## Convert String into array
my $str = " Perl: convert character array to string ";
my @char_array = split(//,$str);
## Make string from each value of char separated by string
$str = "@char_array";
print "$str\n";
## Replace the Extra separating spaces with blank
$str =~ s/(.)\s/$1/seg; ## Simple Regex
print "$str\n";
Subscribe to:
Posts (Atom)