/*==================================================================================================
*   Project              : AUTOSAR 4.4
*   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 INTCTRL_LLD_H_
#define INTCTRL_LLD_H_

/**
*   @file
*
*   @defgroup   IntCtrl_Lld Interrupt Controller IP
*   @ingroup    Platform
*
*   @addtogroup IntCtrl_Lld
*   @{
*/

/*==================================================================================================
*                                        INCLUDE FILES
==================================================================================================*/
#include "IntCtrl_Lld_CfgDefines.h"
#include "IntCtrl_Lld_Cfg.h"
#include "Devassert.h"
/*==================================================================================================
*                              SOURCE FILE VERSION INFORMATION
==================================================================================================*/
#define PLATFORM_INTCTRL_LLD_VENDOR_ID                          (180)
#define PLATFORM_INTCTRL_LLD_SW_MAJOR_VERSION                   (0)
#define PLATFORM_INTCTRL_LLD_SW_MINOR_VERSION                   (8)
#define PLATFORM_INTCTRL_LLD_SW_PATCH_VERSION                   (0)
/*==================================================================================================
                                      FILE VERSION CHECKS
==================================================================================================*/
/* Check if current file and IntCtrl_Lld_Cfg header file are of the same vendor */
#if (PLATFORM_INTCTRL_LLD_VENDOR_ID != PLATFORM_INTCTRL_LLD_CFG_VENDOR_ID)
#error "IntCtrl_Lld.h and IntCtrl_Lld_Cfg.h have different vendor ids"
#endif

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

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


