sleep_console.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include <stdbool.h>
  7. #include "soc/soc_caps.h"
  8. #include "esp_private/sleep_console.h"
  9. #include "esp_attr.h"
  10. #if SOC_USB_SERIAL_JTAG_SUPPORTED
  11. #include "hal/usb_serial_jtag_ll.h"
  12. static sleep_console_usj_enable_state_t s_usj_state = {0};
  13. void sleep_console_usj_pad_backup_and_disable(void)
  14. {
  15. // This function can be called in sleep process only, and sleep process code
  16. // is in critical region and thread safe already, so to avoid build errors/warnings
  17. // declare __DECLARE_RCC_ATOMIC_ENV here.
  18. int __DECLARE_RCC_ATOMIC_ENV __attribute__ ((unused));
  19. s_usj_state.usj_clock_enabled = usb_serial_jtag_ll_module_is_enabled();
  20. if (!s_usj_state.usj_clock_enabled) {
  21. // Enable USJ clock and clear reset
  22. usb_serial_jtag_ll_enable_bus_clock(true);
  23. usb_serial_jtag_ll_reset_register();
  24. }
  25. s_usj_state.usj_pad_enabled = usb_serial_jtag_ll_pad_backup_and_disable();
  26. // Disable USJ clock
  27. usb_serial_jtag_ll_enable_bus_clock(false);
  28. }
  29. void sleep_console_usj_pad_restore(void)
  30. {
  31. // This function can be called in sleep process only, and sleep process code
  32. // is in critical region and thread safe already, so to avoid build errors/warnings
  33. // declare __DECLARE_RCC_ATOMIC_ENV here.
  34. int __DECLARE_RCC_ATOMIC_ENV __attribute__ ((unused));
  35. usb_serial_jtag_ll_enable_bus_clock(true);
  36. usb_serial_jtag_ll_enable_pad(s_usj_state.usj_pad_enabled);
  37. if (!s_usj_state.usj_clock_enabled) {
  38. usb_serial_jtag_ll_enable_bus_clock(false);
  39. }
  40. }
  41. #endif