/*==================================================================================================
*   Project              : RTD AUTOSAR 4.4
*   Platform             : CORTEXM
*   Peripheral           : DMA,CACHE,TRGMUX,LCU,EMIOS,FLEXIO
*   Dependencies         : none
*
*   Autosar Version      : 4.4.0
*   Autosar Revision     : ASR_REL_4_4_REV_0000
*   Autosar Conf.Variant :
*   SW Version           : 0.9.0
*   Build Version        : S32K3_RTD_0_9_0__ASR_REL_4_4_REV_0000_20210326
*
*   (c) Copyright 2020 - 2021 NXP Semiconductors
*   All Rights Reserved.
*
*   NXP Confidential. This software is owned or controlled by NXP and may only be
*   used strictly in accordance with the applicable license terms. By expressly
*   accepting such terms or by downloading, installing, activating and/or otherwise
*   using the software, you are agreeing that you have read, and that you agree to
*   comply with and are bound by, such license terms. If you do not agree to be
*   bound by the applicable license terms, then you may not retain, install,
*   activate or otherwise use the software.
==================================================================================================*/

/**
 *   @file       Emios_Mcl_Ip.h
 *
 *   @version    0.9.0
 *
 *   @brief      AUTOSAR Mcl - Emios Common driver header file.
 *
 *   @addtogroup EMIOS_IP_DRIVER EMIOS IP Driver
 *   @{
 */

#ifndef EMIOS_MCL_IP_H
#define EMIOS_MCL_IP_H

#ifdef __cplusplus
extern "C"{
#endif

/*==================================================================================================
*                                        INCLUDE FILES
* 1) system and project includes
* 2) needed interfaces from external units
* 3) internal and external interfaces from this unit
==================================================================================================*/
#include "OsIf.h"

#include "StandardTypes.h"
#include "Emios_Mcl_Ip_Cfg.h"

#if (EMIOS_MCL_IP_DEV_ERROR_DETECT == STD_ON)
#include "Devassert.h"
#endif

/*==================================================================================================
*                              SOURCE FILE VERSION INFORMATION
==================================================================================================*/
#define EMIOS_MCL_IP_VENDOR_ID_H                    43
#define EMIOS_MCL_IP_AR_RELEASE_MAJOR_VERSION_H     4
#define EMIOS_MCL_IP_AR_RELEASE_MINOR_VERSION_H     4
#define EMIOS_MCL_IP_AR_RELEASE_REVISION_VERSION_H  0
#define EMIOS_MCL_IP_SW_MAJOR_VERSION_H             0
#define EMIOS_MCL_IP_SW_MINOR_VERSION_H             9
#define EMIOS_MCL_IP_SW_PATCH_VERSION_H             0

/*==================================================================================================
*                                     FILE VERSION CHECKS
==================================================================================================*/
#ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
    /* Check if header file and StandardTypes.h are of the same AUTOSAR version */
    #if ((EMIOS_MCL_IP_AR_RELEASE_MAJOR_VERSION_H != STD_AR_RELEASE_MAJOR_VERSION) || \
         (EMIOS_MCL_IP_AR_RELEASE_MINOR_VERSION_H != STD_AR_RELEASE_MINOR_VERSION))
        #error "AUTOSAR Version Numbers of Emios_Mcl_Ip.h and StandardTypes.h are different"
    #endif
#endif

/* Check if header file and Emios_Mcl_Ip_Cfg header file are of the same vendor. */
#if (EMIOS_MCL_IP_VENDOR_ID_H != EMIOS_MCL_IP_CFG_VENDOR_ID)
    #error "Vendor IDs of Emios_Mcl_Ip.h and Emios_Mcl_Ip_Cfg.h are different."
#endif

/* Check if header file and Emios_Mcl_Ip_Cfg header file are of the same AUTOSAR version. */
#if ((EMIOS_MCL_IP_AR_RELEASE_MAJOR_VERSION_H    != EMIOS_MCL_IP_CFG_AR_RELEASE_MAJOR_VERSION) || \
     (EMIOS_MCL_IP_AR_RELEASE_MINOR_VERSION_H    != EMIOS_MCL_IP_CFG_AR_RELEASE_MINOR_VERSION) || \
     (EMIOS_MCL_IP_AR_RELEASE_REVISION_VERSION_H != EMIOS_MCL_IP_CFG_AR_RELEASE_REVISION_VERSION))
    #error "AUTOSAR version numbers of Emios_Mcl_Ip.h and Emios_Mcl_Ip_Cfg.h are different."
#endif

/* Check if header file and Emios_Pwm_Ip_Cfg header file are of the same software version */
#if ((EMIOS_MCL_IP_SW_MAJOR_VERSION_H != EMIOS_MCL_IP_CFG_SW_MAJOR_VERSION) || \
     (EMIOS_MCL_IP_SW_MINOR_VERSION_H != EMIOS_MCL_IP_CFG_SW_MINOR_VERSION) || \
     (EMIOS_MCL_IP_SW_PATCH_VERSION_H != EMIOS_MCL_IP_CFG_SW_PATCH_VERSION))
    #error "Software version numbers of Emios_Mcl_Ip.h and Emios_Mcl_Ip_Cfg.h are different."
#endif

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

