更新日期: 2022/06/01 来源: https://gitee.com/weharmony/kernel_liteos_a_note
Event
Event 的协作图:

结构体

struct  tagEvent
 

类型定义

typedef struct tagEvent EVENT_CB_S
 
typedef struct tagEventPEVENT_CB_S
 

函数

UINT32 LOS_EventInit (PEVENT_CB_S eventCB)
 Initialize an event control block. 更多...
 
UINT32 LOS_EventPoll (UINT32 *eventID, UINT32 eventMask, UINT32 mode)
 Obtain an event specified by the event ID. 更多...
 
UINT32 LOS_EventRead (PEVENT_CB_S eventCB, UINT32 eventMask, UINT32 mode, UINT32 timeout)
 Read an event. 更多...
 
UINT32 LOS_EventWrite (PEVENT_CB_S eventCB, UINT32 events)
 Write an event. 更多...
 
UINT32 LOS_EventClear (PEVENT_CB_S eventCB, UINT32 eventMask)
 Clear the event of the eventCB by a specified eventMask. 更多...
 
UINT32 LOS_EventDestroy (PEVENT_CB_S eventCB)
 Destroy an event. 更多...
 

详细描述

类型定义说明

◆ EVENT_CB_S

typedef struct tagEvent EVENT_CB_S

Event control structure | 事件控制块数据结构

◆ PEVENT_CB_S

typedef struct tagEvent * PEVENT_CB_S

函数说明

◆ LOS_EventClear()

UINT32 LOS_EventClear ( PEVENT_CB_S  eventCB,
UINT32  eventMask 
)

Clear the event of the eventCB by a specified eventMask.

Description:
  • This API is used to set the ID of an event that has a specified mask and of which the information is stored in an event control block pointed to by eventCB to 0. eventCB must point to valid memory.
注意
  • The value of events needs to be reversed when it is passed-in.
参数
eventCB[IN/OUT] Pointer to the event control block to be cleared.
eventMask[IN] Mask of the event to be cleared.
返回值
#LOS_ERRNO_EVENT_PTR_NULLNull pointer.
#LOS_OKThe event is successfully cleared.
Dependency:
  • los_event.h: the header file that contains the API declaration.
参见
LOS_EventPoll | LOS_EventRead | LOS_EventWrite

Clear the event of the eventCB by a specified eventMask.

在文件 los_event.c355 行定义.

356{
357 UINT32 intSave;
358
359 if (eventCB == NULL) {
360 return LOS_ERRNO_EVENT_PTR_NULL;
361 }
362 OsHookCall(LOS_HOOK_TYPE_EVENT_CLEAR, eventCB, eventMask);
363 SCHEDULER_LOCK(intSave);
364 eventCB->uwEventID &= eventMask;
365 SCHEDULER_UNLOCK(intSave);
366
367 return LOS_OK;
368}
unsigned int UINT32
Definition: los_typedef.h:57
UINT32 uwEventID
Definition: los_event.h:165
这是这个函数的调用关系图:

◆ LOS_EventDestroy()

UINT32 LOS_EventDestroy ( PEVENT_CB_S  eventCB)

Destroy an event.

Description:
  • This API is used to Destroy an event.
注意
  • The specific event should be a valid one.
参数
eventCB[IN/OUT] Pointer to the event control block to be destroyed.
返回值
#LOS_ERRNO_EVENT_PTR_NULLNull pointer.
#LOS_OKThe event is successfully cleared.
Dependency:
  • los_event.h: the header file that contains the API declaration.
参见
LOS_EventPoll | LOS_EventRead | LOS_EventWrite

Destroy an event.

在文件 los_event.c334 行定义.

