

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

#include "ComM_Priv.h"

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

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

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

#define COMM_START_SEC_CODE
#include "ComM_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.*/
Std_ReturnType ComM_GetMaxComMode(ComM_UserHandleType User, ComM_ModeType * ComMode)
{
    /* Local variables declaration */
    #if (COMM_INHIBITION_ENABLED)
    ComM_UserVarType_tst *  userRamPtr_pst;
    #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_en!= 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 COMM_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 (ComM_Prv_ValidateUserId(User) == FALSE)
    {
        /* 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***************************************************/

    /* Local variable initialization */

    #if (COMM_INHIBITION_ENABLED)
    User = ComM_UserId_MappingTable_acst[User];
    userRamPtr_pst = &ComM_UserStruct[User];

    if(((userRamPtr_pst->WakeUpInhibitionCtr_u16) != C_ZERO) || ((userRamPtr_pst->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_MemMap.h"

