

/*
 ***************************************************************************************************
 * Includes
 ***************************************************************************************************
 */

#include "ComM_Priv.h"

/*
 ***************************************************************************************************
 * Defines
 ***************************************************************************************************
 */

/*
 ***************************************************************************************************
 * Type definitions
 ***************************************************************************************************
 */

/*
 ***************************************************************************************************
 * Variables
 ***************************************************************************************************
 */

#define COMM_START_SEC_CODE
#include "ComM_Cfg_MemMap.h"


/**************************************************************************************
 * Function name    : ComM_GetMaxComMode
 * Syntax           : Std_ReturnType ComM_GetMaxComMode
 *                   (
 *                     ComM_UserHandleType User, ComM_ModeType* ComMode
 *                     )
 * Description      : Function to query the maximum allowed Communication Mode of the corresponding
 *                    user.
 * Parameters       : User -> Handle of the user who requests a mode
 *                    ComMode ->  ComM_ModeType
 * Return value     : E_OK: Successfully returned maximum allowed Communication Mode
 *                    E_NOT_OK: Return of maximum allowed Communication Mode failed
 *                    COMM_E_UNINIT: ComM not initialized
 **************************************************************************************/
/* MR12 RULE 8.3 VIOLATION:Two declarations exists for this api. One is in ComM.h & another generated by RTE. Hence,the difference in identifiers.*/
FUNC(Std_ReturnType,COMM_CODE) ComM_GetMaxComMode
                                            (
                                            VAR(ComM_UserHandleType, COMM_VAR) User,
                                            P2VAR(ComM_ModeType, AUTOMATIC, COMM_VAR) ComMode
                                            )
{
    /* Local variables declaration */
    #if (COMM_INHIBITION_ENABLED)
    P2VAR(ComM_UserVarType, AUTOMATIC, COMM_APPL_DATA) userRamPtr_ps;
    #endif  /*  if (COMM_INHIBITION_ENABLED)  */

    /* Local variable initialization */

    #if (COMM_INHIBITION_ENABLED)
    userRamPtr_ps = &ComM_UserStruct[User];
    #endif  /*  if (COMM_INHIBITION_ENABLED)  */

	/******************************************DET STARTS HERE***************************************************/
    /* DET check for ComM initialization */
    #if (COMM_DEV_ERROR_DETECT != STD_OFF)

    if (ComM_GlobalStruct.ComM_InitStatus != COMM_INIT)
    {
        /* Report DET with ComM not initialized status*/
        (void)Det_ReportError(COMM_MODULE_ID,COMM_INSTANCE_ID,COMM_GET_MAX_COMMODE_APIID,COMM_E_NOT_INITED);
        return E_NOT_INITIALIZED;
    }
    /* check if pointer used is NULL. If so raise DET and return status as E_NOT_OK */
    if (ComMode == NULL_PTR)
    {
        /* Report DET with NULL parameter*/
        (void)Det_ReportError(COMM_MODULE_ID,COMM_INSTANCE_ID,COMM_GET_MAX_COMMODE_APIID,COMM_E_WRONG_PARAMETERS);
        return E_NOT_OK;
    }

    /* DET check for valid user */
    if (User >= COMM_NO_OF_USERS)
    {
        /* Report DET with Invalid Mode parameter*/
        (void)Det_ReportError(COMM_MODULE_ID,COMM_INSTANCE_ID,COMM_GET_MAX_COMMODE_APIID,COMM_E_WRONG_PARAMETERS);
        return E_NOT_OK;
    }
    #endif  /*  #if (COMM_DEV_ERROR_DETECT != STD_OFF)  */

    /******************************************DET ENDS HERE***************************************************/

    #if (COMM_INHIBITION_ENABLED)
    if(((userRamPtr_ps->WakeUpInhibitionCtr_u16) != C_ZERO) || ((userRamPtr_ps->LimitToNoComCtr_u16) != C_ZERO))
    {
        *ComMode = COMM_NO_COMMUNICATION;
    }
    else
    #endif  /* (COMM_INHIBITION_ENABLED)  */
    {
    *ComMode = COMM_FULL_COMMUNICATION;
    }
    return E_OK;
}

#define COMM_STOP_SEC_CODE
#include "ComM_Cfg_MemMap.h"