335{
336 UINT32 intSave;
337
338 if (eventCB == NULL) {
339 return LOS_ERRNO_EVENT_PTR_NULL;
340 }
341
342 SCHEDULER_LOCK(intSave);
343 if (!LOS_ListEmpty(&eventCB->stEventList)) {
344 SCHEDULER_UNLOCK(intSave);
345 return LOS_ERRNO_EVENT_SHOULD_NOT_DESTROY;
346 }
347
348 eventCB->uwEventID = 0;
349 LOS_ListDelInit(&eventCB->stEventList);
350 SCHEDULER_UNLOCK(intSave);
351 OsHookCall(LOS_HOOK_TYPE_EVENT_DESTROY, eventCB);
352 return LOS_OK;
353}
LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListDelInit(LOS_DL_LIST *list)
Delete initialize a doubly linked list. | 将指定节点从链表中删除,并使用该节点初始化链表
Definition: los_list.h:525
LITE_OS_SEC_ALW_INLINE STATIC INLINE BOOL LOS_ListEmpty(LOS_DL_LIST *list)
Identify whether a specified doubly linked list is empty. | 判断链表是否为空
Definition: los_list.h:321
LOS_DL_LIST stEventList
Definition: los_event.h:167
函数调用图:
这是这个函数的调用关系图:

◆ LOS_EventInit()

UINT32 LOS_EventInit ( PEVENT_CB_S  eventCB)

Initialize an event control block.

Description:
This API is used to initialize the event control block pointed to by eventCB.
注意
  • None.
参数
eventCB[IN/OUT] Pointer to the event control block to be initialized.
返回值
#LOS_ERRNO_EVENT_PTR_NULLNull pointer.
#LOS_OKThe event control block is successfully initialized.
Dependency:
  • los_event.h: the header file that contains the API declaration.
参见
LOS_EventClear

Initialize an event control block.

在文件 los_event.c95 行定义.

96{
97 UINT32 intSave;
98
99 if (eventCB == NULL) {
100 return LOS_ERRNO_EVENT_PTR_NULL;
101 }
102
103 intSave = LOS_IntLock();//锁中断
104 eventCB->uwEventID = 0;//事件类型初始化
105 LOS_ListInit(&eventCB->stEventList);//事件链表初始化
106 LOS_IntRestore(intSave);//恢复中断
107 OsHookCall(LOS_HOOK_TYPE_EVENT_INIT, eventCB);
108 return LOS_OK;
109}
STATIC INLINE VOID LOS_IntRestore(UINT32 intSave)
Restore interrupts. | 恢复到使用LOS_IntLock关闭所有中断之前的状态
Definition: los_hwi.h:337
STATIC INLINE UINT32 LOS_IntLock(VOID)
Disable all interrupts. | 关闭当前处理器所有中断响应
Definition: los_hwi.h:286
LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListInit(LOS_DL_LIST *list)
Definition: los_list.h:104
函数调用图:
这是这个函数的调用关系图:

◆ LOS_EventPoll()

UINT32 LOS_EventPoll ( UINT32 eventID,
UINT32  eventMask,
UINT32  mode 
)

Obtain an event specified by the event ID.

Description:
This API is used to check whether an event expected by the user occurs according to the event ID, event mask, and event reading mode, and process the event based on the event reading mode. The event ID must point to valid memory.
注意
  • When the mode is LOS_WAITMODE_CLR, the eventID is passed-out.
  • Otherwise the eventID is passed-in.
  • An error code and an event return value can be same. To differentiate the error code and return value, bit 25 of the event mask is forbidden to be used.
参数
eventID[IN/OUT] Pointer to the ID of the event to be checked.
eventMask[IN] Mask of the event expected to occur by the user, indicating the event obtained after it is logically processed that matches the ID pointed to by eventID.
mode[IN] Event reading mode. The modes include LOS_WAITMODE_AND, LOS_WAITMODE_OR, LOS_WAITMODE_CLR.
返回值
#LOS_ERRNO_EVENT_SETBIT_INVALIDBit 25 of the event mask cannot be set because it is set to an error number.
#LOS_ERRNO_EVENT_EVENTMASK_INVALIDThe passed-in event mask is incorrect.
#LOS_ERRNO_EVENT_FLAGS_INVALIDThe passed-in event mode is invalid.
#LOS_ERRNO_EVENT_PTR_NULLThe passed-in pointer is null.
0The event expected by the user does not occur.
UINT32The event expected by the user occurs.
Dependency:
  • los_event.h: the header file that contains the API declaration.
参见
LOS_EventRead | LOS_EventWrite

Obtain an event specified by the event ID.

在文件 los_event.c297 行定义.

