biker126 wrote on Monday, October 08, 2007:
hello again guys!
I’m sorry to make a new post again but this is the first time I’m using freeRTOS semaphores and I can’t get them work
I want to synch my SPI Task with the SPI ISR, so that the Task writes a byte, then waits for the semaphore. When the write is done the ISR fires and should release the semaphore so the SPI Task can go on (read and do anothe write etc).
here’s my code:
**********************
SPI TASK
**********************
only the relevant part of the code
for (i = 0; i < ui8_dataLength; i++)
{
// take semaphore once so that its taken
xSemaphoreTake(SPISemaphore, (portTickType)portMAX_DELAY);
// write the data
S0SPDR = *pui8_readPointer++;
// take semaphore again, its empty already so task should block here!
xSemaphoreTake(SPISemaphore, (portTickType)portMAX_DELAY);
// when the ISR has fired the write was done and the semaphore (should) be
// give back. thus, we can read the received data now
*pui8_writePointer++ = S0SPDR;
}
with the for-loop I send several bytes (some sort of "message"). the messages to send are received by queue from another task (that should be working).
*****************
SPI ISR
*****************
void SPI_ISR( void )
{
portENTER_SWITCHING_ISR();
uint32 xTaskWoken = pdFALSE;
ui8_readDummyByte = S0SPSR;
// Clear the interrupt
S0SPINT = 0x01;
// problem lies here: xTaskWoken wont become 0x1 !!
xTaskWoken = xSemaphoreGiveFromISR(SPISemaphore, xTaskWoken);
// Acknowledge interrupt in the VIC
VICVectAddr = 0;
// Switch to the SPITask
portEXIT_SWITCHING_ISR( xTaskWoken );
}
within the spi.h the ISR is defined as __attribute__((naked)) (the ISR itself is working - or at least its executed)
the semaphore I create in main.ch with:
vSemaphoreCreateBinary(SPISemaphore);
I already checked: PCLKSEL0, PINSEL0/1, PCONP, VicAddr10, VicPrio10, VicEnable, S0SPICR, SP0SPCCR and they all should be ok (as the ISR is running).
the only big error I’ve found is that xTaskWoken won’t get true…
System is still LPC2378/68 with GCC/eclipse
I’m at bit clueless now so I would appreciate it if someone has some ideas and tips!