1 // Copyright 2023 The Pigweed Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not 4 // use this file except in compliance with the License. You may obtain a copy of 5 // the License at 6 // 7 // https://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 // License for the specific language governing permissions and limitations under 13 // the License. 14 #include "chre/platform/system_time.h" 15 16 #include "chre/platform/assert.h" 17 #include "chre/platform/log.h" 18 #include "pw_chrono/system_clock.h" 19 20 namespace chre { 21 22 namespace { 23 24 int64_t estimated_host_time_offset = 0; 25 26 } 27 getMonotonicTime()28Nanoseconds SystemTime::getMonotonicTime() { 29 const pw::chrono::SystemClock::time_point now = 30 pw::chrono::SystemClock::now(); 31 auto nsecs = std::chrono::duration_cast<std::chrono::nanoseconds>( 32 now.time_since_epoch()) 33 .count(); 34 return Nanoseconds(static_cast<uint64_t>(nsecs)); 35 } 36 getEstimatedHostTimeOffset()37int64_t SystemTime::getEstimatedHostTimeOffset() { 38 return estimated_host_time_offset; 39 } 40 setEstimatedHostTimeOffset(int64_t offset)41void SystemTime::setEstimatedHostTimeOffset(int64_t offset) { 42 estimated_host_time_offset = offset; 43 } 44 45 } // namespace chre 46