|
16 | 16 | #include <toolchain/gcc.h> |
17 | 17 | #include <zephyr/types.h> |
18 | 18 |
|
| 19 | +#include "esp_private/system_internal.h" |
| 20 | +#include "esp32/rom/cache.h" |
| 21 | +#include "hal/soc_ll.h" |
| 22 | +#include "soc/cpu.h" |
| 23 | +#include "soc/gpio_periph.h" |
| 24 | + |
19 | 25 | extern void z_cstart(void); |
20 | 26 |
|
21 | 27 | /* |
@@ -104,3 +110,76 @@ int arch_printk_char_out(int c) |
104 | 110 | esp32_rom_uart_tx_one_char(c); |
105 | 111 | return 0; |
106 | 112 | } |
| 113 | + |
| 114 | +void sys_arch_reboot(int type) |
| 115 | +{ |
| 116 | + esp_restart_noos(); |
| 117 | +} |
| 118 | + |
| 119 | +void IRAM_ATTR esp_restart_noos(void) |
| 120 | +{ |
| 121 | + /* Disable interrupts */ |
| 122 | + z_xt_ints_off(0xFFFFFFFF); |
| 123 | + |
| 124 | + const uint32_t core_id = cpu_hal_get_core_id(); |
| 125 | + const uint32_t other_core_id = (core_id == 0) ? 1 : 0; |
| 126 | + |
| 127 | + soc_ll_reset_core(other_core_id); |
| 128 | + soc_ll_stall_core(other_core_id); |
| 129 | + |
| 130 | + /* Flush any data left in UART FIFOs */ |
| 131 | + esp32_rom_uart_tx_wait_idle(0); |
| 132 | + esp32_rom_uart_tx_wait_idle(1); |
| 133 | + esp32_rom_uart_tx_wait_idle(2); |
| 134 | + |
| 135 | + /* Disable cache */ |
| 136 | + Cache_Read_Disable(0); |
| 137 | + Cache_Read_Disable(1); |
| 138 | + |
| 139 | + /* 2nd stage bootloader reconfigures SPI flash signals. */ |
| 140 | + /* Reset them to the defaults expected by ROM */ |
| 141 | + WRITE_PERI_REG(GPIO_FUNC0_IN_SEL_CFG_REG, 0x30); |
| 142 | + WRITE_PERI_REG(GPIO_FUNC1_IN_SEL_CFG_REG, 0x30); |
| 143 | + WRITE_PERI_REG(GPIO_FUNC2_IN_SEL_CFG_REG, 0x30); |
| 144 | + WRITE_PERI_REG(GPIO_FUNC3_IN_SEL_CFG_REG, 0x30); |
| 145 | + WRITE_PERI_REG(GPIO_FUNC4_IN_SEL_CFG_REG, 0x30); |
| 146 | + WRITE_PERI_REG(GPIO_FUNC5_IN_SEL_CFG_REG, 0x30); |
| 147 | + |
| 148 | + /* Reset wifi/bluetooth/ethernet/sdio (bb/mac) */ |
| 149 | + DPORT_SET_PERI_REG_MASK(DPORT_CORE_RST_EN_REG, |
| 150 | + DPORT_BB_RST | DPORT_FE_RST | DPORT_MAC_RST | |
| 151 | + DPORT_BT_RST | DPORT_BTMAC_RST | |
| 152 | + DPORT_SDIO_RST | DPORT_SDIO_HOST_RST | |
| 153 | + DPORT_EMAC_RST | DPORT_MACPWR_RST | |
| 154 | + DPORT_RW_BTMAC_RST | DPORT_RW_BTLP_RST); |
| 155 | + DPORT_REG_WRITE(DPORT_CORE_RST_EN_REG, 0); |
| 156 | + |
| 157 | + /* Reset timer/spi/uart */ |
| 158 | + DPORT_SET_PERI_REG_MASK( |
| 159 | + DPORT_PERIP_RST_EN_REG, |
| 160 | + /* UART TX FIFO cannot be reset correctly on ESP32, */ |
| 161 | + /* so reset the UART memory by DPORT here. */ |
| 162 | + DPORT_TIMERS_RST | DPORT_SPI01_RST | DPORT_UART_RST | |
| 163 | + DPORT_UART1_RST | DPORT_UART2_RST | DPORT_UART_MEM_RST); |
| 164 | + DPORT_REG_WRITE(DPORT_PERIP_RST_EN_REG, 0); |
| 165 | + |
| 166 | + /* Clear entry point for APP CPU */ |
| 167 | + DPORT_REG_WRITE(DPORT_APPCPU_CTRL_D_REG, 0); |
| 168 | + |
| 169 | + /* Reset CPUs */ |
| 170 | + if (core_id == 0) { |
| 171 | + /* Running on PRO CPU: APP CPU is stalled. Can reset both CPUs. */ |
| 172 | + soc_ll_reset_core(1); |
| 173 | + soc_ll_reset_core(0); |
| 174 | + } else { |
| 175 | + /* Running on APP CPU: need to reset PRO CPU and unstall it, */ |
| 176 | + /* then reset APP CPU */ |
| 177 | + soc_ll_reset_core(0); |
| 178 | + soc_ll_stall_core(0); |
| 179 | + soc_ll_reset_core(1); |
| 180 | + } |
| 181 | + |
| 182 | + while (true) { |
| 183 | + ; |
| 184 | + } |
| 185 | +} |
0 commit comments