usb: dfu: give wait_for_usb_dfu an argument

Allow callers to wait for an arbitrary amount of time, instead of always
waiting for a compile-time fixed period.

Signed-off-by: Josh Gao <josh@jmgao.dev>
This commit is contained in:
Josh Gao 2020-11-13 18:49:30 -08:00 committed by Carles Cufí
commit 16d2ab790c
4 changed files with 10 additions and 17 deletions

View file

@ -29,6 +29,9 @@ interface and listing all issues with the `bug label
API Changes API Changes
*********** ***********
* The :c:func:`wait_for_usb_dfu` function now accepts a ``k_timeout_t`` argument instead of
using the ``CONFIG_USB_DFU_WAIT_DELAY_MS`` macro.
Deprecated in this release Deprecated in this release
* :c:macro:`DT_CLOCKS_LABEL_BY_IDX`, :c:macro:`DT_CLOCKS_LABEL_BY_NAME`, * :c:macro:`DT_CLOCKS_LABEL_BY_IDX`, :c:macro:`DT_CLOCKS_LABEL_BY_NAME`,

View file

@ -44,6 +44,8 @@
#ifndef ZEPHYR_INCLUDE_USB_CLASS_USB_DFU_H_ #ifndef ZEPHYR_INCLUDE_USB_CLASS_USB_DFU_H_
#define ZEPHYR_INCLUDE_USB_CLASS_USB_DFU_H_ #define ZEPHYR_INCLUDE_USB_CLASS_USB_DFU_H_
#include <sys_clock.h>
/** DFU Class Subclass */ /** DFU Class Subclass */
#define DFU_SUBCLASS 0x01 #define DFU_SUBCLASS 0x01
@ -121,6 +123,6 @@ enum dfu_state {
dfuERROR, dfuERROR,
}; };
void wait_for_usb_dfu(void); void wait_for_usb_dfu(k_timeout_t delay);
#endif /* ZEPHYR_INCLUDE_USB_CLASS_USB_DFU_H_ */ #endif /* ZEPHYR_INCLUDE_USB_CLASS_USB_DFU_H_ */

View file

@ -18,14 +18,6 @@ config USB_DEVICE_DFU_PID
help help
USB device product ID in DFU mode. MUST be configured by vendor. USB device product ID in DFU mode. MUST be configured by vendor.
config USB_DFU_WAIT_DELAY_MS
int "wait_for_usb_dfu() timeout"
default 12000
range 1000 120000
help
A thread can use wait_for_usb_dfu() call for wait a prescribed
time (in ms) for DFU to begin
config USB_DFU_DETACH_TIMEOUT config USB_DFU_DETACH_TIMEOUT
int int
default 1000 default 1000

View file

@ -64,10 +64,6 @@ LOG_MODULE_REGISTER(usb_dfu);
#define FIRMWARE_IMAGE_0_LABEL "image-0" #define FIRMWARE_IMAGE_0_LABEL "image-0"
#define FIRMWARE_IMAGE_1_LABEL "image-1" #define FIRMWARE_IMAGE_1_LABEL "image-1"
/* MCUBoot waits for CONFIG_USB_DFU_WAIT_DELAY_MS time in total to let DFU to
* be commenced. It intermittently checks every INTERMITTENT_CHECK_DELAY
* milliseconds to see if DFU has started.
*/
#define INTERMITTENT_CHECK_DELAY 50 #define INTERMITTENT_CHECK_DELAY 50
static struct k_poll_event dfu_event; static struct k_poll_event dfu_event;
@ -829,14 +825,14 @@ static bool is_dfu_started(void)
* *
* @return N/A * @return N/A
*/ */
void wait_for_usb_dfu(void) void wait_for_usb_dfu(k_timeout_t delay)
{ {
uint64_t end = z_timeout_end_calc(delay);
/* Wait for a prescribed duration of time. If DFU hasn't started within /* Wait for a prescribed duration of time. If DFU hasn't started within
* that time, stop waiting and proceed further. * that time, stop waiting and proceed further.
*/ */
for (int time = 0; while (end > k_uptime_ticks()) {
time < (CONFIG_USB_DFU_WAIT_DELAY_MS/INTERMITTENT_CHECK_DELAY);
time++) {
if (is_dfu_started()) { if (is_dfu_started()) {
k_poll_event_init(&dfu_event, K_POLL_TYPE_SIGNAL, k_poll_event_init(&dfu_event, K_POLL_TYPE_SIGNAL,
K_POLL_MODE_NOTIFY_ONLY, &dfu_signal); K_POLL_MODE_NOTIFY_ONLY, &dfu_signal);