/*==================================================================================================
*                                      DEFINES AND MACROS
==================================================================================================*/

/*==================================================================================================
*                                            ENUMS
==================================================================================================*/

/*==================================================================================================
*                                 STRUCTURES AND OTHER TYPEDEFS
==================================================================================================*/

/*==================================================================================================
*                                GLOBAL VARIABLE DECLARATIONS
==================================================================================================*/

/*==================================================================================================
*                                    FUNCTION PROTOTYPES
==================================================================================================*/
#define MCL_START_SEC_CODE
#include "Mcl_MemMap.h"

/**
 * @brief   Emios start channel function.
 * @details This function is called separately for each EMIOS hw channel in order to enable it.
 *
 * @param[in] instance    Instance of EMIOS used.
 * @param[in] u8HwChannel EMIOS hardware channel used.
 */
void Emios_Mcl_Ip_EnableChannel(uint8 instance, uint8 u8HwChannel);

/**
 * @brief   Emios stop channel function.
 * @details This function is called separately for each EMIOS hw channel in order to disable it.
 *
 * @param[in] instance    Instance of EMIOS used.
 * @param[in] u8HwChannel EMIOS hardware channel used.
 */
void Emios_Mcl_Ip_DisableChannel(uint8 instance, uint8 u8HwChannel);

/**
 * @brief The function shall enable the output update for the corresponding channel.
 *
 * @param[in] instance    Instance of EMIOS used.
 * @param[in] channelMask EMIOS channel mask used to enable the output update.
 *                        This mask should be on 32 bits.
 *                        0x00000001U <- First channel will be affected
 *                          ^      ^
 *                          |      |
 *                         MSB    LSB
 *                        0x00FFFFFFU <- All channels will be affected
 *                                       (EMIOS instance has only 24 channels)
 */
void Emios_Mcl_Ip_ComparatorTransferEnable(uint8 instance, uint32 channelMask);

/**
 * @brief The function shall disable the output update for the corresponding channel.
 *
 * @param[in] instance    Instance of EMIOS used.
 * @param[in] channelMask EMIOS channel mask used to disable the output update.
 *                        This mask should be on 32 bits.
 *                        0x00000001U <- First channel will be affected
 *                          ^      ^
 *                          |      |
 *                         MSB    LSB
 *                        0x00FFFFFFU <- All channels will be affected
 *                                       (EMIOS instance has only 24 channels)
 */
void Emios_Mcl_Ip_ComparatorTransferDisable(uint8 instance, uint32 channelMask);

/**
 * @brief This function shall reset all the register used to initialize a channel as a masterbus. The
 * API should reset to POR values all registers used for configuring the common part of EMIOS IP.
 *
 * @param[in] instance  Instance of EMIOS used.
 * @return Emios_Ip_CommonStatusType
 */
Emios_Ip_CommonStatusType Emios_Mcl_Ip_Deinit(uint8 instance);

/**
 * @brief The API should configure the common part of EMIOS IP to be used by any driver implementation
 *        with EMIOS support (ex:  ICU, PWM, GPT, OCU)
 *
 * @param[in] instance Instance of EMIOS used.
 * @param[in] pConfig  EMIOS instance specific configuration.
 * @return Emios_Ip_CommonStatusType
 */
Emios_Ip_CommonStatusType Emios_Mcl_Ip_Init(uint8 instance, const Emios_Mcl_Ip_ConfigType *const pConfig);

/**
 * @brief   Allow the user to specify the number of bus reload events skipped.
 * 
 * @details Reload Signal Output Delay Interval
 *          Specifies the delay interval, in counter bus reload events, between each assertion of AS1-BS1 reload in
 *          MC and MCB modes.
 *              00000b - Every event
 *              00001b - Every 2nd event
 *              00010b - Every 3rd event
 *              . . .
 *              11111b - Every 32nd event
 * 
 * @param hwInstance Instance of EMIOS used.
 * @param hwChannel  EMIOS hardware channel used.
 * @param interval 
 */
void Emios_Mcl_Ip_SetReloadInterval(uint8 hwInstance, uint8 hwChannel, uint8 interval);

/**
 * @brief Change the period on active/intialized EMIOS counter(master) bus.
 * 
 * @param hwInstance Instance of EMIOS used.
 * @param hwChannel  EMIOS hardware channel used.
 * 
 * @return boolean Status of operation.
 */
boolean Emios_Mcl_Ip_ValidateChannel(uint8 hwInstance, uint8 hwChannel);

/**
 * @brief 
 * 
 * @param hwInstance 
 * @param hwChannel 
 * @param period 
 * @return Emios_Ip_CommonStatusType 
 */
Emios_Ip_CommonStatusType Emios_Mcl_Ip_SetCounterBusPeriod(uint8 hwInstance, uint8 hwChannel, uint16 period);

#if (EMIOS_IP_MULTICORE_IS_AVAILABLE == STD_ON)
/**
 * @brief 
 * 
 * @param hwInstance 
 * @return boolean 
 */
boolean Emios_Ip_ValidateMultiCoreInit(uint8 hwInstance);
#endif

#define MCL_STOP_SEC_CODE
#include "Mcl_MemMap.h"

#ifdef __cplusplus
}
#endif

/** @} */

#endif /* EMIOS_MCL_IP_H */
