Quality RTOS & Embedded Software

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




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) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

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

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

OpenRTOS and SafeRTOS