1 |
103 |
mihad |
#include <sys/types.h>
|
2 |
|
|
#include <sys/stat.h>
|
3 |
|
|
#include <fcntl.h>
|
4 |
|
|
#include <malloc.h>
|
5 |
|
|
#include <unistd.h>
|
6 |
|
|
#include <stdio.h>
|
7 |
|
|
#include <spartan_kint.h>
|
8 |
|
|
#include <sys/ioctl.h>
|
9 |
|
|
#include <pci_bridge32_test.h>
|
10 |
|
|
#include <string.h>
|
11 |
|
|
#include <stdlib.h>
|
12 |
|
|
|
13 |
|
|
#define WALKING_ONES 0
|
14 |
|
|
#define WALKING_ZEROS 1
|
15 |
|
|
#define INVERTED_ADDRESS 2
|
16 |
|
|
#define ALL_ZEROS 3
|
17 |
|
|
#define ALL_ONES 4
|
18 |
|
|
#define PSEUDO_RANDOM 5
|
19 |
|
|
|
20 |
|
|
#define MAX_PATTERN 5
|
21 |
|
|
|
22 |
|
|
unsigned int guint_random_seed = 1 ;
|
23 |
|
|
|
24 |
|
|
void prompt(void) ;
|
25 |
|
|
int execute_command(char *command) ;
|
26 |
|
|
void cmd_help (int command_num) ;
|
27 |
|
|
int cmd_select_region (char *command_str) ;
|
28 |
|
|
int sp_set_region(unsigned char region) ;
|
29 |
|
|
int sp_write (unsigned int value) ;
|
30 |
|
|
int sp_read(unsigned int *value) ;
|
31 |
|
|
int cmd_write (char *command_str) ;
|
32 |
|
|
int cmd_read (char *command_str) ;
|
33 |
|
|
int cmd_burst_read(char *command_str) ;
|
34 |
|
|
int cmd_target_write(char *command_str) ;
|
35 |
|
|
int cmd_master_do(char *command_str, unsigned int opcode) ;
|
36 |
|
|
#define cmd_master_write(command_str) cmd_master_do(command_str, 0x00000001)
|
37 |
|
|
#define cmd_master_read(command_str) cmd_master_do(command_str, 0x00000000)
|
38 |
|
|
int cmd_master_fill(char *command_str) ;
|
39 |
|
|
int cmd_target_slide_window_test (void) ;
|
40 |
|
|
int cmd_master_slide_window_test (void) ;
|
41 |
|
|
int cmd_enable_wb_image (char *command_str) ;
|
42 |
|
|
void master_buffer_fill(unsigned char pattern) ;
|
43 |
|
|
int cmd_master_chk(char *command_str) ;
|
44 |
|
|
int cmd_target_chk(char *command_str) ;
|
45 |
|
|
int sp_target_write(unsigned int num_of_transactions, unsigned int transaction_size, unsigned int starting_offset, unsigned char pattern) ;
|
46 |
|
|
int sp_target_check_data(unsigned int num_of_transactions, unsigned int transaction_size, unsigned int starting_offset, unsigned char pattern) ;
|
47 |
|
|
int sp_master_check_data(unsigned int size, unsigned int offset, unsigned char pattern) ;
|
48 |
|
|
int sp_master_do(unsigned int num_of_transactions, unsigned int transaction_size, unsigned int starting_offset, unsigned int opcode) ;
|
49 |
|
|
#define sp_master_write(num_of_transactions, transaction_size, starting_offset) sp_master_do(num_of_transactions, transaction_size, starting_offset, 0x00000001)
|
50 |
|
|
#define sp_master_read(num_of_transactions, transaction_size, starting_offset) sp_master_do(num_of_transactions, transaction_size, starting_offset, 0x00000000)
|
51 |
|
|
int sp_get_pci_region (void) ;
|
52 |
|
|
unsigned int sp_get_first_val(unsigned char pattern) ;
|
53 |
|
|
unsigned int sp_get_next_val(unsigned int cur_val, unsigned char pattern) ;
|
54 |
|
|
|
55 |
|
|
int spartan_fd ;
|
56 |
|
|
|
57 |
|
|
char unused_str [MAX_COMMAND_LEN + 1] ;
|
58 |
|
|
|
59 |
|
|
int main(int argc, char* argv[])
|
60 |
|
|
{
|
61 |
|
|
FILE* cmd_file_fd ;
|
62 |
|
|
|
63 |
|
|
unsigned short use_cmd_file ;
|
64 |
|
|
|
65 |
|
|
char current_command [MAX_COMMAND_LEN + 2] ;
|
66 |
|
|
|
67 |
|
|
spartan_fd = open("/dev/spartan", O_RDWR) ;
|
68 |
|
|
|
69 |
|
|
if (spartan_fd <= 0) {
|
70 |
|
|
printf("\nSpartan device not found!\n") ;
|
71 |
|
|
printf("\nThe /dev/spartan device must exist with appropriate module loaded!\n") ;
|
72 |
|
|
return spartan_fd ;
|
73 |
|
|
}
|
74 |
|
|
|
75 |
|
|
printf("\nPCI Bridge Test Application\n") ;
|
76 |
|
|
printf("\nType help for list of available commands\n\n");
|
77 |
|
|
prompt() ;
|
78 |
|
|
|
79 |
|
|
use_cmd_file = 0 ;
|
80 |
|
|
|
81 |
|
|
if (argc > 1) {
|
82 |
|
|
|
83 |
|
|
// command line argument is input file name - open the file
|
84 |
|
|
cmd_file_fd = fopen(argv[1], "r") ;
|
85 |
|
|
if (cmd_file_fd <= 0) {
|
86 |
|
|
printf("\nCannot open file %s in read mode!\n", argv[1]) ;
|
87 |
|
|
}
|
88 |
|
|
else
|
89 |
|
|
use_cmd_file = 1 ;
|
90 |
|
|
}
|
91 |
|
|
|
92 |
|
|
while (1) {
|
93 |
|
|
|
94 |
|
|
if (use_cmd_file)
|
95 |
|
|
if (fgets(current_command, MAX_COMMAND_LEN + 2, cmd_file_fd) == NULL)
|
96 |
|
|
use_cmd_file = 0 ;
|
97 |
|
|
else
|
98 |
|
|
printf ("%s", current_command) ;
|
99 |
|
|
else
|
100 |
|
|
fgets(current_command, MAX_COMMAND_LEN + 2, stdin) ;
|
101 |
|
|
|
102 |
|
|
if (execute_command(current_command)) {
|
103 |
|
|
return 0 ;
|
104 |
|
|
}
|
105 |
|
|
prompt() ;
|
106 |
|
|
}
|
107 |
|
|
|
108 |
|
|
printf("\n") ;
|
109 |
|
|
return 0 ;
|
110 |
|
|
}
|
111 |
|
|
|
112 |
|
|
void prompt (void) {
|
113 |
|
|
printf("\npci> ") ;
|
114 |
|
|
}
|
115 |
|
|
|
116 |
|
|
int execute_command (char *command) {
|
117 |
|
|
int i = 0 ;
|
118 |
|
|
char command_wo_param [MAX_COMMAND_LEN + 1] ;
|
119 |
|
|
int result ;
|
120 |
|
|
|
121 |
|
|
if (!(strcmp("\n", command))) return 0 ;
|
122 |
|
|
|
123 |
|
|
result = sscanf(command, "%s", command_wo_param) ;
|
124 |
|
|
|
125 |
|
|
if (result == EOF) return 0 ;
|
126 |
|
|
|
127 |
|
|
if (result != 1) return 0 ;
|
128 |
|
|
|
129 |
|
|
while ((i < NUM_OF_COMMANDS) & (strcmp(GET_CMD(i), command_wo_param))) {
|
130 |
|
|
++i ;
|
131 |
|
|
}
|
132 |
|
|
|
133 |
|
|
switch (i) {
|
134 |
|
|
case 0 : cmd_help(-1); break ;
|
135 |
|
|
case 1 : return 1 ;
|
136 |
|
|
case 2 : if (cmd_select_region (command)) cmd_help( 2) ; break ;
|
137 |
|
|
case 3 : if (cmd_write (command)) cmd_help( 3) ; break ;
|
138 |
|
|
case 4 : if (cmd_read (command)) cmd_help( 4) ; break ;
|
139 |
|
|
case 5 : if (cmd_target_write (command)) cmd_help( 5) ; break ;
|
140 |
|
|
case 6 : if (cmd_burst_read (command)) cmd_help( 6) ; break ;
|
141 |
|
|
case 7 : if (cmd_master_read (command)) cmd_help( 7) ; break ;
|
142 |
|
|
case 8 : if (cmd_master_fill (command)) cmd_help( 8) ; break ;
|
143 |
|
|
case 9 : if (cmd_master_write (command)) cmd_help( 9) ; break ;
|
144 |
|
|
case 10: if (cmd_master_chk (command)) cmd_help(10) ; break ;
|
145 |
|
|
case 11: if (cmd_target_chk (command)) cmd_help(11) ; break ;
|
146 |
|
|
case 12: if (cmd_target_slide_window_test()) cmd_help(12) ; break ;
|
147 |
|
|
case 13: if (cmd_enable_wb_image (command)) cmd_help(13) ; break ;
|
148 |
|
|
case 14: if (cmd_master_slide_window_test()) cmd_help(14) ; break ;
|
149 |
|
|
default: printf("\n\nError: Unknown command!\n\n") ;
|
150 |
|
|
}
|
151 |
|
|
|
152 |
|
|
return 0 ;
|
153 |
|
|
}
|
154 |
|
|
|
155 |
|
|
void cmd_help (int command_num) {
|
156 |
|
|
int i, start, end ;
|
157 |
|
|
|
158 |
|
|
if (command_num >= 0) start = end = command_num ;
|
159 |
|
|
else { start = 0 ; end = NUM_OF_COMMANDS - 1; }
|
160 |
|
|
|
161 |
|
|
for (i = start ; i <= end ; ++i) {
|
162 |
|
|
printf("%s %s\n: %s\n\n", GET_CMD(i), GET_CMD_PARMS(i), GET_CMD_DES(i)) ;
|
163 |
|
|
}
|
164 |
|
|
}
|
165 |
|
|
|
166 |
|
|
int cmd_select_region (char *command_str) {
|
167 |
|
|
int result ;
|
168 |
|
|
unsigned char sel_region ;
|
169 |
|
|
unsigned int base ;
|
170 |
|
|
unsigned int base_size ;
|
171 |
|
|
|
172 |
|
|
result = sscanf(command_str, "%s %u", unused_str, &sel_region) ;
|
173 |
|
|
|
174 |
|
|
if (result != 2) {
|
175 |
|
|
printf("\nError: Wrong command, parameter or number of parameters!\n") ;
|
176 |
|
|
return -1 ;
|
177 |
|
|
}
|
178 |
|
|
|
179 |
|
|
result = sp_set_region (sel_region) ;
|
180 |
|
|
|
181 |
|
|
if (result) return 0 ;
|
182 |
|
|
|
183 |
|
|
result = ioctl(spartan_fd, SPARTAN_IOC_CURBASE, &base) ;
|
184 |
|
|
printf("\nNote: Selected region's base address 0x%x\n", base) ;
|
185 |
|
|
|
186 |
|
|
result = ioctl(spartan_fd, SPARTAN_IOC_CURBASESIZE, &base_size) ;
|
187 |
|
|
printf("\nNote: Selected region's size %d\n", base_size) ;
|
188 |
|
|
|
189 |
|
|
return 0 ;
|
190 |
|
|
}
|
191 |
|
|
|
192 |
|
|
int cmd_enable_wb_image (char *command_str) {
|
193 |
|
|
|
194 |
|
|
// store current selected pci image number
|
195 |
|
|
int current_pci_region = sp_get_pci_region() ;
|
196 |
|
|
unsigned int region ;
|
197 |
|
|
unsigned int i ;
|
198 |
|
|
unsigned int base ;
|
199 |
|
|
|
200 |
|
|
|
201 |
|
|
// check the parameter passed with the command
|
202 |
|
|
if (sscanf(command_str, "%s %d", unused_str, ®ion) != 2) {
|
203 |
|
|
printf("\nError: Invalid command, parameter or number of parameters!\n") ;
|
204 |
|
|
return -1;
|
205 |
|
|
}
|
206 |
|
|
|
207 |
|
|
if ((region > 5) | (!region)) {
|
208 |
|
|
printf("\nError: Invalid WB image selected!\n") ;
|
209 |
|
|
return -1 ;
|
210 |
|
|
}
|
211 |
|
|
|
212 |
|
|
// activate region 0 - configuration space
|
213 |
|
|
if (sp_set_region(0)) {
|
214 |
|
|
printf("\nError: Failed to activate pci region 0 - configuration image!\n") ;
|
215 |
|
|
return 0 ;
|
216 |
|
|
}
|
217 |
|
|
|
218 |
|
|
// first disable all wb images!
|
219 |
|
|
for ( i = 0x18C ; i <= 0x1CC ; i = i + 0x10 ) {
|
220 |
|
|
if (sp_seek(i)) {
|
221 |
|
|
printf("\nError: Failed to write one of the WB address mask registers!\n") ;
|
222 |
|
|
if (current_pci_region >= 0) sp_set_region(current_pci_region) ;
|
223 |
|
|
return 0 ;
|
224 |
|
|
}
|
225 |
|
|
|
226 |
|
|
if (sp_write(0x00000000)) {
|
227 |
|
|
printf("\nError: Failed to write one of the WB address mask registers!.\n") ;
|
228 |
|
|
if (current_pci_region >= 0) sp_set_region(current_pci_region) ;
|
229 |
|
|
return 0 ;
|
230 |
|
|
}
|
231 |
|
|
}
|
232 |
|
|
|
233 |
|
|
// get base address of the system memory buffer
|
234 |
|
|
ioctl(spartan_fd, SPARTAN_IOC_VIDEO_BASE, &base) ;
|
235 |
|
|
|
236 |
|
|
i = 0x178 + 0x10 * region ;
|
237 |
|
|
|
238 |
|
|
if (sp_seek(i)) {
|
239 |
|
|
printf("\nError: Failed to write selected WB base address register!\n") ;
|
240 |
|
|
if (current_pci_region >= 0) sp_set_region(current_pci_region) ;
|
241 |
|
|
return 0 ;
|
242 |
|
|
}
|
243 |
|
|
|
244 |
|
|
if (sp_write(base)) {
|
245 |
|
|
printf("\nError: Failed to write WB base address register!.\n") ;
|
246 |
|
|
if (current_pci_region >= 0) sp_set_region(current_pci_region) ;
|
247 |
|
|
return 0 ;
|
248 |
|
|
}
|
249 |
|
|
|
250 |
|
|
// write address mask register with all ones.
|
251 |
|
|
i = 0x17C + 0x10 * region ;
|
252 |
|
|
|
253 |
|
|
if (sp_seek(i)) {
|
254 |
|
|
printf("\nError: Failed to write selected WB address mask register!\n") ;
|
255 |
|
|
if (current_pci_region >= 0) sp_set_region(current_pci_region) ;
|
256 |
|
|
return 0 ;
|
257 |
|
|
}
|
258 |
|
|
|
259 |
|
|
if (sp_write(0xFFFFFFFF)) {
|
260 |
|
|
printf("\nError: Failed to write selected WB address mask register!.\n") ;
|
261 |
|
|
if (current_pci_region >= 0) sp_set_region(current_pci_region) ;
|
262 |
|
|
return 0 ;
|
263 |
|
|
}
|
264 |
|
|
|
265 |
|
|
if (current_pci_region >= 0) sp_set_region(current_pci_region) ;
|
266 |
|
|
|
267 |
|
|
return 0 ;
|
268 |
|
|
}
|
269 |
|
|
|
270 |
|
|
int sp_set_region(unsigned char region) {
|
271 |
|
|
int result = ioctl(spartan_fd, SPARTAN_IOC_NUMOFRES) ;
|
272 |
|
|
|
273 |
|
|
if (result <= 0) {
|
274 |
|
|
printf("\nError: Error accessing device!\n") ;
|
275 |
|
|
return -1 ;
|
276 |
|
|
}
|
277 |
|
|
|
278 |
|
|
if (region > 5 ) {
|
279 |
|
|
printf("\nError: Invalid region!\n") ;
|
280 |
|
|
return -1 ;
|
281 |
|
|
}
|
282 |
|
|
|
283 |
|
|
if (result <= region) {
|
284 |
|
|
printf("\nError: You selected region %u\n", region) ;
|
285 |
|
|
printf("Driver reports only %u [0:%u] regions available!\n", result, result - 1) ;
|
286 |
|
|
return -1 ;
|
287 |
|
|
}
|
288 |
|
|
|
289 |
|
|
result = ioctl(spartan_fd, SPARTAN_IOC_CURRESSET, region + 1) ;
|
290 |
|
|
|
291 |
|
|
if (result) {
|
292 |
|
|
printf("\nError: Driver reported failure to intialize resource %u!\n", region) ;
|
293 |
|
|
return -1;
|
294 |
|
|
}
|
295 |
|
|
|
296 |
|
|
return 0 ;
|
297 |
|
|
}
|
298 |
|
|
|
299 |
|
|
int sp_get_pci_region (void) {
|
300 |
|
|
return (ioctl(spartan_fd, SPARTAN_IOC_CURRESGET) - 1) ;
|
301 |
|
|
}
|
302 |
|
|
|
303 |
|
|
int cmd_write (char *command_str) {
|
304 |
|
|
int result ;
|
305 |
|
|
unsigned int value ;
|
306 |
|
|
unsigned int offset ;
|
307 |
|
|
|
308 |
|
|
result = sscanf(command_str, "%s %x %x", unused_str, &offset, &value) ;
|
309 |
|
|
if (result != 3) {
|
310 |
|
|
printf("\nError: Invalid command, parameter or number of parameters!\n") ;
|
311 |
|
|
return -1;
|
312 |
|
|
}
|
313 |
|
|
|
314 |
|
|
if (sp_seek(offset)) {
|
315 |
|
|
printf("\nError: Write failed. Couldn't write to offset 0x%x!\n", offset) ;
|
316 |
|
|
return 0 ;
|
317 |
|
|
}
|
318 |
|
|
|
319 |
|
|
if (sp_write(value)) {
|
320 |
|
|
printf("\nError: Write failed.\n") ;
|
321 |
|
|
return 0 ;
|
322 |
|
|
}
|
323 |
|
|
|
324 |
|
|
if (sp_seek(offset)) {
|
325 |
|
|
printf("\nError: Read-back failed. Couldn't read from offset 0x%x!\n", offset) ;
|
326 |
|
|
return 0 ;
|
327 |
|
|
}
|
328 |
|
|
|
329 |
|
|
if (sp_read(&offset)) {
|
330 |
|
|
printf("\nError: Read-back failed.\n") ;
|
331 |
|
|
return 0;
|
332 |
|
|
}
|
333 |
|
|
|
334 |
|
|
printf("\n0x%08x\n", offset) ;
|
335 |
|
|
|
336 |
|
|
return 0 ;
|
337 |
|
|
}
|
338 |
|
|
|
339 |
|
|
int cmd_read (char *command_str) {
|
340 |
|
|
int result ;
|
341 |
|
|
unsigned int value ;
|
342 |
|
|
unsigned int offset ;
|
343 |
|
|
|
344 |
|
|
result = sscanf(command_str, "%s %x", unused_str, &offset) ;
|
345 |
|
|
if (result != 2) {
|
346 |
|
|
printf("\nError: Invalid command, parameter or number of parameters!\n") ;
|
347 |
|
|
return -1 ;
|
348 |
|
|
}
|
349 |
|
|
|
350 |
|
|
if (sp_seek(offset)) {
|
351 |
|
|
printf("\nError: Read failed. Couldn't read from offset 0x%x!\n", offset) ;
|
352 |
|
|
return 0 ;
|
353 |
|
|
}
|
354 |
|
|
|
355 |
|
|
if (sp_read(&value)) {
|
356 |
|
|
printf("\nError: Read failed.\n") ;
|
357 |
|
|
return 0 ;
|
358 |
|
|
}
|
359 |
|
|
|
360 |
|
|
printf("\n0x%08x\n", value) ;
|
361 |
|
|
|
362 |
|
|
return 0 ;
|
363 |
|
|
}
|
364 |
|
|
|
365 |
|
|
int sp_write (unsigned int value) {
|
366 |
|
|
int result = write(spartan_fd, &value, 4) ;
|
367 |
|
|
if (result != 4)
|
368 |
|
|
return -1 ;
|
369 |
|
|
else
|
370 |
|
|
return 0 ;
|
371 |
|
|
}
|
372 |
|
|
|
373 |
|
|
int sp_seek (unsigned int offset) {
|
374 |
|
|
int result = lseek(spartan_fd, offset, SEEK_SET) ;
|
375 |
|
|
if (result != offset)
|
376 |
|
|
return -1 ;
|
377 |
|
|
else
|
378 |
|
|
return 0 ;
|
379 |
|
|
}
|
380 |
|
|
|
381 |
|
|
int sp_read (unsigned int *value) {
|
382 |
|
|
|
383 |
|
|
int result = read(spartan_fd, (char *) value, 4) ;
|
384 |
|
|
|
385 |
|
|
if (result != 4)
|
386 |
|
|
return -1 ;
|
387 |
|
|
else
|
388 |
|
|
return 0 ;
|
389 |
|
|
}
|
390 |
|
|
|
391 |
|
|
int sp_target_write(unsigned int num_of_transactions, unsigned int transaction_size, unsigned int starting_offset, unsigned char pattern) {
|
392 |
|
|
unsigned int buffer[SPARTAN_BOARD_BUFFER_SIZE] ;
|
393 |
|
|
|
394 |
|
|
int i ;
|
395 |
|
|
|
396 |
|
|
buffer[0] = sp_get_first_val(pattern) ;
|
397 |
|
|
|
398 |
|
|
for (i = 1; i < SPARTAN_BOARD_BUFFER_SIZE ; i++) {
|
399 |
|
|
buffer[i] = sp_get_next_val(buffer[i-1], pattern) ;
|
400 |
|
|
}
|
401 |
|
|
|
402 |
|
|
if (sp_seek(starting_offset*4)) {
|
403 |
|
|
printf("\nError: Seek failed!\n") ;
|
404 |
|
|
return -1 ;
|
405 |
|
|
}
|
406 |
|
|
|
407 |
|
|
for (i = 0 ; i < num_of_transactions ; ++i) {
|
408 |
|
|
if ((write(spartan_fd, buffer + (i*transaction_size) + starting_offset, transaction_size*4)) != (transaction_size*4)) {
|
409 |
|
|
printf("\nError: Write test failed. Transaction number %d couldn't finish %d writes through target!\n", i, transaction_size) ;
|
410 |
|
|
return -1 ;
|
411 |
|
|
}
|
412 |
|
|
}
|
413 |
|
|
|
414 |
|
|
return 0 ;
|
415 |
|
|
}
|
416 |
|
|
|
417 |
|
|
int sp_target_check_data(unsigned int num_of_transactions, unsigned int transaction_size, unsigned int starting_offset, unsigned char pattern) {
|
418 |
|
|
unsigned int buffer[SPARTAN_BOARD_BUFFER_SIZE] ;
|
419 |
|
|
unsigned int expected_value ;
|
420 |
|
|
|
421 |
|
|
int i ;
|
422 |
|
|
int j ;
|
423 |
|
|
|
424 |
|
|
expected_value = sp_get_first_val(pattern) ;
|
425 |
|
|
|
426 |
|
|
for (i = 1 ; i <= starting_offset ; ++i) {
|
427 |
|
|
expected_value = sp_get_next_val(expected_value, pattern) ;
|
428 |
|
|
}
|
429 |
|
|
|
430 |
|
|
if (sp_seek(starting_offset * 4)) {
|
431 |
|
|
printf("\nError: Seek failed!\n") ;
|
432 |
|
|
return -1 ;
|
433 |
|
|
}
|
434 |
|
|
|
435 |
|
|
for (i = 0 ; i < num_of_transactions ; ++i) {
|
436 |
|
|
|
437 |
|
|
if ((read(spartan_fd, buffer, transaction_size*4)) != (transaction_size*4)) {
|
438 |
|
|
printf("\nError: Check data failed. Transaction number %d couldn't finish %d reads through target!\n", i, transaction_size) ;
|
439 |
|
|
return -1 ;
|
440 |
|
|
}
|
441 |
|
|
|
442 |
|
|
for (j = 0 ; j < transaction_size ; ++j) {
|
443 |
|
|
if ((*(buffer + j)) != (expected_value)) {
|
444 |
|
|
printf("\nError: Value on offset 0x%x not as expected!\n", ((i*transaction_size*4) + (j * 4) + starting_offset * 4)) ;
|
445 |
|
|
printf("\nExpected value: 0x%x\nActual value: 0x%x\n", expected_value, (*(buffer + j))) ;
|
446 |
|
|
return 0 ;
|
447 |
|
|
}
|
448 |
|
|
|
449 |
|
|
expected_value = sp_get_next_val(expected_value, pattern) ;
|
450 |
|
|
}
|
451 |
|
|
}
|
452 |
|
|
return 0 ;
|
453 |
|
|
}
|
454 |
|
|
|
455 |
|
|
unsigned int sp_get_first_val(unsigned char pattern) {
|
456 |
|
|
unsigned int base ;
|
457 |
|
|
|
458 |
|
|
switch (pattern) {
|
459 |
|
|
case WALKING_ONES : return 0x00000001 ; break ;
|
460 |
|
|
case WALKING_ZEROS : return 0xFFFFFFFE ; break ;
|
461 |
|
|
case INVERTED_ADDRESS: ioctl(spartan_fd, SPARTAN_IOC_CURBASE, &base) ; return ~base ; break ;
|
462 |
|
|
case ALL_ZEROS : return 0x00000000 ; break ;
|
463 |
|
|
case ALL_ONES : return 0xFFFFFFFF ; break ;
|
464 |
|
|
case PSEUDO_RANDOM : srand(guint_random_seed) ; return rand() ; break ;
|
465 |
|
|
}
|
466 |
|
|
}
|
467 |
|
|
|
468 |
|
|
unsigned int sp_get_next_val(unsigned int cur_val, unsigned char pattern) {
|
469 |
|
|
unsigned int new_val ;
|
470 |
|
|
switch (pattern) {
|
471 |
|
|
case WALKING_ONES : new_val = cur_val << 1 ; if (new_val == 0) return (sp_get_first_val(pattern)); else return new_val; break ;
|
472 |
|
|
case WALKING_ZEROS : new_val = ~cur_val ; new_val = new_val << 1 ; if (new_val == 0) return (sp_get_first_val(pattern)); else return ~new_val ; break ;
|
473 |
|
|
case INVERTED_ADDRESS: return ~((~cur_val) + 4) ; break ;
|
474 |
|
|
case ALL_ZEROS : return 0x00000000 ; break ;
|
475 |
|
|
case ALL_ONES : return 0xFFFFFFFF ; break ;
|
476 |
|
|
case PSEUDO_RANDOM : return rand() ; break ;
|
477 |
|
|
}
|
478 |
|
|
}
|
479 |
|
|
|
480 |
|
|
int cmd_burst_read (char *command_str) {
|
481 |
|
|
int result ;
|
482 |
|
|
unsigned int base ;
|
483 |
|
|
unsigned int buf [32] ;
|
484 |
|
|
unsigned int offset ;
|
485 |
|
|
|
486 |
|
|
result = sscanf(command_str, "%s %x", unused_str, &offset) ;
|
487 |
|
|
|
488 |
|
|
if (result != 2) {
|
489 |
|
|
printf("\nError: Wrong command, parameter or invalid number of parameters!\n") ;
|
490 |
|
|
return -1 ;
|
491 |
|
|
}
|
492 |
|
|
|
493 |
|
|
if (sp_seek(offset)) {
|
494 |
|
|
printf("\nError: Read failed. Couldn't read from offset 0x%x!\n", offset) ;
|
495 |
|
|
return 0 ;
|
496 |
|
|
}
|
497 |
|
|
|
498 |
|
|
if ((read(spartan_fd, buf, 32*4)) != (32*4)) {
|
499 |
|
|
printf("\nError: Read failed. Couldn't finish %d reads through target!\n", 32) ;
|
500 |
|
|
return 0 ;
|
501 |
|
|
}
|
502 |
|
|
|
503 |
|
|
ioctl(spartan_fd, SPARTAN_IOC_CURBASE, &base) ;
|
504 |
|
|
|
505 |
|
|
for (result = 0 ; result < 32 ; result = result + 4) {
|
506 |
|
|
printf("\n0x%08x: ", base + offset + result * 4) ;
|
507 |
|
|
printf("0x%08x 0x%08x 0x%08x 0x%08x", *(buf + result), *(buf + result + 1), *(buf + result + 2), *(buf + result + 3)) ;
|
508 |
|
|
}
|
509 |
|
|
|
510 |
|
|
printf("\n") ;
|
511 |
|
|
return 0 ;
|
512 |
|
|
}
|
513 |
|
|
|
514 |
|
|
int cmd_master_do (char *command_str, unsigned int opcode) {
|
515 |
|
|
unsigned int offset ;
|
516 |
|
|
unsigned int num_of_trans ;
|
517 |
|
|
unsigned int trans_size ;
|
518 |
|
|
|
519 |
|
|
if (sscanf(command_str, "%s %x %u %u", unused_str, &offset, &num_of_trans, &trans_size) != 4) {
|
520 |
|
|
printf("\nError: Wrong command, parameter or number of parameters!\n") ;
|
521 |
|
|
return -1 ;
|
522 |
|
|
}
|
523 |
|
|
|
524 |
|
|
if (((num_of_trans * trans_size) + (offset/4)) > SYS_BUFFER_SIZE) {
|
525 |
|
|
printf("\nError: Size of data from specifed offset crosses system buffer boundary!\n") ;
|
526 |
|
|
return 0 ;
|
527 |
|
|
}
|
528 |
|
|
|
529 |
|
|
sp_master_do(num_of_trans, trans_size, offset, opcode) ;
|
530 |
|
|
|
531 |
|
|
return 0 ;
|
532 |
|
|
}
|
533 |
|
|
|
534 |
|
|
void master_buffer_fill(unsigned char pattern) {
|
535 |
|
|
int i ;
|
536 |
|
|
unsigned int buf[SYS_BUFFER_SIZE] ;
|
537 |
|
|
|
538 |
|
|
buf[0] = sp_get_first_val(pattern) ;
|
539 |
|
|
for (i = 1 ; i < SYS_BUFFER_SIZE ; ++i) {
|
540 |
|
|
buf[i] = sp_get_next_val(buf[i-1], pattern) ;
|
541 |
|
|
}
|
542 |
|
|
|
543 |
|
|
ioctl(spartan_fd, SPARTAN_IOC_SET_VIDEO_BUFF, buf) ;
|
544 |
|
|
}
|
545 |
|
|
|
546 |
|
|
int cmd_master_fill (char *command_str) {
|
547 |
|
|
unsigned int pattern ;
|
548 |
|
|
|
549 |
|
|
if ((sscanf(command_str, "%s %u", unused_str, &pattern)) != 2) {
|
550 |
|
|
printf("\nError: Invalid command, parameter or number of parameters!\n") ;
|
551 |
|
|
return -1;
|
552 |
|
|
}
|
553 |
|
|
|
554 |
|
|
if (pattern > MAX_PATTERN) {
|
555 |
|
|
printf("\nError: Invalid pattern selected!\n") ;
|
556 |
|
|
return 0 ;
|
557 |
|
|
}
|
558 |
|
|
|
559 |
|
|
master_buffer_fill(pattern) ;
|
560 |
|
|
|
561 |
|
|
return 0 ;
|
562 |
|
|
}
|
563 |
|
|
|
564 |
|
|
int cmd_master_chk(char *command_str) {
|
565 |
|
|
unsigned int pattern ;
|
566 |
|
|
unsigned int cur_val ;
|
567 |
|
|
unsigned int offset ;
|
568 |
|
|
unsigned int size ;
|
569 |
|
|
unsigned int buf[SYS_BUFFER_SIZE] ;
|
570 |
|
|
int i ;
|
571 |
|
|
|
572 |
|
|
if ((sscanf(command_str, "%s %x %u %u", unused_str, &offset, &size, &pattern)) != 4) {
|
573 |
|
|
printf("\nError: Wrong command, parameter or number of parameters!\n") ;
|
574 |
|
|
return -1 ;
|
575 |
|
|
}
|
576 |
|
|
|
577 |
|
|
if (pattern > MAX_PATTERN) {
|
578 |
|
|
printf("\nError: Invalid pattern selected!\n") ;
|
579 |
|
|
return 0 ;
|
580 |
|
|
}
|
581 |
|
|
|
582 |
|
|
if ((offset/4 + size) > SYS_BUFFER_SIZE) {
|
583 |
|
|
printf("\nError: <size> words of data from specified offset cross system buffer boundary!\n") ;
|
584 |
|
|
return 0 ;
|
585 |
|
|
}
|
586 |
|
|
|
587 |
|
|
sp_master_check_data(size, offset, pattern) ;
|
588 |
|
|
|
589 |
|
|
return 0 ;
|
590 |
|
|
}
|
591 |
|
|
|
592 |
|
|
int sp_master_check_data(unsigned int size, unsigned int offset, unsigned char pattern) {
|
593 |
|
|
unsigned int cur_val = 0xDEADDEAD ;
|
594 |
|
|
unsigned int buf[SYS_BUFFER_SIZE] ;
|
595 |
|
|
int i ;
|
596 |
|
|
int error_detected = 0 ;
|
597 |
|
|
|
598 |
|
|
ioctl(spartan_fd, SPARTAN_IOC_GET_VIDEO_BUFF, buf) ;
|
599 |
|
|
|
600 |
|
|
i = 0 ;
|
601 |
|
|
|
602 |
|
|
for (i = 0 ; i < offset/4 ; ++i) {
|
603 |
|
|
if (i % SPARTAN_BOARD_BUFFER_SIZE)
|
604 |
|
|
cur_val = sp_get_next_val(cur_val, pattern) ;
|
605 |
|
|
else
|
606 |
|
|
cur_val = sp_get_first_val(pattern) ;
|
607 |
|
|
}
|
608 |
|
|
|
609 |
|
|
for(; i < (offset/4 + size); ++i) {
|
610 |
|
|
if (i % SPARTAN_BOARD_BUFFER_SIZE)
|
611 |
|
|
cur_val = sp_get_next_val(cur_val, pattern) ;
|
612 |
|
|
else
|
613 |
|
|
cur_val = sp_get_first_val(pattern) ;
|
614 |
|
|
|
615 |
|
|
if (cur_val != buf[i]) {
|
616 |
|
|
error_detected = 1 ;
|
617 |
|
|
printf("\nError: Data on offset 0x%x wrong!\n", i*4) ;
|
618 |
|
|
printf("Expected data 0x%08x, actual 0x%08x!\n", cur_val, buf[i]) ;
|
619 |
|
|
}
|
620 |
|
|
}
|
621 |
|
|
|
622 |
|
|
return error_detected ;
|
623 |
|
|
}
|
624 |
|
|
|
625 |
|
|
int cmd_target_write(char *command_str) {
|
626 |
|
|
int result ;
|
627 |
|
|
unsigned int num_of_trans ;
|
628 |
|
|
unsigned int trans_size ;
|
629 |
|
|
unsigned int pattern ;
|
630 |
|
|
unsigned int starting_offset ;
|
631 |
|
|
|
632 |
|
|
result = sscanf(command_str, "%s %x %u %u %u", unused_str, &starting_offset, &num_of_trans, &trans_size, &pattern ) ;
|
633 |
|
|
|
634 |
|
|
if (result != 5) {
|
635 |
|
|
printf("\nError: Wrong command, parameter or number of parameters!\n") ;
|
636 |
|
|
return -1 ;
|
637 |
|
|
}
|
638 |
|
|
|
639 |
|
|
if ((trans_size * num_of_trans) > SPARTAN_BOARD_BUFFER_SIZE) {
|
640 |
|
|
printf("\nError: Size of write transfers exceeds the buffer size!\n") ;
|
641 |
|
|
return 0 ;
|
642 |
|
|
}
|
643 |
|
|
|
644 |
|
|
if (((starting_offset/4) + (trans_size * num_of_trans)) > SPARTAN_BOARD_BUFFER_SIZE) {
|
645 |
|
|
printf("\nError: Specified number of writes from specified offset will exceede Target buffer size!\n") ;
|
646 |
|
|
return 0 ;
|
647 |
|
|
}
|
648 |
|
|
|
649 |
|
|
if (pattern > MAX_PATTERN) {
|
650 |
|
|
printf("\nError: Invalid pattern selected!\n") ;
|
651 |
|
|
return 0 ;
|
652 |
|
|
}
|
653 |
|
|
|
654 |
|
|
sp_target_write(num_of_trans, trans_size, starting_offset / 4, pattern) ;
|
655 |
|
|
|
656 |
|
|
return 0 ;
|
657 |
|
|
}
|
658 |
|
|
|
659 |
|
|
int cmd_target_chk (char *command_str) {
|
660 |
|
|
unsigned int num_of_trans ;
|
661 |
|
|
unsigned int trans_size ;
|
662 |
|
|
unsigned int pattern ;
|
663 |
|
|
unsigned int starting_offset ;
|
664 |
|
|
|
665 |
|
|
if (sscanf(command_str, "%s %x %u %u %u", unused_str, &starting_offset, &num_of_trans, &trans_size, &pattern) != 5) {
|
666 |
|
|
printf("\nError: Wrong command, parameter or number of parameters.\n") ;
|
667 |
|
|
return -1 ;
|
668 |
|
|
}
|
669 |
|
|
|
670 |
|
|
if ((trans_size * num_of_trans) > SPARTAN_BOARD_BUFFER_SIZE) {
|
671 |
|
|
printf("\nError: Size of write transfers exceeds the buffer size!\n") ;
|
672 |
|
|
return 0 ;
|
673 |
|
|
}
|
674 |
|
|
|
675 |
|
|
if (((starting_offset/4) + (trans_size * num_of_trans)) > SPARTAN_BOARD_BUFFER_SIZE) {
|
676 |
|
|
printf("\nError: Specified number of writes from specified offset will cross Target buffer boundary!\n") ;
|
677 |
|
|
return 0 ;
|
678 |
|
|
}
|
679 |
|
|
|
680 |
|
|
if (pattern > MAX_PATTERN) {
|
681 |
|
|
printf("\nError: Invalid pattern selected!\n") ;
|
682 |
|
|
return 0 ;
|
683 |
|
|
}
|
684 |
|
|
|
685 |
|
|
sp_target_check_data(num_of_trans, trans_size, starting_offset / 4, pattern) ;
|
686 |
|
|
|
687 |
|
|
return 0 ;
|
688 |
|
|
}
|
689 |
|
|
|
690 |
|
|
int cmd_target_slide_window_test (void) {
|
691 |
|
|
unsigned int i, j ;
|
692 |
|
|
unsigned int base ;
|
693 |
|
|
|
694 |
|
|
|
695 |
|
|
/* for ( i = 1 ; i <= SPARTAN_BOARD_BUFFER_SIZE ; ++i ) {
|
696 |
|
|
for ( j = 0 ; j + i <= SPARTAN_BOARD_BUFFER_SIZE ; ++j) {
|
697 |
|
|
|
698 |
|
|
guint_random_seed = guint_random_seed + 1 ;
|
699 |
|
|
|
700 |
|
|
// clear on board buffer
|
701 |
|
|
sp_target_write(1, SPARTAN_BOARD_BUFFER_SIZE, 0x0, ALL_ZEROS) ;
|
702 |
|
|
|
703 |
|
|
sp_target_write(1, i, j, PSEUDO_RANDOM) ;
|
704 |
|
|
|
705 |
|
|
// if j > 0 check the buffer before written data
|
706 |
|
|
if (j) {
|
707 |
|
|
sp_target_check_data(1, j, 0x0, ALL_ZEROS) ;
|
708 |
|
|
}
|
709 |
|
|
|
710 |
|
|
// if write didn't finish at the buffer boundary - check the data after written data
|
711 |
|
|
if ((j + i) < SPARTAN_BOARD_BUFFER_SIZE) {
|
712 |
|
|
sp_target_check_data(1, (SPARTAN_BOARD_BUFFER_SIZE - j - i), j + i, ALL_ZEROS) ;
|
713 |
|
|
}
|
714 |
|
|
|
715 |
|
|
// check the written data
|
716 |
|
|
sp_target_check_data(1, i, j, PSEUDO_RANDOM) ;
|
717 |
|
|
}
|
718 |
|
|
}
|
719 |
|
|
|
720 |
|
|
// clear the board buffer
|
721 |
|
|
sp_target_write(1, SPARTAN_BOARD_BUFFER_SIZE, 0x0, ALL_ZEROS) ;
|
722 |
|
|
|
723 |
|
|
for ( i = 1 ; i <= SPARTAN_BOARD_BUFFER_SIZE ; ++i) {
|
724 |
|
|
|
725 |
|
|
// reset random seed
|
726 |
|
|
guint_random_seed = 1 ;
|
727 |
|
|
|
728 |
|
|
for (j = 0 ; ((j + 1) * i) <= SPARTAN_BOARD_BUFFER_SIZE ; ++j) {
|
729 |
|
|
sp_target_write(1, i, (j * i), PSEUDO_RANDOM) ;
|
730 |
|
|
guint_random_seed = guint_random_seed + 1 ;
|
731 |
|
|
}
|
732 |
|
|
|
733 |
|
|
// check if there is any room left in the buffer
|
734 |
|
|
if ((j * i) != SPARTAN_BOARD_BUFFER_SIZE) {
|
735 |
|
|
// write the remainder of the data to the onboard buffer
|
736 |
|
|
sp_target_write(1, SPARTAN_BOARD_BUFFER_SIZE - (j * i), (j * i), PSEUDO_RANDOM) ;
|
737 |
|
|
}
|
738 |
|
|
|
739 |
|
|
// now check the written data - read transactions the same as write transactions
|
740 |
|
|
// reset random seed
|
741 |
|
|
guint_random_seed = 1 ;
|
742 |
|
|
|
743 |
|
|
for (j = 0 ; ((j + 1) * i) <= SPARTAN_BOARD_BUFFER_SIZE ; ++j) {
|
744 |
|
|
sp_target_check_data(1, i, (j * i), PSEUDO_RANDOM) ;
|
745 |
|
|
guint_random_seed = guint_random_seed + 1 ;
|
746 |
|
|
}
|
747 |
|
|
|
748 |
|
|
// check the end of buffer
|
749 |
|
|
if ((j * i) != SPARTAN_BOARD_BUFFER_SIZE) {
|
750 |
|
|
// check the remainder of the data in the onboard buffer
|
751 |
|
|
sp_target_check_data(1, SPARTAN_BOARD_BUFFER_SIZE - (j * i), (j * i), PSEUDO_RANDOM) ;
|
752 |
|
|
}
|
753 |
|
|
}
|
754 |
|
|
|
755 |
|
|
*/
|
756 |
|
|
|
757 |
|
|
/* // fill system buffer
|
758 |
|
|
master_buffer_fill(PSEUDO_RANDOM) ;
|
759 |
|
|
|
760 |
|
|
// instruct the master to fill the onboard buffer with reads!
|
761 |
|
|
sp_master_read(1, SPARTAN_BOARD_BUFFER_SIZE, 0x0) ;
|
762 |
|
|
|
763 |
|
|
// check the data in on board buffer
|
764 |
|
|
sp_target_check_data(1, SPARTAN_BOARD_BUFFER_SIZE, 0x0, PSEUDO_RANDOM) ;
|
765 |
|
|
|
766 |
|
|
// clear the master buffer
|
767 |
|
|
master_buffer_fill(ALL_ZEROS) ;
|
768 |
|
|
|
769 |
|
|
// perform one whole board buffer write through master, to setup all registers
|
770 |
|
|
sp_master_write(1, SPARTAN_BOARD_BUFFER_SIZE, 0x0) ;
|
771 |
|
|
|
772 |
|
|
// check the data in buffer
|
773 |
|
|
sp_master_check_data(SPARTAN_BOARD_BUFFER_SIZE, 0x0, PSEUDO_RANDOM) ;
|
774 |
|
|
|
775 |
|
|
// if system buffer is larget than board buffer, check the data in the remainder of the system buffer
|
776 |
|
|
if (SPARTAN_BOARD_BUFFER_SIZE < SYS_BUFFER_SIZE)
|
777 |
|
|
sp_master_check_data(SYS_BUFFER_SIZE - SPARTAN_BOARD_BUFFER_SIZE, SPARTAN_BOARD_BUFFER_SIZE * 4, ALL_ZEROS) ;
|
778 |
|
|
|
779 |
|
|
++guint_random_seed ;
|
780 |
|
|
|
781 |
|
|
for (i = 1 ; i <= 10000000 ; ++i) {
|
782 |
|
|
master_buffer_fill(ALL_ZEROS) ;
|
783 |
|
|
|
784 |
|
|
sp_target_write(1, SPARTAN_BOARD_BUFFER_SIZE, 0x0, PSEUDO_RANDOM) ;
|
785 |
|
|
|
786 |
|
|
// instruct master to write the data out
|
787 |
|
|
sp_seek(MASTER_TRANS_COUNT_OFFSET) ;
|
788 |
|
|
sp_write(0x1) ;
|
789 |
|
|
|
790 |
|
|
++guint_random_seed ;
|
791 |
|
|
|
792 |
|
|
// do another write through target
|
793 |
|
|
sp_target_write(1, SPARTAN_BOARD_BUFFER_SIZE, 0x0, PSEUDO_RANDOM) ;
|
794 |
|
|
|
795 |
|
|
--guint_random_seed ;
|
796 |
|
|
// check the previous data written by master
|
797 |
|
|
sp_master_check_data(SPARTAN_BOARD_BUFFER_SIZE, 0x0, PSEUDO_RANDOM) ;
|
798 |
|
|
|
799 |
|
|
// if system buffer is larget than board buffer, check the data in the remainder of the system buffer
|
800 |
|
|
if (SPARTAN_BOARD_BUFFER_SIZE < SYS_BUFFER_SIZE)
|
801 |
|
|
sp_master_check_data(SYS_BUFFER_SIZE - SPARTAN_BOARD_BUFFER_SIZE, SPARTAN_BOARD_BUFFER_SIZE * 4, ALL_ZEROS) ;
|
802 |
|
|
|
803 |
|
|
++guint_random_seed ;
|
804 |
|
|
}
|
805 |
|
|
*/
|
806 |
|
|
|
807 |
|
|
// setup the slave registers
|
808 |
|
|
ioctl(spartan_fd, SPARTAN_IOC_CURBASE, &base) ;
|
809 |
|
|
if (!base) {
|
810 |
|
|
printf("Error: Couldn't get target image base address!") ;
|
811 |
|
|
return 0 ;
|
812 |
|
|
}
|
813 |
|
|
|
814 |
|
|
if (sp_seek(TARGET_TEST_START_ADR_OFFSET)) {
|
815 |
|
|
printf("Error: Seek failed!") ;
|
816 |
|
|
return 0 ;
|
817 |
|
|
}
|
818 |
|
|
|
819 |
|
|
if (sp_write(base)) {
|
820 |
|
|
printf("Error: Write to register failed!") ;
|
821 |
|
|
return 0 ;
|
822 |
|
|
}
|
823 |
|
|
|
824 |
|
|
if (sp_seek(TARGET_TEST_START_DATA_OFFSET)) {
|
825 |
|
|
printf("Error: Seek failed!") ;
|
826 |
|
|
return 0 ;
|
827 |
|
|
}
|
828 |
|
|
|
829 |
|
|
if (sp_write(sp_get_first_val(WALKING_ZEROS))) {
|
830 |
|
|
printf("Error: Write to register failed!") ;
|
831 |
|
|
return 0 ;
|
832 |
|
|
}
|
833 |
|
|
|
834 |
|
|
|
835 |
|
|
for (i = 1 ; i <= 200000 ; ++i) {
|
836 |
|
|
// setup the target test size register
|
837 |
|
|
if (sp_seek(TARGET_TEST_SIZE_OFFSET)) {
|
838 |
|
|
printf("Error: Seek failed!") ;
|
839 |
|
|
return 0 ;
|
840 |
|
|
}
|
841 |
|
|
|
842 |
|
|
if (i > 1) {
|
843 |
|
|
if (sp_write(SPARTAN_BOARD_BUFFER_SIZE)) {
|
844 |
|
|
printf("Error: Write to register failed!") ;
|
845 |
|
|
return 0 ;
|
846 |
|
|
}
|
847 |
|
|
} else {
|
848 |
|
|
if (sp_write(SPARTAN_BOARD_BUFFER_SIZE + 1)) {
|
849 |
|
|
printf("Error: Write to register failed!") ;
|
850 |
|
|
return 0 ;
|
851 |
|
|
}
|
852 |
|
|
}
|
853 |
|
|
|
854 |
|
|
if (sp_target_write(1, SPARTAN_BOARD_BUFFER_SIZE, 0x0, WALKING_ZEROS)) {
|
855 |
|
|
printf("Error: Write through target failed!") ;
|
856 |
|
|
return 0 ;
|
857 |
|
|
}
|
858 |
|
|
|
859 |
|
|
if (i < 2) {
|
860 |
|
|
if (sp_target_write(1, 1, 0x8, WALKING_ONES)) {
|
861 |
|
|
printf("Error: Write failed!") ;
|
862 |
|
|
return 0 ;
|
863 |
|
|
}
|
864 |
|
|
}
|
865 |
|
|
|
866 |
|
|
// previously the error was produced intentionally - now check if the error status is still set
|
867 |
|
|
if (i == 2) {
|
868 |
|
|
if (sp_seek(TARGET_TEST_ERR_REP_OFFSET)) {
|
869 |
|
|
printf("Error: Seek failed!") ;
|
870 |
|
|
return 0 ;
|
871 |
|
|
}
|
872 |
|
|
|
873 |
|
|
if (sp_read(&base)) {
|
874 |
|
|
printf("Error: Read failed!") ;
|
875 |
|
|
return 0 ;
|
876 |
|
|
}
|
877 |
|
|
|
878 |
|
|
if (base != 3) {
|
879 |
|
|
printf("Error: Value in the error status register not as expected!") ;
|
880 |
|
|
return 0 ;
|
881 |
|
|
}
|
882 |
|
|
|
883 |
|
|
if (sp_seek(TARGET_TEST_ERR_REP_OFFSET)) {
|
884 |
|
|
printf("Error: Seek failed!") ;
|
885 |
|
|
return 0 ;
|
886 |
|
|
}
|
887 |
|
|
|
888 |
|
|
if (sp_write(0xFFFFFFFF)) {
|
889 |
|
|
printf("Error: Write failed!") ;
|
890 |
|
|
return 0 ;
|
891 |
|
|
}
|
892 |
|
|
}
|
893 |
|
|
}
|
894 |
|
|
|
895 |
|
|
|
896 |
|
|
if (sp_seek(TARGET_TEST_ERR_REP_OFFSET)) {
|
897 |
|
|
printf("Error: Seek failed!") ;
|
898 |
|
|
return 0 ;
|
899 |
|
|
}
|
900 |
|
|
|
901 |
|
|
if (sp_read(&base)) {
|
902 |
|
|
printf("Error: read failed!") ;
|
903 |
|
|
return 0 ;
|
904 |
|
|
}
|
905 |
|
|
|
906 |
|
|
if (base) {
|
907 |
|
|
printf("Error: Test application detected an error!") ;
|
908 |
|
|
|
909 |
|
|
if (sp_seek(TARGET_TEST_ERR_REP_OFFSET)) {
|
910 |
|
|
printf("Error: Seek failed!") ;
|
911 |
|
|
return 0 ;
|
912 |
|
|
}
|
913 |
|
|
|
914 |
|
|
if (sp_write(0)) {
|
915 |
|
|
printf("Error: Write to register failed!") ;
|
916 |
|
|
return 0 ;
|
917 |
|
|
}
|
918 |
|
|
|
919 |
|
|
return 0 ;
|
920 |
|
|
}
|
921 |
|
|
return 0 ;
|
922 |
|
|
}
|
923 |
|
|
|
924 |
|
|
int cmd_master_slide_window_test (void) {
|
925 |
|
|
unsigned int i, j ;
|
926 |
|
|
|
927 |
|
|
/* for (i = 1 ; i <= SPARTAN_BOARD_BUFFER_SIZE ; ++i) {
|
928 |
|
|
for (j = 0 ; j + i <= SYS_BUFFER_SIZE ; ++j ) {
|
929 |
|
|
guint_random_seed = guint_random_seed + 1 ;
|
930 |
|
|
|
931 |
|
|
// fill the system memory buffer with random data
|
932 |
|
|
master_buffer_fill(PSEUDO_RANDOM) ;
|
933 |
|
|
|
934 |
|
|
// clear the on board buffer
|
935 |
|
|
sp_target_write(1, SPARTAN_BOARD_BUFFER_SIZE, 0x0, ALL_ZEROS) ;
|
936 |
|
|
|
937 |
|
|
if (sp_master_read((j % 2) ? 1 : SPARTAN_BOARD_BUFFER_SIZE, (j % 2) ? SPARTAN_BOARD_BUFFER_SIZE : 1, 0x0))
|
938 |
|
|
return 0 ;
|
939 |
|
|
|
940 |
|
|
// all of the master reads are finished
|
941 |
|
|
// clear the system buffer
|
942 |
|
|
master_buffer_fill(ALL_ZEROS) ;
|
943 |
|
|
|
944 |
|
|
if (sp_master_write(1, i, j * 4))
|
945 |
|
|
return 0 ;
|
946 |
|
|
|
947 |
|
|
// write is done - check the data
|
948 |
|
|
sp_master_check_data(i, j * 4, PSEUDO_RANDOM) ;
|
949 |
|
|
|
950 |
|
|
if (j) {
|
951 |
|
|
sp_master_check_data(j, 0, ALL_ZEROS) ;
|
952 |
|
|
}
|
953 |
|
|
|
954 |
|
|
if ( j + i < SYS_BUFFER_SIZE) {
|
955 |
|
|
sp_master_check_data(SYS_BUFFER_SIZE - i - j, (i + j) * 4, ALL_ZEROS) ;
|
956 |
|
|
}
|
957 |
|
|
}
|
958 |
|
|
}
|
959 |
|
|
*/
|
960 |
|
|
sp_target_write(1, SPARTAN_BOARD_BUFFER_SIZE, 0x0, WALKING_ONES) ;
|
961 |
|
|
sp_target_check_data(1, SPARTAN_BOARD_BUFFER_SIZE, 0x0, WALKING_ONES) ;
|
962 |
|
|
master_buffer_fill(ALL_ZEROS) ;
|
963 |
|
|
sp_master_write(SYS_BUFFER_SIZE / SPARTAN_BOARD_BUFFER_SIZE, SPARTAN_BOARD_BUFFER_SIZE, 0x0) ;
|
964 |
|
|
sp_master_check_data(SYS_BUFFER_SIZE, 0x0, WALKING_ONES) ;
|
965 |
|
|
|
966 |
|
|
// clear the master transaction counters
|
967 |
|
|
if (sp_seek(MASTER_NUM_OF_WB_OFFSET)) {
|
968 |
|
|
printf("\nError: Seek error!\n") ;
|
969 |
|
|
return 0 ;
|
970 |
|
|
}
|
971 |
|
|
|
972 |
|
|
if (sp_write(0xFFFFFFFF)) {
|
973 |
|
|
printf("\nError: Write to register failed\n") ;
|
974 |
|
|
return 0 ;
|
975 |
|
|
}
|
976 |
|
|
|
977 |
|
|
if (sp_seek(MASTER_NUM_OF_WB_OFFSET)) {
|
978 |
|
|
printf("\nError: Seek error!\n") ;
|
979 |
|
|
return 0 ;
|
980 |
|
|
}
|
981 |
|
|
|
982 |
|
|
if (sp_read(&i)) {
|
983 |
|
|
printf("\nError: Read from register failed\n") ;
|
984 |
|
|
return 0 ;
|
985 |
|
|
}
|
986 |
|
|
|
987 |
|
|
if (i != 0) {
|
988 |
|
|
printf("\nError: Transaction counter clear operation not OK!\n") ;
|
989 |
|
|
return 0 ;
|
990 |
|
|
}
|
991 |
|
|
|
992 |
|
|
if (sp_seek(MASTER_NUM_OF_PCI_OFFSET)) {
|
993 |
|
|
printf("\nError: Seek error!\n") ;
|
994 |
|
|
return 0 ;
|
995 |
|
|
}
|
996 |
|
|
|
997 |
|
|
if (sp_read(&j)) {
|
998 |
|
|
printf("\nError: Read from register failed\n") ;
|
999 |
|
|
return 0 ;
|
1000 |
|
|
}
|
1001 |
|
|
|
1002 |
|
|
if (j != 0) {
|
1003 |
|
|
printf("\nError: Transaction counter clear operation not OK!\n") ;
|
1004 |
|
|
return 0 ;
|
1005 |
|
|
}
|
1006 |
|
|
|
1007 |
|
|
|
1008 |
|
|
|
1009 |
|
|
// if (SPARTAN_BOARD_BUFFER_SIZE < SYS_BUFFER_SIZE)
|
1010 |
|
|
// sp_master_check_data(SYS_BUFFER_SIZE - SPARTAN_BOARD_BUFFER_SIZE, SPARTAN_BOARD_BUFFER_SIZE * 4, ALL_ZEROS) ;
|
1011 |
|
|
|
1012 |
|
|
for (i = 1 ; i <= 1 ; i = ++i) {
|
1013 |
|
|
|
1014 |
|
|
if (i == 1) {
|
1015 |
|
|
if (sp_seek(0)) {
|
1016 |
|
|
printf("\nError: Seek error!\n") ;
|
1017 |
|
|
return 0 ;
|
1018 |
|
|
}
|
1019 |
|
|
|
1020 |
|
|
if (sp_write(sp_get_first_val(WALKING_ZEROS))) {
|
1021 |
|
|
printf("\nError: Write to register failed!\n") ;
|
1022 |
|
|
return 0 ;
|
1023 |
|
|
}
|
1024 |
|
|
}
|
1025 |
|
|
|
1026 |
|
|
if (sp_seek(MASTER_TRANS_COUNT_OFFSET)) {
|
1027 |
|
|
printf("\nError: Seek error!\n") ;
|
1028 |
|
|
return 0 ;
|
1029 |
|
|
}
|
1030 |
|
|
|
1031 |
|
|
if (sp_read(&j)) {
|
1032 |
|
|
printf("\nError: Read from master number of transactions failed!\n") ;
|
1033 |
|
|
return 0 ;
|
1034 |
|
|
}
|
1035 |
|
|
|
1036 |
|
|
if (j == 0) {
|
1037 |
|
|
|
1038 |
|
|
if (sp_seek(MASTER_TEST_DATA_ERROR_OFFSET)) {
|
1039 |
|
|
printf("\nError: Seek failed!\n") ;
|
1040 |
|
|
return 0 ;
|
1041 |
|
|
}
|
1042 |
|
|
|
1043 |
|
|
if (sp_read(&j)) {
|
1044 |
|
|
printf("\nError: Read from register failed!\n") ;
|
1045 |
|
|
return 0 ;
|
1046 |
|
|
}
|
1047 |
|
|
|
1048 |
|
|
if (i == 1) {
|
1049 |
|
|
printf("\nNote: The following error is produced intentionally, to test software/hardware functionality!\n") ;
|
1050 |
|
|
}
|
1051 |
|
|
|
1052 |
|
|
if (j) {
|
1053 |
|
|
printf("\nError: Test application detected an error in the data sequence on the PCI Master side of the bridge!\n") ;
|
1054 |
|
|
}
|
1055 |
|
|
|
1056 |
|
|
if (sp_seek(MASTER_TEST_START_DATA_OFFSET)) {
|
1057 |
|
|
printf("\nError: Seek failed!\n") ;
|
1058 |
|
|
return 0 ;
|
1059 |
|
|
}
|
1060 |
|
|
|
1061 |
|
|
if (sp_write(sp_get_first_val(WALKING_ONES))) {
|
1062 |
|
|
printf("\nError: Write to register failed!\n") ;
|
1063 |
|
|
return 0 ;
|
1064 |
|
|
}
|
1065 |
|
|
|
1066 |
|
|
if (sp_seek(MASTER_TEST_SIZE_OFFSET)) {
|
1067 |
|
|
printf("\nError: Seek failed!\n") ;
|
1068 |
|
|
return 0 ;
|
1069 |
|
|
}
|
1070 |
|
|
|
1071 |
|
|
if (sp_write(SYS_BUFFER_SIZE)) {
|
1072 |
|
|
printf("\nError: Write to register failed!\n") ;
|
1073 |
|
|
return 0 ;
|
1074 |
|
|
}
|
1075 |
|
|
|
1076 |
|
|
if (sp_seek(MASTER_TRANS_COUNT_OFFSET)) {
|
1077 |
|
|
printf("\nError: Seek error!\n") ;
|
1078 |
|
|
return 0 ;
|
1079 |
|
|
}
|
1080 |
|
|
|
1081 |
|
|
if (sp_write(SYS_BUFFER_SIZE / SPARTAN_BOARD_BUFFER_SIZE)) {
|
1082 |
|
|
printf("\nError: Unable to write master number of transactions register!\n") ;
|
1083 |
|
|
return 0 ;
|
1084 |
|
|
}
|
1085 |
|
|
}
|
1086 |
|
|
|
1087 |
|
|
if (i == 1) {
|
1088 |
|
|
printf("\nNote: The following two errors are produced intentionally, to test software/hardware functionality!\n") ;
|
1089 |
|
|
|
1090 |
|
|
if (sp_seek(0)) {
|
1091 |
|
|
printf("\nError: Seek error!\n") ;
|
1092 |
|
|
return 0 ;
|
1093 |
|
|
}
|
1094 |
|
|
|
1095 |
|
|
if (sp_write(sp_get_first_val(WALKING_ONES))) {
|
1096 |
|
|
printf("\nError: Write to register failed!\n") ;
|
1097 |
|
|
return 0 ;
|
1098 |
|
|
}
|
1099 |
|
|
}
|
1100 |
|
|
|
1101 |
|
|
for (j = 1 ; j <= (SYS_BUFFER_SIZE / SPARTAN_BOARD_BUFFER_SIZE) * 2 ; ++j) {
|
1102 |
|
|
sp_master_check_data(SYS_BUFFER_SIZE, 0x0, WALKING_ONES) ;
|
1103 |
|
|
printf("juhu") ;
|
1104 |
|
|
}
|
1105 |
|
|
|
1106 |
|
|
// if (SPARTAN_BOARD_BUFFER_SIZE < SYS_BUFFER_SIZE)
|
1107 |
|
|
// sp_master_check_data(SYS_BUFFER_SIZE - SPARTAN_BOARD_BUFFER_SIZE, SPARTAN_BOARD_BUFFER_SIZE * 4, ALL_ZEROS) ;
|
1108 |
|
|
|
1109 |
|
|
// master_buffer_fill(ALL_ZEROS) ;
|
1110 |
|
|
}
|
1111 |
|
|
|
1112 |
|
|
j = 0 ;
|
1113 |
|
|
|
1114 |
|
|
// read and clear the master transaction counters
|
1115 |
|
|
if (sp_seek(MASTER_NUM_OF_WB_OFFSET)) {
|
1116 |
|
|
printf("\nError: Seek error!\n") ;
|
1117 |
|
|
return 0 ;
|
1118 |
|
|
}
|
1119 |
|
|
|
1120 |
|
|
if (sp_read(&j)) {
|
1121 |
|
|
printf("\nError: Read from register failed!\n") ;
|
1122 |
|
|
return 0 ;
|
1123 |
|
|
}
|
1124 |
|
|
|
1125 |
|
|
if (j != ((i-1)*SYS_BUFFER_SIZE)) {
|
1126 |
|
|
printf("\nError: Number of WISHBONE transactions unexpected!\n") ;
|
1127 |
|
|
printf("Expected %u, actual %u\n", (i-1)*SYS_BUFFER_SIZE, j) ;
|
1128 |
|
|
} else {
|
1129 |
|
|
printf("\nNote: %u WISHBONE Slave write transfers reported succesfull!\n", j) ;
|
1130 |
|
|
}
|
1131 |
|
|
|
1132 |
|
|
if (sp_seek(MASTER_NUM_OF_PCI_OFFSET)) {
|
1133 |
|
|
printf("\nError: Seek error!\n") ;
|
1134 |
|
|
return 0 ;
|
1135 |
|
|
}
|
1136 |
|
|
|
1137 |
|
|
j = 0 ;
|
1138 |
|
|
|
1139 |
|
|
if (sp_read(&j)) {
|
1140 |
|
|
printf("\nError: Read from register failed\n") ;
|
1141 |
|
|
return 0 ;
|
1142 |
|
|
}
|
1143 |
|
|
|
1144 |
|
|
if (j != ((i-1)*SYS_BUFFER_SIZE)) {
|
1145 |
|
|
printf("\nError: Number of PCI transactions unexpected!\n") ;
|
1146 |
|
|
printf("Expected %u, actual %u\n", (i-1)*SYS_BUFFER_SIZE, j) ;
|
1147 |
|
|
} else {
|
1148 |
|
|
printf("Note: %u PCI Master write transfers reported succesfull!\n") ;
|
1149 |
|
|
}
|
1150 |
|
|
|
1151 |
|
|
// clear the counters
|
1152 |
|
|
/* if (sp_seek(MASTER_NUM_OF_WB_OFFSET)) {
|
1153 |
|
|
printf("\nError: Seek error!\n") ;
|
1154 |
|
|
return 0 ;
|
1155 |
|
|
}
|
1156 |
|
|
|
1157 |
|
|
if (sp_write(0xFFFFFFFF)) {
|
1158 |
|
|
printf("\nError: Write to register failed!\n") ;
|
1159 |
|
|
return 0 ;
|
1160 |
|
|
}
|
1161 |
|
|
*/
|
1162 |
|
|
|
1163 |
|
|
// perform a read and write tests with variable size and number of transactions.
|
1164 |
|
|
// i represents transaction size, j represents number of transactions
|
1165 |
|
|
/* for (i = 1 ; i <= SPARTAN_BOARD_BUFFER_SIZE ; ++i) {
|
1166 |
|
|
for (j = 1 ; j * i <= SPARTAN_BOARD_BUFFER_SIZE ; ++j) {
|
1167 |
|
|
|
1168 |
|
|
guint_random_seed = guint_random_seed + 1 ;
|
1169 |
|
|
|
1170 |
|
|
// clear the onboard buffer
|
1171 |
|
|
sp_target_write(1, SPARTAN_BOARD_BUFFER_SIZE, 0x0, (i % 2) ? ALL_ZEROS : ALL_ONES) ;
|
1172 |
|
|
|
1173 |
|
|
master_buffer_fill(PSEUDO_RANDOM) ;
|
1174 |
|
|
|
1175 |
|
|
if ( sp_master_read( j, i, ( SPARTAN_BOARD_BUFFER_SIZE - i * j ) * 4) ) return 0 ;
|
1176 |
|
|
|
1177 |
|
|
// check the data in system buffer by writing it through pci master
|
1178 |
|
|
master_buffer_fill((i % 2) ? ALL_ONES : ALL_ZEROS) ;
|
1179 |
|
|
|
1180 |
|
|
if ( sp_master_write( 1, SPARTAN_BOARD_BUFFER_SIZE, 0x0)) return 0 ;
|
1181 |
|
|
|
1182 |
|
|
// check the data that was not read in on lower offsets
|
1183 |
|
|
if (i*j < SPARTAN_BOARD_BUFFER_SIZE) {
|
1184 |
|
|
// check the data in the begining of the buffer, which was not read
|
1185 |
|
|
if (sp_master_check_data(SPARTAN_BOARD_BUFFER_SIZE - i * j, 0x0, (i % 2) ? ALL_ZEROS : ALL_ONES)) {
|
1186 |
|
|
printf("\nError during Master read test detected!\n") ;
|
1187 |
|
|
printf("Read test properties: number of transactions %d, transaction sizes %d\n", j, i) ;
|
1188 |
|
|
printf("Checking the data in onboard buffer\n") ;
|
1189 |
|
|
sp_target_check_data(1, SPARTAN_BOARD_BUFFER_SIZE - i * j, 0x0, (i % 2) ? ALL_ZEROS : ALL_ONES) ;
|
1190 |
|
|
printf("Check done!\n") ;
|
1191 |
|
|
}
|
1192 |
|
|
}
|
1193 |
|
|
|
1194 |
|
|
// check the data that was read
|
1195 |
|
|
if (sp_master_check_data(i*j, ( SPARTAN_BOARD_BUFFER_SIZE - ( i * j ) ) * 4, PSEUDO_RANDOM)) {
|
1196 |
|
|
printf("\nError during Master read test detected!\n") ;
|
1197 |
|
|
printf("Read test properties: number of transactions %d, transaction sizes %d\n", j, i) ;
|
1198 |
|
|
printf("Checking the data in onboard buffer\n") ;
|
1199 |
|
|
sp_target_check_data(1, i*j, SPARTAN_BOARD_BUFFER_SIZE - i * j, PSEUDO_RANDOM ) ;
|
1200 |
|
|
printf("Check done!\n") ;
|
1201 |
|
|
}
|
1202 |
|
|
|
1203 |
|
|
}
|
1204 |
|
|
}
|
1205 |
|
|
*/
|
1206 |
|
|
return 0 ;
|
1207 |
|
|
}
|
1208 |
|
|
|
1209 |
|
|
int sp_master_do(unsigned int num_of_transactions, unsigned int transaction_size, unsigned int starting_offset, unsigned int opcode) {
|
1210 |
|
|
unsigned int base ;
|
1211 |
|
|
unsigned int transactions_left ;
|
1212 |
|
|
unsigned int deadlock_cnt ;
|
1213 |
|
|
unsigned int wait ;
|
1214 |
|
|
|
1215 |
|
|
ioctl(spartan_fd, SPARTAN_IOC_VIDEO_BASE, &base) ;
|
1216 |
|
|
|
1217 |
|
|
if (sp_seek(MASTER_ADDR_REG_OFFSET)) {
|
1218 |
|
|
printf("\nError: Seek error!\n") ;
|
1219 |
|
|
return 1 ;
|
1220 |
|
|
}
|
1221 |
|
|
|
1222 |
|
|
if (sp_write(base + starting_offset)) {
|
1223 |
|
|
printf("\nError: Unable to write master address register!\n") ;
|
1224 |
|
|
return 1;
|
1225 |
|
|
}
|
1226 |
|
|
|
1227 |
|
|
if (sp_seek(MASTER_OP_CODE_OFFSET)) {
|
1228 |
|
|
printf("\nError: Seek error!\n") ;
|
1229 |
|
|
return 1 ;
|
1230 |
|
|
}
|
1231 |
|
|
|
1232 |
|
|
if (sp_write(opcode)) {
|
1233 |
|
|
printf("\nError: Unable to write master opcode register!\n") ;
|
1234 |
|
|
return 1 ;
|
1235 |
|
|
}
|
1236 |
|
|
|
1237 |
|
|
if (sp_seek(MASTER_TRANS_SIZE_OFFSET)) {
|
1238 |
|
|
printf("\nError: Seek error!\n") ;
|
1239 |
|
|
return 1 ;
|
1240 |
|
|
}
|
1241 |
|
|
|
1242 |
|
|
if (sp_write(transaction_size)) {
|
1243 |
|
|
printf("\nError: Unable to write master transaction size register!\n") ;
|
1244 |
|
|
return 1 ;
|
1245 |
|
|
}
|
1246 |
|
|
|
1247 |
|
|
if (sp_seek(MASTER_TRANS_COUNT_OFFSET)) {
|
1248 |
|
|
printf("\nError: Seek error!\n") ;
|
1249 |
|
|
return 1 ;
|
1250 |
|
|
}
|
1251 |
|
|
|
1252 |
|
|
if (sp_write(num_of_transactions)) {
|
1253 |
|
|
printf("\nError: Unable to write master number of transactions register!\n") ;
|
1254 |
|
|
return 1 ;
|
1255 |
|
|
}
|
1256 |
|
|
|
1257 |
|
|
transactions_left = num_of_transactions ;
|
1258 |
|
|
deadlock_cnt = 0 ;
|
1259 |
|
|
while (transactions_left && (deadlock_cnt < 100)) {
|
1260 |
|
|
|
1261 |
|
|
// suspend the polling of remaining transactions, until minimum required time has passed, or for small writes for 1 us.
|
1262 |
|
|
for (wait = 0 ; wait < (transactions_left * transaction_size * 100) ; ++wait) ;
|
1263 |
|
|
|
1264 |
|
|
if (sp_seek(MASTER_TRANS_COUNT_OFFSET)) {
|
1265 |
|
|
printf("\nError: Seek error!\n") ;
|
1266 |
|
|
return 1 ;
|
1267 |
|
|
}
|
1268 |
|
|
|
1269 |
|
|
if (sp_read(&transactions_left)) {
|
1270 |
|
|
printf("\nError: Read failed!\n") ;
|
1271 |
|
|
return 1 ;
|
1272 |
|
|
}
|
1273 |
|
|
|
1274 |
|
|
++deadlock_cnt ;
|
1275 |
|
|
}
|
1276 |
|
|
|
1277 |
|
|
if (deadlock_cnt == 0x00200000) {
|
1278 |
|
|
printf("\nError: The requested master operation is not beeing processed. Is at least one wb image enabled?\n") ;
|
1279 |
|
|
return 1 ;
|
1280 |
|
|
}
|
1281 |
|
|
return 0 ;
|
1282 |
|
|
}
|