#if defined(__cplusplus)
extern "C" {
#endif /* __cplusplus*/

/**
 * @brief         Initializes the configured interrupts at interrupt controller
 *                level. Configures the vector table address (if enabled),
 *                clears pending flags, sets priorities, and enables or
 *                disables interrupts according to the provided configuration.
 * @autosar       N/A
 *
 * @details       Service ID: N/A
 *                Sync/Async: Synchronous
 *                Reentrancy: Non Reentrant
 *                Available via: IntCtrl_Lld.h
 *
 * @param[in] IntCtrlCtrlConfig Pointer to interrupt controller
 *                              configuration structure containing vector
 *                              table address, interrupt count, and
 *                              interrupt configuration array with IRQ
 *                              numbers, priorities, and enable/disable
 *                              settings.
 * @return IntCtrl_Lld_StatusType Returns INTCTRL_LLD_STATUS_SUCCESS if
 *                                 initialization is successful.
 */
IntCtrl_Lld_StatusType IntCtrl_Lld_Init(const IntCtrl_Lld_CtrlConfigType *IntCtrlCtrlConfig);

#if (INT_CTRL_LLD_MSCM_SYSTEM_INTERRUPT_ROUTER == STD_ON)
/**
 * @brief         Initializes the configured routing interrupts for
 *                multi-core systems. Configures interrupt routing to
 *                target cores and installs interrupt handlers for each
 *                configured interrupt.
 * @autosar       N/A
 *
 * @details       Service ID: N/A
 *                Sync/Async: Synchronous
 *                Reentrancy: Non Reentrant
 *                Available via: IntCtrl_Lld.h
 *
 * @param[in] routeConfig Pointer to interrupt routing configuration
 *                        structure containing interrupt count and
 *                        interrupt routing configuration array with IRQ
 *                        numbers, target cores, and handler functions.
 * @return IntCtrl_Lld_StatusType Returns INTCTRL_LLD_STATUS_SUCCESS if
 *                                 routing configuration is successful.
 */
IntCtrl_Lld_StatusType IntCtrl_Lld_ConfigIrqRouting(const IntCtrl_Lld_GlobalRouteConfigType *routeConfig);
#endif

/**
 * @brief         Installs a handler for an interrupt request (IRQ).
 *                Replaces the current interrupt handler in the vector
 *                table with the new handler function. The old handler
 *                address can be optionally stored. This function works
 *                only when the interrupt vector table resides in RAM.
 * @autosar       N/A
 *
 * @details       Service ID: N/A
 *                Sync/Async: Synchronous
 *                Reentrancy: Non Reentrant
 *                Available via: IntCtrl_Lld.h
 *
 * @param[in] IrqNumber  Interrupt number for which the handler is
 *                       installed.
 * @param[in] NewHandler Function pointer for the new interrupt handler
 *                       to be installed.
 * @param[out] OldHandler Pointer to store the address of the old
 *                        interrupt handler. This parameter can be
 *                        passed as NULL if not needed.
 * @return No return value.
 */
void IntCtrl_Lld_InstallHandler(IRQn_Type IrqNumber, const IntCtrl_Lld_IrqHandlerType NewHandler, IntCtrl_Lld_IrqHandlerType *const OldHandler);

/**
 * @brief         Enables an interrupt request at the interrupt controller
 *                level. This function enables the specified interrupt in
 *                the NVIC (Nested Vectored Interrupt Controller).
 * @autosar       N/A
 *
 * @details       Service ID: N/A
 *                Sync/Async: Synchronous
 *                Reentrancy: Non Reentrant
 *                Available via: IntCtrl_Lld.h
 *
 * @param[in] IrqNumber Interrupt number to be enabled.
 * @return No return value.
 */
void IntCtrl_Lld_EnableIrq(IRQn_Type IrqNumber);

/**
 * @brief         Disables an interrupt request at the interrupt controller
 *                level. This function disables the specified interrupt in
 *                the NVIC (Nested Vectored Interrupt Controller).
 * @autosar       N/A
 *
 * @details       Service ID: N/A
 *                Sync/Async: Synchronous
 *                Reentrancy: Non Reentrant
 *                Available via: IntCtrl_Lld.h
 *
 * @param[in] IrqNumber Interrupt number to be disabled.
 * @return No return value.
 */
void IntCtrl_Lld_DisableIrq(IRQn_Type IrqNumber);

/**
 * @brief         Sets the priority for an interrupt request. This
 *                function configures the priority level of the specified
 *                interrupt in the NVIC priority registers.
 * @autosar       N/A
 *
 * @details       Service ID: N/A
 *                Sync/Async: Synchronous
 *                Reentrancy: Non Reentrant
 *                Available via: IntCtrl_Lld.h
 *
 * @param[in] IrqNumber Interrupt number for which the priority is set.
 * @param[in] Priority  Priority value to be set. The valid range
 *                      depends on the number of priority bits
 *                      configured (INT_CTRL_LLD_NVIC_PRIO_BITS).
 * @return No return value.
 */
void IntCtrl_Lld_SetPriority(IRQn_Type IrqNumber, uint8 Priority);

/**
 * @brief         Gets the priority for an interrupt request. This
 *                function retrieves the current priority level of the
 *                specified interrupt from the NVIC priority registers.
 * @autosar       N/A
 *
 * @details       Service ID: N/A
 *                Sync/Async: Synchronous
 *                Reentrancy: Non Reentrant
 *                Available via: IntCtrl_Lld.h
 *
 * @param[in] IrqNumber Interrupt number for which the priority is
 *                      retrieved.
 * @return uint8        Returns the current priority value of the
 *                      interrupt.
 */
uint8 IntCtrl_Lld_GetPriority(IRQn_Type IrqNumber);

/**
 * @brief         Clears the pending flag for an interrupt request.
 *                This function clears the pending interrupt status in
 *                the NVIC, removing any pending interrupt request for
 *                the specified interrupt.
 * @autosar       N/A
 *
 * @details       Service ID: N/A
 *                Sync/Async: Synchronous
 *                Reentrancy: Reentrant
 *                Available via: IntCtrl_Lld.h
 *
 * @param[in] IrqNumber Interrupt number for which the pending flag is
 *                      cleared.
 * @return No return value.
 */
void IntCtrl_Lld_ClearPending(IRQn_Type IrqNumber);


#if (INT_CTRL_LLD_STANDALONE_APIS == STD_ON)
/**
 * @brief         Sets the pending flag for an interrupt request.
 *                This function sets the pending interrupt status in the
 *                NVIC, causing the interrupt to be serviced (if
 *                enabled).
 * @autosar       N/A
 *
 * @details       Service ID: N/A
 *                Sync/Async: Synchronous
 *                Reentrancy: Reentrant
 *                Available via: IntCtrl_Lld.h
 *
 * @param[in] IrqNumber Interrupt number for which the pending flag is
 *                      set.
 * @return No return value.
 */
void IntCtrl_Lld_SetPending(IRQn_Type IrqNumber);

/**
 * @brief         Gets the pending flag status for an interrupt request.
 *                This function retrieves the pending interrupt status
 *                from the NVIC to determine if the interrupt is pending.
 * @autosar       N/A
 *
 * @details       Service ID: N/A
 *                Sync/Async: Synchronous
 *                Reentrancy: Reentrant
 *                Available via: IntCtrl_Lld.h
 *
 * @param[in] IrqNumber Interrupt number for which the pending flag
 *                      status is retrieved.
 * @return boolean      Returns TRUE if the pending flag is set; FALSE
 *                      if the pending flag is cleared.
 */
boolean IntCtrl_Lld_GetPending(IRQn_Type IrqNumber);

/**
 * @brief         Gets the active flag status for an interrupt request.
 *                This function retrieves the active interrupt status
 *                from the NVIC to determine if the interrupt is
 *                currently being serviced.
 * @autosar       N/A
 *
 * @details       Service ID: N/A
 *                Sync/Async: Synchronous
 *                Reentrancy: Reentrant
 *                Available via: IntCtrl_Lld.h
 *
 * @param[in] IrqNumber Interrupt number for which the active flag
 *                      status is retrieved.
 * @return boolean      Returns TRUE if the active flag is set
 *                      (interrupt is being serviced); FALSE if the
 *                      active flag is cleared.
 */
boolean IntCtrl_Lld_GetActive(IRQn_Type IrqNumber);

#endif /* INT_CTRL_LLD_STANDALONE_APIS*/

#if ((INT_CTRL_LLD_MSCM_SYSTEM_INTERRUPT_ROUTER == STD_ON) && (INT_CTRL_LLD_ROUTING_CONTROL_REGISTER == STD_ON))
/**
 * @brief         Sets the target cores for an interrupt request in
 *                multi-core systems. This function configures which CPU
 *                cores should receive the interrupt by writing to the
 *                MSCM interrupt routing control registers (IRSPRCx).
 * @autosar       N/A
 *
 * @details       Service ID: N/A
 *                Sync/Async: Synchronous
 *                Reentrancy: Non Reentrant
 *                Available via: IntCtrl_Lld.h
 *
 * @param[in] IrqNumber   Interrupt number for which the target cores
 *                        are configured.
 * @param[in] TargetCores Bit mask defining the target CPU cores. The
 *                        encoding format matches the MSCM IRSPRCx
 *                        register definition, where each bit represents
 *                        a target core.
 * @return No return value.
 */
void IntCtrl_Lld_SetTargetCores(IRQn_Type IrqNumber, uint8 TargetCores);
#endif

#if defined(__cplusplus)
}
#endif /* __cplusplus*/

#endif /* INTCTRL_LLD_H_ */

/** @} */

