lynxis lazus has uploaded this change for review.
dfu: usb_dfu() convert if() intos switch/case
Improves the overview of the handled states.
No functional change.
Change-Id: Ie0abcdb51612598e77cacf7772276919ded17d5a
---
M usb_start.c
1 file changed, 10 insertions(+), 5 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-asf4-dfu refs/changes/73/42173/1
diff --git a/usb_start.c b/usb_start.c
index c80703e..78711f1 100644
--- a/usb_start.c
+++ b/usb_start.c
@@ -162,7 +162,9 @@
enum usb_dfu_state last_dfu_state = dfu_state;
// run the second part of the USB DFU state machine handling non-USB aspects
- if (USB_DFU_STATE_DFU_DNLOAD_SYNC == last_dfu_state || USB_DFU_STATE_DFU_DNBUSY == last_dfu_state) { // there is some data to be flashed
+ switch (last_dfu_state) {
+ case USB_DFU_STATE_DFU_DNLOAD_SYNC:
+ case USB_DFU_STATE_DFU_DNBUSY: // there is some data to be flashed
LED_SYSTEM_off(); // switch LED off to indicate we are flashing
if (dfu_download_length > 0) { // there is some data to be flashed
int32_t rc = flash_write(&FLASH_0, application_start_address + dfu_download_offset, dfu_download_data, dfu_download_length); // write downloaded data chunk to flash
@@ -183,8 +185,8 @@
dfu_state = USB_DFU_STATE_DFU_DNLOAD_IDLE; // indicate flashing can continue
}
LED_SYSTEM_on(); // switch LED on to indicate USB DFU can resume
- }
- if (USB_DFU_STATE_DFU_MANIFEST == last_dfu_state) { // we can start manifestation (finish flashing)
+ break;
+ case USB_DFU_STATE_DFU_MANIFEST: // we can start manifestation (finish flashing)
// in theory every DFU files should have a suffix to with a CRC to check the data
// in practice most downloaded files are just the raw binary with DFU suffix
dfu_manifestation_complete = true; // we completed flashing and all checks
@@ -193,13 +195,16 @@
} else {
dfu_state = USB_DFU_STATE_DFU_MANIFEST_WAIT_RESET;
}
- }
- if (USB_DFU_STATE_DFU_MANIFEST_WAIT_RESET == last_dfu_state) {
+ break;
+ case USB_DFU_STATE_DFU_MANIFEST_WAIT_RESET:
if (usb_dfu_func_desc->bmAttributes & USB_DFU_ATTRIBUTES_WILL_DETACH) {
usb_dfu_reset(USB_EV_RESET, 0); // immediately reset
} else { // wait for USB reset
usb_d_register_callback(USB_D_CB_EVENT, (FUNC_PTR)usb_dfu_reset); // register new USB reset event handler
}
+ break;
+ default:
+ break;
}
}
}
To view, visit change 42173. To unsubscribe, or for help writing mail filters, visit settings.