/**
*   @file    Ocu_eMios.c
*   @version 1.0.0
*
*   @brief   AUTOSAR Ocu - EMIOS driver source file for OCU driver.
*   @details EMIOS driver interface.
*
*   @addtogroup OCU_MODULE
*   @{
*/
/*================================================================================================================
*   Project              : AUTOSAR 4.3 MCAL
*   Platform             : PA
*   Peripheral           : eMios
*   Dependencies         : none
*
*   Autosar Version      : 4.3.1
*   Autosar Revision     : ASR_REL_4_3_REV_0001
*   Autosar Conf.Variant :
*   SW Version           : 1.0.0
*   Build Version        : MPC5777C_MCAL_1_0_0_RTM_ASR_REL_4_3_REV_0001_20190315
*
*   (c) Copyright 2006-2016 Freescale Semiconductor, Inc. 
*       Copyright 2017-2019 NXP
*   All Rights Reserved.
==================================================================================================================*/
/*================================================================================================================
==================================================================================================================*/

#ifdef __cplusplus
extern "C"{
#endif

/**
* @page misra_violations MISRA-C:2012 violations
*
* @section [global]
* Violates MISRA 2012 Required Rule 5.1, External identifiers shall be distinct. The used compilers 
* use more than 31 chars for identifiers.
*
* @section [global]
* Violates MISRA 2012 Required Rule 5.2, Identifiers declared in the same scope and name space shall be distinct. 
* The used compilers use more than 31 chars for identifiers.
*
* @section [global]
* Violates MISRA 2012 Required Rule 5.4, Macro identifiers shall be distinct. 
* The used compilers use more than 31 chars for identifiers.
*
* @section [global]
* Violates MISRA 2012 Required Rule 5.5, Identifiers shall be distinct from macro names. 
* The used compilers use more than 31 chars for identifiers.
*
* @section OCU_EMIOS_C_REF_1
* Violates MISRA 2012 Advisory Rule 20.1, #include directives should only be preceded by preprocessor directives or comments.
* <MA>_MemMap.h is included after each section define in order to set the current memory section as defined by AUTOSAR
*
* @section OCU_EMIOS_C_REF_2
* Violates MISRA 2012 Required Rule 4.10, Precautions shall be taken in order to prevent the contents of a header file 
* being included more than once
*
* @section OCU_EMIOS_C_REF_3
* Violates MISRA 2012 Advisory Rule 11.4, A conversion should not be performed between a pointer to object and an integer type.
* The cast is used to access memory mapped registers.
*
* @section OCU_EMIOS_C_REF_4
* Violates MISRA 2012 Required Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type.
* This macro computes the address of any register by using the hardware offset of the controller. 
* The address calculated as an unsigned int is passed to a macro for initializing the pointer with that address.
*
* @section OCU_EMIOS_C_REF_5
* Violates MISRA 2012 Required Rule 10.8, The value of a conposite expression shall not be cast to 
* a different assential type category or a wider assential type
*
* @section OCU_EMIOS_C_REF_6
* Violates MISRA 2012 Advisory Rule 8.7, Functions and objects should not be defined with 
* external linkage if they are referenced in only one translation unit.
*
*/


/*================================================================================================================
*                                        INCLUDE FILES
* 1) system and project includes
* 2) needed interfaces from external units
* 3) internal and external interfaces from this unit
==================================================================================================================*/
#include "Std_Types.h"
#include "Ocu_eMios.h"
#include "Ocu_Ipw_Irq.h"
#include "eMios_Common.h"
#include "SchM_Ocu.h"
#include "Reg_eSys_eMios.h"
#include "Ocu_eMios_Irq.h"

#define USER_MODE_REG_PROT_ENABLED (OCU_USER_MODE_SOFT_LOCKING)
#include "SilRegMacros.h"


/*================================================================================================================
*                              SOURCE FILE VERSION INFORMATION
==================================================================================================================*/

#define OCU_EMIOS_VENDOR_ID_C                    43
#define OCU_EMIOS_AR_RELEASE_MAJOR_VERSION_C     4
#define OCU_EMIOS_AR_RELEASE_MINOR_VERSION_C     3
#define OCU_EMIOS_AR_RELEASE_REVISION_VERSION_C  1
#define OCU_EMIOS_SW_MAJOR_VERSION_C             1
#define OCU_EMIOS_SW_MINOR_VERSION_C             0
#define OCU_EMIOS_SW_PATCH_VERSION_C             0
/** @} */

/*================================================================================================================
*                                     FILE VERSION CHECKS
==================================================================================================================*/
#ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
 /* Check if this source file and Std_Types.h file are of the same Autosar version */
 #if ((OCU_EMIOS_AR_RELEASE_MAJOR_VERSION_C != STD_AR_RELEASE_MAJOR_VERSION) || \
      (OCU_EMIOS_AR_RELEASE_MINOR_VERSION_C != STD_AR_RELEASE_MINOR_VERSION) \
     )
     #error "AutoSar Version Numbers of Ocu_eMios.c and Std_Types.h are different"
 #endif
 
 /* Check if this source file and eMios_Common.h file are of the same Autosar version */
 #if ((OCU_EMIOS_AR_RELEASE_MAJOR_VERSION_C != EMIOS_COMMON_AR_RELEASE_MAJOR_VERSION) || \
      (OCU_EMIOS_AR_RELEASE_MINOR_VERSION_C != EMIOS_COMMON_AR_RELEASE_MINOR_VERSION) \
     )
     #error "AutoSar Version Numbers of Ocu_eMios.c and eMios_Common.h are different"
 #endif
 
 #if (OCU_EMIOS_VENDOR_ID_C != REG_ESYS_EMIOS_VENDOR_ID)
 #error "Ocu_eMios.c and Reg_eSys_eMios.h have different vendor ids"
 #endif
/* Check if the source file and Ocu header file are of the same Autosar version */
 
 #if ((OCU_EMIOS_AR_RELEASE_MAJOR_VERSION_C != REG_ESYS_EMIOS_AR_RELEASE_MAJOR_VERSION) || \
     (OCU_EMIOS_AR_RELEASE_MINOR_VERSION_C != REG_ESYS_EMIOS_AR_RELEASE_MINOR_VERSION) || \
     (OCU_EMIOS_AR_RELEASE_REVISION_VERSION_C != REG_ESYS_EMIOS_AR_RELEASE_REVISION_VERSION) \
     )
 #error "AutoSar Version Numbers of Ocu_eMios.c and Reg_eSys_eMios.h are different"
 #endif
/* Check if source file and OCU header file are of the same Software version */
 
 #if ((OCU_EMIOS_SW_MAJOR_VERSION_C != REG_ESYS_EMIOS_SW_MAJOR_VERSION) || \
     (OCU_EMIOS_SW_MINOR_VERSION_C != REG_ESYS_EMIOS_SW_MINOR_VERSION) || \
     (OCU_EMIOS_SW_PATCH_VERSION_C != REG_ESYS_EMIOS_SW_PATCH_VERSION) \
     )
 #error "Software Version Numbers of Ocu_eMios.c and Reg_eSys_eMios.h are different"
 #endif
 
 #if (OCU_EMIOS_VENDOR_ID_C != SILREGMACROS_VENDOR_ID)
 #error "Ocu_eMios.c and SilRegMacros.h have different vendor ids"
 #endif
 
/* Check if source file and SilRegMacros.h are of the same Autosar version */
 #if ((OCU_EMIOS_AR_RELEASE_MAJOR_VERSION_C    != SILREGMACROS_AR_RELEASE_MAJOR_VERSION) || \
     (OCU_EMIOS_AR_RELEASE_MINOR_VERSION_C    != SILREGMACROS_AR_RELEASE_MINOR_VERSION) || \
     (OCU_EMIOS_AR_RELEASE_REVISION_VERSION_C != SILREGMACROS_AR_RELEASE_REVISION_VERSION) \
     )
 #error "AutoSar Version Numbers of Ocu_eMios.c and SilRegMacros.h are different"
 #endif
 
 /* Check if source file and SilRegMacros.h are of the same software version */
 #if ((OCU_EMIOS_SW_MAJOR_VERSION_C != SILREGMACROS_SW_MAJOR_VERSION) || \
     (OCU_EMIOS_SW_MINOR_VERSION_C != SILREGMACROS_SW_MINOR_VERSION) || \
     (OCU_EMIOS_SW_PATCH_VERSION_C != SILREGMACROS_SW_PATCH_VERSION) \
     )
 #error "Software Version Numbers of Ocu_eMios.c and SilRegMacros.h are different"
 #endif
#endif

#if (OCU_EMIOS_VENDOR_ID_C != OCU_EMIOS_VENDOR_ID)
 #error "Ocu_eMios.c and Ocu_eMios.h have different vendor ids"
#endif
/* Check if source file and Ocu header file are of the same Autosar version */
#if ((OCU_EMIOS_AR_RELEASE_MAJOR_VERSION_C != OCU_EMIOS_AR_RELEASE_MAJOR_VERSION) || \
     (OCU_EMIOS_AR_RELEASE_MINOR_VERSION_C != OCU_EMIOS_AR_RELEASE_MINOR_VERSION) || \
     (OCU_EMIOS_AR_RELEASE_REVISION_VERSION_C != OCU_EMIOS_AR_RELEASE_REVISION_VERSION) \
    )
 #error "AutoSar Version Numbers of Ocu_eMios.c and Ocu_eMios.h are different"
#endif
/* Check if source file and OCU header file are of the same Software version */
#if ((OCU_EMIOS_SW_MAJOR_VERSION_C != OCU_EMIOS_SW_MAJOR_VERSION) || \
     (OCU_EMIOS_SW_MINOR_VERSION_C != OCU_EMIOS_SW_MINOR_VERSION) || \
     (OCU_EMIOS_SW_PATCH_VERSION_C != OCU_EMIOS_SW_PATCH_VERSION) \
    )
 #error "Software Version Numbers of Ocu_eMios.c and Ocu_eMios.h are different"
