/**
*   @file    Reg_eSys_Stm.h
*   @version 1.0.0
*
*   @brief   AUTOSAR Gpt - STM driver header file.
*   @details STM main register description.
*
*   @addtogroup GPT_MODULE
*   @{
*/
/*==================================================================================================
*   Project              : AUTOSAR 4.3 MCAL
*   Platform             : PA
*   Peripheral           : eMios_Stm_Pit
*   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.
==================================================================================================*/
/*==================================================================================================
==================================================================================================*/

#ifndef REG_ESYS_STM_H
#define REG_ESYS_STM_H

#ifdef __cplusplus
extern "C"{
#endif
/**
* @page misra_violations MISRA-C:2012 violations
*
* @section REG_ESYS_STM_H_REF_1
*     Violates MISRA 2012 Required Directive 4.10, Precautions shall be taken in order to prevent
*     the contents of a header file being included more than once.
*     This violation is not fixed since the inclusion of <MA>_MemMap.h is as per AUTOSAR requirement
*     [SWS_MemMap_00003].
*
* @section REG_ESYS_STM_H_REF_2
*     Violates MISRA 2012 Advisory Rule 2.5, A project should not contain unused macro declarations.
*     Macros that are used in the code only in some configuration (they are guarded by #ifdef…)
*
* @section REG_ESYS_STM_H_REF_3
*     Violates MISRA 2012 Advisory Directive 4.9, A function should be used in preference to
*     a function-like macro where they are interchangeable.
*
*/
/*==================================================================================================
*                                         INCLUDE FILES
* 1) system and project includes
* 2) needed interfaces from external units
* 3) internal and external interfaces from this unit
==================================================================================================*/
#include "Reg_eSys.h"

/*==================================================================================================
*                               SOURCE FILE VERSION INFORMATION
==================================================================================================*/
/**
* @brief Parameters that shall be published within the Gpt driver header file and also in the
*       module's description file
* @{
*/
#define REG_ESYS_STM_VENDOR_ID                       43
#define REG_ESYS_STM_AR_RELEASE_MAJOR_VERSION        4
#define REG_ESYS_STM_AR_RELEASE_MINOR_VERSION        3
#define REG_ESYS_STM_AR_RELEASE_REVISION_VERSION     1
#define REG_ESYS_STM_SW_MAJOR_VERSION                1
#define REG_ESYS_STM_SW_MINOR_VERSION                0
#define REG_ESYS_STM_SW_PATCH_VERSION                0
/** @} */
/*==================================================================================================
*                                      FILE VERSION CHECKS
==================================================================================================*/
#ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
     /* Check if this header file and Reg_eSys.h file are of the same Autosar version */
    #if ((REG_ESYS_STM_AR_RELEASE_MAJOR_VERSION != REG_ESYS_AR_RELEASE_MAJOR_VERSION) || \
         (REG_ESYS_STM_AR_RELEASE_MINOR_VERSION != REG_ESYS_AR_RELEASE_MINOR_VERSION) \
        )
        #error "AutoSar Version Numbers of Reg_eSys_Stm.h and Reg_eSys.h are different"
    #endif
#endif

/*==================================================================================================
*                                           CONSTANT-LIKE DEFINES
==================================================================================================*/
#if (GPT_STM_USED == STD_ON)

#define GPT_START_SEC_CONST_32
/** @violates @ref REG_ESYS_STM_H_REF_1 MISRA 2012 Required Directive 4.10, the contents of a header 
*   file being included more than once.*/
#include "Gpt_MemMap.h"

/**
* @brief Maximum possible number of STM modules
*/
#define STM_MODULE_NUM_MAX_U8          (8U)

/**
* @brief STM base address array declaration
*/
extern CONST(uint32, GPT_CONST) STM_BASE_ADDR32[STM_MODULE_NUM_MAX_U8];

#define GPT_STOP_SEC_CONST_32
/** @violates @ref REG_ESYS_STM_H_REF_1 MISRA 2012 Required Directive 4.10, the contents of a header 
*   file being included more than once.*/
#include "Gpt_MemMap.h"
/*==================================================================================================
*                                 GLOBAL VARIABLE DECLARATIONS
==================================================================================================*/

