diff options
Diffstat (limited to 'pw_chre/include/chre/target_platform')
16 files changed, 521 insertions, 0 deletions
diff --git a/pw_chre/include/chre/target_platform/atomic_base.h b/pw_chre/include/chre/target_platform/atomic_base.h new file mode 100644 index 000000000..3462671c0 --- /dev/null +++ b/pw_chre/include/chre/target_platform/atomic_base.h @@ -0,0 +1,30 @@ +// Copyright 2023 The Pigweed 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 +// +// https://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. + +#pragma once + +#include <atomic> + +namespace chre { + +template <typename AtomicType> +class AtomicBase { + protected: + std::atomic<AtomicType> atomic_; +}; + +typedef AtomicBase<bool> AtomicBoolBase; +typedef AtomicBase<uint32_t> AtomicUint32Base; + +} // namespace chre diff --git a/pw_chre/include/chre/target_platform/atomic_base_impl.h b/pw_chre/include/chre/target_platform/atomic_base_impl.h new file mode 100644 index 000000000..3979a52d6 --- /dev/null +++ b/pw_chre/include/chre/target_platform/atomic_base_impl.h @@ -0,0 +1,63 @@ +// Copyright 2023 The Pigweed 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 +// +// https://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. + +#pragma once + +#include "chre/platform/atomic.h" + +namespace chre { + +inline AtomicBool::AtomicBool(bool starting_value) { + std::atomic_init(&atomic_, starting_value); +} + +inline bool AtomicBool::operator=(bool desired) { return atomic_ = desired; } + +inline bool AtomicBool::load() const { return atomic_.load(); } + +inline void AtomicBool::store(bool desired) { atomic_.store(desired); } + +inline bool AtomicBool::exchange(bool desired) { + return atomic_.exchange(desired); +} + +inline AtomicUint32::AtomicUint32(uint32_t startingValue) { + std::atomic_init(&atomic_, startingValue); +} + +inline uint32_t AtomicUint32::operator=(uint32_t desired) { + return atomic_ = desired; +} + +inline uint32_t AtomicUint32::load() const { return atomic_.load(); } + +inline void AtomicUint32::store(uint32_t desired) { atomic_.store(desired); } + +inline uint32_t AtomicUint32::exchange(uint32_t desired) { + return atomic_.exchange(desired); +} + +inline uint32_t AtomicUint32::fetch_add(uint32_t arg) { + return atomic_.fetch_add(arg); +} + +inline uint32_t AtomicUint32::fetch_increment() { return atomic_.fetch_add(1); } + +inline uint32_t AtomicUint32::fetch_sub(uint32_t arg) { + return atomic_.fetch_sub(arg); +} + +inline uint32_t AtomicUint32::fetch_decrement() { return atomic_.fetch_sub(1); } + +} // namespace chre diff --git a/pw_chre/include/chre/target_platform/condition_variable_base.h b/pw_chre/include/chre/target_platform/condition_variable_base.h new file mode 100644 index 000000000..f40ab3004 --- /dev/null +++ b/pw_chre/include/chre/target_platform/condition_variable_base.h @@ -0,0 +1,26 @@ +// Copyright 2023 The Pigweed 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 +// +// https://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. + +#pragma once + +#include "pw_sync/timed_thread_notification.h" + +namespace chre { + +class ConditionVariableBase { + protected: + pw::sync::TimedThreadNotification notification_; +}; + +} // namespace chre diff --git a/pw_chre/include/chre/target_platform/condition_variable_impl.h b/pw_chre/include/chre/target_platform/condition_variable_impl.h new file mode 100644 index 000000000..2d826ec06 --- /dev/null +++ b/pw_chre/include/chre/target_platform/condition_variable_impl.h @@ -0,0 +1,42 @@ +// Copyright 2023 The Pigweed 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 +// +// https://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. + +#pragma once +#include "chre/platform/condition_variable.h" +#include "pw_chrono/system_clock.h" + +namespace chre { + +inline ConditionVariable::ConditionVariable() {} + +inline ConditionVariable::~ConditionVariable() {} + +inline void ConditionVariable::notify_one() { notification_.release(); } + +inline void ConditionVariable::wait(Mutex& mutex) { + mutex.unlock(); + notification_.acquire(); + mutex.lock(); +} + +inline bool ConditionVariable::wait_for(Mutex& mutex, Nanoseconds timeout) { + mutex.unlock(); + auto pw_timeout = pw::chrono::SystemClock::for_at_least( + std::chrono::nanoseconds(timeout.toRawNanoseconds())); + bool did_acquire = notification_.try_acquire_for(pw_timeout); + mutex.lock(); + return did_acquire; +} + +} // namespace chre diff --git a/pw_chre/include/chre/target_platform/fatal_error.h b/pw_chre/include/chre/target_platform/fatal_error.h new file mode 100644 index 000000000..5b236f613 --- /dev/null +++ b/pw_chre/include/chre/target_platform/fatal_error.h @@ -0,0 +1,21 @@ +// Copyright 2023 The Pigweed 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 +// +// https://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. + +#pragma once +#include "pw_assert/assert.h" + +#define FATAL_ERROR_QUIT() \ + do { \ + PW_ASSERT(false); \ + } while (0) diff --git a/pw_chre/include/chre/target_platform/host_link_base.h b/pw_chre/include/chre/target_platform/host_link_base.h new file mode 100644 index 000000000..6faea634b --- /dev/null +++ b/pw_chre/include/chre/target_platform/host_link_base.h @@ -0,0 +1,25 @@ +// Copyright 2023 The Pigweed 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 +// +// https://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. + +#pragma once +namespace chre { + +// TODO: b/301477662 - This class will likely need a facade since this will be +// implemented in downstream products. +class HostLinkBase { + public: + void sendNanConfiguration(bool enable); +}; + +} // namespace chre diff --git a/pw_chre/include/chre/target_platform/log.h b/pw_chre/include/chre/target_platform/log.h new file mode 100644 index 000000000..58aad2907 --- /dev/null +++ b/pw_chre/include/chre/target_platform/log.h @@ -0,0 +1,24 @@ +// Copyright 2023 The Pigweed 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 +// +// https://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. + +#pragma once + +#include <cstddef> + +#include "pw_log/log.h" + +#define LOGW(...) PW_LOG_WARN(__VA_ARGS__) +#define LOGE(...) PW_LOG_ERROR(__VA_ARGS__) +#define LOGI(...) PW_LOG_INFO(__VA_ARGS__) +#define LOGD(...) PW_LOG_DEBUG(__VA_ARGS__) diff --git a/pw_chre/include/chre/target_platform/mutex_base.h b/pw_chre/include/chre/target_platform/mutex_base.h new file mode 100644 index 000000000..b5e42b009 --- /dev/null +++ b/pw_chre/include/chre/target_platform/mutex_base.h @@ -0,0 +1,20 @@ +// Copyright 2023 The Pigweed 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 +// +// https://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. + +#pragma once +#include "pw_sync/mutex.h" + +struct MutexBase { + pw::sync::Mutex mutex_; +}; diff --git a/pw_chre/include/chre/target_platform/mutex_base_impl.h b/pw_chre/include/chre/target_platform/mutex_base_impl.h new file mode 100644 index 000000000..215813861 --- /dev/null +++ b/pw_chre/include/chre/target_platform/mutex_base_impl.h @@ -0,0 +1,31 @@ +// Copyright 2023 The Pigweed 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 +// +// https://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. + +#pragma once + +#include "chre/platform/mutex.h" + +namespace chre { + +inline Mutex::Mutex() {} + +inline Mutex::~Mutex() {} + +inline void Mutex::lock() { mutex_.lock(); } + +inline bool Mutex::try_lock() { return mutex_.try_lock(); } + +inline void Mutex::unlock() { mutex_.unlock(); } + +} // namespace chre diff --git a/pw_chre/include/chre/target_platform/platform_nanoapp_base.h b/pw_chre/include/chre/target_platform/platform_nanoapp_base.h new file mode 100644 index 000000000..6f12d1e4a --- /dev/null +++ b/pw_chre/include/chre/target_platform/platform_nanoapp_base.h @@ -0,0 +1,29 @@ +// Copyright 2023 The Pigweed 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 +// +// https://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. + +#pragma once + +#include "chre/platform/shared/nanoapp_support_lib_dso.h" + +namespace chre { + +class PlatformNanoappBase { + public: + void loadStatic(const struct chreNslNanoappInfo* app_info); + + protected: + const struct chreNslNanoappInfo* app_info_ = nullptr; +}; + +} // namespace chre diff --git a/pw_chre/include/chre/target_platform/platform_sensor_base.h b/pw_chre/include/chre/target_platform/platform_sensor_base.h new file mode 100644 index 000000000..d87095de7 --- /dev/null +++ b/pw_chre/include/chre/target_platform/platform_sensor_base.h @@ -0,0 +1,43 @@ +// Copyright 2023 The Pigweed 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 +// +// https://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. + +#pragma once +#include "chre_api/chre/sensor.h" + +namespace chre { + +class PlatformSensorBase { + public: + void initBase(const struct chreSensorInfo* sensor_info, + uint32_t sensor_handle) { + sensor_info_ = sensor_info; + sensor_handle_ = sensor_handle; + } + + void setSensorInfo(const struct chreSensorInfo* sensor_info) { + sensor_info_ = sensor_info; + } + + void setSensorHandle(uint32_t sensor_handle) { + sensor_handle_ = sensor_handle; + } + + uint32_t getSensorHandle() const { return sensor_handle_; } + + protected: + const struct chreSensorInfo* sensor_info_; + uint32_t sensor_handle_; +}; + +} // namespace chre diff --git a/pw_chre/include/chre/target_platform/platform_sensor_manager_base.h b/pw_chre/include/chre/target_platform/platform_sensor_manager_base.h new file mode 100644 index 000000000..1c425bdef --- /dev/null +++ b/pw_chre/include/chre/target_platform/platform_sensor_manager_base.h @@ -0,0 +1,38 @@ +// Copyright 2023 The Pigweed 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 +// +// https://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. + +#pragma once +#include <cstdint> + +#include "chre/pal/sensor.h" + +namespace chre { + +class PlatformSensorManagerBase { + public: + // Note: these are load bearing names + static const chrePalSensorCallbacks sSensorCallbacks; + const chrePalSensorApi* mSensorApi; + + private: + static void samplingStatusUpdateCallback( + uint32_t sensor_handle, struct chreSensorSamplingStatus* status); + static void dataEventCallback(uint32_t sensor_handle, void* data); + static void biasEventCallback(uint32_t sensor_handle, void* bias_data); + static void flushCompleteCallback(uint32_t sensor_handle, + uint32_t flush_request_id, + uint8_t error_code); +}; + +} // namespace chre diff --git a/pw_chre/include/chre/target_platform/platform_sensor_type_helpers_base.h b/pw_chre/include/chre/target_platform/platform_sensor_type_helpers_base.h new file mode 100644 index 000000000..072f88678 --- /dev/null +++ b/pw_chre/include/chre/target_platform/platform_sensor_type_helpers_base.h @@ -0,0 +1,20 @@ +// Copyright 2023 The Pigweed 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 +// +// https://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. + +#pragma once +namespace chre { + +class PlatformSensorTypeHelpersBase {}; + +} // namespace chre diff --git a/pw_chre/include/chre/target_platform/power_control_manager_base.h b/pw_chre/include/chre/target_platform/power_control_manager_base.h new file mode 100644 index 000000000..c1d00d376 --- /dev/null +++ b/pw_chre/include/chre/target_platform/power_control_manager_base.h @@ -0,0 +1,21 @@ +// Copyright 2023 The Pigweed 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 +// +// https://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. + +#pragma once + +namespace chre { + +class PowerControlManagerBase {}; + +} // namespace chre diff --git a/pw_chre/include/chre/target_platform/static_nanoapp_init.h b/pw_chre/include/chre/target_platform/static_nanoapp_init.h new file mode 100644 index 000000000..6f2c09119 --- /dev/null +++ b/pw_chre/include/chre/target_platform/static_nanoapp_init.h @@ -0,0 +1,50 @@ +// Copyright 2023 The Pigweed 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 +// +// https://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. + +#pragma once + +#include "chre/core/static_nanoapps.h" +#include "chre/platform/fatal_error.h" +#include "chre/platform/shared/nanoapp_support_lib_dso.h" + +#define CHRE_STATIC_NANOAPP_INIT(appName, appId_, appVersion_, appPerms) \ + namespace chre { \ + \ + UniquePtr<Nanoapp> initializeStaticNanoapp##appName() { \ + UniquePtr<Nanoapp> nanoapp = MakeUnique<Nanoapp>(); \ + static struct chreNslNanoappInfo appInfo; \ + appInfo.magic = CHRE_NSL_NANOAPP_INFO_MAGIC; \ + appInfo.structMinorVersion = CHRE_NSL_NANOAPP_INFO_STRUCT_MINOR_VERSION; \ + appInfo.targetApiVersion = CHRE_API_VERSION; \ + appInfo.vendor = "Google"; \ + appInfo.name = #appName; \ + appInfo.isSystemNanoapp = true; \ + appInfo.isTcmNanoapp = false; \ + appInfo.appId = appId_; \ + appInfo.appVersion = appVersion_; \ + appInfo.entryPoints.start = nanoappStart; \ + appInfo.entryPoints.handleEvent = nanoappHandleEvent; \ + appInfo.entryPoints.end = nanoappEnd; \ + appInfo.appVersionString = "<undefined>"; \ + appInfo.appPermissions = appPerms; \ + if (nanoapp.isNull()) { \ + FATAL_ERROR("Failed to allocate nanoapp " #appName); \ + } else { \ + nanoapp->loadStatic(&appInfo); \ + } \ + \ + return nanoapp; \ + } \ + \ + } // namespace chre diff --git a/pw_chre/include/chre/target_platform/system_timer_base.h b/pw_chre/include/chre/target_platform/system_timer_base.h new file mode 100644 index 000000000..e8cb288c0 --- /dev/null +++ b/pw_chre/include/chre/target_platform/system_timer_base.h @@ -0,0 +1,38 @@ +// Copyright 2023 The Pigweed 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 +// +// https://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. + +#pragma once + +#include <cinttypes> + +#include "pw_chrono/system_timer.h" + +namespace chre { + +class SystemTimerBase { + public: + SystemTimerBase() + : timer_([this](pw::chrono::SystemClock::time_point) { + this->OnExpired(); + }) {} + + protected: + void OnExpired(); + + bool is_active_ = false; + bool initialized_ = false; + pw::chrono::SystemTimer timer_; +}; + +} // namespace chre |