rtos viewer

Hi all,
I am using freertos version 5.4.2 for a project in PIC24FJ256GB110. I used the following code to service the UART interrupt.
void __attribute__((interrupt,no_auto_psv )) _U2RXInterrupt (void)
{
static portBASE_TYPE taskWoken;
taskWoken=pdFALSE;
IFS1bits.U2RXIF=0;
c=U2RXREG;
xQueueSendFromISR(uartqueue, &c, &taskWoken);
} The system seems to work fine for a few minutes and then fails.  When I removed the source of the UART interrupt, the system worked alright. So, I changed the code as follows
void __attribute__((interrupt,no_auto_psv )) _U2RXInterrupt (void)
{
static portBASE_TYPE taskWoken;
taskWoken=pdFALSE;
IFS1bits.U2RXIF=0;
uartrecdval=U2RXREG;
} The system now worked with the UART interrupt well. I don’t understand this behavior. Am I missing something here??. I would appreciate any help, so that I can understand what might be going on here. I also see a plugin in MPLAB IDE called RTOS viewer. Can someone point me to some reading resources on this, so that I can get started on this. Thanks in Advance!!!

rtos viewer

Is the priority of the interrupt set to portKERNEL_INTERRUPT_PRIORITY? If not try changing it to portKERNEL_INTERRUPT_PRIORITY to see if it fixes the problem. Also check the stack sizes of your tasks http://www.freertos.org/Stacks-and-stack-overflow-checking.html.

rtos viewer

One possible issue I see is that you have declared your interrupt handler no_auto_psv, which means that the handler can not access the PSV segment. You then call xQueueSendFromISR which I am not sure if it needs the auto_psv segment. Most of the time the PSV segment will be setup right, and the interrupt will run fine. There may be a few small sections of your program in which the compiler needs to change the PSV segment, if the interrupt occurs there, and xQueueSendFromISR needs to access the PSV segment, then problems will occur. A side note, your interrupt routine is not checking the taskWoken flag, so if a character does arrive, the waiting task will not start up right away, but will need to wait for the next time a task switch happens (like at the next timer tick) before it has a chance to process that character. This may be acceptable for your program.

rtos viewer

Thanks edward and richard for replying… @edward
I have defined
#define configKERNEL_INTERRUPT_PRIORITY 0x01
in the freertosconfig.h file. Is it the same as portKERNEL_INTERRUPT_PRIORITY?? @richard
The problem persisted even when I changed no_auto_psv to auto_psv. So, I am not sure if that was the mistake and yes it is okay for my task to start in the next tick Also, I want to know if there is any material I can look up to use the RTOS viewer plugin in MPLAB. Thanks in advance!!

rtos viewer

If configKERNAL_INTERRUPT_PRIORIRY is set to 1, make sure you have changed the interrupt priority of the interrupt to be 1 also. (Interrupts with a priority high than that are not allowed to call FreeRTOS APIs). As to the documentation of the View Plugin, I know it is in there, I just am not that familiar where. I believe you need to set the option to remove the static qualifications for FreeRTOS locals, enable some tracing options, and it is very helpful to make sure you give each queue a unique name.

rtos viewer

hi richard,
Apologies for a long delay. I got bogged down with another minor project. I have another define in the freertosconfig.h which is
#define configMAX_SYSCALL_INTERRUPT_PRIORITY 0x04 My UART priority is 3. Do you still think I need to make the configKERNEL_INTERRUPT_PRIORITY as 3 or set the UART priority to 1? Thanks!

rtos viewer

From the documentation page for the PIC24 port “Interrupt service routines that can cause a context switch must execute with priority portKERNEL_INTERRUPT_PRIORITY, and only call taskYIELD() at the very end of the service routine after the interrupt source has been cleared. See the file serial.c included in the demo application for an example.” Regards.