esp_freertos_hooks.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. // Copyright 2015-2016 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. #ifndef __ESP_FREERTOS_HOOKS_H__
  14. #define __ESP_FREERTOS_HOOKS_H__
  15. #include <stdbool.h>
  16. #include "freertos/portmacro.h"
  17. #include "esp_err.h"
  18. #ifdef __cplusplus
  19. extern "C"
  20. {
  21. #endif
  22. /*
  23. Definitions for the tickhook and idlehook callbacks
  24. */
  25. typedef bool (*esp_freertos_idle_cb_t)(void);
  26. typedef void (*esp_freertos_tick_cb_t)(void);
  27. /**
  28. * @brief Register a callback to be called from the specified core's idle hook.
  29. * The callback should return true if it should be called by the idle hook
  30. * once per interrupt (or FreeRTOS tick), and return false if it should
  31. * be called repeatedly as fast as possible by the idle hook.
  32. *
  33. * @warning Idle callbacks MUST NOT, UNDER ANY CIRCUMSTANCES, CALL
  34. * A FUNCTION THAT MIGHT BLOCK.
  35. *
  36. * @param[in] new_idle_cb Callback to be called
  37. * @param[in] cpuid id of the core
  38. *
  39. * @return
  40. * - ESP_OK: Callback registered to the specified core's idle hook
  41. * - ESP_ERR_NO_MEM: No more space on the specified core's idle hook to register callback
  42. * - ESP_ERR_INVALID_ARG: cpuid is invalid
  43. */
  44. esp_err_t esp_register_freertos_idle_hook_for_cpu(esp_freertos_idle_cb_t new_idle_cb, UBaseType_t cpuid);
  45. /**
  46. * @brief Register a callback to the idle hook of the core that calls this function.
  47. * The callback should return true if it should be called by the idle hook
  48. * once per interrupt (or FreeRTOS tick), and return false if it should
  49. * be called repeatedly as fast as possible by the idle hook.
  50. *
  51. * @warning Idle callbacks MUST NOT, UNDER ANY CIRCUMSTANCES, CALL
  52. * A FUNCTION THAT MIGHT BLOCK.
  53. *
  54. * @param[in] new_idle_cb Callback to be called
  55. *
  56. * @return
  57. * - ESP_OK: Callback registered to the calling core's idle hook
  58. * - ESP_ERR_NO_MEM: No more space on the calling core's idle hook to register callback
  59. */
  60. esp_err_t esp_register_freertos_idle_hook(esp_freertos_idle_cb_t new_idle_cb);
  61. /**
  62. * @brief Register a callback to be called from the specified core's tick hook.
  63. *
  64. * @param[in] new_tick_cb Callback to be called
  65. * @param[in] cpuid id of the core
  66. *
  67. * @return
  68. * - ESP_OK: Callback registered to specified core's tick hook
  69. * - ESP_ERR_NO_MEM: No more space on the specified core's tick hook to register the callback
  70. * - ESP_ERR_INVALID_ARG: cpuid is invalid
  71. */
  72. esp_err_t esp_register_freertos_tick_hook_for_cpu(esp_freertos_tick_cb_t new_tick_cb, UBaseType_t cpuid);
  73. /**
  74. * @brief Register a callback to be called from the calling core's tick hook.
  75. *
  76. * @param[in] new_tick_cb Callback to be called
  77. *
  78. * @return
  79. * - ESP_OK: Callback registered to the calling core's tick hook
  80. * - ESP_ERR_NO_MEM: No more space on the calling core's tick hook to register the callback
  81. */
  82. esp_err_t esp_register_freertos_tick_hook(esp_freertos_tick_cb_t new_tick_cb);
  83. /**
  84. * @brief Unregister an idle callback from the idle hook of the specified core
  85. *
  86. * @param[in] old_idle_cb Callback to be unregistered
  87. * @param[in] cpuid id of the core
  88. */
  89. void esp_deregister_freertos_idle_hook_for_cpu(esp_freertos_idle_cb_t old_idle_cb, UBaseType_t cpuid);
  90. /**
  91. * @brief Unregister an idle callback. If the idle callback is registered to
  92. * the idle hooks of both cores, the idle hook will be unregistered from
  93. * both cores
  94. *
  95. * @param[in] old_idle_cb Callback to be unregistered
  96. */
  97. void esp_deregister_freertos_idle_hook(esp_freertos_idle_cb_t old_idle_cb);
  98. /**
  99. * @brief Unregister a tick callback from the tick hook of the specified core
  100. *
  101. * @param[in] old_tick_cb Callback to be unregistered
  102. * @param[in] cpuid id of the core
  103. */
  104. void esp_deregister_freertos_tick_hook_for_cpu(esp_freertos_tick_cb_t old_tick_cb, UBaseType_t cpuid);
  105. /**
  106. * @brief Unregister a tick callback. If the tick callback is registered to the
  107. * tick hooks of both cores, the tick hook will be unregistered from
  108. * both cores
  109. *
  110. * @param[in] old_tick_cb Callback to be unregistered
  111. */
  112. void esp_deregister_freertos_tick_hook(esp_freertos_tick_cb_t old_tick_cb);
  113. #ifdef __cplusplus
  114. }
  115. #endif
  116. #endif