Reboot radio to normal mode when done.

This commit is contained in:
Serge Vakulenko 2018-09-04 23:37:42 -07:00
parent c04d34c060
commit ec65b32f65
3 changed files with 29 additions and 9 deletions

29
dfu.c
View File

@ -126,7 +126,7 @@ static int get_status()
}
int error = libusb_control_transfer(dev, REQUEST_TYPE_TO_HOST,
REQUEST_GETSTATUS, 0, 0, (unsigned char*)&status, 6, 0);
if (trace_flag && error == USB_OK) {
if (trace_flag && error >= 0) {
printf("--- Recv ");
print_hex((unsigned char*)&status, 6);
printf("\n");
@ -154,7 +154,7 @@ static int get_state(int *pstate)
int error = libusb_control_transfer(dev, REQUEST_TYPE_TO_HOST,
REQUEST_GETSTATE, 0, 0, &state, 1, 0);
*pstate = state;
if (trace_flag && error == USB_OK) {
if (trace_flag && error >= 0) {
printf("--- Recv ");
print_hex(&state, 1);
printf("\n");
@ -305,7 +305,7 @@ static const char *identify()
__func__, error, libusb_strerror(error));
exit(-1);
}
if (trace_flag && error == USB_OK) {
if (trace_flag) {
printf("--- Recv ");
print_hex(data, 64);
printf("\n");
@ -417,7 +417,7 @@ void dfu_read_block(int bno, uint8_t *data, int nbytes)
__func__, bno, nbytes, error, libusb_strerror(error));
exit(-1);
}
if (trace_flag && error == USB_OK) {
if (trace_flag > 1) {
printf("--- Recv ");
print_hex(data, nbytes);
printf("\n");
@ -432,6 +432,7 @@ void dfu_write_block(int bno, uint8_t *data, int nbytes)
if (trace_flag) {
printf("--- Send DNLOAD [%d] ", nbytes);
if (trace_flag > 1)
print_hex(data, nbytes);
printf("\n");
}
@ -446,3 +447,23 @@ void dfu_write_block(int bno, uint8_t *data, int nbytes)
get_status();
wait_dfu_idle();
}
void dfu_reboot()
{
unsigned char cmd[2] = { 0x91, 0x05 };
if (trace_flag) {
printf("--- Send DNLOAD [2] ");
print_hex(cmd, 2);
printf("\n");
}
wait_dfu_idle();
int error = libusb_control_transfer(dev, REQUEST_TYPE_TO_DEVICE,
REQUEST_DNLOAD, 0, 0, cmd, 2, 0);
if (error < 0) {
fprintf(stderr, "%s: cannot send command: %d: %s\n",
__func__, error, libusb_strerror(error));
exit(-1);
}
get_status();
}

View File

@ -47,11 +47,9 @@ void radio_disconnect()
{
fprintf(stderr, "Close device.\n");
// Restore the port mode.
// Restore the normal radio mode.
dfu_reboot();
dfu_close();
// Radio needs a timeout to reset to a normal state.
mdelay(2000);
}
//

1
util.h
View File

@ -63,6 +63,7 @@ void dfu_close(void);
void dfu_erase(int nbytes);
void dfu_read_block(int bno, unsigned char *data, int nbytes);
void dfu_write_block(int bno, unsigned char *data, int nbytes);
void dfu_reboot(void);
//
// Delay in milliseconds.