


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

#include "ComM_Priv.h"

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

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

#if (COMM_LIMIT_TO_NOCOM_ENABLED != STD_OFF)

#define COMM_START_SEC_CODE
#include "ComM_Cfg_MemMap.h"


/*******************************************************************************
 * Function name    : ComM_LimitChannelToNoComMode
 * Syntax           : Std_ReturnType ComM_LimitChannelToNoComMode( NetworkHandleType Channel, ComM_StateType* State )
 * Description      : API to request limit to no com for a channel.
 * Parameters       : Channel-> The Network Channel for the requested state of ComM state machine.
 *                    Status-> Status of limit to no com
 * Return value     : E_OK: Successfully changed inhibition status for the channel
 *                    E_NOT_OK: Changed of inhibition status for the channel 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_LimitChannelToNoComMode
                                        (
                                        VAR(NetworkHandleType, COMM_VAR) Channel,
                                        VAR(boolean, COMM_VAR) Status
                                        )
{
    /* Local variable declaration */
    VAR(Std_ReturnType, AUTOMATIC) ret_Val;
    P2VAR(ComM_ChannelVarType, AUTOMATIC, COMM_APPL_DATA) channelRamPtr_ps;
    P2VAR(ComM_GlobalVarType, AUTOMATIC, COMM_APPL_DATA) globalRamPtr_ps;
    /* Local variable initialisation*/

    /************************************DET CHECK STARTS HERE*********************************/
    #if (COMM_DEV_ERROR_DETECT != STD_OFF)

    /* Check for ComM Initialized */
    if (ComM_GlobalStruct.ComM_InitStatus != COMM_INIT)
    {
       (void)Det_ReportError(COMM_MODULE_ID,COMM_INSTANCE_ID,COMM_LIMIT_CHNLTO_NOCOMMODE_APIID,COMM_E_NOT_INITED);
        return E_NOT_INITIALIZED;
    }
    /* Check if the channel passed is valid */
    if (Channel >= COMM_NO_OF_CHANNELS)
    {
        (void)Det_ReportError(COMM_MODULE_ID,COMM_INSTANCE_ID,COMM_LIMIT_CHNLTO_NOCOMMODE_APIID,COMM_E_WRONG_PARAMETERS);
        return E_NOT_OK;
    }
    #endif
    /************************************DET CHECK ENDS HERE**********************************/

    /* Local variable initialization */

    ret_Val = E_OK;

    channelRamPtr_ps = &ComM_ChannelStruct[Channel];

    globalRamPtr_ps = &ComM_GlobalStruct;

    /* Proceed only if Limit ECU to No Com is not already active */

    if(globalRamPtr_ps->ComM_LimitECUToNoCom_b != FALSE)
    {
        /* As limit ECU, which is the master is already set, this request will not be processed.
         * Hence return E_NOT_OK  */
        ret_Val = E_NOT_OK;
    }
    else
    {
        /* Proceed only if the request has changed from the previous request */

        if((COMM_GET_LIMIT_TO_NO_COM((channelRamPtr_ps->InhibitionReqStatus_u8))) != Status)
        {
            SchM_Enter_ComM_LimitationNoNest();
            /* If Status is 'true', set Limit to no com bit, else reset the bit */
            if(Status != FALSE)
            {
                /* Accept Limit to No Com request, only if the channel is in network requested state */
                if(channelRamPtr_ps->ChannelState_e == COMM_FULL_COM_NETWORK_REQUESTED)
                {
                    /* Set limit to no com status for the channel */
                    COMM_SET_LIMIT_TO_NO_COM((channelRamPtr_ps->InhibitionReqStatus_u8));
                    /* Update limit to no com counter for all users of channel */
                    ComM_LTranslateInhibitionStatus(Channel,COMM_LIMITTONOCOM,Status);
                }
                else
                {
                    /* As limit to NO Com request is not accepted, return E_NOT_OK */
                    ret_Val = E_NOT_OK;
                }
            }
            else
            {
                /* Clear limit to no com status for the channel */
                COMM_CLR_LIMIT_TO_NO_COM((channelRamPtr_ps->InhibitionReqStatus_u8));
                /* Update limit to no com counter for all users of channel */
                ComM_LTranslateInhibitionStatus(Channel,COMM_LIMITTONOCOM,Status);
            }

            SchM_Exit_ComM_LimitationNoNest();
        }
    }
        return ret_Val;
}

#define COMM_STOP_SEC_CODE
#include "ComM_Cfg_MemMap.h"

#endif  /*  (COMM_LIMIT_TO_NOCOM_ENABLED != STD_OFF)  */

