daverm wrote on Sunday, September 28, 2008:
Hi,
I have a couple of questions, albeit dumb ones, with the xSerialPutChar() example code.
1. Why is the use of the lTaskWaiting variable necessary? Don’t the semaphores handle that?
2. Why is it necessary to wrap everything in a critical section? Especially with the blocking xSemaphoreTake() call. How does it unblock if interrupts are disabled?
portENTER_CRITICAL();
{
/* Can we write to the FIFO? */
if( UART1->FR & serTX_FIFO_FULL )
{
/* Wait for the interrupt letting us know there is space on the
FIFO. It is ok to block in a critical section, interrupts will be
enabled for other tasks once we force a switch. */
lTaskWaiting = pdTRUE;
/* Just to be a bit different this driver uses a semaphore to
block the sending task when the FIFO is full. The standard COMTest
task assumes a queue of adequate length exists so does not use
a block time. For this demo the block time is therefore hard
coded. */
xReturn = xSemaphoreTake( xTxFIFOSemaphore, serTX_BLOCK_TIME );
if( xReturn )
{
UART1->DR = cOutChar;
}
}
else
{
UART1->DR = cOutChar;
xReturn = pdPASS;
}
}
portEXIT_CRITICAL();