Skip to content

Commit 1c2d692

Browse files
jfischer-nofabiobaltieri
authored andcommitted
usb: device_next: use system workqueue in CDC ACM by default
Add Kconfig option to use dedicated workqueue in CDC ACM but use the system work queue in CDC ACM by default. Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
1 parent 6ea0603 commit 1c2d692

File tree

3 files changed

+55
-17
lines changed

3 files changed

+55
-17
lines changed

samples/subsys/usb/cdc_acm/sample.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,19 @@ tests:
3030
type: one_line
3131
regex:
3232
- "Wait for DTR"
33+
sample.usb_device_next.cdc-acm-workqueue:
34+
depends_on: usbd
35+
tags: usb
36+
extra_args:
37+
- CONF_FILE="usbd_next_prj.conf"
38+
- DCONFIG_USBD_CDC_ACM_WORKQUEUE=y
39+
integration_platforms:
40+
- frdm_k64f
41+
harness: console
42+
harness_config:
43+
type: one_line
44+
regex:
45+
- "Wait for DTR"
3346
sample.usb.cdc-acm.buildonly:
3447
depends_on: usb_device
3548
tags: usb

subsys/usb/device_next/class/Kconfig.cdc_acm

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,15 @@ config USBD_CDC_ACM_CLASS
1616

1717
if USBD_CDC_ACM_CLASS
1818

19+
config USBD_CDC_ACM_WORKQUEUE
20+
bool "Use dedicated workqueue in CDC ACM"
21+
help
22+
Use the dedicated queue in CDC ACM implementation if the systemwork
23+
queue cannot be used due to performance issues or other conflicts.
24+
1925
config USBD_CDC_ACM_STACK_SIZE
2026
int "USB CDC ACM workqueue stack size"
27+
depends on USBD_CDC_ACM_WORKQUEUE
2128
default 1024
2229
help
2330
USB CDC ACM workqueue stack size.

subsys/usb/device_next/class/usbd_cdc_acm.c

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,6 @@ UDC_BUF_POOL_DEFINE(cdc_acm_ep_pool,
5151
#define CDC_ACM_RX_FIFO_BUSY 4
5252
#define CDC_ACM_TX_FIFO_BUSY 5
5353

54-
static struct k_work_q cdc_acm_work_q;
55-
static K_KERNEL_STACK_DEFINE(cdc_acm_stack,
56-
CONFIG_USBD_CDC_ACM_STACK_SIZE);
57-
5854
struct cdc_acm_uart_fifo {
5955
struct ring_buf *rb;
6056
bool irq;
@@ -148,6 +144,24 @@ struct net_buf *cdc_acm_buf_alloc(const uint8_t ep)
148144
return buf;
149145
}
150146

147+
#if CONFIG_USBD_CDC_ACM_WORKQUEUE
148+
static struct k_work_q cdc_acm_work_q;
149+
static K_KERNEL_STACK_DEFINE(cdc_acm_stack,
150+
CONFIG_USBD_CDC_ACM_STACK_SIZE);
151+
152+
static int usbd_cdc_acm_init_wq(void)
153+
{
154+
k_work_queue_init(&cdc_acm_work_q);
155+
k_work_queue_start(&cdc_acm_work_q, cdc_acm_stack,
156+
K_KERNEL_STACK_SIZEOF(cdc_acm_stack),
157+
CONFIG_SYSTEM_WORKQUEUE_PRIORITY, NULL);
158+
k_thread_name_set(&cdc_acm_work_q.thread, "cdc_acm_work_q");
159+
160+
return 0;
161+
}
162+
163+
SYS_INIT(usbd_cdc_acm_init_wq, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT);
164+
151165
static ALWAYS_INLINE int cdc_acm_work_submit(struct k_work *work)
152166
{
153167
return k_work_submit_to_queue(&cdc_acm_work_q, work);
@@ -164,6 +178,23 @@ static ALWAYS_INLINE bool check_wq_ctx(const struct device *dev)
164178
return k_current_get() == k_work_queue_thread_get(&cdc_acm_work_q);
165179
}
166180

181+
#else /* Use system workqueue */
182+
183+
static ALWAYS_INLINE int cdc_acm_work_submit(struct k_work *work)
184+
{
185+
return k_work_submit(work);
186+
}
187+
188+
static ALWAYS_INLINE int cdc_acm_work_schedule(struct k_work_delayable *work,
189+
k_timeout_t delay)
190+
{
191+
return k_work_schedule(work, delay);
192+
}
193+
194+
#define check_wq_ctx(dev) true
195+
196+
#endif /* CONFIG_USBD_CDC_ACM_WORKQUEUE */
197+
167198
static uint8_t cdc_acm_get_int_in(struct usbd_class_data *const c_data)
168199
{
169200
struct usbd_context *uds_ctx = usbd_class_get_ctx(c_data);
@@ -1066,17 +1097,6 @@ static int cdc_acm_config_get(const struct device *dev,
10661097
}
10671098
#endif /* CONFIG_UART_USE_RUNTIME_CONFIGURE */
10681099

1069-
static int usbd_cdc_acm_init_wq(void)
1070-
{
1071-
k_work_queue_init(&cdc_acm_work_q);
1072-
k_work_queue_start(&cdc_acm_work_q, cdc_acm_stack,
1073-
K_KERNEL_STACK_SIZEOF(cdc_acm_stack),
1074-
CONFIG_SYSTEM_WORKQUEUE_PRIORITY, NULL);
1075-
k_thread_name_set(&cdc_acm_work_q.thread, "cdc_acm_work_q");
1076-
1077-
return 0;
1078-
}
1079-
10801100
static int usbd_cdc_acm_preinit(const struct device *dev)
10811101
{
10821102
struct cdc_acm_uart_data *const data = dev->data;
@@ -1329,5 +1349,3 @@ const static struct usb_desc_header *cdc_acm_hs_desc_##n[] = { \
13291349
&cdc_acm_uart_api);
13301350

13311351
DT_INST_FOREACH_STATUS_OKAY(USBD_CDC_ACM_DT_DEVICE_DEFINE);
1332-
1333-
SYS_INIT(usbd_cdc_acm_init_wq, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT);

0 commit comments

Comments
 (0)