/*==================================================================================================
*                                       FUNCTION-LIKE DEFINES(MACROS)
==================================================================================================*/
/** @violates @ref REG_ESYS_STM_H_REF_3 MISRA 2012 Advisory Directive 4.9, Function like macro are
*   used to reduce code complexity.*/
#define STM_MODULE_INDEX_U32(ch)      (((ch) & (uint32)STM_MOD_MASK_U8) >> STM_MOD_SHIFT)
/** @violates @ref REG_ESYS_STM_H_REF_3 MISRA 2012 Advisory Directive 4.9, Function like macro are
*   used to reduce code complexity.*/
#define STM_CHANNEL_INDEX_U32(ch)     (((ch) & (uint32)STM_CH_MASK_U8)  >> STM_CH_SHIFT)

/**
* @{
* @brief System Timer Module (STM) Registers address
*/
/** @violates @ref REG_ESYS_STM_H_REF_3 MISRA 2012 Advisory Directive 4.9, Function like macro are
*   used to reduce code complexity.*/
#define STM_CR_ADDR32(ch)       (STM_BASE_ADDR32[STM_MODULE_INDEX_U32(ch)])
/** @violates @ref REG_ESYS_STM_H_REF_3 MISRA 2012 Advisory Directive 4.9, Function like macro are
*   used to reduce code complexity.*/
#define STM_CNT_ADDR32(ch)      (STM_BASE_ADDR32[STM_MODULE_INDEX_U32(ch)] + (uint32)0x4UL)
/** @violates @ref REG_ESYS_STM_H_REF_3 MISRA 2012 Advisory Directive 4.9, Function like macro are
*   used to reduce code complexity.*/
#define STM_CCR_ADDR32(ch)      (STM_BASE_ADDR32[STM_MODULE_INDEX_U32(ch)] + ((uint32)(STM_CHANNEL_INDEX_U32(ch)) << 4) + (uint32)0x10UL)
/** @violates @ref REG_ESYS_STM_H_REF_3 MISRA 2012 Advisory Directive 4.9, Function like macro are
*   used to reduce code complexity.*/
#define STM_CIR_ADDR32(ch)      (STM_BASE_ADDR32[STM_MODULE_INDEX_U32(ch)] + ((uint32)(STM_CHANNEL_INDEX_U32(ch)) << 4) + (uint32)0x14UL)
/** @violates @ref REG_ESYS_STM_H_REF_3 MISRA 2012 Advisory Directive 4.9, Function like macro are
*   used to reduce code complexity.*/
#define STM_CMP_ADDR32(ch)      (STM_BASE_ADDR32[STM_MODULE_INDEX_U32(ch)] + ((uint32)(STM_CHANNEL_INDEX_U32(ch)) << 4) + (uint32)0x18UL)
/** @} */

/**
* @brief Defines for System Timer Module (STM) Registers
*/
#define STM_CCR_CEN_ENABLE_U32   ((uint32)1UL)

#define STM_CIR_CIF_SET_U32      ((uint32)1UL)

#define STM_CR_TEN_MASK_U32      ((uint32)(BIT0))

#define STM_CR_FRZ_MASK_U32      ((uint32)(BIT1))

#define STM_CR_CPS_MASK_U32      ((uint32)(BIT15 | BIT14 | BIT13 | BIT12 | BIT11 | BIT10 | BIT9 | BIT8))
#define STM_CR_CPS_SHIFT         ((uint32)(8U))

/** @violates @ref REG_ESYS_STM_H_REF_2 MISRA 2012 Required Rule 2.5, this macro was used 
*   in some configuration  */
#define STM_CR_CSL_MASK_U32      ((uint32)(BIT4))
/** @violates @ref REG_ESYS_STM_H_REF_2 MISRA 2012 Required Rule 2.5, this macro was used 
*   in some configuration  */
#define STM_CR_CSL_SHIFT         ((uint32)(4U))

#define STM_CCR_CEN_MASK_U32     ((uint32)(BIT0))

#define STM_CIR_CIF_MASK_U32     ((uint32)(BIT0))

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

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

/*==================================================================================================
*                                     FUNCTION PROTOTYPES
==================================================================================================*/
#endif /*(GPT_STM_USED == STD_ON)*/

#ifdef __cplusplus
}
#endif

#endif /*REG_ESYS_STM_H*/

/** @} */
