• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  * Description:  Reboot interface.
15  * Author:
16  * Create:  2018-10-15
17  */
18 
19 #ifndef NON_OS_REBOOT_H
20 #define NON_OS_REBOOT_H
21 
22 #include "core.h"
23 #include "errcode.h"
24 #include "common_def.h"
25 #if EXCEPTION_TEST_ENABLE == YES && defined(SUPPORT_IPC)
26 #include "ipc_actions.h"
27 #endif
28 
29 /**
30  * @defgroup connectivity_drivers_non_os_reboot REBOOT
31  * @ingroup  connectivity_drivers_non_os
32  * @{
33  */
34 #define REBOOT_POWER_ON_TRIGGER_STATUS           0xdead0001UL
35 #define REBOOT_SOFT_RESET_TRIGER_STATUS          0xdead0002UL
36 #define REBOOT_NMI_WDGTIMEOUT_TRIGGER_STATUS     0xdead0003UL
37 #define REBOOT_NMI_XIP_CTRL_TRIGER_STATUS        0xdead0004UL
38 #define REBOOT_NMI_XIP_CACHE_TRIGGER_STATUS      0xdead0005UL
39 #define REBOOT_HARD_FAULT_TRIGER_STATUS          0xdead0006UL
40 #define REBOOT_SOFT_PANIC_TRIGGER_STATUS         0xdead0007UL
41 #define REBOOT_OTHER_CORE_ABNORMAL_TRIGER_STATUS 0xdead0008UL
42 #define REBOOT_HARD_WDGTIMEOUT_TRIGER_STATUS     0xdead0009UL
43 #define REBOOT_BT_WDGTIMEOUT_TRIGER_STATUS       0xdead000aUL
44 #define REBOOT_ULP_WDGTIMEOUT_TRIGER_STATUS      0xdead000bUL
45 #define REBOOT_UPG_COMPLETION_TRIGER_STATUS      0xdead000cUL
46 #define REBOOT_ULP_PIN_RST_TRIGER_STATUS         0xdead000dUL
47 #define REBOOT_UNDEFINED_TRIGER_STATUS           0xdeadaaaaUL
48 #define STANDARD_REBOOT_MAGIC                    0xdeaddeadUL
49 #define ABNORMAL_REBOOT_MAGIC                    0xdeadbeafUL
50 
51 /**
52  * @brief  This is a special enum, it is split into three sections
53  * Only 16 bits are used.
54  * Bits 13 to 15 are flags setting which core caused the reboot
55  * Bit 8 sets if the reset reason is custom or fixed
56  * Bits 0 to 7 contain the reason
57  */
58 typedef enum {
59     REBOOT_CAUSE_UNKNOWN = 0x0000,                 // !< Used as a default for the reboot_reset_reason variable
60     REBOOT_CAUSE_BT_RESET_UNKNOWN = 0x8000,  // !< REBOOT_CAUSE_BT_RESET_UNKNOWN
61     REBOOT_CAUSE_BT_SYSRESETREQ = 0x8001,
62     REBOOT_CAUSE_BT_WATCHDOG = 0x8002,
63     REBOOT_CAUSE_BT_STANDARD_CHIP_WATCHDOG = 0x8004,
64     REBOOT_CAUSE_BT_UPDATER_CHIP_WATCHDOG = 0x8005,
65     REBOOT_CAUSE_BT_RPC_TIMEOUT = 0x8006,
66     REBOOT_CAUSE_BT_HARDFAULT = 0x8007,
67     REBOOT_CAUSE_BT_NNMIFAULT = 0x8008,
68     REBOOT_CAUSE_BT_UNKNOWN_ISR = 0x8009,
69     REBOOT_CAUSE_BT_PANIC = 0x800a,
70     REBOOT_CAUSE_BT_STD_WDT_FRST = 0x800b,         /* force reboot */
71     REBOOT_CAUSE_BT_STD_CHIP_WDT_FRST = 0x800c,    /* force reboot */
72     REBOOT_CAUSE_BT_XIP_HARDFAULT = 0x800d,
73     REBOOT_CAUSE_BT_SSB_EXCEPTION_REBOOT = 0x800e,
74     REBOOT_CAUSE_BT_BUCK1_PROTECT_FRST = 0x8010,   /* buck1 protect */
75     REBOOT_CAUSE_BT_BUCK2_PROTECT_FRST = 0x8020,   /* buck2 protect */
76 
77     REBOOT_CAUSE_BT_MONITOR_REBOOT_REQ = 0x8100,   // !< Start of custom reset reasons
78     REBOOT_CAUSE_BT_REGIONS_UPDATED = 0x8101,
79     REBOOT_CAUSE_BT_FOTA_UPGRADE = 0x8102,
80     REBOOT_CAUSE_BT_END = REBOOT_CAUSE_BT_FOTA_UPGRADE + 1,
81 
82     REBOOT_CAUSE_GNSS_GLOBAL = 0x7000,
83     REBOOT_CAUSE_GNSS_NMI = 0x7001,        // !< watchdog is nmi interrupt
84     REBOOT_CAUSE_GNSS_HARDFAULT = 0x7002,
85     REBOOT_CAUSE_GNSS_PANIC = 0x7003,
86     REBOOT_CAUSE_GNSS_END = REBOOT_CAUSE_GNSS_PANIC + 1,
87 
88     REBOOT_CAUSE_PROTOCOL_GLOBAL = 0x4000,
89     REBOOT_CAUSE_PROTOCOL_SYSRESETREQ = 0x4001,
90     REBOOT_CAUSE_PROTOCOL_WATCHDOG = 0x4002,
91     REBOOT_CAUSE_PROTOCOL_AXI_LOCK = 0x4003,
92     REBOOT_CAUSE_PROTOCOL_AXI_LOCK_TO_BT = 0x4004,
93     REBOOT_CAUSE_PROTOCOL_WDT_FRST = 0x4005,             /* force reboot */
94     REBOOT_CAUSE_PROTOCOL1_WATCHDOG = 0x4006,
95     REBOOT_CAUSE_PROTOCOL_ADDR_MON = 0x4007,
96     REBOOT_CAUSE_PROTOCOL1_ADDR_MON = 0x4008,
97     REBOOT_CAUSE_PROTOCOL_RPC_TIMEOUT = 0x4100,          // !< Start of custom reset reasons
98     REBOOT_CAUSE_PROTOCOL_END = REBOOT_CAUSE_PROTOCOL_RPC_TIMEOUT + 1,
99 
100     REBOOT_CAUSE_APPLICATION_GLOBAL = 0x2000,
101     REBOOT_CAUSE_APPLICATION_SYSRESETREQ = 0x2001,
102     REBOOT_CAUSE_APPLICATION_WATCHDOG = 0x2002,
103     REBOOT_CAUSE_APPLICATION_PANIC = 0x2003,
104     REBOOT_CAUSE_APPLICATION_HARDFAULT = 0x2004,
105     REBOOT_CAUSE_APPLICATION_NNMIFAULT = 0x2005,
106     REBOOT_CAUSE_APPLICATION_UNKNOWN_ISR = 0x2006,
107     REBOOT_CAUSE_APPLICATION_WDT_FRST = 0x2007,          /* force reboot */
108     REBOOT_CAUSE_APPLICATION_CHIP_WDT = 0x2008,
109     REBOOT_CAUSE_APPLICATION_XIP_CTRL = 0x2009,
110     REBOOT_CAUSE_APPLICATION_XIP_CACHE = 0x200a,
111     REBOOT_CAUSE_APPLICATION_MDMA = 0x200b,
112     REBOOT_CAUSE_APPLICATION_SMDMA = 0x200c,
113     REBOOT_CAUSE_APPLICATION_STD_CHIP_WDT_FRST = 0x200d,
114     REBOOT_CAUSE_APPLICATION_STD_BT_WDT_FRST = 0x200e,
115     REBOOT_CAUSE_APPLICATION_STD_ULP_WDT_FRST = 0x200f,
116     REBOOT_CAUSE_APPLICATION_STD_ULP_PIN_FRST = 0x2010,
117 
118     REBOOT_CAUSE_UPG_COMPLETION = 0x2040, // !< Start of custom reset reasons
119     REBOOT_CAUSE_MON_MEM_ALMOST_EMPTY = 0x2041,
120     REBOOT_CAUSE_DFU_UPG_FAIL = 0x2042,
121 
122     REBOOT_CAUSE_APPLICATION_SLDM = 0x2080,
123 
124     REBOOT_CAUSE_APPLICATION_RPC_TIMEOUT = 0x2100,       // !< Start of custom reset reasons
125 
126     REBOOT_CAUSE_POWER_ON = 0xF0F0,
127 } reboot_cause_t;
128 
129 typedef enum {
130     VETO_REBOOT_REASON_RESERVE,
131     VETO_REBOOT_REASON_WR_NV,     /* 写NV项过程中,在超时内,不强制重启 */
132     VETO_REBOOT_REASON_WR_MR_DOC, /* 写表档案过程中,在超时内,不强制重启 */
133     VETO_REBOOT_REASON_USR_RESERVED_2,
134     VETO_REBOOT_REASON_USR_RESERVED_3,
135     VETO_REBOOT_REASON_USR_RESERVED_4,
136     VETO_REBOOT_REASON_USR_RESERVED_5,
137     VETO_REBOOT_REASON_USR_RESERVED_6,
138     VETO_REBOOT_REASON_USR_RESERVED_7,
139 
140     /* STA在抄控器对其做整表测试时,不允许重启 */
141     VETO_REBOOT_REASON_NDM_METER_CHECK,
142     /* 台区识别时不允许重启 */
143     VETO_REBOOT_REASON_TF_IDENTIFY,
144     /* STA上电11小时内,锁定网络状态下,不允许重启 */
145     VETO_REBOOT_REASON_LOCK_NETWORK,
146     /* 进入测试模式后 24 小时内不允许重启 */
147     VETO_REBOOT_REASON_SYS_RST_DELAY_ENTER_PHY_TEST_MODE,
148     VETO_REBOOT_REASON_UPG, /* 升级过程中, 不强制重启。 */
149     VETO_REBOOT_REASON_BOOT_UPG,
150     VETO_REBOOT_REASON_NO_PB, /* 无法收到PB块,导致频偏设置长时间超时(1000分钟),不强制重启 */
151 
152     /* CCO在写组网系列号的时候,不允许重启; */
153     VETO_REBOOT_REASON_SUIT_NET,
154     /* CCO/STA在写SNID的时候,不允许重启; */
155     VETO_REBOOT_REASON_WRT_SNID,
156     /* STA在写关联随机数的时候,不允许重启 */
157     VETO_REBOOT_REASON_RELATING_RANDOM_NUM,
158     VETO_REBOOT_REASON_MAX
159 } veto_reboot_reason_t;
160 
161 #ifdef IPC_NEW
162 typedef struct {
163     uint16_t req_reboot_reason;
164     uint16_t core;
165 } req_reboot_msg;
166 #endif
167 
168 /**
169  * @brief  Initialise the reboot subsystem
170  * @return None
171  */
172 void reboot_init(void);
173 
174 /**
175  * @brief  De-initialise the reboot subsystem
176  * @return None
177  */
178 void reboot_deinit(void);
179 
180 #if CORE == MASTER_BY_ALL
181 /**
182  * @brief  Perform a chip reboot.
183  * @return None
184  */
185 void reboot_chip(void);
186 
187 /**
188  * @brief  Gets the last reason that the security core rebooted
189  * @return The reason, or REBOOT_CAUSE_UNKNOWN if there is more than 1 reason
190  */
191 reboot_cause_t reboot_get_security_reboot_reason(void);
192 #endif
193 
194 /**
195  * @brief  Perform a software reboot of the entire system.
196  * @param  cause The reason we are asking for a chip reset, bits 8 to 15 are ignored as this command
197  *              can only set a custom reboot for this core
198  * @return None
199  */
200 void reboot_system(reboot_cause_t cause);
201 
202 /**
203  * @brief  Gets the reason of the last reset
204  * @return The reason we last reset
205  */
206 reboot_cause_t reboot_get_reset_reason(void);
207 
208 #if CORE == APPS && EXCEPTION_TEST_ENABLE == YES && defined(SUPPORT_IPC)
209 /**
210  * @brief  send a exceptin test command to bt core.
211  * @param  exception_test_command The exception test comand
212  * @return None
213  */
214 void exception_test(ipc_exception_test_command_e exception_test_command);
215 #endif
216 
217 /*
218 * @brief 延时重启,在一段时间内投票反对重启,仅影响uapi_reboot_system_check_veto接口。
219 * @param reason 延时原因
220 * @param sec 延时时间
221 * @retval 返回实际延时时间。如果系统未对最大延时时间进行配置返回传入时间。如果系统进行了限制则返回时间小于最大延时时间。
222 */
223 uint32_t uapi_reboot_vote_against(veto_reboot_reason_t reason, uint32_t sec);
224 
225 /*
226 * @brief 去延时重启
227 * @param reason 延时原因
228 * @retval 返回实际延时时间。如果系统未对最大延时时间进行配置返回传入时间。如果系统进行了限制则返回时间小于最大延时时间。
229 */
230 void uapi_reboot_unvote_against(veto_reboot_reason_t reason);
231 
232 /*
233 * @brief 重启。受延时重启影响
234 * @param reason 重启原因
235 */
236 void uapi_reboot_system_check_veto(reboot_cause_t reason);
237 
238 /**
239  * @}
240  */
241 #endif
242