esp_freertos_hooks.h 4.8 KB

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