1 // Copyright 2021 Espressif Systems (Shanghai) CO LTD 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 7 // http://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, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License 14 15 #pragma once 16 17 #include "esp_err.h" 18 #include "esp_openthread_types.h" 19 #include "openthread/error.h" 20 #include "openthread/instance.h" 21 22 #ifdef __cplusplus 23 extern "C" { 24 #endif 25 26 /** 27 * @brief Initializes the full OpenThread stack. 28 * 29 * @note The OpenThread instance will also be initialized in this function. 30 * 31 * @param[in] init_config The initialization configuration. 32 * 33 * @return 34 * - ESP_OK on success 35 * - ESP_ERR_NO_MEM if allocation has failed 36 * - ESP_ERR_INVALID_ARG if radio or host connection mode not supported 37 * - ESP_ERR_INVALID_STATE if already initialized 38 * 39 */ 40 esp_err_t esp_openthread_init(const esp_openthread_platform_config_t *init_config); 41 42 /** 43 * @brief Launches the OpenThread main loop. 44 * 45 * @note Thie function will not return unless error happens when running the OpenThread stack. 46 * 47 * @return 48 * - ESP_OK on success 49 * - ESP_ERR_NO_MEM if allocation has failed 50 * - ESP_FAIL on other failures 51 * 52 */ 53 esp_err_t esp_openthread_launch_mainloop(void); 54 55 /** 56 * @brief This function performs OpenThread stack and platform driver deinitialization. 57 * 58 * @return 59 * - ESP_OK on success 60 * - ESP_ERR_INVALID_STATE if not initialized 61 * 62 */ 63 esp_err_t esp_openthread_deinit(void); 64 65 /** 66 * @brief This function acquires the underlying OpenThread instance. 67 * 68 * @note This function can be called on other tasks without lock. 69 * 70 * @return The OpenThread instance pointer 71 * 72 */ 73 otInstance *esp_openthread_get_instance(void); 74 75 #ifdef __cplusplus 76 } // end of extern "C" 77 #endif 78