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

Missing bytes when using queues

Posted by kaarebach on January 16, 2015

Hi

I have a very simple UART application, which I have ported from another RTOS to FreeRTOS. But now I got problems:

very simple task: - In my UART RX interrupt, i send byte to a queue. - In a task, I read the bytes from the queue.

ISR:

// Read byte from UART: u8UARTData = UARTReceiveByte(UART);

// Send the byte to the queue: xQueueSendToBackFromISR(xByteQueue, &u8UART_Data, &xHigherPriorityTaskWoken );

In my receiving task, I wait for a byte in the queue:

xQueueReceive( xByteQueue, &u8Receivedbyte, portMAXDELAY );

Extremely simple...

My problem is that I sometimes looses a byte. Not many, but maybe 1 out of 10.000.

The ISR receives EVERY bytes sent to it. But when reading the queue, some bytes are missing.

By mistake, I used the NON-ISR xQueueSendToBack in the first version. When using this, I never lost any bytes, but entered HardfaultHandler once in a while.

Anyone knows why I loose bytes between xQueueSend and xQueueReceive?

thanks in advance!

br Kaare


Missing bytes when using queues

Posted by rtel on January 16, 2015

Do you check the return value of xQueueSendToBackFromISR()? If it returns pdFALSE then the queue was full.

Also, do you call portYIELDFROMISR( xHigherPriorityTaskWoken ) (or portENDSWITCHINGISR( xHigherPriorityTaskWoken ) - depending on the port) at the end of your interrupt handler. If not then adding it may allow the receiving task to drain the queue sooner.

Generally it is not recommended to use a queue to send every received byte unless the data is very slow (like typed characters from a keyboard, as an example). It will be more efficient to store received bytes in a RAM buffer, then use a semaphore (or task notification in V8.2.0) to unblock a task when there is a whole message that needs processing.

Regards.

Attachments

alternate (1502 bytes)

Missing bytes when using queues

Posted by kaarebach on January 16, 2015

Thanks for quick response!

I send 35 characters every second, so the data amount is very small. It is not typed, but, still, i should be able to handle them

My interrupt never misses a character, and my queue is never full (set to 100 bytes length). When I check the queue free size, there are never more than 5 characters in the queue.

I know it is not the most efficient way to do it, but it should be OK with this amount of data.

portYIELDFROMISR and portENDSWITCHINGISR are not available. Only portYIELD is.

br Kaare

Attachments

alternate (1502 bytes)

Missing bytes when using queues

Posted by davedoors on January 16, 2015

portYIELDFROMISR and portENDSWITCHINGISR are not available. Only portYIELD is.

which port are you using?

Attachments

alternate (1502 bytes)

Missing bytes when using queues

Posted by kaarebach on January 16, 2015

I have added this:

vPortYield();

And I have received more than 70.000 bytes without any missed bytes :o)

I am using V8.0.1 with Rowley / GCC on an LPC1788

Attachments

alternate (1502 bytes)

Missing bytes when using queues

Posted by rtel on January 16, 2015

On that chip the expected way of doing this would be to add

portENDSWITCHINGISR( xHigherPriorityTaskWoken ).

Alternatively you can expand the macro yourself and add

if( xHigherPriorityTaskWoken != pdFALSE ) { vPortYield(); }

Attachments

alternate (1502 bytes)

Missing bytes when using queues

Posted by kaarebach on January 16, 2015

portENDSWITCHINGISR() is not available. Should I include something, or enable something in the config file? I can't find anything in the reference manual.

Your alternative seems to work OK until now.

Attachments

alternate (1502 bytes)

Missing bytes when using queues

Posted by rtel on January 16, 2015

portENDSWITCHINGISR() is defined in portmacro.h, so should be available if you have included FreeRTOS.h at the top of the file.

Attachments

alternate (1502 bytes)

Missing bytes when using queues

Posted by kaarebach on January 16, 2015

Ah, yes it is. I think I'm getting a bit tired :o)

It also works with this, so I am happy, and can close this week with a little succes!

Thanks for your help!

br Kaare

Attachments

alternate (1502 bytes)


[ 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