brownout_hal.c 1.2 KB

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