Line 1... |
Line 1... |
/*
|
/*
|
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-01-29 13:16:17 +0100 (Sat, 29 Jan 2011) $
|
$LastChangedDate: 2011-02-10 16:40:57 +0100 (Thu, 10 Feb 2011) $
|
$LastChangedBy: acapola $
|
$LastChangedBy: acapola $
|
$LastChangedRevision: 11 $
|
$LastChangedRevision: 14 $
|
$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
|
|
|
Line 27... |
Line 27... |
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.
|
*/
|
*/
|
`default_nettype none
|
|
|
|
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
|
//hexString2Byte=0;
|
|
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";
|
Line 54... |
Line 52... |
hexString2Byte[i*4+:4]=nibble;
|
hexString2Byte[i*4+:4]=nibble;
|
end
|
end
|
end
|
end
|
endfunction
|
endfunction
|
|
|
|
task getNextHexByte;
|
|
input [8*3*257:0] bytesString;
|
|
input integer indexIn;
|
|
output reg [7:0] byteOut;
|
|
output integer indexOut;
|
|
reg [15:0] byteInHex;
|
|
begin
|
|
byteInHex=" ";
|
|
//$display("bytesString: %x",bytesString);
|
|
while((indexIn>=16)&((8'h0==byteInHex[15:8])|(8'h20==byteInHex[15:8]))) begin
|
|
byteInHex=bytesString[(indexIn-1)-:16];
|
|
indexIn=indexIn-8;
|
|
//$display("indexIn: %d",indexIn);
|
|
end
|
|
indexOut=indexIn-8;
|
|
//$display("indexOut: %d, byteInHex: '%s' (%x)",indexOut, byteInHex, byteInHex);
|
|
if((16'h0!=byteInHex) & (indexOut>=0) & (8'h20!=byteInHex[7:0])) begin
|
|
byteOut=hexString2Byte(byteInHex);
|
|
//$display("byteOut: %x",byteOut);
|
|
end else begin
|
|
indexOut=-1;
|
|
end
|
|
end
|
|
endtask
|
|
|
No newline at end of file
|
No newline at end of file
|