// See of the device is ok and connected, if not, try reconnecting static bool checkDevice(bool usbOk) { if(!usbOk || !device_valid()) { device_close(); device_open(); actions_showConnectionStatus(); if(!device_valid()) return false; actions_showCurrentSettings(); actions_setTransitionTime(); } return true; }
/* * Increment the reference count on an active device. */ static int device_reference(struct device *dev) { sched_lock(); if (!device_valid(dev)) { sched_unlock(); return ENODEV; } dev->refcnt++; sched_unlock(); return 0; }
int device_destroy(struct device *dev) { sched_lock(); if (!device_valid(dev)) { sched_unlock(); return ENODEV; } dev->active = 0; device_release(dev); sched_unlock(); return 0; }
int device_list_init_fpgas(struct device_list *device_list) { int ok_count = 0; struct device *device; for (device = device_list->device; device; device = device->next) { if (!device_valid(device)) continue; int result = device_init_fpgas(device); if (result < 0) { printf("SN %s error %d initializing FPGAs.\n", device->ztex_device->snString, result); device_invalidate(device); } else ok_count ++; } return ok_count; }
int main(int argc, char **argv) { set_random(); int result = libusb_init(NULL); if (result < 0) { printf("libusb_init(): %s\n", libusb_strerror(result)); exit(EXIT_FAILURE); } /////////////////////////////////////////////////////////////// // // 1. Find ZTEX devices, initialize // /////////////////////////////////////////////////////////////// //ZTEX_DEBUG=1; //DEBUG = 1; struct device_list *device_list = device_init_scan(device_list); int device_count = device_list_count(device_list); printf("%d device(s) ZTEX 1.15y ready\n", device_count); if (device_count) ztex_dev_list_print(device_list->ztex_dev_list); //else // exit(0); /////////////////////////////////////////////////////////////// // // 2. Perform I/O. // /////////////////////////////////////////////////////////////// // Signals aren't checked at time of firmware and bitstream uploads signal(SIGHUP, signal_handler); signal(SIGINT, signal_handler); signal(SIGTERM, signal_handler); signal(SIGALRM, signal_handler); printf("Writing to each FPGA of each device and reading back, random length writes (%d-%d)\n", min_len, max_len); struct timeval tv0, tv1; gettimeofday(&tv0, NULL); struct timeval tv2, tv3; gettimeofday(&tv2, NULL); for ( ; ; ) { if (signal_received) { printf("Signal received.\n"); break; } struct device_list *device_list_1 = device_timely_scan(device_list); int found_devices = device_list_count(device_list_1); if (found_devices) { printf("Found %d device(s) ZTEX 1.15y\n", found_devices); ztex_dev_list_print(device_list_1->ztex_dev_list); } device_list_merge(device_list, device_list_1); int device_count = 0; struct device *device; for (device = device_list->device; device; device = device->next) { if (!device_valid(device)) continue; result = device_fpgas_rw(device); if (result < 0) { printf("SN %s error %d doing r/w of FPGAs (%s)\n", device->ztex_device->snString, result, libusb_strerror(result) ); device_invalidate(device); } device_count ++; } if (!device_count) { gettimeofday(&tv3, NULL); if (tv3.tv_sec - tv2.tv_sec == 1) { printf("x"); fflush(stdout); } tv2 = tv3; usleep(500 *1000); } } // for(;;) gettimeofday(&tv1, NULL); unsigned long long usec = (tv1.tv_sec - tv0.tv_sec)*1000000 + tv1.tv_usec - tv0.tv_usec; float kbyte_count = (wr_byte_count+rd_byte_count)/1024; unsigned long long cmd_count = 0; printf("%.2f MB write, %.2f MB read, rate %.2f MB/s, partial reads %d\n", (float)wr_byte_count/1024/1024, (float)rd_byte_count/1024/1024, kbyte_count *1000000/usec /1024, partial_read_count); libusb_exit(NULL); }