1 // Copyright 2018 Espressif Systems (Shanghai) PTE 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 "freertos/FreeRTOSConfig.h" 19 20 #ifdef __cplusplus 21 extern "C" { 22 #endif 23 24 #ifndef PTHREAD_STACK_MIN 25 #define PTHREAD_STACK_MIN CONFIG_PTHREAD_STACK_MIN 26 #endif 27 28 /** pthread configuration structure that influences pthread creation */ 29 typedef struct { 30 size_t stack_size; ///< The stack size of the pthread 31 size_t prio; ///< The thread's priority 32 bool inherit_cfg; ///< Inherit this configuration further 33 const char* thread_name; ///< The thread name. 34 int pin_to_core; ///< The core id to pin the thread to. Has the same value range as xCoreId argument of xTaskCreatePinnedToCore. 35 } esp_pthread_cfg_t; 36 37 /** 38 * @brief Creates a default pthread configuration based 39 * on the values set via menuconfig. 40 * 41 * @return 42 * A default configuration structure. 43 */ 44 esp_pthread_cfg_t esp_pthread_get_default_config(void); 45 46 /** 47 * @brief Configure parameters for creating pthread 48 * 49 * This API allows you to configure how the subsequent 50 * pthread_create() call will behave. This call can be used to setup 51 * configuration parameters like stack size, priority, configuration 52 * inheritance etc. 53 * 54 * If the 'inherit' flag in the configuration structure is enabled, 55 * then the same configuration is also inherited in the thread 56 * subtree. 57 * 58 * @note Passing non-NULL attributes to pthread_create() will override 59 * the stack_size parameter set using this API 60 * 61 * @param cfg The pthread config parameters 62 * 63 * @return 64 * - ESP_OK if configuration was successfully set 65 * - ESP_ERR_NO_MEM if out of memory 66 * - ESP_ERR_INVALID_ARG if stack_size is less than PTHREAD_STACK_MIN 67 */ 68 esp_err_t esp_pthread_set_cfg(const esp_pthread_cfg_t *cfg); 69 70 /** 71 * @brief Get current pthread creation configuration 72 * 73 * This will retrieve the current configuration that will be used for 74 * creating threads. 75 * 76 * @param p Pointer to the pthread config structure that will be 77 * updated with the currently configured parameters 78 * 79 * @return 80 * - ESP_OK if the configuration was available 81 * - ESP_ERR_NOT_FOUND if a configuration wasn't previously set 82 */ 83 esp_err_t esp_pthread_get_cfg(esp_pthread_cfg_t *p); 84 85 /** 86 * @brief Initialize pthread library 87 */ 88 esp_err_t esp_pthread_init(void); 89 90 #ifdef __cplusplus 91 } 92 #endif 93