/* BEGIN_FILE_HDR ******************************************************************************* * NOTICE * This software is the property of HiRain Technologies. Any information * contained in this doc should not be reproduced, or used, or disclosed * without the written authorization from HiRain Technologies. ******************************************************************************* * File Name : E2E_SM.c ******************************************************************************* * Project/Product : AUTOSAR R21-11 * Title : End-to-End protect module * Author : Hirain ******************************************************************************* * Description : The source file of the End-to-End module. * ******************************************************************************* * Limitations : None * ******************************************************************************* * ******************************************************************************* * Revision History: * * Version Date Initials CR# Descriptions * --------- ---------- ------------ ---------- --------------- * 04.00.00 11/08/2022 Wenbo.Cui N/A Original ******************************************************************************* * END_FILE_HDR*/ /****************************************************************************** * Includes ******************************************************************************/ #include "E2E_SM.h" /******************************************************************************* * General QAC Suppression *******************************************************************************/ /*PRQA S 3214,0862,3614 EOF*/ /* According to the requirements of AUTOSAR Specification,when locating address segments in the files of each module,#include "E2E_MemMap.h" is required.Defined XXX_START_SEC_ will undefine in E2E_MemMap.h */ /*PRQA S 3432 EOF*/ /* P2VAR and other macros in the Compiler conforms to AUTOSAR standard.There's no need to revise. */ /***************************************************************************** * E2E QAC Suppression *****************************************************************************/ /*PRQA S 4640,4641 EOF*/ /* Function, macrodefinition is named with a fixed requirement and does not make changes */ /****************************************************************************** * Macro ******************************************************************************/ #define E2E_START_SEC_CODE #include "E2E_MemMap.h" /****************************************************************************** * Private Functions Declare ******************************************************************************/ STATIC FUNC(void, E2E_CODE)E2E_SMAddStatus ( E2E_PCheckStatusType ProfileStatus, P2CONST(E2E_SMConfigType, AUTOMATIC, E2E_APPL_CONST) ConfigPtr, P2VAR(E2E_SMCheckStateType, AUTOMATIC, E2E_APPL_DATA) StatePtr ); /****************************************************************************** * Private Functions ******************************************************************************/ /* BEGIN_FUNCTION_HDR ******************************************************************************* * Function Name: E2E_SMAddStatus * * Description: updates the profileStatusWindow based on history of checks * performed by a corresponding E2E_P0XCheck() function, and updates * the counter. * * Inputs: ProfileStatus : Profile-independent status of the reception on one * single Data in one cycle. * ConfigPtr : Pointer to static configuration. * StatePtr : Pointer to port/data communication state. * * Outputs: None * * Limitations: None ******************************************************************************* END_FUNCTION_HDR */ /*SWS_E2E_00466*/ STATIC FUNC(void, E2E_CODE)E2E_SMAddStatus ( E2E_PCheckStatusType ProfileStatus, P2CONST(E2E_SMConfigType, AUTOMATIC, E2E_APPL_CONST) ConfigPtr, P2VAR(E2E_SMCheckStateType, AUTOMATIC, E2E_APPL_DATA) StatePtr ) { uint8 i; /*update the ProfileStatusWindow*/ StatePtr->ProfileStatusWindow[StatePtr->WindowTopIndex] = ProfileStatus; StatePtr->OkCount = (uint8)0; StatePtr->ErrorCount = (uint8)0; /*calculate the OkCount and ErrorCount*/ for(i = (uint8)0; i < ConfigPtr->WindowSize; i++) { if(E2E_P_OK == StatePtr->ProfileStatusWindow[i]) { StatePtr->OkCount = StatePtr->OkCount + (uint8)1; } else if(E2E_P_ERROR == StatePtr->ProfileStatusWindow[i]) { StatePtr->ErrorCount = StatePtr->ErrorCount + (uint8)1; } else { /* Intentionally Empty */ } } if(StatePtr->WindowTopIndex == (ConfigPtr->WindowSize - (uint8)1)) { StatePtr->WindowTopIndex = (uint8)0; } else { /*PRQA S 3383 ++*/ /*The previously logical judgment of the data is guaranteed that the data value will not overflow.*/ StatePtr->WindowTopIndex++; /*PRQA S 3383 --*/ } } /****************************************************************************** * Public Funtions ******************************************************************************/ /* BEGIN_FUNCTION_HDR ******************************************************************************* * Function Name: E2E_SMCheck * * Description: Checks the communication channel. It determines if the data can * be used for safety-related application, based on history of checks * performed by a corresponding E2E_P0XCheck() function. * * Inputs: ProfileStatus : Profile-independent status of the reception on one * single Data in one cycle. * ConfigPtr : Pointer to static configuration. * StatePtr : Pointer to port/data communication state. * * Outputs: E2E_E_INPUTERR_NULL, * E2E_E_INPUTERR_WRONG, * E2E_E_INTERR, * E2E_E_OK, * E2E_E_WRONGSTATE * * Limitations: None ******************************************************************************* END_FUNCTION_HDR */ /*SWS_E2E_00340*//*SWS_E2E_00354*//*SWS_E2E_00345*/ FUNC(Std_ReturnType, E2E_CODE)E2E_SMCheck ( E2E_PCheckStatusType ProfileStatus, P2CONST(E2E_SMConfigType, AUTOMATIC, E2E_APPL_CONST) ConfigPtr, P2VAR(E2E_SMCheckStateType, AUTOMATIC, E2E_APPL_DATA) StatePtr ) { Std_ReturnType ret = E2E_E_OK; E2E_SMStateType smState; /*SWS_E2E_00371*/ if((NULL_PTR == ConfigPtr) || (NULL_PTR == StatePtr)) { ret = E2E_E_INPUTERR_NULL; } else { smState = StatePtr->SMState; switch (smState) { case E2E_SM_DEINIT: ret = E2E_E_WRONGSTATE; break; case E2E_SM_NODATA: if((ProfileStatus != E2E_P_ERROR) && (ProfileStatus != E2E_P_NONEWDATA)) { StatePtr->SMState = E2E_SM_INIT; } break; case E2E_SM_INIT: E2E_SMAddStatus(ProfileStatus, ConfigPtr, StatePtr); if ((StatePtr->ErrorCount <= ConfigPtr->MaxErrorStateInit) && (StatePtr->OkCount >= ConfigPtr->MinOkStateInit)) { StatePtr->SMState = E2E_SM_VALID; } else if(StatePtr->ErrorCount > ConfigPtr->MaxErrorStateInit) { StatePtr->SMState = E2E_SM_INVALID; } else { /* Intentionally Empty */ } break; case E2E_SM_VALID: E2E_SMAddStatus(ProfileStatus, ConfigPtr, StatePtr); if ((StatePtr->ErrorCount > ConfigPtr->MaxErrorStateValid) || (StatePtr->OkCount < ConfigPtr->MinOkStateValid)) { StatePtr->SMState = E2E_SM_INVALID; } break; case E2E_SM_INVALID: E2E_SMAddStatus(ProfileStatus, ConfigPtr, StatePtr); if ((StatePtr->ErrorCount <= ConfigPtr->MaxErrorStateInvalid) && (StatePtr->OkCount >= ConfigPtr->MinOkStateInvalid)) { StatePtr->SMState = E2E_SM_VALID; } break; default: /* Intentionally Empty */ break; } } return ret; } /* BEGIN_FUNCTION_HDR ******************************************************************************* * Function Name: E2E_SMCheckInit * * Description: Initializes the state machine. * * Inputs: StatePtr : Pointer to port/data communication state. * ConfigPtr : Pointer to configuration of the state machine. * * Outputs: E2E_E_INPUTERR_NULL, * E2E_E_OK * * Limitations: None ******************************************************************************* END_FUNCTION_HDR */ /*SWS_E2E_00353*//*SWS_E2E_00354*//*SWS_E2E_00375*/ FUNC(Std_ReturnType, E2E_CODE) E2E_SMCheckInit ( P2VAR(E2E_SMCheckStateType, AUTOMATIC, E2E_APPL_DATA) StatePtr, P2CONST(E2E_SMConfigType, AUTOMATIC, E2E_APPL_CONST) ConfigPtr ) { Std_ReturnType ret = E2E_E_OK; uint8 i; /*SWS_E2E_00370*/ if((NULL_PTR == ConfigPtr) || (NULL_PTR == StatePtr)) { ret = E2E_E_INPUTERR_NULL; } else { /*SWS_E2E_00467*/ for(i = (uint8)0; i < (ConfigPtr->WindowSize); i++) { StatePtr->ProfileStatusWindow[i] = E2E_P_NOTAVAILABLE; } StatePtr->WindowTopIndex = (uint8)0; StatePtr->ErrorCount = (uint8)0; StatePtr->OkCount = (uint8)0; StatePtr->SMState = E2E_SM_NODATA; } return ret; } #define E2E_STOP_SEC_CODE #include "E2E_MemMap.h"