#endif

#if (OCU_EMIOS_VENDOR_ID_C != OCU_IPW_IRQ_VENDOR_ID)
    #error "Ocu_eMios.c and Ocu_Ipw_Irq.h have different vendor ids"
#endif
/* Check if source file and Ocu header file are of the same Autosar version */
#if ((OCU_EMIOS_AR_RELEASE_MAJOR_VERSION_C != OCU_IPW_IRQ_AR_RELEASE_MAJOR_VERSION) || \
     (OCU_EMIOS_AR_RELEASE_MINOR_VERSION_C != OCU_IPW_IRQ_AR_RELEASE_MINOR_VERSION) || \
     (OCU_EMIOS_AR_RELEASE_REVISION_VERSION_C != OCU_IPW_IRQ_AR_RELEASE_REVISION_VERSION) \
    )
 #error "AutoSar Version Numbers of Ocu_eMios.c and Ocu_Ipw_Irq.h are different"
#endif
/* Check if source file and OCU header file are of the same Software version */
#if ((OCU_EMIOS_SW_MAJOR_VERSION_C != OCU_IPW_IRQ_SW_MAJOR_VERSION) || \
     (OCU_EMIOS_SW_MINOR_VERSION_C != OCU_IPW_IRQ_SW_MINOR_VERSION) || \
     (OCU_EMIOS_SW_PATCH_VERSION_C != OCU_IPW_IRQ_SW_PATCH_VERSION) \
    )
 #error "Software Version Numbers of Ocu_eMios.c and Ocu_Ipw_Irq.h are different"
#endif

#if (OCU_EMIOS_VENDOR_ID_C != OCU_EMIOS_IRQ_VENDOR_ID)
    #error "Ocu_eMios.c and Ocu_eMios_Irq.h have different vendor ids"
#endif
/* Check if source file and Ocu header file are of the same Autosar version */
#if ((OCU_EMIOS_AR_RELEASE_MAJOR_VERSION_C != OCU_EMIOS_IRQ_AR_RELEASE_MAJOR_VERSION) || \
     (OCU_EMIOS_AR_RELEASE_MINOR_VERSION_C != OCU_EMIOS_IRQ_AR_RELEASE_MINOR_VERSION) || \
     (OCU_EMIOS_AR_RELEASE_REVISION_VERSION_C != OCU_EMIOS_IRQ_AR_RELEASE_REVISION_VERSION) \
    )
 #error "AutoSar Version Numbers of Ocu_eMios.c and Ocu_eMios_Irq.h are different"
#endif
/* Check if source file and OCU header file are of the same Software version */
#if ((OCU_EMIOS_SW_MAJOR_VERSION_C != OCU_EMIOS_IRQ_SW_MAJOR_VERSION) || \
     (OCU_EMIOS_SW_MINOR_VERSION_C != OCU_EMIOS_IRQ_SW_MINOR_VERSION) || \
     (OCU_EMIOS_SW_PATCH_VERSION_C != OCU_EMIOS_IRQ_SW_PATCH_VERSION) \
    )
 #error "Software Version Numbers of Ocu_eMios.c and Ocu_eMios_Irq.h are different"
#endif
/*================================================================================================================
*                         LOCAL TYPEDEFS (STRUCTURES, UNIONS, ENUMS)
==================================================================================================================*/

/*================================================================================================================
*                                      LOCAL CONSTANTS
==================================================================================================================*/

/*================================================================================================================
*                                      LOCAL VARIABLES
==================================================================================================================*/
#if (OCU_EMIOS_USED == STD_ON)

#define OCU_START_SEC_VAR_NO_INIT_8
/**@violates @ref OCU_EMIOS_C_REF_1 Precautions shall be taken in order to prevent the contents 
   of a header file being included more than once */
/**@violates @ref OCU_EMIOS_C_REF_2 #include directives should only be preceded by preprocessor directives or comments. */
#include "Ocu_MemMap.h"

#if ((OCU_SET_RELATIVE_THRESHOLD_API == STD_ON) || \
     (OCU_SET_ABSOLUTE_THRESHOLD_API == STD_ON) || \
     (OCU_DEINIT_API == STD_ON))

    #define MASTER_BUS_NOT_INSTALL ((uint8)(0xFFU))

#endif
/**
* @brief    This arrays shall be used to store the action information for each eMios channel
* @details  This array shall be initialized by Ocu_eMios_Init() and Ocu_eMios_SetPinAction.
*           This data shall be used by Ocu_eMios_StartChannel to replace the information erased when
*           Ocu_eMios_StopChannel was called.
*/
static  VAR(uint8, OCU_VAR) Ocu_eMios_u8OcuAction[OCU_EMIOS_HW_CHANNELS];

#if ((OCU_SET_RELATIVE_THRESHOLD_API == STD_ON) || \
     (OCU_SET_ABSOLUTE_THRESHOLD_API == STD_ON) || \
     (OCU_DEINIT_API == STD_ON))
/**
* @brief    This arrays shall be used to store the Counter Bus Id information for each eMios channel
* @details  This array shall be initialized by Ocu_eMios_Init() and Ocu_eMios_SetPinAction.
*           This data shall be used by Ocu_eMios_StartChannel to replace the information erased when
*           Ocu_eMios_StopChannel was called.
*/
static  VAR(uint8, OCU_VAR) Ocu_eMios_u8CounterBusIdx[OCU_EMIOS_HW_CHANNELS];
#endif

#if ((OCU_SET_RELATIVE_THRESHOLD_API == STD_ON) || \
     (OCU_SET_ABSOLUTE_THRESHOLD_API == STD_ON))
/**
* @brief    This arrays shall be used to store the max counter value for each eMios channel
* @details  This array shall be initialized by Ocu_eMios_Init().
*           This data shall be used by Ocu_eMios_GetMaxCountValue and Ocu_eMios_SetRelativeThreshold
*/
static  VAR(uint32, OCU_VAR) Ocu_eMios_u32MaxCounterValue[OCU_EMIOS_HW_CHANNELS];
#endif

#define OCU_STOP_SEC_VAR_NO_INIT_8
/**@violates @ref OCU_EMIOS_C_REF_1 Precautions shall be taken in order to prevent the contents 
   of a header file being included more than once */
/**@violates @ref OCU_EMIOS_C_REF_2 #include directives should only be preceded by preprocessor directives or comments. */
#include "Ocu_MemMap.h"
/*================================================================================================================
*                                      GLOBAL CONSTANTS
==================================================================================================================*/


/*================================================================================================================
*                                      GLOBAL VARIABLES
==================================================================================================================*/


/*================================================================================================================
*                                  LOCAL FUNCTION PROTOTYPES
==================================================================================================================*/
#define OCU_START_SEC_CODE
/**@violates @ref OCU_EMIOS_C_REF_1 Precautions shall be taken in order to prevent the contents 
   of a header file being included more than once */
/**@violates @ref OCU_EMIOS_C_REF_2 #include directives should only be preceded by preprocessor directives or comments. */
#include "Ocu_MemMap.h"

#if ((OCU_SET_ABSOLUTE_THRESHOLD_API  == STD_ON) || \
     (OCU_SET_RELATIVE_THRESHOLD_API  == STD_ON))
LOCAL_INLINE FUNC(Ocu_ReturnType, OCU_CODE) Ocu_eMios_DetermineNextCmStatus
(
   VAR(Ocu_ValueType,   AUTOMATIC) PostCmWriteValue,
   VAR(Ocu_ValueType,   AUTOMATIC) StartIntervalValue,
   VAR(Ocu_ValueType,   AUTOMATIC) EndIntervalValue
);
#endif

/*================================================================================================================
*                                      LOCAL FUNCTIONS
==================================================================================================================*/
#if ((OCU_SET_ABSOLUTE_THRESHOLD_API  == STD_ON) || \
     (OCU_SET_RELATIVE_THRESHOLD_API  == STD_ON))

/**
* @brief          This internal function determines status of the compare match after the new threshold
*                 was written.  
* @details        This function compare systematic the input parameter values to determine if the 
*                 compare-match will occur in the given interval or has already occurred. 
*                 The reference interval if composed of all integer value between the StartIntervalValue and 
*                 EndIntervalValue, considering also the possibility of counter over-run.
*                 I.e. considering a 8bit counter if StartIntervalValue = 253 and  EndIntervalValue = 5 than 
*                 the values inside the interval are {253, 254, 255, 0, 1, 2, 3, 4} and all other values are 
*                 outside reference interval.
*
* @param[in]      PostCmWriteValue        Value of the counter after Compare match was written
* @param[in]      StartIntervalValue      Start value of the reference interval
* @param[in]      EndIntervalValue        End value of the reference interval
*
* @return         Ocu_ValueType           Compare match was written in or outside the given interval
* @retval         OCU_CM_IN_REF_INTERVAL  Compare match was written inside the reference interval
* @retval         OCU_CM_IN_REF_INTERVAL  Compare match was written outside the reference interval
*
*
* @note           .
*/
LOCAL_INLINE FUNC(Ocu_ReturnType, OCU_CODE) Ocu_eMios_DetermineNextCmStatus
(
   VAR(Ocu_ValueType,   AUTOMATIC) PostCmWriteValue,
   VAR(Ocu_ValueType,   AUTOMATIC) StartIntervalValue,
   VAR(Ocu_ValueType,   AUTOMATIC) EndIntervalValue
)
{
    /* Variable to store the value returned by the function */ 
    VAR(Ocu_ReturnType, AUTOMATIC)  StatusValue = OCU_CM_OUT_REF_INTERVAL;

    /*check if compare match will happen before counter roll-over*/
    if (StartIntervalValue <= EndIntervalValue)
    {
        /*counter is not expected to roll-over*/
        /*check if post-update value is inside the compare match interval*/
        if((StartIntervalValue <= PostCmWriteValue) && (PostCmWriteValue < EndIntervalValue))
        {
            StatusValue = OCU_CM_IN_REF_INTERVAL;
        }
        else
        {
            StatusValue = OCU_CM_OUT_REF_INTERVAL;
        }
    }
    else
    {/*counter has rolled-over*/
        
        /*check if post-update value is outside the compare match interval*/
        if((PostCmWriteValue < StartIntervalValue) && (PostCmWriteValue > EndIntervalValue))
        {
            StatusValue = OCU_CM_OUT_REF_INTERVAL;
        }
        else
        {
            StatusValue = OCU_CM_IN_REF_INTERVAL;
        }        
    }
    return StatusValue;    
}
#endif
/*================================================================================================================
*                                      GLOBAL FUNCTIONS
==================================================================================================================*/

