massel74 wrote on Thursday, November 03, 2011:
Currently I’m struggling with the usage of semaphore given from an ISR. My problem is as follow.
There is a gatekeeper task which receives a queue and triggers a SPI burst transfer (via DTC). The data transfer controller issues an interrupt when the transfer has finished. This interrupt gives the semaphore on which the gatekeeper task is waiting for. (gatekeeper in blocked state)
This sounds very easy but unfortunately it doesn’t work on my hardware (Renesas SH7216).
The facts are:
- the interrupt is definitely issued (I’m calling a output toggle funktion in the ISR -> measured with oscilloscope)
- the semaphore is given in the ISR (xSemaphoreGiveFromISR return value is 1, E10A debugger used)
- if I put a wait loop just before the xSemaphoreTake, means try to take the semaphore when the semaphore is already given -> everthing is working fine (but this is not the sense of semaphores
I don’t have no further ideas how to debug this problem. Is there something I should look to to find the problem.
#pragma interrupt INT_RSPI_SPTXI
void INT_RSPI_SPTXI (void)
{
long xHigherPriorityTaskWoken;
extern xSemaphoreHandle xBinarySemaphore_SPITX;
RSPI.SPCR.BIT.SPTIE &= 0; //Transmit interrupt disable
RSPI.SPSR.BYTE &= 0xDF;
xHigherPriorityTaskWoken = pdFALSE;
xSemaphoreGiveFromISR(xBinarySemaphore_SPITX, &xHigherPriorityTaskWoken);
if (xHigherPriorityTaskWoken = pdPASS)
{
portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
}
}
void prvSPIGatekeeperTask( void *pvParameters)
{
xSPIStruct xReceivedStructure;
uint32_t i;
init_rspi();
xSemaphoreTake( xBinarySemaphore_SPIRX, portMAX_DELAY); //take semaphore because initial value is 1
for( ;; )
{
xQueueReceive(xSPIQueue,&xReceivedStructure,portMAX_DELAY); //blocked state until queue entry
setSPIBasefreq(xReceivedStructure.SPIBaseFreq); // set SPI base frequency
SetRSPI_CMD0(xReceivedStructure.SPIcmd); // set SPI command
if(RSPI.SPSR.BIT.MIDLE==1) // if SPI idle
{
//send and receive SPI message
dtc_SPI_io(xReceivedStructure.pDatatoTransmit, xReceivedStructure.pDatatoReceive, xReceivedStructure.cnt_DatatoTransceive);
SetSPIfunction(0xF8); //enable SPI and interrupts
/*for(i=0; i<2000; i++) //if I enable this nop loop everything is working fine because the semaphore
{ // is already given when xSemaphoreTake is reached (not a workaround!!!)
nop();
}*/
xSemaphoreTake( xBinarySemaphore_SPIRX, portMAX_DELAY); //blocked state until SPI interrupt occured
}
}
The Semaphore is created in main funktion with:
vSemaphoreCreateBinary( xBinarySemaphore_SPIRX );
Many thanks in advance.
Martin