Skip to content

Commit 44ea65c

Browse files
committed
Move critical section out of Storage::writeResource()
1 parent fe6eff4 commit 44ea65c

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

Source/MidiHandler.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "Storage.h"
1717
#ifndef USE_BOOTLOADER_MODE
1818
#include "BootloaderStorage.h"
19+
#include "cmsis_os.h"
1920
#endif
2021
#ifdef USE_DIGITALBUS
2122
#include "bus.h"
@@ -275,7 +276,13 @@ void MidiHandler::handleSettingsResetCommand(uint8_t* data, uint16_t size){
275276
}
276277

277278
void MidiHandler::handleSettingsStoreCommand(uint8_t* data, uint16_t size){
279+
#ifndef USE_BOOTLOADER_MODE
280+
UBaseType_t uxSavedInterruptStatus = taskENTER_CRITICAL_FROM_ISR();
281+
#endif
278282
settings.saveToFlash();
283+
#ifndef USE_BOOTLOADER_MODE
284+
taskEXIT_CRITICAL_FROM_ISR(uxSavedInterruptStatus);
285+
#endif
279286
}
280287

281288
void MidiHandler::handleFirmwareUploadCommand(uint8_t* data, uint16_t size){

Source/ProgramManager.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,8 +467,10 @@ void programFlashTask(void* p){
467467
}
468468
}else{
469469
ResourceHeader* header = (ResourceHeader*)flashAddressToWrite;
470+
taskENTER_CRITICAL();
470471
storage.writeResource(header);
471472
registry.init();
473+
taskEXIT_CRITICAL();
472474
if(index == 0){
473475
onResourceUpdate();
474476
}else{

Source/Storage.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -381,9 +381,6 @@ size_t Storage::writeResource(ResourceHeader* header){
381381
error(FLASH_ERROR, "No free resources");
382382
return 0;
383383
}
384-
#ifndef USE_BOOTLOADER_MODE
385-
taskENTER_CRITICAL();
386-
#endif
387384
int status = -1;
388385
if(dest->isMemoryMapped()){
389386
#ifdef USE_FLASH
@@ -402,9 +399,6 @@ size_t Storage::writeResource(ResourceHeader* header){
402399
error(FLASH_ERROR, "Readback failed");
403400
#endif
404401
}
405-
#ifndef USE_BOOTLOADER_MODE
406-
taskEXIT_CRITICAL();
407-
#endif
408402
if(status){
409403
error(FLASH_ERROR, "Write failed");
410404
}else if(dest->getTotalSize() < length){ // allow for storage-specific alignment

0 commit comments

Comments
 (0)