1 /*
2  * SPDX-FileCopyrightText: 2010-2022 Espressif Systems (Shanghai) CO LTD
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #pragma once
8 #include "sdkconfig.h"
9 #include <stdint.h>
10 #include "soc/reset_reasons.h"
11 
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15 
16 /**
17   * @brief Software Reset digital core include RTC.
18   *
19   * It is not recommended to use this function in esp-idf, use
20   * esp_restart() instead.
21   */
22 void esp_rom_software_reset_system(void);
23 
24 /**
25   * @brief Software Reset cpu core.
26   *
27   * It is not recommended to use this function in esp-idf, use
28   * esp_restart() instead.
29   *
30   * @param  cpu_no : The CPU to reset, 0 for PRO CPU, 1 for APP CPU.
31   */
32 void esp_rom_software_reset_cpu(int cpu_no);
33 
34 /**
35  * @brief Print formated string to console device
36  * @note float and long long data are not supported!
37  *
38  * @param fmt Format string
39  * @param ... Additional arguments, depending on the format string
40  * @return int: Total number of characters written on success; A negative number on failure.
41  */
42 int esp_rom_printf(const char *fmt, ...);
43 
44 /**
45  * @brief Pauses execution for us microseconds
46  *
47  * @param us Number of microseconds to pause
48  */
49 void esp_rom_delay_us(uint32_t us);
50 
51 /**
52  * @brief esp_rom_printf can print message to different channels simultaneously.
53  *        This function can help install the low level putc function for esp_rom_printf.
54  *
55  * @param channel Channel number (startting from 1)
56  * @param putc Function pointer to the putc implementation. Set NULL can disconnect esp_rom_printf with putc.
57  */
58 void esp_rom_install_channel_putc(int channel, void (*putc)(char c));
59 
60 /**
61  * @brief Install UART1 as the default console channel, equivalent to `esp_rom_install_channel_putc(1, esp_rom_uart_putc)`
62  */
63 void esp_rom_install_uart_printf(void);
64 
65 /**
66  * @brief Get reset reason of CPU
67  *
68  * @param cpu_no CPU number
69  * @return Reset reason code (see in soc/reset_reasons.h)
70  */
71 soc_reset_reason_t esp_rom_get_reset_reason(int cpu_no);
72 
73 /**
74  * @brief Route peripheral interrupt sources to CPU's interrupt port by matrix
75  *
76  * Usually there're 4 steps to use an interrupt:
77  * 1. Route peripheral interrupt source to CPU. e.g.  esp_rom_route_intr_matrix(0, ETS_WIFI_MAC_INTR_SOURCE, ETS_WMAC_INUM)
78  * 2. Set interrupt handler for CPU
79  * 3. Enable CPU interupt
80  * 4. Enable peripheral interrupt
81  *
82  * @param cpu_core The CPU number, which the peripheral interupt will inform to
83  * @param periph_intr_id The peripheral interrupt source number
84  * @param cpu_intr_num The CPU interrupt number
85  */
86 void esp_rom_route_intr_matrix(int cpu_core, uint32_t periph_intr_id, uint32_t cpu_intr_num);
87 
88 /**
89  * @brief Get the real CPU ticks per us
90  *
91  * @return CPU ticks per us
92  */
93 uint32_t esp_rom_get_cpu_ticks_per_us(void);
94 
95 /**
96  * @brief Set the real CPU tick rate
97  *
98  * @note Call this function when CPU frequency is changed, otherwise the `esp_rom_delay_us` can be inaccurate.
99  *
100  * @param ticks_per_us CPU ticks per us
101  */
102 void esp_rom_set_cpu_ticks_per_us(uint32_t ticks_per_us);
103 
104 #ifdef __cplusplus
105 }
106 #endif
107