From 829e5627cd7aa116dd55bea22b9cc7ab754d3e39 Mon Sep 17 00:00:00 2001 From: cfif Date: Tue, 14 Apr 2026 16:20:17 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CanUds.c | 13 ++++++++++++- CanUds.h | 12 +++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/CanUds.c b/CanUds.c index 479df77..7e23308 100644 --- a/CanUds.c +++ b/CanUds.c @@ -959,7 +959,14 @@ static uint16_t vUDS_routine_Erase_Memory(tCanUds *env, eUdsRoutineControlType u eUdsRequestRoutineResult udsRequestRoutineResult = UDS_routine_RoutineFinishSuccess; if ((udsRoutineControlType == UDS_routine_StartRoutine) || (udsRoutineControlType == UDS_routine_StopRoutine)) { - env->dataResponse[4] = udsStartStopRoutineResult; + + bool result = env->clear_flash_func(0x01010000, 512 * 1024); + + if (result) { + env->dataResponse[4] = UDS_routine_RoutineStartStopSuccess; + } else { + env->dataResponse[4] = UDS_routine_RoutineStartStopFailure; + } } if (udsRoutineControlType == UDS_routine_RequestRoutineResults) { @@ -1546,6 +1553,8 @@ void CanUds_Init( tDeviceStorage *deviceStorage, tCanSpamTransmitter *canSpamTransmitter, tAdcTask *adcTask0, + uds_clear_flash_func *clear_flash_func, + uds_write_flash_func *write_flash_func, tLoggerInterface *logger) { env->logger = logger; @@ -1555,6 +1564,8 @@ void CanUds_Init( env->adcTask0 = adcTask0; env->filterIdCount = 2; env->canSpamTransmitter = canSpamTransmitter; + env->clear_flash_func = clear_flash_func; + env->write_flash_func = write_flash_func; env->queue = osMessageQueueNew(CAN_US_QUEUE_SIZE, sizeof(tCanTP_data), NULL); setDefaultStatus(); diff --git a/CanUds.h b/CanUds.h index 3fff669..5d74124 100644 --- a/CanUds.h +++ b/CanUds.h @@ -55,7 +55,7 @@ typedef enum { UDS_error_responseTooLong = 0x14, UDS_error_requestOutOfRange = 0x31, UDS_error_securityAccessDenied = 0x33, - UDS_error_invalidKey= 0x35, + UDS_error_invalidKey = 0x35, UDS_error_sub_functionNotSupported = 0x12, UDS_error_conditionsNotCorrect = 0x22, UDS_error_requestSequenceError = 0x24, @@ -134,6 +134,10 @@ typedef struct { uint8_t *data; } tUdsServiceCommand; +typedef bool (uds_clear_flash_func)(uint32_t firstPageAddr, uint32_t totalSize); + +typedef bool (uds_write_flash_func)(uint32_t beginPageAddr, void *sourceRamAddr, uint32_t size); + typedef struct { tCanSerialPortFrameTp canSerialPortFrameTp; tLoggerInterface *logger; @@ -170,6 +174,9 @@ typedef struct { uint32_t time_counter_max_attempts_default; } SA; + uds_clear_flash_func *clear_flash_func; + uds_write_flash_func *write_flash_func; + tStaticThreadBlock(384) T_can_Uds; } tCanUds; @@ -180,6 +187,7 @@ typedef struct { char *desc; } eUds_com; + void CanUds_Init( tCanUds *env, tDiagnostic *Diagnostic, @@ -187,6 +195,8 @@ void CanUds_Init( tDeviceStorage *deviceStorage, tCanSpamTransmitter *canSpamTransmitter, tAdcTask *adcTask0, + uds_clear_flash_func *clear_flash_func, + uds_write_flash_func *write_flash_func, tLoggerInterface *logger); void CanSerialPortCanUds_Start(tCanUds *env);