/*==================================================================================================
*   Platform             : CORTEXM
*   Peripheral           :
*   Dependencies         : none
*
*   Autosar Version      : 4.4.0
*   Autosar Revision     : ASR_REL_4_4_REV_0000
*   Autosar Conf.Variant :
*   SW Version           : 0.8.0
*
*   (c) Copyright 2020-2026 Yuntu Microelectronics co.,ltd.
*   All Rights Reserved.
*
*   YUNTU Confidential. This software is owned or controlled by YUNTU 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.
==================================================================================================*/

#ifndef PLATFORM_MLD_H_
#define PLATFORM_MLD_H_

#ifdef __cplusplus
extern "C"
{
#endif

/**
*   @file
*
*   @internal
*   @addtogroup Platform_Mld
*   @{
*/

/*==================================================================================================
*                                        INCLUDE FILES
==================================================================================================*/

#include "Platform_Mld_Cfg.h"
#include "IntCtrl_Lld.h"
#include "Platform_Types.h"
#include "System_Lld.h"
#include "IntCtrl_Lld_CfgDefines.h"

#if (PLATFORM_INT_MONITOR == STD_ON)
#include "Intm_Lld.h"
#endif

#if (PLATFORM_PCACHE == STD_ON)
#include "Pcache_Lld.h"
#endif

/*==================================================================================================
*                              SOURCE FILE VERSION INFORMATION
==================================================================================================*/
#define PLATFORM_MLD_VENDOR_ID                         (180)
#define PLATFORM_MLD_AR_RELEASE_MAJOR_VERSION          (4)
#define PLATFORM_MLD_AR_RELEASE_MINOR_VERSION          (4)
#define PLATFORM_MLD_AR_RELEASE_REVISION_VERSION       (0)
#define PLATFORM_MLD_SW_MAJOR_VERSION                  (0)
#define PLATFORM_MLD_SW_MINOR_VERSION                  (8)
#define PLATFORM_MLD_SW_PATCH_VERSION                  (0)
/*==================================================================================================
*                                     FILE VERSION CHECKS
==================================================================================================*/
/* Check if current file and Platform_Mld_Cfg header file are of the same vendor */
#if (PLATFORM_MLD_VENDOR_ID != PLATFORM_MLD_CFG_VENDOR_ID)
#error "Platform_Mld.h and Platform_Mld_Cfg.h have different vendor ids"
#endif
/* Check if current file and Platform_Mld_Cfg header file are of the same Autosar version */
#if ((PLATFORM_MLD_AR_RELEASE_MAJOR_VERSION    != PLATFORM_MLD_CFG_AR_MAJOR_VERSION) || \
     (PLATFORM_MLD_AR_RELEASE_MINOR_VERSION    != PLATFORM_MLD_CFG_AR_MINOR_VERSION) || \
     (PLATFORM_MLD_AR_RELEASE_REVISION_VERSION != PLATFORM_MLD_CFG_AR_REVISION_VERSION) \
    )
#error "AutoSar Version Numbers of Platform_Mld.h and Platform_Mld_Cfg.h are different"
#endif
/* Check if current file and Platform_Mld_Cfg header file are of the same Software version */
#if ((PLATFORM_MLD_SW_MAJOR_VERSION != PLATFORM_MLD_CFG_SW_MAJOR_VERSION) || \
     (PLATFORM_MLD_SW_MINOR_VERSION != PLATFORM_MLD_CFG_SW_MINOR_VERSION) || \
     (PLATFORM_MLD_SW_PATCH_VERSION != PLATFORM_MLD_CFG_SW_PATCH_VERSION) \
    )
#error "Software Version Numbers of Platform_Mld.h and Platform_Mld_Cfg.h are different"
#endif


/* Check if current file and IntCtrl_Lld header file are of the same vendor */
#if (PLATFORM_MLD_VENDOR_ID != PLATFORM_INTCTRL_LLD_VENDOR_ID)
#error "Platform_Mld.h and IntCtrl_Lld.h have different vendor ids"
#endif

