esp_pthread.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #pragma once
  14. #include "esp_err.h"
  15. #include <freertos/FreeRTOSConfig.h>
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. #ifndef PTHREAD_STACK_MIN
  20. #define PTHREAD_STACK_MIN CONFIG_PTHREAD_STACK_MIN
  21. #endif
  22. /** pthread configuration structure that influences pthread creation */
  23. typedef struct {
  24. size_t stack_size; ///< The stack size of the pthread
  25. size_t prio; ///< The thread's priority
  26. bool inherit_cfg; ///< Inherit this configuration further
  27. const char* thread_name; ///< The thread name.
  28. int pin_to_core; ///< The core id to pin the thread to. Has the same value range as xCoreId argument of xTaskCreatePinnedToCore.
  29. } esp_pthread_cfg_t;
  30. /**
  31. * @brief Creates a default pthread configuration based
  32. * on the values set via menuconfig.
  33. *
  34. * @return
  35. * A default configuration structure.
  36. */
  37. esp_pthread_cfg_t esp_pthread_get_default_config(void);
  38. /**
  39. * @brief Configure parameters for creating pthread
  40. *
  41. * This API allows you to configure how the subsequent
  42. * pthread_create() call will behave. This call can be used to setup
  43. * configuration parameters like stack size, priority, configuration
  44. * inheritance etc.
  45. *
  46. * If the 'inherit' flag in the configuration structure is enabled,
  47. * then the same configuration is also inherited in the thread
  48. * subtree.
  49. *
  50. * @note Passing non-NULL attributes to pthread_create() will override
  51. * the stack_size parameter set using this API
  52. *
  53. * @param cfg The pthread config parameters
  54. *
  55. * @return
  56. * - ESP_OK if configuration was successfully set
  57. * - ESP_ERR_NO_MEM if out of memory
  58. * - ESP_ERR_INVALID_ARG if stack_size is less than PTHREAD_STACK_MIN
  59. */
  60. esp_err_t esp_pthread_set_cfg(const esp_pthread_cfg_t *cfg);
  61. /**
  62. * @brief Get current pthread creation configuration
  63. *
  64. * This will retrieve the current configuration that will be used for
  65. * creating threads.
  66. *
  67. * @param p Pointer to the pthread config structure that will be
  68. * updated with the currently configured parameters
  69. *
  70. * @return
  71. * - ESP_OK if the configuration was available
  72. * - ESP_ERR_NOT_FOUND if a configuration wasn't previously set
  73. */
  74. esp_err_t esp_pthread_get_cfg(esp_pthread_cfg_t *p);
  75. #ifdef __cplusplus
  76. }
  77. #endif