str-ctl 实现源码
AMSS/platform/services/applications/str-ctl/main.c
int main ( int argc, char** argv)
{
int c ;
uint64_t entry_timeout_nsec = 1000000000ull;
uint64_t wakeup_timeout_nsec = 1000000000ull;
bool initiate = false ;
while( ( c = getopt( argc, argv, "e:w:i" ) ) != -1 ) {
switch( c ) {
case 'e':
entry_timeout_nsec = strtoull ( optarg, NULL, 0 );
break;
case 'w':
wakeup_timeout_nsec = strtoull ( optarg, NULL, 0 );
break;
case 'i':
initiate = true;
break;
case '?':
ERR("Invalid option(%c), see \"use %s\"", c, argv[0]);
return -1;
}
}
if ( !initiate ) {
ERR("'-i' option mandatory, see \"use %s\"", argv[0]);
return EOK ;
}
int fd = open ( "/dev/pm", O_RDWR | O_CLOEXEC) ;
if ( fd < 0 ) {
ERR ("open(/dev/pm) failed, err=%d", errno);
return -1;
}
struct timespec start, stop;
uint64_t cycle, ncycles;
uint64_t duration_nsec ;
struct pm_str_s cmd = {0};
cmd.entry_timeout = entry_timeout_nsec ;
cmd.wakeup_timeout = wakeup_timeout_nsec ;
(void) clock_gettime( CLOCK_REALTIME, &start) ;
cycle = ClockCycles();
int const rc = devctl ( fd, DCMD_PM_ENTER_STR , &cmd, sizeof (struct pm_str_s), 0 );
ncycles = ClockCycles() - cycle;
(void) clock_gettime( CLOCK_REALTIME, &stop) ;
duration_nsec = timespec2nsec (&stop) - timespec2nsec (&start);
if ( rc == EOK && duration_nsec < wakeup_timeout_nsec ) {
LOG("STR interrupted, expected to sleep=%llu ms, actual sleep =%llu ms",
NSEC_TO_MSEC ( wakeup_timeout_nsec ), NSEC_TO_MSEC (duration_nsec ));
}
LOG("DCMD_PM_ENTER_STR %s rc=%d", rc ? "failed" : "succeeded" , rc );
LOG("Elapsed system time -> %fs", 1.0f * duration_nsec / ( BILLION * 1.0f) );
LOG("Elapsed raw cycles time -> %fs", (double) ncycles / SYSPAGE_ENTRY(q

本文详细解释了str-ctl在QNX系统中的作用,涉及设备休眠、唤醒时的参数设置,以及与powermanager的交互,展示了如何通过str-ctl命令执行整机休眠过程和相关模块的同步操作。
最低0.47元/天 解锁文章
1423

被折叠的 条评论
为什么被折叠?



