Skip to content

Commit 2e1ba54

Browse files
committed
platform: Support zephyr
Add an implementation for platform/zephyr along with appropriate build rules and Kconfig. This was tested against zephyrproject-rtos/zephyr#41735 Signed-off-by: Yuval Peress <[email protected]> Change-Id: I34cd7b100db1d1c2411b9151d537ce6594d2cd89
1 parent 4a4454e commit 2e1ba54

27 files changed

+1174
-3
lines changed

platform/zephyr/CMakeLists.txt

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# Copyright (C) 2022 The Android Open Source Project
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://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,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
if(CONFIG_CHRE)
16+
get_filename_component(CHRE_DIR "${ZEPHYR_CURRENT_MODULE_DIR}" ABSOLUTE)
17+
18+
zephyr_library()
19+
20+
set(CHRE_INCLUDE_DIRS
21+
"${CHRE_DIR}/chpp/include"
22+
"${CHRE_DIR}/chre_api/include"
23+
"${CHRE_DIR}/chre_api/include/chre_api"
24+
"${CHRE_DIR}/core/include"
25+
"${CHRE_DIR}/pal/include"
26+
"${CHRE_DIR}/platform/include"
27+
"${CHRE_DIR}/platform/shared/include"
28+
"${CHRE_DIR}/util/include"
29+
"${CMAKE_CURRENT_SOURCE_DIR}/include")
30+
zephyr_include_directories("${CHRE_INCLUDE_DIRS}")
31+
zephyr_library_include_directories("${CHRE_INCLUDE_DIRS}")
32+
33+
zephyr_library_sources(
34+
"context.cc"
35+
"host_link.cc"
36+
"init.cc"
37+
"log_module.c"
38+
"memory.cc"
39+
"platform_nanoapp.cc"
40+
"power_control_manager.cc"
41+
"system_time.cc"
42+
"system_timer.cc"
43+
"${CHRE_DIR}/core/debug_dump_manager.cc"
44+
"${CHRE_DIR}/core/event.cc"
45+
"${CHRE_DIR}/core/event_loop.cc"
46+
"${CHRE_DIR}/core/event_loop_manager.cc"
47+
"${CHRE_DIR}/core/event_ref_queue.cc"
48+
"${CHRE_DIR}/core/host_comms_manager.cc"
49+
"${CHRE_DIR}/core/init.cc"
50+
"${CHRE_DIR}/core/nanoapp.cc"
51+
"${CHRE_DIR}/core/settings.cc"
52+
"${CHRE_DIR}/core/static_nanoapps.cc"
53+
"${CHRE_DIR}/core/timer_pool.cc"
54+
"${CHRE_DIR}/platform/shared/version.cc"
55+
"${CHRE_DIR}/platform/shared/system_time.cc"
56+
"${CHRE_DIR}/util/dynamic_vector_base.cc"
57+
)
58+
59+
# Optional audio support
60+
if(CONFIG_CHRE_AUDIO_SUPPORT_ENABLED)
61+
zephyr_compile_definitions(CHRE_AUDIO_SUPPORT_ENABLED)
62+
zephyr_library_sources("${CHRE_DIR}/core/audio_request_manager.cc")
63+
endif()
64+
65+
# Optional GNSS support
66+
if(CONFIG_CHRE_GNSS_SUPPORT_ENABLED)
67+
zephyr_compile_definitions(CHRE_GNSS_SUPPORT_ENABLED)
68+
zephyr_library_sources("${CHRE_DIR}/core/gnss_manager.cc")
69+
endif()
70+
71+
# Optional sensor support
72+
if(CONFIG_CHRE_SENSORS_SUPPORT_ENABLED)
73+
zephyr_compile_definitions(CHRE_SENSORS_SUPPORT_ENABLED)
74+
zephyr_library_sources(
75+
"${CHRE_DIR}/core/sensor.cc"
76+
"${CHRE_DIR}/core/sensor_request.cc"
77+
"${CHRE_DIR}/core/sensor_request_manager.cc"
78+
"${CHRE_DIR}/core/sensor_request_multiplexer.cc"
79+
"${CHRE_DIR}/core/sensor_type.cc"
80+
"${CHRE_DIR}/core/sensor_type_helpers.cc"
81+
)
82+
endif()
83+
84+
# Optional WiFi support
85+
if(CONFIG_CHRE_WIFI_SUPPORT_ENABLED)
86+
zephyr_compile_definitions(CHRE_WIFI_SUPPORT_ENABLED)
87+
zephyr_library_sources(
88+
"${CHRE_DIR}/core/wifi_request_manager.cc"
89+
"${CHRE_DIR}/core/wifi_scan_request.cc"
90+
)
91+
endif()
92+
93+
# Optional WWAN support
94+
if(CONFIG_CHRE_WWAN_SUPPORT_ENABLED)
95+
zephyr_compile_definitions(CHRE_WWAN_SUPPORT_ENABLED)
96+
zephyr_library_sources("${CHRE_DIR}/core/wwan_request_manager.cc")
97+
endif()
98+
99+
zephyr_compile_definitions(
100+
CHRE_MESSAGE_TO_HOST_MAX_SIZE=${CONFIG_CHRE_MESSAGE_TO_HOST_MAX_SIZE})
101+
102+
zephyr_compile_definitions(CHRE_FILENAME=__FILE__)
103+
104+
# Add logging definitions
105+
if((NOT DEFINED CONFIG_CHRE_LOG_LEVEL) OR
106+
"${CONFIG_CHRE_LOG_LEVEL}" EQUAL "0")
107+
zephyr_compile_definitions(CHRE_MINIMUM_LOG_LEVEL=CHRE_LOG_LEVEL_MUTE)
108+
elseif("${CONFIG_CHRE_LOG_LEVEL}" EQUAL "1")
109+
zephyr_compile_definitions(CHRE_MINIMUM_LOG_LEVEL=CHRE_LOG_LEVEL_ERROR)
110+
elseif("${CONFIG_CHRE_LOG_LEVEL}" EQUAL "2")
111+
zephyr_compile_definitions(CHRE_MINIMUM_LOG_LEVEL=CHRE_LOG_LEVEL_WARN)
112+
elseif("${CONFIG_CHRE_LOG_LEVEL}" EQUAL "3")
113+
zephyr_compile_definitions(CHRE_MINIMUM_LOG_LEVEL=CHRE_LOG_LEVEL_INFO)
114+
elseif(("${CONFIG_CHRE_LOG_LEVEL}" EQUAL "4") OR
115+
("${CONFIG_CHRE_LOG_LEVEL}" EQUAL "5"))
116+
# Debug and verbose are collapsed into one since Zephyr doesn't
117+
# differentiate the two levels
118+
zephyr_compile_definitions(CHRE_MINIMUM_LOG_LEVEL=CHRE_LOG_LEVEL_VERBOSE)
119+
endif()
120+
121+
if(DEFINED CONFIG_CHRE_ASSERTIONS)
122+
zephyr_compile_definitions(CHRE_ASSERTIONS_ENABLED)
123+
else()
124+
zephyr_compile_definitions(CHRE_ASSERTIONS_DISABLED)
125+
endif()
126+
127+
zephyr_compile_definitions(CHRE_FIRST_SUPPORTED_API_VERSION=CHRE_API_VERSION_1_5)
128+
endif()

