ulp_common.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #ifndef __ULP_COMMON_H__
  7. #define __ULP_COMMON_H__
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. #include <stdint.h>
  12. #include "esp_err.h"
  13. #include "ulp_common_defs.h"
  14. /**
  15. * @brief Set one of ULP wakeup period values
  16. *
  17. * ULP coprocessor starts running the program when the wakeup timer counts up
  18. * to a given value (called period). There are 5 period values which can be
  19. * programmed into SENS_ULP_CP_SLEEP_CYCx_REG registers, x = 0..4 for ESP32, and
  20. * one period value which can be programmed into RTC_CNTL_ULP_CP_TIMER_1_REG register for ESP32-S2/S3.
  21. * By default, for ESP32, wakeup timer will use the period set into SENS_ULP_CP_SLEEP_CYC0_REG,
  22. * i.e. period number 0. ULP program code can use SLEEP instruction to select
  23. * which of the SENS_ULP_CP_SLEEP_CYCx_REG should be used for subsequent wakeups.
  24. *
  25. * However, please note that SLEEP instruction issued (from ULP program) while the system
  26. * is in deep sleep mode does not have effect, and sleep cycle count 0 is used.
  27. *
  28. * For ESP32-S2/S3 the SLEEP instruction not exist. Instead a WAKE instruction will be used.
  29. *
  30. * @param period_index wakeup period setting number (0 - 4)
  31. * @param period_us wakeup period, us
  32. * @note The ULP FSM requires two clock cycles to wakeup before being able to run the program.
  33. * Then additional 16 cycles are reserved after wakeup waiting until the 8M clock is stable.
  34. * The FSM also requires two more clock cycles to go to sleep after the program execution is halted.
  35. * The minimum wakeup period that may be set up for the ULP
  36. * is equal to the total number of cycles spent on the above internal tasks.
  37. * For a default configuration of the ULP running at 150kHz it makes about 133us.
  38. * @return
  39. * - ESP_OK on success
  40. * - ESP_ERR_INVALID_ARG if period_index is out of range
  41. */
  42. esp_err_t ulp_set_wakeup_period(size_t period_index, uint32_t period_us);
  43. #ifdef __cplusplus
  44. }
  45. #endif
  46. #endif // __ULP_COMMON_H__