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_CMD_DEBUG
34 #include "stdlib.h"
35 #include "los_swtmr_pri.h"
36 #include "shcmd.h"
37 #include "shell.h"
38
39
40 #define SWTMR_STRLEN 12
41
42 LITE_OS_SEC_DATA_MINOR STATIC CHAR g_shellSwtmrMode[][SWTMR_STRLEN] = {
43 "Once",
44 "Period",
45 "NSD",
46 "OPP",
47 };
48
49 LITE_OS_SEC_DATA_MINOR STATIC CHAR g_shellSwtmrStatus[][SWTMR_STRLEN] = {
50 "UnUsed",
51 "Created",
52 "Ticking",
53 };
54
OsPrintSwtmrMsg(const SWTMR_CTRL_S * swtmr)55 STATIC VOID OsPrintSwtmrMsg(const SWTMR_CTRL_S *swtmr)
56 {
57 UINT32 ticks = 0;
58 (VOID)LOS_SwtmrTimeGet(swtmr->usTimerID, &ticks);
59
60 PRINTK("0x%08x "
61 "%-7s "
62 "%-6s "
63 "%-6u "
64 "%-6u "
65 "0x%08x "
66 "%p\n",
67 swtmr->usTimerID % LOSCFG_BASE_CORE_SWTMR_LIMIT,
68 g_shellSwtmrStatus[swtmr->ucState],
69 g_shellSwtmrMode[swtmr->ucMode],
70 swtmr->uwInterval,
71 ticks,
72 swtmr->uwArg,
73 swtmr->pfnHandler);
74 }
75
OsPrintSwtmrMsgHead(VOID)76 STATIC INLINE VOID OsPrintSwtmrMsgHead(VOID)
77 {
78 PRINTK("\r\nSwTmrID State Mode Interval Count Arg handlerAddr\n");
79 PRINTK("---------- ------- ------- --------- ------- ---------- --------\n");
80 }
81
OsShellCmdSwtmrInfoGet(INT32 argc,const UINT8 ** argv)82 LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdSwtmrInfoGet(INT32 argc, const UINT8 **argv)
83 {
84 #define OS_ALL_SWTMR_MASK 0xffffffff
85 SWTMR_CTRL_S *swtmr = g_swtmrCBArray;
86 SWTMR_CTRL_S *swtmr1 = g_swtmrCBArray;
87 UINT16 index;
88 size_t timerID;
89 UINT16 num = 0;
90 CHAR *endPtr = NULL;
91
92 if (argc > 1) {
93 PRINTK("\nUsage: swtmr [ID]\n");
94 return OS_ERROR;
95 }
96
97 if (argc == 0) {
98 timerID = OS_ALL_SWTMR_MASK;
99 } else {
100 timerID = strtoul((CHAR *)argv[0], &endPtr, 0);
101 if ((endPtr == NULL) || (*endPtr != 0) || (timerID > LOSCFG_BASE_CORE_SWTMR_LIMIT)) {
102 PRINTK("\nswtmr ID can't access %s.\n", argv[0]);
103 return OS_ERROR;
104 }
105 }
106
107 for (index = 0; index < LOSCFG_BASE_CORE_SWTMR_LIMIT; index++, swtmr1++) {
108 if (swtmr1->ucState == 0) {
109 num = num + 1;
110 }
111 }
112
113 if (num == LOSCFG_BASE_CORE_SWTMR_LIMIT) {
114 PRINTK("\r\nThere is no swtmr was created!\n");
115 return OS_ERROR;
116 }
117
118 if (timerID == OS_ALL_SWTMR_MASK) {
119 for (index = 0; index < LOSCFG_BASE_CORE_SWTMR_LIMIT; index++, swtmr++) {
120 if (swtmr->ucState != 0) {
121 OsPrintSwtmrMsgHead();
122 OsPrintSwtmrMsg(swtmr);
123 }
124 }
125 } else {
126 for (index = 0; index < LOSCFG_BASE_CORE_SWTMR_LIMIT; index++, swtmr++) {
127 if ((timerID == (size_t)(swtmr->usTimerID % LOSCFG_BASE_CORE_SWTMR_LIMIT)) && (swtmr->ucState != 0)) {
128 OsPrintSwtmrMsgHead();
129 OsPrintSwtmrMsg(swtmr);
130 return LOS_OK;
131 }
132 }
133 PRINTK("\r\nThe SwTimerID is not exist.\n");
134 }
135 return LOS_OK;
136 }
137
138 SHELLCMD_ENTRY(swtmr_shellcmd, CMD_TYPE_EX, "swtmr", 1, (CmdCallBackFunc)OsShellCmdSwtmrInfoGet);
139
140 #endif /* LOSCFG_SHELL */
141