WS63 SDK 文档 7021f4f@fbb_ws63
ws63 和 ws63e 解决方案的 SDK 文档
载入中...
搜索中...
未找到
Semaphore
Semaphore 的协作图:

宏定义

#define LOS_SEM_COUNT_MAX   0xFFFE
 
#define LOS_ERRNO_SEM_NO_MEMORY   LOS_ERRNO_OS_ERROR(LOS_MOD_SEM, 0x00)
 
#define LOS_ERRNO_SEM_INVALID   LOS_ERRNO_OS_ERROR(LOS_MOD_SEM, 0x01)
 
#define LOS_ERRNO_SEM_PTR_NULL   LOS_ERRNO_OS_ERROR(LOS_MOD_SEM, 0x02)
 
#define LOS_ERRNO_SEM_ALL_BUSY   LOS_ERRNO_OS_ERROR(LOS_MOD_SEM, 0x03)
 
#define LOS_ERRNO_SEM_UNAVAILABLE   LOS_ERRNO_OS_ERROR(LOS_MOD_SEM, 0x04)
 
#define LOS_ERRNO_SEM_PEND_INTERR   LOS_ERRNO_OS_ERROR(LOS_MOD_SEM, 0x05)
 
#define LOS_ERRNO_SEM_PEND_IN_LOCK   LOS_ERRNO_OS_ERROR(LOS_MOD_SEM, 0x06)
 
#define LOS_ERRNO_SEM_TIMEOUT   LOS_ERRNO_OS_ERROR(LOS_MOD_SEM, 0x07)
 
#define LOS_ERRNO_SEM_OVERFLOW   LOS_ERRNO_OS_ERROR(LOS_MOD_SEM, 0x08)
 
#define LOS_ERRNO_SEM_PENDED   LOS_ERRNO_OS_ERROR(LOS_MOD_SEM, 0x09)
 
#define LOS_ERRNO_SEM_PEND_IN_SYSTEM_TASK   LOS_ERRNO_OS_ERROR(LOS_MOD_SEM, 0x0A)
 

函数

UINT32 LOS_SemCreate (UINT16 count, UINT32 *semHandle)
 Create a semaphore.
 
UINT32 LOS_BinarySemCreate (UINT16 count, UINT32 *semHandle)
 Create a binary semaphore.
 
UINT32 LOS_SemDelete (UINT32 semHandle)
 Delete a semaphore.
 
UINT32 LOS_SemPend (UINT32 semHandle, UINT32 timeout)
 Request a semaphore.
 
UINT32 LOS_SemPost (UINT32 semHandle)
 Release a semaphore.
 

详细描述

宏定义说明

◆ LOS_ERRNO_SEM_ALL_BUSY

#define LOS_ERRNO_SEM_ALL_BUSY   LOS_ERRNO_OS_ERROR(LOS_MOD_SEM, 0x03)

Semaphore error code: No semaphore control structure is available.

Value: 0x02000703.

Solution: Perform corresponding operations based on the requirements in the code context.

◆ LOS_ERRNO_SEM_INVALID

#define LOS_ERRNO_SEM_INVALID   LOS_ERRNO_OS_ERROR(LOS_MOD_SEM, 0x01)

Semaphore error code: Invalid parameter.

Value: 0x02000701.

Solution: Change the passed-in invalid parameter value to a valid value.

◆ LOS_ERRNO_SEM_NO_MEMORY

#define LOS_ERRNO_SEM_NO_MEMORY   LOS_ERRNO_OS_ERROR(LOS_MOD_SEM, 0x00)

Semaphore error code: The memory is insufficient.

Value: 0x02000700.

Solution: Allocate more memory.

◆ LOS_ERRNO_SEM_OVERFLOW

#define LOS_ERRNO_SEM_OVERFLOW   LOS_ERRNO_OS_ERROR(LOS_MOD_SEM, 0x08)

Semaphore error code: The times of semaphore release exceed the maximum times permitted.

Value: 0x02000708.

Solution: Perform corresponding operations based on the requirements in the code context.

◆ LOS_ERRNO_SEM_PEND_IN_LOCK

#define LOS_ERRNO_SEM_PEND_IN_LOCK   LOS_ERRNO_OS_ERROR(LOS_MOD_SEM, 0x06)