/*=================================================================================================================*/
/**
* @brief   Ocu driver initialization function for eMios module.
* @details This function is called once for all eMios hw channels corresponding to the configured
*          timer channels, and:
*          - initializes the global data-stores (Ocu_Emios_u8ChannPerHwModuleMap)        
*          - disables the timer channel
*          - disables the timer compare interrupts corresponding to Emios channel
*          - clears the timer compare interrupt flags corresponding to Emios channel
*          - Select the clock divider value for the internal prescaler of Unified Channel
*          - select counter Bus ( A, B, C, D, E or INTERNAL Bus)
*          - set the compare register A to configured default threshold value to Emios channel.
*          - set the compare register A of Counter Bus to configured max counter value.
*          - if output pin is enable, Set the mode for SAOC and the output pin operates normally.
*          - clear pending interrupt serviced .         
*          - enables the prescaler for counter bus (start run counter) .         
*          - configures Control EMIOS_CCR_ADDR32 register to expected values.         
*
* @param[in] peMiosIpConfig - Pointer to configuration structure of emios channels
*
*/
/** @violates @ref OCU_EMIOS_C_REF_6 MISRA 2012  Advisory Rule 8.7, These functions represent the API 
*   of the driver. External linkage is needed to ""export"" the API.*/
FUNC(void, GPT_CODE) Ocu_eMios_Init
(
    CONSTP2CONST(Ocu_eMios_IpConfigType, AUTOMATIC, OCU_APPL_CONST)  peMiosIpConfig
)
{
    VAR(uint8, AUTOMATIC)   u8HwChannelId;              /* assigned HW channel id code */
    VAR(uint8, AUTOMATIC)   u8ModuleIdx;                /* assigned eMios HW module  index */
    VAR(uint8, AUTOMATIC)   u8ChannelIdx;               /* assigned eMios HW channel index */
    VAR(uint8, AUTOMATIC)   u8HwChannelMasterBusId;     /* assigned HW channel id code */
    VAR(uint8, AUTOMATIC)   u8ChannelMasterBusIdx;      /* assigned eMios HW channel index */
    VAR(uint8, AUTOMATIC)   u8Counter;                  /* Counter value used in loops */
    VAR(uint32, AUTOMATIC)  u32CCRRegValue      = 0U;
    VAR(uint32, AUTOMATIC)  u32CCRRegMasterBus  = 0U;
    VAR(uint32, AUTOMATIC)  u32BusSelect        = 0U;
    VAR(uint32, AUTOMATIC)  u32ControlValue     = 0U;
    VAR(uint8, AUTOMATIC)   u8OcuNumHwChannels  = 0U;

    /* @brief Pointer to eMios channel specific configuration */
    P2CONST(Ocu_eMios_ChannelConfigType, AUTOMATIC, OCU_APPL_CONST) peMiosChannelConfig;
    
    u8OcuNumHwChannels = peMiosIpConfig->nNumChannels; /*update the number of channels for current configuration*/
    
    /* Initialize each eMios configured channel */
    for (u8Counter = 0x0U; u8Counter < u8OcuNumHwChannels; u8Counter++)
    {
        /* Reset u32CCRRegValue to 0 */
        u32CCRRegValue = 0x0U;

        /* Reset u32CCRRegValue of to 0 */
        u32CCRRegMasterBus = 0x0U;

        peMiosChannelConfig = &(*peMiosIpConfig->pChannelsConfig)[u8Counter];

        /* get module HW channel id code - which is formed for the physical module and channel index values*/
        u8HwChannelId   = peMiosChannelConfig->HwChannel;
        u32ControlValue = peMiosChannelConfig->ControlValue;

        /* Get eMios Module and Channel of this Ocu channel */
        u8ModuleIdx  = (uint8)(EMIOS_MODULE_INDEX_U8(u8HwChannelId));
        u8ChannelIdx = (uint8)(EMIOS_CHANNEL_INDEX_U8(u8HwChannelId));

        /* Get eMios Channel of Counter Bus */
        u8HwChannelMasterBusId   = peMiosChannelConfig->HwChannel_CounterBus;
        u8ChannelMasterBusIdx    =(uint8)(EMIOS_CHANNEL_INDEX_U8(u8HwChannelMasterBusId));
        
        #if ((OCU_SET_RELATIVE_THRESHOLD_API == STD_ON) || (OCU_SET_ABSOLUTE_THRESHOLD_API == STD_ON) || (OCU_DEINIT_API == STD_ON))
        /* Install Ocu_eMios_u8CounterBusIdx[] is MASTER_BUS_NOT_INSTALL */
        Ocu_eMios_u8CounterBusIdx[u8HwChannelId] = (uint8) MASTER_BUS_NOT_INSTALL;
        #endif

        #if ((OCU_SET_RELATIVE_THRESHOLD_API == STD_ON) || (OCU_SET_ABSOLUTE_THRESHOLD_API == STD_ON))
        /* Store the Max Counter Value*/
        Ocu_eMios_u32MaxCounterValue[u8HwChannelId] =(uint32)peMiosChannelConfig->MaxCounterValue;
        #endif
        /* Disable interrupts */
        /**@violates @ref OCU_EMIOS_C_REF_3  Rule 11.4, A conversion should not be performed between a pointer to object and an integer type */
        /**@violates @ref OCU_EMIOS_C_REF_4  Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type */
        /**@violates @ref OCU_EMIOS_C_REF_5  Rule 10.8, The value of a composite expression shall not be cast to a different assential type category or a wider assential type */
        REG_BIT_CLEAR32(EMIOS_CCR_ADDR32(u8ModuleIdx, u8ChannelIdx), CCR_FEN_MASK_U32);
    
        /* Reset Channel to Configure Channel */
        /**@violates @ref OCU_EMIOS_C_REF_3  Rule 11.4, A conversion should not be performed between a pointer to object and an integer type */
        /**@violates @ref OCU_EMIOS_C_REF_4  Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type */
        /**@violates @ref OCU_EMIOS_C_REF_5  Rule 10.8, The value of a composite expression shall not be cast to a different assential type category or a wider assential type */
        REG_RMW32(EMIOS_CCR_ADDR32(u8ModuleIdx, u8ChannelIdx), (CCR_MODE_MASK_U32 | CCR_EDSEL_MASK_U32 | CCR_UCPREN_MASK_U32 | CCR_EDPOL_MASK_U32 | CCR_BSL_MASK_U32), 0x0UL);
        
        /*Configure Bus Select for EMIOS*/
        u32BusSelect = (uint32)((uint32)((u32ControlValue & OCU_EMIOS_BUS_SELECT_PARAM_MASK) >> OCU_EMIOS_BUS_SELECT_PARAM_SHIFT));

        u32CCRRegValue |= u32BusSelect << CCR_BSL_SHIFT;
        
        /*configure DEBUG bits*/
        u32CCRRegValue |= (uint32)((uint32)((u32ControlValue & OCU_EMIOS_DBG_INFO_MASK) >> OCU_EMIOS_DBG_INFO_SHIFT) << CCR_FREN_SHIFT);
        
        /* Select the clock divider value for the internal prescaler of Unified Channel*/
        u32CCRRegValue |= (uint32)((uint32)((u32ControlValue & OCU_EMIOS_CLOCK_DIV_MASK) >> OCU_EMIOS_CLOCK_DIV_SHIFT) << CCR_UCPRE_SHIFT);
         
        
        /*Configure default PIN Action behavior*/
        Ocu_eMios_u8OcuAction[u8HwChannelId] = (uint8)((u32ControlValue & OCU_EMIOS_PIN_ACTION_MASK) >> OCU_EMIOS_PIN_ACTION_SHIFT);

        /* Set Compare A Value  = DefaultThreshold) */
        /**@violates @ref OCU_EMIOS_C_REF_3  Rule 11.4, A conversion should not be performed between a pointer to object and an integer type */
        /**@violates @ref OCU_EMIOS_C_REF_4  Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type */
        /**@violates @ref OCU_EMIOS_C_REF_5  Rule 10.8, The value of a composite expression shall not be cast to a different assential type category or a wider assential type */
        REG_WRITE32(EMIOS_CADR_ADDR32(u8ModuleIdx, u8ChannelIdx), (uint32) peMiosChannelConfig->DefaultThreshold);
        
        /* The EDPOL value is transferred to the output flip-flop */
        u32CCRRegValue |= ((uint32)((uint32)((u32ControlValue & OCU_EMIOS_PIN_STATE_MASK) >> OCU_EMIOS_PIN_STATE_SHIFT) << CCR_EDPOL_SHIFT));
        
        
        if(OCU_EMIOS_OUTPUT_ENABLE == ((u32ControlValue & OCU_EMIOS_OUTPIN_USED_MASK) >> OCU_EMIOS_OUTPIN_USED_SHIFT)) {

            /*Set bit EDSEL to 0 */
            u32CCRRegValue |= CCR_EDSEL_0_U32 << CCR_EDSEL_SHIFT;
            /* Set the mode for SAOC Out put */
            u32CCRRegValue |= CCR_MODE_SAOC_U32 << CCR_MODE_SHIFT;
            /* The output pin operates normally */
            u32CCRRegValue &= ~CCR_ODIS_MASK_U32;
        }
        
        /**@violates @ref OCU_EMIOS_C_REF_3  Rule 11.4, A conversion should not be performed between a pointer to object and an integer type */
        /**@violates @ref OCU_EMIOS_C_REF_4  Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type */
        /**@violates @ref OCU_EMIOS_C_REF_5  Rule 10.8, The value of a composite expression shall not be cast to a different assential type category or a wider assential type */
        /* Clear pending interrupt serviced */
        REG_WRITE32(EMIOS_CSR_ADDR32(u8ModuleIdx, u8ChannelIdx),(uint32)(CSR_OVR_BIT_U32 | CSR_OVFL_BIT_U32 | CSR_FLAG_BIT_U32));
        
        /* Configure for eMIOS_Cn Master Bus */
        if (u32BusSelect != (uint32)EMIOS_BUS_INTERNAL_COUNTER) 
        {
            #if ((OCU_SET_RELATIVE_THRESHOLD_API == STD_ON) || (OCU_SET_ABSOLUTE_THRESHOLD_API == STD_ON) || (OCU_DEINIT_API == STD_ON))
            /* Store CounterBus Id*/
            Ocu_eMios_u8CounterBusIdx[u8HwChannelId] = u8ChannelMasterBusIdx;
            #endif
            
            /* Set the mode for MCB Out put */
            u32CCRRegMasterBus |= CCR_MODE_MCB_INT_CLOCK_U32 << CCR_MODE_SHIFT;
            
            /* Select the clock divider value for the internal prescaler of Unified Channel*/
            u32CCRRegMasterBus |= (uint32)((uint32)((u32ControlValue & OCU_EMIOS_CLOCK_DIV_MASK) >> OCU_EMIOS_CLOCK_DIV_SHIFT) << CCR_UCPRE_SHIFT);

            /* The UCPREN bit enables the prescaler counter*/
            u32CCRRegMasterBus |= (uint32)(CCR_UCPREN_ENABLE_U32 << CCR_UCPREN_SHIFT);
            
            /* Bus select is EMIOS_BUS_INTERNAL_COUNTER*/
            u32CCRRegMasterBus |= (uint32)((uint32)EMIOS_BUS_INTERNAL_COUNTER << CCR_BSL_SHIFT);
            
            /* Set Configure for Master Bus*/
            /**@violates @ref OCU_EMIOS_C_REF_3  Rule 11.4, A conversion should not be performed between a pointer to object and an integer type */
            /**@violates @ref OCU_EMIOS_C_REF_4  Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type */
            /**@violates @ref OCU_EMIOS_C_REF_5  Rule 10.8, The value of a composite expression shall not be cast to a different assential type category or a wider assential type */
            REG_WRITE32(EMIOS_CADR_ADDR32(u8ModuleIdx, u8ChannelMasterBusIdx), (uint32)peMiosChannelConfig->MaxCounterValue);
            
            /**@violates @ref OCU_EMIOS_C_REF_3  Rule 11.4, A conversion should not be performed between a pointer to object and an integer type */
            /**@violates @ref OCU_EMIOS_C_REF_4  Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type */
            /**@violates @ref OCU_EMIOS_C_REF_5  Rule 10.8, The value of a composite expression shall not be cast to a different assential type category or a wider assential type */
            REG_WRITE32(EMIOS_CCR_ADDR32(u8ModuleIdx, u8ChannelMasterBusIdx), u32CCRRegMasterBus);
        } 
        else 
        {
            /* The UCPREN bit enables the prescaler counter*/
            u32CCRRegValue |= (uint32)(CCR_UCPREN_ENABLE_U32 << CCR_UCPREN_SHIFT);
            
            #if ((OCU_SET_RELATIVE_THRESHOLD_API == STD_ON) || (OCU_SET_ABSOLUTE_THRESHOLD_API == STD_ON) || (OCU_DEINIT_API == STD_ON))
            /* Store CounterBus Id*/ 
            Ocu_eMios_u8CounterBusIdx[u8HwChannelId] = u8ChannelIdx;
            #endif
        }
        
        
        /**@violates @ref OCU_EMIOS_C_REF_3  Rule 11.4, A conversion should not be performed between a pointer to object and an integer type */
        /**@violates @ref OCU_EMIOS_C_REF_4  Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type */
        /**@violates @ref OCU_EMIOS_C_REF_5  Rule 10.8, The value of a composite expression shall not be cast to a different assential type category or a wider assential type */
        /* Set Configure for eMIOS_Cn*/
        REG_WRITE32(EMIOS_CCR_ADDR32(u8ModuleIdx, u8ChannelIdx), u32CCRRegValue);
    }
}

