Skip to content

Commit

Permalink
apps/shell: fix board sleep during TASH Input
Browse files Browse the repository at this point in the history
This commit resolve the issue of board sleep during TASH Input. With the
PM Quick Sleep the board is frequently going to sleep whenever user
tries to enter the command in tash prompt. This issue cause the board to
wake frequently resulting in high power consumption. To avoid this we
have suspended the PM Sleep for TASH_PM_TIMEDSUSPEND_TIME_IN_MS whenever
TASH read user's input.
  • Loading branch information
gSahitya-samsung authored and r-prabu committed Aug 23, 2024
1 parent 2a03f59 commit 3e46963
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 1 deletion.
3 changes: 3 additions & 0 deletions apps/shell/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ STACKSIZE = 2048

ASRCS =
CSRCS = tash_command.c tash_init.c
ifeq ($(CONFIG_PM),y)
CSRCS += tash_pm.c
endif
ifeq ($(CONFIG_TASH_SCRIPT),y)
CSRCS += tash_script.c
endif
Expand Down
6 changes: 6 additions & 0 deletions apps/shell/tash_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ extern int tash_sleep(int argc, char **args);
#ifdef CONFIG_TASH_USLEEP
extern int tash_usleep(int argc, char **args);
#endif
#ifdef CONFIG_PM
void tash_pm_open_driver(void);
void tash_pm_close_driver(void);
int tash_pm_get_domain_id(void);
void tash_pm_timedsuspend(uint32_t milliseconds);
#endif
#endif

#endif /* __APPS_SHELL_TASH_INTERNAL_H */
16 changes: 15 additions & 1 deletion apps/shell/tash_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ enum tash_input_state_e {
#define TASH_PROMPT "TASH>>"
#endif /* CONFIG_TASH */

#ifdef CONFIG_PM
#define TASH_PM_TIMEDSUSPEND_TIME_IN_MS 5000
#endif

static int tash_running = FALSE;

#if TASH_MAX_STORE > 0
Expand Down Expand Up @@ -156,7 +160,10 @@ char *tash_read_input_line(int fd)
shdbg("TASH: can not read uart\n");
return buffer;
}

#ifdef CONFIG_PM
/* Ensure board does not go to sleep for TASH_PM_TIMEDSUSPEND_TIME_IN_MS*/
tash_pm_timedsuspend(TASH_PM_TIMEDSUSPEND_TIME_IN_MS);
#endif
for (char_idx = 0; char_idx < nbytes; char_idx++) {

if ((CURR_CHAR == ASCII_BS) || (CURR_CHAR == ASCII_DEL)) {
Expand Down Expand Up @@ -341,6 +348,10 @@ static int tash_main(int argc, char *argv[])

tash_running = TRUE;

#ifdef CONFIG_PM
/* Open PM Driver to perform pm operations inside tash_read_input_line */
tash_pm_open_driver();
#endif
do {
nbytes = write(fd, (const void *)TASH_PROMPT, sizeof(TASH_PROMPT));
if (nbytes <= 0) {
Expand Down Expand Up @@ -380,6 +391,9 @@ int tash_start(void)
void tash_stop(void)
{
tash_running = FALSE;
#ifdef CONFIG_PM
tash_pm_close_driver();
#endif
}
#endif /* CONFIG_TASH */

Expand Down
76 changes: 76 additions & 0 deletions apps/shell/tash_pm.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/****************************************************************************
*
* 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.
*
****************************************************************************/

#include <stdio.h>
#include <sys/types.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <tinyara/pm/pm.h>
#include <errno.h>
#include "tash_internal.h"

#define TASH_PM_DOMAIN_NAME "TASH"

static int tash_pm_domain_id = -1;
static int pmdrv_fd = -1;

void tash_pm_open_driver(void)
{
if (pmdrv_fd < 0) {
pmdrv_fd = open(PM_DRVPATH, O_WRONLY);
if (pmdrv_fd < 0) {
shdbg("open %s failed(%d), \n", PM_DRVPATH, get_errno());
}
}
}

void tash_pm_close_driver(void)
{
if (pmdrv_fd >= 0) {
close(pmdrv_fd);
pmdrv_fd = -1;
}
}

int tash_pm_get_domain_id(void)
{
pm_domain_arg_t pm_domain_arg;
if (tash_pm_domain_id == -1) {
pm_domain_arg.domain_name = TASH_PM_DOMAIN_NAME;
if (pmdrv_fd < 0) {
shdbg("First open pm driver using tash_pm_open_driver() to register %s domain\n", TASH_PM_DOMAIN_NAME);
} else if (ioctl(pmdrv_fd, PMIOC_DOMAIN_REGISTER, &pm_domain_arg) != OK) {
shdbg("pm_domain_register failed(%d)\n", get_errno());
} else {
tash_pm_domain_id = pm_domain_arg.domain_id;
}
}
return tash_pm_domain_id;
}

void tash_pm_timedsuspend(uint32_t milliseconds)
{
pm_suspend_arg_t pm_suspend_arg;
pm_suspend_arg.domain_id = tash_pm_get_domain_id();
pm_suspend_arg.timer_interval = milliseconds;
if (pmdrv_fd < 0) {
shdbg("First open pm driver using tash_pm_open_driver() to timedsuspend %s domain\n", TASH_PM_DOMAIN_NAME);
} else if (ioctl(pmdrv_fd, PMIOC_TIMEDSUSPEND, &pm_suspend_arg) != OK) {
shdbg("Unable to timedsuspend the %s domain for %d ms, error = %d\n", TASH_PM_DOMAIN_NAME, milliseconds, get_errno());
}
}

0 comments on commit 3e46963

Please sign in to comment.