xref: /aosp_15_r20/external/pigweed/pw_chre/chre.cc (revision 61c4878ac05f98d0ceed94b57d316916de578985)
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 
15 #include "pw_chre/chre.h"
16 
17 #include "chre/core/event_loop.h"
18 #include "chre/core/event_loop_manager.h"
19 #include "chre/core/host_comms_manager.h"
20 #include "chre/core/init.h"
21 #include "chre/core/static_nanoapps.h"
22 
23 namespace pw::chre {
24 
Init()25 void Init() {
26   ::chre::init();
27   ::chre::EventLoopManagerSingleton::get()->lateInit();
28   ::chre::loadStaticNanoapps();
29 }
30 
Deinit()31 void Deinit() { ::chre::deinit(); }
32 
RunEventLoop()33 void RunEventLoop() {
34   ::chre::EventLoopManagerSingleton::get()->getEventLoop().run();
35 }
36 
StopEventLoop()37 void StopEventLoop() {
38   ::chre::EventLoopManagerSingleton::get()->getEventLoop().stop();
39 }
40 
SendMessageToNanoapp(pw::chre::NanoappMessage message)41 void SendMessageToNanoapp(pw::chre::NanoappMessage message) {
42   ::chre::HostCommsManager& manager =
43       ::chre::EventLoopManagerSingleton::get()->getHostCommsManager();
44   manager.sendMessageToNanoappFromHost(message.nano_app_id,
45                                        message.message_type,
46                                        message.host_endpoint,
47                                        message.data,
48                                        message.length);
49 }
50 
FreeMessageToAp(MessageToApContext context)51 void FreeMessageToAp(MessageToApContext context) {
52   auto& hostCommsManager =
53       ::chre::EventLoopManagerSingleton::get()->getHostCommsManager();
54   hostCommsManager.onMessageToHostComplete(
55       static_cast<const ::chre::MessageToHost*>(context));
56 }
57 
SetEstimatedHostTimeOffset(int64_t offset)58 void SetEstimatedHostTimeOffset(int64_t offset) {
59   ::chre::SystemTime::setEstimatedHostTimeOffset(offset);
60 }
61 
62 }  // namespace pw::chre
63