swtmr_shellcmd.c 6.4 KB
Newer Older
W
wenjun 已提交
1
/*
M
mamingshuai 已提交
2 3
 * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
 * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
W
wenjun 已提交
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this list of
 *    conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
 *    of conditions and the following disclaimer in the documentation and/or other materials
 *    provided with the distribution.
 *
 * 3. Neither the name of the copyright holder nor the names of its contributors may be used
 *    to endorse or promote products derived from this software without specific prior written
 *    permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include "los_config.h"
#ifdef LOSCFG_SHELL_CMD_DEBUG
#include "stdlib.h"
#include "los_swtmr_pri.h"
#include "shcmd.h"
#include "shell.h"

Z
zhushengle 已提交
39
#define OS_ALL_SWTMR_MASK 0xffffffff
W
wenjun 已提交
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
#define SWTMR_STRLEN  12

LITE_OS_SEC_DATA_MINOR STATIC CHAR g_shellSwtmrMode[][SWTMR_STRLEN] = {
    "Once",
    "Period",
    "NSD",
    "OPP",
};

LITE_OS_SEC_DATA_MINOR STATIC CHAR g_shellSwtmrStatus[][SWTMR_STRLEN] = {
    "UnUsed",
    "Created",
    "Ticking",
};

STATIC VOID OsPrintSwtmrMsg(const SWTMR_CTRL_S *swtmr)
{
57 58 59
    UINT32 ticks = 0;
    (VOID)LOS_SwtmrTimeGet(swtmr->usTimerID, &ticks);

Z
zhushengle 已提交
60
    PRINTK("%7u%10s%8s%12u%7u%#12x%#12x\n",
W
wenjun 已提交
61 62 63 64
           swtmr->usTimerID % LOSCFG_BASE_CORE_SWTMR_LIMIT,
           g_shellSwtmrStatus[swtmr->ucState],
           g_shellSwtmrMode[swtmr->ucMode],
           swtmr->uwInterval,
65
           ticks,
W
wenjun 已提交
66 67 68 69 70 71
           swtmr->uwArg,
           swtmr->pfnHandler);
}

STATIC INLINE VOID OsPrintSwtmrMsgHead(VOID)
{
Z
zhushengle 已提交
72
    PRINTK("\r\nSwTmrID     State    Mode    Interval  Count         Arg handlerAddr\n");
W
wenjun 已提交
73 74
}

Z
zhushengle 已提交
75
STATIC UINT32 SwtmrBaseInfoGet(UINT32 timerID)
W
wenjun 已提交
76 77 78 79 80 81 82 83 84 85 86 87 88 89
{
    SWTMR_CTRL_S *swtmr = g_swtmrCBArray;
    SWTMR_CTRL_S *swtmr1 = g_swtmrCBArray;
    UINT16 index;
    UINT16 num = 0;

    for (index = 0; index < LOSCFG_BASE_CORE_SWTMR_LIMIT; index++, swtmr1++) {
        if (swtmr1->ucState == 0) {
            num = num + 1;
        }
    }

    if (num == LOSCFG_BASE_CORE_SWTMR_LIMIT) {
        PRINTK("\r\nThere is no swtmr was created!\n");
Z
zhushengle 已提交
90
        return LOS_NOK;
W
wenjun 已提交
91 92 93
    }

    if (timerID == OS_ALL_SWTMR_MASK) {
Z
zhushengle 已提交
94
        OsPrintSwtmrMsgHead();
W
wenjun 已提交
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
        for (index = 0; index < LOSCFG_BASE_CORE_SWTMR_LIMIT; index++, swtmr++) {
            if (swtmr->ucState != 0) {
                OsPrintSwtmrMsg(swtmr);
            }
        }
    } else {
        for (index = 0; index < LOSCFG_BASE_CORE_SWTMR_LIMIT; index++, swtmr++) {
            if ((timerID == (size_t)(swtmr->usTimerID % LOSCFG_BASE_CORE_SWTMR_LIMIT)) && (swtmr->ucState != 0)) {
                OsPrintSwtmrMsgHead();
                OsPrintSwtmrMsg(swtmr);
                return LOS_OK;
            }
        }
        PRINTK("\r\nThe SwTimerID is not exist.\n");
    }
    return LOS_OK;
}

Z
zhushengle 已提交
113 114 115 116 117 118
#ifdef LOSCFG_SWTMR_DEBUG
STATIC VOID OsSwtmrTimeInfoShow(VOID)
{
    UINT8 mode;
    SwtmrDebugData data;

119 120
    PRINTK("SwtmrID  Cpuid   Mode    Period(us) WaitTime(us) WaitMax(us) RTime(us) RTimeMax(us) ReTime(us)"
           " ReTimeMax(us)      RunCount    LostNum     Handler\n");
Z
zhushengle 已提交
121 122 123 124 125 126 127 128 129 130
    for (UINT32 index = 0; index < LOSCFG_BASE_CORE_SWTMR_LIMIT; index++) {
        if (!OsSwtmrDebugDataUsed(index)) {
            continue;
        }

        UINT32 ret = OsSwtmrDebugDataGet(index, &data, sizeof(SwtmrDebugData), &mode);
        if (ret != LOS_OK) {
            break;
        }

131 132 133 134 135 136 137 138 139 140
        SwtmrDebugBase *base = &data.base;
        UINT64 waitTime = ((base->waitTime / base->waitCount) * OS_NS_PER_CYCLE) / OS_SYS_NS_PER_US;
        UINT64 waitTimeMax = (base->waitTimeMax * OS_NS_PER_CYCLE) / OS_SYS_NS_PER_US;
        UINT64 runTime = ((base->runTime / base->runCount) * OS_NS_PER_CYCLE) / OS_SYS_NS_PER_US;
        UINT64 runTimeMax = (base->runTimeMax * OS_NS_PER_CYCLE) / OS_SYS_NS_PER_US;
        UINT64 readyTime = ((base->readyTime / base->runCount) * OS_NS_PER_CYCLE) / OS_SYS_NS_PER_US;
        UINT64 readyTimeMax = (base->readyTimeMax * OS_NS_PER_CYCLE) / OS_SYS_NS_PER_US;
        PRINTK("%4u%10u%7s%14u%13llu%12llu%10llu%13llu%10llu%14llu%15llu%11u%#12x\n",
               index, data.cpuid, g_shellSwtmrMode[mode], data.period * OS_US_PER_TICK, waitTime, waitTimeMax,
               runTime, runTimeMax, readyTime, readyTimeMax, base->runCount, base->times, data.handler);
Z
zhushengle 已提交
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
    }
}
#endif

LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdSwtmrInfoGet(INT32 argc, const CHAR **argv)
{
    UINT32 timerID;
    CHAR *endPtr = NULL;

    if (argc > 1) {
        goto SWTMR_HELP;
    }

    if (argc == 0) {
        timerID = OS_ALL_SWTMR_MASK;
#ifdef LOSCFG_SWTMR_DEBUG
    } else if (strcmp("-t", argv[0]) == 0) {
        OsSwtmrTimeInfoShow();
        return LOS_OK;
#endif
    } else {
        timerID = strtoul(argv[0], &endPtr, 0);
        if ((endPtr == NULL) || (*endPtr != 0) || (timerID > LOSCFG_BASE_CORE_SWTMR_LIMIT)) {
            PRINTK("\nswtmr ID can't access %s.\n", argv[0]);
            return LOS_NOK;
        }
    }

    return SwtmrBaseInfoGet(timerID);
SWTMR_HELP:
    PRINTK("Usage:\n");
    PRINTK(" swtmr      --- Information about all created software timers.\n");
    PRINTK(" swtmr ID   --- Specifies information about a software timer.\n");
    return LOS_OK;
}

W
wenjun 已提交
177 178 179
SHELLCMD_ENTRY(swtmr_shellcmd, CMD_TYPE_EX, "swtmr", 1, (CmdCallBackFunc)OsShellCmdSwtmrInfoGet);

#endif /* LOSCFG_SHELL */