Skip to content

Commit

Permalink
ESP32:Fix CaseSession fail on ESP32, Add InitClock_ReadTime function (#…
Browse files Browse the repository at this point in the history
…13492)

* Fix CaseSession fail on ESP32, Add InitClock_ReadTime function

* Restyled by whitespace

Co-authored-by: Restyled.io <commits@restyled.io>
  • Loading branch information
wqx6 and restyled-commits authored Jan 12, 2022
1 parent 124f590 commit 1181e94
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/platform/ESP32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ assert(chip_device_platform == "esp32")

static_library("ESP32") {
sources = [
"../FreeRTOS/SystemTimeSupport.cpp",
"../SingletonConfigurationManager.cpp",
"BLEManagerImpl.h",
"CHIPDevicePlatformConfig.h",
Expand All @@ -45,6 +44,7 @@ static_library("ESP32") {
"PlatformManagerImpl.cpp",
"PlatformManagerImpl.h",
"SystemTimeSupport.cpp",
"SystemTimeSupport.h",
"bluedroid/BLEManagerImpl.cpp",
"nimble/BLEManagerImpl.cpp",
]
Expand Down
2 changes: 2 additions & 0 deletions src/platform/ESP32/PlatformManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <crypto/CHIPCryptoPAL.h>
#include <platform/ESP32/DiagnosticDataProviderImpl.h>
#include <platform/ESP32/ESP32Utils.h>
#include <platform/ESP32/SystemTimeSupport.h>
#include <platform/PlatformManager.h>
#include <platform/internal/GenericPlatformManagerImpl_FreeRTOS.cpp>

Expand Down Expand Up @@ -123,6 +124,7 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack(void)
// to finish the initialization process.
ReturnErrorOnFailure(Internal::GenericPlatformManagerImpl_FreeRTOS<PlatformManagerImpl>::_InitChipStack());

ReturnErrorOnFailure(System::Clock::InitClock_RealTime());
exit:
return chip::DeviceLayer::Internal::ESP32Utils::MapError(err);
}
Expand Down
11 changes: 10 additions & 1 deletion src/platform/ESP32/SystemTimeSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
/* this file behaves like a config.h, comes first */
#include <platform/internal/CHIPDeviceLayerInternal.h>

#include <lib/support/TimeUtils.h>
#include <lib/support/logging/CHIPLogging.h>
#include <platform/ESP32/SystemTimeSupport.h>

#include <esp_timer.h>

Expand Down Expand Up @@ -112,6 +112,15 @@ CHIP_ERROR ClockImpl::SetClock_RealTime(Clock::Microseconds64 aNewCurTime)
return CHIP_NO_ERROR;
}

CHIP_ERROR InitClock_RealTime()
{
Clock::Microseconds64 curTime =
Clock::Microseconds64((static_cast<uint64_t>(CHIP_SYSTEM_CONFIG_VALID_REAL_TIME_THRESHOLD) * UINT64_C(1000000)));
// Use CHIP_SYSTEM_CONFIG_VALID_REAL_TIME_THRESHOLD as the initial value of RealTime.
// Then the RealTime obtained from GetClock_RealTime will be always valid.
return System::SystemClock().SetClock_RealTime(curTime);
}

} // namespace Clock
} // namespace System
} // namespace chip
28 changes: 28 additions & 0 deletions src/platform/ESP32/SystemTimeSupport.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
*
* Copyright (c) 2022 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <lib/support/TimeUtils.h>

namespace chip {
namespace System {
namespace Clock {

CHIP_ERROR InitClock_RealTime();

} // namespace Clock
} // namespace System
} // namespace chip

0 comments on commit 1181e94

Please sign in to comment.