/*=================================================================================================================*/
#if (OCU_DEINIT_API == STD_ON)
/**
* @brief   Ocu driver de-initialization function for eMios module.
* @details This function is called separately for each EMIOS hw channel corresponding to the configured
*          timer channels, and:
*          - disables the timer compare interrupts corresponding to Emios channel
*          - clears the timer compare interrupt flags corresponding to Emios channel
*          - resets eMIOS UC Control register.
*          - resets the compare register eMIOS UC A register .
*          - resets eMIOS UC Control register of Master Bus.
*          - resets the compare register eMIOS UC A register of Master Bus.
*
* @param[in]     peMiosIpConfig - Pointer to configuration structure of emios channels
*
*
*/
/** @violates @ref OCU_EMIOS_C_REF_6 MISRA 2012  Advisory Rule 8.7, These functions represent the API 
*   of the driver. External linkage is needed to ""export"" the API.*/
FUNC(void, GPT_CODE) Ocu_eMios_DeInit
(
    CONSTP2CONST(Ocu_eMios_IpConfigType, AUTOMATIC, OCU_APPL_CONST)  peMiosIpConfig
)
{
    /* @brief Pointer to eMios channel specific configuration */
    P2CONST(Ocu_eMios_ChannelConfigType, AUTOMATIC, OCU_APPL_CONST) peMiosChannelConfig;
    
    VAR(Ocu_eMios_ChannelType, AUTOMATIC) chCounter;
    VAR(uint8, AUTOMATIC) u8HwChannelId;
    VAR(uint8, AUTOMATIC) u8ModuleIdx;   /* assigned eMios HW module  index */
    VAR(uint8, AUTOMATIC) u8ChannelIdx;  /* assigned eMios HW channel index */
    VAR(uint8, AUTOMATIC) u8ChannelMasterBusIdx;  /* assigned eMios HW channel index */
    
    for (chCounter=0U; chCounter < peMiosIpConfig->nNumChannels; chCounter++)
    {
        /* only handle eMios channels */
        peMiosChannelConfig = &(*peMiosIpConfig->pChannelsConfig)[chCounter];

        /* get module HW channel id code - which is formed for the physical module and channel index values*/        
        u8HwChannelId  = peMiosChannelConfig->HwChannel;
        
        u8ModuleIdx  = (uint8)(EMIOS_MODULE_INDEX_U8(u8HwChannelId));
        u8ChannelIdx = (uint8)(EMIOS_CHANNEL_INDEX_U8(u8HwChannelId));
    
        u8ChannelMasterBusIdx = (uint8)(Ocu_eMios_u8CounterBusIdx[u8HwChannelId]);
        
        /* Disable interrupts */
        /**@violates @ref OCU_EMIOS_C_REF_3  Rule 11.4, A conversion should not be performed between a pointer to object and an integer type */
        /**@violates @ref OCU_EMIOS_C_REF_4  Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type */
        /**@violates @ref OCU_EMIOS_C_REF_5  Rule 10.8, The value of a composite expression shall not be cast to a different assential type category or a wider assential type */
        REG_BIT_CLEAR32(EMIOS_CCR_ADDR32(u8ModuleIdx, u8ChannelIdx), CCR_FEN_MASK_U32);
        
        /* Clear pending interrupt serviced */
        /**@violates @ref OCU_EMIOS_C_REF_3  Rule 11.4, A conversion should not be performed between a pointer to object and an integer type */
        /**@violates @ref OCU_EMIOS_C_REF_4  Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type */
        /**@violates @ref OCU_EMIOS_C_REF_5  Rule 10.8, The value of a composite expression shall not be cast to a different assential type category or a wider assential type */
        REG_WRITE32(EMIOS_CSR_ADDR32(u8ModuleIdx, u8ChannelIdx),(uint32)(CSR_OVR_BIT_U32 | CSR_OVFL_BIT_U32 | CSR_FLAG_BIT_U32));
        
        /* Reset Timer control register, internal Counter is also cleared when entering GPIO Mode */
        /**@violates @ref OCU_EMIOS_C_REF_3  Rule 11.4, A conversion should not be performed between a pointer to object and an integer type */
        /**@violates @ref OCU_EMIOS_C_REF_4  Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type */
        /**@violates @ref OCU_EMIOS_C_REF_5  Rule 10.8, The value of a composite expression shall not be cast to a different assential type category or a wider assential type */
        REG_WRITE32(EMIOS_CCR_ADDR32(u8ModuleIdx, u8ChannelIdx), 0U);
    
        /* Set Compare Value to 1 (writing 0 may lead to unpredictable result ) */
        /**@violates @ref OCU_EMIOS_C_REF_3  Rule 11.4, A conversion should not be performed between a pointer to object and an integer type */
        /**@violates @ref OCU_EMIOS_C_REF_4  Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type */
        /**@violates @ref OCU_EMIOS_C_REF_5  Rule 10.8, The value of a composite expression shall not be cast to a different assential type category or a wider assential type */
        REG_WRITE32(EMIOS_CADR_ADDR32(u8ModuleIdx, u8ChannelIdx), 0U);
        
        if (MASTER_BUS_NOT_INSTALL != u8ChannelMasterBusIdx)
        {
            /* Bus Counter is also cleared when entering GPIO Mode */
            /**@violates @ref OCU_EMIOS_C_REF_3  Rule 11.4, A conversion should not be performed between a pointer to object and an integer type */
            /**@violates @ref OCU_EMIOS_C_REF_4  Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type */
            /**@violates @ref OCU_EMIOS_C_REF_5  Rule 10.8, The value of a composite expression shall not be cast to a different assential type category or a wider assential type */
            REG_WRITE32(EMIOS_CCR_ADDR32(u8ModuleIdx, u8ChannelMasterBusIdx), 0U);
        
            /* Set max counter Value to 0  */
            /**@violates @ref OCU_EMIOS_C_REF_3  Rule 11.4, A conversion should not be performed between a pointer to object and an integer type */
            /**@violates @ref OCU_EMIOS_C_REF_4  Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type */
            /**@violates @ref OCU_EMIOS_C_REF_5  Rule 10.8, The value of a composite expression shall not be cast to a different assential type category or a wider assential type */
            REG_WRITE32(EMIOS_CADR_ADDR32(u8ModuleIdx, u8ChannelMasterBusIdx), 0U);
        }
        /* Clear Interrupt Flag */
        /**@violates @ref OCU_EMIOS_C_REF_3  Rule 11.4, A conversion should not be performed between a pointer to object and an integer type */
        /**@violates @ref OCU_EMIOS_C_REF_4  Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type */
        /**@violates @ref OCU_EMIOS_C_REF_5  Rule 10.8, The value of a composite expression shall not be cast to a different assential type category or a wider assential type */
        REG_WRITE32(EMIOS_CSR_ADDR32(u8ModuleIdx, u8ChannelIdx), CSR_FLAG_MASK_U32);
    }
}
#endif

