blob: 21577861149523bfe94fd0bb2ba119976e3acb58 [file] [log] [blame]
Carlos Chinchillaecf3d802021-12-08 12:35:54 -08001// Copyright 2021 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_system/init.h"
16
17#include "pw_log/log.h"
18#include "pw_rpc/echo_service_nanopb.h"
Armando Montanezce59a872022-03-16 11:14:28 -070019#include "pw_system/rpc_server.h"
Armando Montanez2c042f92021-12-15 14:55:36 -080020#include "pw_system/target_hooks.h"
21#include "pw_system/work_queue.h"
Carlos Chinchillaecf3d802021-12-08 12:35:54 -080022#include "pw_system_private/log.h"
Carlos Chinchillaecf3d802021-12-08 12:35:54 -080023#include "pw_thread/detached_thread.h"
24
25namespace pw::system {
26namespace {
27rpc::EchoService echo_service;
Carlos Chinchillaecf3d802021-12-08 12:35:54 -080028
Armando Montanez2c042f92021-12-15 14:55:36 -080029void InitImpl() {
Carlos Chinchillaecf3d802021-12-08 12:35:54 -080030 PW_LOG_INFO("System init");
31
32 // Setup logging.
33 const Status status = GetLogThread().OpenUnrequestedLogStream(
Armando Montanezce59a872022-03-16 11:14:28 -070034 kDefaultRpcChannelId, GetRpcServer(), GetLogService());
Carlos Chinchillaecf3d802021-12-08 12:35:54 -080035 if (!status.ok()) {
Carlos Chinchilla4021c352021-12-15 16:08:33 -080036 PW_LOG_ERROR("Error opening unrequested log streams %d",
37 static_cast<int>(status.code()));
Carlos Chinchillaecf3d802021-12-08 12:35:54 -080038 }
39
40 PW_LOG_INFO("Registering RPC services");
41 GetRpcServer().RegisterService(echo_service);
42 GetRpcServer().RegisterService(GetLogService());
43
44 PW_LOG_INFO("Starting threads");
45 // Start threads.
46 thread::DetachedThread(system::LogThreadOptions(), GetLogThread());
47 thread::DetachedThread(system::RpcThreadOptions(), GetRpcDispatchThread());
Armando Montanez2c042f92021-12-15 14:55:36 -080048
49 GetWorkQueue().CheckPushWork(UserAppInit);
50}
51
52} // namespace
53
54void Init() {
55 thread::DetachedThread(system::WorkQueueThreadOptions(), GetWorkQueue());
56 GetWorkQueue().CheckPushWork(InitImpl);
Carlos Chinchillaecf3d802021-12-08 12:35:54 -080057}
58
59} // namespace pw::system