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

Subversion Repositories iso7816_3_master

[/] [iso7816_3_master/] [trunk/] [test/] [ComTxDriverTasks.v] - Blame information for rev 15

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 11 acapola
/*
2
Author: Sebastien Riou (acapola)
3
Creation date: 17:16:40 01/09/2011
4
 
5
$LastChangedDate: 2011-02-13 16:20:10 +0100 (Sun, 13 Feb 2011) $
6
$LastChangedBy: acapola $
7
$LastChangedRevision: 15 $
8
$HeadURL: file:///svn/iso7816_3_master/iso7816_3_master/trunk/test/ComTxDriverTasks.v $
9
 
10
This file is under the BSD licence:
11
Copyright (c) 2011, Sebastien Riou
12
 
13
All rights reserved.
14
 
15
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
16
 
17
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
18
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.
19
The names of contributors may not be used to endorse or promote products derived from this software without specific prior written permission.
20
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
*/
32
`default_nettype none
33 9 acapola
`include "HexStringConversion.v"
34 5 acapola
 
35 9 acapola
//low level tasks
36 5 acapola
task sendByte;
37
  input [7:0] data;
38
  begin
39
      wait(bufferFull==1'b0);
40
      dataIn=data;
41
      nWeDataIn=0;
42
      @(posedge COM_clk);
43
      dataIn=8'hxx;
44
      nWeDataIn=1;
45
      @(posedge COM_clk);
46
        end
47
endtask
48
task sendWord;
49
  input [15:0] data;
50
  begin
51
      sendByte(data[15:8]);
52
                sendByte(data[7:0]);
53
        end
54
endtask
55 12 acapola
 
56
//return when the stop bit of the last byte is starting
57 5 acapola
task waitEndOfTx;
58
  begin
59
      @(posedge COM_clk)
60
                wait(txPending==0);
61
                wait(isTx==0);
62
        end
63
endtask
64
 
65 9 acapola
 
66
//Higher level tasks
67 15 acapola
 
68
 
69 9 acapola
task sendHexBytes;
70
        input [16*257:0] bytesString;
71
        integer i;
72
        reg [15:0] byteInHex;
73
        reg [7:0] byteToSend;
74
begin
75 14 acapola
        i=16*257;
76
        getNextHexByte(bytesString, i, byteToSend, i);
77
        while(i!=-1) begin
78
                sendByte(byteToSend);
79
                getNextHexByte(bytesString, i, byteToSend, i);
80 9 acapola
        end
81
end
82
endtask
83
 
84 15 acapola
task sendT0TpduLc;
85
        input [8*3*(256+5+1+2):0] bytesString;
86
        integer i;
87
        reg [15:0] byteInHex;
88
        reg [7:0] byteToSend;
89
        reg [8*(256+5+1+2):0] cmdBytes;
90
        integer nBytes;
91
begin
92
        hexStringToBytes(bytesString,cmdBytes,nBytes);
93
        sendByte(cmdBytes[0*8+:8]);
94
        sendByte(cmdBytes[1*8+:8]);
95
        sendByte(cmdBytes[2*8+:8]);
96
        sendByte(cmdBytes[3*8+:8]);
97
        sendByte(cmdBytes[4*8+:8]);
98
        if(0!==cmdBytes[4*8+:8]) begin
99
                i=5;
100
                receiveAndCheckByte(cmdBytes[1*8+:8]);//TODO: handle NACK
101
                while(i!=nBytes) begin
102
                        sendByte(cmdBytes[i*8+:8]);
103
                        i=i+1;
104
                end
105
        end
106
end
107
endtask
108
 
109
task sendT0TpduLeFull;
110
        input [8*3*5:0] bytesString;
111
        output [8*256:0] leBytes;
112
        output integer le;
113
        integer i;
114
        reg [15:0] byteInHex;
115
        reg [7:0] byteToSend;
116
        reg [8*(256+5+1+2):0] cmdBytes;
117
        integer nBytes;
118
begin
119
        hexStringToBytes(bytesString,cmdBytes,nBytes);
120
        sendByte(cmdBytes[0*8+:8]);
121
        sendByte(cmdBytes[1*8+:8]);
122
        sendByte(cmdBytes[2*8+:8]);
123
        sendByte(cmdBytes[3*8+:8]);
124
        sendByte(cmdBytes[4*8+:8]);
125
        le = (0===cmdBytes[4*8+:8]) ? 256 : cmdBytes[4*8+:8];
126
        if((nBytes!==5) & (le !== nBytes-5)) begin
127
                $display("ERROR: le (%d) don't match with nBytes (%d) in command %s",le,nBytes,bytesString);
128
                $finish;
129
        end
130
        receiveByte(cmdBytes[1*8+:8]);
131
        for(i=0;i<le;i=i+1) begin
132
                receiveByte(leBytes[i*8+:8]);
133
        end
134
end
135
endtask
136
 
137
task sendT0TpduLe;
138
        input [8*3*5:0] bytesString;
139
        output [8*256:0] leBytes;
140
        integer i;
141
begin
142
        sendT0TpduLeFull(bytesString,leBytes,i);
143
end
144
endtask
145
 
146
task sendT0TpduLeCheck;
147
        input [8*3*5:0] bytesString;
148
        input [8*3*256:0] expectedLeBytesString;
149
        integer i;
150
        reg [15:0] byteInHex;
151
        reg [7:0] byteToSend;
152
        reg [8*(256+5+1+2):0] cmdBytes;
153
        reg [8*256:0] leBytes;
154
        reg [8*256:0] expectedLeBytes;
155
        integer nBytes;
156
        integer expectedLe;
157
        integer le;
158
begin
159
        sendT0TpduLeFull(bytesString,leBytes,le);
160
        hexStringToBytes(expectedLeBytesString,expectedLeBytes,expectedLe);
161
        if(expectedLe !== le) begin
162
                $display("ERROR: expectedLe (%d) don't match with le (%d) in command %s, %s",expectedLe,le,bytesString, expectedLeBytesString);
163
                $finish;
164
        end
165
        for(i=0;i<le;i=i+1) begin
166
                if(leBytes[i*8+:8]!==expectedLeBytes[i*8+:8]) begin
167
                        $display("ERROR: recived %x instead of %x at index %d in command %s, %s",leBytes[i*8+:8],expectedLeBytes[i*8+:8],i,bytesString, expectedLeBytesString);
168
                        $finish;
169
                end
170
        end
171
end
172
endtask
173
 

powered by: WebSVN 2.1.0

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