FreeRTOS (event flag group)

1. What is an event flag group?

Event flag bit: Indicates whether an event occurs, association: global variable flag, Usually represented by bits,Each bit represents an event (the upper 8 bits are not counted)

Event flag group: It is a set ofevent flag bits. It can be simply understood that the event flag group is an integer.

Event flag groupEssence is a 16-bit or 32-bit unsigned data type EventBits_t, determined by configUSE_16_BIT_TICKS.

Although a 32-bit unsigned data type variable is used to store the event flag, the high 8 bits of are used to store the control information of the event flag group, and the low 24 bits are used to store the event flag group. To store event flags, so an event group can store up to 24 event flags!

[ESP32+freeRTOS Study Notes-(9) Event Group]_Bull Riding and Singing Script Blog-CSDN Blog 

2. API functions related to event flag group

1. Create event flag group

EventGroupHandle_t xEventGroupCreate( void );

  • Parameters: None

  • Return value: If successful, return the handle of the corresponding event flag group; if failed, return NULL.

2. Set event flag bit

EventBits_t xEventGroupSetBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet );

  • parameter:

  • xEventGroup: Corresponding event group handle.

  • uxBitsToSet: Specifies the bitwise value of one or more bits to be set in the event group.

  • Return value: The event flag bit value in the event group after setting.

3. Clear event flag bit

EventBits_t xEventGroupClearBits(EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToClear );

parameter:

  • xEventGroup: Corresponding event group handle.
  • uxBitsToClear: Specifies the bitwise value of one or more bits to clear in the event group.
  • Return value: The value of the event flag bit in the event group before clearing.

4. Wait for event flag

EventBits_t xEventGroupWaitBits( const EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToWaitFor, const BaseType_t xClearOnExit, const BaseType_t xWaitForAllBits, TickType_t xTicksToWait );

parameter:

  • xEventGroup: corresponding event flag group handle
  • uxBitsToWaitFor: The bitwise value of one or more event bits in the specified event group to wait for
  • xClearOnExit: pdTRUE - clear the corresponding event bit, pdFALSE - not clear
  • xWaitForAllBits: pdTRUE - all waiting event bits are 1 (logical AND), pdFALSE - one of the waiting event bits is 1 (logical OR)
  • xTicksToWait: timeout
  • Return value: Waiting event flag value: If the waiting event flag succeeds, the waiting event flag is returned. Other values: If the waiting event flag fails, the event flag in the event group is returned.

3. Experiment

Experimental requirements: Create an event flag group and two tasks (task1 and task2). Task1 detects key presses. If it is detected that both KEY1 and KEY2 have been pressed, task2 will be executed.

Code

 

 

 

 

Guess you like

Origin blog.csdn.net/m0_70987863/article/details/131901242