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 {
269
269
/**
270
270
* @brief Callback type definition for USB device message delivery
271
271
*
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.
276
280
*
277
281
* @param[in] ctx Pointer to USB device support context
278
282
* @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
81
81
help
82
82
Maximum number of USB device notification messages that can be queued.
83
83
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
+
84
91
config 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
86
93
range 1 100
87
94
default 1
88
95
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,
116
116
};
117
117
118
118
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
+ }
120
124
}
121
125
}
122
126
@@ -129,6 +133,10 @@ void usbd_msg_pub_device(struct usbd_context *const ctx,
129
133
};
130
134
131
135
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
+ }
133
141
}
134
142
}
You can’t perform that action at this time.
0 commit comments