/**
*   @file           SysDal_Cfg.c
*   @version        1.0.0
*
*   @brief          Integration Framework - SysDal Abstraction Layer component
*   @details        This file implements the SysDal interface to application layer.
*
*   (c) Copyright 2006-2016 Freescale Semiconductor, Inc. 
*       Copyright 2017-2018 NXP
*   All Rights Reserved.
*   This file contains sample code only. It is not part of the production code deliverables.
*
*/
/*==================================================================================================
*   Platform             : PA
*
*   Autosar Version      : 4.3.1
*   Autosar Revision     : ASR_REL_4_3_REV_0001
*   SW Version           : 1.0.0
*   Build Version        : MPC5777CXG_MCAL_1_0_0_RTM_ASR_REL_4_3_REV_0001_20190318
*
============================================================================================================================*/
/*============================================================================================================================
==============================================================================================================================*/

#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 "SysDal.h"
/*===================================================================================================================
*                              SOURCE FILE VERSION INFORMATION
====================================================================================================================*/
#define SYSDAL_CFG_VENDOR_ID_C                       43

#define SYSDAL_CFG_AR_RELEASE_MAJOR_VERSION_C        4
#define SYSDAL_CFG_AR_RELEASE_MINOR_VERSION_C        3
#define SYSDAL_CFG_AR_RELEASE_REVISION_VERSION_C     1

#define SYSDAL_CFG_SW_MAJOR_VERSION_C                1
#define SYSDAL_CFG_SW_MINOR_VERSION_C                0
#define SYSDAL_CFG_SW_PATCH_VERSION_C                0
#include "Port.h"
#include "Adc.h"
#include "Gpt.h"
#include "Ocu.h"
#include "Pwm.h"
#include "IoDal.h"
#include "SwcRte.h"

#include "sys_init.h"
extern ISR (Gpt_PIT_0_TIMER_0_ISR);
extern ISR (EMIOS_1_CH_0_ISR);
extern ISR (Adc_Eqadc_EqadcACFifo0Empty);
extern ISR (Adc_Eqadc_EqadcARFifo0Full);

FUNC(void, SYSDAL_APP_CODE)SysDal_SetAllProgrammableInterrupts(void)
{
    sys_disableAllInterrupts();
    sys_enableIsrSource(301, 0xe);

    sys_enableIsrSource(59, 0xc);

    sys_enableIsrSource(104, 0xe);

    sys_enableIsrSource(105, 0xe);

    sys_enableAllInterrupts();
}


/**
@brief      SysDal_InitBlockZero - Function used for initialising the system
@details    Shall be used to init module that will not be deinitialised when go to sleep
            
@return     None
*/
FUNC (void, SYSDAL_APP_CODE)SysDal_InitBlockZero(void)
{
    Port_Init(&PortConfigSet_0);
}

/**
@brief      SysDal_InitBlockOne - Function used for initialising the system
@details    Shall be used to init module that will be deinitialised when go to sleep
            Shall be used to invoke callouts used for System initialisation
            
@return     None
*/
FUNC (void, SYSDAL_APP_CODE)SysDal_InitBlockOne(void)
{
    Adc_Init(&AdcConfigSet_0);
    Gpt_Init(&GptChannelConfigSet_0);
    Gpt_EnableNotification(0);
    Ocu_Init(&OcuConfigSet_0);
    Pwm_Init(&PwmChannelConfigSet_0);
    IoDal_Init(&IoDal_Config[0]);
}

void INTAPP_TASK_2(void)
{
    IoDal_MainFunction();
}

void INTAPP_TASK_3(void)
{
    SwcRte_MainRunnable();
}

void INTAPP_PREHOOK_TASK(void)
{
    SwcRte_Init(&SwcRte_AppInstanceMapPB[0]);
}

void INTAPP_TASK_1(void)
{
    SysDal_MainFunction();
}


#ifdef IFWK_USE_WDG
#if (ENABLE_WDG_EXPIRE_TEST == STD_ON)
FUNC (void, SYSDAL_APP_CODE) WdgExpire_Callback(void)
{
    #ifdef SYSDAL_STARTUP_MSG_CHANNEL    
    ComDal_WriteData(SYSDAL_STARTUP_MSG_CHANNEL, "WatchDog EVENT!", 13U);
    #endif    
    SysDal_Wdg_SetMode(WDGIF_SLOW_MODE);
}
#endif 

FUNC(void, SYSDAL_APP_CODE) SysDal_Wdg_SetTriggerCondition(uint16 TimeOut) 
{
     Wdg_SetTriggerCondition(TimeOut);
}
 
#endif  

const SysDal_ConfigType SysDal_Config=
{
    &SysDal_InitBlockZero,
    &SysDal_InitBlockOne,
    &SysDal_SetAllProgrammableInterrupts
#if (SYSDAL_LOW_POWER_MODE == STD_ON)     
    ,
    &SysDal_DeinitBlockOne,
    &SysDal_SetWakeupEvents,
    &SysDal_ClearWakeupEvents
#endif
};

#ifdef __cplusplus
}
#endif
