Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / examples / pigweed-app / esp32 / main / main.cpp
1 /*
2  *
3  *    Copyright (c) 2021 Project CHIP Authors
4  *
5  *    Licensed under the Apache License, Version 2.0 (the "License");
6  *    you may not use this file except in compliance with the License.
7  *    You may obtain a copy of the License at
8  *
9  *        http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *    Unless required by applicable law or agreed to in writing, software
12  *    distributed under the License is distributed on an "AS IS" BASIS,
13  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *    See the License for the specific language governing permissions and
15  *    limitations under the License.
16  */
17
18 #include "esp_log.h"
19 #include "freertos/FreeRTOS.h"
20 #include "freertos/event_groups.h"
21 #include "freertos/semphr.h"
22 #include "freertos/task.h"
23 #include "pw_log/log.h"
24 #include "pw_rpc/echo_service_nanopb.h"
25 #include "pw_rpc/server.h"
26 #include "pw_sys_io/sys_io.h"
27 #include "pw_sys_io_esp32/init.h"
28
29 #include "RpcService.h"
30
31 #include "lwip/err.h"
32 #include "lwip/sockets.h"
33 #include "lwip/sys.h"
34
35 const char * TAG = "chip-pigweed-app";
36
37 namespace {
38 using std::byte;
39
40 constexpr size_t kRpcStackSizeBytes = (4 * 1024);
41 constexpr uint8_t kRpcTaskPriority  = 5;
42
43 SemaphoreHandle_t uart_mutex;
44
45 class LoggerMutex : public chip::rpc::Mutex
46 {
47 public:
48     void Lock() override { xSemaphoreTake(uart_mutex, portMAX_DELAY); }
49     void Unlock() override { xSemaphoreGive(uart_mutex); }
50 };
51
52 LoggerMutex logger_mutex;
53
54 TaskHandle_t rpcTaskHandle;
55
56 pw::rpc::EchoService echo_service;
57
58 void RegisterServices(pw::rpc::Server & server)
59 {
60     server.RegisterService(echo_service);
61 }
62
63 void RunRpcService(void *)
64 {
65     ::chip::rpc::Start(RegisterServices, &logger_mutex);
66 }
67
68 } // namespace
69
70 extern "C" void app_main()
71 {
72     pw_sys_io_Init();
73
74     ESP_LOGI(TAG, "----------- chip-esp32-pigweed-example starting -----------");
75
76     uart_mutex = xSemaphoreCreateMutex();
77     xTaskCreate(RunRpcService, "RPC", kRpcStackSizeBytes / sizeof(StackType_t), nullptr, kRpcTaskPriority, &rpcTaskHandle);
78
79     while (1)
80     {
81         vTaskDelay(50 / portTICK_PERIOD_MS);
82     }
83 }