1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
46
47
48
49
50
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
82
83
84
85
86
87
/* ... */
#include <stdio.h>
#include <unistd.h>
#include "esp_event.h"
#include "nvs_flash.h"
#include "esp_openthread.h"
#include "esp_ot_config.h"
#include "esp_vfs_eventfd.h"
#include "driver/uart.h"8 includes
#if CONFIG_EXTERNAL_COEX_ENABLE
#include "esp_coexist.h"
#endif
#if !SOC_IEEE802154_SUPPORTED
#error "RCP is only supported for the SoCs which have IEEE 802.15.4 module"
#endif
#define TAG "ot_esp_rcp"
extern void otAppNcpInit(otInstance *instance);
#if CONFIG_EXTERNAL_COEX_ENABLE
#if SOC_EXTERNAL_COEX_ADVANCE
static void ot_external_coexist_init(void)
{
esp_external_coex_gpio_set_t gpio_pin = ESP_OPENTHREAD_DEFAULT_EXTERNAL_COEX_CONFIG();
esp_external_coex_set_work_mode(EXTERNAL_COEX_FOLLOWER_ROLE);
ESP_ERROR_CHECK(esp_enable_extern_coex_gpio_pin(CONFIG_EXTERNAL_COEX_WIRE_TYPE, gpio_pin));
}{...}
/* ... */#endif /* ... */
#endif
static void ot_task_worker(void *aContext)
{
esp_openthread_platform_config_t config = {
.radio_config = ESP_OPENTHREAD_DEFAULT_RADIO_CONFIG(),
.host_config = ESP_OPENTHREAD_DEFAULT_HOST_CONFIG(),
.port_config = ESP_OPENTHREAD_DEFAULT_PORT_CONFIG(),
}{...};
ESP_ERROR_CHECK(esp_openthread_init(&config));
#if CONFIG_EXTERNAL_COEX_ENABLE
ot_external_coexist_init();
#endif
otAppNcpInit(esp_openthread_get_instance());
esp_openthread_launch_mainloop();
esp_vfs_eventfd_unregister();
vTaskDelete(NULL);
}{ ... }
void app_main(void)
{
esp_vfs_eventfd_config_t eventfd_config = {
.max_fds = 2,
}{...};
ESP_ERROR_CHECK(nvs_flash_init());
ESP_ERROR_CHECK(esp_event_loop_create_default());
ESP_ERROR_CHECK(esp_vfs_eventfd_register(&eventfd_config));
xTaskCreate(ot_task_worker, "ot_rcp_main", 3072, xTaskGetCurrentTaskHandle(), 5, NULL);
}{ ... }