pull/5/head
cailun 11 months ago
parent a0bc24b6c1
commit 486ae70df4

@ -25,7 +25,11 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */
/*
LiteOSShell
CPU
CPU101
*/
#include "los_config.h"
#ifdef LOSCFG_SHELL
#ifdef LOSCFG_CPUP_INCLUDE_IRQ
@ -39,7 +43,7 @@
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
//这个函数实现了打印硬件中断信息的表头
LITE_OS_SEC_TEXT_MINOR STATIC VOID OsShellCmdHwiInfoTitle(VOID)
{
#ifdef LOSCFG_CPUP_INCLUDE_IRQ
@ -53,7 +57,7 @@ LITE_OS_SEC_TEXT_MINOR STATIC VOID OsShellCmdHwiInfoTitle(VOID)
PRINTK("----------- ----- ------------- --------- --------\n");
#endif
}
//这个函数会根据传入的硬件中断句柄信息,获取该中断是否为共享模式
STATIC BOOL GetHwiShare(const HwiHandleInfo *hwiForm)
{
#ifndef LOSCFG_SHARED_IRQ
@ -64,9 +68,10 @@ STATIC BOOL GetHwiShare(const HwiHandleInfo *hwiForm)
}
#ifdef LOSCFG_CPUP_INCLUDE_IRQ
STATIC CPUP_INFO_S g_hwiCpupAll[LOSCFG_PLATFORM_HWI_LIMIT];
STATIC CPUP_INFO_S g_hwiCpup10s[LOSCFG_PLATFORM_HWI_LIMIT];
STATIC CPUP_INFO_S g_hwiCpup1s[LOSCFG_PLATFORM_HWI_LIMIT];
STATIC CPUP_INFO_S g_hwiCpupAll[LOSCFG_PLATFORM_HWI_LIMIT];//所有时间段CPU利用率的统计信息
STATIC CPUP_INFO_S g_hwiCpup10s[LOSCFG_PLATFORM_HWI_LIMIT];//最近10sCPU利用率的统计信息
STATIC CPUP_INFO_S g_hwiCpup1s[LOSCFG_PLATFORM_HWI_LIMIT];//最近1sCPU利用率的统计信息
//这个函数实现了硬件中断信息的查询根据参数argc和argv判断是否有误并调用其他函数获取硬件中断的各项信息最终打印输出硬件中断的详细信息。
LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdHwi(INT32 argc, const CHAR **argv)
{
UINT32 i, intSave;
@ -75,22 +80,24 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdHwi(INT32 argc, const CHAR **argv)
HwiHandleInfo *hwiForm = NULL;
(VOID)argv;
//打印错误信息
if (argc > 0) {
PRINTK("\nUsage: hwi\n");
return OS_ERROR;
}
(VOID)memset_s(g_hwiCpupAll, size, 0, size);
(VOID)memset_s(g_hwiCpup10s, size, 0, size);
(VOID)memset_s(g_hwiCpup1s, size, 0, size);
(VOID)memset_s(g_hwiCpupAll, size, 0, size);//置零
(VOID)memset_s(g_hwiCpup10s, size, 0, size);//置零
(VOID)memset_s(g_hwiCpup1s, size, 0, size);//置零
intSave = LOS_IntLock();
(VOID)LOS_AllCpuUsage(LOSCFG_PLATFORM_HWI_LIMIT, g_hwiCpupAll, CPUP_ALL_TIME, 0);
(VOID)LOS_AllCpuUsage(LOSCFG_PLATFORM_HWI_LIMIT, g_hwiCpup10s, CPUP_LAST_TEN_SECONDS, 0);
(VOID)LOS_AllCpuUsage(LOSCFG_PLATFORM_HWI_LIMIT, g_hwiCpup1s, CPUP_LAST_ONE_SECONDS, 0);
LOS_IntRestore(intSave);
//打印硬件中断信息的表头
OsShellCmdHwiInfoTitle();
//打印CPU硬件中断的利用率
for (i = 0; i < LOSCFG_PLATFORM_HWI_LIMIT; i++) {
if (!HWI_IS_REGISTED(i)) {
continue;
@ -101,6 +108,7 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdHwi(INT32 argc, const CHAR **argv)
}
/* Different cores has different hwi form implementation */
//打印各个时间内的硬件中断利用率
hwiForm = OsGetHwiForm(i);
PRINTK("%-8u\t %-s\t %-10u\t %-10llu %2u.%-7u %2u.%-7u %2u.%-6u",
i, GetHwiShare(hwiForm) ? "Y" : "N", OsGetHwiFormCnt(i), cycles,
@ -110,6 +118,7 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdHwi(INT32 argc, const CHAR **argv)
#ifdef LOSCFG_SHARED_IRQ
hwiForm = hwiForm->next;
#endif
//打印中断设备ID和信息
if ((hwiForm->registerInfo != 0) && ((HWI_IRQ_PARAM_S *)hwiForm->registerInfo)->pName != NULL) {
PRINTK("\t %-16s 0x%-.8x\n",
((HWI_IRQ_PARAM_S *)hwiForm->registerInfo)->pName,
@ -128,24 +137,28 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdHwi(INT32 argc, const CHAR **argv)
return 0;
}
#else
//这个函数主要实现对hwi命令的解释功能输出硬件中断信息
LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdHwi(INT32 argc, const CHAR **argv)
{
UINT32 i;
HwiHandleInfo *hwiForm = NULL;
//参数错误,打印错误信息
(VOID)argv;
if (argc > 0) {
PRINTK("\nUsage: hwi\n");
return OS_ERROR;
}
//打印硬件中断信息的表头
OsShellCmdHwiInfoTitle();
//遍历所有硬件中断寄存器
for (i = 0; i < LOSCFG_PLATFORM_HWI_LIMIT; i++) {
if (!HWI_IS_REGISTED(i)) {
continue;
}
/* Different cores has different hwi form implementation */
//输出信息
hwiForm = OsGetHwiForm(i);
PRINTK("%-8u\t %-s\t %-10u", i, GetHwiShare(hwiForm) ? "Y" : "N", OsGetHwiFormCnt(i));
#ifdef LOSCFG_SHARED_IRQ
@ -170,7 +183,7 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdHwi(INT32 argc, const CHAR **argv)
return 0;
}
#endif
//该函数实现了OsShellCmdHwi的函数调用用户可以输入hwi命令来调用该函数从而查询和展示硬件中断信息
SHELLCMD_ENTRY(hwi_shellcmd, CMD_TYPE_EX, "hwi", 0, (CmdCallBackFunc)OsShellCmdHwi);
#ifdef __cplusplus

@ -25,7 +25,10 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */
/*
LiteOSShell
使
*/
#include "stdlib.h"
#include "stdio.h"
#include "los_memory_pri.h"
@ -45,54 +48,60 @@ extern "C" {
#define MEM_SIZE_1K 0x400
#define MEM_SIZE_1M 0x100000
//这个函数用于检查内存完整性
LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdMemCheck(INT32 argc, const CHAR *argv[])
{
//打印错误信息
if (argc > 0) {
PRINTK("\nUsage: memcheck\n");
return OS_ERROR;
}
//调用OsMemIntegrityMultiCheck函数完成内存完整性检查
OsMemIntegrityMultiCheck();
return 0;
}
#ifdef LOSCFG_SHELL
//这个函数可以读取内存中指定位置指定长度的数据调用OsDumpMemByte函数完成内存读取并打印数据
LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdMemRead(INT32 argc, const CHAR *argv[])
{
size_t tempAddr;
size_t length;
CHAR *ptrlen = NULL;
CHAR *ptrAddr = NULL;
//读取错误,打印错误信息
if ((argc == 0) || (argc > 2)) { /* argc is num of parameters */
PRINTK("\nUsage: readreg [ADDRESS] [LENGTH]\n");
return OS_ERROR;
}
//读取正确
if (argc == 1) {
length = 0;
} else {
//读取长度为负数,打印错误信息
length = strtoul(argv[1], &ptrlen, 0);
if ((ptrlen == NULL) || (*ptrlen != 0)) {
PRINTK("readreg invalid length %s\n", argv[1]);
return OS_ERROR;
}
}
//保存ptrAddr的地址
tempAddr = strtoul(argv[0], &ptrAddr, 0);
//地址错误,打印错误信息
if ((ptrAddr == NULL) || (*ptrAddr != 0) || (tempAddr > g_sys_mem_addr_end) ||
((tempAddr + length) > g_sys_mem_addr_end) || (tempAddr > (OS_NULL_INT - length))) {
PRINTK("readreg invalid address %s\n", argv[0]);
return OS_ERROR;
}
//调用OsDumpMemByte函数打印指定内存位置读取的信息。
OsDumpMemByte(length, tempAddr);
return 0;
}
//这个函数用于输出代码段、数据段、只读数据段和BSS段的大小信息。
LITE_OS_SEC_TEXT_MINOR STATIC VOID OsShellCmdSectionInfo(INT32 argc, const CHAR *argv[])
{
//计算各部分长度
size_t textLen = &__text_end - &__text_start;
size_t dataLen = &__ram_data_end - &__ram_data_start;
size_t rodataLen = &__rodata_end - &__rodata_start;
@ -103,7 +112,7 @@ LITE_OS_SEC_TEXT_MINOR STATIC VOID OsShellCmdSectionInfo(INT32 argc, const CHAR
dataLen += &__fast_data_end - &__fast_data_start;
rodataLen += &__fast_rodata_end - &__fast_rodata_start;
#endif
//打印代码段、数据段、只读数据段、BSS段的大小信息
PRINTK("\r\n text data rodata bss\n");
if ((argc == 1) && (strcmp(argv[0], "-k") == 0)) {
PRINTK("Mem: %-9lu %-10lu %-10lu %-10lu\n", textLen / MEM_SIZE_1K, dataLen / MEM_SIZE_1K,
@ -115,19 +124,24 @@ LITE_OS_SEC_TEXT_MINOR STATIC VOID OsShellCmdSectionInfo(INT32 argc, const CHAR
PRINTK("Mem: %-9lu %-10lu %-10lu %-10lu\n", textLen, dataLen, rodataLen, bssLen);
}
}
//这个函数用于输出系统可用的内存总量、已经使用的内存量和剩余内存量的大小
LITE_OS_SEC_TEXT_MINOR STATIC UINT32 OsShellCmdFreeInfo(INT32 argc, const CHAR *argv[])
{
#ifdef LOSCFG_EXC_INTERACTION
//调用LOS_MemTotaUsedGet函数得到已经使用的内存量
UINT32 memUsed0 = LOS_MemTotalUsedGet(m_aucSysMem0);
//调用LOS_MemPoolSizeGet函数得到系统可用的内存总量
UINT32 totalMem0 = LOS_MemPoolSizeGet(m_aucSysMem0);
//计算得到系统剩余的内存量
UINT32 freeMem0 = totalMem0 - memUsed0;
#endif
//调用LOS_MemTotaUsedGet函数得到已经使用的内存量
UINT32 memUsed = LOS_MemTotalUsedGet(m_aucSysMem1);
//调用LOS_MemPoolSizeGet函数得到系统可用的内存总量
UINT32 totalMem = LOS_MemPoolSizeGet(m_aucSysMem1);
/
UINT32 freeMem = totalMem - memUsed;
//打印统可用的内存总量、已经使用的内存量和剩余内存量的大小
if ((argc == 0) ||
((argc == 1) && (strcmp(argv[0], "-k") == 0)) ||
((argc == 1) && (strcmp(argv[0], "-m") == 0))) {
@ -157,47 +171,57 @@ LITE_OS_SEC_TEXT_MINOR STATIC UINT32 OsShellCmdFreeInfo(INT32 argc, const CHAR *
PRINTK("Mem1: %-9u %-10u %-10u\n", totalMem0, memUsed0, freeMem0);
#endif
} else {
//打印错误信息
PRINTK("\nUsage: free or free [-k/-m]\n");
return OS_ERROR;
}
return 0;
}
//这个函数用于显示系统内存的使用情况调用了OsShellCmdFreeInfo和OsShellCmdSectionInfo函数完成内存使用情况和内存分配情况的打印输出。
LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdFree(INT32 argc, const CHAR *argv[])
{
//打印错误信息
if (argc > 1) {
PRINTK("\nUsage: free or free [-k/-m]\n");
return OS_ERROR;
}
//打印错误信息
if (OsShellCmdFreeInfo(argc, argv) != 0) {
return OS_ERROR;
}
//调用OsShellCmdSectionInfo函数输出存使用情况和内存分配情况
OsShellCmdSectionInfo(argc, argv);
return 0;
}
//这个函数根据参数选择输出不同的系统信息,在控制台上输出相应的信息。
LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdUname(INT32 argc, const CHAR *argv[])
{
//如果参数为0在控制台上打印Huawei LiteOS
if (argc == 0) {
PRINTK("Huawei LiteOS\n");
return 0;
}
if (argc == 1) {
//系统参数为-a时打印LiteOS所有的信息
if (strcmp(argv[0], "-a") == 0) {
PRINTK("%s %s %s %s %s\n", HW_LITEOS_VER, HW_LITEOS_SYSNAME, HW_LITEOS_KERNEL_VERSION_STRING,
__DATE__, __TIME__);
return 0;
//系统参数为-s时打印Huawei LiteOS
} else if (strcmp(argv[0], "-s") == 0) {
PRINTK("Huawei LiteOS\n");
return 0;
//系统参数为-t时打印系统创建的时间信息
} else if (strcmp(argv[0], "-t") == 0) {
PRINTK("build date : %s %s", __DATE__, __TIME__);
return 0;
//系统参数为-v时打印LiteOS的版本信息和时间信息
} else if (strcmp(argv[0], "-v") == 0) {
PRINTK("%s %s %s %s\n", HW_LITEOS_SYSNAME, HW_LITEOS_KERNEL_VERSION_STRING,
__DATE__, __TIME__);
return 0;
//系统参数为--help时打印各参数的含义
} else if (strcmp(argv[0], "--help") == 0) {
PRINTK("-a, print all information\n"
"-s, print the kernel name\n"
@ -206,20 +230,22 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdUname(INT32 argc, const CHAR *argv[])
return 0;
}
}
//如果都不是,打印错误信息,提示用户输入--help来查看信息
PRINTK("uname: invalid option %s\n"
"Try 'uname --help' for more information.\n",
argv[0]);
return OS_ERROR;
}
#ifdef LOSCFG_MEM_LEAKCHECK
//这个函数打印了系统已使用的内存信息
LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdMemUsed(INT32 argc, const CHAR *argv[])
{
//打印错误信息
if (argc > 0) {
PRINTK("\nUsage: memused\n");
return OS_ERROR;
}
//调用OsMemUsedNodeShow函数输出已使用的节点信息
OsMemUsedNodeShow(m_aucSysMem1);
#ifdef LOSCFG_EXC_INTERACTION
@ -230,6 +256,14 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdMemUsed(INT32 argc, const CHAR *argv[])
}
#endif
/*
memcheckOsMemIntegrityMultiCheck
memread [ADDRESS] [LENGTH]OsDumpMemByte
free使OsShellCmdFreeInfoOsShellCmdSectionInfo使
uname [-a/-s/-t/-v]PRINTK
*/
#ifdef LOSCFG_MEM_LEAKCHECK
SHELLCMD_ENTRY(memused_shellcmd, CMD_TYPE_EX, "memused", 0, (CmdCallBackFunc)OsShellCmdMemUsed);
#endif

@ -25,7 +25,10 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */
/*
LiteOSShell
*/
#include "securec.h"
#include "los_config.h"
#include "los_stackinfo_pri.h"
@ -34,7 +37,7 @@
#include "shcmd.h"
#include "shell.h"
#endif
//这个函数用于检查堆栈是否溢出
VOID OsExcStackCheck(VOID)
{
UINT32 index;
@ -42,15 +45,17 @@ VOID OsExcStackCheck(VOID)
UINTPTR *stackTop = NULL;
const StackInfo *stackInfo = NULL;
UINT32 stackNum;
//获取堆栈信息,如果堆栈信息错误,直接返回
OsGetStackInfo(&stackInfo, &stackNum);
if ((stackInfo == NULL) || (stackNum == 0)) {
return;
}
//从头开始,遍历所有的堆栈
for (index = 0; index < stackNum; index++) {
for (cpuid = 0; cpuid < LOSCFG_KERNEL_CORE_NUM; cpuid++) {
//堆栈的栈顶
stackTop = (UINTPTR *)((UINTPTR)stackInfo[index].stackTop + cpuid * stackInfo[index].stackSize);
//检查栈顶信息是否被篡改,如果被篡改输出该堆栈溢出的信息
if (*stackTop != OS_STACK_MAGIC_WORD) {
PRINT_ERR("cpu:%u %s overflow , magic word changed to 0x%x\n",
LOSCFG_KERNEL_CORE_NUM - 1 - cpuid, stackInfo[index].stackName, *stackTop);
@ -58,7 +63,7 @@ VOID OsExcStackCheck(VOID)
}
}
}
//这个函数用于获取并打印所有的堆栈信息
VOID OsExcStackInfo(VOID)
{
UINT32 index;
@ -68,29 +73,31 @@ VOID OsExcStackInfo(VOID)
UINTPTR *stack = NULL;
const StackInfo *stackInfo = NULL;
UINT32 stackNum;
//获取堆栈信息,如果堆栈信息错误,直接返回
OsGetStackInfo(&stackInfo, &stackNum);
if ((stackInfo == NULL) || (stackNum == 0)) {
return;
}
//输出堆栈名、CPU ID、堆栈的地址、堆栈的总大小堆栈已使用的大小
PrintExcInfo("\n stack name cpu id stack addr total size used size\n"
" ---------- ------ --------- -------- --------\n");
//从头开始,遍历所有的堆栈
for (index = 0; index < stackNum; index++) {
for (cpuid = 0; cpuid < LOSCFG_KERNEL_CORE_NUM; cpuid++) {
//获取堆栈的栈顶
stackTop = (UINTPTR *)((UINTPTR)stackInfo[index].stackTop + cpuid * stackInfo[index].stackSize);
stack = (UINTPTR *)((UINTPTR)stackTop + stackInfo[index].stackSize);
//调用OsStackWaterLineGet函数计算堆栈已使用的大小
(VOID)OsStackWaterLineGet(stack, stackTop, &size);
//输出各类信息
PrintExcInfo("%11s %-5d %-10p 0x%-8x 0x%-4x\n", stackInfo[index].stackName,
LOSCFG_KERNEL_CORE_NUM - 1 - cpuid, stackTop, stackInfo[index].stackSize, size);
}
}
//进行堆栈溢出检查
OsExcStackCheck();
}
//注册Shell命令stack调用OsExcStackInfo函数获取并打印所有堆栈信息至控制台。
#ifdef LOSCFG_SHELL
SHELLCMD_ENTRY(stack_shellcmd, CMD_TYPE_EX, "stack", 1, (CmdCallBackFunc)OsExcStackInfo);
#endif

@ -25,7 +25,10 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */
/*
LiteOS
ID
*/
#include "los_config.h"
#ifdef LOSCFG_SHELL
#include "stdlib.h"
@ -42,20 +45,20 @@ extern "C" {
#define SWTMR_STRLEN 12
#ifdef LOSCFG_BASE_CORE_SWTMR
//展示g_shellSwtmrMode的数据
LITE_OS_SEC_DATA_MINOR STATIC CHAR g_shellSwtmrMode[][SWTMR_STRLEN] = {
"Once",
"Period",
"NSD",
"OPP",
};
//展示g_shellSwtmrStatus的数据
LITE_OS_SEC_DATA_MINOR STATIC CHAR g_shellSwtmrStatus[][SWTMR_STRLEN] = {
"UnUsed",
"Created",
"Ticking",
};
//这个函数用于打印软件定时器的信息包括定时器ID、状态、模式、间隔、参数和处理函数地址等。
STATIC VOID OsPrintSwtmrMsg(const LosSwtmrCB *swtmr)
{
PRINTK("0x%08x "
@ -64,20 +67,20 @@ STATIC VOID OsPrintSwtmrMsg(const LosSwtmrCB *swtmr)
"%-6u "
"0x%08x "
"%p\n",
swtmr->timerId % LOSCFG_BASE_CORE_SWTMR_LIMIT,
g_shellSwtmrStatus[swtmr->state],
g_shellSwtmrMode[swtmr->mode],
swtmr->interval,
swtmr->arg,
swtmr->handler);
swtmr->timerId % LOSCFG_BASE_CORE_SWTMR_LIMIT,//打印定时器ID
g_shellSwtmrStatus[swtmr->state],//打印定时器的状态
g_shellSwtmrMode[swtmr->mode],//打印定时器的模式
swtmr->interval,//打印定时器的间隔
swtmr->arg,//打印定时器的参数
swtmr->handler);//打印定时器的处理函数地址
}
//这个函数用于打印软件定时器信息的表头
STATIC INLINE VOID OsPrintSwtmrMsgHead(VOID)
{
PRINTK("\r\nSwTmrID State Mode Interval Arg handlerAddr\n");
PRINTK("---------- ------- ------- --------- ---------- --------\n");
}
//这个函数用于获取软件定时器的信息。
LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdSwtmrInfoGet(INT32 argc, const UINT8 **argv)
{
#define OS_ALL_SWTMR_MASK 0xffffffff
@ -87,34 +90,36 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdSwtmrInfoGet(INT32 argc, const UINT8 **a
size_t timerId;
UINT16 num = 0;
CHAR *endPtr = NULL;
//打印错误信息
if (argc > 1) {
PRINTK("\nUsage: swtmr [ID]\n");
return OS_ERROR;
}
//获取计时器ID
if (argc == 0) {
timerId = OS_ALL_SWTMR_MASK;
} else {
//没有这个ID打印错误信息
timerId = strtoul((CHAR *)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 OS_ERROR;
}
}
//遍历所有计时器让计时器的状态加1
for (index = 0; index < LOSCFG_BASE_CORE_SWTMR_LIMIT; index++, swtmr1++) {
if (swtmr1->state == 0) {
num = num + 1;
}
}
//达到时间限制,输出错误信息
if (num == LOSCFG_BASE_CORE_SWTMR_LIMIT) {
PRINTK("\r\nThere is no swtmr was created!\n");
return OS_ERROR;
}
//打印软件定时器信息的表头
OsPrintSwtmrMsgHead();
//打印软件定时器的各类信息
if (timerId == OS_ALL_SWTMR_MASK) {
for (index = 0; index < LOSCFG_BASE_CORE_SWTMR_LIMIT; index++, swtmr++) {
if (swtmr->state != 0) {
@ -132,7 +137,7 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdSwtmrInfoGet(INT32 argc, const UINT8 **a
}
return LOS_OK;
}
//注册Shell命令swtmr调用OsShellCmdSwtmrInfoGet函数获取软件定时器的信息。根据输入的参数获取特定或者所有软件定时器的状态信息并打印出来。
SHELLCMD_ENTRY(swtmr_shellcmd, CMD_TYPE_EX, "swtmr", 1, (CmdCallBackFunc)OsShellCmdSwtmrInfoGet);
#endif

@ -25,7 +25,10 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */
/*
LiteOSShell
*/
#include "los_config.h"
#include "los_swtmr.h"
#include "los_sem_pri.h"
@ -43,141 +46,173 @@
extern "C" {
#endif
#endif /* __cplusplus */
//这个函数用于获取当系统的进程数量
UINT32 OsShellCmdTaskCntGet(VOID)
{
UINT32 loop;
UINT32 taskCnt = 0;
UINT32 intSave;
LosTaskCB *taskCB = NULL;
//加上锁,用于防止中断
intSave = LOS_IntLock();
//遍历所有进程,并统计进程数量
for (loop = 0; loop < g_taskMaxNum; loop++) {
taskCB = (LosTaskCB *)g_taskCBArray + loop;
//若该进程未使用,则直接跳过
if (taskCB->taskStatus & OS_TASK_STATUS_UNUSED) {
continue;
}
taskCnt++;
}
//为进程解锁
LOS_IntRestore(intSave);
//返回系统的进程数量
return taskCnt;
}
#ifdef LOSCFG_BASE_IPC_SEM
//这个函数用于获取当前系统信号量的数量
UINT32 OsShellCmdSemCntGet(VOID)
{
UINT32 loop;
UINT32 semCnt = 0;
UINT32 intSave;
LosSemCB *semNode = NULL;
//加上锁,用于防止中断
intSave = LOS_IntLock();
//遍历所有信号量
for (loop = 0; loop < LOSCFG_BASE_IPC_SEM_LIMIT; loop++) {
semNode = GET_SEM(loop);
//如果该信号量被使用了数量加1
if (semNode->semStat == LOS_USED) {
semCnt++;
}
}
//为进程解锁
LOS_IntRestore(intSave);
//返回系统信号量的数量
return semCnt;
}
#endif
#ifdef LOSCFG_BASE_IPC_MUX
//这个函数用于获取当前系统互斥锁的数量
UINT32 OsShellCmdMuxCntGet(VOID)
{
UINT32 loop;
UINT32 muxCnt = 0;
UINT32 intSave;
LosMuxCB *muxNode = NULL;
//加上锁,用于防止中断
intSave = LOS_IntLock();
//遍历所有互斥锁
for (loop = 0; loop < LOSCFG_BASE_IPC_MUX_LIMIT; loop++) {
muxNode = GET_MUX(loop);
//如果互斥锁的状态被使用了数量加1
if (muxNode->muxStat == LOS_USED) {
muxCnt++;
}
}
//为进程解锁
LOS_IntRestore(intSave);
//返回系统互斥锁的数量
return muxCnt;
}
#endif
#ifdef LOSCFG_BASE_IPC_QUEUE
//这个函数用于获取系统消息队列的数量
UINT32 OsShellCmdQueueCntGet(VOID)
{
UINT32 loop;
UINT32 queueCnt = 0;
UINT32 intSave;
LosQueueCB *queueCB = NULL;
//加上锁,用于防止中断
intSave = LOS_IntLock();
queueCB = g_allQueue;
//遍历所有消息队列
for (loop = 0; loop < LOSCFG_BASE_IPC_QUEUE_LIMIT; loop++, queueCB++) {
//如果消息队列的状态为使用数量加1
if (queueCB->queueState == LOS_USED) {
queueCnt++;
}
}
//为进程解锁
LOS_IntRestore(intSave);
//返回系统获取消息队列的数量
return queueCnt;
}
#endif
#ifdef LOSCFG_BASE_CORE_SWTMR
//这个函数用于获取系统软件定时器的数量
UINT32 OsShellCmdSwtmrCntGet(VOID)
{
UINT32 loop;
UINT32 swtmrCnt = 0;
UINT32 intSave;
LosSwtmrCB *swtmrCB = NULL;
//加上锁,用于防止中断
intSave = LOS_IntLock();
swtmrCB = g_swtmrCBArray;
//遍历所有软件定时器
for (loop = 0; loop < LOSCFG_BASE_CORE_SWTMR_LIMIT; loop++, swtmrCB++) {
//如果软件定时器的状态不是没有使用数量加1
if (swtmrCB->state != OS_SWTMR_STATUS_UNUSED) {
swtmrCnt++;
}
}
//为进程解锁
LOS_IntRestore(intSave);
//返回系统软件定时器的数量
return swtmrCnt;
}
#endif
//这个函数用于打印系统信息,包括进程数量、信号量数量、互斥锁数量、消息队列数量和软件定时器数量。
LITE_OS_SEC_TEXT_MINOR VOID OsShellCmdSystemInfoGet(VOID)
{
//打印表头
PRINTK("\n Module Used Total\n");
PRINTK("--------------------------------\n");
//打印进程数量
PRINTK(" Task %-10u%-10d\n",
OsShellCmdTaskCntGet(),
LOSCFG_BASE_CORE_TSK_LIMIT);
#ifdef LOSCFG_BASE_IPC_SEM
//打印信号量数量
PRINTK(" Sem %-10u%-10d\n",
OsShellCmdSemCntGet(),
LOSCFG_BASE_IPC_SEM_LIMIT);
#endif
#ifdef LOSCFG_BASE_IPC_MUX
//打印互斥锁数量
PRINTK(" Mutex %-10u%-10d\n",
OsShellCmdMuxCntGet(),
LOSCFG_BASE_IPC_MUX_LIMIT);
#endif
#ifdef LOSCFG_BASE_IPC_QUEUE
//打印消息队列数量
PRINTK(" Queue %-10u%-10d\n",
OsShellCmdQueueCntGet(),
LOSCFG_BASE_IPC_QUEUE_LIMIT);
#endif
#ifdef LOSCFG_BASE_CORE_SWTMR
//打印软件定时器数量
PRINTK(" SwTmr %-10u%-10d\n",
OsShellCmdSwtmrCntGet(),
LOSCFG_BASE_CORE_SWTMR_LIMIT);
#endif
}
//这个函数用于处理shell的systeminfo命令根据相应的参数做出相应的处理
INT32 OsShellCmdSystemInfo(INT32 argc, const CHAR **argv)
{
//如果参数数量为0调用OsShellCmdSystemInfoGet函数打印所有的系统信息。
if (argc == 0) {
OsShellCmdSystemInfoGet();
return 0;
}
//参数数量不正确,打印错误信息
PRINTK("systeminfo: invalid option %s\n"
"Systeminfo has NO ARGS.\n",
argv[0]);
@ -185,6 +220,7 @@ INT32 OsShellCmdSystemInfo(INT32 argc, const CHAR **argv)
}
#ifdef LOSCFG_SHELL
//注册Shell命令systeminfo调用OsShellCmdSystemInfo根据参数输出当前系统的程数量、信号量数量、互斥锁数量、消息队列数量和软件定时器数量。。
SHELLCMD_ENTRY(systeminfo_shellcmd, CMD_TYPE_EX, "systeminfo", 1, (CmdCallBackFunc)OsShellCmdSystemInfo);
#endif /* LOSCFG_SHELL */

@ -25,7 +25,10 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */
/*
LiteOSShell
*/
#include "stdio.h"
#include "stdlib.h"
#include "los_config.h"
@ -53,55 +56,65 @@ extern "C" {
#define OS_INVALID_SEM_ID 0xFFFFFFFF
#ifdef LOSCFG_KERNEL_CPUP
LITE_OS_SEC_BSS STATIC CPUP_INFO_S g_taskCpupAll[LOSCFG_BASE_CORE_TSK_LIMIT];
LITE_OS_SEC_BSS STATIC CPUP_INFO_S g_taskCpup10s[LOSCFG_BASE_CORE_TSK_LIMIT];
LITE_OS_SEC_BSS STATIC CPUP_INFO_S g_taskCpup1s[LOSCFG_BASE_CORE_TSK_LIMIT];
LITE_OS_SEC_BSS STATIC CPUP_INFO_S g_taskCpupAll[LOSCFG_BASE_CORE_TSK_LIMIT];//所有时间段CPU利用率的统计信息
LITE_OS_SEC_BSS STATIC CPUP_INFO_S g_taskCpup10s[LOSCFG_BASE_CORE_TSK_LIMIT];//最近10sCPU利用率的统计信息
LITE_OS_SEC_BSS STATIC CPUP_INFO_S g_taskCpup1s[LOSCFG_BASE_CORE_TSK_LIMIT];//最近1sCPU利用率的统计信息
#endif
LITE_OS_SEC_BSS STATIC UINT32 g_taskWaterLine[LOSCFG_BASE_CORE_TSK_LIMIT];
LITE_OS_SEC_BSS STATIC UINT32 g_taskWaterLine[LOSCFG_BASE_CORE_TSK_LIMIT];//记录各个堆栈最低的水位
//这个函数通过进程状态位来判断进程的状态,并返回相应的字符串表示进程状态。
LITE_OS_SEC_TEXT_MINOR UINT8 *OsShellCmdConvertTskStatus(UINT16 taskStatus)
{
//进程处于运行状态返回Running
if (taskStatus & OS_TASK_STATUS_RUNNING) {
return (UINT8 *)"Running";
return (UINT8 *)"Running";
//进程处于就绪状态返回Ready
} else if (taskStatus & OS_TASK_STATUS_READY) {
return (UINT8 *)"Ready";
//其他的进程状态
} else {
//进程处于延迟状态返回Delay
if (taskStatus & OS_TASK_STATUS_DELAY) {
return (UINT8 *)"Delay";
} else if (taskStatus & OS_TASK_STATUS_PEND_TIME) {
//进程处于定时挂起状态返回SuspendTime
if (taskStatus & OS_TASK_STATUS_SUSPEND) {
return (UINT8 *)"SuspendTime";
//进程处于定时等待状态返回PendTime
} else if (taskStatus & OS_TASK_STATUS_PEND) {
return (UINT8 *)"PendTime";
}
//进程处于等待状态返回Pend
} else if (taskStatus & OS_TASK_STATUS_PEND) {
return (UINT8 *)"Pend";
//进程处于挂起状态返回SusPend
} else if (taskStatus & OS_TASK_STATUS_SUSPEND) {
return (UINT8 *)"Suspend";
}
}
//进程状态不合法返回Invalid
return (UINT8 *)"Invalid";
}
//这个函数用于获取所有堆栈的栈水位(堆栈的使用情况)
STATIC VOID OsShellCmdTaskWaterLineGet(const LosTaskCB *allTaskArray)
{
const LosTaskCB *taskCB = NULL;
UINT32 loop;
//遍历所有堆栈
for (loop = 0; loop < g_taskMaxNum; ++loop) {
taskCB = allTaskArray + loop;
//如果该堆栈未使用,直接跳过
if (taskCB->taskStatus & OS_TASK_STATUS_UNUSED) {
continue;
}
//调用OsStackWaterLineGet输出堆栈的栈水位信息
(VOID)OsStackWaterLineGet((const UINTPTR *)((UINTPTR)taskCB->topOfStack + taskCB->stackSize),
(const UINTPTR *)taskCB->topOfStack, &g_taskWaterLine[taskCB->taskId]);
}
}
#ifdef LOSCFG_SHELL_EXCINFO_DUMP
//这个函数用于在异常信息输出缓冲区中打印任务信息的标题。
LITE_OS_SEC_TEXT_MINOR STATIC VOID OsShellCmdTskInfoTitleExc(VOID)
{
WriteExcInfoToBuf("\r\nName TaskEntryAddr TID ");
@ -133,7 +146,7 @@ LITE_OS_SEC_TEXT_MINOR STATIC VOID OsShellCmdTskInfoTitleExc(VOID)
WriteExcInfoToBuf("\n");
}
#endif
//这个函数用于在控制台打印任务信息的标题。
LITE_OS_SEC_TEXT_MINOR STATIC VOID OsShellCmdTskInfoTitle(VOID)
{
PRINTK("\r\nName TaskEntryAddr TID ");
@ -165,14 +178,15 @@ LITE_OS_SEC_TEXT_MINOR STATIC VOID OsShellCmdTskInfoTitle(VOID)
PRINTK("\n");
#ifdef LOSCFG_SHELL_EXCINFO_DUMP
//在异常信息输出缓冲区中打印任务信息的标题。
OsShellCmdTskInfoTitleExc();
#endif
}
//这个函数通过TCB进程控制块获取进程所持有的信号量的ID。
LITE_OS_SEC_TEXT_MINOR STATIC INLINE UINT32 OsGetSemID(const LosTaskCB *taskCB)
{
UINT32 semId = OS_INVALID_SEM_ID;
//返回该进程的信号量ID
if (taskCB->taskSem != NULL) {
semId = ((LosSemCB *)taskCB->taskSem)->semId;
}
@ -181,12 +195,13 @@ LITE_OS_SEC_TEXT_MINOR STATIC INLINE UINT32 OsGetSemID(const LosTaskCB *taskCB)
}
#ifdef LOSCFG_SHELL_EXCINFO_DUMP
//这个函数用于将TCB进程控制块中的进程信息输出到异常信息输出缓冲区。
LITE_OS_SEC_TEXT_MINOR STATIC VOID OsShellCmdTskInfoDataExc(const LosTaskCB *allTaskArray)
{
const LosTaskCB *taskCB = NULL;
UINT32 loop;
UINT32 semId;
//遍历所有的堆栈
for (loop = 0; loop < g_taskMaxNum; ++loop) {
taskCB = allTaskArray + loop;
if (taskCB->taskStatus & OS_TASK_STATUS_UNUSED) {
@ -194,21 +209,25 @@ LITE_OS_SEC_TEXT_MINOR STATIC VOID OsShellCmdTskInfoDataExc(const LosTaskCB *all
}
semId = OsGetSemID(taskCB);
//调用WriteExcInfoToBuf函数将TCB进程控制块的信息写入缓冲区
WriteExcInfoToBuf("%-23s0x%-18.8x0x%-5x", taskCB->taskName, taskCB->taskEntry, taskCB->taskId);
#ifdef LOSCFG_KERNEL_SMP
//调用WriteExcInfoToBuf函数将TCB进程控制块的信息写入缓冲区
WriteExcInfoToBuf("0x%04x %4d ", taskCB->cpuAffiMask, (INT16)(taskCB->currCpu));
#endif
//调用WriteExcInfoToBuf函数将TCB进程控制块的信息写入缓冲区
WriteExcInfoToBuf("%-11u%-13s0x%-11x0x%-11x 0x%-.8x 0x%-.8x 0x%-11x", taskCB->priority,
OsShellCmdConvertTskStatus(taskCB->taskStatus), taskCB->stackSize,
g_taskWaterLine[taskCB->taskId],
taskCB->stackPointer, taskCB->topOfStack, semId);
#ifdef LOSCFG_BASE_IPC_EVENT
//调用WriteExcInfoToBuf函数将TCB进程控制块的信息写入缓冲区
WriteExcInfoToBuf("0x%-6x", taskCB->eventMask);
#endif
#ifdef LOSCFG_KERNEL_CPUP
//调用WriteExcInfoToBuf函数将TCB进程控制块的信息写入缓冲区
WriteExcInfoToBuf(" %4u.%1u%9u.%1u%8u.%1u ",
g_taskCpupAll[taskCB->taskId].uwUsage / LOS_CPUP_PRECISION_MULT,
g_taskCpupAll[taskCB->taskId].uwUsage % LOS_CPUP_PRECISION_MULT,
@ -218,41 +237,47 @@ LITE_OS_SEC_TEXT_MINOR STATIC VOID OsShellCmdTskInfoDataExc(const LosTaskCB *all
g_taskCpup1s[taskCB->taskId].uwUsage % LOS_CPUP_PRECISION_MULT);
#endif /* LOSCFG_KERNEL_CPUP */
#ifdef LOSCFG_MEM_TASK_STAT
//调用WriteExcInfoToBuf函数将TCB进程控制块的信息写入缓冲区
WriteExcInfoToBuf(" %-11u", OsMemTaskUsage(taskCB->taskId));
#endif
//调用WriteExcInfoToBuf函数将TCB进程控制块的信息写入缓冲区
WriteExcInfoToBuf("\n");
}
}
#endif
//这个函数可以将TCB(进程控制块)中的信息输出到控制台。
LITE_OS_SEC_TEXT_MINOR STATIC VOID OsShellCmdTskInfoData(const LosTaskCB *allTaskArray)
{
const LosTaskCB *taskCB = NULL;
UINT32 loop;
UINT32 semId;
//遍历所有的堆栈
for (loop = 0; loop < g_taskMaxNum; ++loop) {
taskCB = allTaskArray + loop;
if (taskCB->taskStatus & OS_TASK_STATUS_UNUSED) {
continue;
}
//调用OsGetSemID获取该进程的信号量ID
semId = OsGetSemID(taskCB);
//输出进程信息到控制台
PRINTK("%-23s0x%-18.8x0x%-5x", taskCB->taskName, taskCB->taskEntry, taskCB->taskId);
#ifdef LOSCFG_KERNEL_SMP
//输出进程信息到控制台
PRINTK("0x%04x %4d ", taskCB->cpuAffiMask, (INT16)(taskCB->currCpu));
#endif
//输出进程信息到控制台
PRINTK("%-11u%-13s0x%-11x0x%-11x 0x%-.8x 0x%-.8x 0x%-11x", taskCB->priority,
OsShellCmdConvertTskStatus(taskCB->taskStatus), taskCB->stackSize,
g_taskWaterLine[taskCB->taskId],
taskCB->stackPointer, taskCB->topOfStack, semId);
#ifdef LOSCFG_BASE_IPC_EVENT
//输出进程信息到控制台
PRINTK("0x%-6x", taskCB->eventMask);
#endif
#ifdef LOSCFG_KERNEL_CPUP
//输出进程信息到控制台
PRINTK(" %4u.%1u%9u.%1u%8u.%1u ",
g_taskCpupAll[taskCB->taskId].uwUsage / LOS_CPUP_PRECISION_MULT,
g_taskCpupAll[taskCB->taskId].uwUsage % LOS_CPUP_PRECISION_MULT,
@ -262,16 +287,19 @@ LITE_OS_SEC_TEXT_MINOR STATIC VOID OsShellCmdTskInfoData(const LosTaskCB *allTas
g_taskCpup1s[taskCB->taskId].uwUsage % LOS_CPUP_PRECISION_MULT);
#endif /* LOSCFG_KERNEL_CPUP */
#ifdef LOSCFG_MEM_TASK_STAT
//输出进程信息到控制台
PRINTK(" %-11u", OsMemTaskUsage(taskCB->taskId));
#endif
//输出进程信息到控制台
PRINTK("\n");
}
#ifdef LOSCFG_SHELL_EXCINFO_DUMP
//将进程信息输出到异常信息输出缓冲区。
OsShellCmdTskInfoDataExc(allTaskArray);
#endif
}
//这个函数可以通过进程号获取进程的信息
LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdTskInfoGet(UINT32 taskId)
{
BOOL backupFlag = TRUE;
@ -279,50 +307,57 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdTskInfoGet(UINT32 taskId)
UINT32 size, intSave;
LosTaskCB *tcbArray = NULL;
INT32 ret;
//如果是目标进程
if (taskId == OS_ALL_TASK_MASK) {
size = g_taskMaxNum * sizeof(LosTaskCB);
tcbArray = (LosTaskCB *)LOS_MemAlloc(m_aucSysMem1, size);
//如果目标进程信息为空输出错误信息将backup设置为Fasle不备份该进程信息
if (tcbArray == NULL) {
PRINTK("Memory is not enough to save task info!\n");
tcbArray = g_taskCBArray;
backupFlag = FALSE;
}
#ifdef LOSCFG_KERNEL_CPUP
(VOID)memset_s((VOID *)g_taskCpupAll, sizeof(g_taskCpupAll), 0, sizeof(g_taskCpupAll));
(VOID)memset_s((VOID *)g_taskCpup10s, sizeof(g_taskCpup10s), 0, sizeof(g_taskCpup10s));
(VOID)memset_s((VOID *)g_taskCpup1s, sizeof(g_taskCpup1s), 0, sizeof(g_taskCpup1s));
(VOID)memset_s((VOID *)g_taskCpupAll, sizeof(g_taskCpupAll), 0, sizeof(g_taskCpupAll));//置零
(VOID)memset_s((VOID *)g_taskCpup10s, sizeof(g_taskCpup10s), 0, sizeof(g_taskCpup10s));//置零
(VOID)memset_s((VOID *)g_taskCpup1s, sizeof(g_taskCpup1s), 0, sizeof(g_taskCpup1s));//置零
#endif
(VOID)memset_s((VOID *)g_taskWaterLine, sizeof(g_taskWaterLine), 0, sizeof(g_taskWaterLine));
(VOID)memset_s((VOID *)g_taskWaterLine, sizeof(g_taskWaterLine), 0, sizeof(g_taskWaterLine));//置零
//如果没有调度器自旋锁,为该进程添加调度器自旋锁
if (LOS_SpinHeld(&g_taskSpin) == FALSE) {
SCHEDULER_LOCK(intSave);
lockFlag = TRUE;
}
//如果需要将进程信息备份
if (backupFlag == TRUE) {
//将进程信息备份到tcbArray
ret = memcpy_s(tcbArray, size, g_taskCBArray, size);
//如果没有备份成果返回错误
if (ret != EOK) {
return LOS_NOK;
}
}
#ifdef LOSCFG_KERNEL_CPUP
(VOID)LOS_AllCpuUsage(LOSCFG_BASE_CORE_TSK_LIMIT, g_taskCpupAll, CPUP_ALL_TIME, 1);
(VOID)LOS_AllCpuUsage(LOSCFG_BASE_CORE_TSK_LIMIT, g_taskCpup10s, CPUP_LAST_TEN_SECONDS, 1);
(VOID)LOS_AllCpuUsage(LOSCFG_BASE_CORE_TSK_LIMIT, g_taskCpup1s, CPUP_LAST_ONE_SECONDS, 1);
(VOID)LOS_AllCpuUsage(LOSCFG_BASE_CORE_TSK_LIMIT, g_taskCpupAll, CPUP_ALL_TIME, 1);//显示CPU所有时段的使用率信息
(VOID)LOS_AllCpuUsage(LOSCFG_BASE_CORE_TSK_LIMIT, g_taskCpup10s, CPUP_LAST_TEN_SECONDS, 1);//显示CPU最近10s的使用率信息
(VOID)LOS_AllCpuUsage(LOSCFG_BASE_CORE_TSK_LIMIT, g_taskCpup1s, CPUP_LAST_ONE_SECONDS, 1);//显示CPU最近1s的使用率信息
#endif
//获取进程的栈水位信息
OsShellCmdTaskWaterLineGet(tcbArray);
//如果进程有调度器自旋锁,将该进程解锁
if (lockFlag == TRUE) {
SCHEDULER_UNLOCK(intSave);
}
//打印进程信息标题
OsShellCmdTskInfoTitle();
//打印进程信息的数据
OsShellCmdTskInfoData(tcbArray);
//如果进程信息数据备份成果释放tcbArrayd的内存空间
if (backupFlag == TRUE) {
(VOID)LOS_MemFree(m_aucSysMem1, tcbArray);
}
} else {
//调用 OsTaskBackTrace函数来获取该任务的回溯信息。
OsTaskBackTrace(taskId);
}
@ -330,29 +365,34 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdTskInfoGet(UINT32 taskId)
}
#ifdef LOSCFG_SHELL
//这个函数用于处理task命令通过各种参数输出结果
LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdDumpTask(INT32 argc, const CHAR **argv)
{
size_t taskId;
CHAR *endPtr = NULL;
//当参数数量合法时
if (argc < 2) { /* 2:Just as number of parameters */
//如果没有参数,进程号是所有进程
if (argc == 0) {
taskId = OS_ALL_TASK_MASK;
//存在一个参数为进程号
} else {
taskId = strtoul(argv[0], &endPtr, 0);
//如果进程号不合法,打印错误信息
if ((*endPtr != 0) || (taskId >= g_taskMaxNum)) {
PRINTK("\ntask ID can't access %s.\n", argv[0]);
return OS_ERROR;
}
}
//调用OsShellCmdTskInfoGet函数输出该进程的进程信息
return OsShellCmdTskInfoGet((UINT32)taskId);
} else {
//参数不合法,打印错误信息
PRINTK("\nUsage: task or task ID\n");
return OS_ERROR;
}
}
//注册Shell命令task调用OsShellCmdDumpTask根据参数进程号或者没有参数获取进程信息并输出。
SHELLCMD_ENTRY(task_shellcmd, CMD_TYPE_EX, "task", 1, (CmdCallBackFunc)OsShellCmdDumpTask);
#endif

Loading…
Cancel
Save