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




Loading

Sync. between task and isr / binary semaphore

Posted by Jonas Poulsen on September 29, 2011
Hi

I have a question regarding synchronization between a task and an interrupt-routine using xSemaphoreTake and xSemaphoreGiveFromISR(…, …). My semaphore is created using the vSemaphoreCreateBinary() wrapper.

Data flow:

My task receives messages with data that are to be sent via. an uart. The uart write routine call the xSemaphoreTake(…,portMAX_DELAY) and triggers the TX interrupt to start sending data. Afterwards the task returns to “listening” for new messages (while the TX interrupt routine is active). After the last byte is sent in the interrupt context the xSemaphoreGiveFromISR() routine is called.

The idea is, that if a new messages arrives to the task while we still are transmitting data, the task will be suspended until the xSemaphoreGiveFromISR() is called from the interrupt routine.


Unfortunately this seems to crash my system and I cannot figure out why. Have I misunderstood the properties of the binary semaphore? Is it not possible to call xSemaphoreTake() multiple times on the binary semaphore to “stall” a task (if the semaphore is already taken)?

Using FreeRTOS 6.0.0 on a NEC 78K0R 1167 @ 14,7 MHz using IAR 4.70.

Br,
Jonas, DK

RE: Sync. between task and isr / binary semaphore

Posted by Richard on September 30, 2011
If I interpret your email correctly, your UART task is doing something like this:

for( ;; )
{
____/* Listen for an incoming message. */
____ListenForUARTMessage();

____/* A message was received. Process it and generate a reply. */
____ProcessMessage();

____/* Wait until previous Tx has completed. */
____xSemaphoreTake( ... );

___/* Send generated reply. */
SendUARTMessage();
}

Is that correct?

That should be ok, provided ListenForUARTMessage() can queue messages up, in case more than one message is received while the task is blocked on xSemaphoreTake().

Have you done the usual things like checking for stack overflows in the tasks?

Regards.

RE: Sync. between task and isr / binary semaphore

Posted by Jonas Poulsen on October 12, 2011
Hi

As it turned out, it was my lazy programming, rather than an errored FreeRTOS, that was to blame for my problem. I actually re-programmed the UART hardware whilst transferring data (due to the new data transfer request) – this for some reason crashes the system. Back to reading the uC UserGuide I guess…


Br,
Jonas, DK

RE: Sync. between task and isr / binary semaphore

Posted by Samuel on October 14, 2011
I your Tx ISR; do you use "taskYIELD_FROM_ISR(xHigherPriorityTaskWoken)" after xSemaphoreGiveFromISR(…, …) ?


[ 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