Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training




Loading

How should xQueueSendFromISR and xQueueReceive be used?

Posted by adissida on September 15, 2015

The example projects I have looked at, its simple. To be more shure and understand the xQueue I have read the manual for it and this video guide https://www.youtube.com/watch?v=8lIpI30Tj-g

This is my code for setting up the interrupt handler:


INTCregisterinterrupt((inthandler)&trvCLIUARTISR, AVR32USART1IRQ, AVR32INTC_INT0);


then from the example project the portENTERSWITCHINGISR is needed:


_attribute((naked)) static void trvCLIUARTISR( void ) { portENTERSWITCHING_ISR();

trvCLI_UART_ISR_Recieve();

portEXIT_SWITCHING_ISR();

}


and at last this function is called after entering switching ISR:


_attribute((noinline)) static portBASETYPE trvCLIUARTISRRecieve( void ) { /* Now we can declare the local variables. */ signed portCHAR cChar = 0; portBASETYPE xHigherPriorityTaskWoken = pdFALSE; unsigned portLONG ulStatus; volatile avr32usartt *usart = trvCLI_USART;

/* What caused the interrupt? */
ulStatus = usart->csr & usart->imr;

if (ulStatus & AVR32_USART_CSR_RXRDY_MASK)
{
	/* The interrupt was caused by the receiver getting data. */
	cChar = usart->rhr; //TODO

	/* Because FreeRTOS is not supposed to run with nested interrupts, put all OS
	calls in a critical section . */
	portENTER_CRITICAL();
		if (xQueueSendFromISR(xRxedChars, &cChar, &xHigherPriorityTaskWoken))
		{
			gpio_tgl_gpio_pin(trvLED_GPS);
		}
	portEXIT_CRITICAL();
}

usart->csr;

/* The return value will be used by portEXIT_SWITCHING_ISR() to know if it
should perform a vTaskSwitchContext(). */
return ( xHigherPriorityTaskWoken );

}


I have a simple task, to watch the xRxedChars queue:


void trvUARTCLIRX( void *pvParameters ) { signed portCHAR receivedChars = 0; uint8_t str[30]; ( void ) pvParameters;

for ( ;; )
{
	if (xQueueReceive(xRxedChars, &receivedChars, comRX_BLOCK_TIME))
	{
		sprintf( str,"%d",receivedChars );
		trvCLI_WriteLine( &str );
	}
}
//vTaskDelete(NULL);

}


As soon as I enter something in the console, everything hangs. If I change the xQueueReceive to xQueueReceiveFromISR it doesent hangs but the value is never copied to receivedChars.

Using ATMEL UC3, FreeRTOS V8.2.2


How should xQueueSendFromISR and xQueueReceive be used?

Posted by heinbali01 on September 15, 2015

From your previous post:

So it has something to do with usart->ier = AVR32USARTIERRXRDYMASK When I delete that line in the code above, it always works (two LEDs blinking)

When you delete that line there won't be any RX interrupt.

Your ISR is indeed masking off bits that have not been enabled:

~~~~~ /* What caused the interrupt? */ ulStatus = usart->csr & usart->imr; ~~~~~

Because FreeRTOS is not supposed to run with nested interrupts, put all OS calls in a critical section portENTERCRITICAL(); if (xQueueSendFromISR(xRxedChars, &cChar, &xHigherPriorityTaskWoken)) portEXITCRITICAL();

I don't think the critical section is necessary. Interrupts are not enabled (by the global flag) until you enable them. And ask your self: will there be another ISR that will try to access your xRxedChars? That shouldn't be.

Note that if you expect lots of data (kilobytes), you better look at other methods like using PDC (DMA) channels.

My guess is that taking away the critical sections will solve the problem.

From trvUART_CLI_RX() you will call xQueueReceive() (without the FromISR), and xQueueReceive() will use critical sections when necessary.

Regards.


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists