/*!
* @file     CDD_Pdl.c
*
* @version  1.0.0
*
* @brief    The source file of the Pdl driver.
*           This source file contains the API specification and other variables of the PDL driver.
* @attention
*
* Project Name      : AUTOSAR MCAL
*
* Platform          : Arm
*
* Autosar Standard  : Classic Platform 4.4.0
*
* Compiled Version  : G32A10xx_MCAL_1_0_0_01-Otc-25
*
* Copyright (C) 2026 Geehy Semiconductor
*
* You may not use this file except in compliance with the
* GEEHY COPYRIGHT NOTICE (Geehy Semiconductor Software License Agreement).
*
* The program is only for reference, which is distributed in the hope
* that it will be usefull and instructional for customers to develop
* their software. Unless required by applicable law or agreed to in
* writing, the program is distributed on an "AS IS" BASIS, WITHOUT
* ANY WARRANTY OR CONDITIONS OF ANY KIND, either express or implied.
* See the Geehy Semiconductor Software License Agreement for the governing permissions
* and limitations under the License.
*/

#ifdef __cplusplus
extern "C"
{
#endif  /* ifdef __cplusplus */

#include "Mcal.h"
#include "CDD_Pdl.h"

#if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)
    #include "Det.h"
#endif  /* {if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)} */
/** @addtogroup G32A10xx_StdPeriphDriver
  @{
*/

/** @defgroup PDL_Driver
  * @brief PDL driver modules
  @{
*/

/** @defgroup PDL_Macros
  @{
*/
/***********************************************************************************************************************
                                    VENDOR ID & AUTOSAR VERSION INFO
***********************************************************************************************************************/
/** Vendor ID (vendorId) of the dedicated implementation of this module according to the AUTOSAR vendor list. */
#define CDD_PDL_VENDOR_ID                                  0x00C1U
/** Major version number of AUTOSAR release on which the appropriate implementation is based on. */
#define CDD_PDL_AR_RELEASE_MAJOR_VERSION                   0x04U
/** Minor version number of AUTOSAR release on which the appropriate implementation is based on. */
#define CDD_PDL_AR_RELEASE_MINOR_VERSION                   0x04U
/** Revision version number of AUTOSAR release on which the appropriate implementation is based on. */
#define CDD_PDL_AR_RELEASE_REVISION_VERSION                0x00U
/** Major version number of the vendor specific implementation of the module. The numbering is vendor specific. */ 
#define CDD_PDL_SW_MAJOR_VERSION                           0x01U
/** Minor version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define CDD_PDL_SW_MINOR_VERSION                           0x00U
/** Patch level version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define CDD_PDL_SW_PATCH_VERSION                           0x00U
/**@} end of group PDL_Macros */
/**********************************************************************************************************************
                                        VERSION INFOMATION VERIFICATION
***********************************************************************************************************************/
#if (CDD_PDL_VENDOR_ID != CDD_PDL_H_VENDOR_ID)
#error "Vendor ids mismatch between CDD_Pdl.c and CDD_Pdl.h"
#endif  /* {if (CDD_PDL_VENDOR_ID != CDD_PDL_H_VENDOR_ID)} */

/* Make sure the AUTOSAR major version number is the same between CDD_Pdl.c and CDD_Pdl.h */
#if (CDD_PDL_AR_RELEASE_MAJOR_VERSION != CDD_PDL_H_AR_RELEASE_MAJOR_VERSION)
    #error "AUTOSAR Major Version Numbers mismatch between CDD_Pdl.c and CDD_Pdl.h"
#endif
/* Make sure the AUTOSAR minor version number is the same between CDD_Pdl.c and CDD_Pdl.h */
#if (CDD_PDL_AR_RELEASE_MINOR_VERSION != CDD_PDL_H_AR_RELEASE_MINOR_VERSION)
    #error "AUTOSAR Minor Version Numbers mismatch between CDD_Pdl.c and CDD_Pdl.h"
#endif
/* Make sure the AUTOSAR revision version number is the same between CDD_Pdl.c and CDD_Pdl.h */
#if (CDD_PDL_AR_RELEASE_REVISION_VERSION != CDD_PDL_H_AR_RELEASE_REVISION_VERSION)
    #error "AUTOSAR Revision Version Numbers mismatch between CDD_Pdl.c and CDD_Pdl.h"
#endif

/* Make sure the software major version number is the same between CDD_Pdl.c and CDD_Pdl.h */
#if (CDD_PDL_SW_MAJOR_VERSION != CDD_PDL_H_SW_MAJOR_VERSION)
    #error "Software Major Version Numbers mismatch between CDD_Pdl.c and CDD_Pdl.h"
#endif
/* Make sure the software minor version number is the same between CDD_Pdl.c and CDD_Pdl.h */
#if (CDD_PDL_SW_MINOR_VERSION != CDD_PDL_H_SW_MINOR_VERSION)
    #error "Software Minor Version Numbers mismatch between CDD_Pdl.c and CDD_Pdl.h"
#endif
/* Make sure the software patch version number is the same between CDD_Pdl.c and CDD_Pdl.h */
#if (CDD_PDL_SW_PATCH_VERSION != CDD_PDL_H_SW_PATCH_VERSION)
    #error "Software Patch Version Numbers mismatch between CDD_Pdl.c and CDD_Pdl.h"
#endif

#if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)
#ifdef ENABLE_INTERMODULE_MCAL_CHECK
/* Make sure the AUTOSAR major version number is the same between CDD_Pdl.c and Det.h */
#if (CDD_PDL_AR_RELEASE_MAJOR_VERSION != DET_H_AR_RELEASE_MAJOR_VERSION)
    #error "AUTOSAR Major Version Numbers mismatch between CDD_Pdl.c and Det.h"
#endif
/* Make sure the AUTOSAR minor version number is the same between CDD_Pdl.c and Det.h */
#if (CDD_PDL_AR_RELEASE_MINOR_VERSION != DET_H_AR_RELEASE_MINOR_VERSION)
    #error "AUTOSAR Minor Version Numbers mismatch between CDD_Pdl.c and Det.h"
#endif
#endif  
#endif /* {if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)} */

#ifdef ENABLE_INTERMODULE_MCAL_CHECK
/* Make sure the AUTOSAR major version number is the same between CDD_Pdl.c and Mcal.h */
#if (CDD_PDL_AR_RELEASE_MAJOR_VERSION != MCAL_H_AR_RELEASE_MAJOR_VERSION)
    #error "AUTOSAR Major Version Numbers mismatch between CDD_Pdl.c and Mcal.h"
#endif
/* Make sure the AUTOSAR minor version number is the same between CDD_Pdl.c and Mcal.h */
#if (CDD_PDL_AR_RELEASE_MINOR_VERSION != MCAL_H_AR_RELEASE_MINOR_VERSION)
    #error "AUTOSAR Minor Version Numbers mismatch between CDD_Pdl.c and Mcal.h"
#endif
#endif

/**********************************************************************************************************************
                                             GLOBAL VARIABLE
***********************************************************************************************************************/
/** @defgroup PDL_Variable
  @{
*/
#define PDL_START_SEC_VAR_INIT_UNSPECIFIED
#include "Pdl_MemMap.h"

/** This varible is used to store the configuration data of the Pdl driver */
P2CONST(Pdl_ConfigType, PDL_VAR,  PDL_APPL_CONST)  g_pdlConfigPtr  = NULL_PTR;

#if (STD_ON == CDD_PDL_DMA_SUPPORT)
#if (STD_OFF == CDD_PDL_DEM_ERR_REP_DISABLE)
P2CONST(Pdl_DemConfigType, PDL_VAR, PDL_APPL_CONST) g_pdlDemConfigPtr = NULL_PTR;
#endif  /* {if (STD_OFF == CDD_PDL_DEM_ERR_REP_DISABLE)} */
#endif  /* {if (STD_ON == CDD_PDL_DMA_SUPPORT)} */

#define PDL_STOP_SEC_VAR_INIT_UNSPECIFIED
#include "Pdl_MemMap.h"
/**@} end of group PDL_Variable */
/**********************************************************************************************************************
                                                  LOCAL FUNCTION
***********************************************************************************************************************/
/** @defgroup PDL_Fuctions
  @{
*/
#define PDL_START_SEC_CODE
#include "Pdl_MemMap.h"

#if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)
/*!
* @brief         This function is a non reentrant function used to validate the calling of the Pdl_Init
*
* @param[in]      ServiceId            The service id of the API
*
* @retval        E_OK: The function call is valid
*                E_NOT_OK:The function call is invalid
*/
LOCAL_INLINE FUNC(Std_ReturnType, PDL_CODE) Pdl_ValidateGlobalFunctionCall(VAR(uint8, AUTOMATIC) ServiceId)
{
    VAR(Std_ReturnType, AUTOMATIC) retVal = (Std_ReturnType)E_NOT_OK;
    
    if (NULL_PTR == g_pdlConfigPtr)
    {      
        switch(ServiceId)
        {
            case (uint8)PDL_INIT_SID:
                retVal = (Std_ReturnType)E_OK;
                break;
            default:
                (void)Det_ReportError((uint16)CDD_PDL_H_MODULE_ID, 0U, (uint8)ServiceId, (uint8)PDL_E_UNINIT);
                break;
        }     
    }
    else
    {
        switch(ServiceId)
        {
            case (uint8)PDL_INIT_SID:
                (void)Det_ReportError((uint16)CDD_PDL_H_MODULE_ID, 0U, (uint8)ServiceId, (uint8)PDL_E_INITED);
                break;
            default:
                retVal = (Std_ReturnType)E_OK;
                break;
        }
    }

    return retVal;
}

#endif /* {if (STD_ON == CDD_PDL_DEINIT_API)} */

#if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)
/*!
* @brief         This function validate the parameter pointer of the initialization API.
*
* @param[in]     ConfigPtr   The parameter pointer of the initialization API
*
* @retval        E_OK: The parameter pointer is valid
*                E_NOT_OK:The parameter pointer is invalid
*/
LOCAL_INLINE FUNC(Std_ReturnType, PDL_CODE) Pdl_ValidateParaPtrInit( P2CONST(Pdl_ConfigType, AUTOMATIC, PDL_APPL_CONST) ConfigPtr)
{
    VAR(Std_ReturnType, AUTOMATIC) retVal = (Std_ReturnType)E_OK;

    #if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)
        if (NULL_PTR == ConfigPtr)
        {
            retVal=(Std_ReturnType)E_NOT_OK;
            (void)Det_ReportError((uint16)CDD_PDL_H_MODULE_ID, 0U, (uint8)PDL_INIT_SID, (uint8)PDL_E_INIT_FAILED);
        }
        else
        {
            /* do nothing */
        }
   #endif

    return retVal;
}
#endif /* {if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)} */

#if ((STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE) && (STD_ON == CDD_PDL_VERSION_INFO_API))
/*!
* @brief         This function validate the parameter pointer of the version  API.
*
* @param[in]     VersionInfoPtr   The parameter pointer of the version API
*
* @retval        E_OK: The parameter pointer is valid
*                E_NOT_OK:The parameter pointer is invalid
*/
LOCAL_INLINE FUNC(Std_ReturnType, PDL_CODE) Pdl_ValidateVersionInfoCall(P2CONST(Std_VersionInfoType, AUTOMATIC, PDL_APPL_CONST) VersionInfoPtr)
{
    VAR(Std_ReturnType, AUTOMATIC) retVal = (Std_ReturnType)E_NOT_OK;

    if(NULL_PTR != VersionInfoPtr)
    {
        retVal = (Std_ReturnType)E_OK;
    }
    else
    {
        (void)Det_ReportError((uint16)CDD_PDL_H_MODULE_ID, 0U, (uint8)PDL_GET_VERSION_INFO_SID, (uint8)PDL_E_VINFO_POINTER);
    }

    return retVal;
}
#endif /* {if ((STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE) && (STD_ON == CDD_PDL_VERSION_INFO_API))} */

#if (STD_ON == CDD_PDL_DMA_SUPPORT)
#if ((STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE) && (STD_ON == CDD_PDL_DMA_NOTIFICATION_ENABLE))
/*!
* @brief         This function validates notification handler of a Pdl channel.
*
* @param[in]     PdlChannelNotifiPtr   The parameter pointer of the  notification
*
* @retval        E_OK: The parameter pointer is valid
*                E_NOT_OK:The parameter pointer is invalid
*/
LOCAL_INLINE  FUNC(Std_ReturnType, PDL_CODE) Pdl_ValidateParamNotifi(VAR(Pdl_NotifyType, AUTOMATIC) PdlChannelNotifiPtr)
{
    /* Variable to store the value returned by the function */
    VAR(Std_ReturnType, AUTOMATIC) returnVal = (Std_ReturnType)E_NOT_OK;

    /* Check if Notification param is not NULL */
    if(NULL_PTR != PdlChannelNotifiPtr)
    {
        returnVal = (Std_ReturnType)E_OK;
    }
    else
    {
        (void)Det_ReportError((uint16) CDD_PDL_H_MODULE_ID, 0U, (uint8)PDL_ENABLE_NOTIFICATION_SID, (uint8)PDL_E_NULL_NOTIFI_CALLBACK);
    }

    return returnVal;
}
#endif /* {if ((STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE) && (STD_ON == CDD_PDL_DMA_NOTIFICATION_ENABLE))} */

#if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)
/*!
* @brief         This function validates the impacting of the configuration of the calling of a function.
*
* @param[in]     ChannelId   The DMA channel id
* @param[in]     ServiceId   The function service id
*
* @retval        E_OK: The calling of the function is valid
*                E_NOT_OK:The calling of the function is invalid
*/
LOCAL_INLINE  FUNC(Std_ReturnType, PDL_CODE) Pdl_ValidateChannelConfigCall(VAR(Pdl_ChType, AUTOMATIC) ChannelId,\
    VAR(uint8,  AUTOMATIC) ServiceId)
{
    VAR(Std_ReturnType, AUTOMATIC) returnVal = (Std_ReturnType)E_NOT_OK;

    /* Check the driver is initlized */    
    if(NULL_PTR != g_pdlConfigPtr)
    {
        /* Check the channel is in the valid range */
        if(ChannelId > DMA_HW_CH5)
        {
            (void)Det_ReportError((uint16)CDD_PDL_H_MODULE_ID, 0U, (uint8)ServiceId, (uint8)PDL_E_CH);
        }
        else
        {
            returnVal = (Std_ReturnType)E_OK;
        }
    }
    else
    {
        (void)Det_ReportError((uint16) CDD_PDL_H_MODULE_ID, 0U, (uint8)ServiceId, (uint8)PDL_E_UNINIT);
    }

    return returnVal;
}

#endif /* {if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)} */

#if (STD_ON == CDD_PDL_DMA_NOTIFICATION_ENABLE)
#if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)
/*!
* @brief         The function is called in order to report an unexpected ISR 
*
* @param[in]     None
*
* @retval        void
*/ 
LOCAL_INLINE FUNC(void, PDL_CODE) Pdl_RepUnexpIsrErrFunc(void)
{
    (void)Det_ReportError((uint16)CDD_PDL_H_MODULE_ID, 0U, (uint8)PDL_PROCESS_NOTIFICATION_SID, (uint8)PDL_E_UNEX_INT);
}
#endif /* {if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)} */
#endif /* {if (STD_ON == CDD_PDL_DMA_NOTIFICATION_ENABLE)} */
#endif /* {if (STD_ON == CDD_PDL_DMA_SUPPORT)} */
/**********************************************************************************************************************
                                                    GLOBAL FUNCTION
***********************************************************************************************************************/
/*!
* @brief         This function initializes the hardware components of the PDL driver.
*
* @param[in]     PdlConfigPtr    The pointer of the PDL configuration
*
* @retval        void
*/
FUNC(void, PDL_CODE) Pdl_Init(P2CONST( Pdl_ConfigType, AUTOMATIC, PDL_APPL_CONST) PdlConfigPtr)
{
#if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)
    if((Std_ReturnType)E_OK != Pdl_ValidateGlobalFunctionCall((uint8)PDL_INIT_SID))
    {
        /* nothing */
    }
    else if ((Std_ReturnType)E_OK != Pdl_ValidateParaPtrInit(PdlConfigPtr))
    {
        /* nothing */
    }
    else
    {
#endif /* {if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)} */

        g_pdlConfigPtr = PdlConfigPtr;

#if (STD_ON == CDD_PDL_DMA_SUPPORT)
#if (STD_OFF == CDD_PDL_DEM_ERR_REP_DISABLE)
        g_pdlDemConfigPtr = g_pdlConfigPtr->pdlDemConfigPtr;
#endif            
        /* INitlize the DMA driver */
        Pdl_Dma_Init(g_pdlConfigPtr->pdlDmaHwConfigPtr->pdlDmaConfigPtr);
#endif  /* {if (STD_ON == CDD_PDL_DMA_SUPPORT)} */

#if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)
    }
    PDL_END_VALIDATE_GLOBAL_CALL();
#endif  /* {if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)} */
}

#if (STD_ON == CDD_PDL_DEINIT_API)
/*!
* @brief         This function de-initializes the hardware components of the PDL driver.
*
* @param[in]     void
*
* @retval        void
*/
FUNC(void, PDL_CODE) Pdl_DeInit(void)
{
#if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)
    if((Std_ReturnType)E_OK == Pdl_ValidateGlobalFunctionCall((uint8)PDL_DEINIT_SID))
    {
#endif  /* {if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)} */

#if (STD_ON == CDD_PDL_DMA_SUPPORT)
            /* DeInitlize the DMA driver */
        Pdl_Dma_DeInit(g_pdlConfigPtr->pdlDmaHwConfigPtr->pdlDmaConfigPtr);
#endif  /* {if (STD_ON == CDD_PDL_DMA_SUPPORT)} */

        g_pdlConfigPtr = NULL_PTR;

#if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)
    }
    else
    {
        /* do nothing */
    }

    PDL_END_VALIDATE_GLOBAL_CALL();
#endif  /* {if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)} */
}
#endif  /* {if (STD_ON == CDD_PDL_DEINIT_API)} */

#if (STD_ON == CDD_PDL_VERSION_INFO_API)
/*!
* @brief         This function gets the version information of this module.
*
* @param[in]     PdlVersionInfoPtr    The pointer of the version information
*
* @retval        void
*/
FUNC(void, PDL_CODE) Pdl_TopGetVersionInfo(P2VAR(Std_VersionInfoType, AUTOMATIC, PDL_APPL_DATA) PdlVersionInfoPtr)
{
#if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)
    switch ((Std_ReturnType)Pdl_ValidateVersionInfoCall(PdlVersionInfoPtr))
    {
        case (Std_ReturnType)E_OK:
        {
#endif  /* {if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)} */

            (PdlVersionInfoPtr)->vendorID         = (uint16)CDD_PDL_H_VENDOR_ID;
            (PdlVersionInfoPtr)->moduleID         = (uint8)CDD_PDL_H_MODULE_ID;
            (PdlVersionInfoPtr)->sw_major_version = (uint8)CDD_PDL_H_SW_MAJOR_VERSION;
            (PdlVersionInfoPtr)->sw_minor_version = (uint8)CDD_PDL_H_SW_MINOR_VERSION;
            (PdlVersionInfoPtr)->sw_patch_version = (uint8)CDD_PDL_H_SW_PATCH_VERSION;

#if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)
            break;
        }         
        default:
        {
            /* do nothing */
            break;
        }
    }   
#endif
}
#endif  /* {if (STD_ON == CDD_PDL_VERSION_INFO_API)} */

#if (STD_ON == CDD_PDL_DMA_SUPPORT)
/*!
* @brief         This function configures the specified DMA channel.
*
* @param[in]     PdlDmaChannel         The id of the Dma channel
* @param[in]     DmaChHwConfigPtr     The pointer of the channel's hardware config
*
* @retval        void
*/
FUNC(void, PDL_CODE) Pdl_TopDmaChConfig(VAR(Pdl_ChType, AUTOMATIC) PdlDmaChannel,
                                        P2CONST(Pdl_DmaChHwConfigType, AUTOMATIC, PDL_APPL_DATA) DmaChHwConfigPtr)
{
#if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)
    VAR(Std_ReturnType, AUTOMATIC) validStatus = E_NOT_OK;

    validStatus = Pdl_ValidateGlobalFunctionCall((uint8)PDL_CONFIG_CH_SID);
    if (((Std_ReturnType)E_OK == Pdl_ValidateChannelConfigCall(PdlDmaChannel, (uint8)PDL_CONFIG_CH_SID)) && \
        ((Std_ReturnType)E_OK == validStatus))
    {
        if(NULL_PTR != DmaChHwConfigPtr)
        {
#endif /* {if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)} */

            Pdl_Dma_ChConfig(PdlDmaChannel, DmaChHwConfigPtr);

#if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)
        }
        else
        {
            (void)Det_ReportError((uint16)CDD_PDL_H_MODULE_ID, 0U, (uint8)PDL_CONFIG_CH_SID, (uint8)PDL_E_POINTER_PARA);
        }        
    }
    else
    {
        /* do nothing */
    }
    
    if((Std_ReturnType)E_OK == validStatus)
    {
        PDL_END_VALIDATE_CH_CONFIG_CALL(PdlDmaChannel);
    }
    else
    {
        /* do nothing */
    }

    PDL_END_VALIDATE_GLOBAL_CALL();
#endif /* {if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)} */
}

/*!
* @brief         The function enable the DMA channel.
*
* @param[in]     ChannelId         The channel id
*
* @retval        void 
*/ 
FUNC(void, PDL_CODE) Pdl_TopDmaChEn(VAR(Pdl_ChType, AUTOMATIC) ChannelId)
{
#if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)
    if((Std_ReturnType)E_OK == Pdl_ValidateChannelConfigCall(ChannelId, (uint8)PDL_ENABLE_DMA_CH_SID))
    {
#endif /* {if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)} */

        Pdl_Dma_Enable(ChannelId);

#if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)
    }
    else
    {
        /* do nothing */
    }
    PDL_END_VALIDATE_CH_CONFIG_CALL(ChannelId);
#endif /* {if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)} */
}

/*!
* @brief         The function disable the DMA channel.
*
* @param[in]     ChannelId         The channel id
*
* @retval        void 
*/ 
FUNC(void, PDL_CODE) Pdl_TopDmaChDis(VAR(Pdl_ChType, AUTOMATIC) ChannelId)
{
#if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)
    if((Std_ReturnType)E_OK == Pdl_ValidateChannelConfigCall(ChannelId, (uint8)PDL_DISABLE_DMA_CH_SID))
    {
#endif /* {if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)} */

        Pdl_Dma_Disable(ChannelId);

#if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)
    }
    else
    {
        /* do nothing */
    }
    PDL_END_VALIDATE_CH_CONFIG_CALL(ChannelId);
#endif /* {if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)} */
}

#if (STD_ON == CDD_PDL_DMA_GET_CH_ERR_STAT_API)
/*!
* @brief         The function gets the error staus of the logical channel.
*
* @param[in]     PdlDmaChannel          The logical channel id
*
* @retval        The error information of the logical channel
*/ 
FUNC(Pdl_DmaChErrStsType, PDL_CODE) Pdl_TopDmaChErrStsGet(VAR(Pdl_ChType, AUTOMATIC) PdlDmaChannel)
{
     Pdl_DmaChErrStsType errorStatus = DMA_CH_NO_ERR;

#if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)
    if((Std_ReturnType)E_OK == Pdl_ValidateChannelConfigCall(PdlDmaChannel, (uint8)PDL_GET_CH_ERR_STATUS_SID))
    {
#endif /* {if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)} */

        errorStatus = Pdl_Dma_ChErrStsGet(PdlDmaChannel);

#if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)
    }
    else
    {
        /* do nothing */
    }

    PDL_END_VALIDATE_CH_CONFIG_CALL(ChannelId);
#endif /* {if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)} */

    return errorStatus;
}
#endif  /* {if (STD_ON == CDD_PDL_DMA_GET_CH_ERR_STAT_API)} */

/*!
* @brief         The function sets the priority of a Dma channel.
*
* @param[in]     PdlDmaChannel         The id of the Dma channel
* @param[in]     DmaChannelPrio        The priority of the Dma channel
*
* @retval        void
*/ 
FUNC(void, PDL_CODE) Pdl_TopDmaChPrioSet(VAR(Pdl_ChType, AUTOMATIC) PdlDmaChannel,\
                                               VAR(Pdl_DmaPrioType, AUTOMATIC) DmaChannelPrio)
{
#if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)
    if((Std_ReturnType)E_OK == Pdl_ValidateChannelConfigCall(PdlDmaChannel, (uint8)PDL_SET_PRI_SID))
    {
#endif /* {if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)} */

        Pdl_Dma_ChPrioSet(PdlDmaChannel, DmaChannelPrio);

#if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)
    }
    else
    {
      /* do nothing */
    }
    PDL_END_VALIDATE_CH_CONFIG_CALL(PdlDmaChannel);
#endif /* {if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)} */
}

/*!
* @brief         The function verify the Dma transfer is completed.
*
* @param[in]     PdlDmaChannel    The id of the Dma channel
*
* @retval        true             The Dma transfer is completed
*                false            The Dma transfer is running
*/ 
FUNC(boolean, PDL_CODE) Pdl_TopDmaIsTransComp(VAR(Pdl_ChType, AUTOMATIC) PdlDmaChannel)
{
    VAR(boolean, AUTOMATIC) completeStatus = (boolean)FALSE;
    
#if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)
    if((Std_ReturnType)E_OK == Pdl_ValidateChannelConfigCall(PdlDmaChannel, (uint8)PDL_TRANSF_COMPL_SID))
    {
#endif /* {if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)} */

        completeStatus = Pdl_Dma_TransDoneCheck(PdlDmaChannel);

#if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)
    }
    else
    {
        /* do nothing */
    }
    PDL_END_VALIDATE_CH_CONFIG_CALL(PdlDmaChannel);
#endif /* {if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)} */

    return (completeStatus);
}

#if ((STD_ON == CDD_PDL_DMA_NOTIFICATION_ENABLE)  || (STD_ON == CDD_PDL_DMA_ERR_NOTIFICATION_SUPPORT))
/*!
* @brief         The function enables the user notifications.
*
* @param[in]     PdlDmaChannel         The id of the Dma channel
* @param[in]     NotificationType      The type of the notification:
*                                      PDL_DMA_TRAN_COMPLETED: Transfer complete notification
*                                      PDL_DMA_TRAN_HALF_COMPLETED: Half transfer complete notification
*                                      PDL_DMA_TRAN_ERROR: Transfer error notification
*
* @retval        void
*/ 
FUNC(void, PDL_CODE) Pdl_TopDmaNotifiEn(VAR(Pdl_ChType, AUTOMATIC) PdlDmaChannel,
    VAR(Pdl_DmaTranNotifType, AUTOMATIC)  NotificationType)
{
#if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)
    uint32 cnt = 0;
    Std_ReturnType retVal = E_NOT_OK;

    if((Std_ReturnType)E_OK == Pdl_ValidateChannelConfigCall(PdlDmaChannel, (uint8)PDL_ENABLE_NOTIFICATION_SID))
    {
#if (STD_ON == CDD_PDL_DMA_NOTIFICATION_ENABLE)
        for(cnt = 0; cnt < (uint32)PDL_DMA_CONFIG_CHANNELS_COUNT; cnt++)
        {
            if(PdlDmaChannel == (*(g_pdlConfigPtr->pdlDmaHwConfigPtr->pdlDmaConfigPtr->chConfigPtr))[cnt].dmaChannel)
            {
                retVal = Pdl_ValidateParamNotifi((*(g_pdlConfigPtr->pdlDmaHwConfigPtr->pdlDmaConfigPtr->chConfigPtr))[cnt].dmaChNotifiFuncPtr);
                break;
            }
            else
            {
                /* do nothing */
            }
        }
        if((Std_ReturnType)E_OK == retVal)
        {
#endif  /* {if (STD_ON == CDD_PDL_DMA_NOTIFICATION_ENABLE)} */
#endif /* {if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)} */

            Pdl_Dma_NotifEn(PdlDmaChannel, NotificationType);

#if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)
#if (STD_ON == CDD_PDL_DMA_NOTIFICATION_ENABLE)
        }
        else
        {
            /* do nothing */
        }
#endif /* {if ((STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE) (STD_ON == CDD_PDL_DMA_NOTIFICATION_ENABLE))} */
    }
    else
    {
        /* do nothing */
    }
    
    PDL_END_VALIDATE_CH_CONFIG_CALL(PdlDmaChannel);
    (void)retVal;
#endif /* {if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)} */
}

/*!
* @brief         The function disables the user notifications.
*
* @param[in]     PdlDmaChannel         The id of the Dma channel
*
* @param[in]     NotificationType      The type of the notification:
*                                      PDL_DMA_TRAN_COMPLETED: Transfer complete notification
*                                      PDL_DMA_TRAN_HALF_COMPLETED: Half transfer complete notification
*                                      PDL_DMA_TRAN_ERROR: Transfer error notification
* @retval        void
*/ 
FUNC(void, PDL_CODE) Pdl_TopDmaNotifiDis(VAR(Pdl_ChType,AUTOMATIC) PdlDmaChannel,
    VAR(Pdl_DmaTranNotifType, AUTOMATIC)  NotificationType)
{
#if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)
    if((Std_ReturnType)E_OK == Pdl_ValidateChannelConfigCall(PdlDmaChannel, (uint8)PDL_DISABLE_NOTIFICATION_SID))
    {
#endif /* {if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)} */

        Pdl_Dma_NotifDis(PdlDmaChannel, NotificationType);

#if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)
    }
    else
    {
        /* do nothing */
    }
    PDL_END_VALIDATE_CH_CONFIG_CALL(PdlDmaChannel);
#endif /* {if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)} */
}

/*!
* @brief         The function acknowledges the interrupt for the channel.
*
* @param[in]     PdlDmaChannel         The id of the Dma channel
*
* @retval        void
*/ 
FUNC(void, PDL_CODE) Pdl_TopDmaAcknowlInt(VAR(Pdl_ChType,AUTOMATIC) PdlDmaChannel)
{
#if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)
    if((Std_ReturnType)E_OK == Pdl_ValidateChannelConfigCall(PdlDmaChannel, (uint8)PDL_ACKNOWLEDGE_INTERRUPT_SID))
    {
#endif /* {if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)} */

        Pdl_Dma_IntAcknow(PdlDmaChannel);

#if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)
    }
    else
    {
        /* do nothing */
    }
    PDL_END_VALIDATE_CH_CONFIG_CALL(PdlDmaChannel);
#endif /* {if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)} */
}

#endif /* {if ((STD_ON == CDD_PDL_DMA_NOTIFICATION_ENABLE)  || (STD_ON == CDD_PDL_DMA_ERR_NOTIFICATION_SUPPORT))} */

/*!
* @brief         The function sets the channel transmission data size.
*
* @param[in]     PdlDmaChannel         The id of the Dma channel
* @param[in]     DataNum               The number of data to be transferred
*
* @retval        void
*/ 
FUNC(void, PDL_CODE) Pdl_TopDmaChDataNumSet(VAR(Pdl_ChType,AUTOMATIC) PdlDmaChannel, VAR(uint32, AUTOMATIC) DataNum)
{
#if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)
    if((Std_ReturnType)E_OK == Pdl_ValidateChannelConfigCall(PdlDmaChannel, (uint8)PDL_SET_TRANSF_DATA_SIZE_SID))
    {
#endif /* {if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)} */

        Pdl_Dma_SetDataNumber(PdlDmaChannel, DataNum);

#if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)
    }
    else
    {
        /* do nothing */
    }
    PDL_END_VALIDATE_CH_CONFIG_CALL(PdlDmaChannel);
#endif /* {if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)} */
}

/*!
* @brief         The function reads the channel transmission data size.
*
* @param[in]     PdlDmaChannel         The id of the Dma channel
*
* @retval        The number of data units in the current DMA Channel transfer
*/ 
FUNC(uint32, PDL_CODE) Pdl_TopDmaChDataNumRead(VAR(Pdl_ChType,AUTOMATIC) PdlDmaChannel)
{
    VAR(uint32, AUTOMATIC) dataNum = 0U;

#if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)
    if((Std_ReturnType)E_OK == Pdl_ValidateChannelConfigCall(PdlDmaChannel, (uint8)PDL_SET_TRANSF_DATA_SIZE_SID))
    {
#endif /* {if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)} */

       dataNum = Pdl_Dma_ReadDataNumber(PdlDmaChannel);

#if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)
    }
    else
    {
        /* do nothing */
    }
    PDL_END_VALIDATE_CH_CONFIG_CALL(PdlDmaChannel);
#endif /* {if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)} */

    return dataNum;
}

/*!
* @brief         The function reads the status.
*
* @param[in]     Flag:   Specifies the flag to check
*                      This parameter can be one of the following values:
*                       DMA1_FLAG_AL1:   DMA1 Channel 1 All flag
*                       DMA1_FLAG_TF1:   DMA1 Channel 1 Transfer Complete flag
*                       DMA1_FLAG_HT1:   DMA1 Channel 1 Half Transfer Complete flag
*                       DMA1_FLAG_TE1:   DMA1 Channel 1 Transfer Error flag
*                       DMA1_FLAG_AL2:   DMA1 Channel 2 All flag
*                       DMA1_FLAG_TF2:   DMA1 Channel 2 Transfer Complete flag
*                       DMA1_FLAG_HT2:   DMA1 Channel 2 Half Transfer Complete flag
*                       DMA1_FLAG_TE2:   DMA1 Channel 2 Transfer Error flag
*                       DMA1_FLAG_AL3:   DMA1 Channel 3 All flag
*                       DMA1_FLAG_TF3:   DMA1 Channel 3 Transfer Complete flag
*                       DMA1_FLAG_HT3:   DMA1 Channel 3 Half Transfer Complete flag
*                       DMA1_FLAG_TE3:   DMA1 Channel 3 Transfer Error flag
*                       DMA1_FLAG_AL4:   DMA1 Channel 4 All flag
*                       DMA1_FLAG_TF4:   DMA1 Channel 4 Transfer Complete flag
*                       DMA1_FLAG_HT4:   DMA1 Channel 4 Half Transfer Complete flag
*                       DMA1_FLAG_TE4:   DMA1 Channel 4 Transfer Error flag
*                       DMA1_FLAG_AL5:   DMA1 Channel 5 All flag
*                       DMA1_FLAG_TF5:   DMA1 Channel 5 Transfer Complete flag
*                       DMA1_FLAG_HT5:   DMA1 Channel 5 Half Transfer Complete flag
*                       DMA1_FLAG_TE5:   DMA1 Channel 5 Transfer Error flag
*
* @retval        The new state of flag (SET or RESET)
*/ 
FUNC(uint8, PDL_CODE) Pdl_TopDmaChStsFlagRead(VAR(Pdl_DmaChFlagType, AUTOMATIC) Flag)
{
    return Pdl_Dma_ReadStatusFlag(Flag);
}

/*!
* @brief         The function clears the status.
*
* @param[in]      Flag:   Specifies the flag to check
*                      This parameter can be one of the following values:
*                       DMA1_FLAG_AL1:   DMA1 Channel 1 All flag
*                       DMA1_FLAG_TF1:   DMA1 Channel 1 Transfer Complete flag
*                       DMA1_FLAG_HT1:   DMA1 Channel 1 Half Transfer Complete flag
*                       DMA1_FLAG_TE1:   DMA1 Channel 1 Transfer Error flag
*                       DMA1_FLAG_AL2:   DMA1 Channel 2 All flag
*                       DMA1_FLAG_TF2:   DMA1 Channel 2 Transfer Complete flag
*                       DMA1_FLAG_HT2:   DMA1 Channel 2 Half Transfer Complete flag
*                       DMA1_FLAG_TE2:   DMA1 Channel 2 Transfer Error flag
*                       DMA1_FLAG_AL3:   DMA1 Channel 3 All flag
*                       DMA1_FLAG_TF3:   DMA1 Channel 3 Transfer Complete flag
*                       DMA1_FLAG_HT3:   DMA1 Channel 3 Half Transfer Complete flag
*                       DMA1_FLAG_TE3:   DMA1 Channel 3 Transfer Error flag
*                       DMA1_FLAG_AL4:   DMA1 Channel 4 All flag
*                       DMA1_FLAG_TF4:   DMA1 Channel 4 Transfer Complete flag
*                       DMA1_FLAG_HT4:   DMA1 Channel 4 Half Transfer Complete flag
*                       DMA1_FLAG_TE4:   DMA1 Channel 4 Transfer Error flag
*                       DMA1_FLAG_AL5:   DMA1 Channel 5 All flag
*                       DMA1_FLAG_TF5:   DMA1 Channel 5 Transfer Complete flag
*                       DMA1_FLAG_HT5:   DMA1 Channel 5 Half Transfer Complete flag
*                       DMA1_FLAG_TE5:   DMA1 Channel 5 Transfer Error flag
*
* @retval        None
*/ 
FUNC(void, PDL_CODE) Pdl_TopDmaChStsFlagClr(VAR(Pdl_DmaChFlagType, AUTOMATIC) Flag)
{
    Pdl_Dma_ClrStsFlag((uint32)Flag);
}

/*!
* @brief         The function updates the peripheral address of the channel.
*
* @param[in]     ChannelId          The channel id
* @param[in]     Paddr              The peripheral address of the channel
*
* @retval        void
*/ 
FUNC(void, PDL_CODE) Pdl_TopDmaPAddrRefresh(VAR(Pdl_ChType, AUTOMATIC) ChannelId,\
    VAR(uint32, AUTOMATIC) Paddr)
{
    Pdl_Dma_PAddrRefresh(ChannelId, Paddr);
}

/*!
* @brief         The function updates the memory address of the channel.
*
* @param[in]     ChannelId          The channel id
* @param[in]     Maddr              The memory address of the channel
*
* @retval        void
*/ 
FUNC(void, PDL_CODE) Pdl_TopDmaMAddrRefresh(VAR(Pdl_ChType, AUTOMATIC) ChannelId,\
    VAR(uint32, AUTOMATIC) Maddr)
{
    Pdl_Dma_MAddrRefresh(ChannelId, Maddr);
}

#if (STD_ON == CDD_PDL_DMA_NOTIFICATION_ENABLE)

/*!
* @brief         The function is called when user enable the notification. 
*
* @param[in]     ChId  The id of the channel
*
* @retval        void
*/ 
FUNC(void, PDL_CODE) Pdl_NotifiCallbackFunc(VAR(Pdl_ChType, AUTOMATIC) ChId)
{
    VAR(Pdl_NotifyType, AUTOMATIC) pfNotify = NULL_PTR;
    uint32 cnt = 0;

    if(NULL_PTR != g_pdlConfigPtr)
    {
        /* Verify that there is a logic channel associated with the hardware channel */
        if (ChId <= DMA_HW_CH5)
        {
            for(cnt = 0; cnt < (uint32)PDL_DMA_CONFIG_CHANNELS_COUNT; cnt++)
            {
                if(ChId == (*(g_pdlConfigPtr->pdlDmaHwConfigPtr->pdlDmaConfigPtr->chConfigPtr))[cnt].dmaChannel)
                {
                    pfNotify = (*(g_pdlConfigPtr->pdlDmaHwConfigPtr->pdlDmaConfigPtr->chConfigPtr))[cnt].dmaChNotifiFuncPtr;
                    break;
                }
                else
                {
                    /* do nothing */
                }
            }

            if(NULL_PTR == pfNotify)
            {
#if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE) 
                Pdl_RepUnexpIsrErrFunc();
#endif
            }
            else
            {
                pfNotify();
            }
        }
        else
        {
#if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)
            /* Hardware channel has not been associated with a logic channel */
            Pdl_RepUnexpIsrErrFunc();
#endif /* {if (STD_ON == CDD_PDL_DEV_ERR_DETECT_ENABLE)} */
        }
    }
    else
    {
        /* do nothing */
    }
}
#endif /* {if (STD_ON == CDD_PDL_DMA_NOTIFICATION_ENABLE)} */


#if (STD_ON == CDD_PDL_DMA_ERR_NOTIFICATION_SUPPORT)
/*!
* @brief         The function is called when user enable the error notification. 
*
* @param[in]     DmaCh   The id of the DMA hardware channel(1-5)
* @param[in]     Error   The id of the error
*
* @retval        void
*/ 
FUNC(void, PDL_CODE) Pdl_ErrNotifiCallbackFunc(VAR(Pdl_DmaModType, AUTOMATIC) DmaCh)
{
    VAR(Pdl_DmaErrNotifiType, AUTOMATIC) pfNotify = NULL_PTR;
    uint32 cnt = 0;

    for(cnt = 0; cnt < (uint32)PDL_DMA_CONFIG_CHANNELS_COUNT; cnt++)
    {
        if(DmaCh == (*(g_pdlConfigPtr->pdlDmaHwConfigPtr->pdlDmaConfigPtr->chConfigPtr))[cnt].dmaChannel)
        {
            pfNotify = (*(g_pdlConfigPtr->pdlDmaHwConfigPtr->pdlDmaConfigPtr->chConfigPtr))[cnt].dmaErrNotifiPtr;
            break;
        }
        else
        {
            /* do nothing */
        }
    }

    if (NULL_PTR != pfNotify)
    {
        pfNotify();
    }
    else
    {
        /* do nothing */
    }
}
#endif /* {if (STD_ON == CDD_PDL_DMA_ERR_NOTIFICATION_SUPPORT)} */

#endif /* {if (STD_ON == CDD_PDL_DMA_SUPPORT)} */

#define PDL_STOP_SEC_CODE
#include "Pdl_MemMap.h"

/**@} end of group PDL_Fuctions */
#ifdef __cplusplus
}
#endif  /* ifdef __cplusplus */
/**@} end of group PDL_Driver */
/**@} end of group G32A10xx_StdPeriphDriver */