/*=================================================================================================================*/
/**
* @brief   Ocu driver function for starting the eMios timer channel.
* @details This function:
*          - enables the channel timer.
*
* @param[in]     u8HwChannelId        eMios hw channel ID
*
*/
/** @violates @ref OCU_EMIOS_C_REF_6 MISRA 2012  Advisory Rule 8.7, These functions represent the API 
*   of the driver. External linkage is needed to ""export"" the API.*/
FUNC(void, OCU_CODE) Ocu_eMios_StartChannel
(
    VAR(uint8, AUTOMATIC) u8HwChannelId
)
{
    VAR(uint8, AUTOMATIC) u8ModuleIdx;   /**< @brief assigned eMios HW module  index */
    VAR(uint8, AUTOMATIC) u8ChannelIdx;  /**< @brief assigned eMios HW channel index */
    VAR(uint32, AUTOMATIC) u32UCCtrlReg;
    VAR(uint32, AUTOMATIC) u32UCsReg;
    
    u8ModuleIdx  = (uint8)EMIOS_MODULE_INDEX_U8(u8HwChannelId);
    u8ChannelIdx = (uint8)EMIOS_CHANNEL_INDEX_U8(u8HwChannelId);
    
    /*enter critical section TODO check*/
    SchM_Enter_Ocu_OCU_EXCLUSIVE_AREA_09();
    {
        /**@violates @ref OCU_EMIOS_C_REF_3  Rule 11.4, A conversion should not be performed between a pointer to object and an integer type */
        /**@violates @ref OCU_EMIOS_C_REF_4  Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type */
        /**@violates @ref OCU_EMIOS_C_REF_5  Rule 10.8, The value of a conposite expression shall not be cast to a different assential type category or a wider assential type */
        u32UCCtrlReg = REG_READ32(EMIOS_CCR_ADDR32(u8ModuleIdx, (uint32)u8ChannelIdx));
        
        /*clear EDSEL, EDPOL, ODIS bits */
        /**@violates @ref OCU_EMIOS_C_REF_3  Rule 11.4, A conversion should not be performed between a pointer to object and an integer type */
        /**@violates @ref OCU_EMIOS_C_REF_4  Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type */
        /**@violates @ref OCU_EMIOS_C_REF_5  Rule 10.8, The value of a conposite expression shall not be cast to a different assential type category or a wider assential type */
        u32UCCtrlReg &= (uint32)(~(CCR_EDSEL_MASK_U32 | CCR_EDPOL_MASK_U32 | CCR_ODIS_MASK_U32));
        
        switch(Ocu_eMios_u8OcuAction[u8HwChannelId])
        {
        case (uint8)OCU_SET_HIGH:
            {
                u32UCCtrlReg |= (CCR_EDPOL_MASK_U32);
            }
            break;
            
        case (uint8)OCU_DISABLE:
            {
            u32UCCtrlReg |= CCR_ODIS_MASK_U32;
            }
            break;
            
        case (uint8)OCU_TOGGLE:
            {
            u32UCCtrlReg |= CCR_EDSEL_MASK_U32;
            }
            break;
            
            default:
            {
                /**@violates @ref OCU_EMIOS_C_REF_3  Rule 11.4, A conversion should not be performed between a pointer to object and an integer type */
                /**@violates @ref OCU_EMIOS_C_REF_4  Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type */
                /**@violates @ref OCU_EMIOS_C_REF_5  Rule 10.8, The value of a conposite expression shall not be cast to a different assential type category or a wider assential type */
                u32UCsReg = REG_READ32(EMIOS_CSR_ADDR32(u8ModuleIdx, u8ChannelIdx));
                u32UCCtrlReg |= ((uint32)((uint32)(u32UCsReg & CSR_UCOUT_MASK_U32) >> CSR_UCOUT_SHIFT) << CCR_EDPOL_SHIFT);
            }
            break;
        }
        
        /* Write the EMIOS_CCR_ADDR32 with appropriate values */
        /**@violates @ref OCU_EMIOS_C_REF_3  Rule 11.4, A conversion should not be performed between a pointer to object and an integer type */
        /**@violates @ref OCU_EMIOS_C_REF_4  Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type */
        /**@violates @ref OCU_EMIOS_C_REF_5  Rule 10.8, The value of a conposite expression shall not be cast to a different assential type category or a wider assential type */
        REG_WRITE32(EMIOS_CCR_ADDR32(u8ModuleIdx, (uint32)u8ChannelIdx), u32UCCtrlReg);
 #if (OCU_NOTIFICATION_SUPPORTED == STD_ON)
        /*Clear interrupt flags*/
        /**@violates @ref OCU_EMIOS_C_REF_3  Rule 11.4, A conversion should not be performed between a pointer to object and an integer type */
        /**@violates @ref OCU_EMIOS_C_REF_4  Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type */
        /**@violates @ref OCU_EMIOS_C_REF_5  Rule 10.8, The value of a conposite expression shall not be cast to a different assential type category or a wider assential type */
        REG_WRITE32(EMIOS_CSR_ADDR32(u8ModuleIdx, u8ChannelIdx),CSR_FLAG_MASK_U32);

        /* Enable interrupt */
        /**@violates @ref OCU_EMIOS_C_REF_3  Rule 11.4, A conversion should not be performed between a pointer to object and an integer type */
        /**@violates @ref OCU_EMIOS_C_REF_4  Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type */
        /**@violates @ref OCU_EMIOS_C_REF_5  Rule 10.8, The value of a conposite expression shall not be cast to a different assential type category or a wider assential type */
        REG_BIT_SET32(EMIOS_CCR_ADDR32(u8ModuleIdx, (uint32)u8ChannelIdx), CCR_FEN_MASK_U32);
#endif
    }
    /*exit critical section*/
    SchM_Exit_Ocu_OCU_EXCLUSIVE_AREA_09();
}

/*=================================================================================================================*/
/**
* @brief   Ocu driver function for stopping the eMios timer channel.
* @details This function:
*          - stop the timer channel
*
* @param[in]     u8HwChannelId        eMios hw channel ID
*
*/
/** @violates @ref OCU_EMIOS_C_REF_6 MISRA 2012  Advisory Rule 8.7, These functions represent the API 
*   of the driver. External linkage is needed to ""export"" the API.*/
FUNC(void, OCU_CODE) Ocu_eMios_StopChannel
(
    VAR(uint8, AUTOMATIC) u8HwChannelId
)
{
    VAR(uint8, AUTOMATIC) u8ModuleIdx;   /* assigned eMios HW module  index */
    VAR(uint8, AUTOMATIC) u8ChannelIdx;  /* assigned eMios HW channel index */    
    
    /* Get eMios Module and Channel of this Ocu channel */
    u8ModuleIdx  = (uint8)EMIOS_MODULE_INDEX_U8(u8HwChannelId);
    u8ChannelIdx = (uint8)EMIOS_CHANNEL_INDEX_U8(u8HwChannelId);
    
    /*enter critical section*/
    SchM_Enter_Ocu_OCU_EXCLUSIVE_AREA_10();
    {
        /*Clear output mode bits*/
        /**@violates @ref OCU_EMIOS_C_REF_3  Rule 11.4, A conversion should not be performed between a pointer to object and an integer type */
        /**@violates @ref OCU_EMIOS_C_REF_4  Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type */
        /**@violates @ref OCU_EMIOS_C_REF_5  Rule 10.8, The value of a conposite expression shall not be cast to a different assential type category or a wider assential type */
        REG_RMW32(EMIOS_CCR_ADDR32(u8ModuleIdx, (uint32)u8ChannelIdx), (CCR_EDSEL_MASK_U32 | CCR_EDPOL_MASK_U32 | CCR_ODIS_MASK_U32), 0x0UL);
 #if (OCU_NOTIFICATION_SUPPORTED == STD_ON)
     
        /*Clear interrupt flags*/
        /**@violates @ref OCU_EMIOS_C_REF_3  Rule 11.4, A conversion should not be performed between a pointer to object and an integer type */
        /**@violates @ref OCU_EMIOS_C_REF_4  Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type */
        /**@violates @ref OCU_EMIOS_C_REF_5  Rule 10.8, The value of a conposite expression shall not be cast to a different assential type category or a wider assential type */
        REG_BIT_CLEAR32(EMIOS_CSR_ADDR32(u8ModuleIdx, (uint32)u8ChannelIdx), CSR_FLAG_MASK_U32);
        
        /* disable interrupt */
        /**@violates @ref OCU_EMIOS_C_REF_3  Rule 11.4, A conversion should not be performed between a pointer to object and an integer type */
        /**@violates @ref OCU_EMIOS_C_REF_4  Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type */
        /**@violates @ref OCU_EMIOS_C_REF_5  Rule 10.8, The value of a conposite expression shall not be cast to a different assential type category or a wider assential type */
        REG_BIT_CLEAR32(EMIOS_CCR_ADDR32(u8ModuleIdx, u8ChannelIdx), CCR_FEN_MASK_U32);
#endif
    }
    /*exit critical section*/
    SchM_Exit_Ocu_OCU_EXCLUSIVE_AREA_10();
}

