timers/mcp794xx: add possibility to store datetime in UTC

This commit adds configuration option CONFIG_MCP794XX_DATETIME_UTC.
If set, the datetime is stored in UTC instead of local time. The
default value is kept at local time to keep backwards compatibility
with devices currently using the RTC.

Signed-off-by: Michal Lenc <michallenc@seznam.cz>
This commit is contained in:
Michal Lenc 2024-05-28 10:16:48 +02:00 committed by Alan Carvalho de Assis
parent 3b2faa31e8
commit c59b48355c
2 changed files with 19 additions and 0 deletions

View File

@ -339,6 +339,13 @@ config RTC_MCP794XX
if RTC_MCP794XX if RTC_MCP794XX
config MCP794XX_DATETIME_UTC
bool "Store datetime in UTC"
default n
---help---
If set, the datetime is stored in UTC timezone instead of timezone
defined by local time.
config MCP794XX_I2C_FREQUENCY config MCP794XX_I2C_FREQUENCY
int "MCP794XX I2C frequency" int "MCP794XX I2C frequency"
default 400000 default 400000

View File

@ -407,11 +407,23 @@ int up_rtc_settime(FAR const struct timespec *tp)
newtime++; newtime++;
} }
#ifndef CONFIG_MCP794XX_DATETIME_UTC
/* Save datetime in local time. */
if (localtime_r(&newtime, &newtm) == NULL) if (localtime_r(&newtime, &newtm) == NULL)
{ {
rtcerr("ERROR: localtime_r failed\n"); rtcerr("ERROR: localtime_r failed\n");
return -EINVAL; return -EINVAL;
} }
#else
/* Save datetime in UTC time. */
if (gmtime_r(&newtime, &newtm) == NULL)
{
rtcerr("ERROR: gmtime_r failed\n");
return -EINVAL;
}
#endif
rtc_dumptime(&newtm, "New time"); rtc_dumptime(&newtm, "New time");