298{
299 UINT32 ret;
300 UINT32 intSave;
301 //事件参数检查
302 ret = OsEventParamCheck((VOID *)eventID, eventMask, mode);
303 if (ret != LOS_OK) {
304 return ret;
305 }
306
307 SCHEDULER_LOCK(intSave);//申请任务自旋锁
308 ret = OsEventPoll(eventID, eventMask, mode);
309 SCHEDULER_UNLOCK(intSave);
310 return ret;
311}
LITE_OS_SEC_TEXT UINT32 OsEventPoll(UINT32 *eventID, UINT32 eventMask, UINT32 mode)
根据用户传入的事件值、事件掩码及校验模式,返回用户传入的事件是否符合预期
Definition: los_event.c:133
LITE_OS_SEC_TEXT STATIC UINT32 OsEventParamCheck(const VOID *ptr, UINT32 eventMask, UINT32 mode)
事件参数检查
Definition: los_event.c:111
函数调用图:

◆ LOS_EventRead()

UINT32 LOS_EventRead ( PEVENT_CB_S  eventCB,
UINT32  eventMask,
UINT32  mode,
UINT32  timeout 
)

Read an event.

Description:
This API is used to block or schedule a task that reads an event of which the event control block, event mask, reading mode, and timeout information are specified.
注意
  • An error code and an event return value can be same. To differentiate the error code and return value, bit 25 of the event mask is forbidden to be used.
参数
eventCB[IN/OUT] Pointer to the event control block to be checked. This parameter must point to valid memory.
eventMask[IN] Mask of the event expected to occur by the user, indicating the event obtained after it is logically processed that matches the ID pointed to by eventID.
mode[IN] Event reading mode.
timeout[IN] Timeout interval of event reading (unit: Tick).
返回值
#LOS_ERRNO_EVENT_SETBIT_INVALIDBit 25 of the event mask cannot be set because it is set to an error number.
#LOS_ERRNO_EVENT_EVENTMASK_INVALIDThe passed-in event reading mode is incorrect.
#LOS_ERRNO_EVENT_READ_IN_INTERRUPTThe event is being read during an interrupt.
#LOS_ERRNO_EVENT_FLAGS_INVALIDThe event mode is invalid.
#LOS_ERRNO_EVENT_READ_IN_LOCKThe event reading task is locked.
#LOS_ERRNO_EVENT_PTR_NULLThe passed-in pointer is null.
0The event expected by the user does not occur.
UINT32The event expected by the user occurs.
Dependency:
  • los_event.h: the header file that contains the API declaration.
参见
LOS_EventPoll | LOS_EventWrite

Read an event.

在文件 los_event.c313 行定义.

314{
315 return OsEventRead(eventCB, eventMask, mode, timeout, FALSE);
316}
LITE_OS_SEC_TEXT STATIC UINT32 OsEventRead(PEVENT_CB_S eventCB, UINT32 eventMask, UINT32 mode, UINT32 timeout, BOOL once)
读取指定事件类型,超时时间为相对时间:单位为Tick
Definition: los_event.c:213
函数调用图:
这是这个函数的调用关系图:

◆ LOS_EventWrite()

UINT32 LOS_EventWrite ( PEVENT_CB_S  eventCB,
UINT32  events 
)

Write an event.

Description:
This API is used to write an event specified by the passed-in event mask into an event control block pointed to by eventCB.
注意
  • To determine whether the LOS_EventRead API returns an event or an error code, bit 25 of the event mask is forbidden to be used.
参数
eventCB[IN/OUT] Pointer to the event control block into which an event is to be written. This parameter must point to valid memory.
events[IN] Event mask to be written.
返回值
#LOS_ERRNO_EVENT_SETBIT_INVALIDBit 25 of the event mask cannot be set to an event because it is set to an error code.
#LOS_ERRNO_EVENT_PTR_NULLNull pointer.
#LOS_OKThe event is successfully written.
Dependency:
  • los_event.h: the header file that contains the API declaration.
参见
LOS_EventPoll | LOS_EventRead

Write an event.

在文件 los_event.c318 行定义.

319{
320 return OsEventWrite(eventCB, events, FALSE);
321}
LITE_OS_SEC_TEXT STATIC UINT32 OsEventWrite(PEVENT_CB_S eventCB, UINT32 events, BOOL once)
写入事件
Definition: los_event.c:273
函数调用图:
这是这个函数的调用关系图: