Skip to content

Commit ae4d38e

Browse files
committed
drivers: flash: RRAM nonblocking writes
removes while loop in driver. Signed-off-by: Mateusz Michalek <[email protected]>
1 parent 2ccb892 commit ae4d38e

File tree

2 files changed

+33
-24
lines changed

2 files changed

+33
-24
lines changed

drivers/flash/soc_flash_nrf_rram.c

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ LOG_MODULE_REGISTER(flash_nrf_rram, CONFIG_FLASH_LOG_LEVEL);
5656
#define ERASE_VALUE 0xFF
5757
#define WRITE_LINE_SIZE WRITE_BLOCK_SIZE_FROM_DT
5858

59+
static volatile bool write_busy;
60+
5961
static inline bool is_aligned_32(uint32_t data)
6062
{
6163
return (data & 0x3) ? false : true;
@@ -88,6 +90,18 @@ static int nrf_rram_read(const struct device *dev, off_t addr, void *data, size_
8890
return 0;
8991
}
9092

93+
void rrw_done(void)
94+
{
95+
uint32_t pm = __get_PRIMASK();
96+
97+
__disable_irq();
98+
write_busy = false;
99+
if (!pm) {
100+
__enable_irq();
101+
}
102+
barrier_dmem_fence_full(); /* Barrier following our last write. */
103+
}
104+
91105
static int nrf_rram_write(const struct device *dev, off_t addr, const void *data, size_t len)
92106
{
93107
int ret = 0;
@@ -113,6 +127,18 @@ static int nrf_rram_write(const struct device *dev, off_t addr, const void *data
113127
return 0;
114128
}
115129

130+
uint32_t pm = __get_PRIMASK();
131+
132+
__disable_irq();
133+
if (write_busy) {
134+
if (!pm) {
135+
__enable_irq();
136+
}
137+
return -EBUSY;
138+
}
139+
if (!pm) {
140+
__enable_irq();
141+
}
116142
LOG_DBG("Write: %p: %zu", (void *)addr, len);
117143

118144
ret = sd_flash_write((uint32_t *)addr, data, len / sizeof(uint32_t));
@@ -121,30 +147,6 @@ static int nrf_rram_write(const struct device *dev, off_t addr, const void *data
121147
return -EIO;
122148
}
123149

124-
while (1) {
125-
int taskid;
126-
127-
/* Wait for an event. */
128-
__WFE();
129-
130-
/* Clear Event Register */
131-
__SEV();
132-
__WFE();
133-
134-
ret = sd_evt_get(&taskid);
135-
136-
if (!ret && (taskid == NRF_EVT_FLASH_OPERATION_SUCCESS ||
137-
taskid == NRF_EVT_FLASH_OPERATION_ERROR)) {
138-
if (taskid != NRF_EVT_FLASH_OPERATION_SUCCESS) {
139-
ret = -EIO;
140-
}
141-
142-
break;
143-
}
144-
}
145-
146-
barrier_dmem_fence_full(); /* Barrier following our last write. */
147-
148150
return ret;
149151
}
150152

subsys/softdevice_handler/nrf_sdh_soc.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ const char *nrf_sdh_soc_evt_to_str(uint32_t evt)
5151
}
5252
}
5353

54+
void rrw_done(void);
55+
5456
static void soc_evt_poll(void *context)
5557
{
5658
uint32_t nrf_err;
@@ -64,6 +66,11 @@ static void soc_evt_poll(void *context)
6466

6567
LOG_DBG("%s", nrf_sdh_soc_evt_to_str(evt_id));
6668

69+
if (evt_id == NRF_EVT_FLASH_OPERATION_SUCCESS) {
70+
#if defined(CONFIG_SOC_FLASH_NRF_RRAM_BM)
71+
rrw_done();
72+
#endif
73+
}
6774
/* Forward the event to SoC observers. */
6875
TYPE_SECTION_FOREACH(
6976
struct nrf_sdh_soc_evt_observer, nrf_sdh_soc_evt_observers, obs) {

0 commit comments

Comments
 (0)