brownout_hal.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 "regi2c_brownout.h"
  19. void brownout_hal_config(const brownout_hal_config_t *cfg)
  20. {
  21. REGI2C_WRITE_MASK(I2C_BOD, I2C_BOD_THRESHOLD, cfg->threshold);
  22. typeof(RTCCNTL.brown_out) brown_out_reg = {
  23. .close_flash_ena = cfg->flash_power_down,
  24. .pd_rf_ena = cfg->rf_power_down,
  25. .rst_wait = 0x3ff,
  26. .rst_ena = cfg->reset_enabled,
  27. .ena = cfg->enabled,
  28. .rst_sel = 1,
  29. };
  30. RTCCNTL.brown_out = brown_out_reg;
  31. }
  32. void brownout_hal_intr_enable(bool enable)
  33. {
  34. RTCCNTL.int_ena.rtc_brown_out = enable;
  35. }
  36. void brownout_hal_intr_clear(void)
  37. {
  38. RTCCNTL.int_clr.rtc_brown_out = 1;
  39. }