Skip to content

Commit de0d8b9

Browse files
vbrzeskihenrikbrixandersen
authored andcommitted
usb: device_next: cdc_acm: switch irq_lock to spinlock
Change the irq_lock to a spinlock to be more semantically correct. Signed-off-by: Victor Brzeski <[email protected]>
1 parent 68be678 commit de0d8b9

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

subsys/usb/device_next/class/usbd_cdc_acm.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <zephyr/init.h>
1010
#include <zephyr/kernel.h>
1111
#include <zephyr/drivers/uart.h>
12+
#include <zephyr/spinlock.h>
1213
#include <zephyr/sys/ring_buffer.h>
1314
#include <zephyr/sys/byteorder.h>
1415

@@ -123,6 +124,7 @@ struct cdc_acm_uart_data {
123124
struct k_work rx_fifo_work;
124125
atomic_t state;
125126
struct k_sem notif_sem;
127+
struct k_spinlock lock;
126128
};
127129

128130
static void cdc_acm_irq_rx_enable(const struct device *dev);
@@ -770,7 +772,7 @@ static int cdc_acm_fifo_fill(const struct device *dev,
770772
const int len)
771773
{
772774
struct cdc_acm_uart_data *const data = dev->data;
773-
unsigned int lock;
775+
k_spinlock_key_t key;
774776
uint32_t done;
775777

776778
if (!check_wq_ctx(dev)) {
@@ -779,9 +781,9 @@ static int cdc_acm_fifo_fill(const struct device *dev,
779781
return 0;
780782
}
781783

782-
lock = irq_lock();
784+
key = k_spin_lock(&data->lock);
783785
done = ring_buf_put(data->tx_fifo.rb, tx_data, len);
784-
irq_unlock(lock);
786+
k_spin_unlock(&data->lock, key);
785787
if (done) {
786788
data->tx_fifo.altered = true;
787789
}
@@ -989,13 +991,13 @@ static int cdc_acm_poll_in(const struct device *dev, unsigned char *const c)
989991
static void cdc_acm_poll_out(const struct device *dev, const unsigned char c)
990992
{
991993
struct cdc_acm_uart_data *const data = dev->data;
992-
unsigned int lock;
994+
k_spinlock_key_t key;
993995
uint32_t wrote;
994996

995997
while (true) {
996-
lock = irq_lock();
998+
key = k_spin_lock(&data->lock);
997999
wrote = ring_buf_put(data->tx_fifo.rb, &c, 1);
998-
irq_unlock(lock);
1000+
k_spin_unlock(&data->lock, key);
9991001

10001002
if (wrote == 1) {
10011003
break;

0 commit comments

Comments
 (0)