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 #include "soc/rtc_cntl_reg.h"
19 #include "regi2c_ctrl.h"
20 #include "regi2c_brownout.h"
21
22 #if defined(__ZEPHYR__)
23 #include "stubs.h"
24 #endif
25
brownout_hal_config(const brownout_hal_config_t * cfg)26 void brownout_hal_config(const brownout_hal_config_t *cfg)
27 {
28 REGI2C_WRITE_MASK(I2C_BOD, I2C_BOD_THRESHOLD, cfg->threshold);
29 typeof(RTCCNTL.brown_out) brown_out_reg = {
30 .out2_ena = 1,
31 .int_wait = 0x002,
32 .close_flash_ena = cfg->flash_power_down,
33 .pd_rf_ena = cfg->rf_power_down,
34 .rst_wait = 0x3ff,
35 .rst_ena = cfg->reset_enabled,
36 .ena = cfg->enabled,
37 .rst_sel = 1,
38 };
39 RTCCNTL.brown_out = brown_out_reg;
40 }
41
brownout_hal_intr_enable(bool enable)42 void brownout_hal_intr_enable(bool enable)
43 {
44 RTCCNTL.int_ena.rtc_brown_out = enable;
45 }
46
brownout_hal_intr_clear(void)47 void brownout_hal_intr_clear(void)
48 {
49 RTCCNTL.int_clr.rtc_brown_out = 1;
50 }
51