/*=================================================================================================================*/
#if (OCU_GET_COUNTER_API == STD_ON)
/**
* @brief   Ocu driver function for getting the current counter value for an eMios timer channel.
* @details This function is called for reading the eMios channel counter register.
*
* @param[in]     u8HwChannelId                eMios hw channel ID
* return         register CNTR current value
*/
/** @violates @ref OCU_EMIOS_C_REF_6 MISRA 2012  Advisory Rule 8.7, These functions represent the API 
*   of the driver. External linkage is needed to ""export"" the API.*/
FUNC(Ocu_ValueType, OCU_CODE) Ocu_eMios_GetCounter
(
    VAR(uint8, AUTOMATIC) u8HwChannelId
)
{
    VAR(Ocu_ValueType, AUTOMATIC)  nReturnValue;
    VAR(uint8, AUTOMATIC) u8ModuleIdx;   /* assigned eMios HW module  index */
    VAR(uint8, AUTOMATIC) u8ChannelIdx;  /* assigned eMios HW channel index */    

    u8ModuleIdx  = EMIOS_MODULE_INDEX_U8(u8HwChannelId);
    u8ChannelIdx = EMIOS_CHANNEL_INDEX_U8(u8HwChannelId);

    /*Read the elapsed time*/
    /**@violates @ref OCU_EMIOS_C_REF_3  Rule 11.4, A conversion should not be performed between a pointer to object and an integer type */
    /**@violates @ref OCU_EMIOS_C_REF_4  Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type */
    /**@violates @ref OCU_EMIOS_C_REF_5  Rule 10.8, The value of a conposite expression shall not be cast to a different assential type category or a wider assential type */
    nReturnValue = (Ocu_ValueType)REG_READ32(EMIOS_CCNTR_ADDR32(u8ModuleIdx, (uint32)u8ChannelIdx));  /* TODO - check if masterbus should be read for channels that have masterbus */
    /* TODO - check if master bus should be read for channels that have master bus */

    return(nReturnValue);
}
#endif /*OCU_GET_COUNTER_API == STD_ON*/

/*=================================================================================================================*/
#if (OCU_SET_PIN_ACTION_API == STD_ON)
/**
* @brief   Ocu driver function for setting the Pin Action for the current eMios channel
* @details This function:
*
*
* @param[in]     u8HwChannel        Etimer hw channel ID
* @param[in]     PinAction          Type of action: OCU_SET_LOW,OCU_SET_HIGH,OCU_TOGGLE
* @param[in]     bIsRunning         Is channel running or not?
*
*
*/
/** @violates @ref OCU_EMIOS_C_REF_6 MISRA 2012  Advisory Rule 8.7, These functions represent the API 
*   of the driver. External linkage is needed to ""export"" the API.*/
FUNC(void, OCU_CODE) Ocu_eMios_SetPinAction
(
    VAR(uint8, AUTOMATIC) u8HwChannel, 
    VAR(uint8, AUTOMATIC) PinAction,
    VAR(boolean, AUTOMATIC) bIsRunning
)
{
    VAR(uint8,AUTOMATIC) u8ModuleIdx;
    VAR(uint8,AUTOMATIC) u8ChannelIdx;
    VAR(uint32,AUTOMATIC) u32UCCtrlReg;
    VAR(uint32, AUTOMATIC) u32tempLevel;
    
    u8ModuleIdx = EMIOS_MODULE_INDEX_U8(u8HwChannel);
    u8ChannelIdx = EMIOS_CHANNEL_INDEX_U8(u8HwChannel);
        
    /*enter critical section*/
    SchM_Enter_Ocu_OCU_EXCLUSIVE_AREA_11();
    {
        /**@violates @ref OCU_EMIOS_C_REF_3  Rule 11.4, A conversion should not be performed between a pointer to object and an integer type */
        /**@violates @ref OCU_EMIOS_C_REF_4  Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type */
        /**@violates @ref OCU_EMIOS_C_REF_5  Rule 10.8, The value of a conposite expression shall not be cast to a different assential type category or a wider assential type */
        u32UCCtrlReg = REG_READ32(EMIOS_CCR_ADDR32(u8ModuleIdx,(uint32)u8ChannelIdx));
        /*clear EDSEL EDPOL ODIS*/
        u32UCCtrlReg &= (uint32)(~(CCR_EDSEL_MASK_U32 | CCR_EDPOL_MASK_U32 | CCR_ODIS_MASK_U32));
        
        Ocu_eMios_u8OcuAction[u8HwChannel] = PinAction;
        
        switch(Ocu_eMios_u8OcuAction[u8HwChannel])
        {
            case (uint8)OCU_DISABLE:
                {
                    /* Read level output of channel before Disable output */
                    /**@violates @ref OCU_EMIOS_C_REF_3  Rule 11.4, A conversion should not be performed between a pointer to object and an integer type */
                    /**@violates @ref OCU_EMIOS_C_REF_4  Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type */
                    /**@violates @ref OCU_EMIOS_C_REF_5  Rule 10.8, The value of a composite expression shall not be cast to a different assential type category or a wider assential type */
                    u32tempLevel = (uint32)((REG_READ32(EMIOS_CSR_ADDR32(u8ModuleIdx, u8ChannelIdx)) \
                                    & CSR_UCOUT_MASK_U32) >> CSR_UCOUT_SHIFT) << CCR_EDPOL_SHIFT;
                                    
                    u32UCCtrlReg |= u32tempLevel;
                    
                }
            break;
            case (uint8)OCU_SET_HIGH:
                {
                    u32UCCtrlReg |= (CCR_EDPOL_MASK_U32);
                }
                break;
            case (uint8)OCU_TOGGLE:
                {
                    u32UCCtrlReg |= (CCR_EDSEL_MASK_U32);
                }
                break;
            default:
                {
                    /*do nothing */
                }
            break;
        }
        if((boolean)TRUE == bIsRunning)
        {
            /**@violates @ref OCU_EMIOS_C_REF_3  Rule 11.4, A conversion should not be performed between a pointer to object and an integer type */
            /**@violates @ref OCU_EMIOS_C_REF_4  Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type */
            /**@violates @ref OCU_EMIOS_C_REF_5  Rule 10.8, The value of a conposite expression shall not be cast to a different assential type category or a wider assential type */
            REG_WRITE32(EMIOS_CCR_ADDR32(u8ModuleIdx, (uint32)u8ChannelIdx), u32UCCtrlReg);
            
 #if (OCU_NOTIFICATION_SUPPORTED == STD_ON)       
            /*Clear interrupt flags*/
            /**@violates @ref OCU_EMIOS_C_REF_3  Rule 11.4, A conversion should not be performed between a pointer to object and an integer type */
            /**@violates @ref OCU_EMIOS_C_REF_4  Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type */
            /**@violates @ref OCU_EMIOS_C_REF_5  Rule 10.8, The value of a composite expression shall not be cast to a different assential type category or a wider assential type */
            REG_WRITE32(EMIOS_CSR_ADDR32(u8ModuleIdx, (uint32)u8ChannelIdx), CSR_FLAG_MASK_U32);
        
            /* Enable interrupt */
            /**@violates @ref OCU_EMIOS_C_REF_3  Rule 11.4, A conversion should not be performed between a pointer to object and an integer type */
            /**@violates @ref OCU_EMIOS_C_REF_4  Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type */
            /**@violates @ref OCU_EMIOS_C_REF_5  Rule 10.8, The value of a composite expression shall not be cast to a different assential type category or a wider assential type */
            REG_BIT_SET32(EMIOS_CCR_ADDR32(u8ModuleIdx, (uint32)u8ChannelIdx), CCR_FEN_MASK_U32);
#endif
        }

        
    }
    /*exit critical section*/
    SchM_Exit_Ocu_OCU_EXCLUSIVE_AREA_11();
}
#endif /* OCU_SET_PIN_ACTION_API == STD_ON */


