mirror of
https://github.com/espressif/esp-idf.git
synced 2025-09-30 19:19:21 +00:00
esp32s2: add brownout detector support
1. add brownout detector HAL for esp32 and esp32s2 2. enable brownout reset for esp32 rev. 1 and above 3. add approximate brownout detector levels for esp32s2
This commit is contained in:
46
components/soc/esp32s2/brownout_hal.c
Normal file
46
components/soc/esp32s2/brownout_hal.c
Normal file
@@ -0,0 +1,46 @@
|
||||
|
||||
// Copyright 2020 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 "hal/brownout_hal.h"
|
||||
#include "soc/rtc_cntl_struct.h"
|
||||
#include "soc/rtc_cntl_reg.h"
|
||||
#include "i2c_rtc_clk.h"
|
||||
#include "i2c_brownout.h"
|
||||
|
||||
|
||||
void brownout_hal_config(const brownout_hal_config_t *cfg)
|
||||
{
|
||||
I2C_WRITEREG_MASK_RTC(I2C_BOD, I2C_BOD_THRESHOLD, cfg->threshold);
|
||||
typeof(RTCCNTL.brown_out) brown_out_reg = {
|
||||
.out2_ena = 1,
|
||||
.int_wait = 0x002,
|
||||
.close_flash_ena = cfg->flash_power_down,
|
||||
.pd_rf_ena = cfg->rf_power_down,
|
||||
.rst_wait = 0x3ff,
|
||||
.rst_ena = cfg->reset_enabled,
|
||||
.ena = cfg->enabled,
|
||||
};
|
||||
RTCCNTL.brown_out = brown_out_reg;
|
||||
}
|
||||
|
||||
void brownout_hal_intr_enable(bool enable)
|
||||
{
|
||||
RTCCNTL.int_ena.rtc_brown_out = enable;
|
||||
}
|
||||
|
||||
void brownout_hal_intr_clear(void)
|
||||
{
|
||||
RTCCNTL.int_clr.rtc_brown_out = 1;
|
||||
}
|
30
components/soc/esp32s2/i2c_brownout.h
Normal file
30
components/soc/esp32s2/i2c_brownout.h
Normal file
@@ -0,0 +1,30 @@
|
||||
// Copyright 2020 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.
|
||||
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* @file i2c_brownout.h
|
||||
* @brief Register definitions for brownout detector
|
||||
*
|
||||
* This file lists register fields of the brownout detector, located on an internal configuration
|
||||
* bus. These definitions are used via macros defined in i2c_rtc_clk.h.
|
||||
*/
|
||||
|
||||
#define I2C_BOD 0x61
|
||||
#define I2C_BOD_HOSTID 1
|
||||
|
||||
#define I2C_BOD_THRESHOLD 0x5
|
||||
#define I2C_BOD_THRESHOLD_MSB 2
|
||||
#define I2C_BOD_THRESHOLD_LSB 0
|
25
components/soc/esp32s2/include/soc/brownout_caps.h
Normal file
25
components/soc/esp32s2/include/soc/brownout_caps.h
Normal file
@@ -0,0 +1,25 @@
|
||||
// Copyright 2020 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.
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define SOC_BROWNOUT_RESET_SUPPORTED 1
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@@ -1,4 +1,5 @@
|
||||
set(SOC_SRCS "adc_periph.c"
|
||||
"brownout_hal.c"
|
||||
"dac_periph.c"
|
||||
"cpu_util.c"
|
||||
"gpio_periph.c"
|
||||
|
Reference in New Issue
Block a user