time() C 函数与底层硬件之间的耦合

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

这是一个更普遍的问题。

time()
c 函数与底层硬件之间的耦合是如何完成的?假设您为不包含任何 RTC 的微控制器进行编译,您会得到什么值?或者,如果您使用自己的 RTC,通过独立芯片上的电池保持运行?重新通电后如何更新
time()
?有什么方法可以重定向吗?

我在 Mbed 中使用 RTC 和

time()
功能与
MCU_STM32U575xG
进行了试验。

另请参阅 https://forums.mbed.com/t/time-null-of-rtc-example-not-synchronizing-with-rtc-when-using-battery/22248/10

c gcc mbed
1个回答
0
投票

time() c 函数与底层硬件之间的耦合是如何完成的?

没有“完成”耦合。 必须“做”。

您能得到什么价值?

我希望出现链接错误,或者也许我希望

time()
返回
(time_t)-1
,并将
errno
设置为
ENOSYS

返回 -1 和 ENOSYS 是默认的

nosys
实现
newlib
C 标准库实现,因此通常与 GNU
arm-none-eabi-gcc
编译器工具链一起使用 https://github.com/bminor/newlib/blob/master/libgloss /libnosys/gettod.c#L18 .

我在 Mbed 中使用 RTC 和 time() 函数与 MCU_STM32U575xG 进行了试验。

对于 mbed-os,时间函数在这里实现 https://github.com/mbed-ce/mbed-os/blob/master/platform/source/mbed_rtc_time.cpp#L120 。该函数的细节以及

_rtc_read()
函数调用的内容是通过 mbed-os 配置进行配置的。 必须配置 mbed-os 并为其提供配置并使用 mbed-os 进行编译。

底线,没有耦合。如果你想要的话,你必须进行耦合。

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