vxworks 更新时间并在重启后保持它

问题描述 投票:0回答:1

我正在尝试让我的设备重新启动,并且重新启动后时间相同。我如何从 usrAppInit.c 实现这一点?我可以更改时间,但它不会在重新启动时保持为“gettime #1”。我错过了什么?感谢您的时间。到目前为止我已经尝试过但失败了......

    struct timespec timep;
    struct tm *ptr_tm_GMT;

    if (clock_gettime (CLOCK_REALTIME, &timep) == 0)
    {
        (void)ipcom_printf("%s[%d]  gettime #1: %lx.%lx, %s\n", __FUNCTION__, __LINE__,
                  timep.tv_sec, timep.tv_nsec, ipcom_ctime((time_t*)&timep.tv_sec));

    timep.tv_sec = (time_t)(1674065500UL);
        timep.tv_nsec = 0;
        ptr_tm_GMT = gmtime((time_t*)&timep);   // out *tm    in *time_t
    vxbRtcSet(ptr_tm_GMT);
        if (clock_settime (CLOCK_REALTIME, &timep) == 0)
        {
        //vxbRtcGet(ptr_tm_GMT);
        if (clock_gettime (CLOCK_REALTIME, &timep) == 0)
            {
                (void)ipcom_printf("%s[%d]  gettime #2: %lx.%lx, %s\n", __FUNCTION__, __LINE__,
                        timep.tv_sec, timep.tv_nsec, ipcom_ctime((time_t*)&timep.tv_sec));
        }
        else
        {
                (void)ipcom_printf("%s[%d]  ERROR:  clock_gettime\n", __FUNCTION__, __LINE__);
        }
        }
        else
    {
            (void)ipcom_printf("%s[%d]  ERROR:  clock_settime\n", __FUNCTION__, __LINE__);
    }
    }
    else
    {
        (void)ipcom_printf("%s[%d]  ERROR:  clock_settime\n", __FUNCTION__, __LINE__);
    }

我曾尝试使用不会在重启后持续存在的 clockLib 函数。我想学习如何使用代码来永久设置重启后的时间。

c time vxworks
1个回答
0
投票

这将取决于您运行的硬件。

为了在重启后保持时间不变,您通常需要在板上安装实时时钟 (RTC) 硬件。这些通常由电池供电,即使硬件断电也会保持时间。

如果没有其中之一,您不太可能在重置时保持时间。

有了 RTC,您需要有一个合适的设备驱动程序或一些代码,可以在重置时查询当前时间并设置系统时钟(假设 RTC 设备驱动程序尚未完成)。

© www.soinside.com 2019 - 2024. All rights reserved.