freeRTOS事件组学习

像其他RTOS一样,freeRTOS同样有对事件标志位的创建和处理,在中断中可以通过事件组传递信息给其他的任务,那么如何创建事件组呢?

要使用创建Event的API,首先必须配置,且包含event的头文件和源文件在工程中,

主要使用EventGroupHandle_txEventGroupCreate( void ),源码如下显示:

0?wx_fmt=jpeg

使用用例可以参照下述代码

Example usage:

    /* Declare a variable to hold thecreated event group. */

    EventGroupHandle_t xCreatedEventGroup;

 

    /* Attempt to create the event group. */

    xCreatedEventGroup = xEventGroupCreate();

 

    /* Was the event group createdsuccessfully? */

    if( xCreatedEventGroup == NULL )

    {

        /* The event group was not createdbecause there was insufficient

        FreeRTOS heap available. */

    }

    else

    {

        /* The event group was created. */

    }

事件的删除使用void vEventGroupDelete( EventGroupHandle_t xEventGroup );API函数。
置事件位使用EventBits_t xEventGroupSetBits( EventGroupHandle_t xEventGroup,
                                 const EventBits_t uxBitsToSet );
BaseType_t xEventGroupSetBitsFromISR(
                          EventGroupHandle_t xEventGroup,
                          const EventBits_t uxBitsToSet,
                          BaseType_t *pxHigherPriorityTaskWoken );
还有事件清标志位API,获取位状态API,事件同步API等函数供用户调用和在工程中使用,从源码注释和API文档介绍可以很容易的上手事件组的应用。更多有关使用freeRTOS事件组的问题可以参阅官方文档或网站。具体在我们的工程应用中,比如可以在串口接收中断使用事件组。还有很多在我们工程中可以使用事件组的地方,希望大家在自己的实际应用中多多体验,学会事件组的使用。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值