Search code examples
embeddedsemaphorertosfreertos

FreeRTOS Semaphore overhead time


First of all I would like to note that I am quite new at the RTOS business.

I am using FreeRTOS on my STM32L151VC arm processor. I am using binary-semaphore to sync between an interrupt and some task (The semaphore state that the DMA has finished its action). Now, The time passed between the command of xSemaphoreGiveFromISR() to the required task being on and running again is about 50[us]. That seems too long to me, isn't it?

I would like to state, that for this test I have used only 1 task (and IDLE task), my cpu clk is 24[MHz]. I have looked on FreeRTOS and StackOverflow web-sites for some answer and didn't find any. I only found a statement that this action should take less then 1[us].

My question is, has anyone encountered a similar problem? Anyone knows how to solve this time overhead problem?

Thanks for all the helpers..


Solution

  • Do you have configUSE_PORT_OPTIMISED_TASK_SELECTION set to 1 in FreeRTOSConfig.h? If so then task selection will be performed using a CLZ instruction, rather than a generic C algorithm, and hence be much faster.

    After giving the semaphore, do you call portEND_SWITCHING_ISR( x ), where x is the value passed out of the semaphore give function? If so then your task switch will happen immediately rather than waiting until the next tick interrupt.

    By the way - for best results - ask FreeRTOS support questions on the FreeRTOS support forum as that is where people who use FreeRTOS every day will be able to give you expert advice

    http://www.freertos.org/FreeRTOS_Support_Forum_Archive/freertos_support_forum_archive_index.html