[AUTOSAR][Diagnostic Management][$11] Reset Service

Article directory

  • 1. Introduction
    • (1) Application scenarios
    • (2) Request format
    • (3) Restart type
  • 2. Sample code
    • (1) 11_ecu_reset.c


1. Introduction

The ECU reset service uses this diagnostic command to command the ECU to perform a self-reset. There are many forms of reset, which are distinguished according to sub-function parameters (that is, the client uses the ECU reset service to request the server to reset. After the reset is successful, you will directly enter the default session).

Generally speaking, after receiving a diagnostic command, the ECU must first perform corresponding processing, perform certain diagnostic operations, and then send a positive response after completion. But the ECU reset service is a special case because its diagnostic operation is reset. At this time, the ECU will start running again. At this time, the ECU will not remember that you have sent a diagnostic command before, so there is nothing you can do after reset. The ECU cannot send a diagnostic response anymore, so it must first send a positive response and then perform a reset.

Note: During the period from sending a positive response to executing a reset, whether the ECU can still respond to other diagnostic requests is not specified in the standard. It is recommended that the ECU does not accept any request messages or send any response messages during this period.

(1) Application scenarios

Generally speaking, for 11 diagnostic services, the main application scenarios are as follows:

  1. After the ECU is flashed with new software, it is necessary to restart the ECU through the 11 diagnostic service to restore it to its initial state to ensure a very clean operating environment;
  2. During the offline calibration process of the production line, for the KL30-powered ECU, there are some data that are only stored when the power is turned off. At this time, it is necessary to use the 11 diagnostic service to power the ECU through the power-off process to complete the saving of the corresponding data;
  3. In order to meet the needs of specific functions, after inputting relevant calibration parameters to the ECU, the calibration parameters can only take effect by sending diagnostic service 11;
  4. For KL30-powered ECU nodes, diagnostic service 11 can be used to quickly put the ECU into sleep scenarios;
    The above application scenarios are relatively common. In addition, of course there are many application scenarios for ECU internal testing, which will not be listed here.

Note:

According to the ISO14229-1 standard, when the Client sends an 11 diagnostic service request to the Server, the Server can send the request to the Client after the reset behavior is completed or before the restart behavior is started.

Diagnostic response, but one approach strongly recommended by 14229-1 is: “When the Server receives a 11 diagnostic service request from the Client, the Server should first give a diagnostic response and then start the restart behavior.”

As for why this is so, I think of a scenario: if the function addressing requests the 11 diagnostic service (the positive response is not suppressed), before the reset is completed, NRC78 will usually be replied to let the client wait. Then the client needs to be based on different ECU nodes. Timeout monitoring of the reply will undoubtedly increase the burden on the Client. For the Client, the simplest method is to send the request, have each ECU node reply with a positive response, and then complete the reset operation.

(2) Request format


(3) Restart type

The reset type mentioned in Figure 2 above is passed as a subfunction parameter to the server to cause corresponding restart behavior. Specifically, it consists of the following types:

  • HardReset: hard reset;
  • keyOffOnReset: ignition switch reset;
  • SoftReset: soft reset;
  • enableRapidPowerShutDown: enable rapid sleep process;
  • disableRapidPowerShutDown: suppress the rapid sleep process;
  • vehicleManufacturerSpecific: Custom reset type for vehicle manufacturers;
  • systemSupplierSpecific: Custom reset type for system suppliers;

2. Sample code

(1) 11_ecu_reset.c

/********************************************** **********************************
* @file 11_ecu_reset.c
* @author jianqiang.xue
* @version V1.0.0
* @date 2023-05-30
* @brief ECU reset function
*************************************************** ******************************/
/* Includes ----------------------------------------------- ------------------*/
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <stdlib.h>
#include "modules.h"
#include "os_api.h"
#include "edebug.h"
#include "kv_sys.h"
#include "ecu_ble_uart.h"

/* Private includes -------------------------------------------------- ----------*/
#include "std_math.h"
#include "app_can.h"
#include "can_nm.h"
#include "app_nm.h"
#include "diag_main.h"
/* Private define -------------------------------------------------- ---------------*/
#define UDS_ID 0x11

/* Private typedef ----------------------------------------------- -------------*/
/* Private macro ----------------------------------------------- ---------------*/
/* Private variables -------------------------------------------------- -----------*/
static uint8_t ecu_reset_req = 0;
/******************Soft timer creation******************/
/* Private func ----------------------------------------------- ----------------*/
void post_func(uint8_t val) {<!-- -->
    (void)val;
    if (ecu_reset_req) {<!-- -->
        diag_main_send_signal(SIGNAL_DIAG_RESET);
    }
}

void uds11_main(nwl_msg_t* p) {<!-- -->
    uint8_t data[10];
    ecu_reset_req = 0;
    if (p->len != 2) {<!-- -->
        send_nrc_data(UDS_ID, NRC_INCORRECT_MESSAGE_LENTH);
        goto end;
    }
    switch (p->data[1] & amp; 0x7F) {<!-- --> // Sub-function, bit7 is the response bit. =1, no response is allowed
        case 0x01: //hardware reset
            if ((g_car_ste.IPB.bit.VehicleSpeedVld == 1) & amp; & amp; (get_car_speed() > 3)) {<!-- -->
                send_nrc_data(UDS_ID, NRC_CONDITION_NOT_CORRECT);
                goto end;
            }
            if (p->data[1] & amp; 0x80) {<!-- -->
                // Application does not need to respond
            } else {<!-- -->
                //Reply positive response code single frame format: len, service ID|0x40, sub-function ID,
                data[0] = 2; // Total data length = data length + service number
                data[1] = UDS_ID | 0x40; // Service number, required to reply to the host computer |0x40
                data[2] = p->data[1];
                memset( & amp;data[3], 0xAA, 5);
                app_can_enqueue_msg(CAN_MSG_EVENT_SEND, NWL_RES_ADDR, data, 8);
                g_p2_service_time_remaining = 0; // If a diagnostic message is sent, clear the countdown. P2_SERVER_MAX
                os_delay(1);
            }
            ecu_reset_req = 1;
            break;

        default:
            send_nrc_data(UDS_ID, NRC_SUBFUNCTION_NOT_SUPPORTED);
            break;
    }
end:
    return;
}

#if AUTOSAR_DIAG_SWITCH & amp; & amp; USE_UDS_11
DIAG_SERVICE_REG(UDS_ID, DIAG_NO_SECURITY_LEVEL, (DEFAULT_SESSION|PROGRAMMING_SESSION|EXTENDED_SESSION),
                 (DIAG_PHYS_REQ|DIAG_FUNC_REQ), NULL, post_func, uds11_main);
#endif