1 |
2 |
cmagleby |
// ===========================================================================
|
2 |
|
|
// File : tlp_gen.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 |
|
|
// Please contact www.gutzlogic.com for details.
|
10 |
|
|
// cmagleby@gutzlogic.com; cwinward@gutzlogic.com
|
11 |
|
|
// ===========================================================================
|
12 |
|
|
//
|
13 |
5 |
cmagleby |
// $Id: tlp_gen.vri,v 1.2 2007-12-05 23:01:11 cmagleby Exp $
|
14 |
2 |
cmagleby |
//
|
15 |
|
|
// ===========================================================================
|
16 |
|
|
//
|
17 |
|
|
// $Log: not supported by cvs2svn $
|
18 |
5 |
cmagleby |
// Revision 1.1.1.1 2007/12/05 18:37:07 cmagleby
|
19 |
|
|
// importing tb files
|
20 |
2 |
cmagleby |
//
|
21 |
5 |
cmagleby |
//
|
22 |
2 |
cmagleby |
// ===========================================================================
|
23 |
|
|
// Function : This file generates cfgrd/wr memrd/wr.
|
24 |
|
|
//
|
25 |
|
|
// ===========================================================================
|
26 |
|
|
// ===========================================================================
|
27 |
|
|
#include
|
28 |
|
|
#define STP_s 8'hfb
|
29 |
|
|
#define EDB 8'hfe
|
30 |
|
|
task tlp_gen() {
|
31 |
|
|
|
32 |
|
|
bit [15:0] req_id;
|
33 |
|
|
bit [7:0] busnum;
|
34 |
|
|
bit [7:0] reg_num;
|
35 |
|
|
bit [3:0] first_be;
|
36 |
|
|
bit [3:0] last_be;
|
37 |
|
|
bit [63:0] address;
|
38 |
|
|
bit [9:0] length;
|
39 |
|
|
bit [31:0] data;
|
40 |
|
|
bit [7:0] tag;
|
41 |
|
|
|
42 |
|
|
sequence_id = 0; reg_num=0;first_be=4'hf;req_id=0101;tag=1;busnum=1;
|
43 |
|
|
printf ("read vendor id\n");
|
44 |
|
|
cfgrd(reg_num,first_be,req_id,tag,busnum);
|
45 |
5 |
cmagleby |
|
46 |
2 |
cmagleby |
sequence_id++; reg_num='h5;first_be=4'hf;req_id=0101;tag++;busnum=1;
|
47 |
|
|
printf ("write base address 1 register\n");
|
48 |
|
|
cfgwr(reg_num,first_be,req_id,tag,busnum,32'hba120000);
|
49 |
|
|
sequence_id++;address = 64'hba120000;length=10'h5;first_be=4'hf;last_be=4'hf;req_id=16'h0100;tag++;
|
50 |
|
|
memwr(address,length,first_be,last_be,req_id,tag);
|
51 |
5 |
cmagleby |
sequence_id++;
|
52 |
|
|
memrd(address,length,first_be,last_be,req_id,tag);
|
53 |
2 |
cmagleby |
}
|
54 |
|
|
|
55 |
|
|
task cfgrd (bit [7:0] reg_num,
|
56 |
|
|
bit [3:0] first_be,
|
57 |
|
|
bit [15:0] req_id,
|
58 |
|
|
bit [7:0] tag,
|
59 |
|
|
bit [7:0] busnum) {
|
60 |
|
|
|
61 |
|
|
integer index;
|
62 |
5 |
cmagleby |
integer ret;
|
63 |
|
|
bit [127:0] return_pkt;
|
64 |
|
|
bit [31:0] return_data;
|
65 |
2 |
cmagleby |
bit [63:0] address = {32'b0,busnum,5'b1,3'b0,8'b0,reg_num,2'b0};
|
66 |
|
|
|
67 |
|
|
tlp_packet = new(sequence_id,5'b00100,2'b0,10'h1,*,*,*,*,
|
68 |
|
|
address,req_id,tag,first_be,4'b0,*,*,*,*,*);
|
69 |
|
|
tlp_packet.build_packet("nonposted");
|
70 |
|
|
printf ("header %0h \n",tlp_packet.header);
|
71 |
|
|
if (!semaphore_get(WAIT,my_semaphore,1))
|
72 |
|
|
error ("Semaphore_get returned 0\n");
|
73 |
|
|
//sequence id
|
74 |
|
|
printf("%0h put into mailbox\n",{2'b01,packet_array[0][15:8],STP_s});
|
75 |
|
|
mailbox_put (rx_data_mailbox, {2'b01,packet_array[0][7:0],STP_s});
|
76 |
|
|
printf("%0h put into mailbox\n",{2'b00,packet_array[1][7:0],packet_array[0][7:0]});
|
77 |
|
|
mailbox_put (rx_data_mailbox, {2'b00,packet_array[1][7:0],packet_array[0][15:8]});
|
78 |
|
|
//loop for sending out packet
|
79 |
|
|
for (index=1;index<3;index++) {
|
80 |
|
|
printf("%0h put into mailbox index = %0d\n",{2'b00,packet_array[index][23:8]},index);
|
81 |
|
|
mailbox_put(rx_data_mailbox, {2'b00,packet_array[index][23:8]});
|
82 |
|
|
printf("%0h put into mailbox index+1 = %0d\n",{2'b00,packet_array[index+1][7:0],packet_array[index][31:24]},index+1);
|
83 |
|
|
mailbox_put(rx_data_mailbox, {2'b00,packet_array[index+1][7:0],packet_array[index][31:24]});
|
84 |
|
|
}
|
85 |
|
|
printf("%0h put into mailbox index = %0d\n",{2'b00,packet_array[index][23:8]},index);
|
86 |
|
|
mailbox_put(rx_data_mailbox, {2'b00,packet_array[index][23:8]});
|
87 |
|
|
printf("%0h put into mailbox index = %0d\n",{2'b00,tlp_packet.lcrc[7:0],packet_array[index][31:24]},index);
|
88 |
|
|
mailbox_put(rx_data_mailbox, {2'b00,tlp_packet.lcrc[7:0],packet_array[index][31:24]});
|
89 |
|
|
printf("%0h put into mailbox index = %0d\n",{2'b00,tlp_packet.lcrc[23:8]},index);
|
90 |
|
|
mailbox_put(rx_data_mailbox, {2'b00,tlp_packet.lcrc[23:8]});
|
91 |
|
|
printf("%0h put into mailbox\n",{2'b10,END_s,tlp_packet.lcrc[31:24]});
|
92 |
|
|
mailbox_put(rx_data_mailbox, {2'b10,END_s,tlp_packet.lcrc[31:24]});
|
93 |
|
|
semaphore_put (my_semaphore, 1);
|
94 |
5 |
cmagleby |
|
95 |
|
|
ret = mailbox_get (WAIT,tlp_header_mailbox,return_pkt,CHECK);
|
96 |
|
|
if (ret <= 0)
|
97 |
|
|
error ("mailbox_get returned %0d\n",ret);
|
98 |
|
|
if (return_pkt[4:0] == 4'ha) {
|
99 |
|
|
if (return_pkt[6] == 1'b1) {
|
100 |
|
|
ret = mailbox_get (WAIT,tlp_data_mailbox,return_data,CHECK);
|
101 |
|
|
if (ret <= 0)
|
102 |
|
|
error ("mailbox_get returned %0d\n",ret);
|
103 |
|
|
printf("returned header %0h and data %0h for tag %0h\n",return_pkt,return_data,tag);
|
104 |
|
|
}
|
105 |
|
|
}
|
106 |
|
|
else if ((return_pkt[4:0] == 4'ha) && (return_pkt[5] == 1'b0)) {
|
107 |
|
|
printf("comp without data returned header %0h and comp_stat of %0b\n",return_pkt,return_pkt[55:53]);
|
108 |
|
|
}
|
109 |
2 |
cmagleby |
}
|
110 |
|
|
|
111 |
5 |
cmagleby |
|
112 |
|
|
|
113 |
2 |
cmagleby |
task cfgwr (bit [7:0] reg_num,
|
114 |
|
|
bit [3:0] first_be,
|
115 |
|
|
bit [15:0] req_id,
|
116 |
|
|
bit [7:0] tag,
|
117 |
|
|
bit [7:0] busnum,
|
118 |
|
|
bit [31:0] data) {
|
119 |
|
|
|
120 |
5 |
cmagleby |
integer index;
|
121 |
|
|
integer ret;
|
122 |
|
|
bit [127:0] return_pkt;
|
123 |
2 |
cmagleby |
//bus num,device num,function num,ext reg reg_num;
|
124 |
|
|
bit [63:0] address = {32'b0,busnum,5'b1,3'b0,8'b0,reg_num,2'b0};
|
125 |
|
|
printf ("cfgwr data = %0h\n",data);
|
126 |
|
|
tlp_packet = new(sequence_id,5'b00100,2'b10,10'h1,*,*,*,*,
|
127 |
|
|
address,req_id,tag,first_be,4'b0,*,*,*,*,data);
|
128 |
|
|
tlp_packet.build_packet("nonposted");
|
129 |
|
|
printf ("header %0h \n",tlp_packet.header);
|
130 |
|
|
if (!semaphore_get(WAIT,my_semaphore,1))
|
131 |
|
|
error ("Semaphore_get returned 0\n");
|
132 |
|
|
//sequence id
|
133 |
|
|
printf("%0h put into mailbox\n",{2'b01,packet_array[0][15:8],STP_s});
|
134 |
|
|
mailbox_put (rx_data_mailbox, {2'b01,packet_array[0][7:0],STP_s});
|
135 |
|
|
printf("%0h put into mailbox\n",{2'b00,packet_array[1][7:0],packet_array[0][7:0]});
|
136 |
|
|
mailbox_put (rx_data_mailbox, {2'b00,packet_array[1][7:0],packet_array[0][15:8]});
|
137 |
|
|
//loop for sending out packet
|
138 |
|
|
for (index=1;index<4;index++) {
|
139 |
|
|
printf("%0h put into mailbox index = %0d\n",{2'b00,packet_array[index][23:8]},index);
|
140 |
|
|
mailbox_put(rx_data_mailbox, {2'b00,packet_array[index][23:8]});
|
141 |
|
|
printf("%0h put into mailbox index+1 = %0d\n",{2'b00,packet_array[index+1][7:0],packet_array[index][31:24]},index+1);
|
142 |
|
|
mailbox_put(rx_data_mailbox, {2'b00,packet_array[index+1][7:0],packet_array[index][31:24]});
|
143 |
|
|
}
|
144 |
|
|
printf("%0h put into mailbox index = %0d\n",{2'b00,packet_array[index][23:8]},index);
|
145 |
|
|
mailbox_put(rx_data_mailbox, {2'b00,packet_array[index][23:8]});
|
146 |
|
|
printf("%0h put into mailbox index = %0d\n",{2'b00,tlp_packet.lcrc[7:0],packet_array[index][31:24]},index);
|
147 |
|
|
mailbox_put(rx_data_mailbox, {2'b00,tlp_packet.lcrc[7:0],packet_array[index][31:24]});
|
148 |
|
|
printf("%0h put into mailbox index = %0d\n",{2'b00,tlp_packet.lcrc[23:8]},index);
|
149 |
|
|
mailbox_put(rx_data_mailbox, {2'b00,tlp_packet.lcrc[23:8]});
|
150 |
|
|
printf("%0h put into mailbox\n",{2'b10,END_s,tlp_packet.lcrc[31:24]});
|
151 |
|
|
mailbox_put(rx_data_mailbox, {2'b10,END_s,tlp_packet.lcrc[31:24]});
|
152 |
|
|
semaphore_put (my_semaphore, 1);
|
153 |
5 |
cmagleby |
ret = mailbox_get (WAIT,tlp_header_mailbox,return_pkt,CHECK);
|
154 |
|
|
if (ret <= 0)
|
155 |
|
|
error ("mailbox_get returned %0d\n",ret);
|
156 |
|
|
|
157 |
|
|
if ((return_pkt[4:0] == 4'ha) && (return_pkt[5] == 1'b0)) {
|
158 |
|
|
if (return_pkt[55:53] == 3'b000) printf("comp without data returned header %0h tag %0h and comp_stat of successful completion\n",return_pkt,tag);
|
159 |
|
|
else if (return_pkt[55:53] == 3'b001) printf("comp without data returned header %0h tag %0hand comp_stat of unsupported response\n",return_pkt,tag);
|
160 |
|
|
else if (return_pkt[55:53] == 3'b010) printf("comp without data returned header %0h tag %0hand comp_stat of completer abort\n",return_pkt,tag);
|
161 |
|
|
}
|
162 |
2 |
cmagleby |
}
|
163 |
|
|
|
164 |
|
|
|
165 |
|
|
task memwr (bit [63:0] address,
|
166 |
|
|
bit [9:0] length,
|
167 |
|
|
bit [3:0] first_be,
|
168 |
|
|
bit [3:0] last_be,
|
169 |
|
|
bit [15:0] req_id,
|
170 |
|
|
bit [7:0] tag){
|
171 |
|
|
integer index;
|
172 |
|
|
bit seq_header;
|
173 |
|
|
integer total_length;
|
174 |
|
|
bit[1:0] fmt;
|
175 |
|
|
integer hdr_dw;
|
176 |
|
|
fmt = |address[63:32] == 1 ? 2'b11 : 2'b10;
|
177 |
|
|
hdr_dw = |address[63:32] == 1 ? 4 : 3;
|
178 |
|
|
total_length = hdr_dw + length; //add td when ready
|
179 |
|
|
//bus num,device num,function num,ext reg reg_num;
|
180 |
|
|
tlp_packet = new(sequence_id,5'b00000,fmt,length,*,*,*,*,
|
181 |
5 |
cmagleby |
address,req_id,tag,first_be,last_be,*,*,*,*,*);
|
182 |
2 |
cmagleby |
tlp_packet.build_packet("nonposted");
|
183 |
|
|
printf ("header %0h \n",tlp_packet.header);
|
184 |
|
|
if (!semaphore_get(WAIT,my_semaphore,1))
|
185 |
|
|
error ("Semaphore_get returned 0\n");
|
186 |
|
|
//sequence id
|
187 |
|
|
printf("%0h put into mailbox\n",{2'b01,packet_array[0][15:8],STP_s});
|
188 |
|
|
mailbox_put (rx_data_mailbox, {2'b01,packet_array[0][7:0],STP_s});
|
189 |
|
|
printf("%0h put into mailbox\n",{2'b00,packet_array[1][7:0],packet_array[0][7:0]});
|
190 |
|
|
mailbox_put (rx_data_mailbox, {2'b00,packet_array[1][7:0],packet_array[0][15:8]});
|
191 |
|
|
//loop for sending out packet
|
192 |
|
|
for (index=1;index
|
193 |
|
|
printf("%0h put into mailbox index = %0d\n",{2'b00,packet_array[index][23:8]},index);
|
194 |
|
|
mailbox_put(rx_data_mailbox, {2'b00,packet_array[index][23:8]});
|
195 |
|
|
printf("%0h put into mailbox index+1 = %0d\n",{2'b00,packet_array[index+1][7:0],packet_array[index][31:24]},index+1);
|
196 |
|
|
mailbox_put(rx_data_mailbox, {2'b00,packet_array[index+1][7:0],packet_array[index][31:24]});
|
197 |
|
|
}
|
198 |
|
|
printf("%0h put into mailbox index = %0d\n",{2'b00,packet_array[index][23:8]},index);
|
199 |
|
|
mailbox_put(rx_data_mailbox, {2'b00,packet_array[index][23:8]});
|
200 |
|
|
printf("%0h put into mailbox index = %0d\n",{2'b00,tlp_packet.lcrc[7:0],packet_array[index][31:24]},index);
|
201 |
|
|
mailbox_put(rx_data_mailbox, {2'b00,tlp_packet.lcrc[7:0],packet_array[index][31:24]});
|
202 |
|
|
printf("%0h put into mailbox index = %0d\n",{2'b00,tlp_packet.lcrc[23:8]},index);
|
203 |
|
|
mailbox_put(rx_data_mailbox, {2'b00,tlp_packet.lcrc[23:8]});
|
204 |
|
|
printf("%0h put into mailbox\n",{2'b10,END_s,tlp_packet.lcrc[31:24]});
|
205 |
|
|
mailbox_put(rx_data_mailbox, {2'b10,END_s,tlp_packet.lcrc[31:24]});
|
206 |
|
|
|
207 |
|
|
semaphore_put (my_semaphore, 1);
|
208 |
|
|
}
|
209 |
|
|
|
210 |
|
|
task memrd (bit [63:0] address,
|
211 |
|
|
bit [9:0] length,
|
212 |
|
|
bit [3:0] first_be,
|
213 |
|
|
bit [3:0] last_be,
|
214 |
|
|
bit [15:0] req_id,
|
215 |
5 |
cmagleby |
bit [7:0] tag){integer index;
|
216 |
|
|
bit seq_header;
|
217 |
|
|
integer total_length;
|
218 |
|
|
bit[1:0] fmt;
|
219 |
|
|
integer hdr_dw;
|
220 |
|
|
integer ret;
|
221 |
|
|
bit [127:0] return_pkt;
|
222 |
|
|
bit [31:0] return_data;
|
223 |
|
|
fmt = |address[63:32] == 1 ? 2'b01 : 2'b00;
|
224 |
|
|
hdr_dw = |address[63:32] == 1 ? 4 : 3;
|
225 |
|
|
total_length = hdr_dw; //add td when ready
|
226 |
|
|
//bus num,device num,function num,ext reg reg_num;
|
227 |
|
|
tlp_packet = new(sequence_id,5'b00000,fmt,length,*,*,*,*,
|
228 |
|
|
address,req_id,tag,first_be,last_be,*,*,*,*,*);
|
229 |
|
|
tlp_packet.build_packet("nonposted");
|
230 |
|
|
printf ("header %0h \n",tlp_packet.header);
|
231 |
|
|
if (!semaphore_get(WAIT,my_semaphore,1))
|
232 |
|
|
error ("Semaphore_get returned 0\n");
|
233 |
|
|
//sequence id
|
234 |
|
|
printf("%0h put into mailbox\n",{2'b01,packet_array[0][15:8],STP_s});
|
235 |
|
|
mailbox_put (rx_data_mailbox, {2'b01,packet_array[0][7:0],STP_s});
|
236 |
|
|
printf("%0h put into mailbox\n",{2'b00,packet_array[1][7:0],packet_array[0][7:0]});
|
237 |
|
|
mailbox_put (rx_data_mailbox, {2'b00,packet_array[1][7:0],packet_array[0][15:8]});
|
238 |
|
|
//loop for sending out packet
|
239 |
|
|
for (index=1;index
|
240 |
|
|
printf("%0h put into mailbox index = %0d\n",{2'b00,packet_array[index][23:8]},index);
|
241 |
|
|
mailbox_put(rx_data_mailbox, {2'b00,packet_array[index][23:8]});
|
242 |
|
|
printf("%0h put into mailbox index+1 = %0d\n",{2'b00,packet_array[index+1][7:0],packet_array[index][31:24]},index+1);
|
243 |
|
|
mailbox_put(rx_data_mailbox, {2'b00,packet_array[index+1][7:0],packet_array[index][31:24]});
|
244 |
|
|
}
|
245 |
|
|
printf("%0h put into mailbox index = %0d\n",{2'b00,packet_array[index][23:8]},index);
|
246 |
|
|
mailbox_put(rx_data_mailbox, {2'b00,packet_array[index][23:8]});
|
247 |
|
|
printf("%0h put into mailbox index = %0d\n",{2'b00,tlp_packet.lcrc[7:0],packet_array[index][31:24]},index);
|
248 |
|
|
mailbox_put(rx_data_mailbox, {2'b00,tlp_packet.lcrc[7:0],packet_array[index][31:24]});
|
249 |
|
|
printf("%0h put into mailbox index = %0d\n",{2'b00,tlp_packet.lcrc[23:8]},index);
|
250 |
|
|
mailbox_put(rx_data_mailbox, {2'b00,tlp_packet.lcrc[23:8]});
|
251 |
|
|
printf("%0h put into mailbox\n",{2'b10,END_s,tlp_packet.lcrc[31:24]});
|
252 |
|
|
mailbox_put(rx_data_mailbox, {2'b10,END_s,tlp_packet.lcrc[31:24]});
|
253 |
|
|
|
254 |
|
|
semaphore_put (my_semaphore, 1);
|
255 |
|
|
|
256 |
|
|
ret = mailbox_get (WAIT,tlp_header_mailbox,return_pkt,CHECK);
|
257 |
|
|
if (ret <= 0)
|
258 |
|
|
error ("mailbox_get returned %0d\n",ret);
|
259 |
|
|
if (return_pkt[4:0] == 4'ha) {
|
260 |
|
|
if (return_pkt[6] == 1'b1) {
|
261 |
|
|
for (index = 0;index<{return_pkt[17:16],return_pkt[31:24]};index++){
|
262 |
|
|
ret = mailbox_get (WAIT,tlp_data_mailbox,return_data,CHECK);
|
263 |
|
|
if (ret <= 0)
|
264 |
|
|
error ("mailbox_get returned %0d\n",ret);
|
265 |
|
|
printf("returned header %0h and data %0h for tag %0h\n",return_pkt,return_data,tag);
|
266 |
|
|
}
|
267 |
|
|
}
|
268 |
|
|
}
|
269 |
|
|
else if ((return_pkt[4:0] == 4'ha) && (return_pkt[5] == 1'b0)) {
|
270 |
|
|
printf("comp without data returned header %0h and comp_stat of %0b\n",return_pkt,return_pkt[55:53]);
|
271 |
|
|
}
|
272 |
2 |
cmagleby |
}
|
273 |
|
|
|
274 |
|
|
|
275 |
|
|
|
276 |
|
|
|
277 |
|
|
|