diff --git a/apps/examples/power/power_main.c b/apps/examples/power/power_main.c index 7d8fe2d5bd..b692006fe1 100644 --- a/apps/examples/power/power_main.c +++ b/apps/examples/power/power_main.c @@ -54,7 +54,7 @@ static int pm_sleep_test(void *args) int fd = open(PM_DRVPATH, O_WRONLY); if (fd < 0) { - printf("Fail to open pm sleep(errno %d)", get_errno()); + printf("Fail to open pm driver(errno %d)", get_errno()); return -1; } @@ -75,7 +75,7 @@ static void _pm_suspend(char *name) int domain_id; int fd = open(PM_DRVPATH, O_WRONLY); if (fd < 0) { - printf("Fail to open pm(errno %d)", get_errno()); + printf("Fail to open pm driver(errno %d)", get_errno()); return; } domain_arg.domain_name = name; @@ -98,7 +98,7 @@ static void _pm_resume(char *name) int domain_id; int fd = open(PM_DRVPATH, O_WRONLY); if (fd < 0) { - printf("Fail to open pm(errno %d)", get_errno()); + printf("Fail to open pm driver(errno %d)", get_errno()); return; } domain_arg.domain_name = name; @@ -123,7 +123,7 @@ static int pm_suspend_resume_test(void) int test_count = 0; int fd = open(PM_DRVPATH, O_WRONLY); if (fd < 0) { - printf("Fail to open pm(errno %d)", get_errno()); + printf("Fail to open pm driver(errno %d)", get_errno()); return -1; } @@ -167,11 +167,11 @@ static int start_pm_test(int argc, char *argv[]) fd = open(PM_DRVPATH, O_WRONLY); if (fd < 0) { - printf("Fail to open pm start(errno %d)", get_errno()); + printf("Fail to open pm driver(errno %d)", get_errno()); return -1; } - if(ioctl(fd, PMIOC_START, 0) < 0) { + if (ioctl(fd, PMIOC_START, 0) < 0) { printf("Fail to pm start(errno %d)\n", get_errno()); close(fd); return -1; @@ -223,6 +223,27 @@ static int start_pm_test(int argc, char *argv[]) } } + close(fd); + + return 0; +} + +static int stop_pm_test(int argc, char *argv[]) +{ + int fd; + + fd = open(PM_DRVPATH, O_WRONLY); + if (fd < 0) { + printf("Fail to open pm driver(errno %d)", get_errno()); + return -1; + } + + if (ioctl(fd, PMIOC_STOP, 0) < 0) { + printf("Fail to pm stop(errno %d)\n", get_errno()); + close(fd); + return -1; + } + close(fd); printf("######################### PM LONG TERM TEST END #########################\n"); @@ -287,6 +308,12 @@ int power_main(int argc, char *argv[]) return 0; } + pid = task_create("stop_pm_test", 100, 1024, stop_pm_test, NULL); + if (pid < 0) { + printf("Fail to create stop_pm_test task(errno %d)\n", get_errno()); + return -1; + } + is_running = false; } else if (strncmp(argv[1], "suspend", 8) == 0 && argc == 3) { diff --git a/os/drivers/pm/pm.c b/os/drivers/pm/pm.c index 941b62ad2b..042c6e5c68 100644 --- a/os/drivers/pm/pm.c +++ b/os/drivers/pm/pm.c @@ -77,6 +77,7 @@ static ssize_t pm_write(FAR struct file *filep, FAR const char *buffer, size_t l * PMIOC_TUNEFREQ - for changing the operating frequency of the core to save power * PMIOC_SUSPEND_COUNT - to get suspend count of pm domain * PMIOC_START - to start PM functionality to make board sleep + * PMIOC_STOP - to stop PM functionality to make board awake * * Arguments: * filep is ioctl fd, cmd is required command, arg is required argument for @@ -90,6 +91,7 @@ static ssize_t pm_write(FAR struct file *filep, FAR const char *buffer, size_t l * for PMIOC_TUNEFREQ, arg should be an int type. * for PMIOC_SUSPEND_COUNT, arg should be an int type. * for PMIOC_START, arg should be NULL + * for PMIOC_STOP, arg should be NULL * * Description: * This api can be used to perform PM operation. @@ -106,6 +108,7 @@ static ssize_t pm_write(FAR struct file *filep, FAR const char *buffer, size_t l * PMIOC_TUNEFREQ - return OK on success * PMIOC_SUSPEND_COUNT - return non-negative suspend count of domain * PMIOC_START - return OK + * PMIOC_STOP - return OK * ************************************************************************************/ static int pm_ioctl(FAR struct file *filep, int cmd, unsigned long arg) @@ -151,6 +154,10 @@ static int pm_ioctl(FAR struct file *filep, int cmd, unsigned long arg) pm_start(); ret = OK; break; + case PMIOC_STOP: + pm_stop(); + ret = OK; + break; case PMIOC_SUSPEND_COUNT: ret = pm_suspendcount((struct pm_domain_s *)arg); break; diff --git a/os/include/tinyara/fs/ioctl.h b/os/include/tinyara/fs/ioctl.h index e5febc35f6..40b2f6301b 100644 --- a/os/include/tinyara/fs/ioctl.h +++ b/os/include/tinyara/fs/ioctl.h @@ -498,6 +498,7 @@ #define PMIOC_METRICS _PMIOC(0x0007) #define PMIOC_SUSPEND_COUNT _PMIOC(0x0008) #define PMIOC_START _PMIOC(0x0009) +#define PMIOC_STOP _PMIOC(0x000A) /* Cpuload driver ioctl definitions ************************/ diff --git a/os/include/tinyara/pm/pm.h b/os/include/tinyara/pm/pm.h index 64ae526a8a..7e6b58961b 100644 --- a/os/include/tinyara/pm/pm.h +++ b/os/include/tinyara/pm/pm.h @@ -317,7 +317,7 @@ void pm_driver_register(void); * * Description: * This function is called by the application thread to start the Power - * Management system. This fucntion sets the is_running flag which + * Management system. This function sets the is_running flag which * enables pm to transition between low and high power states. * * Input parameters: @@ -330,6 +330,24 @@ void pm_driver_register(void); void pm_start(void); +/**************************************************************************** + * Name: pm_stop + * + * Description: + * This function is called by the application thread to stop the Power + * Management system. This function resets the is_running flag which + * enables pm to transition between low and high power states. + * + * Input parameters: + * None. + * + * Returned value: + * None. + * + ****************************************************************************/ + +void pm_stop(void); + /**************************************************************************** * Name: pm_initialize * @@ -632,6 +650,7 @@ int pm_metrics(int milliseconds); */ #define pm_start() +#define pm_stop() #define pm_initialize(sleep_ops) (0) #define pm_register(cb) (0) #define pm_unregister(cb) (0) diff --git a/os/pm/pm_initialize.c b/os/pm/pm_initialize.c index c748239e3a..e806928470 100644 --- a/os/pm/pm_initialize.c +++ b/os/pm/pm_initialize.c @@ -88,7 +88,7 @@ const char *wakeup_src_name[PM_WAKEUP_SRC_COUNT] = {"UNKNOWN", "BLE", "WIFI", "U * * Description: * This function is called by the application thread to start the Power - * Management system. This fucntion sets the is_running flag which + * Management system. This function sets the is_running flag which * enables pm to transition between low and high power states. * * Input parameters: @@ -99,10 +99,32 @@ const char *wakeup_src_name[PM_WAKEUP_SRC_COUNT] = {"UNKNOWN", "BLE", "WIFI", "U * ****************************************************************************/ -void pm_start(void) { +void pm_start(void) +{ g_pmglobals.is_running = true; } +/**************************************************************************** + * Name: pm_stop + * + * Description: + * This function is called by the application thread to stop the Power + * Management system. This function resets the is_running flag which + * enables pm to transition between low and high power states. + * + * Input parameters: + * None. + * + * Returned value: + * None. + * + ****************************************************************************/ + +void pm_stop(void) +{ + g_pmglobals.is_running = false; +} + /**************************************************************************** * Name: pm_initialize * diff --git a/os/pm/pm_procfs.c b/os/pm/pm_procfs.c index 4519f0d477..e493cf9762 100644 --- a/os/pm/pm_procfs.c +++ b/os/pm/pm_procfs.c @@ -203,6 +203,8 @@ static void power_read_domains(void (*readprint)(const char *, ...)) static void power_read_state(void (*readprint)(const char *, ...)) { enum pm_state_e pm_state; + + readprint("PM %s\n\n", (g_pmglobals.is_running) ? "RUNNING" : "STOPPED"); for (pm_state = PM_NORMAL; pm_state < PM_COUNT; pm_state++) { readprint("%s %s\n", (pm_state == g_pmglobals.state) ? "*" : " ", pm_state_name[pm_state]); }