Skip to content

Commit bc33ef4

Browse files
pabigotnashif
authored andcommitted
drivers: flash: nrf_qspi_nor: remove multithreading dependency
Replace semaphores with an atomic ready flag when used without multithreading enabled. Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
1 parent ca08cc0 commit bc33ef4

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

drivers/flash/Kconfig.nordic_qspi_nor

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ menuconfig NORDIC_QSPI_NOR
66
select FLASH_HAS_DRIVER_ENABLED
77
select NRFX_QSPI
88
depends on HAS_HW_NRF_QSPI
9-
depends on MULTITHREADING
109
help
1110
Enable support for nrfx QSPI driver with EasyDMA.
1211

drivers/flash/nrf_qspi_nor.c

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,22 @@ struct qspi_cmd {
8282

8383
/**
8484
* @brief Structure for defining the QSPI NOR access
85-
* @param sem The semaphore to access to the flash
86-
* @param sync The semaphore to ensure that transfer has finished
87-
* @param write_protection Indicates if write protection for flash
88-
* device is enabled
8985
*/
9086
struct qspi_nor_data {
87+
#ifdef CONFIG_MULTITHREADING
88+
/* The semaphore to control exclusive access to the device. */
9189
struct k_sem sem;
90+
/* The semaphore to indicate that transfer has completed. */
9291
struct k_sem sync;
92+
#else /* CONFIG_MULTITHREADING */
93+
/* A flag that signals completed transfer when threads are
94+
* not enabled.
95+
*/
96+
volatile bool ready;
97+
#endif /* CONFIG_MULTITHREADING */
98+
/* Indicates if write protection for flash device is
99+
* enabled.
100+
*/
93101
bool write_protection;
94102
};
95103

@@ -194,8 +202,10 @@ static inline nrf_qspi_addrmode_t qspi_get_address_size(bool addr_size)
194202
* @brief Main configuration structure
195203
*/
196204
static struct qspi_nor_data qspi_nor_memory_data = {
205+
#ifdef CONFIG_MULTITHREADING
197206
.sem = Z_SEM_INITIALIZER(qspi_nor_memory_data.sem, 1, 1),
198207
.sync = Z_SEM_INITIALIZER(qspi_nor_memory_data.sync, 0, 1),
208+
#endif /* CONFIG_MULTITHREADING */
199209
};
200210

201211
/**
@@ -225,16 +235,24 @@ static inline struct qspi_nor_data *get_dev_data(const struct device *dev)
225235

226236
static inline void qspi_lock(const struct device *dev)
227237
{
238+
#ifdef CONFIG_MULTITHREADING
228239
struct qspi_nor_data *dev_data = get_dev_data(dev);
229240

230241
k_sem_take(&dev_data->sem, K_FOREVER);
242+
#else /* CONFIG_MULTITHREADING */
243+
ARG_UNUSED(dev);
244+
#endif /* CONFIG_MULTITHREADING */
231245
}
232246

233247
static inline void qspi_unlock(const struct device *dev)
234248
{
249+
#ifdef CONFIG_MULTITHREADING
235250
struct qspi_nor_data *dev_data = get_dev_data(dev);
236251

237252
k_sem_give(&dev_data->sem);
253+
#else /* CONFIG_MULTITHREADING */
254+
ARG_UNUSED(dev);
255+
#endif /* CONFIG_MULTITHREADING */
238256
}
239257

240258
static inline void qspi_wait_for_completion(const struct device *dev,
@@ -243,13 +261,28 @@ static inline void qspi_wait_for_completion(const struct device *dev,
243261
struct qspi_nor_data *dev_data = get_dev_data(dev);
244262

245263
if (res == NRFX_SUCCESS) {
264+
#ifdef CONFIG_MULTITHREADING
246265
k_sem_take(&dev_data->sync, K_FOREVER);
266+
#else /* CONFIG_MULTITHREADING */
267+
unsigned int key = irq_lock();
268+
269+
while (!dev_data->ready) {
270+
k_cpu_atomic_idle(key);
271+
key = irq_lock();
272+
}
273+
dev_data->ready = false;
274+
irq_unlock(key);
275+
#endif /* CONFIG_MULTITHREADING */
247276
}
248277
}
249278

250279
static inline void qspi_complete(struct qspi_nor_data *dev_data)
251280
{
281+
#ifdef CONFIG_MULTITHREADING
252282
k_sem_give(&dev_data->sync);
283+
#else /* CONFIG_MULTITHREADING */
284+
dev_data->ready = true;
285+
#endif /* CONFIG_MULTITHREADING */
253286
}
254287

255288
/**

0 commit comments

Comments
 (0)