/*==================================================================================================
* 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 : 6.0.0
* Build Version : S32K3_RTD_6_0_0_D2506_ASR_REL_4_7_REV_0000_20250610
*
* Copyright 2020 - 2025 NXP
*
* NXP Confidential and Proprietary. 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"

volatile int exit_code = 0;
/* User includes */
#include "Clock_Ip.h"
#include "OsIf.h"
#include "Siul2_Port_Ip_Cfg.h"
#include "Siul2_Port_Ip.h"
#include "Siul2_Dio_Ip.h"
#include "Swt_Ip.h"

#include "FreeRTOS.h"
#include "task.h"

#define START_TASK_PRIO 	2 	//任务优先级
#define START_STK_SIZE 		512 //任务堆栈大小

TaskHandle_t StartTask_Handler; //任务句柄

void led_toggle(void)
{
	Siul2_Dio_Ip_TogglePins(LED_PORT, 1 << LED_PIN);
}

void start_task(void *pvParameters) //任务函数
{
	(void)pvParameters;
	static uint32_t period_100ms_counter = 0;

	while(1)
	{
		if(period_100ms_counter == 9)
		{
			// Swt_Ip_Service(0);
		}
		else if(period_100ms_counter == 10)
		{
			led_toggle();
			period_100ms_counter = 0;
		}
		else
		{
			;
		}
		period_100ms_counter++;
		vTaskDelay(100);
	}
}

/*!
  \brief The main function for the project.
  \details The startup initialization sequence is the following:
 * - startup asm routine
 * - main()
*/
int main(void)
{
	Clock_Ip_Init(&Clock_Ip_aClockConfig[0]);

	OsIf_Init(NULL_PTR);

	Siul2_Port_Ip_Init(NUM_OF_CONFIGURED_PINS_PortContainer_0_BOARD_InitPeripherals, g_pin_mux_InitConfigArr_PortContainer_0_BOARD_InitPeripherals);

    /* Write your code here */
	Swt_Ip_Init(0, &Swt_Ip_Cfg0);

	if(xTaskCreate(start_task, "start_task", START_STK_SIZE, NULL, START_TASK_PRIO, &StartTask_Handler) != pdPASS)
	{
//		logError("start task create failed");
	}

	vTaskStartScheduler();

    for(;;)
    {
		vTaskDelay(100);
        if(exit_code != 0)
        {
            break;
        }
    }
    return exit_code;
}

/** @} */
