brownout_hal.c 915 B

12345678910111213141516171819202122232425262728293031323334353637
  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. .close_flash_ena = cfg->flash_power_down,
  17. .pd_rf_ena = cfg->rf_power_down,
  18. .rst_wait = 0x3ff,
  19. .rst_ena = cfg->reset_enabled,
  20. .ena = cfg->enabled,
  21. .rst_sel = 1,
  22. };
  23. RTCCNTL.brown_out = brown_out_reg;
  24. }
  25. void brownout_hal_intr_enable(bool enable)
  26. {
  27. RTCCNTL.int_ena.rtc_brown_out = enable;
  28. }
  29. IRAM_ATTR void brownout_hal_intr_clear(void)
  30. {
  31. RTCCNTL.int_clr.rtc_brown_out = 1;
  32. }