Skip to content

Commit ae9d1b4

Browse files
[nrf fromlist] drivers: spi: spi_nrfx_spim: patch to support nothread
The spi_nrfx_spim device driver is used in nothread bootloaders, the wake implementation waits on a k_sem, patch to poll an atomic variable if CONFIG_MULTITHREADING=n Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no> Upstream PR #: 110447
1 parent fbc1377 commit ae9d1b4

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

drivers/spi/spi_nrfx_spim.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ LOG_MODULE_DECLARE(spi_nrfx_spim);
1515
struct driver_data {
1616
struct spi_nrfx_common_data common;
1717
struct spi_context ctx;
18+
#if CONFIG_MULTITHREADING
1819
struct k_sem wake_sem;
20+
#else
21+
atomic_t wake_atom;
22+
#endif
1923
};
2024

2125
struct driver_config {
@@ -83,7 +87,11 @@ static void spim_wake_handler(const struct device *dev)
8387
{
8488
struct driver_data *dev_data = dev->data;
8589

90+
#if CONFIG_MULTITHREADING
8691
k_sem_give(&dev_data->wake_sem);
92+
#else
93+
atomic_set(&dev_data->wake_atom, 1);
94+
#endif
8795
}
8896

8997
static void spim_evt_handler(const struct device *dev, nrfx_spim_event_t *evt)
@@ -129,8 +137,20 @@ static int transceive(const struct device *dev,
129137

130138
dev_data->ctx.config = spi_cfg;
131139

140+
#if CONFIG_MULTITHREADING
141+
k_sem_reset(&dev_data->wake_sem);
142+
#else
143+
atomic_set(&dev_data->wake_atom, 0);
144+
#endif
145+
132146
spi_nrfx_spim_common_wake_start(dev, spim_wake_handler);
147+
148+
#if CONFIG_MULTITHREADING
133149
k_sem_take(&dev_data->wake_sem, K_FOREVER);
150+
#else
151+
while (atomic_get(&dev_data->wake_atom) == 0) {
152+
}
153+
#endif
134154

135155
spi_nrfx_spim_common_cs_set(dev, spi_cfg);
136156
transfer_start(dev);
@@ -213,7 +233,9 @@ static int driver_init(const struct device *dev)
213233
return ret;
214234
}
215235

236+
#if CONFIG_MULTITHREADING
216237
k_sem_init(&dev_data->wake_sem, 0, 1);
238+
#endif
217239

218240
spi_context_unlock_unconditionally(&dev_data->ctx);
219241

0 commit comments

Comments
 (0)