queue. h
portBASE_TYPE xQueueReceiveFromISR( xQueueHandle pxQueue, void *pvBuffer, portBASE_TYPE *pxTaskWoken );
待ち行列からアイテムを受信する。 割り込みサービスルーチンの中からこの関数は安全に使用できます。
パラメータ:
pxQueue アイテムを受信すべき待ち行列へのハンドル。
pvBuffer 受信アイテムがコピーされるべきバッファへのポインタ。
pxTaskWoken タスクが待ち行列に受信可能になるまで待つためにブロックしていた。 xQueueReceiveFromISRはそのようなタスクをブロック解除する事象が発生した場合、
*pxTaskWokenはpdTRUEに設定されます、それ以外の場合*pxTaskWokenは変更されません。
リターン:
待ち行列からアイテム受信が成功ならばpdTRUE が返る、さもなければ pdFALSE を受け取る。
使用例:
xQueueHandle xQueue;
// Function to create a queue and post some values.
void vAFunction( void *pvParameters )
{
portCHAR cValueToPost;
const portTickType
xBlockTime = ( portTickType )0xff;
// Create a queue capable of containing 10 characters.
xQueue = xQueueCreate( 10, sizeof( portCHAR ) );
if( xQueue == 0 ) {
// Failed to create the queue.
}
// ...
// Post some characters that will be used within an ISR. If the queue
// is full then this task will block for xBlockTime ticks.
cValueToPost = 'a';
xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
cValueToPost = 'b';
xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
// ... keep posting characters ... this task may block when the queue
// becomes full.
cValueToPost = 'c';
xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
}
// ISR that outputs all the characters received on the queue.
void vISR_Routine( void )
{
portBASE_TYPE xTaskWokenByReceive = pdFALSE;
portCHAR cRxedChar;
while( xQueueReceiveFromISR( xQueue, ( void * ) &cRxedChar, &xTaskWokenByReceive) ) {
// A character was received. Output the character now.
vOutputCharacter( cRxedChar );
// If removing the character from the queue woke the task that was
// posting onto the queue xTaskWokenByReceive will have been set to
// pdTRUE. No matter how many times this loop iterates only one
// task will be woken.
}
if( xTaskWokenByPost != pdFALSE ) {
// We should switch context so the ISR returns to a different task.
// NOTE: How this is done depends on the port you are using. Check
// the documentation and examples for your port.
taskYIELD ();
}
}