Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 33 additions & 6 deletions apps/examples/power/power_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code can be called first than "start_pm_test" task termination

like

call resume(10)
######################### PM LONG TERM TEST END #########################
call suspend(10)

printf("Fail to pm stop(errno %d)\n", get_errno());
close(fd);
return -1;
}

close(fd);
printf("######################### PM LONG TERM TEST END #########################\n");

Expand Down Expand Up @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason why we should do start and stop test in separate tasks?

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) {
Expand Down
7 changes: 7 additions & 0 deletions os/drivers/pm/pm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions os/include/tinyara/fs/ioctl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 ************************/

Expand Down
21 changes: 20 additions & 1 deletion os/include/tinyara/pm/pm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
*
Expand Down Expand Up @@ -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)
Expand Down
26 changes: 24 additions & 2 deletions os/pm/pm_initialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is pm_initialize. Let's add this with new file.
same for pm_start

{
g_pmglobals.is_running = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pm_ioctl doesn't use semaphore, so I think this is not 'thread-safe'

}
Comment on lines +123 to +126
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me this stop fucntion.


/****************************************************************************
* Name: pm_initialize
*
Expand Down
2 changes: 2 additions & 0 deletions os/pm/pm_procfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

procfs is not only for information.
sometimes application should parse data from procfs, so it shoul memcpy data to buffer.
Hence if you want reveal running state, then you should create additional directory, not here.

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]);
}
Expand Down