/**
* @file    Crypto_Cfg.h
* @implements Crypto_Cfg.h_Artifact
* @version 1.0.0
* @brief   AUTOSAR Crypto - CRYPTO driver configuration.
* @details This is the CRYPTO driver configuration header.
*
* @addtogroup Crypto
* @{
*/
/*=================================================================================================
*   Project              : AUTOSAR 4.3 MCAL
*   Platform             : PA
*   Peripheral           : Crypto
*   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 CRYPTO_CFG_H
#define CRYPTO_CFG_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 "Crypto_Types.h"

/*=================================================================================================
*                              SOURCE FILE VERSION INFORMATION
=================================================================================================*/
#define CRYPTO_VENDOR_ID_CFG                       43
#define CRYPTO_AR_RELEASE_MAJOR_VERSION_CFG        4
#define CRYPTO_AR_RELEASE_MINOR_VERSION_CFG        3
#define CRYPTO_AR_RELEASE_REVISION_VERSION_CFG     1
#define CRYPTO_SW_MAJOR_VERSION_CFG                1
#define CRYPTO_SW_MINOR_VERSION_CFG                0
#define CRYPTO_SW_PATCH_VERSION_CFG                0

/*=================================================================================================
*                               FILE VERSION CHECKS
=================================================================================================*/
[!NOCODE!][!//
[!INCLUDE "Crypto_VersionCheck_Inc.m"!][!//
[!ENDNOCODE!][!//

/* Check if Crypto_Cfg.h file and Crypto Types header file are of the same vendor */
#if (CRYPTO_VENDOR_ID_CFG != CRYPTO_VENDOR_ID_TYPES)
    #error "Crypto_Cfg.h and Crypto_Types.h have different vendor ids"
#endif

/* Check if Crypto_Cfg.h file and Crypto Types header file are of the same Autosar version */
#if ((CRYPTO_AR_RELEASE_MAJOR_VERSION_CFG    != CRYPTO_AR_RELEASE_MAJOR_VERSION_TYPES) || \
     (CRYPTO_AR_RELEASE_MINOR_VERSION_CFG    != CRYPTO_AR_RELEASE_MINOR_VERSION_TYPES) || \
     (CRYPTO_AR_RELEASE_REVISION_VERSION_CFG != CRYPTO_AR_RELEASE_REVISION_VERSION_TYPES) \
    )
    #error "AutoSar Version Numbers of Crypto_Cfg.h and Crypto_Types.h are different"
#endif

/* Check if Crypto_Cfg.h file and Crypto Types header file are of the same Software version */
#if ((CRYPTO_SW_MAJOR_VERSION_CFG != CRYPTO_SW_MAJOR_VERSION_TYPES) || \
     (CRYPTO_SW_MINOR_VERSION_CFG != CRYPTO_SW_MINOR_VERSION_TYPES) || \
     (CRYPTO_SW_PATCH_VERSION_CFG != CRYPTO_SW_PATCH_VERSION_TYPES)    \
    )
    #error "Software Version Numbers of Crypto_Cfg.h and Crypto_Types.h are different"
#endif

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

/*=================================================================================================
*                                      DEFINES AND MACROS
=================================================================================================*/
/* Pre-processor switch to enable and disable development error detection */
#define CRYPTO_DEV_ERROR_DETECT                ([!IF "CryptoGeneral/CryptoDevErrorDetect"!]STD_ON[!ELSE!]STD_OFF[!ENDIF!])

/* Set asynchronous job process method */
[!IF "node:value(CryptoGeneral/AsyncJobProcessMethod) = 'INTERRUPT' "!][!//
#define CRYPTO_ASYNC_PROCESS_INTERRUPT          (STD_ON)
[!ELSE!][!//
#define CRYPTO_ASYNC_PROCESS_INTERRUPT          (STD_OFF)
[!ENDIF!][!//

/* True Random Number Generator Clock Divider */
#define CRYPTO_TRNG_CLOCK_DIV_U32               ((uint32)((0x[!"node:value(CryptoGeneral/TrngClockDividerSelect)"!]) << 8U))

/* Pre-processor switch to enable / disable the API to read out the modules
    version information */
#define CRYPTO_VERSION_INFO_API                ([!IF "CryptoGeneral/CryptoVersionInfoApi"!]STD_ON[!ELSE!]STD_OFF[!ENDIF!])

/* Crypto instance ID value */
#define CRYPTO_INSTANCE_ID                     ((uint8)[!"node:value(CryptoGeneral/CryptoInstanceId)"!])

/* Crypto Timeout value */
#define CRYPTO_TIMEOUT_DURATION_U32            ([!"node:value("CryptoGeneral/CryptoTimeoutDuration")"!]U)

/* Number of configured Crypto driver objects */
#define CRYPTO_NUMBER_OF_DRIVER_OBJECTS_U32    ([!"num:i(count(CryptoDriverObjects/CryptoDriverObject/*))"!]U)

/* Verify if there are keys configured or not */
[!IF "node:exists(CryptoKeys)"!][!//
#define CRYPTO_KEYS_EXIST                               (STD_ON)

/* Number of Crypto keys */
#define CRYPTO_NUMBER_OF_KEYS_U32                       ([!"num:i(count(CryptoKeys/CryptoKey/*))"!]U)

/* Number of Crypto key elements */
#define CRYPTO_NUMBER_OF_KEY_ELEMENTS_U32               ([!"num:i(count(CryptoKeyElements/CryptoKeyElement/*))"!]U)
[!ELSE!]
#define CRYPTO_KEYS_EXIST                               (STD_OFF)
[!ENDIF!][!//

/* Verify if there are keys configured or not */
[!IF "node:exists(CryptoLoadKeys)"!][!//
#define CRYPTO_LOAD_KEYS_EXIST                          (1U)

/* Number of Crypto Load key*/
#define CRYPTO_NUMBER_OF_LOAD_KEY_ELEMENTS              ([!"num:i(count(CryptoLoadKeys/CryptoLoadKey/*))"!]U)

[!ELSE!]
#define CRYPTO_LOAD_KEYS_EXIST                          (0U)
[!ENDIF!][!//

/* Verify if there are keys configured or not */
[!IF "node:exists(CryptoInstallCerts)"!][!//
#define CRYPTO_INSTALL_CERT_EXIST                       (1U)

/* Number of Crypto Install Cert*/
#define CRYPTO_NUMBER_OF_INSTALL_CERT_ELEMENTS          ([!"num:i(count(CryptoInstallCerts/CryptoInstallCert/*))"!]U)

[!ELSE!]
#define CRYPTO_INSTALL_CERT_EXIST                       (0U)
[!ENDIF!][!//

/* Verify if there are keys configured or not */
[!IF "node:exists(CryptoDhKeyPairGens)"!][!//
#define CRYPTO_DH_PAIR_EXIST                            (1U)

/* Number of Crypto Dh key*/
#define CRYPTO_NUMBER_OF_DH_PAIR_ELEMENTS               ([!"num:i(count(CryptoDhKeyPairGens/CryptoDhKeyPairGen/*))"!]U)

[!ELSE!]
#define CRYPTO_DH_PAIR_EXIST                            (0U)
[!ENDIF!][!//

/* Verify if there are keys configured or not */
[!IF "node:exists(CryptoKeyGenerates)"!][!//
#define CRYPTO_KEY_GEN_EXIST                            (1U)

/* Number of Crypto key generate*/
#define CRYPTO_NUMBER_OF_KEY_GEN_ELEMENTS               ([!"num:i(count(CryptoKeyGenerates/CryptoKeyGenerate/*))"!]U)

[!ELSE!]
#define CRYPTO_KEY_GEN_EXIST                            (0U)
[!ENDIF!][!//

/* Verify if there are keys configured or not */
[!IF "node:exists(CryptoKeyDerives)"!][!//
#define CRYPTO_KEY_DERIVE_EXIST                         (1U)

/* Number of Crypto key derives*/
#define CRYPTO_NUMBER_OF_KEY_DERIVE_ELEMENTS            ([!"num:i(count(CryptoKeyDerives/CryptoKeyDerive/*))"!]U)

[!ELSE!]
#define CRYPTO_KEY_DERIVE_EXIST                         (0U)
[!ENDIF!][!//

/* Verify if there are keys export or not */
[!IF "node:exists(CryptoExportKeys)"!][!//
#define CRYPTO_KEY_EXPORT_EXIST                         (1U)

/* Number of Crypto key derives*/
#define CRYPTO_NUMBER_OF_KEY_EXPORT_ELEMENTS            ([!"num:i(count(CryptoExportKeys/CryptoExportKey/*))"!]U)

[!ELSE!]
#define CRYPTO_KEY_EXPORT_EXIST                         (0U)
[!ENDIF!][!//

[!LOOP "CryptoKeys/CryptoKey/*"!][!//
[!VAR "KeyId" = "CryptoKeyId"!][!//
/**
* @brief          Symbolic name for the CryptoKeyId [!"node:name(.)"!].
*
*/
#define  CryptoConf_[!"node:name(.)"!]_CryptoKeyId   ((uint32)[!"num:i($KeyId)"!]U)

[!ENDLOOP!][!//

[!LOOP "CryptoDriverObjects/CryptoDriverObject/*"!][!//
[!VAR "ObjectId" = "CryptoDriverObjectId"!][!//
/**
* @brief          Symbolic name for the CryptoDriverObjectId [!"node:name(.)"!].
*
*/
#define  CryptoConf_[!"node:name(.)"!]_CryptoDriverObjectId   ((uint32)[!"num:i($ObjectId)"!]U)

[!ENDLOOP!][!//

[!LOOP "CryptoKeyElements/CryptoKeyElement/*"!][!//
[!VAR "ElementId" = "CryptoKeyElementId"!][!//
/**
* @brief          Symbolic name for the CryptoKeyElementId [!"node:name(.)"!].
*
*/
#define  CryptoConf_[!"node:name(.)"!]_CryptoKeyElementId   ((uint32)[!"num:i($ElementId)"!]U)

[!ENDLOOP!][!//

[!CODE!]
[!LOOP "node:CryptoKeyElements/CryptoKeyElement/*"!][!//

#define CRYPTO_FLAGS_[!"text:toupper(node:name(.))"!]     ((uint32)([!LOOP "CryptoKeyFlags/*"!] (uint32)([!"node:value(CryptoKeyMask)"!]) |[!ENDLOOP!](uint32)0U))

[!ENDLOOP!]  
[!ENDCODE!]
/*=================================================================================================
*                                             ENUMS
=================================================================================================*/

/*=================================================================================================
*                                STRUCTURES AND OTHER TYPEDEFS
=================================================================================================*/
typedef struct
{
    CONST(uint32,                           CRYPTO_CONST) u32CryptoKeyElementId;
    CONST(boolean,                          CRYPTO_CONST) bCryptoKeyElementAllowPartialAccess;
    CONST(Crypto_KeyFormatType,             CRYPTO_CONST) Crypto_KeyFormatType;
    CONST(boolean,                          CRYPTO_CONST) bCryptoKeyElementPersist;
    CONST(Crypto_KeyElementReadAccessType,  CRYPTO_CONST) eCryptoKeyElementReadAccess;
    CONST(uint32,                           CRYPTO_CONST) u32CryptoKeyElementMaxSize;
    VAR  (uint32,                             CRYPTO_VAR) u32CryptoKeyElementActualSize;
    CONST(Crypto_KeyElementWriteAccessType, CRYPTO_CONST) eCryptoKeyElementWriteAccess;
    P2VAR(uint8, AUTOMATIC,             CRYPTO_APPL_DATA) pCryptoElementArray;
    CONST(uint32,                           CRYPTO_CONST) u32CryptoKeyHandle;
    CONST(uint32,                           CRYPTO_CONST) u32CryptoKeyFlags;
} Crypto_KeyElementType;

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

/*=================================================================================================
*                                    FUNCTION PROTOTYPES
=================================================================================================*/

#ifdef __cplusplus
}
#endif

#endif /* CRYPTO_CFG_H */
