This version of this document is no longer maintained. For the latest documentation, see http://www.qnx.com/developers/docs. |
Set the power mode of a power managed device
#include <sys/pm.h> int iopower_setmode(int filedes, pm_power_mode_t mode, unsigned flags);
libpm
The iopower_setmode() function replaces pm_set_power() that has been deprecated. |
The iopower_setmode() is used to change the power mode of a power managed device.
The mode can be either a generic power mode or a device specific power mode. See pm_power_mode_t for details.
If the power manager is running, it determines whether the requested power mode change is allowed, subject to the current system power management policy.
If there's no power manager running, the driver may reject the mode change based on some internal policy. For example, it may refuse to power down a device if the device is in use.
The flags argument controls the behavior of the power mode change:
If the mode change can't be performed immediately, this call returns -1 with errno set to EINPROGRESS. This can happen for example if powering down the device requires the driver to wait for buffered data to drain.
#include <sys/pm.h> #include <fcntl.h> #include <stdlib.h> int main(void) { int fd; fd = open("/dev/device", O_RDWR); if (fd == -1) { perror("open"); return EXIT_FAILURE; } // try to set device to active if (iopower_setmode(fd, PM_MODE_ACTIVE, 0) == -1 && errno != EINPROGRESS) { perror("iopower_setmode"); // try to force device to active if (iopower_setmode(fd, PM_MODE_ACTIVE, PM_MODE_FORCE) == -1) { perror("iopower_setmode"); } } return EXIT_SUCCESS; }
Safety: | |
---|---|
Cancellation point | Yes |
Interrupt handler | No |
Signal handler | Yes |
Thread | Yes |
pm_power_mode_t, iopower_getattr(), iopower_modeattr(), iopower_getmodes()