Counting Semaphore Loses Count???

Hi, I’m new to FreeRTOS though I have a lot of experience with other RTOSs. I have a serial stream coming into a UART interrupt where the characters are stored in a large buffer. I’m trying to use a counting semaphore to count one particular character, lets call it FLAG, coming in on the UART. For each FLAG, I want to Give the semaphore to a task. In my task, I pend on a Take, then read from buffer until I get FLAG, then I pend for the next Take. This works fine until I send a lot of messages. Eventually, my task hangs on Take. Doing this in a debugger, I can stop and look at my buffer. I can see the last Take stopped at the next to last FLAG, but I can also see the UART received more characters and another FLAG that are sitting in the buffer unread. I tried to dig into FreeRTOS to see if I could find the actual count of the semaphore when a FLAG is in the buffer but the Take doesn’t see it, but all I can find is a void * and don’t know where the count is. I did put in a global counter on Give and Take and I find that Give is always 1 greater than Take when the hang occurs. It appears the Give worked but the Take didn’t see it. At this point I don’t know what else to think other than this is a critical timing issue. Anyone have any ideas on how I might find this problem? Thanks, Dave

Counting Semaphore Loses Count???

To ensure our answer is targetted, please let us know which FreeRTOS port are you using (chip and compiler). Regards.

Counting Semaphore Loses Count???

Hi, sure. I didn’t think it was important, but hey, if I knew what was going on I wouldn’t have posted. V8.1.2 PIC32MX460, 470 and 575. Thanks. Dave

Counting Semaphore Loses Count???

What is the value of configMAXSYSCALLINTERRUPT_PRIORITY in FreeRTOSConfig.h? Have you set the priority of the interrupt to ensure it is at or below the configMAXSYSCALLINTERRUPT_PRIORITY setting? Which method are you using to implement the interrupt? With or without the assembly wrapper? The methods are described on http://www.freertos.org/portPIC32MIPS_MK4.html Maybe not directly related to your question, but if it is always the same task that is being signaled from the interrupt then a task notification will be faster than a counting semaphore: http://www.freertos.org/RTOSTaskNotificationAsCounting_Semaphore.html Regards.

Counting Semaphore Loses Count???

OK, I’m old school. Intuitively (to me), I always make UART ISRs higher priority to avoid dropping characters. But doing that put the UART above configMAXSYSCALLINTERRUPT_PRIORITY. I’ve lowered the UART priority to 3 (same as that macro) and am now testing. So far, 60K+ messages without a failure, 5x more than before. So it appears you’ve found my problem. And so quickly too! THANKS A TON! Dave