OpenCores
URL https://opencores.org/ocsvn/iso7816_3_master/iso7816_3_master/trunk

Subversion Repositories iso7816_3_master

[/] [iso7816_3_master/] [trunk/] [test/] [HexStringConversion.v] - Diff between revs 14 and 15

Only display areas with differences | Details | Blame | View Log

Rev 14 Rev 15
/*
/*
Author: Sebastien Riou (acapola)
Author: Sebastien Riou (acapola)
Creation date: 17:16:40 01/09/2011
Creation date: 17:16:40 01/09/2011
 
 
$LastChangedDate: 2011-02-10 16:40:57 +0100 (Thu, 10 Feb 2011) $
$LastChangedDate: 2011-02-13 16:20:10 +0100 (Sun, 13 Feb 2011) $
$LastChangedBy: acapola $
$LastChangedBy: acapola $
$LastChangedRevision: 14 $
$LastChangedRevision: 15 $
$HeadURL: file:///svn/iso7816_3_master/iso7816_3_master/trunk/test/HexStringConversion.v $
$HeadURL: file:///svn/iso7816_3_master/iso7816_3_master/trunk/test/HexStringConversion.v $
 
 
This file is under the BSD licence:
This file is under the BSD licence:
Copyright (c) 2011, Sebastien Riou
Copyright (c) 2011, Sebastien Riou
 
 
All rights reserved.
All rights reserved.
 
 
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
 
 
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
The names of contributors may not be used to endorse or promote products derived from this software without specific prior written permission.
The names of contributors may not be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
*/
 
 
function [7:0] hexString2Byte;
function [7:0] hexString2Byte;
        input [15:0] byteInHexString;
        input [15:0] byteInHexString;
        integer i;
        integer i;
        reg [7:0] hexDigit;
        reg [7:0] hexDigit;
        reg [4:0] nibble;
        reg [4:0] nibble;
        begin
        begin
                for(i=0;i<2;i=i+1) begin
                for(i=0;i<2;i=i+1) begin
                        nibble=5'b10000;//invalid
                        nibble=5'b10000;//invalid
                        hexDigit=byteInHexString[i*8+:8];
                        hexDigit=byteInHexString[i*8+:8];
                        if(("0"<=hexDigit)&&("9">=hexDigit))
                        if(("0"<=hexDigit)&&("9">=hexDigit))
                                nibble=hexDigit-"0";
                                nibble=hexDigit-"0";
                        if(("a"<=hexDigit)&&("f">=hexDigit))
                        if(("a"<=hexDigit)&&("f">=hexDigit))
                                nibble=10+hexDigit-"a";
                                nibble=10+hexDigit-"a";
                        if(("A"<=hexDigit)&&("F">=hexDigit))
                        if(("A"<=hexDigit)&&("F">=hexDigit))
                                nibble=10+hexDigit-"A";
                                nibble=10+hexDigit-"A";
                        if(nibble>15) begin
                        if(nibble>15) begin
                                $display("Invalid input for hex conversion: '%s', hexDigit='%s' (%x), nibble=%d",byteInHexString,hexDigit,hexDigit,nibble);
                                $display("Invalid input for hex conversion: '%s', hexDigit='%s' (%x), nibble=%d",byteInHexString,hexDigit,hexDigit,nibble);
                                $finish;
                                $finish;
                        end
                        end
                        hexString2Byte[i*4+:4]=nibble;
                        hexString2Byte[i*4+:4]=nibble;
                end
                end
        end
        end
endfunction
endfunction
 
 
task getNextHexByte;
task getNextHexByte;
input [8*3*257:0] bytesString;
input [8*3*(256+5+1+2):0] bytesString;
input integer indexIn;
input integer indexIn;
output reg [7:0] byteOut;
output reg [7:0] byteOut;
output integer indexOut;
output integer indexOut;
reg [15:0] byteInHex;
reg [15:0] byteInHex;
begin
begin
        byteInHex="  ";
        byteInHex="  ";
        //$display("bytesString: %x",bytesString);      
        //$display("bytesString: %x",bytesString);      
        while((indexIn>=16)&((8'h0==byteInHex[15:8])|(8'h20==byteInHex[15:8]))) begin
        while((indexIn>=16)&((8'h0==byteInHex[15:8])|(8'h20==byteInHex[15:8]))) begin
                byteInHex=bytesString[(indexIn-1)-:16];
                byteInHex=bytesString[(indexIn-1)-:16];
                indexIn=indexIn-8;
                indexIn=indexIn-8;
                //$display("indexIn: %d",indexIn);              
                //$display("indexIn: %d",indexIn);              
        end
        end
        indexOut=indexIn-8;
        indexOut=indexIn-8;
        //$display("indexOut: %d, byteInHex: '%s' (%x)",indexOut, byteInHex, byteInHex);
        //$display("indexOut: %d, byteInHex: '%s' (%x)",indexOut, byteInHex, byteInHex);
        if((16'h0!=byteInHex) & (indexOut>=0) & (8'h20!=byteInHex[7:0])) begin
        if((16'h0!=byteInHex) & (indexOut>=0) & (8'h20!=byteInHex[7:0])) begin
                byteOut=hexString2Byte(byteInHex);
                byteOut=hexString2Byte(byteInHex);
                //$display("byteOut: %x",byteOut);
                //$display("byteOut: %x",byteOut);
        end else begin
        end else begin
                indexOut=-1;
                indexOut=-1;
        end
        end
 
end
 
endtask
 
 
 
task hexStringToBytes;
 
input [8*3*(256+5+1+2):0] bytesString;
 
output reg [8*(256+5+1+2):0] bytesOut;
 
output integer nBytes;
 
integer i;
 
reg [7:0] newByte;
 
begin
 
        nBytes=0;
 
        i=8*3*(256+5+1+2);
 
        //$display("bytesString: %x",bytesString);
 
        getNextHexByte(bytesString, i, newByte, i);
 
        while(i!=-1) begin
 
                //$display("i: %d, nBytes: %d, newByte: %x",i, nBytes, newByte);
 
                bytesOut[nBytes*8+:8]=newByte;
 
                nBytes=nBytes+1;
 
                getNextHexByte(bytesString, i, newByte, i);
 
        end
end
end
endtask
endtask
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.