/*
 * AppTimer.c
 *
 *  Created on: Nov 7, 2025
 *      Author: tummalanr
 */

#include <inttypes.h>
#include "ti_drivers_open_close.h"
#include "ti_board_open_close.h"
#include "FreeRTOS.h"
#include "event_groups.h"
#include <kernel/dpl/TimerP.h>

#include "AppExterns.h"
#include "AppGlobal.h"
#include "BoardInitExtern.h"
#include "ShmDataSyncExterns.h"
#include "CIPCoreExterns.h"


uint64_t Timeout1ms_Timer = 0u;
uint32_t Timeout5ms_Timer = 0u;

struct MyArgs {
    uint32_t arg1;
    uint32_t arg2;
} gMyArgs;


//xxms Timer
AppRET_T App_Timer_Init(void)
{
    int32_t sts = SystemP_FAILURE;

    sts = HwiP_setArgs(&gTimerHwiObj[CONFIG_TIMER0], &gMyArgs);
    if(sts != SystemP_SUCCESS) {

        canmbnposterr |=  MBN_CANCore_IimerInitErr;
        return AppHWTimerCreate_Err;
    }
    TimerP_start(gTimerBaseAddr[CONFIG_TIMER0]);

    return AppRET_OK;
}

//100ms Timer
void App_Timer_Start(void)
{
    TimerP_start(gTimerBaseAddr[CONFIG_TIMER0]);

    return;
}

/*!
 *  <!-- Description: -->
 *
 *  \brief
 *  HW Timer DMTIMER3 5msec Timer expire CallBack
 *   Used for Timeouts manipulation in Application
 *  <!-- Parameters and return values: -->
 *  \param[in]  None.
 *  \return     None.
 */
void App_Timer_CallBack(void *args)
{

    BaseType_t xHigherPriorityTaskWoken;
    BaseType_t xResult = pdFAIL;
    EventBits_t SetuxBits = 0u;


    Timeout1ms_Timer++;

    //DebugP_log("%s [%" PRId64 " ms]\r\n",__func__,(ClockP_getTimeUsec()/1000u));


        /* call timer interrupt service routine */
//        CANFDStack



    if(!(Timeout1ms_Timer % 5u) ) {

        Timeout5ms_Timer++;

    }

}

