Quality RTOS & Embedded Software

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


Counting Semaphore Loses Count???

Posted by sfalias on March 11, 2015


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?



Counting Semaphore Loses Count???

Posted by rtel on March 11, 2015

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


Counting Semaphore Loses Count???

Posted by sfalias on March 11, 2015

Hi, sure. I didn't think it was important, but hey, if I knew what was going on I wouldn't have posted.


PIC32MX460, 470 and 575.



Counting Semaphore Loses Count???

Posted by rtel on March 11, 2015

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


Counting Semaphore Loses Count???

Posted by sfalias on March 11, 2015

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!



[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]

Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.

Free TCP/IP and file system demos for the RTOS

Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

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

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

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

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists