我正在使用实时操作系统 Ecos。 我在 Ubuntu 上运行此代码:
#include <stdio.h>
#include <sys/time.h>
#include <unistd.h>
static int tv_diff(struct timeval *t1, struct timeval *t2)
{
return
(t1->tv_sec - t2->tv_sec) * 1000 +
(t1->tv_usec - t2->tv_usec) / 1000;
}
int main(void)
{
struct timespec ts;
struct timeval tv1, tv2;
printf("Hello, eCos !\n");
clock_gettime(1, &ts);
tv1.tv_sec = ts.tv_sec;
tv1.tv_usec = ts.tv_nsec / 1000;
printf("Time: %ld \n", tv1.tv_sec);
sleep(10);
clock_gettime(1, &ts);
tv2.tv_sec = ts.tv_sec;
tv2.tv_usec = ts.tv_nsec / 1000;
printf("Time: %ld \n", tv2.tv_sec);
printf("diff Time: %d \n", tv_diff(&tv2, &tv1));
return 0;
}
并且工作正常:
root@ubuntu:/home/feres/Bureau# ./amin
Hello, eCos !
Time: 45417
Time: 45427
diff Time: 10000
但是当我在 ecos 上运行它(它在 qemu 上运行)时,它给了我这些结果:
Hello, eCos !
Time: 0
Time: 0
diff Time: 0
ecos(或qemu)上是否缺少任何软件包,或者是否有任何特定命令可以在ecos(或qemu)上获取时间?
看起来您的 ECOS-HAL 设置不正确(以便系统刻度定期更新)。