• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
3  * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice, this list of
9  *    conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice, this list
12  *    of conditions and the following disclaimer in the documentation and/or other materials
13  *    provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its contributors may be used
16  *    to endorse or promote products derived from this software without specific prior written
17  *    permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #include "los_config.h"
33 #ifdef LOSCFG_SHELL
34 #include "shcmd.h"
35 #include "shell.h"
36 #endif
37 #include "los_swtmr_pri.h"
38 
39 
40 #ifdef LOSCFG_SHELL_CMD_DEBUG
41 STATIC BOOL systemExcReset = FALSE;
42 
OsSystemExcIsReset(VOID)43 LITE_OS_SEC_TEXT_MINOR BOOL OsSystemExcIsReset(VOID)
44 {
45     return systemExcReset;
46 }
47 #ifdef LOSCFG_DRIVERS_HDF_PLATFORM_WATCHDOG
48 #include "watchdog_if.h"
49 
50 #define WATCHDOG_TIMER_INTERVAL 5 // 5 seconds
51 #define WATCHDOG_TIMER_INTERVAL_HALF (WATCHDOG_TIMER_INTERVAL / 2)
52 
53 STATIC UINT16 g_swtmrID;
54 STATIC BOOL g_wdStarted = FALSE;
55 STATIC DevHandle g_wdHandle;
56 
StartWatchdog(void)57 STATIC void StartWatchdog(void)
58 {
59     int32_t ret;
60     if (g_wdStarted) {
61         return;
62     }
63 
64     ret = WatchdogOpen(0, &g_wdHandle);
65     if (ret != HDF_SUCCESS) {
66         return;
67     }
68     WatchdogSetTimeout(g_wdHandle, WATCHDOG_TIMER_INTERVAL);
69 
70     if (LOS_SwtmrCreate(LOSCFG_BASE_CORE_TICK_PER_SECOND * WATCHDOG_TIMER_INTERVAL_HALF, LOS_SWTMR_MODE_PERIOD,
71                         (SWTMR_PROC_FUNC)WatchdogFeed, &g_swtmrID, (UINTPTR)g_wdHandle) != LOS_OK) {
72         WatchdogClose(g_wdHandle);
73         g_wdHandle = NULL;
74         return;
75     }
76 
77     WatchdogStart(g_wdHandle);
78     LOS_SwtmrStart(g_swtmrID);
79     g_wdStarted = TRUE;
80 }
81 
StopWatchdog(void)82 STATIC void StopWatchdog(void)
83 {
84     if (!g_wdStarted) {
85         return;
86     }
87 
88     LOS_SwtmrStop(g_swtmrID);
89     LOS_SwtmrDelete(g_swtmrID);
90     g_swtmrID = 0;
91 
92     WatchdogStop(g_wdHandle);
93     WatchdogClose(g_wdHandle);
94     g_wdHandle = NULL;
95 
96     g_wdStarted = FALSE;
97 }
98 
OsShellCmdSystemExcReset(INT32 argc,const CHAR ** argv)99 LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdSystemExcReset(INT32 argc, const CHAR **argv)
100 {
101     if (argc != 1) {
102         goto EXC_RESET_HELP;
103     }
104 
105     if (strcmp(argv[0], "on") == 0) {
106         systemExcReset = TRUE;
107         StartWatchdog();
108         PRINTK("panicreset on!\n");
109         return LOS_OK;
110     }
111 
112     if (strcmp(argv[0], "off") == 0) {
113         systemExcReset = FALSE;
114         StopWatchdog();
115         PRINTK("panicreset off!\n");
116         return LOS_OK;
117     }
118 
119 EXC_RESET_HELP:
120     PRINTK("usage: panicreset [on/off]\n");
121     return LOS_OK;
122 }
123 
124 SHELLCMD_ENTRY(panic_reset_shellcmd, CMD_TYPE_EX, "panicreset", 1, (CmdCallBackFunc)OsShellCmdSystemExcReset);
125 #endif
126 #endif
127 
128