9
9
#include <zephyr/init.h>
10
10
#include <zephyr/kernel.h>
11
11
#include <zephyr/drivers/uart.h>
12
+ #include <zephyr/spinlock.h>
12
13
#include <zephyr/sys/ring_buffer.h>
13
14
#include <zephyr/sys/byteorder.h>
14
15
@@ -123,6 +124,7 @@ struct cdc_acm_uart_data {
123
124
struct k_work rx_fifo_work ;
124
125
atomic_t state ;
125
126
struct k_sem notif_sem ;
127
+ struct k_spinlock lock ;
126
128
};
127
129
128
130
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,
770
772
const int len )
771
773
{
772
774
struct cdc_acm_uart_data * const data = dev -> data ;
773
- unsigned int lock ;
775
+ k_spinlock_key_t key ;
774
776
uint32_t done ;
775
777
776
778
if (!check_wq_ctx (dev )) {
@@ -779,9 +781,9 @@ static int cdc_acm_fifo_fill(const struct device *dev,
779
781
return 0 ;
780
782
}
781
783
782
- lock = irq_lock ( );
784
+ key = k_spin_lock ( & data -> lock );
783
785
done = ring_buf_put (data -> tx_fifo .rb , tx_data , len );
784
- irq_unlock ( lock );
786
+ k_spin_unlock ( & data -> lock , key );
785
787
if (done ) {
786
788
data -> tx_fifo .altered = true;
787
789
}
@@ -989,13 +991,13 @@ static int cdc_acm_poll_in(const struct device *dev, unsigned char *const c)
989
991
static void cdc_acm_poll_out (const struct device * dev , const unsigned char c )
990
992
{
991
993
struct cdc_acm_uart_data * const data = dev -> data ;
992
- unsigned int lock ;
994
+ k_spinlock_key_t key ;
993
995
uint32_t wrote ;
994
996
995
997
while (true) {
996
- lock = irq_lock ( );
998
+ key = k_spin_lock ( & data -> lock );
997
999
wrote = ring_buf_put (data -> tx_fifo .rb , & c , 1 );
998
- irq_unlock ( lock );
1000
+ k_spin_unlock ( & data -> lock , key );
999
1001
1000
1002
if (wrote == 1 ) {
1001
1003
break ;
0 commit comments