12
12
#include <zephyr/drivers/flash.h>
13
13
#include <zephyr/logging/log.h>
14
14
#include <zephyr/irq.h>
15
+ #include <zephyr/sys/__assert.h>
15
16
#include <zephyr/sys/barrier.h>
16
17
#include <hal/nrf_rramc.h>
17
18
#include "nrf_soc.h"
@@ -88,6 +89,28 @@ static int nrf_rram_read(const struct device *dev, off_t addr, void *data, size_
88
89
return 0 ;
89
90
}
90
91
92
+ #if defined(CONFIG_NRF_SDH_SOC )
93
+ static enum flash_status {
94
+ FLASH_STATUS_READY ,
95
+ FLASH_STATUS_PENDING ,
96
+ FLASH_STATUS_DONE ,
97
+ FLASH_STATUS_ERROR ,
98
+ } flash_status = FLASH_STATUS_READY ;
99
+
100
+ static void soc_evt_flash_handler (uint32_t evt_id , void * context )
101
+ {
102
+ __ASSERT_NO_MSG (flash_op_status == FLASH_OP_STATUS_PENDING );
103
+
104
+ if (evt_id == NRF_EVT_FLASH_OPERATION_SUCCESS ) {
105
+ flash_status = FLASH_STATUS_DONE ;
106
+ } else if (evt_id == NRF_EVT_FLASH_OPERATION_ERROR ) {
107
+ flash_status = FLASH_STATUS_ERROR ;
108
+ }
109
+ }
110
+
111
+ NRF_SDH_SOC_OBSERVER (soc_evt_flash_obs , soc_evt_flash_handler , NULL , 0 );
112
+ #endif
113
+
91
114
static int nrf_rram_write (const struct device * dev , off_t addr , const void * data , size_t len )
92
115
{
93
116
int ret = 0 ;
@@ -115,16 +138,32 @@ static int nrf_rram_write(const struct device *dev, off_t addr, const void *data
115
138
116
139
LOG_DBG ("Write: %p: %zu" , (void * )addr , len );
117
140
141
+ #if defined(CONFIG_NRF_SDH_SOC )
142
+ __ASSERT_NO_MSG (flash_op_status == FLASH_OP_STATUS_READY );
143
+ flash_status = FLASH_STATUS_PENDING ;
144
+ #endif
145
+
118
146
ret = sd_flash_write ((uint32_t * )addr , data , len / sizeof (uint32_t ));
119
147
120
148
if (ret ) {
149
+ #if defined(CONFIG_NRF_SDH_SOC )
150
+ flash_status = FLASH_STATUS_READY ;
151
+ #endif
121
152
return - EIO ;
122
153
}
123
154
124
155
while (1 ) {
156
+ sd_app_evt_wait ();
157
+
158
+ #if defined(CONFIG_NRF_SDH_SOC )
159
+ if (flash_status != FLASH_STATUS_PENDING ) {
160
+ ret = (flash_status == FLASH_STATUS_DONE ) ? 0 : - EIO ;
161
+ flash_status = FLASH_STATUS_READY ;
162
+ break ;
163
+ }
164
+ #else
125
165
int taskid ;
126
166
127
- sd_app_evt_wait ();
128
167
ret = sd_evt_get (& taskid );
129
168
130
169
if (!ret && (taskid == NRF_EVT_FLASH_OPERATION_SUCCESS ||
@@ -135,6 +174,7 @@ static int nrf_rram_write(const struct device *dev, off_t addr, const void *data
135
174
136
175
break ;
137
176
}
177
+ #endif
138
178
}
139
179
140
180
barrier_dmem_fence_full (); /* Barrier following our last write. */
0 commit comments