3 * Copyright (c) 2021 Project CHIP Authors
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
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"
29 #include "RpcService.h"
32 #include "lwip/sockets.h"
35 const char * TAG = "chip-pigweed-app";
40 constexpr size_t kRpcStackSizeBytes = (4 * 1024);
41 constexpr uint8_t kRpcTaskPriority = 5;
43 SemaphoreHandle_t uart_mutex;
45 class LoggerMutex : public chip::rpc::Mutex
48 void Lock() override { xSemaphoreTake(uart_mutex, portMAX_DELAY); }
49 void Unlock() override { xSemaphoreGive(uart_mutex); }
52 LoggerMutex logger_mutex;
54 TaskHandle_t rpcTaskHandle;
56 pw::rpc::EchoService echo_service;
58 void RegisterServices(pw::rpc::Server & server)
60 server.RegisterService(echo_service);
63 void RunRpcService(void *)
65 ::chip::rpc::Start(RegisterServices, &logger_mutex);
70 extern "C" void app_main()
74 ESP_LOGI(TAG, "----------- chip-esp32-pigweed-example starting -----------");
76 uart_mutex = xSemaphoreCreateMutex();
77 xTaskCreate(RunRpcService, "RPC", kRpcStackSizeBytes / sizeof(StackType_t), nullptr, kRpcTaskPriority, &rpcTaskHandle);
81 vTaskDelay(50 / portTICK_PERIOD_MS);