• 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_CMD_DEBUG
34 #include "stdlib.h"
35 #include "los_swtmr_pri.h"
36 #include "shcmd.h"
37 #include "shell.h"
38 
39 #define OS_ALL_SWTMR_MASK 0xffffffff
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("%7u%10s%8s%12u%7u%#12x%#12x\n",
61            swtmr->usTimerID % LOSCFG_BASE_CORE_SWTMR_LIMIT,
62            g_shellSwtmrStatus[swtmr->ucState],
63            g_shellSwtmrMode[swtmr->ucMode],
64            swtmr->uwInterval,
65            ticks,
66            swtmr->uwArg,
67            swtmr->pfnHandler);
68 }
69 
OsPrintSwtmrMsgHead(VOID)70 STATIC INLINE VOID OsPrintSwtmrMsgHead(VOID)
71 {
72     PRINTK("\r\nSwTmrID     State    Mode    Interval  Count         Arg handlerAddr\n");
73 }
74 
SwtmrBaseInfoGet(UINT32 timerID)75 STATIC UINT32 SwtmrBaseInfoGet(UINT32 timerID)
76 {
77     SWTMR_CTRL_S *swtmr = g_swtmrCBArray;
78     SWTMR_CTRL_S *swtmr1 = g_swtmrCBArray;
79     UINT16 index;
80     UINT16 num = 0;
81 
82     for (index = 0; index < LOSCFG_BASE_CORE_SWTMR_LIMIT; index++, swtmr1++) {
83         if (swtmr1->ucState == 0) {
84             num = num + 1;
85         }
86     }
87 
88     if (num == LOSCFG_BASE_CORE_SWTMR_LIMIT) {
89         PRINTK("\r\nThere is no swtmr was created!\n");
90         return LOS_NOK;
91     }
92 
93     if (timerID == OS_ALL_SWTMR_MASK) {
94         OsPrintSwtmrMsgHead();
95         for (index = 0; index < LOSCFG_BASE_CORE_SWTMR_LIMIT; index++, swtmr++) {
96             if (swtmr->ucState != 0) {
97                 OsPrintSwtmrMsg(swtmr);
98             }
99         }
100     } else {
101         for (index = 0; index < LOSCFG_BASE_CORE_SWTMR_LIMIT; index++, swtmr++) {
102             if ((timerID == (size_t)(swtmr->usTimerID % LOSCFG_BASE_CORE_SWTMR_LIMIT)) && (swtmr->ucState != 0)) {
103                 OsPrintSwtmrMsgHead();
104                 OsPrintSwtmrMsg(swtmr);
105                 return LOS_OK;
106             }
107         }
108         PRINTK("\r\nThe SwTimerID is not exist.\n");
109     }
110     return LOS_OK;
111 }
112 
113 #ifdef LOSCFG_SWTMR_DEBUG
OsSwtmrTimeInfoShow(VOID)114 STATIC VOID OsSwtmrTimeInfoShow(VOID)
115 {
116     UINT8 mode;
117     SwtmrDebugData data;
118 
119     PRINTK("SwtmrID  Cpuid   Mode    Period(us) WaitTime(us) WaitMax(us) RTime(us) RTimeMax(us) ReTime(us)"
120            " ReTimeMax(us)      RunCount    LostNum     Handler\n");
121     for (UINT32 index = 0; index < LOSCFG_BASE_CORE_SWTMR_LIMIT; index++) {
122         if (!OsSwtmrDebugDataUsed(index)) {
123             continue;
124         }
125 
126         UINT32 ret = OsSwtmrDebugDataGet(index, &data, sizeof(SwtmrDebugData), &mode);
127         if (ret != LOS_OK) {
128             break;
129         }
130 
131         SwtmrDebugBase *base = &data.base;
132         UINT64 waitTime = ((base->waitTime / base->waitCount) * OS_NS_PER_CYCLE) / OS_SYS_NS_PER_US;
133         UINT64 waitTimeMax = (base->waitTimeMax * OS_NS_PER_CYCLE) / OS_SYS_NS_PER_US;
134         UINT64 runTime = ((base->runTime / base->runCount) * OS_NS_PER_CYCLE) / OS_SYS_NS_PER_US;
135         UINT64 runTimeMax = (base->runTimeMax * OS_NS_PER_CYCLE) / OS_SYS_NS_PER_US;
136         UINT64 readyTime = ((base->readyTime / base->runCount) * OS_NS_PER_CYCLE) / OS_SYS_NS_PER_US;
137         UINT64 readyTimeMax = (base->readyTimeMax * OS_NS_PER_CYCLE) / OS_SYS_NS_PER_US;
138         PRINTK("%4u%10u%7s%14u%13llu%12llu%10llu%13llu%10llu%14llu%15llu%11u%#12x\n",
139                index, data.cpuid, g_shellSwtmrMode[mode], data.period * OS_US_PER_TICK, waitTime, waitTimeMax,
140                runTime, runTimeMax, readyTime, readyTimeMax, base->runCount, base->times, data.handler);
141     }
142 }
143 #endif
144 
OsShellCmdSwtmrInfoGet(INT32 argc,const CHAR ** argv)145 LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdSwtmrInfoGet(INT32 argc, const CHAR **argv)
146 {
147     UINT32 timerID;
148     CHAR *endPtr = NULL;
149 
150     if (argc > 1) {
151         goto SWTMR_HELP;
152     }
153 
154     if (argc == 0) {
155         timerID = OS_ALL_SWTMR_MASK;
156 #ifdef LOSCFG_SWTMR_DEBUG
157     } else if (strcmp("-t", argv[0]) == 0) {
158         OsSwtmrTimeInfoShow();
159         return LOS_OK;
160 #endif
161     } else {
162         timerID = strtoul(argv[0], &endPtr, 0);
163         if ((endPtr == NULL) || (*endPtr != 0) || (timerID > LOSCFG_BASE_CORE_SWTMR_LIMIT)) {
164             PRINTK("\nswtmr ID can't access %s.\n", argv[0]);
165             return LOS_NOK;
166         }
167     }
168 
169     return SwtmrBaseInfoGet(timerID);
170 SWTMR_HELP:
171     PRINTK("Usage:\n");
172     PRINTK(" swtmr      --- Information about all created software timers.\n");
173     PRINTK(" swtmr ID   --- Specifies information about a software timer.\n");
174     return LOS_OK;
175 }
176 
177 SHELLCMD_ENTRY(swtmr_shellcmd, CMD_TYPE_EX, "swtmr", 1, (CmdCallBackFunc)OsShellCmdSwtmrInfoGet);
178 
179 #endif /* LOSCFG_SHELL */
180