1
2 // Copyright 2020 Espressif Systems (Shanghai) PTE LTD
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15
16 #include "hal/brownout_hal.h"
17 #include "soc/rtc_cntl_struct.h"
18
brownout_hal_config(const brownout_hal_config_t * cfg)19 void brownout_hal_config(const brownout_hal_config_t *cfg)
20 {
21 typeof(RTCCNTL.brown_out) brown_out_reg = {
22 .close_flash_ena = cfg->flash_power_down,
23 .pd_rf_ena = cfg->rf_power_down,
24 .rst_wait = 0x3ff,
25 .rst_ena = cfg->reset_enabled,
26 .thres = cfg->threshold,
27 .ena = cfg->enabled,
28 };
29
30 RTCCNTL.brown_out = brown_out_reg;
31 }
32
brownout_hal_intr_enable(bool enable)33 void brownout_hal_intr_enable(bool enable)
34 {
35 RTCCNTL.int_ena.rtc_brown_out = enable;
36 }
37
brownout_hal_intr_clear(void)38 void brownout_hal_intr_clear(void)
39 {
40 RTCCNTL.int_clr.rtc_brown_out = 1;
41 }
42