#include <stdio.h>
#include <usb.h>
#include <getopt.h>
#include "hexfile.h"
#include "flashprog.h"
Go to the source code of this file.
Function Documentation
usb_dev_handle* find_and_open_usb |
( |
unsigned short |
vid, |
|
|
unsigned short |
pid |
|
) |
| |
Definition at line 23 of file main.c.
{
struct usb_bus *bus;
struct usb_device *dev;
usb_dev_handle *hdev;
usb_find_busses();
usb_find_devices();
for(bus = usb_busses; bus; bus = bus->next)
{
for(dev = bus->devices; dev; dev = dev->next)
{
if(dev->descriptor.idVendor == vid && dev->descriptor.idProduct == pid)
{
hdev = usb_open(dev);
if(usb_set_configuration(hdev, 1) < 0)
{
usb_close(hdev);
continue;
}
if(usb_claim_interface(hdev, 0) < 0)
{
usb_close(hdev);
continue;
}
return hdev;
}
}
}
return 0;
}
void print_usage |
( |
void |
) |
|
Definition at line 57 of file main.c.
{
fprintf(stderr, "usage: bootlu1 [options] <hex-file>\n");
fprintf(stderr, " options:\n");
fprintf(stderr, " -f 16 Flash size is 16K Bytes\n");
fprintf(stderr, " -f 32 Flash size is 32K Bytes\n");
}
int main |
( |
int |
argc, |
|
|
char * |
argv[] |
|
) |
| |
Definition at line 65 of file main.c.
{
char c;
unsigned flash_size, i, low_addr = 0, high_addr = 0;
FILE *fp;
usb_dev_handle *hdev;
while((c = getopt(argc, argv, "f:")) != EOF)
{
switch(c)
{
case 'f':
i = (unsigned)atoi(optarg);
if ((i != 16) && (i != 32))
{
print_usage();
exit(EXIT_FAILURE);
}
flash_size = i * 1024;
break;
default:
print_usage();
exit(EXIT_FAILURE);
}
}
if ((argc - optind) != 1)
{
print_usage();
exit(EXIT_FAILURE);
}
if ((fp = fopen(argv[optind], "rt")) == 0)
{
fprintf(stderr, "ERROR: Can't open input file <%s>\n", argv[optind]);
return 1;
}
usb_init();
hdev = find_and_open_usb(VID_NORDIC, PID_LU1BOOT);
if (hdev == 0)
{
fprintf(stderr, "ERROR: nRF24LU1P Bootloader not found\n");
exit(EXIT_FAILURE);
}
for(i=0;i<flash_size;i++)
hex_buf[i] = 0xff;
if (read_hex_file(fp, 1, hex_buf, flash_size, &low_addr, &high_addr) != NO_ERR)
{
exit(EXIT_FAILURE);
}
if (!flash_prog(hdev, low_addr, high_addr, flash_size, hex_buf))
{
fprintf(stderr, "ERROR: There was an error programming the flash\n");
exit(EXIT_FAILURE);
}
usb_close(hdev);
exit(EXIT_SUCCESS);
}
Variable Documentation