FreeRTOS : Issue with switching between 2 Tasks and usage of vTaskDelay().

mansoor wrote on Friday, November 15, 2019:

Hi,

CASE 1:

i am using vTaskDelay() to put the Task in Blocked state for some Time.
while using vTaskDelay() its entering into the infinite delay state.
The control is not coming out of the delay statement.

following is the code flow, where vTaskDelay() is been used in both CADENCE and SYNOPSYS.
int Count;
int main()
{
xTaskCreate (test_delay ); /create a task ( test_delay)/
vTaskStartScheduler();
}

void test_delay()
{
while(1)
{
Count++;
printf(“Task running iter %d\n”,Count);
vTaskDelay(1);
}
}

• Here the expected result is the printf() should print the statement infinte times
but it is printing only once in both Cadence and synopsys.
• In cadence it is showing as Stack Overflow stopping…

CASE 2:
i am trying to communicate betweeen the 2 Tasks,
if Task1 is sending Task2 should receive.
Task2 again will send the data to Task1 and Task1 should Receive Data.

following is the code flow which i have tested in cadence but it is not working in the synopsys.

int main()
{

 xTaskCreate (send_Task);  /*created a send task */ 
 xTaskCreate(Receive_Task);/*created a receive task */ 
 vTaskStartScheduler();

}

void send_Task()
{
while(1)
{
xMessageBufferSend(Data_1);
vTaskDelay(1);
//taskYIELD();
xMessageBufferReceive(Data_2);
}

}
void Receive_Task()
{
while(1)
{
xMessageBufferReceive(Data_1);
xMessageBufferSend(Data_2);
}
}

• Here i am expecting after executing Task2 should switch back to Task1 which is not happenning.
• i tried increasing the priority of the send_Task also but it is not working.
• i used taskYIELD() function, it is executing the next task2 of same priority but after executing it is not Resuming back to the task.
• if i remove the vTaskDelay() only Task1 will execute continously.

      Is there any property settings that has to be changed based on the platform we are using to get this working.
      presently we are working on synopsys. 

Thanks and Regards,
Mansoor Basha

rtel wrote on Friday, November 15, 2019:

• In cadence it is showing as Stack Overflow stopping…

Did you try increasing the stack size? The stack allocated to a task is
one of the parameters passed into the xTaskCreate() function
This page describes the RTOS xTaskCreate() FreeRTOS API function which is part of the RTOS task control API. FreeRTOS is a professional grade, small footprint, open source RTOS for microcontrollers. . There are also some utility
functions you can use to monitor the task’s stack usage so you know if
you allocate too much or too little.

CASE 2:
i am trying to communicate betweeen the 2 Tasks,
if Task1 is sending Task2 should receive.
Task2 again will send the data to Task1 and Task1 should Receive Data.

following is the code flow which i have tested in cadence but it is not
working in the synopsys.

int main()
{

xTaskCreate (send_Task); /*created a send task */
xTaskCreate(Receive_Task);/*created a receive task */
vTaskStartScheduler();

}

void send_Task()
{
while(1)
{
xMessageBufferSend(Data_1);
vTaskDelay(1);
//taskYIELD();
xMessageBufferReceive(Data_2);
}

}
void Receive_Task()
{
while(1)
{
xMessageBufferReceive(Data_1);
xMessageBufferSend(Data_2);
}
}

• Here i am expecting after executing Task2 should switch back to Task1
which is not happenning.

Please post the complete function calls as without being able to see the
priorities you are using or the block times you are using I don’t know
the expected behaviour.

richard_damon wrote on Friday, November 15, 2019:

My first guess is that your Tick Timer isn’t working, and the system isn’t seeing time move forward, so the delays are never satisifed.

It would be helpful to know what processor you are building this on.

richard_damon wrote on Friday, November 15, 2019:

My first guess is that your Tick Timer isn’t working, and the system isn’t seeing time move forward, so the delays are never satisifed.

It would be helpful to know what processor you are building this on.

mansoor wrote on Monday, November 18, 2019:

ARCEM9D

Thanks for the Reply.
Mansoor Basha

mansoor wrote on Monday, November 18, 2019:

Project file and screenshots are attached here. one screenshot is the Result in cadence and the same result is expected in synopsys also but it is not switching back to the task1 to get the correct Result.

mansoor wrote on Wednesday, November 20, 2019:

Hi,

  [SYNOPSYS SWITCHING RELATED ISSUE SOLVED].
         if i increase the Stack Size of the parameter passing to xTaskCreate the switching of the Tasks is working fine now. 
   
  [SYNOPSYS vTaskDelay() ISSUE NOT SOLVED].
           but without vTaskDelay() it is working, if i include vTaskDelay() it is not working bcz the functionality of vTaskDelay() may be enetering into infinite condition.

richard_damon wrote on Wednesday, November 20, 2019:

If increasing the stack size fixes things, then likely your issue is memory corruption causes by over running the stack. If that is happening, basically don’t try to figure out what is happening, but just fix the stack issue.

You probably should also enable stack checking, at least during early debugging to confirm that stacks are big enough (it may slow down things enough that you don’t want to use it in production, but it is good to check things at first.)

mansoor wrote on Thursday, November 21, 2019:

Hi,

  As i am trying to make vTaskDelay() functionality working. i am not able to understand what is the problem in this case. as i got reply that Tick Timer isn't working, how to make this Tick Timer working. in SYNOPSYS (ARCEM9D)
  Screenshot (62)= Result with vTaskDelay(1)
  Screenshot (63)= Result without vTaskDelay(1)

CASE 1:

i am using vTaskDelay() to put the Task in Blocked state for some Time.
while using vTaskDelay() its entering into the infinite delay state.
The control is not coming out of the delay statement.

following is the code flow, where vTaskDelay() is been used in both CADENCE and SYNOPSYS.
int Count;
int main()
{
xTaskCreate (test_delay ); //create a task ( test_delay)//
vTaskStartScheduler();
}

void test_delay()
{
while(1)
{
Count++;
printf(“Task running iter %d\n”,Count);
vTaskDelay(1);
}
}

• Here the expected result is the printf() should print the statement infinte times
but it is printing only once in synopsys.