1 |
2 |
cmagleby |
// ===========================================================================
|
2 |
|
|
// File : receive_packet.vri
|
3 |
|
|
// Author : cmagleby
|
4 |
|
|
// Date : Mon Dec 3 11:03:46 MST 2007
|
5 |
|
|
// Project : TI PHY design
|
6 |
|
|
//
|
7 |
|
|
// Copyright (c) notice
|
8 |
|
|
// This code adheres to the GNU public license
|
9 |
|
|
//
|
10 |
|
|
// ===========================================================================
|
11 |
|
|
//
|
12 |
6 |
cmagleby |
// $Id: receive_packet.vri,v 1.2 2007-12-07 20:16:29 cmagleby Exp $
|
13 |
2 |
cmagleby |
//
|
14 |
|
|
// ===========================================================================
|
15 |
|
|
//
|
16 |
|
|
// $Log: not supported by cvs2svn $
|
17 |
6 |
cmagleby |
// Revision 1.1.1.1 2007/12/05 18:37:06 cmagleby
|
18 |
|
|
// importing tb files
|
19 |
2 |
cmagleby |
//
|
20 |
6 |
cmagleby |
//
|
21 |
2 |
cmagleby |
// ===========================================================================
|
22 |
|
|
// Function : This file processes all packets received from the 16 tx interface
|
23 |
|
|
//
|
24 |
|
|
// ===========================================================================
|
25 |
|
|
// ===========================================================================
|
26 |
|
|
#include
|
27 |
|
|
#include "scramble8.vri"
|
28 |
|
|
#define COM_s 8'hbc
|
29 |
|
|
#define SKP_s 8'h1c
|
30 |
|
|
#define IDLE_s 8'h7c
|
31 |
|
|
#define FTS_s 8'h3c
|
32 |
|
|
#define STP_s 8'hfb
|
33 |
|
|
#define SDP_s 8'h5c
|
34 |
|
|
#define EDB 8'hfe
|
35 |
|
|
#define END_s 8'hfd
|
36 |
|
|
|
37 |
|
|
task receive_packet () {
|
38 |
|
|
bit [7:0] tx_data[];
|
39 |
|
|
bit tx_datak[];
|
40 |
|
|
integer ret,ret1,ret2,ret3,ret4;
|
41 |
|
|
integer i = 0;
|
42 |
|
|
integer m = 0;
|
43 |
|
|
bit[8:0] tx_pkt;
|
44 |
|
|
event phy_start, phy_done, tlp_start, tlp_done, dllp_start, dllp_done;
|
45 |
|
|
bit [7:0] phy_pkt[];
|
46 |
|
|
bit [7:0] dll_pkt[];
|
47 |
|
|
bit [7:0] tlp_pkt[];
|
48 |
|
|
integer j,k,l;
|
49 |
|
|
bit [127:0] build_phy_pkt;
|
50 |
|
|
bit [47:0] build_dll_pkt;
|
51 |
|
|
bit [127:0] build_tlp_header;
|
52 |
|
|
bit [31:0] build_tlp_data;
|
53 |
|
|
bit [15:0] expected_seq_id = 0;
|
54 |
|
|
bit [15:0] recv_seq_id = 0;
|
55 |
|
|
bit [9:0] recv_length = 0;
|
56 |
6 |
cmagleby |
bit [11:0] byte_length = 0;
|
57 |
2 |
cmagleby |
bit [31:0] recv_lcrc = 0;
|
58 |
|
|
bit td = 0;
|
59 |
|
|
integer kstart = 0;
|
60 |
|
|
integer debug = 1;
|
61 |
|
|
bit [15:0] lfsr = 16'hFFFF;
|
62 |
|
|
bit [7:0] scramble_data[];
|
63 |
|
|
bit skp_detect = 1'b0;
|
64 |
|
|
bit com_detect = 1'b0;
|
65 |
|
|
bit scram_bypass = 1'b0;
|
66 |
|
|
bit [3:0] bypass_count = 4'b0;
|
67 |
|
|
|
68 |
|
|
printf("Look for transmit packets\n");
|
69 |
|
|
wait_var(phy_rdy);
|
70 |
|
|
@ (posedge CLOCK);
|
71 |
|
|
fork
|
72 |
|
|
while (1) {
|
73 |
|
|
@ (posedge CLOCK);
|
74 |
|
|
tx_data[0] = ti_phy_top.txdata16[7:0];
|
75 |
|
|
tx_data[1] = ti_phy_top.txdata16[15:8];
|
76 |
|
|
tx_datak[0] = ti_phy_top.txdatak16[0];
|
77 |
|
|
tx_datak[1] = ti_phy_top.txdatak16[1];
|
78 |
|
|
for (i=0; i<2; i++) {
|
79 |
|
|
|
80 |
|
|
if(com_detect == 1'b1){
|
81 |
|
|
scram_bypass = 1'b1;
|
82 |
|
|
}
|
83 |
|
|
else if(((bypass_count == 4'b0011) & tx_datak[i] == 1'b1) | (bypass_count == 4'b1111)){
|
84 |
|
|
scram_bypass = 1'b0;
|
85 |
|
|
}
|
86 |
|
|
|
87 |
|
|
if((com_detect == 1'b1) | scram_bypass){
|
88 |
|
|
bypass_count = bypass_count + 1'b1;
|
89 |
|
|
}
|
90 |
|
|
else if(((bypass_count == 4'b0011) & tx_datak[i] == 1'b1) | (bypass_count == 4'b1111)){
|
91 |
|
|
bypass_count = 4'b0000;
|
92 |
|
|
}
|
93 |
|
|
|
94 |
|
|
|
95 |
|
|
if({tx_datak[i],tx_data[i]} == {1'b1,SKP_s}){
|
96 |
|
|
skp_detect = 1'b1;
|
97 |
|
|
}
|
98 |
|
|
else{
|
99 |
|
|
skp_detect = 1'b0;
|
100 |
|
|
}
|
101 |
|
|
if({tx_datak[i],tx_data[i]} == {1'b1,COM_s}){
|
102 |
|
|
com_detect = 1'b1;
|
103 |
|
|
}
|
104 |
|
|
else{
|
105 |
|
|
com_detect = 1'b0;
|
106 |
|
|
}
|
107 |
|
|
|
108 |
|
|
|
109 |
|
|
//printf("K-Code = %h DATA = %h COM = %h SKP = %h bypass_count = %d scram_bypass = %h\n",tx_datak[i],tx_data[i],com_detect,skp_detect,bypass_count,scram_bypass);
|
110 |
|
|
|
111 |
|
|
//if({tx_datak[i],tx_data[i]} == {1'b1,STP_s}){
|
112 |
|
|
// printf("Start of TLP packet.\n");
|
113 |
|
|
//}
|
114 |
|
|
|
115 |
|
|
scramble8(tx_data[i],skp_detect,com_detect,(scram_bypass | tx_datak[i]),lfsr,scramble_data[i],lfsr);
|
116 |
|
|
//printf("K-Code = %h COM = %h SKP = %h bypass = %h scramble_data = %h unscramble_data = %h lfsr = %h bypass_cnt = %d\n",tx_datak[i],com_detect,skp_detect,scram_bypass,tx_data[i],scramble_data[i],lfsr,bypass_count);
|
117 |
|
|
|
118 |
|
|
mailbox_put (tx_data_mailbox, {tx_datak[i],scramble_data[i]});
|
119 |
|
|
//printf("Add packet to tx_mailbox %0h\n",tx_data[i]);
|
120 |
|
|
|
121 |
|
|
}
|
122 |
|
|
}
|
123 |
|
|
while (1) {
|
124 |
|
|
ret = mailbox_get (WAIT,tx_data_mailbox,tx_pkt,CHECK);
|
125 |
|
|
if (ret <= 0)
|
126 |
|
|
error ("mailbox_get returned %0d\n",ret);
|
127 |
|
|
//printf ("got tx_pkt %0h\n",tx_pkt);
|
128 |
|
|
if (tx_pkt == {1'b1,COM_s}) {
|
129 |
|
|
trigger (ONE_BLAST,phy_start);
|
130 |
|
|
sync (ALL,phy_done);
|
131 |
|
|
}
|
132 |
|
|
if (tx_pkt == {1'b1,STP_s}) {
|
133 |
|
|
trigger (ONE_BLAST,tlp_start);
|
134 |
|
|
sync (ALL,tlp_done);
|
135 |
|
|
}
|
136 |
|
|
if (tx_pkt == {1'b1,SDP_s}) {
|
137 |
|
|
trigger (ONE_BLAST,dllp_start);
|
138 |
|
|
sync (ALL,dllp_done);
|
139 |
|
|
}
|
140 |
|
|
}
|
141 |
|
|
//phy layer packets
|
142 |
|
|
while (1) {
|
143 |
|
|
sync(ALL,phy_start);
|
144 |
|
|
//printf ("got past sync %0h\n",tx_pkt);
|
145 |
|
|
phy_pkt[0] = COM_s;
|
146 |
|
|
phy_pkt[4] = 0;
|
147 |
|
|
phy_pkt[5] = 0;
|
148 |
|
|
phy_pkt[6] = 0;
|
149 |
|
|
phy_pkt[7] = 0;
|
150 |
|
|
phy_pkt[8] = 0;
|
151 |
|
|
phy_pkt[9] = 0;
|
152 |
|
|
phy_pkt[10] = 0;
|
153 |
|
|
phy_pkt[11] = 0;
|
154 |
|
|
phy_pkt[12] = 0;
|
155 |
|
|
phy_pkt[13] = 0;
|
156 |
|
|
phy_pkt[14] = 0;
|
157 |
|
|
phy_pkt[15] = 0;
|
158 |
|
|
ret2 = mailbox_get (WAIT,tx_data_mailbox,tx_pkt,CHECK);
|
159 |
|
|
//printf ("got past mailbox get %0h\n",tx_pkt);
|
160 |
|
|
phy_pkt[1] = tx_pkt;
|
161 |
|
|
//training set
|
162 |
|
|
if ((tx_pkt == 'h1f7) || ~tx_pkt[8]) {
|
163 |
|
|
for (j = 2; j <16; j++) {
|
164 |
|
|
ret2 = mailbox_get (WAIT,tx_data_mailbox,tx_pkt,CHECK);
|
165 |
|
|
phy_pkt[j] = tx_pkt;
|
166 |
|
|
}
|
167 |
|
|
}
|
168 |
|
|
//skip fst idle
|
169 |
|
|
else {
|
170 |
|
|
for (j=2;j<4;j++) {
|
171 |
|
|
ret1 = mailbox_get (WAIT,tx_data_mailbox,tx_pkt,CHECK);
|
172 |
|
|
phy_pkt[j] = tx_pkt;
|
173 |
|
|
//printf ("skip loop got past %0h\n",tx_pkt);
|
174 |
|
|
}
|
175 |
|
|
}
|
176 |
|
|
build_phy_pkt = {phy_pkt[15],phy_pkt[14],phy_pkt[13],phy_pkt[12],phy_pkt[11],
|
177 |
|
|
phy_pkt[10],phy_pkt[9],phy_pkt[8],phy_pkt[7],phy_pkt[6],
|
178 |
|
|
phy_pkt[5],phy_pkt[4],phy_pkt[3],phy_pkt[2],phy_pkt[1],phy_pkt[0]};
|
179 |
|
|
mailbox_put (phy_mailbox, build_phy_pkt);
|
180 |
|
|
printf ("Recieved PHY PACKET (%0h) added to phy mailbox\n",build_phy_pkt);
|
181 |
|
|
trigger (ONE_BLAST,phy_done);
|
182 |
|
|
}
|
183 |
|
|
//dll layer packets
|
184 |
|
|
while (1) {
|
185 |
|
|
sync (ALL,dllp_start);
|
186 |
|
|
//printf ("sync into dllp packet\n");
|
187 |
|
|
for (k = 0; k < 6; k++) {
|
188 |
|
|
ret3 = mailbox_get (WAIT,tx_data_mailbox,tx_pkt,CHECK);
|
189 |
|
|
dll_pkt[k] = tx_pkt;
|
190 |
|
|
//printf ("dll_pkt(%0h)\n",dll_pkt[k]);
|
191 |
|
|
}
|
192 |
|
|
ret3 = mailbox_get (WAIT,tx_data_mailbox,tx_pkt,CHECK);
|
193 |
|
|
//printf ("dll this should be end(%0h)\n",tx_pkt);
|
194 |
|
|
if (tx_pkt == {1'b1,END_s}) {
|
195 |
|
|
build_dll_pkt = {dll_pkt[6],dll_pkt[5],dll_pkt[4],dll_pkt[3],
|
196 |
|
|
dll_pkt[2],dll_pkt[1],dll_pkt[0]};
|
197 |
|
|
mailbox_put (dllp_mailbox, build_dll_pkt);
|
198 |
|
|
printf ("Recieved DLL PACKET (%0h) added to dllp mailbox\n",build_dll_pkt);
|
199 |
|
|
}
|
200 |
|
|
else
|
201 |
|
|
printf ("ERROR ->>>>>>> DLL malformed no END\n");
|
202 |
|
|
|
203 |
|
|
trigger (ONE_BLAST,dllp_done);
|
204 |
|
|
}
|
205 |
|
|
//tlp layer packets
|
206 |
|
|
while (1) {
|
207 |
|
|
sync (ALL,tlp_start);
|
208 |
|
|
printf ("sync into tlp packet\n");
|
209 |
|
|
@(posedge CLOCK);
|
210 |
6 |
cmagleby |
//3 dw header + seq.
|
211 |
|
|
for (k = 0; k < 14; k++) {
|
212 |
2 |
cmagleby |
//printf("debug1 %0d\n",debug++);
|
213 |
|
|
ret4 = mailbox_get (WAIT,tx_data_mailbox,tx_pkt,CHECK);
|
214 |
|
|
tlp_pkt[k] = tx_pkt;
|
215 |
|
|
}
|
216 |
6 |
cmagleby |
//dword 4
|
217 |
|
|
if (tlp_pkt[2][5] == 1'b1) {
|
218 |
|
|
for (k=14;k<18;k++) {
|
219 |
|
|
ret4 = mailbox_get (WAIT,tx_data_mailbox,tx_pkt,CHECK);
|
220 |
|
|
tlp_pkt[k] = tx_pkt;
|
221 |
|
|
}
|
222 |
|
|
}
|
223 |
|
|
|
224 |
|
|
//****************************************************************************************
|
225 |
|
|
//Check sequence ID and send ACK
|
226 |
2 |
cmagleby |
recv_seq_id = {tlp_pkt[0],tlp_pkt[1]};
|
227 |
|
|
if (recv_seq_id != expected_seq_id) printf ("ERROR ->>>>>>> TLP BAD SEQUENCE ID of %0h\n",recv_seq_id);
|
228 |
|
|
else {
|
229 |
|
|
if (!semaphore_get(WAIT,my_semaphore,1))
|
230 |
|
|
error ("Semaphore_get returned 0\n");
|
231 |
|
|
ack_seq_num = new(recv_seq_id[7:0],{4'b0,recv_seq_id[11:8]},8'b0,8'b0);
|
232 |
6 |
cmagleby |
ack_seq_num.build_packet("ack");
|
233 |
|
|
printf("ACK PACKET Sequence Number (%0h)\n",recv_seq_id);
|
234 |
2 |
cmagleby |
for(m=0; m <= 3; m ++) {
|
235 |
|
|
if(m==0){
|
236 |
|
|
mailbox_put (rx_data_mailbox, {2'b01,ack_seq_num.temp_packet[0][7:0],8'h5C});
|
237 |
|
|
printf("DLLP bytes SDB & DLL_TYPE %h%h.\n",ack_seq_num.temp_packet[0][7:0],8'h5C);
|
238 |
|
|
}
|
239 |
|
|
else if(m==1){
|
240 |
|
|
mailbox_put (rx_data_mailbox, {2'b00,ack_seq_num.temp_packet[0][23:16],ack_seq_num.temp_packet[0][15:8]});
|
241 |
|
|
printf("DLLP bytes 2 & 1 %h%h.\n",ack_seq_num.temp_packet[0][23:16],ack_seq_num.temp_packet[0][15:8]);
|
242 |
|
|
}
|
243 |
|
|
else if(m==2){
|
244 |
|
|
mailbox_put (rx_data_mailbox, {2'b00,ack_seq_num.temp_packet[1][7:0],ack_seq_num.temp_packet[0][31:24]});
|
245 |
|
|
printf("DLLP CRC and byte 3 %h%h.\n",ack_seq_num.temp_packet[1][7:0],ack_seq_num.temp_packet[0][31:24]);
|
246 |
|
|
}
|
247 |
|
|
else if(m==3){
|
248 |
|
|
mailbox_put (rx_data_mailbox, {2'b10,8'hFD,ack_seq_num.temp_packet[1][15:8]});
|
249 |
|
|
printf("DLLP STP and CRC %h%h.\n",8'hFD,ack_seq_num.temp_packet[1][15:8]);
|
250 |
|
|
}
|
251 |
|
|
}
|
252 |
|
|
semaphore_put (my_semaphore, 1);
|
253 |
|
|
}
|
254 |
|
|
expected_seq_id++;
|
255 |
6 |
cmagleby |
//****************************************************************************************
|
256 |
|
|
//build tlp get all header information
|
257 |
2 |
cmagleby |
build_tlp_header = {tlp_pkt[17],tlp_pkt[16],tlp_pkt[15],tlp_pkt[14],
|
258 |
|
|
tlp_pkt[13],tlp_pkt[12],tlp_pkt[11],tlp_pkt[10],
|
259 |
|
|
tlp_pkt[9],tlp_pkt[8],tlp_pkt[7],tlp_pkt[6],
|
260 |
|
|
tlp_pkt[5],tlp_pkt[4],tlp_pkt[3],tlp_pkt[2]};
|
261 |
6 |
cmagleby |
|
262 |
2 |
cmagleby |
if (build_tlp_header[5] == 1'b0) {
|
263 |
|
|
build_tlp_header[127:96] = 32'b0;
|
264 |
|
|
}
|
265 |
6 |
cmagleby |
//****************************************************************************************
|
266 |
|
|
//put header in mailbox
|
267 |
2 |
cmagleby |
mailbox_put (tlp_header_mailbox, build_tlp_header);
|
268 |
|
|
printf ("Recieved TLP PACKET (%0h) added to tlp header mailbox\n",build_tlp_header);
|
269 |
6 |
cmagleby |
//****************************************************************************************
|
270 |
|
|
//check for data and put into mailbox
|
271 |
2 |
cmagleby |
if (build_tlp_header[6] == 1) {
|
272 |
|
|
td = build_tlp_header[23];
|
273 |
|
|
recv_length = {build_tlp_header[17:16],build_tlp_header[31:24]};
|
274 |
6 |
cmagleby |
byte_length = (recv_length*4) + (td*4);
|
275 |
|
|
printf ("TLP PACKET Receive Length dw(%0d) byte(%0d)\n",recv_length,byte_length);
|
276 |
|
|
for (k=1;k<=byte_length;k++) {
|
277 |
2 |
cmagleby |
ret4 = mailbox_get (WAIT,tx_data_mailbox,tx_pkt,CHECK);
|
278 |
|
|
tlp_pkt[k] = tx_pkt;
|
279 |
6 |
cmagleby |
if (k%4 ==0) {
|
280 |
2 |
cmagleby |
mailbox_put (tlp_data_mailbox, {tlp_pkt[k],tlp_pkt[k-1],tlp_pkt[k-2],tlp_pkt[k-3]});
|
281 |
6 |
cmagleby |
printf ("k = (%0d)\n",k);
|
282 |
2 |
cmagleby |
printf ("Recieved TLP DATA (%0h) added to tlp data mailbox\n",{tlp_pkt[k],tlp_pkt[k-1],tlp_pkt[k-2],tlp_pkt[k-3]});
|
283 |
|
|
}
|
284 |
|
|
|
285 |
|
|
}
|
286 |
|
|
}
|
287 |
6 |
cmagleby |
//****************************************************************************************
|
288 |
|
|
//Read out the LCRC
|
289 |
|
|
for (k=0;k<=3;k++) {
|
290 |
|
|
ret4 = mailbox_get (WAIT,tx_data_mailbox,tx_pkt,CHECK);
|
291 |
|
|
//printf("debug3 %0d\n",debug++);
|
292 |
|
|
tlp_pkt[k] = tx_pkt;
|
293 |
2 |
cmagleby |
}
|
294 |
6 |
cmagleby |
printf ("tlp lcrc value = %0h \n",{tlp_pkt[3],tlp_pkt[2],tlp_pkt[1],tlp_pkt[0]});
|
295 |
|
|
|
296 |
|
|
//****************************************************************************************
|
297 |
|
|
//READ out the END VALUE
|
298 |
2 |
cmagleby |
ret4 = mailbox_get (WAIT,tx_data_mailbox,tx_pkt,CHECK);
|
299 |
|
|
if (tx_pkt != {1'b1,END_s}) printf ("ERROR ->>>>>>> TLP malformed no END(%0h)\n",tx_pkt);
|
300 |
|
|
|
301 |
|
|
|
302 |
|
|
trigger (ONE_BLAST,tlp_done);
|
303 |
|
|
}
|
304 |
|
|
join none
|
305 |
|
|
}
|
306 |
|
|
|