Using Queue and Semaphore (from ISR)

Hello,
I have two tasks prvTxTask and prvRxTask with the same priority tskIDLE_PRIORITY + 2.
Each second prvTxTask send a string to prvRxTask using queue, they work well.

I have one more task vTask_Video_DMA_App with a priority less than the others have. Below te code in short form

int main(void){
	if(xTaskCreate( 	prvTxTask, ( const char * ) "Tx", 2*configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 2, &xTxTask ) != pdPASS)
	{
		xil_printf("Tx Task was not created\r\n");
		for(;;);
	}

	if(xTaskCreate( prvRxTask, ( const char * ) "GB", 2*configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 2, &xRxTask ) != pdPASS)
	{
		xil_printf("Rx Task was not created\r\n");
		for(;;);
	}

	if( xTaskCreate( vTask_Video_DMA_App, ( const char * ) "VDMA", 2*configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 2, &xHandler_VDMA ) != pdPASS )
	{
		xil_printf("VDMA Task was not created\r\n");
		for(;;);
	}

	xQueue = xQueueCreate( 	4,sizeof( HWstring ) );
	configASSERT( xQueue );

	vTaskStartScheduler();
	for( ;; );
}

static void prvTxTask( void *pvParameters )
{
	const TickType_t x1second = pdMS_TO_TICKS( DELAY_1_SECOND );
	xil_printf("Tx Task started\r\n");
	for( ;; )
	{
		/* Delay for 1 second. */
		vTaskDelay( x1second );

		if(xQueueSend( xQueue, HWstring, 0L )){
			xil_printf("xQueueSend\r\n");
		}else{
			xil_printf("Tx waiting\r\n");
		}

	}
}

static void prvRxTask( void *pvParameters )
{
	char Recdstring[15] = "";
	const TickType_t x1second = pdMS_TO_TICKS( DELAY_1_SECOND );

	xil_printf("Rx Task started, period tick: %d\r\n",x1second);
	for( ;; )
	{
		if(xQueueReceive( xQueue,	Recdstring, portMAX_DELAY ))	/* portMAX_DELAY: Wait without a timeout for data. */
		{
			xil_printf( "Rx task received string from Tx task\r\n", Recdstring );
		}
	}
}

And here the code for the tasks and task call back function for interruptions that happends each 33 ms aprox. In the call back function i added a counter in such way the the interruption happens slowly 1 second aprox.

void vTask_Video_DMA_App(void *args){

	SemVDMAWr = xSemaphoreCreateBinary();

	for(;;){
		
		if( xSemaphoreTake( SemVDMAWr, portMAX_DELAY) == pdTRUE ){
			xil_printf("Write\r\n");
		}
	}
}

static void WriteCallBack(void *CallbackRef, u32 Mask)
{
	static BaseType_t xHigherPriorityTaskWoken2 = pdFALSE;
	static int counterTx = 0;

	xHigherPriorityTaskWoken2 = pdFALSE;
	counterTx++;

	if(counterTx > 30){
		counterTx = 0;
		xSemaphoreGiveFromISR(SemVDMAWr, &xHigherPriorityTaskWoken2);
	}
	portYIELD_FROM_ISR( xHigherPriorityTaskWoken2);
}

As a result , in vTask_Video_DMA_App if i set xSemaphoreTake( SemVDMAWr, 0), all tasks start to run, but only vTask_Video_DMA_App works continuously, it seems that prvTxTask is always suspended, but if i set xSemaphoreTake( SemVDMAWr, portMAX_DELAY) or wait time different than zero , everything is stopped with the message “HALT: Task VDMA overflowed its stack”
I show it in the picture:

I hope you could tell me what i am missing, or what is the best way make all three task work?
Thanks in advanced

my FreeRTOSConfig.h is :


#ifndef _FREERTOSCONFIG_H
#define _FREERTOSCONFIG_H

#include "xparameters.h" 

#include "bspconfig.h" 

#define configUSE_PREEMPTION 1

#define configUSE_MUTEXES 1

#define INCLUDE_xSemaphoreGetMutexHolder 1

#define configUSE_RECURSIVE_MUTEXES 1

#define configUSE_COUNTING_SEMAPHORES 1

#define configUSE_TIMERS 1

#define configUSE_IDLE_HOOK 0

#define configUSE_TICK_HOOK 0

#define configUSE_DAEMON_TASK_STARTUP_HOOK 0

#define configUSE_MALLOC_FAILED_HOOK 1

#define configUSE_TRACE_FACILITY 1

#define configUSE_NEWLIB_REENTRANT 0

#define configSTREAM_BUFFER 0

#define configMESSAGE_BUFFER 0

#define configSUPPORT_STATIC_ALLOCATION 0

#define configUSE_16_BIT_TICKS 0

#define configUSE_APPLICATION_TASK_TAG 0

#define configUSE_CO_ROUTINES 0

#define configTICK_RATE_HZ (100)

#define configMAX_PRIORITIES (8)// default : 8

