Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[zephyr] Do not initialize real time clock #20505

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions config/nrfconnect/chip-module/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,6 @@ if (CONFIG_CHIP_ENABLE_DNSSD_SRP)
chip_gn_arg_string("chip_mdns" "platform")
endif()

if (CONFIG_CHIP_FIRMWARE_BUILD_UNIX_TIME)
string(TIMESTAMP CHIP_FIRMWARE_BUILD_UNIX_TIME "%s")
chip_gn_arg_string("chip_device_config_firmware_build_unix_time" ${CHIP_FIRMWARE_BUILD_UNIX_TIME})
endif()

if (CHIP_PROJECT_CONFIG)
chip_gn_arg_string("chip_project_config_include" ${CHIP_PROJECT_CONFIG})
chip_gn_arg_string("chip_system_project_config_include" ${CHIP_PROJECT_CONFIG})
Expand Down
7 changes: 0 additions & 7 deletions config/zephyr/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,6 @@ config CHIP_MALLOC_SYS_HEAP_SIZE

endif

config CHIP_FIRMWARE_BUILD_UNIX_TIME
bool "Make Unix time of compilation available in source code"
default y
help
When enabled, the Unix time of the firmware build is exposed to the
source code and used to initialize the last known UTC time.

config APP_LINK_WITH_CHIP
bool "Link 'app' with Connected Home over IP"
default y
Expand Down
2 changes: 1 addition & 1 deletion scripts/examples/nrfconnect_example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ BOARD="$2"
shift 2

# Disable debug symbols and firmware build time to increase ccache hit ratio in CI
COMMON_CI_FLAGS=(-DCONFIG_CHIP_DEBUG_SYMBOLS=n -DCONFIG_CHIP_FIRMWARE_BUILD_UNIX_TIME=n)
COMMON_CI_FLAGS=(-DCONFIG_CHIP_DEBUG_SYMBOLS=n)

if [[ ! -f "$APP/nrfconnect/CMakeLists.txt" || -z "$BOARD" ]]; then
echo "Usage: $0 <application> <board>" >&2
Expand Down
6 changes: 0 additions & 6 deletions src/platform/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ if (chip_device_platform != "none" && chip_device_platform != "external") {
# Time the firmware was built.
chip_device_config_firmware_build_time = ""

# Unix time the firmware was built at (seconds since the epoch)
chip_device_config_firmware_build_unix_time = ""

# Use OpenThread ftd or mtd library
chip_device_config_thread_ftd = chip_openthread_ftd

Expand Down Expand Up @@ -142,9 +139,6 @@ if (chip_device_platform != "none" && chip_device_platform != "external") {
if (chip_device_config_firmware_build_time != "") {
defines += [ "CHIP_DEVICE_CONFIG_FIRMWARE_BUILD_TIME=\"${chip_device_config_firmware_build_time}\"" ]
}
if (chip_device_config_firmware_build_unix_time != "") {
defines += [ "CHIP_DEVICE_CONFIG_FIRMWARE_BUILD_UNIX_TIME=${chip_device_config_firmware_build_unix_time}" ]
}

if (chip_use_transitional_commissionable_data_provider) {
defines += [ "CHIP_USE_TRANSITIONAL_COMMISSIONABLE_DATA_PROVIDER=1" ]
Expand Down
20 changes: 9 additions & 11 deletions src/platform/Zephyr/SystemTimeSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,10 @@ ClockImpl gClockImpl;

namespace {

// Last known UTC time in Unix format.
#ifdef CHIP_DEVICE_CONFIG_FIRMWARE_BUILD_UNIX_TIME
Microseconds64 gRealTime = Seconds64(CHIP_DEVICE_CONFIG_FIRMWARE_BUILD_UNIX_TIME);
#else
Microseconds64 gRealTime = Seconds64(CHIP_SYSTEM_CONFIG_VALID_REAL_TIME_THRESHOLD);
#endif
constexpr Microseconds64 kUnknownRealTime = Seconds64::zero();

// Monotonic time of setting the last known UTC time.
Microseconds64 gRealTimeSetTime;
// Unix epoch time of boot event
Microseconds64 gBootRealTime = kUnknownRealTime;

} // namespace

Expand All @@ -66,7 +61,11 @@ Milliseconds64 ClockImpl::GetMonotonicMilliseconds64()

CHIP_ERROR ClockImpl::GetClock_RealTime(Microseconds64 & aCurTime)
{
aCurTime = GetMonotonicMicroseconds64() - gRealTimeSetTime + gRealTime;
// The real time can be configured by an application if it has access to a reliable time source.
// Otherwise, just return an error so that Matter stack can fallback to Last Known UTC Time.
ReturnErrorCodeIf(gBootRealTime == kUnknownRealTime, CHIP_ERROR_INCORRECT_STATE);

aCurTime = gBootRealTime + GetMonotonicMicroseconds64();

return CHIP_NO_ERROR;
}
Expand All @@ -83,8 +82,7 @@ CHIP_ERROR ClockImpl::GetClock_RealTimeMS(Milliseconds64 & aCurTime)

CHIP_ERROR ClockImpl::SetClock_RealTime(Microseconds64 aNewCurTime)
{
gRealTime = aNewCurTime;
gRealTimeSetTime = GetMonotonicMicroseconds64();
gBootRealTime = aNewCurTime - GetMonotonicMicroseconds64();

return CHIP_NO_ERROR;
}
Expand Down