1 /* 2 * Copyright (c) 2021 Espressif Systems (Shanghai) Co., Ltd. 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef ZEPHYR_INCLUDE_DRIVERS_ESP_INTR_ALLOC_H__ 8 #define ZEPHYR_INCLUDE_DRIVERS_ESP_INTR_ALLOC_H__ 9 10 #include <stdint.h> 11 #include <stdbool.h> 12 #include <soc.h> 13 /* 14 * Interrupt allocation flags - These flags can be used to specify 15 * which interrupt qualities the code calling esp_intr_alloc* needs. 16 */ 17 18 /* Keep the LEVELx values as they are here; they match up with (1<<level) */ 19 #define ESP_INTR_FLAG_LEVEL1 (1<<1) /* Accept a Level 1 int vector, lowest priority */ 20 #define ESP_INTR_FLAG_LEVEL2 (1<<2) /* Accept a Level 2 int vector */ 21 #define ESP_INTR_FLAG_LEVEL3 (1<<3) /* Accept a Level 3 int vector */ 22 #define ESP_INTR_FLAG_LEVEL4 (1<<4) /* Accept a Level 4 int vector */ 23 #define ESP_INTR_FLAG_LEVEL5 (1<<5) /* Accept a Level 5 int vector */ 24 #define ESP_INTR_FLAG_LEVEL6 (1<<6) /* Accept a Level 6 int vector */ 25 #define ESP_INTR_FLAG_NMI (1<<7) /* Accept a Level 7 int vector, highest priority */ 26 #define ESP_INTR_FLAG_SHARED (1<<8) /* Interrupt can be shared between ISRs */ 27 #define ESP_INTR_FLAG_EDGE (1<<9) /* Edge-triggered interrupt */ 28 #define ESP_INTR_FLAG_IRAM (1<<10) /* ISR can be called if cache is disabled */ 29 #define ESP_INTR_FLAG_INTRDISABLED (1<<11) /* Return with this interrupt disabled */ 30 31 /* Low and medium prio interrupts. These can be handled in C. */ 32 #define ESP_INTR_FLAG_LOWMED (ESP_INTR_FLAG_LEVEL1|ESP_INTR_FLAG_LEVEL2|ESP_INTR_FLAG_LEVEL3) 33 34 /* High level interrupts. Need to be handled in assembly. */ 35 #define ESP_INTR_FLAG_HIGH (ESP_INTR_FLAG_LEVEL4|ESP_INTR_FLAG_LEVEL5|ESP_INTR_FLAG_LEVEL6| \ 36 ESP_INTR_FLAG_NMI) 37 38 /* Mask for all level flags */ 39 #define ESP_INTR_FLAG_LEVELMASK (ESP_INTR_FLAG_LEVEL1|ESP_INTR_FLAG_LEVEL2|ESP_INTR_FLAG_LEVEL3| \ 40 ESP_INTR_FLAG_LEVEL4|ESP_INTR_FLAG_LEVEL5|ESP_INTR_FLAG_LEVEL6| \ 41 ESP_INTR_FLAG_NMI) 42 43 /* Function prototype for interrupt handler function */ 44 typedef void (*isr_handler_t)(const void *arg); 45 46 /** 47 * @brief Initializes interrupt table to its defaults 48 */ 49 void esp_intr_initialize(void); 50 51 /** 52 * @brief Allocate an interrupt with the given parameters. 53 * 54 * This finds an interrupt that matches the restrictions as given in the flags 55 * parameter, maps the given interrupt source to it and hooks up the given 56 * interrupt handler (with optional argument) as well. If needed, it can return 57 * a handle for the interrupt as well. 58 * 59 * @param source The interrupt source. 60 * @param flags An ORred mask of the ESP_INTR_FLAG_* defines. These restrict the 61 * choice of interrupts that this routine can choose from. If this value 62 * is 0, it will default to allocating a non-shared interrupt of level 63 * 1, 2 or 3. If this is ESP_INTR_FLAG_SHARED, it will allocate a shared 64 * interrupt of level 1. Setting ESP_INTR_FLAG_INTRDISABLED will return 65 * from this function with the interrupt disabled. 66 * @param handler The interrupt handler. 67 * @param arg Optional argument for passed to the interrupt handler 68 * @param ret_handle Pointer to a struct intr_handle_data_t pointer to store a handle that can 69 * later be used to request details or free the interrupt. Can be NULL if no handle 70 * is required. 71 * 72 * @return -EINVAL if the combination of arguments is invalid. 73 * -ENODEV No free interrupt found with the specified flags 74 * 0 otherwise 75 */ 76 int esp_intr_alloc(int source, 77 int flags, 78 isr_handler_t handler, 79 void *arg, 80 void **ret_handle); 81 82 /** 83 * @brief Disable the interrupt associated with the source 84 * 85 * @param source The interrupt source 86 * 87 * @return -EINVAL if the combination of arguments is invalid. 88 * 0 otherwise 89 */ 90 int esp_intr_disable(int source); 91 92 /** 93 * @brief Enable the interrupt associated with the source 94 * 95 * @param source The interrupt source 96 * @return -EINVAL if the combination of arguments is invalid. 97 * 0 otherwise 98 */ 99 int esp_intr_enable(int source); 100 101 /** 102 * @brief Gets the current enabled interrupts 103 * 104 * @param status_mask_number the status mask can be 0 or 1 105 * @return bitmask of enabled interrupt sources 106 */ 107 uint32_t esp_intr_get_enabled_intmask(int status_mask_number); 108 109 #endif 110