47
47
48
48
static ramBufferDescriptor * ramDescr = NULL ;
49
49
static osaMutexId_t pdmMutexHandle = NULL ;
50
+ static bool_t pdmMutexTaken = FALSE;
50
51
51
52
#if PDM_SAVE_IDLE
52
53
static bool_t settingsInitialized = FALSE;
@@ -130,11 +131,13 @@ void otPlatSettingsDeinit(otInstance *aInstance)
130
131
131
132
#if ENABLE_STORAGE_DYNAMIC_MEMORY
132
133
mutex_lock (pdmMutexHandle , osaWaitForever_c );
134
+ pdmMutexTaken = TRUE;
133
135
if (ramDescr -> buffer )
134
136
{
135
137
otPlatFree (ramDescr -> buffer );
136
138
ramDescr -> buffer = NULL ;
137
139
}
140
+ pdmMutexTaken = FALSE;
138
141
mutex_unlock (pdmMutexHandle );
139
142
mutex_destroy (pdmMutexHandle );
140
143
@@ -148,9 +151,20 @@ otError otPlatSettingsGet(otInstance *aInstance, uint16_t aKey, int aIndex, uint
148
151
OT_UNUSED_VARIABLE (aInstance );
149
152
rsError ramStatus = RS_ERROR_NONE ;
150
153
151
- mutex_lock (pdmMutexHandle , osaWaitForever_c );
154
+ if (!OSA_InIsrContext ())
155
+ {
156
+ mutex_lock (pdmMutexHandle , osaWaitForever_c );
157
+ pdmMutexTaken = TRUE;
158
+ }
159
+
152
160
ramStatus = ramStorageGet (ramDescr , aKey , aIndex , aValue , aValueLength );
153
- mutex_unlock (pdmMutexHandle );
161
+
162
+ if (!OSA_InIsrContext ())
163
+ {
164
+ pdmMutexTaken = FALSE;
165
+ mutex_unlock (pdmMutexHandle );
166
+ }
167
+
154
168
return mapRamStorageStatus (ramStatus );
155
169
}
156
170
@@ -165,7 +179,11 @@ otError otPlatSettingsSet(otInstance *aInstance, uint16_t aKey, const uint8_t *a
165
179
uint16_t lengthOfAlreadyExistingValue = 0 ;
166
180
#endif
167
181
168
- mutex_lock (pdmMutexHandle , osaWaitForever_c );
182
+ if (!OSA_InIsrContext ())
183
+ {
184
+ mutex_lock (pdmMutexHandle , osaWaitForever_c );
185
+ pdmMutexTaken = TRUE;
186
+ }
169
187
170
188
#if ENABLE_STORAGE_DYNAMIC_MEMORY
171
189
/* avoid resizing in case ramDescr already contains aValue whose length is >= aValueLength */
@@ -183,7 +201,11 @@ otError otPlatSettingsSet(otInstance *aInstance, uint16_t aKey, const uint8_t *a
183
201
otEXPECT_ACTION ((PDM_E_STATUS_OK == pdmStatus ), error = OT_ERROR_NO_BUFS );
184
202
185
203
exit :
186
- mutex_unlock (pdmMutexHandle );
204
+ if (!OSA_InIsrContext ())
205
+ {
206
+ pdmMutexTaken = FALSE;
207
+ mutex_unlock (pdmMutexHandle );
208
+ }
187
209
return error ;
188
210
}
189
211
@@ -194,6 +216,7 @@ otError otPlatSettingsAdd(otInstance *aInstance, uint16_t aKey, const uint8_t *a
194
216
otError error = OT_ERROR_NONE ;
195
217
196
218
mutex_lock (pdmMutexHandle , osaWaitForever_c );
219
+ pdmMutexTaken = TRUE;
197
220
198
221
#if ENABLE_STORAGE_DYNAMIC_MEMORY
199
222
ramStatus = ramStorageResize (ramDescr , aKey , aValue , aValueLength );
@@ -206,6 +229,7 @@ otError otPlatSettingsAdd(otInstance *aInstance, uint16_t aKey, const uint8_t *a
206
229
otEXPECT_ACTION ((PDM_E_STATUS_OK == pdmStatus ), error = OT_ERROR_NO_BUFS );
207
230
208
231
exit :
232
+ pdmMutexTaken = FALSE;
209
233
mutex_unlock (pdmMutexHandle );
210
234
return error ;
211
235
}
@@ -218,13 +242,15 @@ otError otPlatSettingsDelete(otInstance *aInstance, uint16_t aKey, int aIndex)
218
242
otError error = OT_ERROR_NONE ;
219
243
220
244
mutex_lock (pdmMutexHandle , osaWaitForever_c );
221
- ramStatus = ramStorageDelete (ramDescr , aKey , aIndex );
245
+ pdmMutexTaken = TRUE;
246
+ ramStatus = ramStorageDelete (ramDescr , aKey , aIndex );
222
247
otEXPECT_ACTION ((RS_ERROR_NONE == ramStatus ), error = mapRamStorageStatus (ramStatus ));
223
248
224
249
pdmStatus = PDM_SaveRecord ((uint16_t )kNvmIdOTConfigData , ramDescr );
225
250
otEXPECT_ACTION ((PDM_E_STATUS_OK == pdmStatus ), error = OT_ERROR_NO_BUFS );
226
251
227
252
exit :
253
+ pdmMutexTaken = FALSE;
228
254
mutex_unlock (pdmMutexHandle );
229
255
return error ;
230
256
}
@@ -234,13 +260,24 @@ void otPlatSettingsWipe(otInstance *aInstance)
234
260
OT_UNUSED_VARIABLE (aInstance );
235
261
236
262
mutex_lock (pdmMutexHandle , osaWaitForever_c );
263
+ pdmMutexTaken = TRUE;
237
264
memset (ramDescr -> buffer , 0 , ramDescr -> header .maxLength );
238
265
ramDescr -> header .length = 0 ;
239
266
PDM_vDeleteDataRecord (kNvmIdOTConfigData );
267
+ pdmMutexTaken = FALSE;
240
268
mutex_unlock (pdmMutexHandle );
241
269
}
242
270
243
271
#if gRadioUsePdm_d && PDM_SAVE_IDLE
272
+
273
+ /* in case BLE ISR tries to do a recalibration, make sure that the Ram Buffer Mutex is not
274
+ * taken, otherwise execution will be stuck in a FreeRtos assert.
275
+ */
276
+ bool should_skip_recal ()
277
+ {
278
+ return (OSA_InIsrContext () && pdmMutexTaken && idleMutexIsTaken ());
279
+ }
280
+
244
281
bool bRadioCB_WriteNVM (uint8_t * pu8DataBlock , uint16_t u16Len )
245
282
{
246
283
return (otPlatSettingsSet (NULL , PDM_ID_RADIO_SETTINGS , pu8DataBlock , u16Len ) == OT_ERROR_NONE );
0 commit comments