platform/zephyr/Kconfig

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Copyright (c) 2021 Google LLC
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
config ZEPHYR_CHRE_MODULE
5+
bool
6+
7+
menuconfig CHRE
8+
bool "CHRE Support"
9+
help
10+
This option enables the CHRE library.
11+
12+
if CHRE
13+
14+
module = CHRE
15+
module-str = chre
16+
source "subsys/logging/Kconfig.template.log_config"
17+
18+
config CHRE_MESSAGE_TO_HOST_MAX_SIZE
19+
int "Maximum message size to send to the host (bytes)"
20+
default 4000
21+
help
22+
Defines the maximum message size that can be sent to the host.
23+
24+
config CHRE_ASSERTIONS
25+
bool "Enable CHRE assertions"
26+
help
27+
When enabled, CHRE will include various assertions which will trigger
28+
calls to chreAbort if resolve to false.
29+
30+
config CHRE_AUDIO_SUPPORT_ENABLED
31+
bool "Enable audio support"
32+
help
33+
When enabled, CHRE will include the code needed to support the audio
34+
framework. The framework should be provided via chrePalAudioGetApi()
35+
36+
config CHRE_GNSS_SUPPORT_ENABLED
37+
bool "Enable GNSS support"
38+
help
39+
When enabled, CHRE will include the code needed to support the GNSS
40+
framework. The framework should be provided via chrePalGnssGetApi()
41+
42+
config CHRE_SENSORS_SUPPORT_ENABLED
43+
bool "Enable sensor support"
44+
help
45+
When enabled, CHRE will include the code needed to support the sensor
46+
framework. The framework should be provided via chrePalSensorGetApi()
47+
48+
config CHRE_WIFI_SUPPORT_ENABLED
49+
bool "Enable WiFi support"
50+
help
51+
When enabled, CHRE will include the code needed to support the WiFi
52+
framework. The framework should be provided via chrePalWifiGetApi()
53+
54+
config CHRE_DYNAMIC_MEMORY_SIZE
55+
int "The size of the CHRE memory pool"
56+
default 4096
57+
58+
config CHRE_TASK_NAME
59+
string "The name of the CHRE task"
60+
default "CHRE"
61+
62+
config CHRE_TASK_STACK_SIZE
63+
int "The size of the CHRE task stack"
64+
default 2048
65+
66+
config CHRE_TASK_PRIORITY
67+
int "The priority of the CHRE task"
68+
default 5
69+
70+
endif # CHRE