Semaphore error code: The task is unable to request a semaphore because task scheduling is locked.

Value: 0x02000706.

Solution: Do not call LOS_SemPend when task scheduling is locked.

◆ LOS_ERRNO_SEM_PEND_IN_SYSTEM_TASK

#define LOS_ERRNO_SEM_PEND_IN_SYSTEM_TASK   LOS_ERRNO_OS_ERROR(LOS_MOD_SEM, 0x0A)

Semaphore error code: The API is called in system-level callback, which is forbidden. old usage: The API is called in software timer callback, which is forbidden (LOS_ERRNO_SEM_PEND_SWTERR).

Value: 0x0200070A.

Solution: Do not call the API in the system-level callback.

弃用:
This error code is obsolete since LiteOS 5.0.0.

◆ LOS_ERRNO_SEM_PEND_INTERR

#define LOS_ERRNO_SEM_PEND_INTERR   LOS_ERRNO_OS_ERROR(LOS_MOD_SEM, 0x05)

Semaphore error code: The API is called during an interrupt, which is forbidden.

Value: 0x02000705.

Solution: Do not call the API during an interrupt.

◆ LOS_ERRNO_SEM_PENDED

#define LOS_ERRNO_SEM_PENDED   LOS_ERRNO_OS_ERROR(LOS_MOD_SEM, 0x09)

Semaphore error code: The queue of the tasks that are waiting on the semaphore control structure is not null.

Value: 0x02000709.

Solution: Delete the semaphore after awaking all tasks that are waiting on the semaphore.

◆ LOS_ERRNO_SEM_PTR_NULL

#define LOS_ERRNO_SEM_PTR_NULL   LOS_ERRNO_OS_ERROR(LOS_MOD_SEM, 0x02)

Semaphore error code: Null pointer.

Value: 0x02000702.

Solution: Change the passed-in null pointer to a valid non-null pointer.

◆ LOS_ERRNO_SEM_TIMEOUT

#define LOS_ERRNO_SEM_TIMEOUT   LOS_ERRNO_OS_ERROR(LOS_MOD_SEM, 0x07)

Semaphore error code: The request for a semaphore times out.

Value: 0x02000707.

Solution: Change the passed-in parameter value to the value within the valid range.

◆ LOS_ERRNO_SEM_UNAVAILABLE

#define LOS_ERRNO_SEM_UNAVAILABLE   LOS_ERRNO_OS_ERROR(LOS_MOD_SEM, 0x04)

Semaphore error code: Invalid parameter that specifies the timeout interval.

Value: 0x02000704.

Solution: Change the passed-in parameter value to a valid nonzero value.

◆ LOS_SEM_COUNT_MAX

#define LOS_SEM_COUNT_MAX   0xFFFE

Max count of counting semaphores

函数说明

◆ LOS_BinarySemCreate()

UINT32 LOS_BinarySemCreate ( UINT16  count,
UINT32 semHandle 
)
extern

Create a binary semaphore.

Description:
This API is used to create a binary semaphore control structure according to the initial number of available semaphores specified by count and return the ID of this semaphore control structure.
注意
None.
参数
count[IN] Initial number of available semaphores. The value range is [0, 1].
semHandle[OUT] ID of the semaphore control structure that is initialized.
返回值
LOS_ERRNO_SEM_PTR_NULLThe passed-in semHandle value is NULL.
LOS_ERRNO_SEM_OVERFLOWThe passed-in count value is greater than the maximum number of available semaphores.
LOS_ERRNO_SEM_ALL_BUSYNo semaphore control structure is available.
LOS_OKThe semaphore is successfully created.
Dependency:
  • los_sem.h: the header file that contains the API declaration.
参见
LOS_SemCreate | LOS_SemDelete
自从
Huawei LiteOS V100R001C00

◆ LOS_SemCreate()

UINT32 LOS_SemCreate ( UINT16  count,
UINT32 semHandle 
)
extern

Create a semaphore.