/* Check if current file and IntCtrl_Lld header file are of the same Software version */
#if ((PLATFORM_MLD_SW_MAJOR_VERSION != PLATFORM_INTCTRL_LLD_SW_MAJOR_VERSION) || \
     (PLATFORM_MLD_SW_MINOR_VERSION != PLATFORM_INTCTRL_LLD_SW_MINOR_VERSION) || \
     (PLATFORM_MLD_SW_PATCH_VERSION != PLATFORM_INTCTRL_LLD_SW_PATCH_VERSION) \
    )
#error "Software Version Numbers of Platform_Mld.h and IntCtrl_Lld.h are different"
#endif

#if (PLATFORM_INT_MONITOR == STD_ON)
/* Check if current file and Intm_Lld header file are of the same vendor */
#if (PLATFORM_MLD_VENDOR_ID != INTM_LLD_VENDOR_ID)
#error "Platform_Mld.h and Intm_Lld.h have different vendor ids"
#endif

/* Check if current file and Intm_Lld header file are of the same Software version */
#if ((PLATFORM_MLD_SW_MAJOR_VERSION != INTM_LLD_SW_MAJOR_VERSION) || \
     (PLATFORM_MLD_SW_MINOR_VERSION != INTM_LLD_SW_MINOR_VERSION) || \
     (PLATFORM_MLD_SW_PATCH_VERSION != INTM_LLD_SW_PATCH_VERSION) \
    )
#error "Software Version Numbers of Platform_Mld.h and Intm_Lld.h are different"
#endif
#endif

/* Check if current file and System_Lld header file are of the same vendor */
#if (PLATFORM_MLD_VENDOR_ID != PLATFORM_SYSTEM_LLD_VENDOR_ID)
#error "Platform_Mld.h and System_Lld.h have different vendor ids"
#endif

/* Check if current file and System_Lld header file are of the same Software version */
#if ((PLATFORM_MLD_SW_MAJOR_VERSION != PLATFORM_SYSTEM_LLD_SW_MAJOR_VERSION) || \
     (PLATFORM_MLD_SW_MINOR_VERSION != PLATFORM_SYSTEM_LLD_SW_MINOR_VERSION) || \
     (PLATFORM_MLD_SW_PATCH_VERSION != PLATFORM_SYSTEM_LLD_SW_PATCH_VERSION) \
    )
#error "Software Version Numbers of Platform_Mld.h and System_Lld.h are different"
#endif

/*==================================================================================================
*                                       GLOBAL VARIABLES
==================================================================================================*/
extern uint32 VTABLE[((uint32)(INT_CTRL_LLD_IRQ_MAX)) + 16U + 1U];

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

/**
 * @brief         Initializes the platform settings based on user configuration. Configures interrupt controller, system interrupts (if FPU is enabled), interrupt monitors (if enabled), and P-CACHE (if enabled).
 * @autosar       N/A
 *
 * @details       Service ID: 0x20
 *                Sync/Async: Synchronous
 *                Reentrancy: Non Reentrant
 *                Available via: Platform_Mld.h
 *
 * @param[in] Config: Pointer to platform configuration structure containing interrupt controller configuration, system configuration, interrupt monitor configuration, and P-CACHE configuration.
 * @return Std_ReturnType E_OK if initialization is successful; E_NOT_OK if Config is NULL or if IntCtrlConfig or SystemConfig (when required) or IntMonitorConfig (when enabled) is NULL.
*/
Std_ReturnType Platform_Mld_Init(const Platform_Mld_ConfigType *Config);

#if (PLATFORM_MSCM_CFG == STD_ON)
/**
 * @brief         Initializes the platform settings for non-core elements based on user configuration. Configures interrupt routing for non-core interrupts by clearing pending interrupts and installing interrupt handlers.
 * @autosar       N/A
 *
 * @details       Service ID: N/A
 *                Sync/Async: Synchronous
 *                Reentrancy: Non Reentrant
 *                Available via: Platform_Mld.h
 *
 * @param[in] Config: Pointer to non-core configuration structure containing interrupt route configuration. If NULL, no initialization is performed.
 * @return No return value.
*/
void Platform_Mld_InitNonCore(const Platform_Mld_NonCoreConfigType *Config);
#endif

