FreeRTOS--XQueueReceiveFromISR

XQueueReceiveFromISR-FreeRTOS API


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 (); 
    } 
} 


  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值