croutine.h
portBASE_TYPE crQUEUE_SEND_FROM_ISR (xQueueHandle pxQueue 、無効な * pvBuffer 、 portBASE_TYPE * pxCoRoutineWoken)
crQUEUE_SEND_FROM_ISR () と crQUEUE_RECEIVE_FROM_ISR () は タスクで使うQueueSendFromISR()、 xQueueReceiveFromISR()関数と同等の、コルーチンのマクロです。
crQUEUE_RECEIVE_FROM_ISR() 、crQUEUE_SEND_FROM_ISR() はコルーチンとISR間にデータを受け渡すためだけに使用できる、対して、xQueueSendFromISR
() と xQueueReceiveFromISR () はタスクとISRの間のデータを受け渡しだけができる。
crQUEUE_RECEIVE_FROM_ISR は待ち行列から(コルーチンの中からから待ち行列にポストされた)データを受け取るために ISR
から呼び出されることができる。
タスクとコルーチンの間、 ISR とコルーチンの間でのデータ受け渡しについてのインフォメーションは Web ドキュメンテーションのコルーチンのセクションを見てください。
パラメータ:
xQueue アイテムがポストされるべき待ち行列へのハンドル。
pvBuffer 受信したアイテムが置かれるバッファへのポインタ。 待ち行列が作成されたとき、待ち行列が持つ項目の長さは定義された、その長さのバイト数、待ち行列から
pvBuffer へコピーされる。
pxCoRoutineWoken コルーチンが待ち行列の利用可能なスペースを待ってブロックされていかもしれない。 もし crQUEUE_RECEIVE_FROM_ISR
がこのようなコルーチンをブロック解除させる場合*pxCoRoutineWoken をpdTRUE にセットする、さもなければ *pxCoRoutineWoken
を変更しない。
リターン: 待ち行列からアイテムの受信に成功した場合pdTRUEが戻る、さもなければ pdFALSE が戻る。
使用例:
// A co-routine that posts a character to a queue then blocks for a fixed
// period. The character is incremented each time.
static void vSendingCoRoutine( xCoRoutineHandle xHandle, unsigned portBASE_TYPE uxIndex )
{
// cChar holds its value while this co-routine is blocked and must therefore
// be declared static.
static portCHAR cCharToTx = 'a';
portBASE_TYPE xResult;
// All co-routines must start with a call to crSTART().
crSTART( xHandle );
for( ;; )
{
// Send the next character to the queue.
crQUEUE_SEND( xHandle, xCoRoutineQueue, &cCharToTx, NO_DELAY, &xResult );
if( xResult == pdPASS )
{
// The character was successfully posted to the queue.
}
else
{
// Could not post the character to the queue.
}
// Enable the UART Tx interrupt to cause an interrupt in this
// hypothetical UART. The interrupt will obtain the character
// from the queue and send it.
ENABLE_RX_INTERRUPT();
// Increment to the next character then block for a fixed period.
// cCharToTx will maintain its value across the delay as it is
// declared static.
cCharToTx++;
if( cCharToTx > 'x' )
{
cCharToTx = 'a';
}
crDELAY( 100 );
}
// All co-routines must end with a call to crEND().
crEND();
}
// An ISR that uses a queue to receive characters to send on a UART.
void vUART_ISR( void )
{
portCHAR cCharToTx;
portBASE_TYPE xCRWokenByPost = pdFALSE;
while( UART_TX_REG_EMPTY() )
{
// Are there any characters in the queue waiting to be sent?
// xCRWokenByPost will automatically be set to pdTRUE if a co-routine
// is woken by the post - ensuring that only a single co-routine is
// woken no matter how many times we go around this loop.
if( crQUEUE_RECEIVE_FROM_ISR( pxQueue, &cCharToTx, &xCRWokenByPost ) )
{
SEND_CHARACTER( cCharToTx );
}
}
}