vTaskDelay() does not work

Hello there,
I want to create a semaphore, but the vTaskDelay() does not work, I am using the Psoc 6 and my code is below:

/* ========================================
 *
 * Copyright YOUR COMPANY, THE YEAR
 * All Rights Reserved
 * UNPUBLISHED, LICENSED SOFTWARE.
 *
 * CONFIDENTIAL AND PROPRIETARY INFORMATION
 * WHICH IS THE PROPERTY OF your company.
 *
 * ========================================
*/
#include "FreeRTOS.h"
#include "project.h"
#include "task.h"
#include "semphr.h"
#include "queue.h"  



int tempo1 = 0;
bool aberto = 0;



void SINAL_AUTO_1_TASK(void *arg)
{
	for(;;)
	{
        tempo1 = 0;
        aberto = 0;
        //Sign Green Open
		Cy_GPIO_Write(RED_1_PORT, RED_1_NUM, 0);
        Cy_GPIO_Write(YELLOW_1_PORT, YELLOW_1_NUM, 0);
        Cy_GPIO_Write(GREEN_1_PORT, GREEN_1_NUM, 1);
        while(tempo1 < 45){
            vTaskDelay(1000);
        }
       // CyDelay(45000);
        //Sign Yellow Open
        Cy_GPIO_Write(RED_1_PORT, RED_1_NUM, 0);
        Cy_GPIO_Write(YELLOW_1_PORT, YELLOW_1_NUM, 1);
        Cy_GPIO_Write(GREEN_1_PORT, GREEN_1_NUM, 0);
        vTaskDelay(5000);
       // CyDelay(5000);
        
        aberto = 1;
        //Sign Red Open
        Cy_GPIO_Write(RED_1_PORT, RED_1_NUM, 1);
        Cy_GPIO_Write(YELLOW_1_PORT, YELLOW_1_NUM, 0);
        Cy_GPIO_Write(GREEN_1_PORT, GREEN_1_NUM, 0);
        vTaskDelay(50000);
       // CyDelay(5000);
        
	}
}

void SINAL_PEDESTRE_1_TASK(void *arg)
{
    for(;;){    
        Cy_GPIO_Write(RED_P_1_PORT, RED_P_1_NUM, aberto);
    	Cy_GPIO_Write(GREEN_P_1_PORT, GREEN_P_1_NUM, !aberto);
    }		

}

void BOTAO_1_TASK(void *arg)
{
	for(;;){
        if(Cy_GPIO_Read(BOTAO_1_PORT, BOTAO_1_NUM) == 0 && aberto ==0){
            while(tempo1 < 30){
             tempo1++;   
             vTaskDelay(1000); 
 //            CyDelay(1000);
            }
            Cy_GPIO_Write(RED_1_PORT, RED_1_NUM, 0);
            Cy_GPIO_Write(YELLOW_1_PORT, YELLOW_1_NUM, 1);
            Cy_GPIO_Write(GREEN_1_PORT, GREEN_1_NUM, 0);
            vTaskDelay(5000);
            aberto = 1;
            Cy_GPIO_Write(RED_1_PORT, RED_1_NUM, 1);
            Cy_GPIO_Write(YELLOW_1_PORT, YELLOW_1_NUM, 0);
            Cy_GPIO_Write(GREEN_1_PORT, GREEN_1_NUM, 0);
            vTaskDelay(50000);
        }
    }
   
	
}


int main(void)
{
    __enable_irq(); /* Enable global interrupts. */
    //setupFreeRTOS();
    
    xTaskCreate(SINAL_AUTO_1_TASK, //função da task
                "SINAL_AUTO_1_TASK", //Nome da task
                50, //Tamanho da pilha
                NULL, 
                2, //Prioridade
                0);
    
   xTaskCreate(SINAL_PEDESTRE_1_TASK, 
                "SINAL_PEDESTRE_1_TASK", 
                30, //Tamanho da pilha
                NULL, 
                2, 
                0);
    
    xTaskCreate(BOTAO_1_TASK, 
                "BOTAO_1_TASK", //Nome da task 
                50, 
                NULL, 
                2, //Prioridade
                0);
    
	vTaskStartScheduler();

    for(;;)
    {
       
    }
}

/* [] END OF FILE */
indent preformatted text by 4 spaces

Can you please be slightly more specific ? Since vTaskDelay is unrelated to semaphores it’s a bit confusing…

  1. What’s the expected behaviour ?
  2. What’s the actual behaviour ?
    (What does it mean vTaskDelay does not work ? Is your program crashing ? Are the delays longer/shorter than expected ?)
  3. What did you already try to solve the problem ?

And is it intended that SINAL_PEDESTRE_1_TASK(void *arg) is running without any delay ? I guess it’s way too fast to see any LED blinking :wink:

Did you set configUSE_PREEMPTION and configUSE_TIME_SLICING to 1 in your FreeRTOSConfig.h ?

BTW For better readabilty better enclose posted code blocks by 3 backticks ``` or alternatively by starting with ~~~c and ending with ~~~ (for C-code).

Relax. I did it. I solved my problem. Thanks!

That’s good :+1:
And I am relaxed :sunglasses:

1 Like

Pleased you solved the problem. Its always good in these cases if you can also post what the resolution was - that can be helpful to others with a similar issue in the future.

1 Like

Hello, I solved my problem. I clicked in “FreeRTOSConfig.h” and changed the “#define configUSE_TIME_SLICING 0” for “#define configUSE_TIME_SLICING 1” and work perfectly!