Skip to content

Commit cb24e3c

Browse files
Klaus H. SorensenMaureenHelm
authored andcommitted
canbus: canopen: program: unlock can od during flash access
The callback function canopen_odf_1f56 is called with the can od lock held. Release the lock while performing time consuming flash reading and crc calculations, and reacquire the lock before returning from the function. Signed-off-by: Klaus H. Sorensen <[email protected]>
1 parent 945dc6e commit cb24e3c

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

subsys/canbus/canopen/canopen_program.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,14 @@ static CO_SDO_abortCode_t canopen_odf_1f56(CO_ODF_arg_t *odf_arg)
298298
return CO_SDO_AB_READONLY;
299299
}
300300

301+
/* Reading from flash and calculating crc can take 100ms or more, and
302+
* this function is called with the can od lock taken.
303+
*
304+
* Release the lock before performing time consuming work, and reacquire
305+
* before return.
306+
*/
307+
CO_UNLOCK_OD();
308+
301309
/*
302310
* Calculate the CRC32 of the image that is running or will be
303311
* started upon receiveing the next 'start' command.
@@ -312,13 +320,17 @@ static CO_SDO_abortCode_t canopen_odf_1f56(CO_ODF_arg_t *odf_arg)
312320
if (err) {
313321
LOG_WRN("failed to read bank header (err %d)", err);
314322
CO_setUint32(odf_arg->data, 0U);
323+
324+
CO_LOCK_OD();
315325
return CO_SDO_AB_NONE;
316326
}
317327

318328
if (header.mcuboot_version != 1) {
319329
LOG_WRN("unsupported mcuboot header version %d",
320330
header.mcuboot_version);
321331
CO_setUint32(odf_arg->data, 0U);
332+
333+
CO_LOCK_OD();
322334
return CO_SDO_AB_NONE;
323335
}
324336
len = header.h.v1.image_size;
@@ -328,6 +340,8 @@ static CO_SDO_abortCode_t canopen_odf_1f56(CO_ODF_arg_t *odf_arg)
328340
LOG_ERR("failed to open flash area (err %d)", err);
329341
CO_errorReport(ctx.em, CO_EM_NON_VOLATILE_MEMORY,
330342
CO_EMC_HARDWARE, err);
343+
344+
CO_LOCK_OD();
331345
return CO_SDO_AB_HW;
332346
}
333347

@@ -339,6 +353,8 @@ static CO_SDO_abortCode_t canopen_odf_1f56(CO_ODF_arg_t *odf_arg)
339353
CO_errorReport(ctx.em, CO_EM_NON_VOLATILE_MEMORY,
340354
CO_EMC_HARDWARE, err);
341355
flash_area_close(flash_area);
356+
357+
CO_LOCK_OD();
342358
return CO_SDO_AB_HW;
343359
}
344360

@@ -351,6 +367,7 @@ static CO_SDO_abortCode_t canopen_odf_1f56(CO_ODF_arg_t *odf_arg)
351367

352368
CO_setUint32(odf_arg->data, crc);
353369

370+
CO_LOCK_OD();
354371
return CO_SDO_AB_NONE;
355372
}
356373
#endif /* CONFIG_BOOTLOADER_MCUBOOT */

0 commit comments

Comments
 (0)