/*==================================================================================================
* Project : RTD AUTOSAR 4.7
* Platform : CORTEXM
* Peripheral : S32K3XX
* Dependencies : none
*
* Autosar Version : 4.7.0
* Autosar Revision : ASR_REL_4_7_REV_0000
* Autosar Conf.Variant :
* SW Version : 4.0.0
* Build Version : S32K3_RTD_4_0_0_D2311_ASR_REL_4_7_REV_0000_20231128
*
* Copyright 2020 - 2023 NXP
*
* NXP Confidential. This software is owned or controlled by NXP 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.
==================================================================================================*/

/**
*   @file main.c
*
*   @addtogroup main_module main module documentation
*   @{
*/

/* Including necessary configuration files. */
#include "Mcal.h"
#include "Siul2_Dio_Ip.h"
#include "Siul2_Port_Ip.h"
#include "Clock_Ip.h"
#include "CDD_Rm.h"

void TestDelay(uint32 delay);
void start_core_cm7_2(void);




/*******************************************************************************
 * TestDelay
 *******************************************************************************/
void TestDelay(uint32 delay)
{
	static volatile uint32 DelayTimer = 0;
	while(DelayTimer < delay)
	{
		DelayTimer++;
	}
	DelayTimer = 0;
}

void start_core_cm7_2(void){

	IP_MC_ME->PRTN0_CORE4_ADDR = (uint32)0x00800000;
	IP_MC_ME->PRTN0_CORE4_PCONF = 0x00000001;
	IP_MC_ME->PRTN0_CORE4_PUPD = 0x00000001;
	IP_MC_ME->CTL_KEY = 0x5AF0U;
	IP_MC_ME->CTL_KEY = 0xA50FU;
	while (IP_MC_ME->PRTN0_CORE4_PUPD == 1) { };
	while ((IP_MC_ME->PRTN0_CORE4_STAT & MC_ME_PRTN0_CORE4_STAT_CCS_MASK) == 0) { };
}
volatile int exit_code = 0;

uint16 counter = 0;
/* User includes */

/*!
  \brief The main function for the project.
  \details The startup initialization sequence is the following:
 * - startup asm routine
 * - main()
*/
int main(void)
{
    /* Write your code here */
    /* Initialize all pins using the Port driver */
    /* Initialize RM CDD */
	//Rm_Init(NULL_PTR);

	    Clock_Ip_StatusType Status_Init_Clock = CLOCK_IP_ERROR;
	    Status_Init_Clock = Clock_Ip_Init(Clock_Ip_aClockConfig);

	    if (Status_Init_Clock != CLOCK_IP_SUCCESS)
	    {
	        while(1); // Error during initialization.
	    }

    Siul2_Port_Ip_PortStatusType Status_Init_Port = SIUL2_PORT_ERROR;
    Status_Init_Port = Siul2_Port_Ip_Init(NUM_OF_CONFIGURED_PINS_PortContainer_0_BOARD_InitPeripherals, g_pin_mux_InitConfigArr_PortContainer_0_BOARD_InitPeripherals);

    if(Status_Init_Port != SIUL2_PORT_SUCCESS)
    {
        while(1); /* Error during initialization. */
    }

	while(1)
	{
		if(counter == 4){
#if USE_RTD_POWER_IP
		    Power_Ip_SetMode(&Power_Ip_aModeConfigPB[0]);
#else
			start_core_cm7_2();
			//counter++;
#endif
		}
		else{
			counter++;
		}
		Siul2_Dio_Ip_WritePin(MCU_INDICATOR_PORT, MCU_INDICATOR_PIN, 1U);
		TestDelay(4800000);
		Siul2_Dio_Ip_WritePin(MCU_INDICATOR_PORT, MCU_INDICATOR_PIN, 0U);
		TestDelay(4800000);
	}
    for(;;)
    {
        if(exit_code != 0)
        {
            break;
        }
    }
    return exit_code;
}

/** @} */
