brownout_hal.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. .out2_ena = 1,
  24. .int_wait = 0x002,
  25. .close_flash_ena = cfg->flash_power_down,
  26. .pd_rf_ena = cfg->rf_power_down,
  27. .rst_wait = 0x3ff,
  28. .rst_ena = cfg->reset_enabled,
  29. .ena = cfg->enabled,
  30. .rst_sel = 1,
  31. };
  32. RTCCNTL.brown_out = brown_out_reg;
  33. }
  34. void brownout_hal_intr_enable(bool enable)
  35. {
  36. RTCCNTL.int_ena.rtc_brown_out = enable;
  37. }
  38. void brownout_hal_intr_clear(void)
  39. {
  40. RTCCNTL.int_clr.rtc_brown_out = 1;
  41. }