/*=================================================================================================================*/
#if (OCU_SET_PIN_STATE_API == STD_ON)
/**
* @brief   Ocu driver function for setting the Pin State for the current eMios channel
* @details This function:
*
*
* @param[in]     u8HwChannel        eMios hw channel ID
*
*
*/
/** @violates @ref OCU_EMIOS_C_REF_6 MISRA 2012  Advisory Rule 8.7, These functions represent the API 
*   of the driver. External linkage is needed to ""export"" the API.*/
FUNC(void, OCU_CODE) Ocu_eMios_SetPinState
(
    VAR(uint8, AUTOMATIC) u8HwChannel,
    VAR(Ocu_PinStateType, AUTOMATIC) PinState
)
{
    VAR(uint8,AUTOMATIC) u8ModuleIdx;
    VAR(uint8,AUTOMATIC) u8ChannelIdx;
    VAR(uint32,AUTOMATIC) u32UCCtrlReg;

    u8ModuleIdx = EMIOS_MODULE_INDEX_U8(u8HwChannel);
    u8ChannelIdx = EMIOS_CHANNEL_INDEX_U8(u8HwChannel);
    
    /*enter critical section*/
    SchM_Enter_Ocu_OCU_EXCLUSIVE_AREA_12();
    {
        /**@violates @ref OCU_EMIOS_C_REF_3  Rule 11.4, A conversion should not be performed between a pointer to object and an integer type */
        /**@violates @ref OCU_EMIOS_C_REF_4  Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type */
        /**@violates @ref OCU_EMIOS_C_REF_5  Rule 10.8, The value of a conposite expression shall not be cast to a different assential type category or a wider assential type */
        u32UCCtrlReg = REG_READ32(EMIOS_CCR_ADDR32(u8ModuleIdx,(uint32)u8ChannelIdx));
        if(OCU_HIGH == PinState)
        {
            /*clear EDSEL*/
            u32UCCtrlReg &= (uint32)(~CCR_EDSEL_MASK_U32);
            /*set EDPOL up 1*/
            u32UCCtrlReg |= CCR_EDPOL_MASK_U32;
        }
        else
        {
            /*clear EDPOL and EDSEL*/
            u32UCCtrlReg &= (uint32)(~(CCR_EDSEL_MASK_U32 | CCR_EDPOL_MASK_U32));
        }
        /*write u32UCCtrlReg for CCR*/
        /**@violates @ref OCU_EMIOS_C_REF_3  Rule 11.4, A conversion should not be performed between a pointer to object and an integer type */
        /**@violates @ref OCU_EMIOS_C_REF_4  Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type */
        /**@violates @ref OCU_EMIOS_C_REF_5  Rule 10.8, The value of a conposite expression shall not be cast to a different assential type category or a wider assential type */
        REG_WRITE32(EMIOS_CCR_ADDR32(u8ModuleIdx, (uint32)u8ChannelIdx), u32UCCtrlReg);
        /*bit CCR_FORCMA set comparator A*/
        /**@violates @ref OCU_EMIOS_C_REF_3  Rule 11.4, A conversion should not be performed between a pointer to object and an integer type */
        /**@violates @ref OCU_EMIOS_C_REF_4  Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type */
        /**@violates @ref OCU_EMIOS_C_REF_5  Rule 10.8, The value of a conposite expression shall not be cast to a different assential type category or a wider assential type */
        REG_BIT_SET32(EMIOS_CCR_ADDR32(u8ModuleIdx, (uint32)u8ChannelIdx),CCR_FORCMA_MASK_U32);
    }
    /*exit critical section*/
    SchM_Exit_Ocu_OCU_EXCLUSIVE_AREA_12();
}
#endif /* OCU_SET_PIN_STATE_API == STD_ON */


/*=================================================================================================================*/
#if (OCU_SET_RELATIVE_THRESHOLD_API == STD_ON)
/**
* @brief      The function changes the eMios compare register value.
* @details This function:
*          - Clears the compare load register 1.
*          - sets the compare load register 2 to the new timeout value.
*
* @param[in]     u8HwChannel         eMios hw channel ID
* @param[in]     RelativeValue       Channel timeout value
* @implements    Ocu_eMios_SetRelativeThreshold_Activity
*/
/** @violates @ref OCU_EMIOS_C_REF_6 MISRA 2012  Advisory Rule 8.7, These functions represent the API 
*   of the driver. External linkage is needed to ""export"" the API.*/
FUNC(Ocu_ReturnType, OCU_CODE) Ocu_eMios_SetRelativeThreshold
(
    VAR(uint8,          AUTOMATIC)    u8HwChannel,
    VAR(Ocu_ValueType,  AUTOMATIC)    RelativeValue
)
{
    VAR(Ocu_ValueType, AUTOMATIC) nCntValuePreUpdate = 0U;     /* CNT register value before computing the update */
    VAR(Ocu_ValueType, AUTOMATIC) nCntValuePostUpdate = 0U;    /* CNT register value after computing the update TODO */
    VAR(Ocu_ValueType, AUTOMATIC) nCmpMatchValue = 0U;         /* New CNT register value */
    VAR(Ocu_ReturnType, AUTOMATIC) returnValue;          /* Return value to see if the current counter has overrunned the postupdate CNT */
    VAR(uint8,AUTOMATIC) u8ModuleIdx;
    VAR(uint8,AUTOMATIC) u8ChannelIdx;

    u8ModuleIdx = EMIOS_MODULE_INDEX_U8(u8HwChannel);
    u8ChannelIdx = EMIOS_CHANNEL_INDEX_U8(u8HwChannel);
    
    SchM_Enter_Ocu_OCU_EXCLUSIVE_AREA_06();
    /* Calculate u16CmpMatchValue, matching can occur at current cycle or next cycle */
    /**@violates @ref OCU_EMIOS_C_REF_3  Rule 11.4, A conversion should not be performed between a pointer to object and an integer type */
    /**@violates @ref OCU_EMIOS_C_REF_4  Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type */
    /**@violates @ref OCU_EMIOS_C_REF_5  Rule 10.8, The value of a conposite expression shall not be cast to a different assential type category or a wider assential type */
    nCntValuePreUpdate = (Ocu_ValueType)REG_READ32(EMIOS_CCNTR_ADDR32(u8ModuleIdx, (uint32)u8ChannelIdx));
    
    /*read value of counter*/
    nCmpMatchValue = (Ocu_ValueType)((uint32)(nCntValuePreUpdate) + (uint32)(RelativeValue));
    /* Set timeout value to EMIOS_CADR_ADDR32 register*/
    /**@violates @ref OCU_EMIOS_C_REF_3  Rule 11.4, A conversion should not be performed between a pointer to object and an integer type */
    /**@violates @ref OCU_EMIOS_C_REF_4  Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type */
    /**@violates @ref OCU_EMIOS_C_REF_5  Rule 10.8, The value of a conposite expression shall not be cast to a different assential type category or a wider assential type */
    REG_WRITE32(EMIOS_CADR_ADDR32(u8ModuleIdx, u8ChannelIdx), nCmpMatchValue);
    
    /* re-Read Counter register */
    /**@violates @ref OCU_EMIOS_C_REF_3  Rule 11.4, A conversion should not be performed between a pointer to object and an integer type */
    /**@violates @ref OCU_EMIOS_C_REF_4  Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type */
    /**@violates @ref OCU_EMIOS_C_REF_5  Rule 10.8, The value of a conposite expression shall not be cast to a different assential type category or a wider assential type */
    nCntValuePostUpdate = (Ocu_ValueType)REG_READ32(EMIOS_CCNTR_ADDR32(u8ModuleIdx, (uint32)Ocu_eMios_u8CounterBusIdx[u8HwChannel]));
    
    /*exit critical section*/
    SchM_Exit_Ocu_OCU_EXCLUSIVE_AREA_06();
    
    /*check if compare match will happen before counter roll-over*/
    returnValue = Ocu_eMios_DetermineNextCmStatus(nCntValuePostUpdate, nCntValuePreUpdate, nCmpMatchValue);

    return returnValue;
}
#endif /* OCU_SET_RELATIVE_THRESHOLD_API == STD_ON */


/*=================================================================================================================*/
#if (OCU_SET_ABSOLUTE_THRESHOLD_API == STD_ON)
/**
* @brief      The function changes the eMios compare register value.
* @details This function:
*          - Clears the compare load register 1.
*          - sets the compare load register 2 to the new timeout value.
*
* @param[in]     u8HwChannel        eMios hw channel ID
* @param[in]     ReferenceValue     Value given by the upper layer and used as a base to determine 
* @param[in]     AbsoluteValue      channel timeout value
* @implements    Ocu_eMios_SetAbsoluteThreshold_Activity
*/

/** @violates @ref OCU_EMIOS_C_REF_6 MISRA 2012  Advisory Rule 8.7, These functions represent the API 
*   of the driver. External linkage is needed to ""export"" the API.*/
FUNC(Ocu_ReturnType, OCU_CODE) Ocu_eMios_SetAbsoluteThreshold
(
    VAR(uint8,          AUTOMATIC)  u8HwChannel,
    VAR(Ocu_ValueType,  AUTOMATIC)  ReferenceValue,
    VAR(Ocu_ValueType,  AUTOMATIC)  AbsoluteValue
)
{
    VAR(Ocu_ValueType, AUTOMATIC) nCntValuePostUpdate = 0U;          /* CNT register value after computing the update TODO - remove = 0*/
    VAR(Ocu_ReturnType, AUTOMATIC) returnValue;            /* Return value to see if the current counter has overrunned the postupdate CNT */

    VAR(uint8,AUTOMATIC) u8ModuleIdx;
    VAR(uint8,AUTOMATIC) u8ChannelIdx;

    u8ModuleIdx = EMIOS_MODULE_INDEX_U8(u8HwChannel);
    u8ChannelIdx = EMIOS_CHANNEL_INDEX_U8(u8HwChannel);
    
    SchM_Enter_Ocu_OCU_EXCLUSIVE_AREA_07();
    /*write value of AbsoluteValue to CADR use for compare*/
    /**@violates @ref OCU_EMIOS_C_REF_3  Rule 11.4, A conversion should not be performed between a pointer to object and an integer type */
    /**@violates @ref OCU_EMIOS_C_REF_4  Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type */
    /**@violates @ref OCU_EMIOS_C_REF_5  Rule 10.8, The value of a conposite expression shall not be cast to a different assential type category or a wider assential type */
    REG_WRITE32(EMIOS_CADR_ADDR32(u8ModuleIdx, u8ChannelIdx), AbsoluteValue);
    
    /*Read counter register*/
    /**@violates @ref OCU_EMIOS_C_REF_3  Rule 11.4, A conversion should not be performed between a pointer to object and an integer type */
    /**@violates @ref OCU_EMIOS_C_REF_4  Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type */
    /**@violates @ref OCU_EMIOS_C_REF_5  Rule 10.8, The value of a conposite expression shall not be cast to a different assential type category or a wider assential type */
    nCntValuePostUpdate= (Ocu_ValueType)REG_READ32(EMIOS_CCNTR_ADDR32(u8ModuleIdx, (uint32)Ocu_eMios_u8CounterBusIdx[u8HwChannel]));
    
    SchM_Exit_Ocu_OCU_EXCLUSIVE_AREA_07();
    returnValue = Ocu_eMios_DetermineNextCmStatus(nCntValuePostUpdate, ReferenceValue, AbsoluteValue);  

    return returnValue;
}
#endif /* OCU_SET_ABSOLUTE_THRESHOLD_API == STD_ON */