#define configMAX_CO_ROUTINE_PRIORITIES 2

#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 200)

#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 65536 ) )

#define configMAX_TASK_NAME_LEN 10

#define configIDLE_SHOULD_YIELD 1

#define configUSE_TIME_SLICING 1

#define configTIMER_TASK_PRIORITY (configMAX_PRIORITIES - 1)

#define configTIMER_QUEUE_LENGTH 10

#define configTIMER_TASK_STACK_DEPTH ((configMINIMAL_STACK_SIZE) * 2)

#define configASSERT( x ) if( ( x ) == 0 ) vApplicationAssert( __FILE__, __LINE__ )

#define configUSE_QUEUE_SETS 1

#define configUSE_TASK_NOTIFICATIONS 1

#define configCHECK_FOR_STACK_OVERFLOW 2

#define configUSE_TASK_FPU_SUPPORT 2

#define configQUEUE_REGISTRY_SIZE 10

#define configUSE_STATS_FORMATTING_FUNCTIONS 1

#define configNUM_THREAD_LOCAL_STORAGE_POINTERS 0

#define configGENERATE_RUN_TIME_STATS 0

#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS()

#define portGET_RUN_TIME_COUNTER_VALUE()

#define configUSE_PORT_OPTIMISED_TASK_SELECTION 1

#define configUSE_TICKLESS_IDLE	0
#define configTASK_RETURN_ADDRESS    prvTaskExitError
#define INCLUDE_vTaskPrioritySet             1
#define INCLUDE_uxTaskPriorityGet            1
#define INCLUDE_vTaskDelete                  1
#define INCLUDE_vTaskCleanUpResources        1
#define INCLUDE_vTaskSuspend                 1
#define INCLUDE_vTaskDelayUntil              1
#define INCLUDE_vTaskDelay                   1
#define INCLUDE_eTaskGetState                1
#define INCLUDE_xTimerPendFunctionCall       1
#define INCLUDE_pcTaskGetTaskName            1
#define INCLUDE_xTaskGetHandle               1
#define portPOINTER_SIZE_TYPE	uint32_t
#define portTICK_TYPE_IS_ATOMIC 1
#define configMESSAGE_BUFFER_LENGTH_TYPE uint32_t
#define configSTACK_DEPTH_TYPE uint32_t
#define configMAX_API_CALL_INTERRUPT_PRIORITY (18)// default: 18

#define configINTERRUPT_CONTROLLER_BASE_ADDRESS         ( XPAR_PS7_SCUGIC_0_DIST_BASEADDR )
#define configINTERRUPT_CONTROLLER_CPU_INTERFACE_OFFSET ( -0xf00 )
#define configUNIQUE_INTERRUPT_PRIORITIES                32
void vApplicationAssert( const char *pcFile, uint32_t ulLine );
void FreeRTOS_SetupTickInterrupt( void );
#define configSETUP_TICK_INTERRUPT() FreeRTOS_SetupTickInterrupt()

void FreeRTOS_ClearTickInterrupt( void );
#define configCLEAR_TICK_INTERRUPT()	FreeRTOS_ClearTickInterrupt()

#define portSET_INTERRUPT_MASK_FROM_ISR()	ulPortSetInterruptMask()
#define portCLEAR_INTERRUPT_MASK_FROM_ISR(x)	vPortClearInterruptMask(x)
#ifdef FREERTOS_ENABLE_TRACE
#include "FreeRTOSSTMTrace.h"
#endif /* FREERTOS_ENABLE_TRACE */

#endif

You do a pdMS_TO_TICKS(1) in vTask_Video_DMA_App, but have a 100 Hz tick, so that will compute to a ZERO timeout, so will just always keep running and block the other tasks.

Thanks @richard-damon for your fast answer, I changed the the wait time in xSemaphoreTake funtion, but that i got is “HALT: Task VDMA overflowed its stack.”, it is something to do with how fast the interrupts happen?
I updated my question with more details

Hi @JCesar,
The stack is overflowed from HALT: Task VDMA overflowed its stack.. Try enlarge the stack size for this task.

Just update the third parameter while calling xTaskCreate.

	if( xTaskCreate( vTask_Video_DMA_App, ( const char * ) "VDMA", 2*configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 2, &xHandler_VDMA ) != pdPASS )
	{
		xil_printf("VDMA Task was not created\r\n");
		for(;;);
	}

Thank you.

Thanks @ActoryOu for your answer, I increased the stack and the task is not overloaded. However, only VDMA task works, it seems that prvTxTask never cameout fomr vtaskdelay,
if I set the priority for prvTxTask and prvRxTask higher than vTask_Video_DMA_App has, still only vTask_Video_DMA_App works.
But if in prvTxTask i delete the vTaskDelay(), so prvTxTask and prvRxTask work, but vTask_Video_DMA_App doesn’t work. Sorry i didn’t notice that i haven’t added the code for prvTxTask and prvRxTask . I added already the code

As The first question about “HALT: Task VDMA overflowed its stack” was solved, i think i would create a new topic