From cb24e3c22ec705f4dcbe5e741b3a36ac99f7b6c0 Mon Sep 17 00:00:00 2001 From: "Klaus H. Sorensen" Date: Fri, 15 Jan 2021 12:46:53 +0100 Subject: [PATCH] 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 --- subsys/canbus/canopen/canopen_program.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/subsys/canbus/canopen/canopen_program.c b/subsys/canbus/canopen/canopen_program.c index f1ee0d1127e..ce6539a36b6 100644 --- a/subsys/canbus/canopen/canopen_program.c +++ b/subsys/canbus/canopen/canopen_program.c @@ -298,6 +298,14 @@ static CO_SDO_abortCode_t canopen_odf_1f56(CO_ODF_arg_t *odf_arg) return CO_SDO_AB_READONLY; } + /* Reading from flash and calculating crc can take 100ms or more, and + * this function is called with the can od lock taken. + * + * Release the lock before performing time consuming work, and reacquire + * before return. + */ + CO_UNLOCK_OD(); + /* * Calculate the CRC32 of the image that is running or will be * started upon receiveing the next 'start' command. @@ -312,6 +320,8 @@ static CO_SDO_abortCode_t canopen_odf_1f56(CO_ODF_arg_t *odf_arg) if (err) { LOG_WRN("failed to read bank header (err %d)", err); CO_setUint32(odf_arg->data, 0U); + + CO_LOCK_OD(); return CO_SDO_AB_NONE; } @@ -319,6 +329,8 @@ static CO_SDO_abortCode_t canopen_odf_1f56(CO_ODF_arg_t *odf_arg) LOG_WRN("unsupported mcuboot header version %d", header.mcuboot_version); CO_setUint32(odf_arg->data, 0U); + + CO_LOCK_OD(); return CO_SDO_AB_NONE; } len = header.h.v1.image_size; @@ -328,6 +340,8 @@ static CO_SDO_abortCode_t canopen_odf_1f56(CO_ODF_arg_t *odf_arg) LOG_ERR("failed to open flash area (err %d)", err); CO_errorReport(ctx.em, CO_EM_NON_VOLATILE_MEMORY, CO_EMC_HARDWARE, err); + + CO_LOCK_OD(); return CO_SDO_AB_HW; } @@ -339,6 +353,8 @@ static CO_SDO_abortCode_t canopen_odf_1f56(CO_ODF_arg_t *odf_arg) CO_errorReport(ctx.em, CO_EM_NON_VOLATILE_MEMORY, CO_EMC_HARDWARE, err); flash_area_close(flash_area); + + CO_LOCK_OD(); return CO_SDO_AB_HW; } @@ -351,6 +367,7 @@ static CO_SDO_abortCode_t canopen_odf_1f56(CO_ODF_arg_t *odf_arg) CO_setUint32(odf_arg->data, crc); + CO_LOCK_OD(); return CO_SDO_AB_NONE; } #endif /* CONFIG_BOOTLOADER_MCUBOOT */