mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
esp32, esp32s2beta: move brownout.c to esp_common
This commit is contained in:
parent
70752baba4
commit
caef7ad9f2
@ -12,7 +12,6 @@ if(BOOTLOADER_BUILD)
|
||||
else()
|
||||
# Regular app build
|
||||
set(srcs
|
||||
"brownout.c"
|
||||
"cache_err_int.c"
|
||||
"cache_sram_mmu.c"
|
||||
"clk.c"
|
||||
|
@ -1,66 +0,0 @@
|
||||
// Copyright 2015-2017 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.
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include "sdkconfig.h"
|
||||
#include "soc/soc.h"
|
||||
#include "soc/cpu.h"
|
||||
#include "soc/rtc_periph.h"
|
||||
#include "hal/brownout_hal.h"
|
||||
#include "esp32/rom/ets_sys.h"
|
||||
#include "esp_private/system_internal.h"
|
||||
#include "driver/rtc_cntl.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
|
||||
#ifdef CONFIG_ESP32_BROWNOUT_DET_LVL
|
||||
#define BROWNOUT_DET_LVL CONFIG_ESP32_BROWNOUT_DET_LVL
|
||||
#else
|
||||
#define BROWNOUT_DET_LVL 0
|
||||
#endif //CONFIG_ESP32_BROWNOUT_DET_LVL
|
||||
|
||||
static void rtc_brownout_isr_handler(void *arg)
|
||||
{
|
||||
/* Normally RTC ISR clears the interrupt flag after the application-supplied
|
||||
* handler returns. Since restart is called here, the flag needs to be
|
||||
* cleared manually.
|
||||
*/
|
||||
REG_WRITE(RTC_CNTL_INT_CLR_REG, RTC_CNTL_BROWN_OUT_INT_CLR);
|
||||
/* Stall the other CPU to make sure the code running there doesn't use UART
|
||||
* at the same time as the following ets_printf.
|
||||
*/
|
||||
esp_cpu_stall(!xPortGetCoreID());
|
||||
esp_reset_reason_set_hint(ESP_RST_BROWNOUT);
|
||||
ets_printf("\r\nBrownout detector was triggered\r\n\r\n");
|
||||
esp_restart_noos();
|
||||
}
|
||||
|
||||
void esp_brownout_init(void)
|
||||
{
|
||||
brownout_hal_config_t cfg = {
|
||||
.threshold = BROWNOUT_DET_LVL,
|
||||
.enabled = true,
|
||||
.reset_enabled = false,
|
||||
.flash_power_down = true,
|
||||
.rf_power_down = true,
|
||||
};
|
||||
|
||||
brownout_hal_config(&cfg);
|
||||
|
||||
ESP_ERROR_CHECK( rtc_isr_register(rtc_brownout_isr_handler, NULL, RTC_CNTL_BROWN_OUT_INT_ENA_M) );
|
||||
|
||||
brownout_hal_intr_enable(true);
|
||||
}
|
@ -11,8 +11,7 @@ if(BOOTLOADER_BUILD)
|
||||
else()
|
||||
# Regular app build
|
||||
|
||||
set(srcs "brownout.c"
|
||||
"cache_err_int.c"
|
||||
set(srcs "cache_err_int.c"
|
||||
"clk.c"
|
||||
"cpu_start.c"
|
||||
"crosscore_int.c"
|
||||
|
@ -6,7 +6,8 @@ if(BOOTLOADER_BUILD)
|
||||
set_property(TARGET ${COMPONENT_LIB} APPEND PROPERTY INTERFACE_LINK_LIBRARIES "-Wl,--gc-sections")
|
||||
else()
|
||||
# Regular app build
|
||||
set(srcs "src/dbg_stubs.c"
|
||||
set(srcs "src/brownout.c"
|
||||
"src/dbg_stubs.c"
|
||||
"src/esp_err_to_name.c"
|
||||
"src/esp_timer.c"
|
||||
"src/ets_timer_legacy.c"
|
||||
|
@ -26,11 +26,20 @@
|
||||
#include "driver/rtc_cntl.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
|
||||
#ifdef CONFIG_ESP32S2_BROWNOUT_DET_LVL
|
||||
#if defined(CONFIG_ESP32_BROWNOUT_DET_LVL)
|
||||
#define BROWNOUT_DET_LVL CONFIG_ESP32_BROWNOUT_DET_LVL
|
||||
#elif defined(CONFIG_ESP32S2_BROWNOUT_DET_LVL)
|
||||
#define BROWNOUT_DET_LVL CONFIG_ESP32S2_BROWNOUT_DET_LVL
|
||||
#else
|
||||
#define BROWNOUT_DET_LVL 0
|
||||
#endif //CONFIG_ESP32S2_BROWNOUT_DET_LVL
|
||||
#endif
|
||||
|
||||
#ifdef SOC_BROWNOUT_RESET_SUPPORTED
|
||||
#define BROWNOUT_RESET_EN true
|
||||
#else
|
||||
#define BROWNOUT_RESET_EN false
|
||||
#endif // SOC_BROWNOUT_RESET_SUPPORTED
|
||||
|
||||
|
||||
static void rtc_brownout_isr_handler(void *arg)
|
||||
{
|
||||
@ -38,7 +47,7 @@ static void rtc_brownout_isr_handler(void *arg)
|
||||
* handler returns. Since restart is called here, the flag needs to be
|
||||
* cleared manually.
|
||||
*/
|
||||
REG_WRITE(RTC_CNTL_INT_CLR_REG, RTC_CNTL_BROWN_OUT_INT_CLR);
|
||||
brownout_hal_intr_clear();
|
||||
/* Stall the other CPU to make sure the code running there doesn't use UART
|
||||
* at the same time as the following ets_printf.
|
||||
*/
|
||||
@ -53,7 +62,7 @@ void esp_brownout_init(void)
|
||||
brownout_hal_config_t cfg = {
|
||||
.threshold = BROWNOUT_DET_LVL,
|
||||
.enabled = true,
|
||||
.reset_enabled = false,
|
||||
.reset_enabled = BROWNOUT_RESET_EN,
|
||||
.flash_power_down = true,
|
||||
.rf_power_down = true,
|
||||
};
|
@ -27,6 +27,7 @@ extern "C" {
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "soc/brownout_caps.h"
|
||||
|
||||
typedef struct {
|
||||
uint8_t threshold;
|
||||
|
Loading…
x
Reference in New Issue
Block a user