hackrf_cpldjtag: Update for new hackrf_cpld_write interface
This commit is contained in:
@ -93,8 +93,7 @@ int main(int argc, char** argv)
|
|||||||
int option_index = 0;
|
int option_index = 0;
|
||||||
FILE* fd = NULL;
|
FILE* fd = NULL;
|
||||||
ssize_t bytes_read;
|
ssize_t bytes_read;
|
||||||
uint16_t xfer_len = 0;
|
uint8_t* pdata = &data[0];
|
||||||
uint8_t* pdata = &data[0];
|
|
||||||
|
|
||||||
while ((opt = getopt_long(argc, argv, "x:", long_options,
|
while ((opt = getopt_long(argc, argv, "x:", long_options,
|
||||||
&option_index)) != EOF) {
|
&option_index)) != EOF) {
|
||||||
@ -127,20 +126,20 @@ int main(int argc, char** argv)
|
|||||||
{
|
{
|
||||||
fprintf(stderr, "Failed to open file: %s\n", path);
|
fprintf(stderr, "Failed to open file: %s\n", path);
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
/* Get size of the file */
|
/* Get size of the file */
|
||||||
fseek(fd, 0, SEEK_END); /* Not really portable but work on major OS Linux/Win32 */
|
fseek(fd, 0, SEEK_END); /* Not really portable but work on major OS Linux/Win32 */
|
||||||
length = ftell(fd);
|
length = ftell(fd);
|
||||||
/* Move to start */
|
/* Move to start */
|
||||||
rewind(fd);
|
rewind(fd);
|
||||||
printf("File size %d bytes.\n", length);
|
printf("File size %d bytes.\n", length);
|
||||||
|
|
||||||
if (length > MAX_XSVF_LENGTH) {
|
if (length > MAX_XSVF_LENGTH) {
|
||||||
fprintf(stderr, "XSVF file too large.\n");
|
fprintf(stderr, "XSVF file too large.\n");
|
||||||
usage();
|
usage();
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
total_length = length;
|
total_length = length;
|
||||||
bytes_read = fread(data, 1, total_length, fd);
|
bytes_read = fread(data, 1, total_length, fd);
|
||||||
if (bytes_read != total_length)
|
if (bytes_read != total_length)
|
||||||
@ -168,27 +167,20 @@ int main(int argc, char** argv)
|
|||||||
|
|
||||||
printf("LED1/2/3 blinking means CPLD program success.\nLED3/RED steady means error.\n");
|
printf("LED1/2/3 blinking means CPLD program success.\nLED3/RED steady means error.\n");
|
||||||
printf("Wait message 'Write finished' or in case of LED3/RED steady, Power OFF/Disconnect the Jawbreaker.\n");
|
printf("Wait message 'Write finished' or in case of LED3/RED steady, Power OFF/Disconnect the Jawbreaker.\n");
|
||||||
while( length )
|
result = hackrf_cpld_write(device, pdata, total_length);
|
||||||
|
if (result != HACKRF_SUCCESS)
|
||||||
{
|
{
|
||||||
xfer_len = (length > PACKET_LEN) ? PACKET_LEN : length;
|
fprintf(stderr, "hackrf_cpld_write() failed: %s (%d)\n",
|
||||||
result = hackrf_cpld_write(device, xfer_len, pdata, total_length);
|
hackrf_error_name(result), result);
|
||||||
if (result != HACKRF_SUCCESS)
|
fclose(fd);
|
||||||
{
|
fd = NULL;
|
||||||
fprintf(stderr, "hackrf_cpld_write() failed: %s (%d)\n",
|
return EXIT_FAILURE;
|
||||||
hackrf_error_name(result), result);
|
|
||||||
fclose(fd);
|
|
||||||
fd = NULL;
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
pdata += xfer_len;
|
|
||||||
length -= xfer_len;
|
|
||||||
printf("hackrf_cpld_write() Writing %d bytes, remaining %d bytes.\n",
|
|
||||||
xfer_len, length);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Write finished.\n");
|
printf("Write finished.\n");
|
||||||
printf("Please Power OFF/Disconnect the Jawbreaker.\n");
|
printf("Please Power OFF/Disconnect the Jawbreaker.\n");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
||||||
result = hackrf_close(device);
|
result = hackrf_close(device);
|
||||||
if( result != HACKRF_SUCCESS )
|
if( result != HACKRF_SUCCESS )
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user