#define PLATFORM_START_SEC_CODE
#include "Platform_MemMap.h"

/**
 * @internal
 * @brief         Enables or disables an interrupt by calling the Interrupt Controller IP layer.
 *
 * @details       Sync/Async: Synchronous
 *                Reentrancy: Non Reentrant
 *
 * @param[in] IrqNumber Interrupt number to enable/disable.
 * @param[in] Enable TRUE to enable the interrupt, FALSE to disable it.
 * @return void
 */
PLATFORM_FUNC static inline void Platform_Mld_SetIrq(IRQn_Type IrqNumber, boolean Enable)
{
    if (TRUE == Enable)
    {
        IntCtrl_Lld_EnableIrq(IrqNumber);
    }
    else
    {
        IntCtrl_Lld_DisableIrq(IrqNumber);
    }
}

/**
 * @internal
 * @brief         Sets the priority of an interrupt by calling the Interrupt Controller IP layer.
 *
 * @details       Sync/Async: Synchronous
 *                Reentrancy: Non Reentrant
 *
 * @param[in] IrqNumber Interrupt number whose priority is to be set.
 * @param[in] Priority Priority value to assign to the interrupt.
 * @return void
 */
PLATFORM_FUNC static inline void Platform_Mld_SetIrqPriority(IRQn_Type IrqNumber, uint8 Priority)
{
    IntCtrl_Lld_SetPriority(IrqNumber, Priority);
}

/**
 * @internal
 * @brief         Returns the priority of an interrupt by calling the Interrupt Controller IP layer.
 *
 * @details       Sync/Async: Synchronous
 *                Reentrancy: Non Reentrant
 *
 * @param[in] IrqNumber Interrupt number whose priority is requested.
 * @return uint8 Priority value of the specified interrupt.
 */
PLATFORM_FUNC static inline uint8 Platform_Mld_GetIrqPriority(IRQn_Type IrqNumber)
{
    return IntCtrl_Lld_GetPriority(IrqNumber);
}

/**
 * @internal
 * @brief         Installs a new interrupt handler by calling the Interrupt Controller IP layer.
 *
 * @details       Sync/Async: Synchronous
 *                Reentrancy: Non Reentrant
 *
 * @param[in] IrqNumber Interrupt number for which the handler will be installed.
 * @param[in] NewHandler Pointer to the new handler function.
 * @param[out] OldHandler Pointer to location where the previous handler will be stored (may be NULL).
 * @return void
 */
PLATFORM_FUNC static inline void Platform_Mld_InstallIrqHandler(IRQn_Type IrqNumber,
        const IntCtrl_Lld_IrqHandlerType NewHandler,
        IntCtrl_Lld_IrqHandlerType *const OldHandler)
{
    IntCtrl_Lld_InstallHandler(IrqNumber, NewHandler, OldHandler);
}

#define PLATFORM_STOP_SEC_CODE
#include "Platform_MemMap.h"

#if (PLATFORM_INT_MONITOR == STD_ON)
/**
 * @brief         Enables or disables interrupt monitoring feature by calling the Interrupt Monitor IP layer. This function is used to control the overall interrupt monitoring functionality.
 * @autosar       N/A
 *
 * @details       Service ID: 0x25
 *                Sync/Async: Synchronous
 *                Reentrancy: Non Reentrant
 *                Available via: Platform_Mld.h
 *
 * @param[in] Enable: TRUE to enable interrupt monitoring, FALSE to disable interrupt monitoring.
 * @return No return value.
*/
void Platform_Mld_SetIrqMonitor(boolean Enable);


/**
 * @internal
 * @brief         Acknowledges a monitored interrupt by calling the Interrupt Monitor IP layer.
 */
#define Platform_Mld_AckIrq(IrqNumber) Intm_Lld_AckIrq(IrqNumber)


