Flags are lightweight objects designed for basic data exchange. A flags object consists of a set of bit-flags, allowing each bit to be set or reset individually. Operations on these objects return information regarding which flags were successfully modified during the call.
The osCreateFlags function is used to create a flags object. A flags object may be created prior to system initialization, from within an interrupt handler, or by a running task. During creation, an optional object name may be assigned, enabling other tasks to access the object via the osOpenFlags function. Both creation and opening procedures return a handle assigned by the system to uniquely identify the object. All subsequent operations on the flags object require this handle as a parameter. When a flags object is no longer required, it should be closed using osCloseHandle. The object is deleted only after it has been closed by all tasks that held an open handle. For further details, refer to the system objects management section.
If flags objects are not required by the application, the OS_USE_FLAGS constant can be set to 0 to reduce the final code size.
A flags object serves as a bitmask typically used to signal the occurrence of specific events. The number of available bits depends on the architecture's configuration and is calculated as 8 * sizeof(INDEX). The object is considered to be in a signaled state if at least one bit-flag is set; otherwise, it is in a non-signaled state. The state of the flags can be modified at any time using osSetFlags to set specific bits to 1, or osResetFlags to reset them to 0.
When modifying the state of a flag, the system returns information indicating whether the bits were successfully changed (i.e., if the new state differs from the previous state). The current state of all flags can be retrieved at any time using the osGetFlags function.