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