/**
 * @brief         Selects an interrupt to be monitored by calling the Interrupt Monitor IP layer. Associates a specific interrupt number with a monitoring channel.
 * @autosar       N/A
 *
 * @details       Service ID: 0x27
 *                Sync/Async: Synchronous
 *                Reentrancy: Non Reentrant
 *                Available via: Platform_Mld.h
 *
 * @param[in] Channel: Monitoring channel number to which the interrupt will be assigned.
 * @param[in] IrqNumber: Interrupt number to be monitored by the specified channel.
 * @return No return value.
*/
void Platform_Mld_SelectMonitoredIrq(uint8 Channel, IRQn_Type IrqNumber);

/**
 * @brief         Sets an accepted latency for a monitored interrupt by calling the Interrupt Monitor IP layer. Configures the maximum acceptable latency time for an interrupt to be serviced.
 * @autosar       N/A
 *
 * @details       Service ID: 0x28
 *                Sync/Async: Synchronous
 *                Reentrancy: Non Reentrant
 *                Available via: Platform_Mld.h
 *
 * @param[in] Channel: Monitoring channel number for which the latency is configured.
 * @param[in] Latency: Accepted latency value in clock cycles for the monitored interrupt.
 * @return No return value.
*/
void Platform_Mld_SetMonitoredIrqLatency(uint8 Channel, uint32 Latency);


/**
 * @brief         Resets an interrupt monitor timer by calling the Interrupt Monitor IP layer. Clears the timer for the specified monitoring channel.
 * @autosar       N/A
 *
 * @details       Service ID: 0x29
 *                Sync/Async: Synchronous
 *                Reentrancy: Non Reentrant
 *                Available via: Platform_Mld.h
 *
 * @param[in] Channel: Monitoring channel number whose timer will be reset.
 * @return No return value.
*/
void Platform_Mld_ResetIrqMonitorTimer(uint8 Channel);

/**
 * @brief         Returns the status of an interrupt monitor by calling the Interrupt Monitor IP layer. Indicates whether the monitored interrupt has exceeded its accepted latency.
 * @autosar       N/A
 *
 * @details       Service ID: 0x2A
 *                Sync/Async: Synchronous
 *                Reentrancy: Non Reentrant
 *                Available via: Platform_Mld.h
 *
 * @param[in] Channel: Monitoring channel number for which the status is queried.
 * @return boolean TRUE if the interrupt monitor status indicates a timeout or error condition; FALSE if the monitor is functioning normally.
*/
boolean Platform_Mld_GetIrqMonitorStatus(uint8 Channel);
/**
 * @brief         Validates whether the given logical channel number is within the valid range for interrupt monitoring. Checks if the channel number is less than or equal to the configured number of channels.
 * @autosar       N/A
 *
 * @details       Service ID: N/A
 *                Sync/Async: Synchronous
 *                Reentrancy: Non Reentrant
 *                Available via: Platform_Mld.h
 *
 * @param[in] Config: Pointer to platform configuration structure containing interrupt monitor configuration.
 * @param[in] Channel: Logical channel number to be validated.
 * @return Std_ReturnType E_OK if the channel number is valid (within the configured range); E_NOT_OK if the channel number is invalid or if Config or IntMonitorConfig is NULL.
*/
Std_ReturnType Platform_Mld_ValidateChannelIntm(const Platform_Mld_ConfigType *Config, uint8 Channel);

/**
 * @brief         Validates whether interrupt monitor enabling/disabling can be performed. Checks if the generic interrupt monitor configuration is available in the configuration structure.
 * @autosar       N/A
 *
 * @details       Service ID: N/A
 *                Sync/Async: Synchronous
 *                Reentrancy: Non Reentrant
 *                Available via: Platform_Mld.h
 *
 * @param[in] Config: Pointer to platform configuration structure containing interrupt monitor configuration.
 * @return Std_ReturnType E_OK if interrupt monitor enabling/disabling can be performed (IntmGenericConfig is available); E_NOT_OK if IntmGenericConfig is NULL or if Config or IntMonitorConfig is NULL.
*/
Std_ReturnType Platform_Mld_ValidateSetIrqMonitor(const Platform_Mld_ConfigType *Config);

#endif /* (PLATFORM_INT_MONITOR == STD_ON) */

#ifdef __cplusplus
}
#endif

#endif /* PLATFORM_MLD_H_ */

