1 /*
2  * SPDX-FileCopyrightText: 2016-2021 Espressif Systems (Shanghai) CO LTD
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #pragma once
8 
9 #include <stdint.h>
10 #include "esp_err.h"
11 #include "esp_intr_alloc.h"
12 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16 
17 #define RTC_INTR_FLAG_IRAM   (BIT(0))  /*< Some rtc interrupts can be called with cache disabled */
18 
19 /**
20  * @brief Register a handler for specific RTC_CNTL interrupts
21  *
22  * Multiple handlers can be registered using this function. Whenever an
23  * RTC interrupt happens, all handlers with matching rtc_intr_mask values
24  * will be called.
25  *
26  * @param handler  handler function to call
27  * @param handler_arg  argument to be passed to the handler
28  * @param rtc_intr_mask  combination of RTC_CNTL_*_INT_ENA bits indicating the
29  *                       sources to call the handler for
30  * @param flags  An ORred mask of the RTC_INTR_FLAG_* defines. You can pass different
31  *               flags to it to realize different purpose. If 0, the interrupt will
32  *               not handle anything special. If you pass `RTC_INTR_FLAG_IRAM`, means
33  *               the interrupt can be triggered with cache disabled.
34  * @return
35  *      - ESP_OK on success
36  *      - ESP_ERR_NO_MEM not enough memory to allocate handler structure
37  *      - other errors returned by esp_intr_alloc
38  */
39 esp_err_t rtc_isr_register(intr_handler_t handler, void* handler_arg,
40                             uint32_t rtc_intr_mask, uint32_t flags);
41 /**
42  * @brief Deregister the handler previously registered using rtc_isr_register
43  * @param handler  handler function to call (as passed to rtc_isr_register)
44  * @param handler_arg  argument of the handler (as passed to rtc_isr_register)
45  * @return
46  *      - ESP_OK on success
47  *      - ESP_ERR_INVALID_STATE if a handler matching both handler and
48  *        handler_arg isn't registered
49  */
50 esp_err_t rtc_isr_deregister(intr_handler_t handler, void* handler_arg);
51 
52 /**
53  * @brief Disable the RTC interrupt that is allowed to be executed when cache is disabled.
54  * cache disabled. Internal interrupt handle function will call this function in interrupt
55  * handler function. Disable bits when `esp_intr_noniram_disable` is called.
56  *
57  * @param cpu CPU number.
58  */
59 void rtc_isr_noniram_disable(uint32_t cpu);
60 
61 /**
62  * @brief Enable the RTC interrupt that is allowed to be executed when cache is disabled.
63  * cache disabled. Internal interrupt handle function will call this function in interrupt
64  * handler function. Enable bits when `esp_intr_noniram_enable` is called.
65  *
66  * @param cpu CPU number.
67  */
68 void rtc_isr_noniram_enable(uint32_t cpu);
69 
70 #ifdef __cplusplus
71 }
72 #endif
73