freeRTOS事件组学习

时间:2022-05-07
本文章向大家介绍freeRTOS事件组学习,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

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

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

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

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

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事件组的问题可以参阅官方文档或网站。具体在我们的工程应用中,比如可以在串口接收中断使用事件组。还有很多在我们工程中可以使用事件组的地方,希望大家在自己的实际应用中多多体验,学会事件组的使用。