#ifndef _UDS_FBL_SERVICE_11_SOURCE #define _UDS_FBL_SERVICE_11_SOURCE /******************************************************************************* ** Include Section ** *******************************************************************************/ #include "uds_fbl_mgr.h" #include "uds_fbl_service11.h" #include "common_drv.h" /******************************************************************************* ** Version Information ** *******************************************************************************/ /******************************************************************************* ** Version Check ** *******************************************************************************/ /******************************************************************************* ** Macro definition ** *******************************************************************************/ /******************************************************************************* ** Global Data ** *******************************************************************************/ static RST_FLAG rst_falg = {FALSE,FALSE,FALSE}; const uds_nrc nrc_1103[4] = { UDSincorrectMessageLengthOrInvalidFormat,\ UDSsubfunctionNotSupported,\ UDSconditionNotCorrect,\ UDSsecurityAccessDenied }; /*--------- <0x11> sub function config start-------------*/ static const DIAG_sunfunction_t SessionSubfunction[] = { {0x03 ,7,false,2,2,NULL,{nrc_1103, 4}} }; /*--------- <0x11> sub function config end---------------*/ /*-------------------------------------------------------*/ /******************************************************************************* ** Function Definitions ** *******************************************************************************/ /*===============================================================================================*/ /* uds_nrc service11_nrc_check(UDSpacket_t* qUDSpacket) */ /* ----------------------------------------------------------------------------------------------*/ /* Function: 11 service negative response judgment */ /* Arguments: qUDSpacket : CAN message structure pointer */ /* Return: Response type */ /*===============================================================================================*/ uds_nrc service11_nrc_check(UDSpacket_t* qUDSpacket) { uds_nrc returnType = 0; uint8_t const kwpdiag_num = (sizeof(SessionSubfunction)/sizeof(DIAG_sunfunction_t)); uint8_t index = 0; uint8_t requestsid; requestsid = UDS_GET_SUB_FUNCTION(qUDSpacket->Data.Byte[1]); for (index = 0; index < kwpdiag_num; index++) { nrc_table_t nrc_table = SessionSubfunction[index].nrc_table; uint16_t length = SessionSubfunction[index].rx_dataLen; uint8_t index_nrc = 0; uint8_t sid = SessionSubfunction[index].sub_requestsid; /* Judge abnormal situations according to NRC priority */ for (index_nrc = 0; (index_nrc < nrc_table.nrc_cnt) && (returnType == 0); index_nrc++) { switch (nrc_table.nrc_list[index_nrc]) { case UDSincorrectMessageLengthOrInvalidFormat: if (Uds_Nrc13_Occur(qUDSpacket->size, length)) { returnType = UDSincorrectMessageLengthOrInvalidFormat; } break; case UDSsubfunctionNotSupported: if (Uds_Nrc12_Occur(requestsid, SessionSubfunction, kwpdiag_num)) { returnType = UDSsubfunctionNotSupported; } break; case UDSconditionNotCorrect: if (sid == requestsid) { uint8_t currentSession = 0; currentSession = udsFbl_GetCurrentSessionMode(); if ((currentSession & SessionSubfunction[index].session_mask) == 0) { returnType = UDSconditionNotCorrect; } } case UDSsecurityAccessDenied: if (Uds_Nrc33_Occur(requestsid, SessionSubfunction, kwpdiag_num)) { returnType = UDSsecurityAccessDenied; } break; default: break; } } } return returnType; /* return highest priority nrc*/ } /*===============================================================================================*/ /* void UdsFbl_HardReset(void) */ /* ----------------------------------------------------------------------------------------------*/ /* Function: 11 01 service hardware reset */ /* Arguments: - */ /* Return: - */ /*===============================================================================================*/ void UdsFbl_HardReset(void) { rst_falg.hard_rst_flag = FALSE; /*UdsFbl_WdgReset(); */ /* use watchdog rest for temporary */ *(uint32_t*)0x20000984=0xffffffff; COMMON_SystemReset(); } /*===============================================================================================*/ /* void UdsFbl_WdgReset(void) */ /* ----------------------------------------------------------------------------------------------*/ /* Function: 11 02 service watchdog reset */ /* Arguments: - */ /* Return: - */ /*===============================================================================================*/ void UdsFbl_WdgReset(void) { /*-----------------------*/ /* Configuration for WDT */ /*-----------------------*/ /*Currently nothing to do*/ } /*===============================================================================================*/ /* void UdsFbl_SoftReset(void) */ /* ----------------------------------------------------------------------------------------------*/ /* Function: 11 03 service software reset */ /* Arguments: - */ /* Return: - */ /*===============================================================================================*/ void UdsFbl_SoftReset(void) { rst_falg.soft_rst_flag = FALSE; *(uint32_t*)0x20000984=0xffffffff; COMMON_SystemReset(); } /*===============================================================================================*/ /* uint8_t ApplDiagEcuReset_11(UDSpacket_t* qUDSpacket) */ /* ----------------------------------------------------------------------------------------------*/ /* Function: 11 service entry processing function */ /* Arguments: qUDSpacket : CAN message structure pointer */ /* Return: Response type */ /*===============================================================================================*/ uint8_t ApplDiagEcuReset_11(UDSpacket_t* qUDSpacket) { uds_nrc returnType = 0; uint8_t subFunction; subFunction = UDS_GET_SUB_FUNCTION(qUDSpacket->Data.Byte[1]); returnType = service11_nrc_check(qUDSpacket); if (UDSpositiveResp == returnType) { switch (subFunction) { case 0x01: rst_falg.hard_rst_flag = TRUE; break; case 0x02: rst_falg.wdg_rst_flag = TRUE; break; case 0x03: rst_falg.soft_rst_flag = TRUE; break; default: break; } } if(UDSpositiveResp == returnType) { qUDSpacket->size = 2; qUDSpacket->Data.Byte[0] = UDS_GET_POSITIVE_RSP(qUDSpacket->Data.Byte[0]); } else { /* do nothing */ } return returnType; } /*===============================================================================================*/ /* bool service11_get_rstflag(uint8_t type) */ /* ----------------------------------------------------------------------------------------------*/ /* Function: service 11 get different type of reset flag set status */ /* Arguments: type:reset type */ /* Return: reset flag */ /*===============================================================================================*/ bool service11_get_rstflag(uint8_t type) { bool result; result = FALSE; switch(type) { case 0x01: result = rst_falg.hard_rst_flag; break; case 0x02: result = rst_falg.wdg_rst_flag; break; case 0x03: result = rst_falg.soft_rst_flag; break; default: break; } return result; } /*===============================================================================================*/ /* bool service11_set_rstflag(uint8_t type) */ /* ----------------------------------------------------------------------------------------------*/ /* Function: service 11 set reset flag of different reset type */ /* Arguments: type:reset type */ /* Arguments: status:reset status */ /* Return: - */ /*===============================================================================================*/ void service11_set_rstflag(uint8_t type,bool status) { switch(type) { case 0x01: rst_falg.hard_rst_flag = status; break; case 0x02: rst_falg.wdg_rst_flag = status; break; case 0x03: rst_falg.soft_rst_flag = status; break; default: break; } } /******************************************************************************* ** End of File ** *******************************************************************************/ #endif /*_UDS_FBL_SERVICE_11_SOURCE*/