File tree Expand file tree Collapse file tree 3 files changed +26
-7
lines changed Expand file tree Collapse file tree 3 files changed +26
-7
lines changed Original file line number Diff line number Diff line change @@ -269,10 +269,14 @@ struct usbd_status {
269269/**
270270 * @brief Callback type definition for USB device message delivery
271271 *
272- * The implementation uses the system workqueue, and a callback provided and
273- * registered by the application. The application callback is called in the
274- * context of the system workqueue. Notification messages are stored in a queue
275- * and delivered to the callback in sequence.
272+ * If the Kconfig option USBD_MSG_DEFERRED_MODE is enabled, then the callback
273+ * is executed in the context of the system workqueue. Notification messages are
274+ * stored in a queue and delivered to the callback in sequence.
275+ *
276+ * If the Kconfig option USBD_MSG_DEFERRED_MODE is disabled, the callback is
277+ * executed in the context of the USB device stack thread. The user should make
278+ * sure that the callback execution does not block or disrupt device stack
279+ * handling.
276280 *
277281 * @param[in] ctx Pointer to USB device support context
278282 * @param[in] msg Pointer to USB device message
Original file line number Diff line number Diff line change @@ -81,8 +81,15 @@ config USBD_MSG_SLAB_COUNT
8181 help
8282 Maximum number of USB device notification messages that can be queued.
8383
84+ config USBD_MSG_DEFERRED_MODE
85+ bool "Execute message callback from system workqueue"
86+ default y
87+ help
88+ Execute message callback from system workqueue. If disabled, message
89+ callback will be executed in the device stack context.
90+
8491config USBD_MSG_WORK_DELAY
85- int "USB device notification messages work delay"
92+ int "USB device notification messages work delay" if USBD_MSG_DEFERRED_MODE
8693 range 1 100
8794 default 1
8895 help
Original file line number Diff line number Diff line change @@ -116,7 +116,11 @@ void usbd_msg_pub_simple(struct usbd_context *const ctx,
116116 };
117117
118118 if (ctx -> msg_cb != NULL ) {
119- usbd_msg_pub (ctx , msg );
119+ if (IS_ENABLED (CONFIG_USBD_MSG_DEFERRED_MODE )) {
120+ usbd_msg_pub (ctx , msg );
121+ } else {
122+ ctx -> msg_cb (ctx , & msg );
123+ }
120124 }
121125}
122126
@@ -129,6 +133,10 @@ void usbd_msg_pub_device(struct usbd_context *const ctx,
129133 };
130134
131135 if (ctx -> msg_cb != NULL ) {
132- usbd_msg_pub (ctx , msg );
136+ if (IS_ENABLED (CONFIG_USBD_MSG_DEFERRED_MODE )) {
137+ usbd_msg_pub (ctx , msg );
138+ } else {
139+ ctx -> msg_cb (ctx , & msg );
140+ }
133141 }
134142}
You can’t perform that action at this time.
0 commit comments