int SPI_DOWNLOAD_THREAD::get_fx3_prog_handle() { char *progfile_p, *tmp; cyusb_handle *handle; int i, j, r; struct stat filestat; #if 0 r = check_fx3_flashprog(h); if ( r == 0 ) //return 0; tmp = getenv("CYUSB_ROOT"); if (tmp != NULL) { i = strlen(tmp); progfile_p = (char *)malloc(i + 32); strcpy(progfile_p, tmp); strcat(progfile_p, "/fx3_images/cyfxflashprog.img"); } else { progfile_p = (char *)malloc (32); strcpy (progfile_p, "fx3_images/cyfxflashprog.img"); } r = stat(progfile_p, &filestat); if ( r != 0 ) { printf("Failed to find cyfxflashprog.img file\n"); //return -1; } #endif r = fx3_usbboot_download( qPrintable(QString("/home/linux/app/cyfxflashprog.img"))); // free (progfile_p); if ( r != 0 ) { printf("Failed to download flash prog utility\n"); return -1; } // Now wait for the flash programmer to enumerate, and get a handle to it. for ( j = 0; j < GETHANDLE_TIMEOUT; j++ ) { sleep (1); for ( i = 0; i < num_devices_detected; i++ ) { handle = cyusb_gethandle(i); if ( cyusb_getvendor(handle) == FLASHPROG_VID ) { r = check_fx3_flashprog(handle); if ( r == 0 ) { h = handle; return 0; } } } } printf("Failed to get handle to flash programmer\n"); return -2; }
/* Get the handle to the FX3 flash programmer device, if found. */ static int get_fx3_prog_handle ( cyusb_handle **h) { char *progfile_p, *tmp; cyusb_handle *handle; int i, j, r; struct stat filestat; handle = *h; r = check_fx3_flashprog (handle); if (r == 0) return 0; printf ("Info: Trying to download flash programmer to RAM\n"); tmp = getenv ("CYUSB_ROOT"); if (tmp != NULL) { i = strlen (tmp); progfile_p = (char *)malloc (i + 32); strcpy (progfile_p, tmp); strcat (progfile_p, "/fx3_images/cyfxflashprog.img"); } else { progfile_p = (char *)malloc (32); strcpy (progfile_p, "fx3_images/cyfxflashprog.img"); } r = stat (progfile_p, &filestat); if (r != 0) { fprintf (stderr, "Error: Failed to find cyfxflashprog.img file\n"); return -1; } r = fx3_usbboot_download (handle, progfile_p); free (progfile_p); if (r != 0) { fprintf (stderr, "Error: Failed to download flash prog utility\n"); return -1; } cyusb_close (); *h = NULL; // Now wait for the flash programmer to enumerate, and get a handle to it. for (j = 0; j < GETHANDLE_TIMEOUT; j++) { sleep (1); r = cyusb_open (); if (r > 0) { for (i = 0; i < r; i++) { handle = cyusb_gethandle (i); if (cyusb_getvendor (handle) == FLASHPROG_VID) { r = check_fx3_flashprog (handle); if (r == 0) { printf ("Info: Got handle to FX3 flash programmer\n"); *h = handle; return 0; } } } cyusb_close (); } } fprintf (stderr, "Error: Failed to get handle to flash programmer\n"); return -2; }