brownout_hal.c 1.4 KB

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