croutine.h
portBASE_TYPE crQUEUE_SEND_FROM_ISR( xQueueHandle pxQueue, void *pvItemToQueue, portBASE_TYPE xCoRoutinePreviouslyWoken )
crQUEUE_SEND_FROM_ISR () はマクロです。 上記のプロトタイプで示すデータ型は参照用です
crQUEUE_SEND_FROM_ISR() と crQUEUE_RECEIVE_FROM_ISR() は、タスクによって使われるxQueueSendFromISR()
、xQueueReceiveFromISR()関数と同等の、コルーチン用のマクロです。crQUEUE_SEND_FROM_ISR() と
crQUEUE_RECEIVE_FROM_ISR()はコルーチンとISR間のデータを受け渡すためにだけに使われる、対して、xQueueSendFromISR()
と xQueueReceiveFromISR() はタスクとISR間のみにデータを受け渡すものでした。
crQUEUE_SEND_FROM_ISR はコルーチンの中で使われるデータを、ISR から待ち行列へデータを送信しするだけです。
タスクとコルーチンの間、 ISR とコルーチンの間でのデータ受け渡しについてのインフォメーションは Web ドキュメンテーションのコルーチンのセクションを見てください。
パラメータ:
xQueue アイテムをポストする待ち行列へのハンドル。
pvItemToQueue 待ち行列に送られるべきアイテムへのポインタ。 待ち行列の作成時定義された項目のサイズ分pvItemToQueue
から待ち行列格納エリアへコピーされる。
xCoRoutinePreviouslyWoken 、 ISR が一つの割り込みで同じ待ち行列に複数回ポスト可能なように、これは含まれます。
最初のコールは常に pdFALSE でパスすべきです。 次のコールが前のコールから返された値パスすべきです。
リターン:
もしコルーチンが待ち行列のポストによって起動した場合pdTRUE が返る。 これは ISR によってコンテキストスイッチが ISR の後に要求されたかどうか知るために使われる。
使用例:
// A co-routine that blocks on a queue waiting for characters to be received.
static void vReceivingCoRoutine( xCoRoutineHandle xHandle, unsigned portBASE_TYPE uxIndex )
{
portCHAR cRxedChar;
portBASE_TYPE xResult;
// All co-routines must start with a call to crSTART().
crSTART( xHandle );
for( ;; )
{
// Wait for data to become available on the queue. This assumes the
// queue xCommsRxQueue has already been created!
crQUEUE_RECEIVE( xHandle, xCommsRxQueue, &uxLEDToFlash, portMAX_DELAY, &xResult );
// Was a character received?
if( xResult == pdPASS )
{
// Process the character here.
}
}
// All co-routines must end with a call to crEND().
crEND();
}
// An ISR that uses a queue to send characters received on a serial port to
// a co-routine.
void vUART_ISR( void )
{
portCHAR cRxedChar;
portBASE_TYPE xCRWokenByPost = pdFALSE;
// We loop around reading characters until there are none left in the UART.
while( UART_RX_REG_NOT_EMPTY() )
{
// Obtain the character from the UART.
cRxedChar = UART_RX_REG;
// Post the character onto a queue. xCRWokenByPost will be pdFALSE
// the first time around the loop. If the post causes a co-routine
// to be woken (unblocked) then xCRWokenByPost will be set to pdTRUE.
// In this manner we can ensure that if more than one co-routine is
// blocked on the queue only one is woken by this ISR no matter how
// many characters are posted to the queue.
xCRWokenByPost = crQUEUE_SEND_FROM_ISR( xCommsRxQueue, &cRxedChar, xCRWokenByPost );
}
}