1 /***************************************************************************//** 2 * @file 3 * @brief SLEEPTIMER SDK internal APIs. 4 ******************************************************************************* 5 * # License 6 * <b>Copyright 2019 Silicon Laboratories Inc. www.silabs.com</b> 7 ******************************************************************************* 8 * 9 * SPDX-License-Identifier: Zlib 10 * 11 * The licensor of this software is Silicon Laboratories Inc. 12 * 13 * This software is provided 'as-is', without any express or implied 14 * warranty. In no event will the authors be held liable for any damages 15 * arising from the use of this software. 16 * 17 * Permission is granted to anyone to use this software for any purpose, 18 * including commercial applications, and to alter it and redistribute it 19 * freely, subject to the following restrictions: 20 * 21 * 1. The origin of this software must not be misrepresented; you must not 22 * claim that you wrote the original software. If you use this software 23 * in a product, an acknowledgment in the product documentation would be 24 * appreciated but is not required. 25 * 2. Altered source versions must be plainly marked as such, and must not be 26 * misrepresented as being the original software. 27 * 3. This notice may not be removed or altered from any source distribution. 28 * 29 ******************************************************************************/ 30 31 #ifndef SLI_SLEEPTIMER_H 32 #define SLI_SLEEPTIMER_H 33 34 #include <stdint.h> 35 #include <stddef.h> 36 #include <stdbool.h> 37 #include "em_device.h" 38 #include "sl_sleeptimer_config.h" 39 #include "sl_code_classification.h" 40 41 #define SLEEPTIMER_EVENT_OF (0x01) 42 #define SLEEPTIMER_EVENT_COMP (0x02) 43 44 #define SLI_SLEEPTIMER_POWER_MANAGER_EARLY_WAKEUP_TIMER_FLAG 0x02 45 #define SLI_SLEEPTIMER_POWER_MANAGER_HF_ACCURACY_CLK_FLAG 0x04 46 47 #if SL_SLEEPTIMER_PERIPHERAL == SL_SLEEPTIMER_PERIPHERAL_DEFAULT 48 #if defined(RTCC_PRESENT) && RTCC_COUNT >= 1 49 #undef SL_SLEEPTIMER_PERIPHERAL 50 #define SL_SLEEPTIMER_PERIPHERAL SL_SLEEPTIMER_PERIPHERAL_RTCC 51 #elif defined(RTC_PRESENT) && RTC_COUNT >= 1 52 #undef SL_SLEEPTIMER_PERIPHERAL 53 #define SL_SLEEPTIMER_PERIPHERAL SL_SLEEPTIMER_PERIPHERAL_RTC 54 #elif defined(SYSRTC_PRESENT) && SYSRTC_COUNT >= 1 55 #undef SL_SLEEPTIMER_PERIPHERAL 56 #define SL_SLEEPTIMER_PERIPHERAL SL_SLEEPTIMER_PERIPHERAL_SYSRTC 57 #elif defined(BURTC_PRESENT) && BURTC_COUNT >= 1 58 #undef SL_SLEEPTIMER_PERIPHERAL 59 #define SL_SLEEPTIMER_PERIPHERAL SL_SLEEPTIMER_PERIPHERAL_BURTC 60 #elif defined(WTIMER_PRESENT) && WTIMER_COUNT >= 1 61 #undef SL_SLEEPTIMER_PERIPHERAL 62 #define SL_SLEEPTIMER_PERIPHERAL SL_SLEEPTIMER_PERIPHERAL_WTIMER 63 #elif defined(TIMER_PRESENT) && TIMER_COUNT >= 1 64 #undef SL_SLEEPTIMER_PERIPHERAL 65 #define SL_SLEEPTIMER_PERIPHERAL SL_SLEEPTIMER_PERIPHERAL_TIMER 66 #endif 67 #endif 68 69 #ifdef __cplusplus 70 extern "C" { 71 #endif 72 73 /******************************************************************************* 74 * Hardware Abstraction Layer to perform initialization related to Power Manager. 75 ******************************************************************************/ 76 __WEAK void sli_sleeptimer_hal_power_manager_integration_init(void); 77 78 /******************************************************************************* 79 * Hardware Abstraction Layer to perform initialization related to HFXO Manager. 80 ******************************************************************************/ 81 __WEAK void sli_sleeptimer_hal_hfxo_manager_integration_init(void); 82 83 /******************************************************************************* 84 * Hardware Abstraction Layer to get interrupt status. 85 * 86 * @param local_flag Internal interrupt flag. 87 * 88 * @return Boolean indicating if specified interrupt is set. 89 ******************************************************************************/ 90 SL_CODE_CLASSIFY(SL_CODE_COMPONENT_SLEEPTIMER, SL_CODE_CLASS_TIME_CRITICAL) 91 bool sli_sleeptimer_hal_is_int_status_set(uint8_t local_flag); 92 93 /**************************************************************************//** 94 * Determines if next timer to expire has the option flag 95 * "SLI_SLEEPTIMER_POWER_MANAGER_EARLY_WAKEUP_TIMER_FLAG". 96 * 97 * @return true if power manager will expire at next compare match, 98 * false otherwise. 99 *****************************************************************************/ 100 SL_CODE_CLASSIFY(SL_CODE_COMPONENT_SLEEPTIMER, SL_CODE_CLASS_TIME_CRITICAL) 101 bool sli_sleeptimer_is_power_manager_timer_next_to_expire(void); 102 103 /***************************************************************************//** 104 * Set lowest energy mode based on a project's configurations and clock source 105 * 106 * @note If power_manager_no_deepsleep component is included in a project, the 107 * lowest possible energy mode is EM1, else lowest energy mode is 108 * determined by clock source. 109 ******************************************************************************/ 110 #if defined(SL_CATALOG_POWER_MANAGER_PRESENT) 111 SL_CODE_CLASSIFY(SL_CODE_COMPONENT_SLEEPTIMER, SL_CODE_CLASS_TIME_CRITICAL) 112 void sli_sleeptimer_set_pm_em_requirement(void); 113 #endif 114 115 /***************************************************************************//** 116 * @brief 117 * Update sleep_on_isr_exit flag. 118 * 119 * @param flag Boolean value update_sleep_on_isr_exit will be set to. 120 ******************************************************************************/ 121 SL_CODE_CLASSIFY(SL_CODE_COMPONENT_SLEEPTIMER, SL_CODE_CLASS_TIME_CRITICAL) 122 void sli_sleeptimer_update_sleep_on_isr_exit(bool flag); 123 124 /******************************************************************************* 125 * Gets the associated peripheral capture channel current value. 126 * 127 * @return Capture value 128 * 0 if capture channel is not valid 129 ******************************************************************************/ 130 SL_CODE_CLASSIFY(SL_CODE_COMPONENT_SLEEPTIMER, SL_CODE_CLASS_TIME_CRITICAL) 131 uint32_t sli_sleeptimer_get_capture(void); 132 133 /******************************************************************************* 134 * Resets the PRS signal triggered by the associated peripheral. 135 ******************************************************************************/ 136 SL_CODE_CLASSIFY(SL_CODE_COMPONENT_SLEEPTIMER, SL_CODE_CLASS_TIME_CRITICAL) 137 void sli_sleeptimer_reset_prs_signal(void); 138 139 #ifdef __cplusplus 140 } 141 #endif 142 143 #endif /* SLI_SLEEPTIMER_H */ 144