brownout_hal.c 965 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * SPDX-FileCopyrightText: 2020-2022 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include "hal/brownout_hal.h"
  7. #include "soc/rtc_cntl_struct.h"
  8. #include "soc/rtc_cntl_reg.h"
  9. #include "esp_attr.h"
  10. #include "hal/regi2c_ctrl.h"
  11. #include "soc/regi2c_brownout.h"
  12. void brownout_hal_config(const brownout_hal_config_t *cfg)
  13. {
  14. REGI2C_WRITE_MASK(I2C_BOD, I2C_BOD_THRESHOLD, cfg->threshold);
  15. typeof(RTCCNTL.brown_out) brown_out_reg = {
  16. .out2_ena = 1,
  17. .int_wait = 0x002,
  18. .close_flash_ena = cfg->flash_power_down,
  19. .pd_rf_ena = cfg->rf_power_down,
  20. .rst_wait = 0x3ff,
  21. .rst_ena = cfg->reset_enabled,
  22. .ena = cfg->enabled,
  23. .rst_sel = 1,
  24. };
  25. RTCCNTL.brown_out = brown_out_reg;
  26. }
  27. void brownout_hal_intr_enable(bool enable)
  28. {
  29. RTCCNTL.int_ena.rtc_brown_out = enable;
  30. }
  31. IRAM_ATTR void brownout_hal_intr_clear(void)
  32. {
  33. RTCCNTL.int_clr.rtc_brown_out = 1;
  34. }