platform/zephyr/context.cc

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright (C) 2022 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "chre/platform/context.h"
18+
19+
#include <zephyr.h>
20+
#include "chre/target_platform/init.h"
21+
22+
namespace chre {
23+
24+
bool inEventLoopThread() {
25+
k_tid_t evtLoopTaskId = zephyr::getChreTaskId();
26+
k_tid_t currentTaskId = k_current_get();
27+
28+
return (evtLoopTaskId == currentTaskId);
29+
}
30+
31+
} // namespace chre

platform/zephyr/host_link.cc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright (C) 2022 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "chre/platform/host_link.h"
18+
19+
namespace chre {
20+
21+
void HostLink::flushMessagesSentByNanoapp(uint64_t appId) {
22+
// TODO: implement
23+
}
24+
25+
bool HostLink::sendMessage(const MessageToHost *message) {
26+
// TODO: implement
27+
return false;
28+
}
29+
30+
} // namespace chre
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright (C) 2022 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#ifndef CHRE_PLATFORM_ZEPHYR_ATOMIC_BASE_H_
18+
#define CHRE_PLATFORM_ZEPHYR_ATOMIC_BASE_H_
19+
20+
#include <sys/atomic.h>
21+
22+
namespace chre {
23+
24+
class AtomicBase {
25+
protected:
26+
atomic_t value;
27+
};
28+
29+
typedef AtomicBase AtomicBoolBase;
30+
typedef AtomicBase AtomicUint32Base;
31+
32+
} // namespace chre
33+
34+
#endif // CHRE_PLATFORM_ZEPHYR_ATOMIC_BASE_H_
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* Copyright (C) 2022 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#ifndef CHRE_PLATFORM_ZEPHYR_ATOMIC_BASE_IMPL_H_
18+
#define CHRE_PLATFORM_ZEPHYR_ATOMIC_BASE_IMPL_H_
19+
20+
#include <sys/atomic.h>
21+
22+
#include "chre/platform/atomic.h"
23+
24+
namespace chre {
25+
26+
inline AtomicBool::AtomicBool(bool starting_value) {
27+
value = ATOMIC_INIT(starting_value);
28+
}
29+
30+
inline bool AtomicBool::operator=(bool desired) {
31+
return atomic_set(&value, desired);
32+
}
33+
34+
inline bool AtomicBool::load() const {
35+
return atomic_get(&value);
36+
}
37+
38+
inline void AtomicBool::store(bool desired) {
39+
atomic_set(&value, desired);
40+
}
41+
42+
inline bool AtomicBool::exchange(bool desired) {
43+
return atomic_set(&value, desired);
44+
}
45+
46+
inline AtomicUint32::AtomicUint32(uint32_t starting_value) {
47+
value = ATOMIC_INIT(starting_value);
48+
}
49+
50+
inline uint32_t AtomicUint32::operator=(uint32_t desired) {
51+
return atomic_set(&value, desired);
52+
}
53+
54+
inline uint32_t AtomicUint32::load() const {
55+
return atomic_get(&value);
56+
}
57+
58+
inline void AtomicUint32::store(uint32_t desired) {
59+
atomic_set(&value, desired);
60+
}
61+
62+
inline uint32_t AtomicUint32::exchange(uint32_t desired) {
63+
return atomic_set(&value, desired);
64+
}
65+
66+
inline uint32_t AtomicUint32::fetch_add(uint32_t arg) {
67+
return atomic_add(&value, arg);
68+
}
69+
70+
inline uint32_t AtomicUint32::fetch_increment() {
71+
return atomic_inc(&value);
72+
}
73+
74+
inline uint32_t AtomicUint32::fetch_sub(uint32_t arg) {
75+
return atomic_sub(&value, arg);
76+
}
77+
78+
inline uint32_t AtomicUint32::fetch_decrement() {
79+
return atomic_dec(&value);
80+
}
81+
82+
} // namespace chre
83+
84+
#endif // CHRE_PLATFORM_ZEPHYR_ATOMIC_BASE_IMPL_H_

0 commit comments

Comments
 (0)