Description:
This API is used to create a semaphore control structure according to the initial number of available semaphores specified by count and return the ID of this semaphore control structure.
注意
None.
参数
count[IN] Initial number of available semaphores. The value range is [0, LOS_SEM_COUNT_MAX).
semHandle[OUT] ID of the semaphore control structure that is initialized.
返回值
LOS_ERRNO_SEM_PTR_NULLThe passed-in semHandle value is NULL.
LOS_ERRNO_SEM_OVERFLOWThe passed-in count value is greater than the maximum number of available semaphores.
LOS_ERRNO_SEM_ALL_BUSYNo semaphore control structure is available.
LOS_OKThe semaphore is successfully created.
Dependency:
  • los_sem.h: the header file that contains the API declaration.
参见
LOS_SemDelete | LOS_BinarySemCreate
自从
Huawei LiteOS V100R001C00

◆ LOS_SemDelete()

UINT32 LOS_SemDelete ( UINT32  semHandle)
extern

Delete a semaphore.

Description:
This API is used to delete a semaphore control structure that has an ID specified by semHandle.
注意
The specified sem id must be created first before deleting it.
参数
semHandle[IN] ID of the semaphore control structure to be deleted. The ID of the semaphore control structure is obtained from semaphore creation.
返回值
LOS_ERRNO_SEM_INVALIDThe passed-in semHandle value is invalid.
LOS_ERRNO_SEM_PENDEDThe queue of the tasks that are waiting on the semaphore control structure is not null.
LOS_OKThe semaphore control structure is successfully deleted.
Dependency:
  • los_sem.h: the header file that contains the API declaration.
参见
LOS_SemCreate | LOS_BinarySemCreate
自从
Huawei LiteOS V100R001C00

◆ LOS_SemPend()

UINT32 LOS_SemPend ( UINT32  semHandle,
UINT32  timeout 
)
extern

Request a semaphore.

Description:
This API is used to request a semaphore based on the semaphore control structure ID specified by semHandle and the parameter that specifies the timeout period.
注意
  • Do not pend sem during an interrupt.
  • Do not pend sem in a system task, such as idle or swtmr task.
  • The specified sem id must be created first.
  • Do not recommend to use this API in software timer callback.
参数
semHandle[IN] ID of the semaphore control structure to be requested. The ID of the semaphore control structure is obtained from semaphore creation.
timeout[IN] Timeout interval for waiting on the semaphore. The value range is [0, 0xFFFFFFFF]. If the value is set to 0, the semaphore is not waited on. If the value is set to 0xFFFFFFFF, the semaphore is waited on forever(unit: Tick).
返回值
LOS_ERRNO_SEM_INVALIDThe passed-in semHandle value is invalid.
LOS_ERRNO_SEM_UNAVAILABLEThere is no available semaphore resource.
LOS_ERRNO_SEM_PEND_INTERRThe API is called during an interrupt, which is forbidden.
LOS_ERRNO_SEM_PEND_IN_LOCKThe task is unable to request a semaphore because task scheduling is locked.
LOS_ERRNO_SEM_PEND_IN_SYSTEM_TASKThe API is called in a system task, such as idle task or software timer, which is forbidden.
LOS_ERRNO_SEM_TIMEOUTThe request for the semaphore times out.
LOS_OKThe semaphore request succeeds.
Dependency:
  • los_sem.h: the header file that contains the API declaration.
参见
LOS_SemPost | LOS_SemCreate | LOS_BinarySemCreate
自从
Huawei LiteOS V100R001C00

◆ LOS_SemPost()

UINT32 LOS_SemPost ( UINT32  semHandle)
extern

Release a semaphore.

Description:
This API is used to release a semaphore that has a semaphore control structure ID specified by semHandle.
注意
The specified sem id must be created first.
参数
semHandle[IN] ID of the semaphore control structure to be released.The ID of the semaphore control structure is obtained from semaphore creation.
返回值
LOS_ERRNO_SEM_INVALIDThe passed-in semHandle value is invalid.
LOS_ERRNO_SEM_OVERFLOWThe times of semaphore release exceed the maximum times permitted.
LOS_OKThe semaphore is successfully released.
Dependency:
  • los_sem.h: the header file that contains the API declaration.
参见
LOS_SemPend | LOS_SemCreate | LOS_BinarySemCreate
自从
Huawei LiteOS V100R001C00