Trying to control my state machine cycle time

Hello,

I’m trying to control the time execution of a state machine cycle. For do this i have implemented this code:

adl_tcuTimerSettings_t Config = { { 1, ADL_TCU_TIMER_UNIT_MS }, TRUE };

/* Miliseconds */
static volatile u16 ms=0;  
/* IRQ timer Handler */
s32 timerIRQ;
/* TCU handler */
s32 TCUtimer;
/* Semaphore handle */
static s32 sem_handle=0;

void function1(void)
{
....
....
....
}

void function2(void)
{
....
....
....
}

void function3(void)
{
....
....
....
}

BOOL TimerRSI (adl_irqID_e Source, adl_irqNotificationLevel_e NotificationLevel, adl_irqEventData_t * Data )
{
    /* Check for Timer event */
    /* Case when source is IRQ timer */
    if ( Source == ADL_IRQ_ID_TIMER ){
    	/* Increment MS counter */
        ms++;
        /* I chech if sem_handle is consumed */
        if(FALSE==adl_semIsConsumed(sem_handle))
        {
			/* I consume semaphore */
        	adl_semConsume(sem_handle);
        }
    }
	/* Case when source is not IRQ timer */
	else{
    	/* nothing */
	}
    return TRUE;
}

void TimerInit(void)
{
    /* Initialize data structure */
    ms=(u16)0;
    /* Subscribe the timer interruption */
    timerIRQ = adl_irqSubscribe ( TimerRSI, ADL_IRQ_NOTIFY_HIGH_LEVEL, 0, 0 );
#if TIMER_TIME_UNIT == M_SECONDS
    /* Configure 1ms period interruption */
    adl_tcuTimerSettings_t Config = { { 1, ADL_TCU_TIMER_UNIT_MS }, TRUE };
#endif /* TIMER_TIME_UNIT */
    /* Subscribe RSI with configuration (1ms interruption*/
    TCUtimer=adl_tcuSubscribe ( ADL_TCU_ACCURATE_TIMER, timerIRQ, 0, &Config, NULL );
    /* Enable timer1 and start the count */
    adl_tcuStart ( TCUtimer );
} /* TimerInit */


t_error TimerSync(u16 duration)
{
    t_error result;
    u16 sem_counter;

    /* End cycle synchronization */
    if (ms < cicle_duration) {
        result=ERROR_OK;
		/* I stop in semaphore (ms-cicle duration) ms for be in the state machine during the time that i want */
        sem_counter=(ms)-cicle_duration;
        sem_handle=adl_semSubscribe(sem_counter);
    }
    else {
        result=ERROR_GENERIC;
    }
	ms=0;
	return result;
}

void adl_main()
{
	/*
	Initialitiations...
	*/
	TimerInit();
	
	for(;;)
	{
		/* I call all the functions that i want execute every cicle */
		function1();
		function2();
		function3();
		
		/* I want wait X ms for my cicle duration will be the desired (Y ms) */
		TimerSync( Y );
	}
}

In this code I do initializations and after I execute a loop where I want to execute all the functions of my state machine. At the end of the loop, i put a function for control the cycle duration of my state machine. This function checks if the time consumed by my state machine is lowest that the execution time desired. If this time is lowest, I will call a semaphore with (desired time - consumed time) waits that will be consumed in the TCU interruption. With this mechanism i control the cycle time of my state machine.
But when I try to execute this in my WMP150 i have problems. My WMP 150 don’t work wells and stops. I don’t know if i have problems with the wachtdog. :confused:
Someone can help me? any suspicion :question:

Thanks

Hi,

Please make sure that you have declared the stack size for the low level and high level IRQ handlers.

When you say you have problems, what exactly is the behavior? Are there any exceptions? If possible some logs?

Regards,
Rex