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

Issue using the xSemaphoreGiveFromISR() function

Posted by chris-itk on October 29, 2014

Hi to all, I've got a problem regarding the use of the xSemaphoreGiveFromISR() function. I'm using it out of a callback function which is called within an ISR.

I use a binary semaphore as a signal for a completed spi reception. It has to be taken again immediately after it was given by the callback.

The problem is, that the binary semaphore is still "taken" after calling xSemaphoreGiveFromISR(), so my task blocks again.

Do you have any ideas how to fix my problem?

Here's the callback function:

static void SPIHandlerCallback(void) { static signed short xHigherPriorityTaskWoken;

if((0U != u8_SPI_Handler_Is_Initialized))
{
	xSemaphoreGiveFromISR(SPI_Handler_SPI_Signal, &xHigherPriorityTaskWoken);

	portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}
return;

}


Issue using the xSemaphoreGiveFromISR() function

Posted by rtel on October 29, 2014

What does the call to xSemaphoreGiveFromISR() return?

Do you have configASSERT() defined?

Regards.


Issue using the xSemaphoreGiveFromISR() function

Posted by chris-itk on October 29, 2014

Thanks for your answer. No, I have not defined the configAssert().

The return value of xSemaphoreGiveFromISR() is pdPASS.

I debugged inside this routine and it reaches the line:

/* Increment the lock count so the task that unlocks the queue knows that data was posted while it was locked. */ ++( pxQueue->xTxLock );

I'm not absolutely sure, but I think the semaphore is succesfully incremented after this line, isn't it?

But when that's true, why am I blocking the next time I try to take the same semaphore?


Issue using the xSemaphoreGiveFromISR() function

Posted by rtel on October 29, 2014

Could you please post the code where you are receiving/taking the mutex.


Issue using the xSemaphoreGiveFromISR() function

Posted by chris-itk on October 30, 2014

Here I'm doing a take just immediately after starting the spi transfere:

if(pdFALSE == xSemaphoreTake(SPIHandlerSPISignal, (SPIHANDLERSYNCTIMEOUTWAITMS/portTICKRATEMS))) { ret = MDERROR; SPIHandlerSwitchChipselect(SPIDeviceInfo, CS_DISABLE); }

The Semaphore is then given again within my callback routine (Interrupt context): static void SPIHandlerCallback(void) { signed short xHigherPriorityTaskWoken = pdFALSE;

if((0U != u8_SPI_Handler_Is_Initialized))
{
xSemaphoreGiveFromISR(SPI_Handler_SPI_Signal, &xHigherPriorityTaskWoken);
    portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}
return;

}

I found out, that if I don't request a Taskswitch within the Callback, the task comes up again at the next systick, which is after 1ms. But by using portYIELDFROMISR() the task never comes up again. It seems to be a timing problem. If I do it step by step in debugger everything works fine. Maybe there is some kind of race condition (If I wait little, approx. 20┬Ás, after starting the spi-transfere and before trying to take the semaphore, the problem also doesn't occur?


[ 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