// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #ifndef __ESP_INTR_ALLOC_H__ #define __ESP_INTR_ALLOC_H__ #include #include #include "esp_err.h" #include "freertos/xtensa_api.h" #ifdef __cplusplus extern "C" { #endif /** @addtogroup Intr_Alloc * @{ */ /** @brief Interrupt allocation flags * * These flags can be used to specify which interrupt qualities the * code calling esp_intr_alloc* needs. * */ //Keep the LEVELx values as they are here; they match up with (1<3 * is requested, because these types of interrupts aren't C-callable. * @param arg Optional argument for passed to the interrupt handler * @param ret_handle Pointer to an intr_handle_t to store a handle that can later be * used to request details or free the interrupt. Can be NULL if no handle * is required. * * @return ESP_ERR_INVALID_ARG if the combination of arguments is invalid. * ESP_ERR_NOT_FOUND No free interrupt found with the specified flags * ESP_OK otherwise */ esp_err_t esp_intr_alloc(int source, int flags, intr_handler_t handler, void *arg, intr_handle_t *ret_handle); /** * @brief Allocate an interrupt with the given parameters. * * * This essentially does the same as esp_intr_alloc, but allows specifying a register and mask * combo. For shared interrupts, the handler is only called if a read from the specified * register, ANDed with the mask, returns non-zero. By passing an interrupt status register * address and a fitting mask, this can be used to accelerate interrupt handling in the case * a shared interrupt is triggered; by checking the interrupt statuses first, the code can * decide which ISRs can be skipped * * @param source The interrupt source. One of the ETS_*_INTR_SOURCE interrupt mux * sources, as defined in soc/soc.h, or one of the internal * ETS_INTERNAL_*_INTR_SOURCE sources as defined in this header. * @param flags An ORred mask of the ESP_INTR_FLAG_* defines. These restrict the * choice of interrupts that this routine can choose from. If this value * is 0, it will default to allocating a non-shared interrupt of level * 1, 2 or 3. If this is ESP_INTR_FLAG_SHARED, it will allocate a shared * interrupt of level 1. Setting ESP_INTR_FLAG_INTRDISABLED will return * from this function with the interrupt disabled. * @param intrstatusreg The address of an interrupt status register * @param intrstatusmask A mask. If a read of address intrstatusreg has any of the bits * that are 1 in the mask set, the ISR will be called. If not, it will be * skipped. * @param handler The interrupt handler. Must be NULL when an interrupt of level >3 * is requested, because these types of interrupts aren't C-callable. * @param arg Optional argument for passed to the interrupt handler * @param ret_handle Pointer to an intr_handle_t to store a handle that can later be * used to request details or free the interrupt. Can be NULL if no handle * is required. * * @return ESP_ERR_INVALID_ARG if the combination of arguments is invalid. * ESP_ERR_NOT_FOUND No free interrupt found with the specified flags * ESP_OK otherwise */ esp_err_t esp_intr_alloc_intrstatus(int source, int flags, uint32_t intrstatusreg, uint32_t intrstatusmask, intr_handler_t handler, void *arg, intr_handle_t *ret_handle); /** * @brief Disable and free an interrupt. * * Use an interrupt handle to disable the interrupt and release the resources * associated with it. * * @note * When the handler shares its source with other handlers, the interrupt status * bits it's responsible for should be managed properly before freeing it. see * ``esp_intr_disable`` for more details. * * @param handle The handle, as obtained by esp_intr_alloc or esp_intr_alloc_intrstatus * * @return ESP_ERR_INVALID_ARG if handle is invalid, or esp_intr_free runs on another core than * where the interrupt is allocated on. * ESP_OK otherwise */ esp_err_t esp_intr_free(intr_handle_t handle); /** * @brief Get CPU number an interrupt is tied to * * @param handle The handle, as obtained by esp_intr_alloc or esp_intr_alloc_intrstatus * * @return The core number where the interrupt is allocated */ int esp_intr_get_cpu(intr_handle_t handle); /** * @brief Get the allocated interrupt for a certain handle * * @param handle The handle, as obtained by esp_intr_alloc or esp_intr_alloc_intrstatus * * @return The interrupt number */ int esp_intr_get_intno(intr_handle_t handle); /** * @brief Disable the interrupt associated with the handle * * @note * 1. For local interrupts (ESP_INTERNAL_* sources), this function has to be called on the * CPU the interrupt is allocated on. Other interrupts have no such restriction. * 2. When several handlers sharing a same interrupt source, interrupt status bits, which are * handled in the handler to be disabled, should be masked before the disabling, or handled * in other enabled interrupts properly. Miss of interrupt status handling will cause infinite * interrupt calls and finally system crash. * * @param handle The handle, as obtained by esp_intr_alloc or esp_intr_alloc_intrstatus * * @return ESP_ERR_INVALID_ARG if the combination of arguments is invalid. * ESP_OK otherwise */ esp_err_t esp_intr_disable(intr_handle_t handle); /** * @brief Enable the interrupt associated with the handle * * @note For local interrupts (ESP_INTERNAL_* sources), this function has to be called on the * CPU the interrupt is allocated on. Other interrupts have no such restriction. * * @param handle The handle, as obtained by esp_intr_alloc or esp_intr_alloc_intrstatus * * @return ESP_ERR_INVALID_ARG if the combination of arguments is invalid. * ESP_OK otherwise */ esp_err_t esp_intr_enable(intr_handle_t handle); /** * @brief Set the "in IRAM" status of the handler. * * @note Does not work on shared interrupts. * * @param handle The handle, as obtained by esp_intr_alloc or esp_intr_alloc_intrstatus * @param is_in_iram Whether the handler associated with this handle resides in IRAM. * Handlers residing in IRAM can be called when cache is disabled. * * @return ESP_ERR_INVALID_ARG if the combination of arguments is invalid. * ESP_OK otherwise */ esp_err_t esp_intr_set_in_iram(intr_handle_t handle, bool is_in_iram); /** * @brief Disable interrupts that aren't specifically marked as running from IRAM */ void esp_intr_noniram_disable(void); /** * @brief Re-enable interrupts disabled by esp_intr_noniram_disable */ void esp_intr_noniram_enable(void); /**@}*/ #ifdef __cplusplus } #endif #endif