中级会员
 
- 积分
- 215
- 金钱
- 215
- 注册时间
- 2011-5-11
- 在线时间
- 25 小时
|

楼主 |
发表于 2025-2-6 22:26:59
|
显示全部楼层
根据安富莱的eric2013指点提示,学习到了事件的正确使用方法。
- #define BIT_0 ( 1 << 0 )
- #define BIT_4 ( 1 << 4 )
-
- void aFunction( EventGroupHandle_t xEventGroup )
- {
- EventBits_t uxBits;
- const TickType_t xTicksToWait = 100 / portTICK_PERIOD_MS;
-
- /* Wait a maximum of 100ms for either bit 0 or bit 4 to be set within
- the event group. Clear the bits before exiting. */
- uxBits = xEventGroupWaitBits(
- xEventGroup, /* The event group being tested. */
- BIT_0 | BIT_4, /* The bits within the event group to wait for. */
- pdTRUE, /* BIT_0 & BIT_4 should be cleared before returning. */
- pdFALSE, /* Don't wait for both bits, either bit will do. */
- xTicksToWait );/* Wait a maximum of 100ms for either bit to be set. */
-
- if( ( uxBits & ( BIT_0 | BIT_4 ) ) == ( BIT_0 | BIT_4 ) )
- {
- /* xEventGroupWaitBits() returned because both bits were set. */
- }
- else if( ( uxBits & BIT_0 ) != 0 )
- {
- /* xEventGroupWaitBits() returned because just BIT_0 was set. */
- }
- else if( ( uxBits & BIT_4 ) != 0 )
- {
- /* xEventGroupWaitBits() returned because just BIT_4 was set. */
- }
- else
- {
- /* xEventGroupWaitBits() returned because xTicksToWait ticks passed
- without either BIT_0 or BIT_4 becoming set. */
- }
- }
复制代码
也去查了下API手册,
应该是对事件返回的值进行判断。正常是返回对应事件位,后续可以判断这个事件位。
挂起任务后,返回的是osFlagsErrorTimeout 0xFFFFFFFE 错误代码
另注意:如果按照上述代码判断方式,假如用Bit2=1 判断 时 & 错误代码, 也会 !=0 。
判断方法,需另写即可。
|
|