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.

Hi not sure if anyone is watching this.
I am also using synosys’ arc, and running into the same issue. I can get two tasks to switch if I uses vTaskDelay(0) in at least one of them. If i use a non zero value in both they stop working and seem to get stuck. I have checked and the timer interrupt seems to be working.

Which FreeRTOS version and which FreeRTOS port are you using?

How did you check that? Did you also check if xTickCount is incrementing?

Which FreeRTOS version and which FreeRTOS port are you using?

FreeRTOS 202210.01 LTS. Port: portable/ThirdParty/GCC/ARC_EM_HS. Support files from GitHub - foss-for-synopsys-dwc-arc-processors/embarc_osp: embARC Open Software Platform (OSP) - An embedded software distribution for IoT and other embedded applications for ARC

How did you check that? Did you also check if xTickCount is incrementing?

I am incrementing a variable every time interrupt is fired and reading that. Yes, xTickCount also increments.

What are the value of configUSE_PREEMPTION and configUSE_TIME_SLICING?

If you put a vTaskDelay(1), the task should unblock on the next tick. Can you step though the xTaskIncrementTick and see what it returns?

configUSE_PREEMPTION 1 configUSE_TIME_SLICING 1
I dont have debugger to step through, I will try to see way of getting that status.

Sorry about the delay, the increment is returning 1. I believe I have figured out the missing piece for the task not switching.
The switch was not happening due to me calling the kernel tick ISR directly instead of using the ARC interrupt entry function, exc_entry_int, that is supposed to wrap the kernel tick and yield from ISR.
But… With this change all tasks seem to be stuck and I dont see any activity. Trying to understand the implementation of exc_entry_int in arc_support.s to see what might be missing.

Any hints are welcome

Can you share the task code, what activity do you expect?

These functions are likely from the vendor SDK and you should try reaching out to them also.

Just as an update, figured out the issue. Interrupt prologue and epilogue wasn’t exactly compatible with my arc processor, I had to change that from handwritten implementation in arc_support.s to compiler generated isr wrapper provided by the arc tool chain. From there just call the rest of the arc_support code.

Thank you for sharing!