diff --git a/apps/include/system/utils.h b/apps/include/system/utils.h index 1cb87920ec..fc16b1bf47 100644 --- a/apps/include/system/utils.h +++ b/apps/include/system/utils.h @@ -32,7 +32,10 @@ void fs_register_utilcmds(void); void net_register_utilcmds(void); void net_register_appcmds(void); #endif - +#ifdef CONFIG_PM_CMDS +void pm_register_utilcmds(void); +void pm_register_appcmds(void); +#endif #ifdef CONFIG_ENABLE_STACKMONITOR_CMD void stkmon_logging(struct tcb_s *); #endif diff --git a/apps/system/init/init.c b/apps/system/init/init.c index 3415c37048..d8a6c4520c 100644 --- a/apps/system/init/init.c +++ b/apps/system/init/init.c @@ -92,6 +92,11 @@ static void tash_register_cmds(void) net_register_appcmds(); #endif +#ifdef CONFIG_PM_CMDS +pm_register_utilcmds(); +pm_register_appcmds(); +#endif + #ifdef CONFIG_BUILTIN_APPS register_examples_cmds(); #endif diff --git a/apps/system/utils/Kconfig b/apps/system/utils/Kconfig index 81b5715f45..d7624a81e8 100644 --- a/apps/system/utils/Kconfig +++ b/apps/system/utils/Kconfig @@ -69,6 +69,14 @@ config NET_PING_CMD_ICOUNT endif #NET_CMDS +config PM_CMDS + bool "PM shell commands" + default n + depends on TASH && PM + ---help--- + Enable Power Management System command in TASH. + Command including pm_start, pm_suspend, pm_resume, and so on. + config ENABLE_CPULOAD bool "cpuload monitor" default y diff --git a/apps/system/utils/Makefile b/apps/system/utils/Makefile index 06adcec7e1..d78776e9ae 100644 --- a/apps/system/utils/Makefile +++ b/apps/system/utils/Makefile @@ -103,6 +103,10 @@ ifeq ($(CONFIG_NETUTILS_TFTPC),y) CSRCS += netcmd_tftpc.c endif +ifeq ($(CONFIG_PM_CMDS),y) +CSRCS += pmcmd.c +endif + ifeq ($(CONFIG_ENABLE_CPULOAD),y) CSRCS += utils_cpuload.c endif diff --git a/apps/system/utils/pmcmd.c b/apps/system/utils/pmcmd.c new file mode 100644 index 0000000000..ccde3067b3 --- /dev/null +++ b/apps/system/utils/pmcmd.c @@ -0,0 +1,242 @@ +/**************************************************************************** + * + * Copyright 2024 Samsung Electronics All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the License. + * + ****************************************************************************/ +/**************************************************************************** + * apps/system/utils/pmcmd.c + * + * Copyright (C) 2007, 2009, 2013-2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 NuttX 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 OWNER 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. + * + ****************************************************************************/ +/// @file pmcmd.c +/// @brief Cursor functions. +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef CONFIG_TASH +#include +#endif + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +#define WORK_TIME 50000000 +#define SLEEP_TIME 5000 + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ +#ifdef CONFIG_AMP +static void* pm_smp_test_app(void *arg) { + int ret = -1; + struct timeval start, cur; + int work_time = WORK_TIME; + int sleep_time = SLEEP_TIME; + int delay = 0; + if (fd < 0) { + int pid = getpid(); + int fd = open(PM_DRVPATH, O_RDONLY); + printf("Cannot open %s file with fd = %d\n", PM_DRVPATH, fd); + return NULL; + } + while (1) { + printf("PID %d: I am pm_smp_test_app\n", pid); + printf("PID %d: Lets do non critical work\n", pid); + volatile count = work_time; + while (count) { + count--; + } + printf("PID %d: Lets sleep for %d ms\n", pid, sleep_time); + system_pm_sleep(sleep_time); + } + close(fd); + return NULL; +} + +static int tash_pm_smp_test(int args, char *argv[]) { + pthread_t threadid; + pthread_attr_t attr; + int ret; + ret = pthread_attr_init(&attr); + if (ret != OK) { + printf("Failed to init thread attributes\n"); + } + attr.affinity = 1<