1/** 2 * @file hi_reset.h 3 * 4 * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED. 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18/** @defgroup iot_sys Active Reset 19 * @ingroup system 20 */ 21 22#ifndef __HI_RESET_H__ 23#define __HI_RESET_H__ 24#include <hi_types.h> 25#include <hi_mdm_types.h> 26#include <hi_ft_nv.h> 27 28#ifdef __cplusplus 29extern "C" { 30#endif 31 32#define HI_SYS_REBOOT_CAUSE_USR_BEGIN 0x8000 33#define HI_SYS_REBOOT_CAUSE_USR_END 63 /* 8bit: 0 - 63 */ 34 35/** 36* @ingroup iot_sys 37* 38* Cause for active restart. CNcomment:主动重启原因CNend 39*/ 40typedef enum { 41 HI_SYS_REBOOT_CAUSE_UNKNOWN = 0, 42 HI_SYS_REBOOT_CAUSE_CMD, /**< system reset begin. */ 43 HI_SYS_REBOOT_CAUSE_UPG, /**< upgrade reset begin. */ 44 HI_SYS_REBOOT_CAUSE_UPG_B, /**< upgrade backup image reset. */ 45 HI_SYS_REBOOT_CAUSE_WIFI_MODE, /**< wifi module reset begin. */ 46 HI_SYS_REBOOT_CAUSE_USR_NORMAL_REBOOT, /**< user reset begin. */ 47 HI_SYS_REBOOT_CAUSE_USR0, 48 HI_SYS_REBOOT_CAUSE_USR1, 49 HI_SYS_REBOOT_CAUSE_AT_BUSY, 50 HI_SYS_REBOOT_CAUSE_MAX = HI_SYS_REBOOT_CAUSE_USR_END + 1, 51} hi_sys_reboot_cause; 52 53/** 54* @ingroup iot_sys 55* @brief System hard reboot. CNcomment:系统硬重启。CNend 56* 57* @par 描述: 58* System Hard reboot:reset whole chip. CNcomment:硬重启 :整芯片复位。CNend 59* 60* @attention None 61* 62* @param cause [IN] type #hi_sys_reboot_cause , reboot cause, see hi_sys_reboot_cause. 63CNcomment:重启原因,取值参见hi_sys_reboot_cause。CNend 64* 65* 66* @retval None. 67* 68* @par 依赖: 69* @li hi_reset.h: Describes the APIs for obtaining system information. 70CNcomment:文件用于描述系统复位相关接口。CNend 71* @see None 72*/ 73hi_void hi_hard_reboot(hi_sys_reboot_cause cause); 74 75/** 76* @ingroup iot_sys 77* @brief System soft reboot. CNcomment:系统软重启。CNend 78* 79* @par 描述: 80* System Soft reboot:part of peripheral won't reset(such as GPIO/PWM). 81CNcomment:软重启:部分外设不复位,如GPIO/PWM。CNend 82* @attention 83* @li only GPIO is the default peripheral that won't reset when soft reboot. 84PWM should config in menuconfig. other peripheras need another setting. 85CNcomment:仅GPIO在软重启时默认不复位,PWM需要在menuconfig中配置, 86其余外设需要额外配置。CNend 87* 88* @param cause [IN] type #hi_sys_reboot_cause , reboot cause, see hi_sys_reboot_cause. 89CNcomment:重启原因,取值参见hi_sys_reboot_cause。CNend 90* 91* 92* @retval None. 93* 94* @par 依赖: 95* @li hi_reset.h: Describes the APIs for obtaining system information. 96CNcomment:文件用于描述系统复位相关接口。CNend 97* @see None 98*/ 99hi_void hi_soft_reboot(hi_sys_reboot_cause cause); 100 101/** 102* @ingroup iot_sys 103* @brief Enables or disables the function of recording the reset times. 104CNcomment:使能(去使能)记录复位次数功能。CNend 105* 106* @par 描述: 107* @li Enables or disables the function of recording the reset times. When the function of recording the reset times 108* is enabled, in order to avoid the issue that fast flash life exhaustion caused by writing NV when the system 109* is frequently powered on and off, NV will be written 30 seconds after the system is started. 110CNcomment:使能(去使能)记录复位次数功能。使能复位次数记录功能后, 111为避免系统经常频繁上下电时写NV导致flash寿命快速耗尽问题,每次启动时会在上电后30秒时写NV,正常计数复位次数。CNend 112* @li When the number of reset times is updated, the flash memory needs to be written. Generally, when the system 113* frequently powers on and off and power-on NV write greatly hurts the flash service life, set enable to 114* HI_FALSE and check whether the service function is affected. 115CNcomment:复位次数更新需要执行写Flash操作,通常在系统经常频繁上下电, 116不能接受上电写NV导致flash寿命快速耗尽的场景时,将enable设置为HI_FALSE, 117同时要考虑是否对业务功能造成影响。CNend 118* @li Set enable takes effect after the next reset, and set disable takes effect when write NV next time. 119CNcomment:配置开启是在下次复位后生效,配置关闭是在下次写NV时生效。CNend 120* 121* @attention 122* @li This feature should be disable by default. CNcomment:该功能默认不使能。CNend 123* @li It should be called in the initialization function of the app layer. 124CNcomment:应该在应用层初始化函数中调用。CNend 125* @li Disabling this function may result in some influences. You are advised to disable it in scenarios where the 126* system is frequently powered on and off.CNcomment:关闭该功能需要考虑对使用复位次数业务功能 127的影响,建议在系统经常频繁上下电的场景关闭该功能,其他场景打开该功能。CNend 128* 129* @param enable [IN] type #hi_bool Enable/Disable. CNcomment:是否使能计数功能。CNend 130* 131* @retval #0 Success. 132* @retval #Other Failure. For details, see hi_errno.h. 133* 134* @par 依赖: 135* @li hi_reset.h: Describes the APIs for obtaining system information. 136CNcomment:文件用于描述系统复位相关接口。CNend 137* @see None 138*/ 139hi_u32 hi_enable_reset_times_save(hi_bool enable); 140 141/** 142* @ingroup iot_sys 143* @brief Obtains reset times recorded in NV. CNcomment:获取NV中记录的系统复位次数。CNend 144* 145* @par 描述: 146* Obtains reset times recorded in NV. CNcomment:获取NV中记录的系统复位次数。CNend 147* 148* @attention None 149* 150* @param None 151* 152* @retval #HI_ERR_FAILURE Read NV Failure. 153* @retval #Other Reboot times number. CNcomment:系统复位次数。CNend 154* 155* @par 依赖: 156* @li hi_reset.h: Describes the APIs for obtaining system information. 157CNcomment:文件用于描述系统复位相关接口。CNend 158* @see None 159*/ 160hi_u32 hi_get_reset_times(hi_void); 161 162#ifdef __cplusplus 163} 164#endif 165 166#endif /* __HI_RESET_H__ */ 167 168