Skip to content

Commit 7ba2ba9

Browse files
Tryton77nordicjm
authored andcommitted
st25r3911b: Fixed wrong spinlock ussage
Fixed spinlock ussage with the blocking SPI API, using mutex instead. JIRA: NCSDK-35618 Signed-off-by: Michał Strządała <[email protected]>
1 parent 79b2e77 commit 7ba2ba9

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

lib/st25r3911b/st25r3911b_interrupt.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include <zephyr/device.h>
99
#include <soc.h>
1010
#include <zephyr/drivers/gpio.h>
11-
#include <zephyr/spinlock.h>
1211
#include <zephyr/logging/log.h>
1312

1413
#include "st25r3911b_reg.h"
@@ -26,7 +25,7 @@ static const struct gpio_dt_spec irq_gpio =
2625

2726
static struct gpio_callback gpio_cb;
2827

29-
static struct k_spinlock spinlock;
28+
static K_MUTEX_DEFINE(irq_modify_lock);
3029
static struct k_sem *sem;
3130

3231
static uint32_t irq_mask;
@@ -114,9 +113,12 @@ int st25r3911b_irq_modify(uint32_t clr_mask, uint32_t set_mask)
114113
int err = 0;
115114
uint32_t mask;
116115
uint32_t old_mask;
117-
k_spinlock_key_t key;
118116

119-
key = k_spin_lock(&spinlock);
117+
err = k_mutex_lock(&irq_modify_lock, K_NO_WAIT);
118+
if (err) {
119+
LOG_DBG("Failed to lock irq_modify mutex (err %d)", err);
120+
return err;
121+
}
120122

121123
old_mask = irq_mask;
122124
mask = (~old_mask & set_mask) | (old_mask & clr_mask);
@@ -140,7 +142,10 @@ int st25r3911b_irq_modify(uint32_t clr_mask, uint32_t set_mask)
140142
}
141143
}
142144

143-
k_spin_unlock(&spinlock, key);
145+
err = k_mutex_unlock(&irq_modify_lock);
146+
if (err) {
147+
LOG_DBG("Failed to unlock irq_modify mutex (err %d)", err);
148+
}
144149

145150
LOG_DBG("Interrupts modified, current state %u", old_mask);
146151

0 commit comments

Comments
 (0)