Skip to content

Commit 2270224

Browse files
wqx6restyled-commits
authored andcommitted
ESP32:Fix CaseSession fail on ESP32, Add InitClock_ReadTime function (#13492)
* Fix CaseSession fail on ESP32, Add InitClock_ReadTime function * Restyled by whitespace Co-authored-by: Restyled.io <commits@restyled.io>
1 parent d425515 commit 2270224

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed

src/platform/ESP32/BUILD.gn

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ assert(chip_device_platform == "esp32")
2020

2121
static_library("ESP32") {
2222
sources = [
23-
"../FreeRTOS/SystemTimeSupport.cpp",
2423
"../SingletonConfigurationManager.cpp",
2524
"BLEManagerImpl.h",
2625
"CHIPDevicePlatformConfig.h",
@@ -45,6 +44,7 @@ static_library("ESP32") {
4544
"PlatformManagerImpl.cpp",
4645
"PlatformManagerImpl.h",
4746
"SystemTimeSupport.cpp",
47+
"SystemTimeSupport.h",
4848
"bluedroid/BLEManagerImpl.cpp",
4949
"nimble/BLEManagerImpl.cpp",
5050
]

src/platform/ESP32/PlatformManagerImpl.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <crypto/CHIPCryptoPAL.h>
3030
#include <platform/ESP32/DiagnosticDataProviderImpl.h>
3131
#include <platform/ESP32/ESP32Utils.h>
32+
#include <platform/ESP32/SystemTimeSupport.h>
3233
#include <platform/PlatformManager.h>
3334
#include <platform/internal/GenericPlatformManagerImpl_FreeRTOS.cpp>
3435

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

127+
ReturnErrorOnFailure(System::Clock::InitClock_RealTime());
126128
exit:
127129
return chip::DeviceLayer::Internal::ESP32Utils::MapError(err);
128130
}

src/platform/ESP32/SystemTimeSupport.cpp

+10-1
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
/* this file behaves like a config.h, comes first */
2626
#include <platform/internal/CHIPDeviceLayerInternal.h>
2727

28-
#include <lib/support/TimeUtils.h>
2928
#include <lib/support/logging/CHIPLogging.h>
29+
#include <platform/ESP32/SystemTimeSupport.h>
3030

3131
#include <esp_timer.h>
3232

@@ -112,6 +112,15 @@ CHIP_ERROR ClockImpl::SetClock_RealTime(Clock::Microseconds64 aNewCurTime)
112112
return CHIP_NO_ERROR;
113113
}
114114

115+
CHIP_ERROR InitClock_RealTime()
116+
{
117+
Clock::Microseconds64 curTime =
118+
Clock::Microseconds64((static_cast<uint64_t>(CHIP_SYSTEM_CONFIG_VALID_REAL_TIME_THRESHOLD) * UINT64_C(1000000)));
119+
// Use CHIP_SYSTEM_CONFIG_VALID_REAL_TIME_THRESHOLD as the initial value of RealTime.
120+
// Then the RealTime obtained from GetClock_RealTime will be always valid.
121+
return System::SystemClock().SetClock_RealTime(curTime);
122+
}
123+
115124
} // namespace Clock
116125
} // namespace System
117126
} // namespace chip
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
*
3+
* Copyright (c) 2022 Project CHIP Authors
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include <lib/support/TimeUtils.h>
19+
20+
namespace chip {
21+
namespace System {
22+
namespace Clock {
23+
24+
CHIP_ERROR InitClock_RealTime();
25+
26+
} // namespace Clock
27+
} // namespace System
28+
} // namespace chip

0 commit comments

Comments
 (0)