11bd4fe43Sopenharmony_ci/**
21bd4fe43Sopenharmony_ci* @file hi_sem.h
31bd4fe43Sopenharmony_ci*
41bd4fe43Sopenharmony_ci* Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
51bd4fe43Sopenharmony_ci* Licensed under the Apache License, Version 2.0 (the "License");
61bd4fe43Sopenharmony_ci* you may not use this file except in compliance with the License.
71bd4fe43Sopenharmony_ci* You may obtain a copy of the License at
81bd4fe43Sopenharmony_ci*
91bd4fe43Sopenharmony_ci*     http://www.apache.org/licenses/LICENSE-2.0
101bd4fe43Sopenharmony_ci*
111bd4fe43Sopenharmony_ci* Unless required by applicable law or agreed to in writing, software
121bd4fe43Sopenharmony_ci* distributed under the License is distributed on an "AS IS" BASIS,
131bd4fe43Sopenharmony_ci* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
141bd4fe43Sopenharmony_ci* See the License for the specific language governing permissions and
151bd4fe43Sopenharmony_ci* limitations under the License.
161bd4fe43Sopenharmony_ci*
171bd4fe43Sopenharmony_ci* Description: Semaphore APIs.CNcomment:接口。CNend
181bd4fe43Sopenharmony_ci*
191bd4fe43Sopenharmony_ci* @li Wait semaphore. In the interrupt function, disable interrupt context, and lock task context, this API must not be
201bd4fe43Sopenharmony_ci*     called. Otherwise, uncontrollable exception scheduling may result.CNcomment:等待信号量:在中断、关中断、
211bd4fe43Sopenharmony_ci锁任务上下文禁止调用等待信号量接口,进而产生不可控的异常调度。CNend
221bd4fe43Sopenharmony_ci* @li Release semaphore.In the disable interrupt context, this API must not be called. Otherwise, uncontrollable
231bd4fe43Sopenharmony_ci*     exception scheduling may result.CNcomment:释放信号量:在关中断上下文禁止调用释放信号量接口,
241bd4fe43Sopenharmony_ci进而产生不可控的异常调度。CNend   \n
251bd4fe43Sopenharmony_ci* Create: 2019-05-29
261bd4fe43Sopenharmony_ci*/
271bd4fe43Sopenharmony_ci
281bd4fe43Sopenharmony_ci/**
291bd4fe43Sopenharmony_ci * @defgroup iot_sem Semaphore
301bd4fe43Sopenharmony_ci * @ingroup osa
311bd4fe43Sopenharmony_ci */
321bd4fe43Sopenharmony_ci#ifndef __HI_SEM_H__
331bd4fe43Sopenharmony_ci#define __HI_SEM_H__
341bd4fe43Sopenharmony_ci#include <hi_types_base.h>
351bd4fe43Sopenharmony_ci
361bd4fe43Sopenharmony_ci#define HI_SEM_ONE  ((hi_u8)1) /**< ucInit Obtained value of the input: Critical resource protection.
371bd4fe43Sopenharmony_ci                                 CNcomment:输入的取值: 临界资源保护 CNend */
381bd4fe43Sopenharmony_ci#define HI_SEM_ZERO ((hi_u8)0) /**< ucInit Obtained value of the input: Synchronization
391bd4fe43Sopenharmony_ci                                 CNcomment:输入的取值: 同步 CNend */
401bd4fe43Sopenharmony_ci
411bd4fe43Sopenharmony_ci/**
421bd4fe43Sopenharmony_ci* @ingroup  iot_sem
431bd4fe43Sopenharmony_ci* @brief  Creates a semaphore.CNcomment:创建信号量。CNend
441bd4fe43Sopenharmony_ci*
451bd4fe43Sopenharmony_ci* @par 描述:
461bd4fe43Sopenharmony_ci*           Creates a semaphore.CNcomment:创建信号量。CNend
471bd4fe43Sopenharmony_ci*
481bd4fe43Sopenharmony_ci* @attention The blocking mode (permanent blocking or timing blocking) of the semaphore application operation cannot
491bd4fe43Sopenharmony_ci*            be used in the interrupt, and the interrupt cannot be blocked.CNcomment:信号量申请操作的阻塞模式
501bd4fe43Sopenharmony_ci(永久阻塞和定时阻塞)不能在中断中使用,中断不能被阻塞。CNend
511bd4fe43Sopenharmony_ci*
521bd4fe43Sopenharmony_ci* @param  sem_id          [OUT] type #hi_u32*,semaphore ID.CNcomment:信号量ID号。CNend
531bd4fe43Sopenharmony_ci* @param  init_value      [IN]  type #hi_u16,Number of initialized valid signals. The value range is [0, 0xFFFF].
541bd4fe43Sopenharmony_ciCNcomment:有效信号的初始化个数,范围为:[0, 0xFFFF]CNend
551bd4fe43Sopenharmony_ci*
561bd4fe43Sopenharmony_ci* @retval #0      Success.
571bd4fe43Sopenharmony_ci* @retval #Other  Failure, for details, see hi_errno.h
581bd4fe43Sopenharmony_ci* @par 依赖:
591bd4fe43Sopenharmony_ci*            @li hi_sem.h:Describes the semaphore APIs.CNcomment:文件用于描述信号量相关接口。CNend
601bd4fe43Sopenharmony_ci* @see  hi_sem_delete。
611bd4fe43Sopenharmony_ci*/
621bd4fe43Sopenharmony_cihi_u32 hi_sem_create(hi_u32 *sem_id, hi_u16 init_value);
631bd4fe43Sopenharmony_ci
641bd4fe43Sopenharmony_ci
651bd4fe43Sopenharmony_ci/**
661bd4fe43Sopenharmony_ci* @ingroup  iot_sem
671bd4fe43Sopenharmony_ci* @brief  Creates a two-value semaphore(0/1).CNcomment:创建二值信号量(0/1)。CNend
681bd4fe43Sopenharmony_ci*
691bd4fe43Sopenharmony_ci* @par 描述:
701bd4fe43Sopenharmony_ci*           Creates a two-value semaphore(0/1).CNcomment:创建二值信号量(0/1)。CNend
711bd4fe43Sopenharmony_ci*
721bd4fe43Sopenharmony_ci* @attention The blocking mode (permanent blocking or timing blocking) of the semaphore application operation cannot
731bd4fe43Sopenharmony_ci*            be used in the interrupt, and the interrupt cannot be blocked.CNcomment:信号量申请操作的阻塞模式
741bd4fe43Sopenharmony_ci(永久阻塞和定时阻塞)不能在中断中使用,中断不能被阻塞。CNend
751bd4fe43Sopenharmony_ci*
761bd4fe43Sopenharmony_ci* @param  sem_id      [OUT] type #hi_u32*,semaphore ID.CNcomment:信号量ID号。CNend
771bd4fe43Sopenharmony_ci* @param  init_value  [IN]  type #hi_u8,initial value. Generally, when the value is HI_SEM_ONE, the API is used for
781bd4fe43Sopenharmony_ci*                     critical resource protection. When the value is HI_SEM_ZERO, the API is used for synchronization.
791bd4fe43Sopenharmony_ciCNcomment:初始值。一般情况下,当值为HI_SEM_ONE时,用作临界资源保护;当值为HI_SEM_ZERO时,用作同步。CNend
801bd4fe43Sopenharmony_ci*
811bd4fe43Sopenharmony_ci* @retval #0      Success.
821bd4fe43Sopenharmony_ci* @retval #Other  Failure, for details, see hi_errno.h
831bd4fe43Sopenharmony_ci* @par 依赖:
841bd4fe43Sopenharmony_ci*            @li hi_sem.h:Describes the semaphore APIs.CNcomment:文件用于描述信号量相关接口。CNend
851bd4fe43Sopenharmony_ci* @see  hi_sem_delete。
861bd4fe43Sopenharmony_ci*/
871bd4fe43Sopenharmony_cihi_u32 hi_sem_bcreate(hi_u32 *sem_id, hi_u8 init_value);
881bd4fe43Sopenharmony_ci
891bd4fe43Sopenharmony_ci/**
901bd4fe43Sopenharmony_ci* @ingroup  iot_sem
911bd4fe43Sopenharmony_ci* @brief  Deletes the semaphore.CNcomment:删除信号量。CNend
921bd4fe43Sopenharmony_ci*
931bd4fe43Sopenharmony_ci* @par 描述:
941bd4fe43Sopenharmony_ci*           Deletes the semaphore.CNcomment:删除信号量。CNend
951bd4fe43Sopenharmony_ci*
961bd4fe43Sopenharmony_ci* @attention The blocking mode (permanent blocking or timing blocking) of the semaphore application operation cannot
971bd4fe43Sopenharmony_ci*            be used in the interrupt, and the interrupt cannot be blocked.CNcomment:信号量申请操作的阻塞模式
981bd4fe43Sopenharmony_ci(永久阻塞和定时阻塞)不能在中断中使用,中断不能被阻塞。CNend
991bd4fe43Sopenharmony_ci*
1001bd4fe43Sopenharmony_ci* @param  sem_id    [IN] type #hi_u32,semaphore ID.CNcomment:信号量ID号。CNend
1011bd4fe43Sopenharmony_ci*
1021bd4fe43Sopenharmony_ci* @retval #0      Success.
1031bd4fe43Sopenharmony_ci* @retval #Other  Failure, for details, see hi_errno.h
1041bd4fe43Sopenharmony_ci* @par 依赖:
1051bd4fe43Sopenharmony_ci*            @li hi_sem.h:Describes the semaphore APIs.CNcomment:文件用于描述信号量相关接口。CNend
1061bd4fe43Sopenharmony_ci* @see  hi_sem_bcreate。
1071bd4fe43Sopenharmony_ci*/
1081bd4fe43Sopenharmony_cihi_u32 hi_sem_delete(hi_u32 sem_id);
1091bd4fe43Sopenharmony_ci
1101bd4fe43Sopenharmony_ci/**
1111bd4fe43Sopenharmony_ci* @ingroup  iot_sem
1121bd4fe43Sopenharmony_ci* @brief  Obtains the semaphore.CNcomment:获取信号量。CNend
1131bd4fe43Sopenharmony_ci*
1141bd4fe43Sopenharmony_ci* @par 描述:
1151bd4fe43Sopenharmony_ci*           Obtains the semaphore.CNcomment:获取信号量。CNend
1161bd4fe43Sopenharmony_ci*
1171bd4fe43Sopenharmony_ci*
1181bd4fe43Sopenharmony_ci* @attention The blocking mode (permanent blocking or timing blocking) of the semaphore application operation cannot
1191bd4fe43Sopenharmony_ci*            be used in the interrupt, and the interrupt cannot be blocked.CNcomment:信号量申请操作的阻塞模式
1201bd4fe43Sopenharmony_ci(永久阻塞和定时阻塞)不能在中断中使用,中断不能被阻塞。CNend
1211bd4fe43Sopenharmony_ci*
1221bd4fe43Sopenharmony_ci* @param  sem_id     [IN] type #hi_u32,semaphore ID.CNcomment:信号量ID号。CNend
1231bd4fe43Sopenharmony_ci* @param  timeout_ms [IN] type #hi_u32,timeout period (unit: ms). HI_SYS_WAIT_FOREVER indicates permanent wait.
1241bd4fe43Sopenharmony_ciCNcomment:超时时间(单位:ms),HI_SYS_WAIT_FOREVER为永久等待。CNend
1251bd4fe43Sopenharmony_ci*
1261bd4fe43Sopenharmony_ci* @retval #0      Success.
1271bd4fe43Sopenharmony_ci* @retval #Other  Failure, for details, see hi_errno.h
1281bd4fe43Sopenharmony_ci* @par 依赖:
1291bd4fe43Sopenharmony_ci*            @li hi_sem.h:Describes the semaphore APIs.CNcomment:文件用于描述信号量相关接口。CNend
1301bd4fe43Sopenharmony_ci* @see  hi_sem_signal。
1311bd4fe43Sopenharmony_ci*/
1321bd4fe43Sopenharmony_cihi_u32 hi_sem_wait(hi_u32 sem_id, hi_u32 timeout_ms);
1331bd4fe43Sopenharmony_ci
1341bd4fe43Sopenharmony_ci/**
1351bd4fe43Sopenharmony_ci* @ingroup  iot_sem
1361bd4fe43Sopenharmony_ci* @brief  Releases the semaphore.CNcomment:释放信号量。CNend
1371bd4fe43Sopenharmony_ci*
1381bd4fe43Sopenharmony_ci* @par 描述:
1391bd4fe43Sopenharmony_ci*           Releases the semaphore.CNcomment:释放信号量。CNend
1401bd4fe43Sopenharmony_ci*
1411bd4fe43Sopenharmony_ci* @attention The blocking mode (permanent blocking or timing blocking) of the semaphore application operation cannot
1421bd4fe43Sopenharmony_ci*            be used in the interrupt, and the interrupt cannot be blocked.CNcomment:信号量申请操作的阻塞模式
1431bd4fe43Sopenharmony_ci(永久阻塞和定时阻塞)不能在中断中使用,中断不能被阻塞。CNend
1441bd4fe43Sopenharmony_ci*
1451bd4fe43Sopenharmony_ci* @param  sem_id    [IN] type #hi_u32,semaphore ID.CNcomment:信号量ID号。CNend
1461bd4fe43Sopenharmony_ci*
1471bd4fe43Sopenharmony_ci* @retval #0      Success.
1481bd4fe43Sopenharmony_ci* @retval #Other  Failure, for details, see hi_errno.h
1491bd4fe43Sopenharmony_ci* @par 依赖:
1501bd4fe43Sopenharmony_ci*            @li hi_sem.h:Describes the semaphore APIs.CNcomment:文件用于描述信号量相关接口。CNend
1511bd4fe43Sopenharmony_ci* @see  hi_sem_wait。
1521bd4fe43Sopenharmony_ci*/
1531bd4fe43Sopenharmony_cihi_u32 hi_sem_signal(hi_u32 sem_id);
1541bd4fe43Sopenharmony_ci
1551bd4fe43Sopenharmony_ci#endif
1561bd4fe43Sopenharmony_ci
157