/*=================================================================================================================*/
#if (OCU_SET_CLOCK_MODE_API == STD_ON)
/**
* @brief      The function changes the prescaler of eMios channel.
* @details This function:
*          - Change value prescaler in control register 1.
*
* @param[in] 
*
*/

/** @violates @ref OCU_EMIOS_C_REF_6 MISRA 2012  Advisory Rule 8.7, These functions represent the API 
*   of the driver. External linkage is needed to ""export"" the API.*/
FUNC(void, OCU_CODE) Ocu_eMios_SetClockMode
(
    CONSTP2CONST(Ocu_eMios_IpConfigType, AUTOMATIC, OCU_APPL_CONST)  peMiosIpConfig,
    VAR (uint8, AUTOMATIC) ePrescaler
)
{
    VAR(uint8,AUTOMATIC) u8ModuleIdx;
    VAR(uint8,AUTOMATIC) u8ChannelIdx;
    VAR(uint8, AUTOMATIC) u8HwChannelId;
    VAR(Ocu_eMios_ChannelType, AUTOMATIC) chCounter;
    
    P2CONST(Ocu_eMios_ChannelConfigType, AUTOMATIC, OCU_APPL_CONST) peMiosChannelConfig;
    
    SchM_Enter_Ocu_OCU_EXCLUSIVE_AREA_05();
    {
        
    for (chCounter=0U; chCounter < peMiosIpConfig->nNumChannels; chCounter++)
    {
        /* only handle eMios channels */
        peMiosChannelConfig = &(*peMiosIpConfig->pChannelsConfig)[chCounter];
        
        /* get module HW channel id code - which is formed for the physical module and channel index values*/
        u8HwChannelId  = peMiosChannelConfig->HwChannel;
        
        u8ModuleIdx = EMIOS_MODULE_INDEX_U8(u8HwChannelId);
        u8ChannelIdx = EMIOS_CHANNEL_INDEX_U8(u8HwChannelId);

        /*stop eMios channel*/
        /*eMios_StopChannel(peMiosChannelConfig->HwChannel);*/
        
        if ((uint8)OCU_ALTERNATIVE_PRESCALER == ePrescaler)
        {
            /**@violates @ref OCU_EMIOS_C_REF_3  Rule 11.4, A conversion should not be performed between a pointer to object and an integer type */
            /**@violates @ref OCU_EMIOS_C_REF_4  Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type */
            /**@violates @ref OCU_EMIOS_C_REF_5  Rule 10.8, The value of a conposite expression shall not be cast to a different assential type category or a wider assential type */
            REG_RMW32(EMIOS_CCR_ADDR32(u8ModuleIdx, (uint32)u8ChannelIdx),CCR_UCPRE_MASK_U32,((uint32)(((uint32)(peMiosChannelConfig->AltControlValue))&OCU_EMIOS_CLOCK_DIV_MASK)>>OCU_EMIOS_CLOCK_DIV_SHIFT)<<CCR_UCPRE_SHIFT);
        }
        
        if ((uint8)EMIOS_OCU_NORMAL_CLOCK_MODE == ePrescaler){
            /**@violates @ref OCU_EMIOS_C_REF_3  Rule 11.4, A conversion should not be performed between a pointer to object and an integer type */
            /**@violates @ref OCU_EMIOS_C_REF_4  Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type */
            /**@violates @ref OCU_EMIOS_C_REF_5  Rule 10.8, The value of a conposite expression shall not be cast to a different assential type category or a wider assential type */
            REG_RMW32(EMIOS_CCR_ADDR32(u8ModuleIdx, (uint32)u8ChannelIdx),CCR_UCPRE_MASK_U32,((uint32)(((uint32)(peMiosChannelConfig->ControlValue))&OCU_EMIOS_CLOCK_DIV_MASK)>>OCU_EMIOS_CLOCK_DIV_SHIFT)<<CCR_UCPRE_SHIFT);
        }
        /*eMios_StartChannel(peMiosChannelConfig->HwChannel);*/
    }
    
    }
    SchM_Exit_Ocu_OCU_EXCLUSIVE_AREA_05();
}

#endif /* OCU_DUAL_CLOCK_MODE == STD_ON */
/*===============================================================================================*/
#if ((OCU_SET_RELATIVE_THRESHOLD_API == STD_ON) || (OCU_SET_ABSOLUTE_THRESHOLD_API == STD_ON))
/**
* @brief            Ocu_eMios_GetMaxCountValue
* @details          This function will return max counter value for given channel
*
* @param[in]        u8IdxChannelConfig -    Index of channel in (*pChannelsConfig)[]
* @return           Ocu_ValueType   - Max counter value for given channel
*/

FUNC (Ocu_ValueType, OCU_CODE) Ocu_eMios_GetMaxCountValue
(
    VAR(Ocu_ChannelType,    AUTOMATIC)  u8HwChannel
)
{
    VAR(Ocu_ValueType, AUTOMATIC)  ReturnMaxCountValue;
    
    ReturnMaxCountValue = Ocu_eMios_u32MaxCounterValue[u8HwChannel];
    return ReturnMaxCountValue;
}
#endif
/*=================================================================================================================*/
#if (OCU_NOTIFICATION_SUPPORTED == STD_ON)
/**
* @brief   Driver routine to process all the interrupts of eMios.
* @details Support function used by interrupt service routines to implement eMios specific operations
*          and call the OCU upper layer handler to implement non-hardware specific operations.
*
* @param[in]     u8HwChannel      hardware channel index
*
* @implements   Ocu_eMios_ProcessCommonInterrupt_Activity
*
* @violates @ref OCU_EMIOS_C_REF_6 MISRA 2012  Advisory Rule 8.7, These functions represent the API 
*   of the driver. External linkage is needed to ""export"" the API.*/
FUNC(void, OCU_CODE) Ocu_eMios_ProcessCommonInterrupt(VAR(uint8, AUTOMATIC) u8HwChannel)
{
    VAR(uint8,AUTOMATIC) u8ModuleIdx;
    VAR(uint8,AUTOMATIC) u8ChannelIdx;
    VAR(uint32,AUTOMATIC) u32UCCcrReg;
    VAR(uint32,AUTOMATIC) u32UCCsrReg;

    u8ModuleIdx = EMIOS_MODULE_INDEX_U8(u8HwChannel);
    u8ChannelIdx = EMIOS_CHANNEL_INDEX_U8(u8HwChannel);

    /*enter critical section*/
    SchM_Enter_Ocu_OCU_EXCLUSIVE_AREA_13();
    {
        /**@violates @ref OCU_EMIOS_C_REF_3  Rule 11.4, A conversion should not be performed between a pointer to object and an integer type */
        /**@violates @ref OCU_EMIOS_C_REF_4  Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type */
        /**@violates @ref OCU_EMIOS_C_REF_5  Rule 10.8, The value of a conposite expression shall not be cast to a different assential type category or a wider assential type */
        u32UCCcrReg = REG_READ32(EMIOS_CCR_ADDR32(u8ModuleIdx, (uint32)u8ChannelIdx));
        /**@violates @ref OCU_EMIOS_C_REF_3  Rule 11.4, A conversion should not be performed between a pointer to object and an integer type */
        /**@violates @ref OCU_EMIOS_C_REF_4  Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type */
        /**@violates @ref OCU_EMIOS_C_REF_5  Rule 10.8, The value of a conposite expression shall not be cast to a different assential type category or a wider assential type */
        u32UCCsrReg = REG_READ32(EMIOS_CSR_ADDR32(u8ModuleIdx, (uint32)u8ChannelIdx));
        
        /* Check for spurious interrupts */
        if ((((uint32)CSR_FLAG_MASK_U32 & u32UCCsrReg) == (uint32)CSR_FLAG_MASK_U32)
           && (((uint32)CCR_FEN_MASK_U32 & u32UCCcrReg) == (uint32)CCR_FEN_MASK_U32))
        {
            Ocu_Ipw_ProcessCommonInterrupt((Ocu_ChannelType)OCU_EMIOS_MAPPING_START_INDEX_U8 + (Ocu_ChannelType)u8HwChannel);
        }
        /* Clear interrupt flag */
        /**@violates @ref OCU_EMIOS_C_REF_3  Rule 11.4, A conversion should not be performed between a pointer to object and an integer type */
        /**@violates @ref OCU_EMIOS_C_REF_4  Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type */
        /**@violates @ref OCU_EMIOS_C_REF_5  Rule 10.8, The value of a conposite expression shall not be cast to a different assential type category or a wider assential type */
        REG_WRITE32(EMIOS_CSR_ADDR32(u8ModuleIdx, u8ChannelIdx), CSR_FLAG_MASK_U32);
    }
    /*exit critical section*/
    SchM_Exit_Ocu_OCU_EXCLUSIVE_AREA_13();
}

#endif /* OCU_NOTIFICATION_SUPPORTED == STD_ON */

#define OCU_STOP_SEC_CODE
/**@violates @ref OCU_EMIOS_C_REF_1 Precautions shall be taken in order to prevent the contents 
   of a header file being included more than once */
/**@violates @ref OCU_EMIOS_C_REF_2 #include directives should only be preceded by preprocessor directives or comments. */
#include "Ocu_MemMap.h"

#endif /* OCU_EMIOS_USED */

#ifdef __cplusplus
}
#endif

/** @} */
