sleep_retention.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #pragma once
  7. #include <stdint.h>
  8. #include "sdkconfig.h"
  9. #include "soc/soc_caps.h"
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif
  13. #if SOC_PAU_SUPPORTED
  14. #include "esp_regdma.h"
  15. /**
  16. * @file sleep_retention.h
  17. *
  18. * This file contains declarations of sleep retention related functions, it
  19. * includes sleep retention list creation, destruction and debugging interfaces.
  20. */
  21. typedef enum sleep_retention_module_bitmap {
  22. /* clock module, which includes system and modem */
  23. SLEEP_RETENTION_MODULE_CLOCK_SYSTEM = BIT(1),
  24. SLEEP_RETENTION_MODULE_CLOCK_MODEM = BIT(2),
  25. /* modem module, which includes WiFi, BLE and 802.15.4 */
  26. SLEEP_RETENTION_MODULE_WIFI_MAC = BIT(10),
  27. SLEEP_RETENTION_MODULE_WIFI_BB = BIT(11),
  28. SLEEP_RETENTION_MODULE_BLE_MAC = BIT(12),
  29. SLEEP_RETENTION_MODULE_BT_BB = BIT(13),
  30. SLEEP_RETENTION_MODULE_802154_MAC = BIT(14),
  31. /* digital peripheral module, which includes Interrupt Matrix, HP_SYSTEM,
  32. * TEE, APM, UART, Timer Group, IOMUX, SPIMEM, SysTimer, etc.. */
  33. SLEEP_RETENTION_MODULE_INTR_MATRIX = BIT(16),
  34. SLEEP_RETENTION_MODULE_HP_SYSTEM = BIT(17),
  35. SLEEP_RETENTION_MODULE_TEE_APM = BIT(18),
  36. SLEEP_RETENTION_MODULE_UART0 = BIT(19),
  37. SLEEP_RETENTION_MODULE_TG0 = BIT(20),
  38. SLEEP_RETENTION_MODULE_IOMUX = BIT(21),
  39. SLEEP_RETENTION_MODULE_SPIMEM = BIT(22),
  40. SLEEP_RETENTION_MODULE_SYSTIMER = BIT(23),
  41. SLEEP_RETENTION_MODULE_ALL = (uint32_t)-1
  42. } sleep_retention_module_bitmap_t;
  43. typedef regdma_entry_buf_t sleep_retention_entries_t;
  44. typedef struct {
  45. regdma_link_config_t config;
  46. uint32_t owner; /**< Indicates which regdma entries the current node will insert into */
  47. } sleep_retention_entries_config_t;
  48. /**
  49. * @brief Create a runtime sleep retention linked list
  50. *
  51. * @param retent sleep retention linked list node configuration table
  52. * @param num the total number of sleep retention linked list configuration
  53. * items
  54. * @param priority the priority of the created sleep retention linked list
  55. * @param module the bitmap of the module to which the created sleep retention
  56. * linked list belongs
  57. * @return
  58. * - ESP_OK on success
  59. * - ESP_ERR_NO_MEM not enough memory for sleep retention
  60. * - ESP_ERR_INVALID_ARG if either of the arguments is out of range
  61. */
  62. esp_err_t sleep_retention_entries_create(const sleep_retention_entries_config_t retent[], int num, regdma_link_priority_t priority, int module);
  63. /**
  64. * @brief Destroy a runtime sleep retention linked list
  65. *
  66. * @param module the bitmap of the module to be destroyed
  67. */
  68. void sleep_retention_entries_destroy(int module);
  69. /**
  70. * @brief Print all runtime sleep retention linked lists
  71. */
  72. void sleep_retention_entries_show_memories(void);
  73. /**
  74. * @brief Find the linked list node with the unique id
  75. *
  76. * @param id the unique identifier of specified linked list node
  77. *
  78. * @return NULL or the address of the linked list node found
  79. */
  80. void * sleep_retention_find_link_by_id(int id);
  81. /**
  82. * @brief Get the head pointer of all entry linked list of REGDMA
  83. *
  84. * @param entries buffer for getting results
  85. */
  86. void sleep_retention_entries_get(sleep_retention_entries_t *entries);
  87. #if SOC_PM_RETENTION_HAS_CLOCK_BUG
  88. /**
  89. * @brief Software trigger REGDMA to do extra linked list retention
  90. *
  91. * @param backup_or_restore true for backup register context to memory
  92. * or false for restore to register from memory
  93. */
  94. void sleep_retention_do_extra_retention(bool backup_or_restore);
  95. void sleep_retention_module_deinit(void);
  96. #endif
  97. /**
  98. * @brief Get all registered modules that require sleep retention
  99. *
  100. * This is an unprotected interface for getting a bitmap of all modules that
  101. * require sleep retention.
  102. *
  103. * It can only be called by the sleep procedure.
  104. *
  105. * @return the bitmap of all modules requiring sleep retention
  106. */
  107. uint32_t sleep_retention_get_modules(void);
  108. #if SOC_PM_RETENTION_HAS_REGDMA_POWER_BUG
  109. /**
  110. * @brief Software trigger REGDMA to do system linked list retention
  111. *
  112. * @param backup_or_restore true for backup register context to memory
  113. * or false for restore to register from memory
  114. */
  115. void sleep_retention_do_system_retention(bool backup_or_restore);
  116. #endif
  117. #endif // SOC_PAU_SUPPORTED
  118. #ifdef __cplusplus
  119. }
  120. #endif