11bd4fe43Sopenharmony_ci/**
21bd4fe43Sopenharmony_ci * @file hi_reset.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
181bd4fe43Sopenharmony_ci/** @defgroup iot_sys  Active Reset
191bd4fe43Sopenharmony_ci * @ingroup system
201bd4fe43Sopenharmony_ci */
211bd4fe43Sopenharmony_ci
221bd4fe43Sopenharmony_ci#ifndef __HI_RESET_H__
231bd4fe43Sopenharmony_ci#define __HI_RESET_H__
241bd4fe43Sopenharmony_ci#include <hi_types.h>
251bd4fe43Sopenharmony_ci#include <hi_mdm_types.h>
261bd4fe43Sopenharmony_ci#include <hi_ft_nv.h>
271bd4fe43Sopenharmony_ci
281bd4fe43Sopenharmony_ci#ifdef __cplusplus
291bd4fe43Sopenharmony_ciextern "C" {
301bd4fe43Sopenharmony_ci#endif
311bd4fe43Sopenharmony_ci
321bd4fe43Sopenharmony_ci#define HI_SYS_REBOOT_CAUSE_USR_BEGIN   0x8000
331bd4fe43Sopenharmony_ci#define HI_SYS_REBOOT_CAUSE_USR_END     63 /* 8bit: 0 - 63 */
341bd4fe43Sopenharmony_ci
351bd4fe43Sopenharmony_ci/**
361bd4fe43Sopenharmony_ci* @ingroup  iot_sys
371bd4fe43Sopenharmony_ci*
381bd4fe43Sopenharmony_ci* Cause for active restart. CNcomment:主动重启原因CNend
391bd4fe43Sopenharmony_ci*/
401bd4fe43Sopenharmony_citypedef enum {
411bd4fe43Sopenharmony_ci    HI_SYS_REBOOT_CAUSE_UNKNOWN = 0,
421bd4fe43Sopenharmony_ci    HI_SYS_REBOOT_CAUSE_CMD,        /**< system reset begin. */
431bd4fe43Sopenharmony_ci    HI_SYS_REBOOT_CAUSE_UPG,        /**< upgrade reset begin. */
441bd4fe43Sopenharmony_ci    HI_SYS_REBOOT_CAUSE_UPG_B,      /**< upgrade backup image reset. */
451bd4fe43Sopenharmony_ci    HI_SYS_REBOOT_CAUSE_WIFI_MODE,  /**< wifi module reset begin. */
461bd4fe43Sopenharmony_ci    HI_SYS_REBOOT_CAUSE_USR_NORMAL_REBOOT, /**< user reset begin. */
471bd4fe43Sopenharmony_ci    HI_SYS_REBOOT_CAUSE_USR0,
481bd4fe43Sopenharmony_ci    HI_SYS_REBOOT_CAUSE_USR1,
491bd4fe43Sopenharmony_ci    HI_SYS_REBOOT_CAUSE_AT_BUSY,
501bd4fe43Sopenharmony_ci    HI_SYS_REBOOT_CAUSE_MAX = HI_SYS_REBOOT_CAUSE_USR_END + 1,
511bd4fe43Sopenharmony_ci} hi_sys_reboot_cause;
521bd4fe43Sopenharmony_ci
531bd4fe43Sopenharmony_ci/**
541bd4fe43Sopenharmony_ci* @ingroup  iot_sys
551bd4fe43Sopenharmony_ci* @brief  System hard reboot. CNcomment:系统硬重启。CNend
561bd4fe43Sopenharmony_ci*
571bd4fe43Sopenharmony_ci* @par 描述:
581bd4fe43Sopenharmony_ci*          System Hard reboot:reset whole chip. CNcomment:硬重启 :整芯片复位。CNend
591bd4fe43Sopenharmony_ci*
601bd4fe43Sopenharmony_ci* @attention  None
611bd4fe43Sopenharmony_ci*
621bd4fe43Sopenharmony_ci* @param  cause         [IN] type #hi_sys_reboot_cause , reboot cause, see hi_sys_reboot_cause.
631bd4fe43Sopenharmony_ciCNcomment:重启原因,取值参见hi_sys_reboot_cause。CNend
641bd4fe43Sopenharmony_ci*
651bd4fe43Sopenharmony_ci*
661bd4fe43Sopenharmony_ci* @retval None.
671bd4fe43Sopenharmony_ci*
681bd4fe43Sopenharmony_ci* @par 依赖:
691bd4fe43Sopenharmony_ci*            @li hi_reset.h: Describes the APIs for obtaining system information.
701bd4fe43Sopenharmony_ciCNcomment:文件用于描述系统复位相关接口。CNend
711bd4fe43Sopenharmony_ci* @see None
721bd4fe43Sopenharmony_ci*/
731bd4fe43Sopenharmony_cihi_void hi_hard_reboot(hi_sys_reboot_cause cause);
741bd4fe43Sopenharmony_ci
751bd4fe43Sopenharmony_ci/**
761bd4fe43Sopenharmony_ci* @ingroup  iot_sys
771bd4fe43Sopenharmony_ci* @brief  System soft reboot. CNcomment:系统软重启。CNend
781bd4fe43Sopenharmony_ci*
791bd4fe43Sopenharmony_ci* @par 描述:
801bd4fe43Sopenharmony_ci*          System Soft reboot:part of peripheral won't reset(such as GPIO/PWM).
811bd4fe43Sopenharmony_ciCNcomment:软重启:部分外设不复位,如GPIO/PWM。CNend
821bd4fe43Sopenharmony_ci* @attention
831bd4fe43Sopenharmony_ci*           @li only GPIO is the default peripheral that won't reset when soft reboot.
841bd4fe43Sopenharmony_ciPWM should config in menuconfig. other peripheras need another setting.
851bd4fe43Sopenharmony_ciCNcomment:仅GPIO在软重启时默认不复位,PWM需要在menuconfig中配置,
861bd4fe43Sopenharmony_ci其余外设需要额外配置。CNend
871bd4fe43Sopenharmony_ci*
881bd4fe43Sopenharmony_ci* @param  cause         [IN] type #hi_sys_reboot_cause ,  reboot cause, see hi_sys_reboot_cause.
891bd4fe43Sopenharmony_ciCNcomment:重启原因,取值参见hi_sys_reboot_cause。CNend
901bd4fe43Sopenharmony_ci*
911bd4fe43Sopenharmony_ci*
921bd4fe43Sopenharmony_ci* @retval None.
931bd4fe43Sopenharmony_ci*
941bd4fe43Sopenharmony_ci* @par 依赖:
951bd4fe43Sopenharmony_ci*            @li hi_reset.h: Describes the APIs for obtaining system information.
961bd4fe43Sopenharmony_ciCNcomment:文件用于描述系统复位相关接口。CNend
971bd4fe43Sopenharmony_ci* @see None
981bd4fe43Sopenharmony_ci*/
991bd4fe43Sopenharmony_cihi_void hi_soft_reboot(hi_sys_reboot_cause cause);
1001bd4fe43Sopenharmony_ci
1011bd4fe43Sopenharmony_ci/**
1021bd4fe43Sopenharmony_ci* @ingroup  iot_sys
1031bd4fe43Sopenharmony_ci* @brief  Enables or disables the function of recording the reset times.
1041bd4fe43Sopenharmony_ciCNcomment:使能(去使能)记录复位次数功能。CNend
1051bd4fe43Sopenharmony_ci*
1061bd4fe43Sopenharmony_ci* @par 描述:
1071bd4fe43Sopenharmony_ci*     @li Enables or disables the function of recording the reset times. When the function of recording the reset times
1081bd4fe43Sopenharmony_ci*         is enabled, in order to avoid the issue that fast flash life exhaustion caused by writing NV when the system
1091bd4fe43Sopenharmony_ci*         is frequently powered on and off, NV will be written 30 seconds after the system is started.
1101bd4fe43Sopenharmony_ciCNcomment:使能(去使能)记录复位次数功能。使能复位次数记录功能后,
1111bd4fe43Sopenharmony_ci为避免系统经常频繁上下电时写NV导致flash寿命快速耗尽问题,每次启动时会在上电后30秒时写NV,正常计数复位次数。CNend
1121bd4fe43Sopenharmony_ci*     @li When the number of reset times is updated, the flash memory needs to be written. Generally, when the system
1131bd4fe43Sopenharmony_ci*         frequently powers on and off and power-on NV write greatly hurts the flash service life, set enable to
1141bd4fe43Sopenharmony_ci*         HI_FALSE and check whether the service function is affected.
1151bd4fe43Sopenharmony_ciCNcomment:复位次数更新需要执行写Flash操作,通常在系统经常频繁上下电,
1161bd4fe43Sopenharmony_ci不能接受上电写NV导致flash寿命快速耗尽的场景时,将enable设置为HI_FALSE,
1171bd4fe43Sopenharmony_ci同时要考虑是否对业务功能造成影响。CNend
1181bd4fe43Sopenharmony_ci*     @li Set enable takes effect after the next reset, and set disable takes effect when write NV next time.
1191bd4fe43Sopenharmony_ciCNcomment:配置开启是在下次复位后生效,配置关闭是在下次写NV时生效。CNend
1201bd4fe43Sopenharmony_ci*
1211bd4fe43Sopenharmony_ci* @attention
1221bd4fe43Sopenharmony_ci*   @li This feature should be disable by default. CNcomment:该功能默认不使能。CNend
1231bd4fe43Sopenharmony_ci*   @li It should be called in the initialization function of the app layer.
1241bd4fe43Sopenharmony_ciCNcomment:应该在应用层初始化函数中调用。CNend
1251bd4fe43Sopenharmony_ci*   @li Disabling this function may result in some influences. You are advised to disable it in scenarios where the
1261bd4fe43Sopenharmony_ci*       system is frequently powered on and off.CNcomment:关闭该功能需要考虑对使用复位次数业务功能
1271bd4fe43Sopenharmony_ci的影响,建议在系统经常频繁上下电的场景关闭该功能,其他场景打开该功能。CNend
1281bd4fe43Sopenharmony_ci*
1291bd4fe43Sopenharmony_ci* @param enable [IN] type #hi_bool Enable/Disable. CNcomment:是否使能计数功能。CNend
1301bd4fe43Sopenharmony_ci*
1311bd4fe43Sopenharmony_ci* @retval #0               Success.
1321bd4fe43Sopenharmony_ci* @retval #Other           Failure. For details, see hi_errno.h.
1331bd4fe43Sopenharmony_ci*
1341bd4fe43Sopenharmony_ci* @par 依赖:
1351bd4fe43Sopenharmony_ci*            @li hi_reset.h: Describes the APIs for obtaining system information.
1361bd4fe43Sopenharmony_ciCNcomment:文件用于描述系统复位相关接口。CNend
1371bd4fe43Sopenharmony_ci* @see None
1381bd4fe43Sopenharmony_ci*/
1391bd4fe43Sopenharmony_cihi_u32 hi_enable_reset_times_save(hi_bool enable);
1401bd4fe43Sopenharmony_ci
1411bd4fe43Sopenharmony_ci/**
1421bd4fe43Sopenharmony_ci* @ingroup  iot_sys
1431bd4fe43Sopenharmony_ci* @brief  Obtains reset times recorded in NV. CNcomment:获取NV中记录的系统复位次数。CNend
1441bd4fe43Sopenharmony_ci*
1451bd4fe43Sopenharmony_ci* @par 描述:
1461bd4fe43Sopenharmony_ci*          Obtains reset times recorded in NV. CNcomment:获取NV中记录的系统复位次数。CNend
1471bd4fe43Sopenharmony_ci*
1481bd4fe43Sopenharmony_ci* @attention  None
1491bd4fe43Sopenharmony_ci*
1501bd4fe43Sopenharmony_ci* @param None
1511bd4fe43Sopenharmony_ci*
1521bd4fe43Sopenharmony_ci* @retval #HI_ERR_FAILURE  Read NV Failure.
1531bd4fe43Sopenharmony_ci* @retval #Other           Reboot times number. CNcomment:系统复位次数。CNend
1541bd4fe43Sopenharmony_ci*
1551bd4fe43Sopenharmony_ci* @par 依赖:
1561bd4fe43Sopenharmony_ci*            @li hi_reset.h: Describes the APIs for obtaining system information.
1571bd4fe43Sopenharmony_ciCNcomment:文件用于描述系统复位相关接口。CNend
1581bd4fe43Sopenharmony_ci* @see None
1591bd4fe43Sopenharmony_ci*/
1601bd4fe43Sopenharmony_cihi_u32 hi_get_reset_times(hi_void);
1611bd4fe43Sopenharmony_ci
1621bd4fe43Sopenharmony_ci#ifdef __cplusplus
1631bd4fe43Sopenharmony_ci}
1641bd4fe43Sopenharmony_ci#endif
1651bd4fe43Sopenharmony_ci
1661bd4fe43Sopenharmony_ci#endif /* __HI_RESET_H__ */
1671bd4fe43Sopenharmony_ci
168