UART IRQ using Queue example

Hai every one iam new to RTOS and dont know how to use queue inside IRQ Handler i searched in web for sample programs.I could not find one can any one help me with some sample code for queue inside irq

UART IRQ using Queue example

If you look at the demos that are distributed with FreeRTOS, there are examples of using queue inside of Interrupt handlers. For example, the serial ports in the demos run based on using a queue. The biggest thing to remember is that inside an Interrupt handler, you should only call FreeRTOS functions that end in FromISR, and none of these functions will offer the opertunity to ‘block’ for something, as ISRs shouldn’t want to wait. That means you need to decide what to do if you have data to put into a queue, but the queue is full.

UART IRQ using Queue example

Hi Thank you for your response. Can you help me with providing the exact link for that bcs i could not find the correct one. i have tried with some example in web but it was not working the program get struck insid the queue loop. Below i have attached my sample code

UART IRQ using Queue example

There are LOTS of demos provide in the FreeRTOS download, organzed by compiler and processor. Since you haven’t said what processor or compiler you are using, we can’t tell you which one is most appropriate. Most of them will have a serial ISR that sends data to a task via a queue.

UART IRQ using Queue example

Yes i have tried using the some example but i can’t able to achive it… when i send some data to the uart it get struck into the queue function.

UART IRQ using Queue example

UART IRQ using Queue example

What does ‘getting stuck’ mean? My immediate thought is that your interrupt priorities are wrong resulting in you hitting an assert(), but you are really going to have to provide more information. Looking at your code though, I do notice you are creating a queue that will hold 4-byte types, and then trying to post 1-byte types – that will cause 3-bytes of junk to be posted to the queue each time and accessing that junk may cause issues. Also, although many of the demos use a queue to send individual bytes out of an ISR that is really done just to stress the system as a test as it is not very efficient – you would be better off using a stream buffer which is much lighter weight.

UART IRQ using Queue example

Getting struck mean the code get into some loop and not exiting from that loop. i have tried by change the queue size also but not getting the output

UART IRQ using Queue example

IF it is stuck in a loop inside the ISR, then likely you have hit an assert in the code because something is setup wrong, the most likely issue is the priority of the interrupt is impropper. Can you use a debugger and see what the loop is, and what caused it?

UART IRQ using Queue example

i cant able to enter into the debugging mode if upoaded the code and enter into the debugging it is giving internal command error and it is only for that code for other codes it is working fine.some time it is entering at that time if the code struct and when i stopped it the code stops inside hardfault handler

UART IRQ using Queue example

Hi i have some how managed tried to open debug mode and entered into it. when iam checking it the code struck into the function name vPortValidateInterruptPriority and not comming out of it can you help me to solve this i have attached the code and screenshort below.

UART IRQ using Queue example

That likely says your Intterupt has been assigned an invalid interrupt priority. FreeRTOS tends to reserve a few very high priority levels for ISRs that don’t need to use FreeRTOS and that FreeRTOS won’t impact with critical sections (This is dependent on what processor and what port for that processor you are using). Some processors default interrupts to the absolute highest priority, which would not be valid to be used with FreeRTOS. You may need to expicitly set the interrupt priority before you enable the interrupt.

UART IRQ using Queue example

Iam using STM32F429IGTx microcontroller it has max 15 priority levels.In my FreeRTOS congig i have given max priority of 5

UART IRQ using Queue example

And if you don’t explicitly assign the priority it will default to priority 0, which is higher than 5.

UART IRQ using Queue example

For system UART Irq i have given the priority 8 and rtos priority as 10 so RTOS will have the highest priority even though i am geting the same issue .

UART IRQ using Queue example

Please familiarise yourself with all the information on this page: https://www.freertos.org/RTOS-Cortex-M3-M4.html

UART IRQ using Queue example

From this i came to understand that configMAXSYSCALLINTERRUPT_PRIORITY should have high priority than other system NVIC piriority is it so…

UART IRQ using Queue example

Your comprehension is perhaps lacking then. configMAXSYSCALLINTERRUPT_PRIORITY is a informational define to tell FreeRTOS what the highest priority (lowest value) interupt the user application will use to call FreeRTOS, and that it should not expect calls from/and not block execution of interrupt with a Higher Priority. The only interrupt priority that FreeRTOS itself will use are configKERNELINTERRUPTPRIORITY which is used as the default for the system timer tick and is used for the scheduler service interrupt to force a task swap.

UART IRQ using Queue example

Even i configure kernal priority as high and system priority low having the same issue my code stops inside vPortValidateInterruptPriority() function

UART IRQ using Queue example

Make sure you are using a recent version of FreeRTOS, at least 10.1.1 or higher as recent versions have more assert points, and that you have configASSERT() defined, then run the code, stop the debugger, see where you are. If you are in an assert let us know which assert you are in.

UART IRQ using Queue example

I have update to latest FreeRTOS version 10.2.1 and tried to run my program but at the starting of the code itself it getting into SVC_Handler

UART IRQ using Queue example

The SCV interrupt handler is not installed. Search for vPortSVCHandler on this page: https://www.freertos.org/FAQHelp.html

UART IRQ using Queue example

Thank you It solved my Issue now Queue from ISR is working good..and my issue gets solved… Need another help from my project regarding queue now using queue inside ISR it sends data to queue by single char is there is any other way to send the total string to the queue..

UART IRQ using Queue example

There is also the StreamBuffer interface, which lets you put an arbitrary number of characters (still limited by the size of the buffer) at a time, and the MessageBuffer which puts a variable length message (which is retreived as a whole block). The StreamBuffer interface may be what you are looking for.

UART IRQ using Queue example

Can you provide me any sample or example program or link using c it will be more usefull for me

UART IRQ using Queue example

On 5/26/2019 11:37 PM, Akash wrote:
Can you provide me any sample or emple program or link it will be more usefull for me
https://www.google.com/search?q=freertos+stream+buffers+interrupt

UART IRQ using Queue example

Hi, I have read about the stream buffer in freeRTOS but one thing not getting clear. In-stream buffer only one data can be stored or we can able to store more than one data like a queue. Is stream buffer can be used as a queue, or we can push the data from stream buffer to queue. My objective is to receive data from the UART and put it inside a queue because i don’t need to miss any data receiving from the UART while using queue inside ISR I can able to fill only single-single byte but I need to store more than one byte in one queue location and receive the data from the queue location, not as a single-single byte. Is there is any other way for this operation to be performed?

UART IRQ using Queue example

A stream buffer is created with a size that indicates how many bytes of data it can hold, which can be inserted or read in one big chunk or multiple smaller chunks. You can sort of think of a stream buffer as a queue that allows the inserting/removing of a variable nuber of bytes at a time. The basic stream buffer is really designed for sending amorphous character data from one source to one sync.(The Message Buffer builds on this base protocal to send a variable sized message chunk from a sender to a receiver by imposing structhre to the byte stream). A Queue can also store multiple bytes if you make the queue larger. With a queue you provide 2 parameters to control its size, one is the size of each thing put in (which would be 1 for a character) and the second is how many of them it can hold. (For Stream Buffers, the size of the chunck is I beleive always a single byte), The ISR can insert multiple bytes into the queue, it just needs to add them one at a time. A Uart ISR could easily have a loop to insert multiple bytes into the queue, and the receiver can have a loop to retrieve multiple bytes from the queue. The Stream Buffer might be a bit more efficient for this as you need to make just a single call to transfer multiple bytes, so there is less overhead. You say you need to store more than one byte IN A SINGLE LOCATION, which can not work, as a single location can only store a single character. You can store multiple bytes in multiple locationas within a single queue (up to its size)