1 /***************************************************************************//**
2  * @file
3  * @brief Power Manager Internal API definition.
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 #include "sl_power_manager.h"
32 #include "sl_slist.h"
33 
34 #if defined(SL_COMPONENT_CATALOG_PRESENT)
35 #include "sl_component_catalog.h"
36 #endif
37 
38 #if defined(SL_CATALOG_EMLIB_CORE_DEBUG_CONFIG_PRESENT)
39 #include "emlib_core_debug_config.h"
40 #endif
41 
42 #if !defined(SL_EMLIB_CORE_ENABLE_INTERRUPT_DISABLED_TIMING)
43 #define SL_EMLIB_CORE_ENABLE_INTERRUPT_DISABLED_TIMING   0
44 #endif
45 
46 #if (SL_EMLIB_CORE_ENABLE_INTERRUPT_DISABLED_TIMING == 1)
47 #include "sl_cycle_counter.h"
48 #endif
49 
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53 
54 /*******************************************************************************
55  *******************************   DEFINES   ***********************************
56  ******************************************************************************/
57 
58 #define SLI_POWER_MANAGER_EM_TABLE_SIZE  2
59 
60 /*******************************************************************************
61  *****************************   DATA TYPES   *********************************
62  ******************************************************************************/
63 
64 // Debug entry
65 typedef struct {
66   sl_slist_node_t node;
67   const char *module_name;
68 } sli_power_debug_requirement_entry_t;
69 
70 /*******************************************************************************
71  *****************************   PROTOTYPES   **********************************
72  ******************************************************************************/
73 
74 void sli_power_manager_init_hardware(void);
75 
76 void sli_power_manager_apply_em(sl_power_manager_em_t em);
77 
78 void sli_power_manager_debug_init(void);
79 
80 #if !defined(SL_CATALOG_POWER_MANAGER_NO_DEEPSLEEP_PRESENT)
81 void sli_power_manager_save_states(void);
82 
83 void sli_power_manager_handle_pre_deepsleep_operations(void);
84 
85 void sli_power_manager_restore_high_freq_accuracy_clk(void);
86 
87 bool sli_power_manager_is_high_freq_accuracy_clk_ready(bool wait);
88 
89 void sli_power_manager_restore_states(void);
90 
91 /*******************************************************************************
92  * Converts microseconds time in sleeptimer ticks.
93  ******************************************************************************/
94 uint32_t sli_power_manager_convert_delay_us_to_tick(uint32_t time_us);
95 
96 /*******************************************************************************
97  * Returns the default minimum offtime for xtal high frequency oscillator.
98  ******************************************************************************/
99 uint32_t sli_power_manager_get_default_high_frequency_minimum_offtime(void);
100 
101 /*******************************************************************************
102  * Restores the Low Frequency clocks according to which LF oscillators are used.
103  ******************************************************************************/
104 void sli_power_manager_low_frequency_restore(void);
105 
106 /***************************************************************************//**
107  * Informs the power manager if the high accuracy/high frequency clock
108  * is used, prior to scheduling an early clock restore.
109  *
110  * @return true if HFXO is used, else false.
111  ******************************************************************************/
112 bool sli_power_manager_is_high_freq_accuracy_clk_used(void);
113 #endif
114 
115 /***************************************************************************//**
116  * Enable or disable fast wake-up in EM2 and EM3
117  *
118  * @note Will also update the wake up time from EM2 to EM0.
119  ******************************************************************************/
120 void sli_power_manager_em23_voltage_scaling_enable_fast_wakeup(bool enable);
121 
122 /*******************************************************************************
123  * Gets the delay associated the wake-up process from EM23.
124  *
125  * @return Delay for the complete wake-up process with full restore.
126  ******************************************************************************/
127 uint32_t sli_power_manager_get_wakeup_process_time_overhead(void);
128 
129 #if !defined(SL_CATALOG_POWER_MANAGER_NO_DEEPSLEEP_PRESENT)
130 /*******************************************************************************
131  * Gets the status of power manager variable is_sleeping_waiting_for_clock_restore.
132  *
133  * @return true if Power Manager is sleeping waiting for clock restore, else false.
134  *
135  * @note FOR INTERNAL USE ONLY.
136  ******************************************************************************/
137 bool sli_power_manager_get_clock_restore_status(void);
138 #endif
139 
140 #ifdef __cplusplus
141 }
142 #endif
143